Skip to content

Commit

Permalink
Add function to enable multiple PWM slices at the same time
Browse files Browse the repository at this point in the history
This is needed to be able to have e.g. 3 PWM slices that are in phase,
but may use different duty cycles.

Example usage: `pwm_slices.enable_simultaneous(0b0000_0111);`
  • Loading branch information
jlpettersson committed Aug 8, 2023
1 parent 29d57af commit a7f51b7
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions rp2040-hal/src/pwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,17 +501,16 @@ impl Slices {
self._pwm
}

// /// Enable multiple slices at the same time to make their counters sync up.
// ///
// /// You still need to call `slice` to get an actual slice
// pub fn enable_simultaneous<S: SliceId>(&mut self, bits: u8) {
// // Enable all slices at the same time
// unsafe {
// &(*pac::PWM::ptr())
// .en
// .modify(|r, w| w.bits(((r.bits() as u8) | bits) as u32));
// }
// }
/// Enable multiple slices at the same time to make their counters sync up.
///
/// You still need to call `slice` to get an actual slice
pub fn enable_simultaneous(&mut self, bits: u8) {
// Enable multiple slices at the same time
unsafe {
let reg = self._pwm.en.as_ptr();
write_bitmask_set(reg, bits as u32);
}
}

// /// Get pwm slice based on gpio pin
// pub fn borrow_mut_from_pin<
Expand Down

0 comments on commit a7f51b7

Please sign in to comment.