From 4c4b47f78a57e5bf3d05b319759351a005e69206 Mon Sep 17 00:00:00 2001 From: Rasmus Melchior Jacobsen Date: Fri, 6 Jan 2023 14:24:29 +0100 Subject: [PATCH] feat(stm32): Add embedded-io traits for UartRx and UartTx --- embassy-stm32/src/usart/mod.rs | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 233b56ba..1c13d9ec 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs @@ -948,6 +948,45 @@ mod eio { self.blocking_flush() } } + + impl Io for UartRx<'_, T, RxDma> + where + T: BasicInstance, + { + type Error = Error; + } + + impl Read for UartRx<'_, T, RxDma> + where + T: BasicInstance, + RxDma: super::RxDma, + { + async fn read(&mut self, buf: &mut [u8]) -> Result { + self.read_until_idle(buf).await + } + } + + 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(