Introduce "peripheral" abstraction to share state between main and interrupt.

This commit is contained in:
Dario Nieuwenhuis
2021-01-03 01:40:40 +01:00
parent 4ce51795f2
commit ace4f40f80
7 changed files with 304 additions and 218 deletions

View File

@ -20,8 +20,4 @@ rustflags = [
]
[build]
# Pick ONE of these compilation targets
# target = "thumbv6m-none-eabi" # Cortex-M0 and Cortex-M0+
# target = "thumbv7m-none-eabi" # Cortex-M3
# target = "thumbv7em-none-eabi" # Cortex-M4 and Cortex-M7 (no FPU)
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU)
target = "thumbv7em-none-eabi"

View File

@ -8,15 +8,17 @@ use example_common::*;
use cortex_m_rt::entry;
use defmt::panic;
use futures::pin_mut;
use nrf52840_hal::gpio;
use embassy::executor::{task, Executor};
use embassy::io::{AsyncBufRead, AsyncBufReadExt, AsyncWrite, AsyncWriteExt};
use embassy::io::{AsyncBufReadExt, AsyncWriteExt};
use embassy::util::Forever;
use embassy_nrf::buffered_uarte;
use embassy_nrf::interrupt;
static mut TX_BUFFER: [u8; 4096] = [0; 4096];
static mut RX_BUFFER: [u8; 4096] = [0; 4096];
#[task]
async fn run() {
let p = unwrap!(embassy_nrf::pac::Peripherals::take());
@ -34,14 +36,15 @@ async fn run() {
};
let irq = interrupt::take!(UARTE0_UART0);
let u = buffered_uarte::BufferedUarte::new(
let mut u = buffered_uarte::BufferedUarte::new(
p.UARTE0,
irq,
unsafe { &mut RX_BUFFER },
unsafe { &mut TX_BUFFER },
pins,
buffered_uarte::Parity::EXCLUDED,
buffered_uarte::Baudrate::BAUD115200,
);
pin_mut!(u);
info!("uarte initialized!");