Skip to content

Commit

Permalink
Add trait embedded_io_async to uarte
Browse files Browse the repository at this point in the history
  • Loading branch information
wackazong committed Dec 13, 2024
1 parent 45d9bd5 commit be1ed10
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions embassy-nrf/src/uarte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize, Self::Error> {
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<usize, Self::Error> {
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<usize, Self::Error> {
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<usize, Self::Error> {
self.write(buf).await?;
Ok(buf.len())
}
}
}

0 comments on commit be1ed10

Please sign in to comment.