diff options
| author | Süha Ünüvar <[email protected]> | 2025-06-20 13:17:50 +0800 |
|---|---|---|
| committer | Süha Ünüvar <[email protected]> | 2025-06-27 09:23:53 +0800 |
| commit | 04bf17dde60c022ffaa5e37233ce45f048f0e2c3 (patch) | |
| tree | d3350a62540c2c7229d8675bec6bcadf021a1639 | |
| parent | 9ee01d9cc6081e53ea17af88904b40294bdda3e8 (diff) | |
rename fns and add documentation
| -rw-r--r-- | embassy-stm32/src/timer/pwm_input.rs | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index 99afb5582..e5b7335e8 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs | |||
| @@ -7,6 +7,10 @@ use crate::time::Hertz; | |||
| 7 | use crate::Peri; | 7 | use crate::Peri; |
| 8 | 8 | ||
| 9 | /// PWM Input driver. | 9 | /// PWM Input driver. |
| 10 | /// | ||
| 11 | /// Only works with CH1 and CH2 | ||
| 12 | /// Note: Not all timer peripherals are supported | ||
| 13 | /// Double check your chips reference manual | ||
| 10 | pub struct PwmInput<'d, T: GeneralInstance4Channel> { | 14 | pub struct PwmInput<'d, T: GeneralInstance4Channel> { |
| 11 | channel: Channel, | 15 | channel: Channel, |
| 12 | inner: Timer<'d, T>, | 16 | inner: Timer<'d, T>, |
| @@ -14,14 +18,14 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> { | |||
| 14 | 18 | ||
| 15 | impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | 19 | impl<'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 TimerPin<T, Ch1>>, pull: Pull, freq: Hertz) -> Self { | 21 | pub fn new_ch1(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch1>>, pull: Pull, freq: Hertz) -> Self { |
| 18 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 22 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 19 | 23 | ||
| 20 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) | 24 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) |
| 21 | } | 25 | } |
| 22 | 26 | ||
| 23 | /// Create a new PWM input driver. | 27 | /// Create a new PWM input driver. |
| 24 | pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch2>>, pull: Pull, freq: Hertz) -> Self { | 28 | pub fn new_ch2(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch2>>, pull: Pull, freq: Hertz) -> Self { |
| 25 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | 29 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 26 | 30 | ||
| 27 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) | 31 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) |
| @@ -37,6 +41,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 37 | 41 | ||
| 38 | // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6 | 42 | // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6 |
| 39 | // or ST RM0008 (STM32F103) chapter 15.3.6 Input capture mode | 43 | // or ST RM0008 (STM32F103) chapter 15.3.6 Input capture mode |
| 44 | // or ST RM0440 (STM32G4) chapter 30.4.8 PWM input mode | ||
| 40 | inner.set_input_ti_selection(ch1, InputTISelection::Normal); | 45 | inner.set_input_ti_selection(ch1, InputTISelection::Normal); |
| 41 | inner.set_input_capture_mode(ch1, InputCaptureMode::Rising); | 46 | inner.set_input_capture_mode(ch1, InputCaptureMode::Rising); |
| 42 | 47 | ||
