use constant for the pwm clock
Description: So it can be used outside of the crate to calculate max duty
This commit is contained in:
parent
31fa0aebd8
commit
dd2577fcf0
1 changed files with 3 additions and 2 deletions
|
@ -47,6 +47,7 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_SEQUENCE_LEN: usize = 32767;
|
const MAX_SEQUENCE_LEN: usize = 32767;
|
||||||
|
pub const PWM_CLK_HZ: u32 = 16_000_000;
|
||||||
|
|
||||||
impl<'d, T: Instance> SequencePwm<'d, T> {
|
impl<'d, T: Instance> SequencePwm<'d, T> {
|
||||||
/// Create a new 1-channel PWM
|
/// Create a new 1-channel PWM
|
||||||
|
@ -788,7 +789,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
|
||||||
/// Sets the PWM output frequency.
|
/// Sets the PWM output frequency.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn set_period(&self, freq: u32) {
|
pub fn set_period(&self, freq: u32) {
|
||||||
let clk = 16_000_000u32 >> (self.prescaler() as u8);
|
let clk = PWM_CLK_HZ >> (self.prescaler() as u8);
|
||||||
let duty = clk / freq;
|
let duty = clk / freq;
|
||||||
self.set_max_duty(duty.min(32767) as u16);
|
self.set_max_duty(duty.min(32767) as u16);
|
||||||
}
|
}
|
||||||
|
@ -796,7 +797,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
|
||||||
/// Returns the PWM output frequency.
|
/// Returns the PWM output frequency.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn period(&self) -> u32 {
|
pub fn period(&self) -> u32 {
|
||||||
let clk = 16_000_000u32 >> (self.prescaler() as u8);
|
let clk = PWM_CLK_HZ >> (self.prescaler() as u8);
|
||||||
let max_duty = self.max_duty() as u32;
|
let max_duty = self.max_duty() as u32;
|
||||||
clk / max_duty
|
clk / max_duty
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue