stm32/uart impl ReadReady for RingbufferdUart

This commit is contained in:
dvdsk 2024-10-23 21:06:58 +02:00
parent 8803128707
commit be50b62677
No known key found for this signature in database
GPG Key ID: F687E89FC7894F98
2 changed files with 14 additions and 0 deletions

View File

@ -260,6 +260,8 @@ pub enum Error {
Parity,
/// Buffer too large for DMA
BufferTooLong,
// TODO: ask what this is and document it (dvdsk)
DmaUnsynced,
}
enum ReadCompletionEvent {
@ -1689,6 +1691,7 @@ impl embedded_hal_nb::serial::Error for Error {
Self::Overrun => embedded_hal_nb::serial::ErrorKind::Overrun,
Self::Parity => embedded_hal_nb::serial::ErrorKind::Parity,
Self::BufferTooLong => embedded_hal_nb::serial::ErrorKind::Other,
Self::DmaUnsynced => embedded_hal_nb::serial::ErrorKind::Other,
}
}
}

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,13 @@ 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 => Self::Error::DmaUnsynced,
})?;
Ok(len > 0)
}
}