Skip to main content

Dac

Struct Dac 

Source
pub struct Dac<'d, T: Instance, DMACh1: PeripheralType = NoDma, DMACh2: PeripheralType = NoDma> { /* private fields */ }
Expand description

DAC driver.

Use this struct when you want to use both channels, either together or independently.

§Example

ⓘ
// Pins may need to be changed for your specific device.
let (dac_ch1, dac_ch2) = ch32_hal::dac::Dac::new(p.DAC1, dma_ch1, dma_ch2, p.PA4, p.PA5).split();

Implementations§

Source§

impl<'d, T: Instance, DMACh1: PeripheralType, DMACh2: PeripheralType> Dac<'d, T, DMACh1, DMACh2>

Source

pub fn new( _peri: Peri<'d, T>, dma_ch1: Peri<'d, DMACh1>, dma_ch2: Peri<'d, DMACh2>, pin_ch1: Peri<'d, impl DacPin<T, 1> + Pin>, pin_ch2: Peri<'d, impl DacPin<T, 2> + Pin>, ) -> Self

Create a new Dac instance, consuming the underlying DAC peripheral.

This struct allows you to access both channels of the DAC, where available. You can either call split() to obtain separate DacChannels, or use methods on Dac to use the two channels together.

The channels are enabled on creation and begin to drive their output pins. Note that methods such as set_trigger() will disable the channel; you must re-enable them with enable().

By default, triggering is disabled, but it can be enabled using the set_trigger() method on the underlying channels.

Source

pub fn split(self) -> (DacCh1<'d, T, DMACh1>, DacCh2<'d, T, DMACh2>)

Split this Dac into separate channels.

You can access and move the channels around separately after splitting.

Source

pub fn ch1(&mut self) -> &mut DacCh1<'d, T, DMACh1>

Temporarily access channel 1.

Source

pub fn ch2(&mut self) -> &mut DacCh2<'d, T, DMACh2>

Temporarily access channel 2.

Source

pub fn trigger(&mut self)

Trigger both channels in the same peripheral write.

Source

pub fn set(&mut self, values: DualValue)

Simultaneously update channels 1 and 2 with a new value.

If triggering is not enabled, the new values are immediately output; otherwise, they will be output after the next trigger.

Auto Trait Implementations§

§

impl<'d, T, DMACh1 = NoDma, DMACh2 = NoDma> !UnwindSafe for Dac<'d, T, DMACh1, DMACh2>

§

impl<'d, T, DMACh1, DMACh2> Freeze for Dac<'d, T, DMACh1, DMACh2>
where DMACh1: Freeze, DMACh2: Freeze,

§

impl<'d, T, DMACh1, DMACh2> RefUnwindSafe for Dac<'d, T, DMACh1, DMACh2>
where DMACh1: RefUnwindSafe, DMACh2: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'d, T, DMACh1, DMACh2> Send for Dac<'d, T, DMACh1, DMACh2>
where DMACh1: Send, DMACh2: Send, T: Send,

§

impl<'d, T, DMACh1, DMACh2> Sync for Dac<'d, T, DMACh1, DMACh2>
where DMACh1: Sync, DMACh2: Sync, T: Sync,

§

impl<'d, T, DMACh1, DMACh2> Unpin for Dac<'d, T, DMACh1, DMACh2>
where DMACh1: Unpin, DMACh2: Unpin,

§

impl<'d, T, DMACh1, DMACh2> UnsafeUnpin for Dac<'d, T, DMACh1, DMACh2>
where DMACh1: UnsafeUnpin, DMACh2: UnsafeUnpin,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.