sipeed / bl602-hal

Hardware Abstract Layer for BL602 RISC-V WiFi + BLE SoC in embedded Rust
Other
74 stars 14 forks source link

Implement PWM #39

Open CobaltCause opened 2 years ago

CobaltCause commented 2 years ago
tpimh commented 1 year ago

Trying to use it now using the adapted example code:

#![no_std]
#![no_main]

use bl602_hal::{pwm, prelude::_bl602_hal_gpio_GlbExt};
use embedded_time::duration::Milliseconds;

#[riscv_rt::entry]
fn main() -> ! {
    let dp = bl602_hal::pac::Peripherals::take().unwrap();
    let clocks = bl602_hal::clock::Clocks::new();
    let mut parts = dp.GLB.split();
    let mut channels = pwm::Channels::from((dp.PWM, clocks));

    pwm.channel2.enable(&()).unwrap();
    pwm.channel2.set_period(Milliseconds::new(20)).unwrap();
    let duty = 5 * (pwm.channel2.get_max_duty().unwrap() / 100);
    pwm.channel2.set_duty(duty).unwrap();

    parts.pin17.into_pull_down_pwm();

    loop { }
}

And I get E0423: expected value, found module pwm.

CobaltCause commented 1 year ago

IIRC I stopped working this and then forgot about it because I encountered a bug somewhere wherein the observed PWM was half or double (can't remember) the specified PWM and couldn't figure out why this was happening. Tbh, not sure if I'll pick it back up, though it would be nice to finish this...