2021-01-02 18:59:37 +00:00
|
|
|
use core::future::Future;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
|
|
|
#[non_exhaustive]
|
|
|
|
pub enum Error {
|
|
|
|
Other,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait Uart {
|
|
|
|
type ReceiveFuture<'a>: Future<Output = Result<(), Error>>;
|
|
|
|
type SendFuture<'a>: Future<Output = Result<(), Error>>;
|
2021-03-24 02:04:18 +00:00
|
|
|
/// Receive into the buffer until the buffer is full
|
2021-01-02 18:59:37 +00:00
|
|
|
fn receive<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReceiveFuture<'a>;
|
2021-03-24 02:04:18 +00:00
|
|
|
/// Send the specified buffer, and return when the transmission has completed
|
2021-01-02 18:59:37 +00:00
|
|
|
fn send<'a>(&'a mut self, buf: &'a [u8]) -> Self::SendFuture<'a>;
|
|
|
|
}
|
2021-03-24 02:04:18 +00:00
|
|
|
|
|
|
|
pub trait IdleUart {
|
|
|
|
type ReceiveFuture<'a>: Future<Output = Result<usize, Error>>;
|
|
|
|
/// 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
|
|
|
|
fn receive_until_idle<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReceiveFuture<'a>;
|
|
|
|
}
|