use crate::{Config, ConfigError, RxSample, SerialEventSet, SerialIrqEvent};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct UartInfo {
pub name: &'static str,
pub register_base: usize,
pub initial_baudrate: u32,
}
pub struct UartParts<P, I> {
pub port: P,
pub irq: I,
}
impl<P, I> UartParts<P, I> {
pub const fn new(port: P, irq: I) -> Self {
Self { port, irq }
}
}
pub trait SplitUart: Sized {
type Port: UartPort;
type Irq: UartIrq;
fn runtime_info(&self) -> UartInfo;
fn split(self) -> UartParts<Self::Port, Self::Irq>;
}
pub trait UartPort: Send + 'static {
fn startup(&mut self, config: &Config) -> Result<(), ConfigError>;
fn shutdown(&mut self);
fn set_config(&mut self, config: &Config) -> Result<(), ConfigError>;
fn read_rx(&mut self) -> Option<RxSample>;
fn write_tx(&mut self, bytes: &[u8]) -> usize;
fn tx_idle(&mut self) -> bool;
fn mask_all(&mut self);
fn rearm(&mut self, sources: SerialEventSet) -> SerialEventSet;
}
pub trait IrqRxSink {
fn push(&mut self, sample: RxSample);
}
pub trait UartIrq: Send + 'static {
fn handle(&mut self, rx: &mut dyn IrqRxSink) -> Option<SerialIrqEvent>;
}