embassy_stm32_plus/builder/uart/uart4/
mod.rs1use 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
14pub struct Uart4Builder {
16 pub base: UartBase<UART4>,
18 pub tx: PC10,
20 pub rx: PC11,
22}
23
24impl Uart4Builder {
26 #[inline]
28 pub fn new(uart: UART4, tx: PC10, rx: PC11) -> Self {
29 Self { base: UartBase::new(uart), tx, rx }
30 }
31
32 #[inline]
34 pub fn config(mut self, config: Config) -> Self {
35 self.base.set_config(config);
36 self
37 }
38
39 #[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}