diff options
author | huntc <huntchr@gmail.com> | 2022-10-09 13:07:25 +1100 |
---|---|---|
committer | huntc <huntchr@gmail.com> | 2022-10-09 13:07:25 +1100 |
commit | e1faf8860776f6ad2bac2f3b06e7160fe00da7df (patch) | |
tree | 72ae88efc2d86e7dbdccee5f5dd7c8d6676a25cf /examples | |
parent | f8fd6ab208fd09142ab9789078e9b23ba8c3e6a9 (diff) | |
download | embassy-e1faf8860776f6ad2bac2f3b06e7160fe00da7df.zip |
Removes some of the code duplication for UarteWithIdle
This commit removes some of the code duplication for UarteWithIdle at the expense of requiring a split. As the example illustrates though, this expense seems worth the benefit in terms of maintenance, and the avoidance of copying over methods. My main motivation for this commit was actually due to the `event_endtx` method not having been copied across.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/nrf/src/bin/uart_idle.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/examples/nrf/src/bin/uart_idle.rs b/examples/nrf/src/bin/uart_idle.rs index 09ec624c..6af4f709 100644 --- a/examples/nrf/src/bin/uart_idle.rs +++ b/examples/nrf/src/bin/uart_idle.rs @@ -15,7 +15,8 @@ async fn main(_spawner: Spawner) { config.baudrate = uarte::Baudrate::BAUD115200; let irq = interrupt::take!(UARTE0_UART0); - let mut uart = uarte::UarteWithIdle::new(p.UARTE0, p.TIMER0, p.PPI_CH0, p.PPI_CH1, irq, p.P0_08, p.P0_06, config); + let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config); + let (mut tx, mut rx) = uart.split_with_idle(p.TIMER0, p.PPI_CH0, p.PPI_CH1); info!("uarte initialized!"); @@ -23,12 +24,12 @@ async fn main(_spawner: Spawner) { let mut buf = [0; 8]; buf.copy_from_slice(b"Hello!\r\n"); - unwrap!(uart.write(&buf).await); + unwrap!(tx.write(&buf).await); info!("wrote hello in uart!"); loop { info!("reading..."); - let n = unwrap!(uart.read_until_idle(&mut buf).await); + let n = unwrap!(rx.read_until_idle(&mut buf).await); info!("got {} bytes", n); } } |