diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 6f8b6a9e..d71aa61a 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -910,6 +910,58 @@ mod eh1 { } } +#[cfg(all(feature = "unstable-traits", feature = "nightly"))] +mod eio { + use embedded_io::asynch::Write; + use embedded_io::Io; + + use super::*; + + impl Io for Uart<'_, T, TxDma, RxDma> + where + T: BasicInstance, + { + type Error = Error; + } + + impl Write for Uart<'_, T, TxDma, RxDma> + where + T: BasicInstance, + TxDma: super::TxDma, + { + async fn write(&mut self, buf: &[u8]) -> Result { + self.write(buf).await?; + Ok(buf.len()) + } + + async fn flush(&mut self) -> Result<(), Self::Error> { + self.blocking_flush() + } + } + + impl Io for UartTx<'_, T, TxDma> + where + T: BasicInstance, + { + type Error = Error; + } + + impl Write for UartTx<'_, T, TxDma> + where + T: BasicInstance, + TxDma: super::TxDma, + { + async fn write(&mut self, buf: &[u8]) -> Result { + self.write(buf).await?; + Ok(buf.len()) + } + + async fn flush(&mut self) -> Result<(), Self::Error> { + self.blocking_flush() + } + } +} + #[cfg(all( feature = "unstable-traits", feature = "nightly",