aboutsummaryrefslogtreecommitdiff
path: root/examples/rp
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2023-01-04 20:18:02 +0000
committerGitHub <[email protected]>2023-01-04 20:18:02 +0000
commitf339e8518f7ec11da93dfb615ed8aa0ed009358f (patch)
treeae99756e87b98f62c78d062c672996a12ed5c465 /examples/rp
parentbf4c0de16a119b9e3a42daf76c4bc60face3c2a1 (diff)
parent6d4c6e0481f0738b8306172e7c5d54aa2758b74e (diff)
Merge #1143
1143: rp2040: add {tx,rx}-only constructors to UART r=Dirbaio a=pferreir As discussed with `@henrik-alser` on Matrix. I also added an example, feel free to remove it if it's too much. Co-authored-by: Pedro Ferreira <[email protected]>
Diffstat (limited to 'examples/rp')
-rw-r--r--examples/rp/src/bin/uart_unidir.rs42
1 files changed, 42 insertions, 0 deletions
diff --git a/examples/rp/src/bin/uart_unidir.rs b/examples/rp/src/bin/uart_unidir.rs
new file mode 100644
index 000000000..f56e7009f
--- /dev/null
+++ b/examples/rp/src/bin/uart_unidir.rs
@@ -0,0 +1,42 @@
1//! test TX-only and RX-only UARTs. You need to connect GPIO0 to GPIO5 for
2//! this to work
3
4#![no_std]
5#![no_main]
6#![feature(type_alias_impl_trait)]
7
8use defmt::*;
9use embassy_executor::Spawner;
10use embassy_rp::peripherals::UART1;
11use embassy_rp::uart::{Async, Config, UartRx, UartTx};
12use embassy_time::{Duration, Timer};
13use {defmt_rtt as _, panic_probe as _};
14
15#[embassy_executor::main]
16async fn main(spawner: Spawner) {
17 let p = embassy_rp::init(Default::default());
18
19 let mut uart_tx = UartTx::new(p.UART0, p.PIN_0, p.DMA_CH0, Config::default());
20 let uart_rx = UartRx::new(p.UART1, p.PIN_5, p.DMA_CH1, Config::default());
21
22 unwrap!(spawner.spawn(reader(uart_rx)));
23
24 info!("Writing...");
25 loop {
26 let data = [1u8, 2, 3, 4, 5, 6, 7, 8];
27 info!("TX {:?}", data);
28 uart_tx.write(&data).await.unwrap();
29 Timer::after(Duration::from_secs(1)).await;
30 }
31}
32
33#[embassy_executor::task]
34async fn reader(mut rx: UartRx<'static, UART1, Async>) {
35 info!("Reading...");
36 loop {
37 // read a total of 4 transmissions (32 / 8) and then print the result
38 let mut buf = [0; 32];
39 rx.read(&mut buf).await.unwrap();
40 info!("RX {:?}", buf);
41 }
42}