use crate::pac::{uart0::RegisterBlock, UART0, UART1};
use crate::resets::SubsystemReset;
use crate::typelevel::Sealed;
use core::ops::Deref;
use fugit::HertzU32;
use rp2040_pac::dma::ch::ch_ctrl_trig::TREQ_SEL_A;
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
BadArgument,
}
pub trait State: Sealed {}
pub trait UartDevice: Deref<Target = RegisterBlock> + SubsystemReset + Sealed + 'static {
fn tx_dreq() -> u8
where
Self: Sized;
fn rx_dreq() -> u8
where
Self: Sized;
}
impl UartDevice for UART0 {
fn tx_dreq() -> u8 {
TREQ_SEL_A::UART0_TX.into()
}
fn rx_dreq() -> u8 {
TREQ_SEL_A::UART0_RX.into()
}
}
impl Sealed for UART0 {}
impl UartDevice for UART1 {
fn tx_dreq() -> u8 {
TREQ_SEL_A::UART1_TX.into()
}
fn rx_dreq() -> u8 {
TREQ_SEL_A::UART1_RX.into()
}
}
impl Sealed for UART1 {}
pub struct Enabled;
pub struct Disabled;
impl State for Enabled {}
impl Sealed for Enabled {}
impl State for Disabled {}
impl Sealed for Disabled {}
pub enum DataBits {
Five,
Six,
Seven,
Eight,
}
pub enum StopBits {
One,
Two,
}
pub enum Parity {
Odd,
Even,
}
#[non_exhaustive]
pub struct UartConfig {
pub baudrate: HertzU32,
pub data_bits: DataBits,
pub stop_bits: StopBits,
pub parity: Option<Parity>,
}
impl UartConfig {
pub const fn new(
baudrate: HertzU32,
data_bits: DataBits,
parity: Option<Parity>,
stop_bits: StopBits,
) -> UartConfig {
UartConfig {
baudrate,
data_bits,
stop_bits,
parity,
}
}
}
pub enum FifoWatermark {
Bytes4,
Bytes8,
Bytes16,
Bytes24,
Bytes28,
}
impl Default for UartConfig {
fn default() -> Self {
Self {
baudrate: HertzU32::from_raw(115_200),
data_bits: DataBits::Eight,
stop_bits: StopBits::One,
parity: None,
}
}
}