embassy_stm32_plus/builder/uart/uart4/
mod.rs

1use embassy_stm32::{bind_interrupts, usart};
2use embassy_stm32::mode::Async;
3use embassy_stm32::peripherals::{DMA2_CH3, DMA2_CH5, PC10, PC11, UART4};
4use embassy_stm32::usart::{Config, ConfigError, Uart};
5use crate::builder::uart::base::UartBase;
6
7pub mod rx;
8pub mod tx;
9
10bind_interrupts!(struct Irqs {
11    UART4 => usart::InterruptHandler<UART4>;
12});
13
14/// uart4 builder
15pub struct Uart4Builder {
16    /// uart4 base device
17    pub base: UartBase<UART4>,
18    /// tx pin
19    pub tx: PC10,
20    /// rx pin
21    pub rx: PC11,
22}
23
24/// custom method
25impl Uart4Builder {
26    /// create builder
27    #[inline]
28    pub fn new(uart: UART4, tx: PC10, rx: PC11) -> Self {
29        Self { base: UartBase::new(uart), tx, rx }
30    }
31
32    /// set uart config
33    #[inline]
34    pub fn config(mut self, config: Config) -> Self {
35        self.base.set_config(config);
36        self
37    }
38
39    /// build a serial port that supports read and write data
40    #[inline]
41    pub fn build(self, tx_dma: DMA2_CH5, rx_dma: DMA2_CH3) -> Result<Uart<'static, Async>, ConfigError> {
42        Uart::new(self.base.uart, self.rx, self.tx, Irqs, tx_dma, rx_dma, self.base.config.unwrap_or_default())
43    }
44}