embassy_stm32_plus/builder/uart/uart3/
rx.rs1use embassy_stm32::mode::Async;
2use embassy_stm32::Peripheral;
3use embassy_stm32::peripherals::{DMA1_CH3, PB11, PB14, USART3};
4#[cfg(PC11)]
5use embassy_stm32::peripherals::PC11;
6#[cfg(PD12)]
7use embassy_stm32::peripherals::PD12;
8#[cfg(PD9)]
9use embassy_stm32::peripherals::PD9;
10use embassy_stm32::usart::{Config, ConfigError, RxPin, UartRx};
11use crate::builder::uart::base::UartBase;
12use crate::builder::uart::uart3::Irqs;
13
14pub enum Uart3Rx {
16 PB11(PB11),
17 #[cfg(PC11)]
18 PC11(PC11),
19 #[cfg(PD9)]
20 PD9(PD9),
21}
22
23pub enum Uart3Rts {
25 PB14(PB14),
26 #[cfg(PD12)]
27 PD12(PD12),
28}
29
30pub struct Uart3RxBuilder {
32 pub base: UartBase<USART3>,
34 pub rx: Uart3Rx,
36 pub rts: Option<Uart3Rts>,
38}
39
40impl Uart3RxBuilder {
42 #[inline]
44 pub fn new(uart: USART3, rx: Uart3Rx) -> Self {
45 Self { base: UartBase::new(uart), rx, rts: None }
46 }
47
48 #[inline]
50 pub fn config(mut self, config: Config) -> Self {
51 self.base.set_config(config);
52 self
53 }
54
55 #[inline]
57 pub fn rts(mut self, rts: Uart3Rts) -> Self {
58 self.rts = Some(rts);
59 self
60 }
61
62 pub fn build(self, rx_dma: DMA1_CH3) -> Result<UartRx<'static, Async>, ConfigError> {
64 match self.rx {
65 Uart3Rx::PB11(pb11) => { Self::build_rts(pb11, rx_dma, self.base, self.rts) }
66 #[cfg(PC11)]
67 Uart3Rx::PC11(pc11) => { Self::build_rts(pc11, rx_dma, self.base, self.rts) }
68 #[cfg(PD9)]
69 Uart3Rx::PD9(pd9) => { Self::build_rts(pd9, rx_dma, self.base, self.rts) }
70 }
71 }
72
73 fn build_rts(
75 rx: impl Peripheral<P=impl RxPin<USART3>> + 'static,
76 rx_dma: DMA1_CH3,
77 base: UartBase<USART3>,
78 rts: Option<Uart3Rts>)
79 -> Result<UartRx<'static, Async>, ConfigError> {
80 let rts = crate::match_some_return!(rts,
81 UartRx::new(base.uart, Irqs, rx, rx_dma, base.config.unwrap_or_default()));
82
83 match rts {
84 Uart3Rts::PB14(pb14) => { UartRx::new_with_rts(base.uart, Irqs, rx, pb14, rx_dma, base.config.unwrap_or_default()) }
85 #[cfg(PD12)]
86 Uart3Rts::PD12(pd12) => { UartRx::new_with_rts(base.uart, Irqs, rx, pd12, rx_dma, base.config.unwrap_or_default()) }
87 }
88 }
89}