aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/pwm_input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-stm32/src/timer/pwm_input.rs')
-rw-r--r--embassy-stm32/src/timer/pwm_input.rs17
1 files changed, 10 insertions, 7 deletions
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs
index 159b5a177..f2f00927d 100644
--- a/embassy-stm32/src/timer/pwm_input.rs
+++ b/embassy-stm32/src/timer/pwm_input.rs
@@ -2,9 +2,9 @@
2 2
3use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; 3use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource};
4use super::{Ch1, Ch2, Channel, GeneralInstance4Channel, TimerPin}; 4use super::{Ch1, Ch2, Channel, GeneralInstance4Channel, TimerPin};
5use crate::Peri;
5use crate::gpio::{AfType, Pull}; 6use crate::gpio::{AfType, Pull};
6use crate::time::Hertz; 7use crate::time::Hertz;
7use crate::Peri;
8 8
9/// PWM Input driver. 9/// PWM Input driver.
10/// 10///
@@ -47,6 +47,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
47 inner.set_counting_mode(CountingMode::EdgeAlignedUp); 47 inner.set_counting_mode(CountingMode::EdgeAlignedUp);
48 inner.set_tick_freq(freq); 48 inner.set_tick_freq(freq);
49 inner.enable_outputs(); // Required for advanced timers, see GeneralInstance4Channel for details 49 inner.enable_outputs(); // Required for advanced timers, see GeneralInstance4Channel for details
50 inner.generate_update_event();
50 inner.start(); 51 inner.start();
51 52
52 // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6 53 // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6
@@ -90,16 +91,18 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
90 91
91 /// Get the period tick count 92 /// Get the period tick count
92 pub fn get_period_ticks(&self) -> u32 { 93 pub fn get_period_ticks(&self) -> u32 {
93 self.inner.get_capture_value(self.channel) 94 self.inner.get_capture_value(self.channel).into()
94 } 95 }
95 96
96 /// Get the pulse width tick count 97 /// Get the pulse width tick count
97 pub fn get_width_ticks(&self) -> u32 { 98 pub fn get_width_ticks(&self) -> u32 {
98 self.inner.get_capture_value(match self.channel { 99 self.inner
99 Channel::Ch1 => Channel::Ch2, 100 .get_capture_value(match self.channel {
100 Channel::Ch2 => Channel::Ch1, 101 Channel::Ch1 => Channel::Ch2,
101 _ => panic!("Invalid channel for PWM input"), 102 Channel::Ch2 => Channel::Ch1,
102 }) 103 _ => panic!("Invalid channel for PWM input"),
104 })
105 .into()
103 } 106 }
104 107
105 /// Get the duty cycle in 100% 108 /// Get the duty cycle in 100%