diff options
| author | Rasmus Melchior Jacobsen <[email protected]> | 2023-01-04 12:57:19 +0100 |
|---|---|---|
| committer | Rasmus Melchior Jacobsen <[email protected]> | 2023-01-04 12:57:19 +0100 |
| commit | 5aa59e97372e2efed4e35625b754364b1b4839a3 (patch) | |
| tree | b642035c5333f693f3355d0b14561e869b5d7175 | |
| parent | bf4c0de16a119b9e3a42daf76c4bc60face3c2a1 (diff) | |
feat(stm32): Let uart implement embedded-io Read/Write
| -rw-r--r-- | embassy-stm32/src/usart/mod.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 6f8b6a9e8..233b56baa 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -910,6 +910,46 @@ mod eh1 { | |||
| 910 | } | 910 | } |
| 911 | } | 911 | } |
| 912 | 912 | ||
| 913 | #[cfg(all(feature = "unstable-traits", feature = "nightly"))] | ||
| 914 | mod eio { | ||
| 915 | use embedded_io::asynch::{Read, Write}; | ||
| 916 | use embedded_io::Io; | ||
| 917 | |||
| 918 | use super::*; | ||
| 919 | |||
| 920 | impl<T, TxDma, RxDma> Io for Uart<'_, T, TxDma, RxDma> | ||
| 921 | where | ||
| 922 | T: BasicInstance, | ||
| 923 | { | ||
| 924 | type Error = Error; | ||
| 925 | } | ||
| 926 | |||
| 927 | impl<T, TxDma, RxDma> Read for Uart<'_, T, TxDma, RxDma> | ||
| 928 | where | ||
| 929 | T: BasicInstance, | ||
| 930 | RxDma: super::RxDma<T>, | ||
| 931 | { | ||
| 932 | async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> { | ||
| 933 | self.read_until_idle(buf).await | ||
| 934 | } | ||
| 935 | } | ||
| 936 | |||
| 937 | impl<T, TxDma, RxDma> Write for Uart<'_, T, TxDma, RxDma> | ||
| 938 | where | ||
| 939 | T: BasicInstance, | ||
| 940 | TxDma: super::TxDma<T>, | ||
| 941 | { | ||
| 942 | async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> { | ||
| 943 | self.write(buf).await?; | ||
| 944 | Ok(buf.len()) | ||
| 945 | } | ||
| 946 | |||
| 947 | async fn flush(&mut self) -> Result<(), Self::Error> { | ||
| 948 | self.blocking_flush() | ||
| 949 | } | ||
| 950 | } | ||
| 951 | } | ||
| 952 | |||
| 913 | #[cfg(all( | 953 | #[cfg(all( |
| 914 | feature = "unstable-traits", | 954 | feature = "unstable-traits", |
| 915 | feature = "nightly", | 955 | feature = "nightly", |
