use core::sync::atomic::{compiler_fence, Ordering::SeqCst};
use nrf52832_hal::nrf52832_pac::UARTE0;
pub(crate) fn start_read(
rx_buffer: &mut [u8],
flush: bool,
) -> Result<(), nrf52832_hal::uarte::Error> {
let periph = unsafe { &*UARTE0::ptr() };
if rx_buffer.len() > u8::max_value() as usize {
return Err(nrf52832_hal::uarte::Error::TxBufferTooLong);
}
compiler_fence(SeqCst);
periph.rxd.ptr.write(|w|
unsafe { w.ptr().bits(rx_buffer.as_ptr() as u32) });
periph.rxd.maxcnt.write(|w|
unsafe { w.maxcnt().bits(rx_buffer.len() as _) });
if flush {
periph.tasks_flushrx.write(|w| unsafe { w.bits(1) });
while periph.events_endrx.read().bits() != 1 {}
periph.events_endrx.write(|w| unsafe { w.bits(0) });
}
periph.tasks_startrx.write(|w|
unsafe { w.bits(1) });
Ok(())
}