pub struct DacChannel<'d, T: Instance, const N: u8, DMA: PeripheralType = NoDma> { /* private fields */ }Expand description
Driver for a single DAC channel.
If you want to use both channels, either together or independently,
create a Dac first and use it to access each channel.
Implementations§
Source§impl<'d, T: Instance, const N: u8, DMA: PeripheralType> DacChannel<'d, T, N, DMA>
impl<'d, T: Instance, const N: u8, DMA: PeripheralType> DacChannel<'d, T, N, DMA>
Sourcepub fn new(
_peri: Peri<'d, T>,
dma: Peri<'d, DMA>,
pin: Peri<'d, impl DacPin<T, N> + Pin>,
) -> Self
pub fn new( _peri: Peri<'d, T>, dma: Peri<'d, DMA>, pin: Peri<'d, impl DacPin<T, N> + Pin>, ) -> Self
Create a new DacChannel instance, consuming the underlying DAC peripheral.
If you’re not using DMA, pass [dma::NoDma] for the dma argument.
The channel is enabled on creation and begin to drive the output pin.
Note that methods such as set_trigger() will
disable the channel; you must re-enable it with enable().
By default, triggering is disabled, but it can be enabled using
DacChannel::set_trigger().
Sourcepub fn set_enable(&mut self, on: bool)
pub fn set_enable(&mut self, on: bool)
Enable or disable this channel.
Sourcepub fn set_buffering(&mut self, enabled: bool)
pub fn set_buffering(&mut self, enabled: bool)
Enable the output buffer, or bypass it for a high-impedance load.
Sourcepub fn set_waveform(
&mut self,
waveform: Waveform,
amplitude: u8,
) -> Result<(), Error>
pub fn set_waveform( &mut self, waveform: Waveform, amplitude: u8, ) -> Result<(), Error>
Select noise or triangle generation and its mask/amplitude encoding.
Sourcepub fn set_trigger(&mut self, source: TriggerSel)
pub fn set_trigger(&mut self, source: TriggerSel)
Set the trigger source for this channel.
This method disables the channel, so you may need to re-enable afterwards.
Sourcepub fn set_triggering(&mut self, on: bool)
pub fn set_triggering(&mut self, on: bool)
Enable or disable triggering for this channel.
Source§impl<'d, T: Instance, DMA> DacChannel<'d, T, 1, DMA>where
DMA: DacDma1<T> + PeripheralType,
impl<'d, T: Instance, DMA> DacChannel<'d, T, 1, DMA>where
DMA: DacDma1<T> + PeripheralType,
Sourcepub async fn write(&mut self, data: ValueArray<'_>, circular: bool)
pub async fn write(&mut self, data: ValueArray<'_>, circular: bool)
Write data to this channel via DMA.
To prevent delays or glitches when outputing a periodic waveform, the circular
flag can be set. This configures a circular DMA transfer that continually outputs
data. Note that for performance reasons in circular mode the transfer-complete
interrupt is disabled.
Sourcepub async fn try_write(
&mut self,
data: ValueArray<'_>,
circular: bool,
) -> Result<(), Error>
pub async fn try_write( &mut self, data: ValueArray<'_>, circular: bool, ) -> Result<(), Error>
DMA output, stopping the channel on cancellation.
Requires triggering enabled with a timer or EXTI source. Circular transfers run until cancelled. Empty buffers leave the DAC unchanged. Completion means all samples reached the holding register; the last sample may need another trigger to reach the output. The channel stays enabled on completion, with its DMA request disabled.
Source§impl<'d, T: Instance, DMA> DacChannel<'d, T, 2, DMA>where
DMA: DacDma2<T> + PeripheralType,
impl<'d, T: Instance, DMA> DacChannel<'d, T, 2, DMA>where
DMA: DacDma2<T> + PeripheralType,
Sourcepub async fn write(&mut self, data: ValueArray<'_>, circular: bool)
pub async fn write(&mut self, data: ValueArray<'_>, circular: bool)
Write data to this channel via DMA.
To prevent delays or glitches when outputing a periodic waveform, the circular
flag can be set. This configures a circular DMA transfer that continually outputs
data. Note that for performance reasons in circular mode the transfer-complete
interrupt is disabled.
Sourcepub async fn try_write(
&mut self,
data: ValueArray<'_>,
circular: bool,
) -> Result<(), Error>
pub async fn try_write( &mut self, data: ValueArray<'_>, circular: bool, ) -> Result<(), Error>
DMA output, stopping the channel on cancellation.
Requires triggering enabled with a timer or EXTI source. Circular transfers run until cancelled. Empty buffers leave the DAC unchanged. Completion means all samples reached the holding register; the last sample may need another trigger to reach the output. The channel stays enabled on completion, with its DMA request disabled.