mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2025-01-10 04:21:32 +11:00
Merge pull request #494 from jannic/pio-change-clkdiv
Allow setting clock divisors on running state machines
This commit is contained in:
commit
4b2b33b950
|
@ -636,6 +636,28 @@ impl<SM: ValidStateMachine, State> StateMachine<SM, State> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Change the clock divider of a state machine.
|
||||
///
|
||||
/// Changing the clock divider of a running state machine is allowed
|
||||
/// and guaranteed to not cause any glitches, but the exact timing of
|
||||
/// clock pulses during the change is not specified.
|
||||
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.set_clock_divisor(int, frac);
|
||||
}
|
||||
|
||||
/// Change the clock divider of a state machine using a 16.8 fixed point value.
|
||||
///
|
||||
/// Changing the clock divider of a running state machine is allowed
|
||||
/// and guaranteed to not cause any glitches, but the exact timing of
|
||||
/// clock pulses during the change is not specified.
|
||||
pub fn clock_divisor_fixed_point(&mut self, int: u16, frac: u8) {
|
||||
self.sm.set_clock_divisor(int, frac);
|
||||
}
|
||||
}
|
||||
|
||||
// Safety: All shared register accesses are atomic.
|
||||
|
@ -656,20 +678,6 @@ 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.set_clock_divisor(int, frac);
|
||||
}
|
||||
|
||||
/// Change the clock divider of a stopped state machine using a 16.8 fixed point value.
|
||||
pub fn clock_divisor_fixed_point(&mut self, int: u16, frac: u8) {
|
||||
self.sm.set_clock_divisor(int, frac);
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
|
Loading…
Reference in a new issue