tweak period calculation in song pwm code
This commit is contained in:
parent
ca5867ba36
commit
5b6e35189a
1 changed files with 6 additions and 15 deletions
21
src/main.rs
21
src/main.rs
|
@ -99,19 +99,6 @@ async fn heartbeat(mut control: Control<'static>) {
|
|||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
// let p = embassy_rp::init(Default::default());
|
||||
// let mut led = Output::new(p.PIN_18, Level::Low);
|
||||
|
||||
// loop {
|
||||
// info!("led on!");
|
||||
// led.set_high();
|
||||
// Timer::after_secs(1).await;
|
||||
|
||||
// info!("led off!");
|
||||
// led.set_low();
|
||||
// Timer::after_secs(1).await;
|
||||
// }
|
||||
|
||||
let mut p = embassy_rp::init(embassy_rp::config::Config::default());
|
||||
let fw = include_bytes!("../embassy/cyw43-firmware/43439A0.bin");
|
||||
let clm = include_bytes!("../embassy/cyw43-firmware/43439A0_clm.bin");
|
||||
|
@ -214,7 +201,7 @@ async fn play_music(slice: &mut PWM_SLICE2, pin: &mut PIN_20) {
|
|||
F4 = 349,
|
||||
G4 = 392,
|
||||
A5 = 440,
|
||||
#[allow(dead_code)]
|
||||
#[expect(dead_code)]
|
||||
B5 = 494,
|
||||
C5 = 524,
|
||||
}
|
||||
|
@ -282,7 +269,11 @@ async fn play_music(slice: &mut PWM_SLICE2, pin: &mut PIN_20) {
|
|||
let clock_freq_hz = embassy_rp::clocks::clk_sys_freq();
|
||||
let divider = 16;
|
||||
#[expect(clippy::cast_possible_truncation)]
|
||||
let period = clock_freq_hz.saturating_div(note as u32 * u32::from(divider)) as u16 - 1;
|
||||
let period = clock_freq_hz
|
||||
.checked_div(note as u32 * u32::from(divider))
|
||||
.unwrap_or_default()
|
||||
.checked_sub(1)
|
||||
.unwrap_or(1) as u16;
|
||||
|
||||
let mut c = pwm::Config::default();
|
||||
c.top = period;
|
||||
|
|
Loading…
Reference in a new issue