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;
|
2022-06-12 22:15:44 +02:00
|
|
|
use embassy_nrf::buffered_uarte::{BufferedUarte, State};
|
|
|
|
use embassy_nrf::{interrupt, uarte, Peripherals};
|
2022-05-26 22:15:06 +02:00
|
|
|
use embedded_io::asynch::{BufRead, Write};
|
2021-03-29 00:42:08 +02:00
|
|
|
use futures::pin_mut;
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-02 04:35:06 +02:00
|
|
|
|
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!");
|
|
|
|
|
|
|
|
loop {
|
|
|
|
info!("reading...");
|
2022-05-26 22:15:06 +02:00
|
|
|
let buf = unwrap!(u.fill_buf().await);
|
2021-02-24 08:57:06 +01:00
|
|
|
info!("read done, got {}", buf);
|
2020-12-23 16:18:29 +01:00
|
|
|
|
2022-05-26 22:15:06 +02:00
|
|
|
// Read bytes have to be explicitly consumed, otherwise fill_buf() will return them again
|
|
|
|
let n = buf.len();
|
|
|
|
u.consume(n);
|
2020-12-23 16:18:29 +01:00
|
|
|
}
|
|
|
|
}
|