Skip to content

Commit 9987e74

Browse files
committed
feat(stm32): Add DAC::new_unbuffered method.
Signed-off-by: Ivan Li <[email protected]>
1 parent ca5ebe8 commit 9987e74

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

embassy-stm32/src/dac/mod.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,46 @@ impl<'d, T: Instance> Dac<'d, T, Async> {
403403
Mode::NormalExternalBuffered,
404404
)
405405
}
406+
/// Create a new `Dac` instance with external output pins and unbuffered mode.
407+
///
408+
/// This function consumes the underlying DAC peripheral and allows access to both channels.
409+
/// The channels are configured for external output with the buffer disabled.
410+
///
411+
/// The channels are enabled on creation and begin to drive their output pins.
412+
/// Note that some methods, such as `set_trigger()` and `set_mode()`, will
413+
/// disable the channel; you must re-enable them with `enable()`.
414+
///
415+
/// By default, triggering is disabled, but it can be enabled using the `set_trigger()`
416+
/// method on the underlying channels.
417+
///
418+
/// # Arguments
419+
///
420+
/// * `peri` - The DAC peripheral instance.
421+
/// * `dma_ch1` - The DMA channel for DAC channel 1.
422+
/// * `dma_ch2` - The DMA channel for DAC channel 2.
423+
/// * `pin_ch1` - The GPIO pin for DAC channel 1 output.
424+
/// * `pin_ch2` - The GPIO pin for DAC channel 2 output.
425+
///
426+
/// # Returns
427+
///
428+
/// A new `Dac` instance in unbuffered mode.
429+
pub fn new_unbuffered(
430+
peri: Peri<'d, T>,
431+
dma_ch1: Peri<'d, impl Dma<T, Ch1>>,
432+
dma_ch2: Peri<'d, impl Dma<T, Ch2>>,
433+
pin_ch1: Peri<'d, impl DacPin<T, Ch1> + crate::gpio::Pin>,
434+
pin_ch2: Peri<'d, impl DacPin<T, Ch2> + crate::gpio::Pin>,
435+
) -> Self {
436+
pin_ch1.set_as_analog();
437+
pin_ch2.set_as_analog();
438+
Self::new_inner(
439+
peri,
440+
new_dma!(dma_ch1),
441+
new_dma!(dma_ch2),
442+
#[cfg(any(dac_v3, dac_v4, dac_v5, dac_v6, dac_v7))]
443+
Mode::NormalExternalUnbuffered,
444+
)
445+
}
406446

407447
/// Create a new `Dac` instance where the external output pins are not used,
408448
/// so the DAC can only be used to generate internal signals but the GPIO

0 commit comments

Comments
 (0)