aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src/bin/uart_split.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/nrf/src/bin/uart_split.rs')
-rw-r--r--examples/nrf/src/bin/uart_split.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs
index 909429b1a..3fde2f0d8 100644
--- a/examples/nrf/src/bin/uart_split.rs
+++ b/examples/nrf/src/bin/uart_split.rs
@@ -3,10 +3,9 @@
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use defmt::*; 5use defmt::*;
6use embassy::blocking_mutex::raw::NoopRawMutex; 6use embassy::blocking_mutex::raw::ThreadModeRawMutex;
7use embassy::channel::mpsc::{self, Channel, Sender}; 7use embassy::channel::channel::Channel;
8use embassy::executor::Spawner; 8use embassy::executor::Spawner;
9use embassy::util::Forever;
10use embassy_nrf::peripherals::UARTE0; 9use embassy_nrf::peripherals::UARTE0;
11use embassy_nrf::uarte::UarteRx; 10use embassy_nrf::uarte::UarteRx;
12use embassy_nrf::{interrupt, uarte, Peripherals}; 11use embassy_nrf::{interrupt, uarte, Peripherals};
@@ -14,7 +13,7 @@ use embassy_nrf::{interrupt, uarte, Peripherals};
14use defmt_rtt as _; // global logger 13use defmt_rtt as _; // global logger
15use panic_probe as _; 14use panic_probe as _;
16 15
17static CHANNEL: Forever<Channel<NoopRawMutex, [u8; 8], 1>> = Forever::new(); 16static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
18 17
19#[embassy::main] 18#[embassy::main]
20async fn main(spawner: Spawner, p: Peripherals) { 19async fn main(spawner: Spawner, p: Peripherals) {
@@ -26,14 +25,11 @@ async fn main(spawner: Spawner, p: Peripherals) {
26 let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config); 25 let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config);
27 let (mut tx, rx) = uart.split(); 26 let (mut tx, rx) = uart.split();
28 27
29 let c = CHANNEL.put(Channel::new());
30 let (s, mut r) = mpsc::split(c);
31
32 info!("uarte initialized!"); 28 info!("uarte initialized!");
33 29
34 // Spawn a task responsible purely for reading 30 // Spawn a task responsible purely for reading
35 31
36 unwrap!(spawner.spawn(reader(rx, s))); 32 unwrap!(spawner.spawn(reader(rx)));
37 33
38 // Message must be in SRAM 34 // Message must be in SRAM
39 { 35 {
@@ -48,19 +44,18 @@ async fn main(spawner: Spawner, p: Peripherals) {
48 // back out the buffer we receive from the read 44 // back out the buffer we receive from the read
49 // task. 45 // task.
50 loop { 46 loop {
51 if let Some(buf) = r.recv().await { 47 let buf = CHANNEL.recv().await;
52 info!("writing..."); 48 info!("writing...");
53 unwrap!(tx.write(&buf).await); 49 unwrap!(tx.write(&buf).await);
54 }
55 } 50 }
56} 51}
57 52
58#[embassy::task] 53#[embassy::task]
59async fn reader(mut rx: UarteRx<'static, UARTE0>, s: Sender<'static, NoopRawMutex, [u8; 8], 1>) { 54async fn reader(mut rx: UarteRx<'static, UARTE0>) {
60 let mut buf = [0; 8]; 55 let mut buf = [0; 8];
61 loop { 56 loop {
62 info!("reading..."); 57 info!("reading...");
63 unwrap!(rx.read(&mut buf).await); 58 unwrap!(rx.read(&mut buf).await);
64 unwrap!(s.send(buf).await); 59 CHANNEL.send(buf).await;
65 } 60 }
66} 61}