Merge pull request #1898 from MathiasKoch/embassy-stm32/uart-blocking-embedded-io

feature(embassy-stm32): implement blocking embedded-io::Write for Uart & UartTx
This commit is contained in:
Dario Nieuwenhuis 2023-09-14 12:33:51 +00:00 committed by GitHub
commit f090a38dde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 24 deletions

View File

@ -410,12 +410,6 @@ impl<'d, T: BasicInstance> Drop for BufferedUartTx<'d, T> {
} }
} }
impl embedded_io_async::Error for Error {
fn kind(&self) -> embedded_io_async::ErrorKind {
embedded_io_async::ErrorKind::Other
}
}
impl<'d, T: BasicInstance> embedded_io_async::ErrorType for BufferedUart<'d, T> { impl<'d, T: BasicInstance> embedded_io_async::ErrorType for BufferedUart<'d, T> {
type Error = Error; type Error = Error;
} }

View File

@ -1037,20 +1037,61 @@ mod eh1 {
} }
} }
#[cfg(all(feature = "unstable-traits", feature = "nightly"))] impl embedded_io::Error for Error {
mod eio { fn kind(&self) -> embedded_io::ErrorKind {
use embedded_io_async::{ErrorType, Write}; embedded_io::ErrorKind::Other
}
}
use super::*; impl<T, TxDma, RxDma> embedded_io::ErrorType for Uart<'_, T, TxDma, RxDma>
impl<T, TxDma, RxDma> ErrorType for Uart<'_, T, TxDma, RxDma>
where where
T: BasicInstance, T: BasicInstance,
{ {
type Error = Error; type Error = Error;
} }
impl<T, TxDma, RxDma> Write for Uart<'_, T, TxDma, RxDma> impl<T, TxDma> embedded_io::ErrorType for UartTx<'_, T, TxDma>
where
T: BasicInstance,
{
type Error = Error;
}
impl<T, TxDma, RxDma> embedded_io::Write for Uart<'_, T, TxDma, RxDma>
where
T: BasicInstance,
TxDma: crate::usart::TxDma<T>,
{
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.blocking_write(buf)?;
Ok(buf.len())
}
fn flush(&mut self) -> Result<(), Self::Error> {
self.blocking_flush()
}
}
impl<T, TxDma> embedded_io::Write for UartTx<'_, T, TxDma>
where
T: BasicInstance,
TxDma: crate::usart::TxDma<T>,
{
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.blocking_write(buf)?;
Ok(buf.len())
}
fn flush(&mut self) -> Result<(), Self::Error> {
self.blocking_flush()
}
}
#[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eio {
use super::*;
impl<T, TxDma, RxDma> embedded_io_async::Write for Uart<'_, T, TxDma, RxDma>
where where
T: BasicInstance, T: BasicInstance,
TxDma: super::TxDma<T>, TxDma: super::TxDma<T>,
@ -1065,14 +1106,7 @@ mod eio {
} }
} }
impl<T, TxDma> ErrorType for UartTx<'_, T, TxDma> impl<T, TxDma> embedded_io_async::Write for UartTx<'_, T, TxDma>
where
T: BasicInstance,
{
type Error = Error;
}
impl<T, TxDma> Write for UartTx<'_, T, TxDma>
where where
T: BasicInstance, T: BasicInstance,
TxDma: super::TxDma<T>, TxDma: super::TxDma<T>,