feat(stm32): Let uart implement embedded-io Read/Write

This commit is contained in:
Rasmus Melchior Jacobsen 2023-01-04 12:57:19 +01:00
parent bf4c0de16a
commit 5aa59e9737

View file

@ -910,6 +910,46 @@ mod eh1 {
}
}
#[cfg(all(feature = "unstable-traits", feature = "nightly"))]
mod eio {
use embedded_io::asynch::{Read, Write};
use embedded_io::Io;
use super::*;
impl<T, TxDma, RxDma> Io for Uart<'_, T, TxDma, RxDma>
where
T: BasicInstance,
{
type Error = Error;
}
impl<T, TxDma, RxDma> Read for Uart<'_, T, TxDma, RxDma>
where
T: BasicInstance,
RxDma: super::RxDma<T>,
{
async fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
self.read_until_idle(buf).await
}
}
impl<T, TxDma, RxDma> Write for Uart<'_, T, TxDma, RxDma>
where
T: BasicInstance,
TxDma: super::TxDma<T>,
{
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
self.write(buf).await?;
Ok(buf.len())
}
async fn flush(&mut self) -> Result<(), Self::Error> {
self.blocking_flush()
}
}
}
#[cfg(all(
feature = "unstable-traits",
feature = "nightly",