embassy_stm32_plus/builder/dac/
mod.rs

1use embassy_stm32::dac::Dac;
2use embassy_stm32::dma::NoDma;
3use embassy_stm32::Peripheral;
4use embassy_stm32::peripherals::{DAC1, PA4, PA5};
5
6pub mod ch1;
7pub mod ch2;
8
9/// dac builder
10pub struct DacBuilder {
11    /// dac device
12    pub dac: DAC1,
13    /// dac ch1 pin
14    pub ch1_pin: PA4,
15    /// dac ch2 pin
16    pub ch2_pin: PA5,
17}
18
19/// custom method
20impl DacBuilder {
21    /// create builder
22    #[inline]
23    pub fn new(dac: DAC1, ch1_pin: PA4, ch2_pin: PA5) -> Self {
24        Self { dac, ch1_pin, ch2_pin }
25    }
26
27    /// Create a new Dac instance, more see [Dac::new]
28    #[inline]
29    pub fn build<DmaCh1, DmaCh2>(self, dma_ch1: impl Peripheral<P=DmaCh1> + 'static, dma_ch2: impl Peripheral<P=DmaCh2> + 'static)
30                                 -> Dac<'static, DAC1, DmaCh1, DmaCh2> {
31        Dac::new(self.dac, dma_ch1, dma_ch2, self.ch1_pin, self.ch2_pin)
32    }
33
34    /// dma_ch2 using NoDma Create a new Dac instance, more see [Dac::new]
35    #[inline]
36    pub fn build_dma_ch1<DmaCh1>(self, dma_ch1: impl Peripheral<P=DmaCh1> + 'static) -> Dac<'static, DAC1, DmaCh1> {
37        Self::build(self, dma_ch1, NoDma)
38    }
39
40    /// dma_ch1 using NoDma Create a new Dac instance, more see [Dac::new]
41    #[inline]
42    pub fn build_dma_ch2<DmaCh2>(self, dma_ch2: impl Peripheral<P=DmaCh2> + 'static) -> Dac<'static, DAC1, NoDma, DmaCh2> {
43        Self::build(self, NoDma, dma_ch2)
44    }
45
46    /// using NoDma Create a new Dac instance, more see [Dac::new]
47    #[inline]
48    pub fn build_no_dma(self) -> Dac<'static, DAC1> {
49        Self::build(self, NoDma, NoDma)
50    }
51}