implement read_ready method in BufferedUart

This commit is contained in:
rafael 2024-07-10 22:54:48 +02:00
parent 6636a5835b
commit 68b3fbe348

View File

@ -315,6 +315,12 @@ impl<'d, T: Instance> BufferedUartRx<'d, T> {
w.set_rtim(true); w.set_rtim(true);
}); });
} }
/// we are ready to read if there is data in the buffer
fn read_ready() -> Result<bool, Error>{
let state = T::buffered_state();
Ok(!state.rx_buf.is_empty())
}
} }
impl<'d, T: Instance> BufferedUartTx<'d, T> { impl<'d, T: Instance> BufferedUartTx<'d, T> {
@ -621,6 +627,18 @@ impl<'d, T: Instance + 'd> embedded_io_async::Read for BufferedUartRx<'d, T> {
} }
} }
impl<'d, T: Instance + 'd> embedded_io_async::ReadReady for BufferedUart<'d, T> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
BufferedUartRx::<'d, T>::read_ready()
}
}
impl<'d, T: Instance + 'd> embedded_io_async::ReadReady for BufferedUartRx<'d, T> {
fn read_ready(&mut self) -> Result<bool, Self::Error> {
Self::read_ready()
}
}
impl<'d, T: Instance + 'd> embedded_io_async::BufRead for BufferedUart<'d, T> { impl<'d, T: Instance + 'd> embedded_io_async::BufRead for BufferedUart<'d, T> {
async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> {
BufferedUartRx::<'d, T>::fill_buf().await BufferedUartRx::<'d, T>::fill_buf().await