Added so stopped PIO state machines can change their clock divider

This commit is contained in:
Emil Fresk 2022-02-26 10:30:28 +01:00 committed by 9names
parent 212ffec6ca
commit b7e56d0869
2 changed files with 17 additions and 1 deletions

View file

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- None
- Stopped PIO state machines can change their clock divider
### Changed

View file

@ -559,6 +559,22 @@ impl<SM: ValidStateMachine> StateMachine<SM, Stopped> {
}
}
/// Change the clock divider of a stopped state machine.
pub fn set_clock_divisor(&mut self, divisor: f32) {
// sm frequency = clock freq / (CLKDIV_INT + CLKDIV_FRAC / 256)
let int = divisor as u16;
let frac = ((divisor - int as f32) * 256.0) as u8;
self.sm.sm().sm_clkdiv.write(|w| {
unsafe {
w.int().bits(int);
w.frac().bits(frac);
}
w
});
}
/// Sets the pin state for the specified pins.
///
/// The user has to make sure that they do not select any pins that are in use by any