embassy/embassy-traits/src/uart.rs

36 lines
935 B
Rust
Raw Normal View History

2021-01-02 19:59:37 +01:00
use core::future::Future;
2021-03-22 01:15:44 +01:00
use core::pin::Pin;
2021-01-02 19:59:37 +01:00
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Error {
Other,
}
2021-03-22 01:15:44 +01:00
pub trait Read {
type ReadFuture<'a>: Future<Output = Result<(), Error>>
where
Self: 'a;
2021-04-14 16:01:43 +02:00
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a>;
2021-01-02 19:59:37 +01:00
}
2021-03-24 03:04:18 +01:00
2021-03-22 01:15:44 +01:00
pub trait ReadUntilIdle {
type ReadUntilIdleFuture<'a>: Future<Output = Result<usize, Error>>
where
Self: 'a;
2021-03-24 03:04:18 +01:00
/// Receive into the buffer until the buffer is full or the line is idle after some bytes are received
/// Return the number of bytes received
2021-04-14 16:01:43 +02:00
fn read_until_idle<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadUntilIdleFuture<'a>;
2021-03-22 01:15:44 +01:00
}
pub trait Write {
type WriteFuture<'a>: Future<Output = Result<(), Error>>
where
Self: 'a;
2021-04-14 16:01:43 +02:00
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a>;
2021-03-24 03:04:18 +01:00
}