mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 08:12:30 +00:00
Merge pull request #2484 from Murmele/main
use constant for the pwm clock
This commit is contained in:
commit
c37e483b3b
@ -47,6 +47,8 @@ pub enum Error {
|
||||
}
|
||||
|
||||
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> {
|
||||
/// Create a new 1-channel PWM
|
||||
@ -713,6 +715,13 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
|
||||
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.
|
||||
#[inline(always)]
|
||||
pub fn enable(&self) {
|
||||
@ -788,7 +797,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> {
|
||||
/// Sets the PWM output frequency.
|
||||
#[inline(always)]
|
||||
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;
|
||||
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.
|
||||
#[inline(always)]
|
||||
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;
|
||||
clk / max_duty
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user