aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src/uarte.rs
diff options
context:
space:
mode:
authorAlexander Walter <[email protected]>2024-12-14 00:57:55 +0100
committerAlexander Walter <[email protected]>2024-12-14 00:57:55 +0100
commitbe1ed104e47e16eca1ec4e403db9ae02da5c9e27 (patch)
treea4098ee5373d1a253e3c2b7a72d81d6a775f849e /embassy-nrf/src/uarte.rs
parent45d9bd57575d9391a68334a2f3966b92032d5dc6 (diff)
Add trait embedded_io_async to uarte
Diffstat (limited to 'embassy-nrf/src/uarte.rs')
-rw-r--r--embassy-nrf/src/uarte.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 2a59d029d..378325749 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -1047,3 +1047,60 @@ mod eh02 {
1047 } 1047 }
1048 } 1048 }
1049} 1049}
1050
1051mod _embedded_io {
1052 use super::*;
1053
1054 impl embedded_io_async::Error for Error {
1055 fn kind(&self) -> embedded_io_async::ErrorKind {
1056 match *self {
1057 Error::BufferTooLong => embedded_io_async::ErrorKind::InvalidInput,
1058 Error::BufferNotInRAM => embedded_io_async::ErrorKind::Unsupported,
1059 Error::Framing => embedded_io_async::ErrorKind::InvalidData,
1060 Error::Parity => embedded_io_async::ErrorKind::InvalidData,
1061 Error::Overrun => embedded_io_async::ErrorKind::OutOfMemory,
1062 Error::Break => embedded_io_async::ErrorKind::ConnectionAborted,
1063 }
1064 }
1065 }
1066
1067 impl<'d, U: Instance> embedded_io_async::ErrorType for Uarte<'d, U> {
1068 type Error = Error;
1069 }
1070
1071 impl<'d, U: Instance> embedded_io_async::ErrorType for UarteRx<'d, U> {
1072 type Error = Error;
1073 }
1074
1075 impl<'d, U: Instance> embedded_io_async::ErrorType for UarteTx<'d, U> {
1076 type Error = Error;
1077 }
1078
1079 impl<'d, U: Instance> embedded_io_async::Read for Uarte<'d, U> {
1080 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
1081 self.read(buf).await?;
1082 Ok(buf.len())
1083 }
1084 }
1085
1086 impl<'d: 'd, U: Instance> embedded_io_async::Read for UarteRx<'d, U> {
1087 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
1088 self.read(buf).await?;
1089 Ok(buf.len())
1090 }
1091 }
1092
1093 impl<'d, U: Instance> embedded_io_async::Write for Uarte<'d, U> {
1094 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
1095 self.write(buf).await?;
1096 Ok(buf.len())
1097 }
1098 }
1099
1100 impl<'d: 'd, U: Instance> embedded_io_async::Write for UarteTx<'d, U> {
1101 async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
1102 self.write(buf).await?;
1103 Ok(buf.len())
1104 }
1105 }
1106}