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::*;
|
2022-08-17 23:40:16 +02:00
|
|
|
use embassy_executor::Spawner;
|
2023-03-05 20:17:52 +01:00
|
|
|
use embassy_nrf::buffered_uarte::{self, BufferedUarte};
|
|
|
|
use embassy_nrf::{bind_interrupts, peripherals, uarte};
|
2023-08-07 13:43:09 +02:00
|
|
|
use embedded_io_async::Write;
|
2022-06-12 22:15:44 +02:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2022-04-02 04:35:06 +02:00
|
|
|
|
2023-03-05 20:17:52 +01:00
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::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-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
|
|
|
|
2023-03-04 05:27:29 +01:00
|
|
|
let mut u = BufferedUarte::new(
|
2021-11-30 23:14:24 +01:00
|
|
|
p.UARTE0,
|
|
|
|
p.TIMER0,
|
|
|
|
p.PPI_CH0,
|
|
|
|
p.PPI_CH1,
|
2023-03-04 05:27:29 +01:00
|
|
|
p.PPI_GROUP0,
|
2023-03-05 20:17:52 +01:00
|
|
|
Irqs,
|
2021-11-30 23:14:24 +01:00
|
|
|
p.P0_08,
|
|
|
|
p.P0_06,
|
|
|
|
config,
|
|
|
|
&mut rx_buffer,
|
|
|
|
&mut tx_buffer,
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
}
|