2021-12-15 07:51:26 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt::*;
|
2022-04-06 00:00:29 +02:00
|
|
|
use embassy::blocking_mutex::raw::ThreadModeRawMutex;
|
2022-06-12 07:16:56 +02:00
|
|
|
use embassy::channel::mpmc::Channel;
|
2022-01-13 22:24:13 +01:00
|
|
|
use embassy::executor::Spawner;
|
2021-12-15 07:51:26 +01:00
|
|
|
use embassy_nrf::peripherals::UARTE0;
|
|
|
|
use embassy_nrf::uarte::UarteRx;
|
|
|
|
use embassy_nrf::{interrupt, uarte, Peripherals};
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-02 04:35:06 +02:00
|
|
|
|
2022-04-06 00:00:29 +02:00
|
|
|
static CHANNEL: Channel<ThreadModeRawMutex, [u8; 8], 1> = Channel::new();
|
2021-12-15 07:51:26 +01:00
|
|
|
|
|
|
|
#[embassy::main]
|
|
|
|
async fn main(spawner: Spawner, p: Peripherals) {
|
|
|
|
let mut config = uarte::Config::default();
|
|
|
|
config.parity = uarte::Parity::EXCLUDED;
|
|
|
|
config.baudrate = uarte::Baudrate::BAUD115200;
|
|
|
|
|
|
|
|
let irq = interrupt::take!(UARTE0_UART0);
|
2022-02-12 01:04:01 +01:00
|
|
|
let uart = uarte::Uarte::new(p.UARTE0, irq, p.P0_08, p.P0_06, config);
|
2021-12-15 07:51:26 +01:00
|
|
|
let (mut tx, rx) = uart.split();
|
|
|
|
|
|
|
|
info!("uarte initialized!");
|
|
|
|
|
|
|
|
// Spawn a task responsible purely for reading
|
|
|
|
|
2022-04-06 00:00:29 +02:00
|
|
|
unwrap!(spawner.spawn(reader(rx)));
|
2021-12-15 07:51:26 +01:00
|
|
|
|
|
|
|
// Message must be in SRAM
|
|
|
|
{
|
|
|
|
let mut buf = [0; 23];
|
|
|
|
buf.copy_from_slice(b"Type 8 chars to echo!\r\n");
|
|
|
|
|
|
|
|
unwrap!(tx.write(&buf).await);
|
|
|
|
info!("wrote hello in uart!");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue reading in this main task and write
|
|
|
|
// back out the buffer we receive from the read
|
|
|
|
// task.
|
|
|
|
loop {
|
2022-04-06 00:00:29 +02:00
|
|
|
let buf = CHANNEL.recv().await;
|
|
|
|
info!("writing...");
|
|
|
|
unwrap!(tx.write(&buf).await);
|
2021-12-15 07:51:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[embassy::task]
|
2022-04-06 00:00:29 +02:00
|
|
|
async fn reader(mut rx: UarteRx<'static, UARTE0>) {
|
2021-12-15 07:51:26 +01:00
|
|
|
let mut buf = [0; 8];
|
|
|
|
loop {
|
|
|
|
info!("reading...");
|
|
|
|
unwrap!(rx.read(&mut buf).await);
|
2022-04-06 00:00:29 +02:00
|
|
|
CHANNEL.send(buf).await;
|
2021-12-15 07:51:26 +01:00
|
|
|
}
|
|
|
|
}
|