Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tnze opened this issue Dec 26, 2023 · 1 comment

Comments

@Tnze
Copy link

Tnze commented Dec 26, 2023

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

@Tnze
Copy link
Author

Tnze commented Dec 26, 2023

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);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant