#![no_std]
extern crate alloc;
use alloc::boxed::Box;
pub use futures::future::LocalBoxFuture;
pub use rdif_base::DriverGeneric;
pub trait Sender: Send {
fn write(&mut self, buf: &[u8]) -> Result<usize, SerialError>;
fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> LocalBoxFuture<'a, Result<(), SerialError>>;
}
pub trait Reciever: Send {
fn read(&mut self, buf: &mut [u8]) -> Result<usize, SerialError>;
fn read_all<'a>(&'a mut self, buf: &'a mut [u8]) -> LocalBoxFuture<'a, Result<(), SerialError>>;
}
pub trait Interface: DriverGeneric {
fn handle_irq(&mut self);
fn take_tx(&mut self) -> Option<Box<dyn Sender>>;
fn take_rx(&mut self) -> Option<Box<dyn Reciever>>;
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[non_exhaustive]
pub enum SerialError {
Overrun,
FrameFormat,
Parity,
Noise,
Closed,
Other,
}
impl core::error::Error for SerialError {}
impl core::fmt::Display for SerialError {
#[inline]
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Overrun => write!(f, "The peripheral receive buffer was overrun"),
Self::Parity => write!(f, "Parity check failed"),
Self::Noise => write!(f, "Serial line is too noisy to read valid data"),
Self::FrameFormat => write!(
f,
"Received data does not conform to the peripheral configuration"
),
Self::Closed => write!(f, "Device was closed"),
Self::Other => write!(
f,
"A different error occurred. The original error may contain more information"
),
}
}
}