use bitfield_struct::bitfield;
use inspect::Inspect;
use open_enum::open_enum;
pub const FIFO_SIZE: usize = 16;
open_enum! {
pub enum Register: u8 {
RHR = 0, THR = 0, DLL = 0, IER = 1, DLM = 1, ISR = 2, FCR = 2, LCR = 3, MCR = 4, LSR = 5, RST = 5, MSR = 6, SPR = 7, }
}
#[derive(Inspect)]
#[bitfield(u8)]
pub struct InterruptEnableRegister {
pub received_data_avail: bool,
pub thr_empty: bool,
pub receiver_line_status: bool,
pub modem_status: bool,
#[bits(4)]
pub reserved: u8,
}
#[derive(Inspect)]
#[bitfield(u8)]
pub struct InterruptIdentificationRegister {
pub no_interrupt_pending: bool,
#[bits(3)]
pub source: u8,
#[bits(2)]
pub reserved: u8,
#[bits(2)]
pub fifo_state: u8,
}
open_enum! {
pub enum InterruptSource: u8 {
MODEM_STATUS = 0,
THR_EMPTY = 1,
RECEIVED_DATA_AVAIL = 2,
RECEIVER_LINE_STATUS = 3,
RECEIVE_TIMEOUT = 6,
}
}
open_enum! {
pub enum FifoState: u8 {
DISABLED = 0,
ENABLED = 3,
}
}
#[derive(Inspect)]
#[bitfield(u8)]
pub struct FifoControlRegister {
pub enable_fifos: bool,
pub clear_rx_fifo: bool,
pub clear_tx_fifo: bool,
#[bits(1)]
pub dma_mode: u8,
#[bits(2)]
pub reserved: u8,
#[bits(2)]
pub rx_fifo_int_trigger: u8,
}
open_enum! {
pub enum RxFifoInterruptTrigger: u8 {
BYTES_1 = 0,
BYTES_4 = 1,
BYTES_8 = 2,
BYTES_14 = 3,
}
}
#[derive(Inspect)]
#[bitfield(u8)]
pub struct LineControlRegister {
#[bits(2)]
pub data_word_length: u8,
#[bits(1)]
pub stop_bits: u8,
#[bits(3)]
pub parity: u8,
pub break_enabled: bool,
pub dlab: bool,
}
#[derive(Inspect)]
#[bitfield(u8)]
pub struct ModemControlRegister {
pub dtr: bool, pub rts: bool, pub out1: bool,
pub out2: bool,
pub loopback: bool,
#[bits(3)]
pub reserved: u8,
}
#[derive(Inspect)]
#[bitfield(u8)]
pub struct LineStatusRegister {
pub rx_ready: bool,
pub overrun_error: bool,
pub parity_error: bool,
pub framing_error: bool,
pub break_signal_received: bool,
pub thr_empty: bool,
pub thr_and_tsr_empty: bool,
pub fifo_data_error: bool,
}
#[derive(Inspect)]
#[bitfield(u8)]
pub struct ModemStatusRegister {
pub cts_change: bool,
pub dsr_change: bool,
pub ri_went_low: bool,
pub dcd_change: bool,
pub cts: bool, pub dsr: bool, pub ri: bool, pub dcd: bool, }