mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-24 07:42:29 +00:00
stm32/uart impl ReadReady for RingbufferdUart
This commit is contained in:
parent
8803128707
commit
be50b62677
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user