embassy/examples
bors[bot] 5df16c6793
Merge #544
544: Introduces split on the nRF Uarte r=Dirbaio a=huntc

A new `split` method is introduced such that the Uarte tx and rx can be used from separate tasks. An MPSC is used in an example to illustrate how data may be passed between these tasks.

The approach taken within the `Uarte` struct is to split into tx and rx fields on calling `Uarte::new`. These fields are returned given a call to `Uarte::split`, but otherwise, if that call isn't made, then the API remains as it was before.

Here's a snippet from a new example introduced:

```rust
#[embassy::main]
async fn main(spawner: Spawner, p: Peripherals) {
    // ...

    let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, NoPin, NoPin, config);
    let (mut tx, rx) = uart.split();

    // ...

    // Spawn a task responsible purely for reading

    unwrap!(spawner.spawn(reader(rx, s)));

    // ...

    // Continue reading in this main task and write
    // back out the buffer we receive from the read
    // task.
    loop {
        if let Some(buf) = r.recv().await {
            info!("writing...");
            unwrap!(tx.write(&buf).await);
        }
    }
}

#[embassy::task]
async fn reader(mut rx: UarteRx<'static, UARTE0>, s: Sender<'static, Noop, [u8; 8], 1>) {
    let mut buf = [0; 8];
    loop {
        info!("reading...");
        unwrap!(rx.read(&mut buf).await);
        unwrap!(s.send(buf).await);
    }
}
```


Co-authored-by: huntc <huntchr@gmail.com>
2021-12-16 07:44:40 +00:00
..
nrf Merge #544 2021-12-16 07:44:40 +00:00
rp Remove unused deps 2021-11-15 20:13:22 +01:00
std Do not use exported Result to mitigate problems with clap. 2021-12-08 22:19:13 +01:00
stm32f0 Remove unused deps 2021-11-15 20:13:22 +01:00
stm32f1 examples: remove unused deps. 2021-11-29 02:07:48 +01:00
stm32f3 [examples] Add examples for STM32F3 2021-12-13 14:50:13 +05:30
stm32f4 examples: remove unused deps. 2021-11-29 02:07:48 +01:00
stm32f7 Use smoltcp 0.8.0 from crates.io. 2021-12-12 15:32:36 +01:00
stm32g0 examples: remove unused deps. 2021-11-29 02:07:48 +01:00
stm32g4 examples/stm32g4: add pwm example 2021-11-27 03:06:46 +01:00
stm32h7 Use smoltcp 0.8.0 from crates.io. 2021-12-12 15:32:36 +01:00
stm32l0 Refactor sx127x radio to use async SPI with DMA 2021-12-03 09:53:28 +01:00
stm32l1 examples: remove unused deps. 2021-11-29 02:07:48 +01:00
stm32l4 examples: remove unused deps. 2021-11-29 02:07:48 +01:00
stm32u5 examples: remove unused deps. 2021-11-29 02:07:48 +01:00
stm32wb55 examples: remove unused deps. 2021-11-29 02:07:48 +01:00
stm32wl55 Update rust-lorawan to version supporting defmt 0.3 2021-12-02 19:10:29 +01:00
wasm Update versions of critical-section and atomic-polyfill 2021-11-02 18:52:03 +01:00