aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorkalkyl <[email protected]>2022-12-22 23:03:05 +0100
committerkalkyl <[email protected]>2022-12-22 23:03:05 +0100
commitaa92ce6dc71cf176eb6e99632fda72c875d071e6 (patch)
tree634476ce53ba0c86b005515984eb5ec9c83d2a95 /examples
parent1bd6c954c23b16041b382243a844a53727f6cc9c (diff)
embassy-rp: Add split() to BufferedUart
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/.cargo/config.toml2
-rw-r--r--examples/rp/src/bin/uart_buffered_split.rs57
2 files changed, 58 insertions, 1 deletions
diff --git a/examples/rp/.cargo/config.toml b/examples/rp/.cargo/config.toml
index 3d6051389..7880c0955 100644
--- a/examples/rp/.cargo/config.toml
+++ b/examples/rp/.cargo/config.toml
@@ -5,4 +5,4 @@ runner = "probe-run --chip RP2040"
5target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ 5target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
6 6
7[env] 7[env]
8DEFMT_LOG = "trace" 8DEFMT_LOG = "info"
diff --git a/examples/rp/src/bin/uart_buffered_split.rs b/examples/rp/src/bin/uart_buffered_split.rs
new file mode 100644
index 000000000..36f31c906
--- /dev/null
+++ b/examples/rp/src/bin/uart_buffered_split.rs
@@ -0,0 +1,57 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_executor::_export::StaticCell;
8use embassy_rp::interrupt;
9use embassy_rp::peripherals::UART0;
10use embassy_rp::uart::{BufferedUart, BufferedUartRx, Config};
11use embassy_time::{Duration, Timer};
12use embedded_io::asynch::{Read, Write};
13use {defmt_rtt as _, panic_probe as _};
14
15macro_rules! singleton {
16 ($val:expr) => {{
17 type T = impl Sized;
18 static STATIC_CELL: StaticCell<T> = StaticCell::new();
19 let (x,) = STATIC_CELL.init(($val,));
20 x
21 }};
22}
23
24#[embassy_executor::main]
25async fn main(spawner: Spawner) {
26 let p = embassy_rp::init(Default::default());
27 let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0);
28
29 let irq = interrupt::take!(UART0_IRQ);
30 let tx_buf = &mut singleton!([0u8; 16])[..];
31 let rx_buf = &mut singleton!([0u8; 16])[..];
32 let mut uart = BufferedUart::new(uart, irq, tx_pin, rx_pin, tx_buf, rx_buf, Config::default());
33 let (rx, mut tx) = uart.split();
34
35 unwrap!(spawner.spawn(reader(rx)));
36
37 info!("Writing...");
38 loop {
39 let data = [
40 1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
41 29, 30, 31,
42 ];
43 info!("TX {:?}", data);
44 tx.write_all(&data).await.unwrap();
45 Timer::after(Duration::from_secs(1)).await;
46 }
47}
48
49#[embassy_executor::task]
50async fn reader(mut rx: BufferedUartRx<'static, UART0>) {
51 info!("Reading...");
52 loop {
53 let mut buf = [0; 31];
54 rx.read_exact(&mut buf).await.unwrap();
55 info!("RX {:?}", buf);
56 }
57}