Merge pull request #2484 from Murmele/main
use constant for the pwm clock
This commit is contained in:
commit
c37e483b3b
1 changed files with 11 additions and 2 deletions
|
@ -47,6 +47,8 @@ pub enum Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_SEQUENCE_LEN: usize = 32767;
|
const MAX_SEQUENCE_LEN: usize = 32767;
|
||||||
|
/// The used pwm clock frequency
|
||||||
|
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
|
||||||
|
@ -713,6 +715,13 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
|
||||||
pwm
|
pwm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the enable state of the pwm counter
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn is_enabled(&self) -> bool {
|
||||||
|
let r = T::regs();
|
||||||
|
r.enable.read().enable().bit_is_set()
|
||||||
|
}
|
||||||
|
|
||||||
/// Enables the PWM generator.
|
/// Enables the PWM generator.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn enable(&self) {
|
pub fn enable(&self) {
|
||||||
|
@ -788,7 +797,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 +805,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
Reference in a new issue