feat(stm32): Let uart implement embedded-io Read/Write
This commit is contained in:
parent
bf4c0de16a
commit
5aa59e9737
1 changed files with 40 additions and 0 deletions
|
@ -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(
|
#[cfg(all(
|
||||||
feature = "unstable-traits",
|
feature = "unstable-traits",
|
||||||
feature = "nightly",
|
feature = "nightly",
|
||||||
|
|
Loading…
Reference in a new issue