gd32vf103xx-hal icon indicating copy to clipboard operation
gd32vf103xx-hal copied to clipboard

How to enable DAC ? The `Enable` and `Reset` for `DAC` is implemented but the traits are `pub(crate)`.

Open Tnze opened this issue 6 months ago • 1 comments

It would be great if there is a HAL for DAC. image

Tnze avatar Dec 26 '23 12:12 Tnze

Wrote a working example.

#![no_std]
#![no_main]

use panic_halt as _;

use core::f32::consts::PI;
use longan_nano::hal::{delay::McycleDelay, pac, prelude::*};
use riscv_rt::entry;

#[entry]
fn main() -> ! {
    let dp = pac::Peripherals::take().unwrap();
    dp.RCU.apb1rst.modify(|_, w| w.dacrst().set_bit());
    dp.RCU.apb1rst.modify(|_, w| w.dacrst().clear_bit());
    dp.RCU.apb1en.modify(|_, w| w.dacen().set_bit());
    let mut rcu = dp.RCU.configure().freeze();

    let dac = &dp.DAC;

    let gpioa = dp.GPIOA.split(&mut rcu);
    let mut pa4 = gpioa.pa4.into_analog();
    dac.ctl.write(|w| w.den0().set_bit().dten0().clear_bit());

    let mut delay = McycleDelay::new(&rcu.clocks);
    let mut i = 0;
    loop {
        dac.dac0_l12dh.write(|w| unsafe { w.dac0_dh().bits(0xfff) });
        delay.delay_ms(3000);
        dac.dac0_l12dh.write(|w| unsafe { w.dac0_dh().bits(0x000) });
        delay.delay_ms(3000);
    }
}

Tnze avatar Dec 26 '23 15:12 Tnze