Merge pull request #3179 from 1-rafael-1/impl-ReadReady-for-buffered-uart

Impl read ready for buffered uart
This commit is contained in:
James Munns 2024-07-14 17:14:37 +00:00 committed by GitHub
commit 4472e08bca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View File

@ -766,6 +766,12 @@ impl<'d, U: UarteInstance, T: TimerInstance> BufferedUarteRx<'d, U, T> {
rx.pop_done(amt);
U::regs().intenset.write(|w| w.rxstarted().set());
}
/// we are ready to read if there is data in the buffer
fn read_ready() -> Result<bool, Error> {
let state = U::buffered_state();
Ok(!state.rx_buf.is_empty())
}
}
impl<'a, U: UarteInstance, T: TimerInstance> Drop for BufferedUarteRx<'a, U, T> {
@ -827,6 +833,18 @@ mod _embedded_io {
}
}
impl<'d, U: UarteInstance, T: TimerInstance + 'd> embedded_io_async::ReadReady for BufferedUarte<'d, U, T> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
BufferedUarteRx::<'d, U, T>::read_ready()
}
}
impl<'d, U: UarteInstance, T: TimerInstance + 'd> embedded_io_async::ReadReady for BufferedUarteRx<'d, U, T> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Self::read_ready()
}
}
impl<'d, U: UarteInstance, T: TimerInstance> embedded_io_async::BufRead for BufferedUarte<'d, U, T> {
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
self.fill_buf().await

View File

@ -436,6 +436,12 @@ impl<'d> BufferedUartRx<'d> {
}
}
/// we are ready to read if there is data in the buffer
fn read_ready(&mut self) -> Result<bool, Error> {
let state = self.state;
Ok(!state.rx_buf.is_empty())
}
/// Reconfigure the driver
pub fn set_config(&mut self, config: &Config) -> Result<(), ConfigError> {
reconfigure(self.info, self.kernel_clock, config)?;
@ -610,6 +616,18 @@ impl<'d> embedded_io_async::Read for BufferedUartRx<'d> {
}
}
impl<'d> embedded_io_async::ReadReady for BufferedUart<'d> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
BufferedUartRx::<'d>::read_ready(&mut self.rx)
}
}
impl<'d> embedded_io_async::ReadReady for BufferedUartRx<'d> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Self::read_ready(self)
}
}
impl<'d> embedded_io_async::BufRead for BufferedUart<'d> {
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
self.rx.fill_buf().await