2020-12-23 16:18:29 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt::*;
|
2021-03-29 02:47:10 +02:00
|
|
|
use embassy::executor::Spawner;
|
2021-01-03 01:40:40 +01:00
|
|
|
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
|
2021-07-29 14:08:32 +02:00
|
|
|
use embassy_nrf::buffered_uarte::State;
|
2021-03-29 02:47:10 +02:00
|
|
|
use embassy_nrf::{buffered_uarte::BufferedUarte, interrupt, uarte, Peripherals};
|
2021-03-29 00:42:08 +02:00
|
|
|
use futures::pin_mut;
|
2021-01-03 01:40:40 +01:00
|
|
|
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt_rtt as _; // global logger
|
|
|
|
use panic_probe as _;
|
|
|
|
|
2021-03-29 02:47:10 +02:00
|
|
|
#[embassy::main]
|
2021-05-17 11:48:58 +02:00
|
|
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
2021-03-28 22:41:45 +02:00
|
|
|
let mut config = uarte::Config::default();
|
|
|
|
config.parity = uarte::Parity::EXCLUDED;
|
|
|
|
config.baudrate = uarte::Baudrate::BAUD115200;
|
|
|
|
|
|
|
|
let mut tx_buffer = [0u8; 4096];
|
|
|
|
let mut rx_buffer = [0u8; 4096];
|
2021-01-06 23:36:46 +01:00
|
|
|
|
2020-12-23 16:18:29 +01:00
|
|
|
let irq = interrupt::take!(UARTE0_UART0);
|
2021-07-29 14:08:32 +02:00
|
|
|
let mut state = State::new();
|
2021-12-12 07:47:38 +01:00
|
|
|
// Please note - important to have hardware flow control (https://github.com/embassy-rs/embassy/issues/536)
|
2021-11-30 23:14:24 +01:00
|
|
|
let u = BufferedUarte::new(
|
|
|
|
&mut state,
|
|
|
|
p.UARTE0,
|
|
|
|
p.TIMER0,
|
|
|
|
p.PPI_CH0,
|
|
|
|
p.PPI_CH1,
|
|
|
|
irq,
|
|
|
|
p.P0_08,
|
|
|
|
p.P0_06,
|
2021-12-12 07:47:38 +01:00
|
|
|
p.P0_07,
|
|
|
|
p.P0_05,
|
2021-11-30 23:14:24 +01:00
|
|
|
config,
|
|
|
|
&mut rx_buffer,
|
|
|
|
&mut tx_buffer,
|
|
|
|
);
|
2021-02-20 00:27:24 +01:00
|
|
|
pin_mut!(u);
|
2020-12-23 16:18:29 +01:00
|
|
|
|
|
|
|
info!("uarte initialized!");
|
|
|
|
|
|
|
|
unwrap!(u.write_all(b"Hello!\r\n").await);
|
|
|
|
info!("wrote hello in uart!");
|
|
|
|
|
|
|
|
// Simple demo, reading 8-char chunks and echoing them back reversed.
|
|
|
|
loop {
|
|
|
|
info!("reading...");
|
|
|
|
let mut buf = [0u8; 8];
|
|
|
|
unwrap!(u.read_exact(&mut buf).await);
|
2021-02-24 08:57:06 +01:00
|
|
|
info!("read done, got {}", buf);
|
2020-12-23 16:18:29 +01:00
|
|
|
|
|
|
|
// Reverse buf
|
|
|
|
for i in 0..4 {
|
2021-02-14 01:41:36 +01:00
|
|
|
buf.swap(i, 7 - i);
|
2020-12-23 16:18:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
info!("writing...");
|
|
|
|
unwrap!(u.write_all(&buf).await);
|
|
|
|
info!("write done");
|
2021-12-10 02:08:00 +01:00
|
|
|
|
|
|
|
// Wait until the bytes are actually finished being transmitted
|
|
|
|
unwrap!(u.flush().await);
|
2020-12-23 16:18:29 +01:00
|
|
|
}
|
|
|
|
}
|