diff options
| author | melvdl <[email protected]> | 2025-06-27 01:08:28 +0200 |
|---|---|---|
| committer | melvdl <[email protected]> | 2025-06-27 01:08:28 +0200 |
| commit | 6f88c2c73caa63a6e534130f4a064cb95d3e9d7d (patch) | |
| tree | fdddad93e4f48f32ff15a3b8ad6cd0ae12095fd4 /embassy-stm32/src/timer/pwm_input.rs | |
| parent | cbd24bf2eece65a787fc085c255e9b2932ea73e3 (diff) | |
stm32: rename timer channel trait; replace impls via macro with impls generic over timer channels
Diffstat (limited to 'embassy-stm32/src/timer/pwm_input.rs')
| -rw-r--r-- | embassy-stm32/src/timer/pwm_input.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index 3f9e5f651..2e05a0593 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs | |||
| @@ -1,14 +1,14 @@ | |||
| 1 | //! PWM Input driver. | 1 | //! PWM Input driver. |
| 2 | 2 | ||
| 3 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; | 3 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; |
| 4 | use super::{Ch1, Ch2, GeneralInstance4Channel, TimerChannel, TimerPin}; | 4 | use super::{Ch1, Ch2, GeneralInstance4Channel, Channel, TimerPin}; |
| 5 | use crate::gpio::{AfType, Pull}; | 5 | use crate::gpio::{AfType, Pull}; |
| 6 | use crate::time::Hertz; | 6 | use crate::time::Hertz; |
| 7 | use crate::Peri; | 7 | use crate::Peri; |
| 8 | 8 | ||
| 9 | /// PWM Input driver. | 9 | /// PWM Input driver. |
| 10 | pub struct PwmInput<'d, T: GeneralInstance4Channel> { | 10 | pub struct PwmInput<'d, T: GeneralInstance4Channel> { |
| 11 | channel: TimerChannel, | 11 | channel: Channel, |
| 12 | inner: Timer<'d, T>, | 12 | inner: Timer<'d, T>, |
| 13 | } | 13 | } |
| 14 | 14 | ||
| @@ -17,17 +17,17 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 17 | pub fn new(tim: Peri<'d, T>, pin: Peri<'d, impl TimerPin<T, Ch1>>, pull: Pull, freq: Hertz) -> Self { | 17 | pub fn new(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)); | 18 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 19 | 19 | ||
| 20 | Self::new_inner(tim, freq, TimerChannel::Ch1, TimerChannel::Ch2) | 20 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | /// Create a new PWM input driver. | 23 | /// 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 { | 24 | pub fn new_alt(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)); | 25 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 26 | 26 | ||
| 27 | Self::new_inner(tim, freq, TimerChannel::Ch2, TimerChannel::Ch1) | 27 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | fn new_inner(tim: Peri<'d, T>, freq: Hertz, ch1: TimerChannel, ch2: TimerChannel) -> Self { | 30 | fn new_inner(tim: Peri<'d, T>, freq: Hertz, ch1: Channel, ch2: Channel) -> Self { |
| 31 | let mut inner = Timer::new(tim); | 31 | let mut inner = Timer::new(tim); |
| 32 | 32 | ||
| 33 | inner.set_counting_mode(CountingMode::EdgeAlignedUp); | 33 | inner.set_counting_mode(CountingMode::EdgeAlignedUp); |
| @@ -44,8 +44,8 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 44 | inner.set_input_capture_mode(ch2, InputCaptureMode::Falling); | 44 | inner.set_input_capture_mode(ch2, InputCaptureMode::Falling); |
| 45 | 45 | ||
| 46 | inner.set_trigger_source(match ch1 { | 46 | inner.set_trigger_source(match ch1 { |
| 47 | TimerChannel::Ch1 => TriggerSource::TI1FP1, | 47 | Channel::Ch1 => TriggerSource::TI1FP1, |
| 48 | TimerChannel::Ch2 => TriggerSource::TI2FP2, | 48 | Channel::Ch2 => TriggerSource::TI2FP2, |
| 49 | _ => panic!("Invalid channel for PWM input"), | 49 | _ => panic!("Invalid channel for PWM input"), |
| 50 | }); | 50 | }); |
| 51 | 51 | ||
| @@ -58,19 +58,19 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 58 | 58 | ||
| 59 | /// Enable the given channel. | 59 | /// Enable the given channel. |
| 60 | pub fn enable(&mut self) { | 60 | pub fn enable(&mut self) { |
| 61 | self.inner.enable_channel(TimerChannel::Ch1, true); | 61 | self.inner.enable_channel(Channel::Ch1, true); |
| 62 | self.inner.enable_channel(TimerChannel::Ch2, true); | 62 | self.inner.enable_channel(Channel::Ch2, true); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | /// Disable the given channel. | 65 | /// Disable the given channel. |
| 66 | pub fn disable(&mut self) { | 66 | pub fn disable(&mut self) { |
| 67 | self.inner.enable_channel(TimerChannel::Ch1, false); | 67 | self.inner.enable_channel(Channel::Ch1, false); |
| 68 | self.inner.enable_channel(TimerChannel::Ch2, false); | 68 | self.inner.enable_channel(Channel::Ch2, false); |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | /// Check whether given channel is enabled | 71 | /// Check whether given channel is enabled |
| 72 | pub fn is_enabled(&self) -> bool { | 72 | pub fn is_enabled(&self) -> bool { |
| 73 | self.inner.get_channel_enable_state(TimerChannel::Ch1) | 73 | self.inner.get_channel_enable_state(Channel::Ch1) |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | /// Get the period tick count | 76 | /// Get the period tick count |
| @@ -81,8 +81,8 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 81 | /// Get the pulse width tick count | 81 | /// Get the pulse width tick count |
| 82 | pub fn get_width_ticks(&self) -> u32 { | 82 | pub fn get_width_ticks(&self) -> u32 { |
| 83 | self.inner.get_capture_value(match self.channel { | 83 | self.inner.get_capture_value(match self.channel { |
| 84 | TimerChannel::Ch1 => TimerChannel::Ch2, | 84 | Channel::Ch1 => Channel::Ch2, |
| 85 | TimerChannel::Ch2 => TimerChannel::Ch1, | 85 | Channel::Ch2 => Channel::Ch1, |
| 86 | _ => panic!("Invalid channel for PWM input"), | 86 | _ => panic!("Invalid channel for PWM input"), |
| 87 | }) | 87 | }) |
| 88 | } | 88 | } |
