diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-05-12 01:57:01 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-05-17 00:57:37 +0200 |
| commit | 0310e4d458b86df31f1765104eb3aa9a6ee09bfc (patch) | |
| tree | aca167ae6e37442cafc932b3c729e37082d23b04 /embassy-nrf-examples/src/bin/uart.rs | |
| parent | bfc7f52e6dd7b5ad12fa1f09483fa60f2732ae0c (diff) | |
Add `init` fn. Initializes hw and returns Peripherals.
Diffstat (limited to 'embassy-nrf-examples/src/bin/uart.rs')
| -rw-r--r-- | embassy-nrf-examples/src/bin/uart.rs | 32 |
1 files changed, 1 insertions, 31 deletions
diff --git a/embassy-nrf-examples/src/bin/uart.rs b/embassy-nrf-examples/src/bin/uart.rs index 23fc89312..9a0e65d3e 100644 --- a/embassy-nrf-examples/src/bin/uart.rs +++ b/embassy-nrf-examples/src/bin/uart.rs | |||
| @@ -17,9 +17,7 @@ use embassy_nrf::gpio::NoPin; | |||
| 17 | use embassy_nrf::{interrupt, uarte, Peripherals}; | 17 | use embassy_nrf::{interrupt, uarte, Peripherals}; |
| 18 | 18 | ||
| 19 | #[embassy::main] | 19 | #[embassy::main] |
| 20 | async fn main(spawner: Spawner) { | 20 | async fn main(spawner: Spawner, p: Peripherals) { |
| 21 | let p = unsafe { Peripherals::steal() }; | ||
| 22 | |||
| 23 | let mut config = uarte::Config::default(); | 21 | let mut config = uarte::Config::default(); |
| 24 | config.parity = uarte::Parity::EXCLUDED; | 22 | config.parity = uarte::Parity::EXCLUDED; |
| 25 | config.baudrate = uarte::Baudrate::BAUD115200; | 23 | config.baudrate = uarte::Baudrate::BAUD115200; |
| @@ -42,33 +40,5 @@ async fn main(spawner: Spawner) { | |||
| 42 | unwrap!(uart.read(&mut buf).await); | 40 | unwrap!(uart.read(&mut buf).await); |
| 43 | info!("writing..."); | 41 | info!("writing..."); |
| 44 | unwrap!(uart.write(&buf).await); | 42 | unwrap!(uart.write(&buf).await); |
| 45 | |||
| 46 | /* | ||
| 47 | // `receive()` doesn't return until the buffer has been completely filled with | ||
| 48 | // incoming data, which in this case is 8 bytes. | ||
| 49 | // | ||
| 50 | // This example shows how to use `select` to run an uart receive concurrently with a | ||
| 51 | // 1 second timer, effectively adding a timeout to the receive operation. | ||
| 52 | let recv_fut = uart.read(&mut buf); | ||
| 53 | let timer_fut = Timer::after(Duration::from_millis(1000)); | ||
| 54 | let received_len = match select(recv_fut, timer_fut).await { | ||
| 55 | // recv_fut completed first, so we've received `buf_len` bytes. | ||
| 56 | Either::Left(_) => buf_len, | ||
| 57 | // timer_fut completed first. `select` gives us back the future that didn't complete, which | ||
| 58 | // is `recv_fut` in this case, so we can do further stuff with it. | ||
| 59 | // | ||
| 60 | // The recv_fut would stop the uart read automatically when dropped. However, we want to know how | ||
| 61 | // many bytes have been received, so we have to "gracefully stop" it with `.stop()`. | ||
| 62 | Either::Right((_, recv_fut)) => recv_fut.stop().await, | ||
| 63 | }; | ||
| 64 | let received = &mut buf[..received_len]; | ||
| 65 | |||
| 66 | if !received.is_empty() { | ||
| 67 | info!("read done, got {}", received); | ||
| 68 | |||
| 69 | // Echo back received data | ||
| 70 | unwrap!(uart.write(received).await); | ||
| 71 | } | ||
| 72 | */ | ||
| 73 | } | 43 | } |
| 74 | } | 44 | } |
