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-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2021-12-15 07:51:26 +01:00
|
|
|
use embassy_nrf::peripherals::UARTE0;
|
|
|
|
use embassy_nrf::uarte::UarteRx;
|
2023-03-05 20:17:52 +01:00
|
|
|
use embassy_nrf::{bind_interrupts, uarte};
|
2022-08-22 21:46:09 +02:00
|
|
|
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
|
2022-08-22 22:00:06 +02:00
|
|
|
use embassy_sync::channel::Channel;
|
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
|
|
|
|
2023-03-05 20:17:52 +01:00
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
UARTE0_UART0 => uarte::InterruptHandler<UARTE0>;
|
|
|
|
});
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 18:49:55 +02:00
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
let p = embassy_nrf::init(Default::default());
|
2021-12-15 07:51:26 +01:00
|
|
|
let mut config = uarte::Config::default();
|
|
|
|
config.parity = uarte::Parity::EXCLUDED;
|
|
|
|
config.baudrate = uarte::Baudrate::BAUD115200;
|
|
|
|
|
2023-03-05 20:17:52 +01:00
|
|
|
let uart = uarte::Uarte::new(p.UARTE0, Irqs, 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 {
|
2023-08-11 11:58:22 +02:00
|
|
|
let buf = CHANNEL.receive().await;
|
2022-04-06 00:00:29 +02:00
|
|
|
info!("writing...");
|
|
|
|
unwrap!(tx.write(&buf).await);
|
2021-12-15 07:51:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 21:58:35 +02:00
|
|
|
#[embassy_executor::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
|
|
|
}
|
|
|
|
}
|