#![macro_use] #[cfg_attr(usart_v1, path = "v1.rs")] #[cfg_attr(usart_v2, path = "v2.rs")] mod _version; use crate::peripherals; pub use _version::*; use crate::gpio::Pin; use crate::pac::usart::Usart; use crate::rcc::RccPeripheral; /// Serial error #[derive(Debug, Eq, PartialEq, Copy, Clone)] #[non_exhaustive] pub enum Error { /// Framing error Framing, /// Noise error Noise, /// RX buffer overrun Overrun, /// Parity check error Parity, } pub(crate) mod sealed { use super::*; use crate::dma::WriteDma; pub trait Instance { fn regs(&self) -> Usart; } pub trait RxPin: Pin { fn af_num(&self) -> u8; } pub trait TxPin: Pin { fn af_num(&self) -> u8; } pub trait CtsPin: Pin { fn af_num(&self) -> u8; } pub trait RtsPin: Pin { fn af_num(&self) -> u8; } pub trait CkPin: Pin { fn af_num(&self) -> u8; } pub trait RxDma {} pub trait TxDma: WriteDma {} } pub trait Instance: sealed::Instance + RccPeripheral {} pub trait RxPin: sealed::RxPin {} pub trait TxPin: sealed::TxPin {} pub trait CtsPin: sealed::CtsPin {} pub trait RtsPin: sealed::RtsPin {} pub trait CkPin: sealed::CkPin {} pub trait RxDma: sealed::RxDma {} pub trait TxDma: sealed::TxDma {} crate::pac::peripherals!( (usart, $inst:ident) => { impl sealed::Instance for peripherals::$inst { fn regs(&self) -> crate::pac::usart::Usart { crate::pac::$inst } } impl Instance for peripherals::$inst {} }; ); macro_rules! impl_pin { ($inst:ident, $pin:ident, $signal:ident, $af:expr) => { impl sealed::$signal for peripherals::$pin { fn af_num(&self) -> u8 { $af } } impl $signal for peripherals::$pin {} }; } crate::pac::peripheral_pins!( ($inst:ident, usart, USART, $pin:ident, TX, $af:expr) => { impl_pin!($inst, $pin, TxPin, $af); }; ($inst:ident, usart, USART, $pin:ident, RX, $af:expr) => { impl_pin!($inst, $pin, RxPin, $af); }; ($inst:ident, usart, USART, $pin:ident, CTS, $af:expr) => { impl_pin!($inst, $pin, CtsPin, $af); }; ($inst:ident, usart, USART, $pin:ident, RTS, $af:expr) => { impl_pin!($inst, $pin, RtsPin, $af); }; ($inst:ident, usart, USART, $pin:ident, CK, $af:expr) => { impl_pin!($inst, $pin, CkPin, $af); }; );