embassy_stm32_plus/builder/dac/
mod.rs1use 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
9pub struct DacBuilder {
11 pub dac: DAC1,
13 pub ch1_pin: PA4,
15 pub ch2_pin: PA5,
17}
18
19impl DacBuilder {
21 #[inline]
23 pub fn new(dac: DAC1, ch1_pin: PA4, ch2_pin: PA5) -> Self {
24 Self { dac, ch1_pin, ch2_pin }
25 }
26
27 #[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 #[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 #[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 #[inline]
48 pub fn build_no_dma(self) -> Dac<'static, DAC1> {
49 Self::build(self, NoDma, NoDma)
50 }
51}