2021-05-06 03:59:16 +02:00
|
|
|
#![macro_use]
|
|
|
|
|
2021-05-15 03:52:58 +02:00
|
|
|
#[cfg_attr(feature = "_usart_v1", path = "usart_v1.rs")]
|
|
|
|
#[cfg_attr(feature = "_usart_v2", path = "usart_v2.rs")]
|
|
|
|
mod usart;
|
2021-04-25 22:35:51 +02:00
|
|
|
|
2021-05-15 03:52:58 +02:00
|
|
|
pub use usart::*;
|
2021-04-14 15:34:58 +02:00
|
|
|
|
2021-05-15 03:52:58 +02:00
|
|
|
use crate::gpio::Pin;
|
|
|
|
use crate::pac::usart::Usart;
|
2021-04-14 15:34:58 +02:00
|
|
|
|
2021-05-15 03:52:58 +02:00
|
|
|
/// Serial error
|
|
|
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
2021-04-14 15:34:58 +02:00
|
|
|
#[non_exhaustive]
|
2021-05-15 03:52:58 +02:00
|
|
|
pub enum Error {
|
|
|
|
/// Framing error
|
|
|
|
Framing,
|
|
|
|
/// Noise error
|
|
|
|
Noise,
|
|
|
|
/// RX buffer overrun
|
|
|
|
Overrun,
|
|
|
|
/// Parity check error
|
|
|
|
Parity,
|
2021-04-14 15:34:58 +02:00
|
|
|
}
|
|
|
|
|
2021-04-25 22:35:51 +02:00
|
|
|
pub(crate) mod sealed {
|
|
|
|
use super::*;
|
2021-05-15 03:52:58 +02:00
|
|
|
|
2021-04-25 22:35:51 +02:00
|
|
|
pub trait Instance {
|
|
|
|
fn regs(&self) -> Usart;
|
|
|
|
}
|
2021-05-15 03:07:37 +02:00
|
|
|
pub trait RxPin<T: Instance>: Pin {
|
|
|
|
fn af_num(&self) -> u8;
|
2021-04-25 22:35:51 +02:00
|
|
|
}
|
2021-05-15 03:07:37 +02:00
|
|
|
pub trait TxPin<T: Instance>: Pin {
|
|
|
|
fn af_num(&self) -> u8;
|
2021-04-25 22:35:51 +02:00
|
|
|
}
|
2021-05-15 03:07:37 +02:00
|
|
|
pub trait CtsPin<T: Instance>: Pin {
|
|
|
|
fn af_num(&self) -> u8;
|
2021-04-25 22:35:51 +02:00
|
|
|
}
|
2021-05-15 03:07:37 +02:00
|
|
|
pub trait RtsPin<T: Instance>: Pin {
|
|
|
|
fn af_num(&self) -> u8;
|
2021-04-25 22:35:51 +02:00
|
|
|
}
|
2021-05-15 03:07:37 +02:00
|
|
|
pub trait CkPin<T: Instance>: Pin {
|
|
|
|
fn af_num(&self) -> u8;
|
2021-04-25 22:35:51 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-14 15:34:58 +02:00
|
|
|
pub trait Instance: sealed::Instance {}
|
2021-04-25 22:35:51 +02:00
|
|
|
pub trait RxPin<T: Instance>: sealed::RxPin<T> {}
|
|
|
|
pub trait TxPin<T: Instance>: sealed::TxPin<T> {}
|
|
|
|
pub trait CtsPin<T: Instance>: sealed::CtsPin<T> {}
|
|
|
|
pub trait RtsPin<T: Instance>: sealed::RtsPin<T> {}
|
|
|
|
pub trait CkPin<T: Instance>: sealed::CkPin<T> {}
|
|
|
|
|
|
|
|
macro_rules! impl_usart {
|
2021-05-06 03:43:46 +02:00
|
|
|
($inst:ident) => {
|
2021-04-25 22:35:51 +02:00
|
|
|
impl crate::usart::sealed::Instance for peripherals::$inst {
|
2021-05-06 03:43:46 +02:00
|
|
|
fn regs(&self) -> crate::pac::usart::Usart {
|
|
|
|
crate::pac::$inst
|
2021-04-14 15:34:58 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-25 22:35:51 +02:00
|
|
|
impl crate::usart::Instance for peripherals::$inst {}
|
2021-04-14 15:34:58 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-04-25 22:35:51 +02:00
|
|
|
macro_rules! impl_usart_pin {
|
2021-05-15 03:07:37 +02:00
|
|
|
($inst:ident, $func:ident, $pin:ident, $af:expr) => {
|
2021-04-25 22:35:51 +02:00
|
|
|
impl crate::usart::sealed::$func<peripherals::$inst> for peripherals::$pin {
|
2021-05-15 03:07:37 +02:00
|
|
|
fn af_num(&self) -> u8 {
|
|
|
|
$af
|
|
|
|
}
|
2021-04-25 22:35:51 +02:00
|
|
|
}
|
|
|
|
impl crate::usart::$func<peripherals::$inst> for peripherals::$pin {}
|
|
|
|
};
|
|
|
|
}
|