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.rs25
1 files changed, 20 insertions, 5 deletions
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs
index 98b798634..159b5a177 100644
--- a/embassy-stm32/src/timer/pwm_input.rs
+++ b/embassy-stm32/src/timer/pwm_input.rs
@@ -1,12 +1,16 @@
1//! PWM Input driver. 1//! PWM Input driver.
2 2
3use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; 3use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource};
4use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel}; 4use super::{Ch1, Ch2, Channel, GeneralInstance4Channel, TimerPin};
5use crate::gpio::{AfType, Pull}; 5use crate::gpio::{AfType, Pull};
6use crate::time::Hertz; 6use crate::time::Hertz;
7use crate::Peri; 7use crate::Peri;
8 8
9/// PWM Input driver. 9/// PWM Input driver.
10///
11/// Only works with CH1 or CH2
12/// Note: Not all timer peripherals are supported
13/// Double check your chips reference manual
10pub struct PwmInput<'d, T: GeneralInstance4Channel> { 14pub struct PwmInput<'d, T: GeneralInstance4Channel> {
11 channel: Channel, 15 channel: Channel,
12 inner: Timer<'d, T>, 16 inner: Timer<'d, T>,
@@ -14,15 +18,25 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> {
14 18
15impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { 19impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
16 /// Create a new PWM input driver. 20 /// Create a new PWM input driver.
17 pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl Channel1Pin<T>>, pull: Pull, freq: Hertz) -> Self { 21 pub fn new_ch1<#[cfg(afio)] A>(
18 pin.set_as_af(pin.af_num(), AfType::input(pull)); 22 tim: Peri<'d, T>,
23 pin: Peri<'d, if_afio!(impl TimerPin<T, Ch1, A>)>,
24 pull: Pull,
25 freq: Hertz,
26 ) -> Self {
27 set_as_af!(pin, AfType::input(pull));
19 28
20 Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) 29 Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2)
21 } 30 }
22 31
23 /// Create a new PWM input driver. 32 /// Create a new PWM input driver.
24 pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl Channel2Pin<T>>, pull: Pull, freq: Hertz) -> Self { 33 pub fn new_ch2<#[cfg(afio)] A>(
25 pin.set_as_af(pin.af_num(), AfType::input(pull)); 34 tim: Peri<'d, T>,
35 pin: Peri<'d, if_afio!(impl TimerPin<T, Ch2, A>)>,
36 pull: Pull,
37 freq: Hertz,
38 ) -> Self {
39 set_as_af!(pin, AfType::input(pull));
26 40
27 Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) 41 Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1)
28 } 42 }
@@ -37,6 +51,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> {
37 51
38 // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6 52 // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6
39 // or ST RM0008 (STM32F103) chapter 15.3.6 Input capture mode 53 // or ST RM0008 (STM32F103) chapter 15.3.6 Input capture mode
54 // or ST RM0440 (STM32G4) chapter 30.4.8 PWM input mode
40 inner.set_input_ti_selection(ch1, InputTISelection::Normal); 55 inner.set_input_ti_selection(ch1, InputTISelection::Normal);
41 inner.set_input_capture_mode(ch1, InputCaptureMode::Rising); 56 inner.set_input_capture_mode(ch1, InputCaptureMode::Rising);
42 57