diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-06-27 14:08:36 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-27 14:08:36 +0000 |
| commit | 93a8435535a3caa9dfa6c279be5c8b96f08f3b76 (patch) | |
| tree | dbc7c7e63e2c160d33ce968dca4186045f41cf78 | |
| parent | 7ba8c22a2d839057e8ed312d8103311643aea67f (diff) | |
| parent | b31a423eea6998ee681eda49433edc5dd03a5c63 (diff) | |
Merge pull request #4323 from phycrax/rename_pwminput_new
embassy-stm32: Rename PWM Input constructors, add warning on usable timer peripherals
| -rw-r--r-- | embassy-stm32/src/timer/pwm_input.rs | 9 | ||||
| -rw-r--r-- | examples/stm32f1/src/bin/pwm_input.rs | 2 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/pwm_input.rs | 2 | ||||
| -rw-r--r-- | examples/stm32g0/src/bin/pwm_input.rs | 2 |
4 files changed, 10 insertions, 5 deletions
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index 99afb5582..1e55f2919 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 or 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 | ||
diff --git a/examples/stm32f1/src/bin/pwm_input.rs b/examples/stm32f1/src/bin/pwm_input.rs index afbef3edb..aa6a11ff8 100644 --- a/examples/stm32f1/src/bin/pwm_input.rs +++ b/examples/stm32f1/src/bin/pwm_input.rs | |||
| @@ -38,7 +38,7 @@ async fn main(spawner: Spawner) { | |||
| 38 | 38 | ||
| 39 | unwrap!(spawner.spawn(blinky(p.PC13))); | 39 | unwrap!(spawner.spawn(blinky(p.PC13))); |
| 40 | 40 | ||
| 41 | let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(10)); | 41 | let mut pwm_input = PwmInput::new_ch1(p.TIM2, p.PA0, Pull::None, khz(10)); |
| 42 | pwm_input.enable(); | 42 | pwm_input.enable(); |
| 43 | 43 | ||
| 44 | loop { | 44 | loop { |
diff --git a/examples/stm32f4/src/bin/pwm_input.rs b/examples/stm32f4/src/bin/pwm_input.rs index 465cbe4f5..74167cbf2 100644 --- a/examples/stm32f4/src/bin/pwm_input.rs +++ b/examples/stm32f4/src/bin/pwm_input.rs | |||
| @@ -38,7 +38,7 @@ async fn main(spawner: Spawner) { | |||
| 38 | 38 | ||
| 39 | unwrap!(spawner.spawn(blinky(p.PB2))); | 39 | unwrap!(spawner.spawn(blinky(p.PB2))); |
| 40 | 40 | ||
| 41 | let mut pwm_input = PwmInput::new(p.TIM3, p.PA6, Pull::None, khz(10)); | 41 | let mut pwm_input = PwmInput::new_ch1(p.TIM3, p.PA6, Pull::None, khz(10)); |
| 42 | pwm_input.enable(); | 42 | pwm_input.enable(); |
| 43 | 43 | ||
| 44 | loop { | 44 | loop { |
diff --git a/examples/stm32g0/src/bin/pwm_input.rs b/examples/stm32g0/src/bin/pwm_input.rs index dc2428607..fd4f53f1e 100644 --- a/examples/stm32g0/src/bin/pwm_input.rs +++ b/examples/stm32g0/src/bin/pwm_input.rs | |||
| @@ -47,7 +47,7 @@ async fn main(spawner: Spawner) { | |||
| 47 | pwm.ch1().set_duty_cycle_fraction(1, 4); | 47 | pwm.ch1().set_duty_cycle_fraction(1, 4); |
| 48 | pwm.ch1().enable(); | 48 | pwm.ch1().enable(); |
| 49 | 49 | ||
| 50 | let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000)); | 50 | let mut pwm_input = PwmInput::new_ch1(p.TIM2, p.PA0, Pull::None, khz(1000)); |
| 51 | pwm_input.enable(); | 51 | pwm_input.enable(); |
| 52 | 52 | ||
| 53 | loop { | 53 | loop { |
