From 04bf17dde60c022ffaa5e37233ce45f048f0e2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCha=20=C3=9Cn=C3=BCvar?= <87157627+phycrax@users.noreply.github.com> Date: Fri, 20 Jun 2025 13:17:50 +0800 Subject: [PATCH 1/3] rename fns and add documentation --- embassy-stm32/src/timer/pwm_input.rs | 9 +++++++-- 1 file 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; use crate::Peri; /// PWM Input driver. +/// +/// Only works with CH1 and CH2 +/// Note: Not all timer peripherals are supported +/// Double check your chips reference manual pub struct PwmInput<'d, T: GeneralInstance4Channel> { channel: Channel, inner: Timer<'d, T>, @@ -14,14 +18,14 @@ pub struct PwmInput<'d, T: GeneralInstance4Channel> { impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { /// Create a new PWM input driver. - pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin>, pull: Pull, freq: Hertz) -> Self { + pub fn new_ch1(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin>, pull: Pull, freq: Hertz) -> Self { pin.set_as_af(pin.af_num(), AfType::input(pull)); Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) } /// Create a new PWM input driver. - pub fn new_alt(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin>, pull: Pull, freq: Hertz) -> Self { + pub fn new_ch2(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin>, pull: Pull, freq: Hertz) -> Self { pin.set_as_af(pin.af_num(), AfType::input(pull)); Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) @@ -37,6 +41,7 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { // Configuration steps from ST RM0390 (STM32F446) chapter 17.3.6 // or ST RM0008 (STM32F103) chapter 15.3.6 Input capture mode + // or ST RM0440 (STM32G4) chapter 30.4.8 PWM input mode inner.set_input_ti_selection(ch1, InputTISelection::Normal); inner.set_input_capture_mode(ch1, InputCaptureMode::Rising); From 5cbc9a235f806bc961ed58da34ed932e39646e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCha=20=C3=9Cn=C3=BCvar?= <87157627+phycrax@users.noreply.github.com> Date: Fri, 20 Jun 2025 13:27:56 +0800 Subject: [PATCH 2/3] correct documentation --- embassy-stm32/src/timer/pwm_input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index e5b7335e8..1e55f2919 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs @@ -8,7 +8,7 @@ use crate::Peri; /// PWM Input driver. /// -/// Only works with CH1 and CH2 +/// Only works with CH1 or CH2 /// Note: Not all timer peripherals are supported /// Double check your chips reference manual pub struct PwmInput<'d, T: GeneralInstance4Channel> { From b31a423eea6998ee681eda49433edc5dd03a5c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCha=20=C3=9Cn=C3=BCvar?= <87157627+phycrax@users.noreply.github.com> Date: Fri, 27 Jun 2025 09:25:24 +0800 Subject: [PATCH 3/3] fix examples --- examples/stm32f1/src/bin/pwm_input.rs | 2 +- examples/stm32f4/src/bin/pwm_input.rs | 2 +- examples/stm32g0/src/bin/pwm_input.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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) { unwrap!(spawner.spawn(blinky(p.PC13))); - let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(10)); + let mut pwm_input = PwmInput::new_ch1(p.TIM2, p.PA0, Pull::None, khz(10)); pwm_input.enable(); 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) { unwrap!(spawner.spawn(blinky(p.PB2))); - let mut pwm_input = PwmInput::new(p.TIM3, p.PA6, Pull::None, khz(10)); + let mut pwm_input = PwmInput::new_ch1(p.TIM3, p.PA6, Pull::None, khz(10)); pwm_input.enable(); 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) { pwm.ch1().set_duty_cycle_fraction(1, 4); pwm.ch1().enable(); - let mut pwm_input = PwmInput::new(p.TIM2, p.PA0, Pull::None, khz(1000)); + let mut pwm_input = PwmInput::new_ch1(p.TIM2, p.PA0, Pull::None, khz(1000)); pwm_input.enable(); loop {