diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-12-23 22:16:58 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-23 22:16:58 +0000 |
| commit | 67a6e5accfce0963060a20418bab04495c5bf50d (patch) | |
| tree | 7bea170664f5f0f9da81464206d243467d89d10d /examples | |
| parent | 74fdd4c03c4e6307445b6e1b55965880186bf4e2 (diff) | |
| parent | 787745188c3b62a0170d15ba39f3e58929ae203b (diff) | |
Merge #1122
1122: embassy-rp: Add split() to BufferedUart r=kalkyl a=kalkyl
Co-authored-by: kalkyl <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/rp/.cargo/config.toml | 2 | ||||
| -rw-r--r-- | examples/rp/src/bin/uart_buffered_split.rs | 57 |
2 files changed, 58 insertions, 1 deletions
diff --git a/examples/rp/.cargo/config.toml b/examples/rp/.cargo/config.toml index 3d6051389..d1c8c1c5a 100644 --- a/examples/rp/.cargo/config.toml +++ b/examples/rp/.cargo/config.toml | |||
| @@ -5,4 +5,4 @@ runner = "probe-run --chip RP2040" | |||
| 5 | target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ | 5 | target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+ |
| 6 | 6 | ||
| 7 | [env] | 7 | [env] |
| 8 | DEFMT_LOG = "trace" | 8 | DEFMT_LOG = "debug" |
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 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_executor::_export::StaticCell; | ||
| 8 | use embassy_rp::interrupt; | ||
| 9 | use embassy_rp::peripherals::UART0; | ||
| 10 | use embassy_rp::uart::{BufferedUart, BufferedUartRx, Config}; | ||
| 11 | use embassy_time::{Duration, Timer}; | ||
| 12 | use embedded_io::asynch::{Read, Write}; | ||
| 13 | use {defmt_rtt as _, panic_probe as _}; | ||
| 14 | |||
| 15 | macro_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] | ||
| 25 | async 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] | ||
| 50 | async 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 | } | ||
