From be1ed104e47e16eca1ec4e403db9ae02da5c9e27 Mon Sep 17 00:00:00 2001 From: Alexander Walter Date: Sat, 14 Dec 2024 00:57:55 +0100 Subject: [PATCH 1/2] Add trait embedded_io_async to uarte --- embassy-nrf/src/uarte.rs | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 2a59d029df..378325749d 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -1047,3 +1047,60 @@ mod eh02 { } } } + +mod _embedded_io { + use super::*; + + impl embedded_io_async::Error for Error { + fn kind(&self) -> embedded_io_async::ErrorKind { + match *self { + Error::BufferTooLong => embedded_io_async::ErrorKind::InvalidInput, + Error::BufferNotInRAM => embedded_io_async::ErrorKind::Unsupported, + Error::Framing => embedded_io_async::ErrorKind::InvalidData, + Error::Parity => embedded_io_async::ErrorKind::InvalidData, + Error::Overrun => embedded_io_async::ErrorKind::OutOfMemory, + Error::Break => embedded_io_async::ErrorKind::ConnectionAborted, + } + } + } + + impl<'d, U: Instance> embedded_io_async::ErrorType for Uarte<'d, U> { + type Error = Error; + } + + impl<'d, U: Instance> embedded_io_async::ErrorType for UarteRx<'d, U> { + type Error = Error; + } + + impl<'d, U: Instance> embedded_io_async::ErrorType for UarteTx<'d, U> { + type Error = Error; + } + + impl<'d, U: Instance> embedded_io_async::Read for Uarte<'d, U> { + async fn read(&mut self, buf: &mut [u8]) -> Result { + self.read(buf).await?; + Ok(buf.len()) + } + } + + impl<'d: 'd, U: Instance> embedded_io_async::Read for UarteRx<'d, U> { + async fn read(&mut self, buf: &mut [u8]) -> Result { + self.read(buf).await?; + Ok(buf.len()) + } + } + + impl<'d, U: Instance> embedded_io_async::Write for Uarte<'d, U> { + async fn write(&mut self, buf: &[u8]) -> Result { + self.write(buf).await?; + Ok(buf.len()) + } + } + + impl<'d: 'd, U: Instance> embedded_io_async::Write for UarteTx<'d, U> { + async fn write(&mut self, buf: &[u8]) -> Result { + self.write(buf).await?; + Ok(buf.len()) + } + } +} From f5ead85377ab78d8f463df4f1e358770ff3eca5b Mon Sep 17 00:00:00 2001 From: Alexander Walter Date: Sat, 14 Dec 2024 15:41:31 +0100 Subject: [PATCH 2/2] Just impl Write --- embassy-nrf/src/uarte.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 378325749d..ebb4dd9418 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -1068,28 +1068,10 @@ mod _embedded_io { type Error = Error; } - impl<'d, U: Instance> embedded_io_async::ErrorType for UarteRx<'d, U> { - type Error = Error; - } - impl<'d, U: Instance> embedded_io_async::ErrorType for UarteTx<'d, U> { type Error = Error; } - impl<'d, U: Instance> embedded_io_async::Read for Uarte<'d, U> { - async fn read(&mut self, buf: &mut [u8]) -> Result { - self.read(buf).await?; - Ok(buf.len()) - } - } - - impl<'d: 'd, U: Instance> embedded_io_async::Read for UarteRx<'d, U> { - async fn read(&mut self, buf: &mut [u8]) -> Result { - self.read(buf).await?; - Ok(buf.len()) - } - } - impl<'d, U: Instance> embedded_io_async::Write for Uarte<'d, U> { async fn write(&mut self, buf: &[u8]) -> Result { self.write(buf).await?;