bl602-hal
bl602-hal copied to clipboard
Implement PWM
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
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.
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...