embassy/embassy-stm32/src/usart/mod.rs

75 lines
1.8 KiB
Rust
Raw Normal View History

#![macro_use]
#[cfg_attr(feature = "_usart_v1", path = "v1.rs")]
#[cfg_attr(feature = "_usart_v2", path = "v2.rs")]
mod _version;
pub use _version::*;
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;
}
pub trait RxPin<T: Instance>: Pin {
fn af_num(&self) -> u8;
2021-04-25 22:35:51 +02:00
}
pub trait TxPin<T: Instance>: Pin {
fn af_num(&self) -> u8;
2021-04-25 22:35:51 +02:00
}
pub trait CtsPin<T: Instance>: Pin {
fn af_num(&self) -> u8;
2021-04-25 22:35:51 +02:00
}
pub trait RtsPin<T: Instance>: Pin {
fn af_num(&self) -> u8;
2021-04-25 22:35:51 +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 {
($inst:ident) => {
2021-04-25 22:35:51 +02:00
impl crate::usart::sealed::Instance for peripherals::$inst {
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 {
($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 {
fn af_num(&self) -> u8 {
$af
}
2021-04-25 22:35:51 +02:00
}
impl crate::usart::$func<peripherals::$inst> for peripherals::$pin {}
};
}