driver_interface/
uart.rs

1use fdt_parser::Node;
2
3use crate::{
4    DriverGeneric, IrqHandleResult,
5    io::{Read, Write},
6};
7
8pub type Hardware = alloc::boxed::Box<dyn Interface>;
9/// The function to probe the hardware.
10/// The first parameter is the ptr of fdt.
11pub type OnProbeFdt = fn(node: Node<'_>) -> Hardware;
12
13pub trait Interface: DriverGeneric + Write + Read + Sync {
14    fn handle_irq(&mut self, irq: usize) -> IrqHandleResult;
15    fn irq_enable(&mut self);
16    fn irq_disable(&mut self);
17    fn set_baudrate(&mut self, baudrate: u64);
18    fn set_databits(&mut self, databits: DataBits);
19    fn set_stopbits(&mut self, stopbits: StopBits);
20    fn set_parity(&mut self, parity: Option<Parity>);
21}
22
23/// Word length.
24#[derive(Clone, Copy, PartialEq, Eq, Debug)]
25pub enum DataBits {
26    Bits5,
27    Bits6,
28    Bits7,
29    Bits8,
30}
31
32/// Parity bit.
33#[derive(Clone, Copy, PartialEq, Eq, Debug)]
34pub enum Parity {
35    Even,
36    Odd,
37}
38
39/// Stop bits.
40#[derive(Clone, Copy, PartialEq, Eq, Debug)]
41pub enum StopBits {
42    #[doc = "1 stop bit"]
43    STOP1,
44    #[doc = "2 stop bits"]
45    STOP2,
46}