driver_interface/
uart.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use core::ptr::NonNull;

use alloc::boxed::Box;

use crate::io;

pub trait Driver: super::DriverGeneric + io::Write {}

pub type BoxDriver = Box<dyn Driver>;

/// Word length.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DataBits {
    Bits5,
    Bits6,
    Bits7,
    Bits8,
}

/// Parity bit.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum Parity {
    None,
    Even,
    Odd,
}

/// Stop bits.
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum StopBits {
    #[doc = "1 stop bit"]
    STOP1,
    #[doc = "2 stop bits"]
    STOP2,
}

pub struct Config {
    pub reg: NonNull<u8>,
    pub baud_rate: u32,
    pub clock_freq: u64,
    pub data_bits: DataBits,
    pub stop_bits: StopBits,
    pub parity: Parity,
}