Merge pull request #3451 from dvdsk/read_ready

stm32/uart impl ReadReady for RingbufferdUart
This commit is contained in:
Dario Nieuwenhuis 2024-11-03 23:57:07 +00:00 committed by GitHub
commit 089b8a482e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View File

@ -21,6 +21,10 @@ pub trait DmaCtrl {
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
Overrun,
/// the newly read DMA positions don't make sense compared to the previous
/// ones. This can usually only occur due to wrong Driver implementation, if
/// the driver author (or the user using raw metapac code) directly resets
/// the channel for instance.
DmaUnsynced,
}

View File

@ -5,6 +5,7 @@ use core::task::Poll;
use embassy_embedded_hal::SetConfig;
use embassy_hal_internal::PeripheralRef;
use embedded_io_async::ReadReady;
use futures_util::future::{select, Either};
use super::{clear_interrupt_flags, rdr, reconfigure, sr, Config, ConfigError, Error, Info, State, UartRx};
@ -262,3 +263,20 @@ impl embedded_io_async::Read for RingBufferedUartRx<'_> {
self.read(buf).await
}
}
impl ReadReady for RingBufferedUartRx<'_> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
let len = self.ring_buf.len().map_err(|e| match e {
crate::dma::ringbuffer::Error::Overrun => Self::Error::Overrun,
crate::dma::ringbuffer::Error::DmaUnsynced => {
error!(
"Ringbuffer error: DmaUNsynced, driver implementation is
probably bugged please open an issue"
);
// we report this as overrun since its recoverable in the same way
Self::Error::Overrun
}
})?;
Ok(len > 0)
}
}