aboutsummaryrefslogtreecommitdiff
path: root/examples/nrf/src/bin/uart_split.rs
diff options
context:
space:
mode:
authorDominik Boehi <[email protected]>2023-01-09 22:29:58 +0100
committerDominik Boehi <[email protected]>2023-01-09 22:30:02 +0100
commit0a27b6cedb52453123190671f294bbd34918e09a (patch)
tree3888e0b352388ace235517ec97c4d3a88fd7fcfa /examples/nrf/src/bin/uart_split.rs
parent401185b1d95a2519ee94e5d5654cc9325fe85eec (diff)
Rename examples/nrf to examples/nrf52840
Diffstat (limited to 'examples/nrf/src/bin/uart_split.rs')
-rw-r--r--examples/nrf/src/bin/uart_split.rs60
1 files changed, 0 insertions, 60 deletions
diff --git a/examples/nrf/src/bin/uart_split.rs b/examples/nrf/src/bin/uart_split.rs
deleted file mode 100644
index 1adaf53fd..000000000
--- a/examples/nrf/src/bin/uart_split.rs
+++ /dev/null
@@ -1,60 +0,0 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_nrf::peripherals::UARTE0;
8use embassy_nrf::uarte::UarteRx;
9use embassy_nrf::{interrupt, uarte};
10use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
11use embassy_sync::channel::Channel;
12use {defmt_rtt as _, panic_probe as _};
13
14static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
15
16#[embassy_executor::main]
17async fn main(spawner: Spawner) {
18 let p = embassy_nrf::init(Default::default());
19 let mut config = uarte::Config::default();
20 config.parity = uarte::Parity::EXCLUDED;
21 config.baudrate = uarte::Baudrate::BAUD115200;
22
23 let irq = interrupt::take!(UARTE0_UART0);
24 let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config);
25 let (mut tx, rx) = uart.split();
26
27 info!("uarte initialized!");
28
29 // Spawn a task responsible purely for reading
30
31 unwrap!(spawner.spawn(reader(rx)));
32
33 // Message must be in SRAM
34 {
35 let mut buf = [0; 23];
36 buf.copy_from_slice(b"Type 8 chars to echo!\r\n");
37
38 unwrap!(tx.write(&buf).await);
39 info!("wrote hello in uart!");
40 }
41
42 // Continue reading in this main task and write
43 // back out the buffer we receive from the read
44 // task.
45 loop {
46 let buf = CHANNEL.recv().await;
47 info!("writing...");
48 unwrap!(tx.write(&buf).await);
49 }
50}
51
52#[embassy_executor::task]
53async fn reader(mut rx: UarteRx<'static, UARTE0>) {
54 let mut buf = [0; 8];
55 loop {
56 info!("reading...");
57 unwrap!(rx.read(&mut buf).await);
58 CHANNEL.send(buf).await;
59 }
60}