diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-01-26 23:40:02 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-26 23:40:02 +0000 |
| commit | c37e483b3b5acbb9bd42b950024c35c24ce34519 (patch) | |
| tree | b35a7f3714e0c057af606f76cd57bad241cd4220 | |
| parent | 31fa0aebd8825fa2faf8ec988f0eda2e62ad4dad (diff) | |
| parent | 2809d3bd45c9d469ae398d55f8d2c4bfda33c9dd (diff) | |
Merge pull request #2484 from Murmele/main
use constant for the pwm clock
| -rw-r--r-- | embassy-nrf/src/pwm.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 2f0397632..856e12024 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs | |||
| @@ -47,6 +47,8 @@ pub enum Error { | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | const MAX_SEQUENCE_LEN: usize = 32767; | 49 | const MAX_SEQUENCE_LEN: usize = 32767; |
| 50 | /// The used pwm clock frequency | ||
| 51 | pub const PWM_CLK_HZ: u32 = 16_000_000; | ||
| 50 | 52 | ||
| 51 | impl<'d, T: Instance> SequencePwm<'d, T> { | 53 | impl<'d, T: Instance> SequencePwm<'d, T> { |
| 52 | /// Create a new 1-channel PWM | 54 | /// Create a new 1-channel PWM |
| @@ -713,6 +715,13 @@ impl<'d, T: Instance> SimplePwm<'d, T> { | |||
| 713 | pwm | 715 | pwm |
| 714 | } | 716 | } |
| 715 | 717 | ||
| 718 | /// Returns the enable state of the pwm counter | ||
| 719 | #[inline(always)] | ||
| 720 | pub fn is_enabled(&self) -> bool { | ||
| 721 | let r = T::regs(); | ||
| 722 | r.enable.read().enable().bit_is_set() | ||
| 723 | } | ||
| 724 | |||
| 716 | /// Enables the PWM generator. | 725 | /// Enables the PWM generator. |
| 717 | #[inline(always)] | 726 | #[inline(always)] |
| 718 | pub fn enable(&self) { | 727 | pub fn enable(&self) { |
| @@ -788,7 +797,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { | |||
| 788 | /// Sets the PWM output frequency. | 797 | /// Sets the PWM output frequency. |
| 789 | #[inline(always)] | 798 | #[inline(always)] |
| 790 | pub fn set_period(&self, freq: u32) { | 799 | pub fn set_period(&self, freq: u32) { |
| 791 | let clk = 16_000_000u32 >> (self.prescaler() as u8); | 800 | let clk = PWM_CLK_HZ >> (self.prescaler() as u8); |
| 792 | let duty = clk / freq; | 801 | let duty = clk / freq; |
| 793 | self.set_max_duty(duty.min(32767) as u16); | 802 | self.set_max_duty(duty.min(32767) as u16); |
| 794 | } | 803 | } |
| @@ -796,7 +805,7 @@ impl<'d, T: Instance> SimplePwm<'d, T> { | |||
| 796 | /// Returns the PWM output frequency. | 805 | /// Returns the PWM output frequency. |
| 797 | #[inline(always)] | 806 | #[inline(always)] |
| 798 | pub fn period(&self) -> u32 { | 807 | pub fn period(&self) -> u32 { |
| 799 | let clk = 16_000_000u32 >> (self.prescaler() as u8); | 808 | let clk = PWM_CLK_HZ >> (self.prescaler() as u8); |
| 800 | let max_duty = self.max_duty() as u32; | 809 | let max_duty = self.max_duty() as u32; |
| 801 | clk / max_duty | 810 | clk / max_duty |
| 802 | } | 811 | } |
