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

Implement PWM

Open CobaltCause opened this issue 4 years ago • 2 comments
trafficstars

  • [X] Initial attempt
  • [X] A silly/clever workaround for embedded-hal's Pwm trait not mapping super well to the BL602
  • [X] Cleanup/actual usable MVP (minus Pwm::get_period)
  • [ ] Extra functions for messing with BL602 specific things

CobaltCause avatar Nov 14 '21 07:11 CobaltCause

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.

tpimh avatar Jul 18 '23 13:07 tpimh

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...

CobaltCause avatar Jul 21 '23 19:07 CobaltCause