diff options
| author | Jan Špaček <[email protected]> | 2024-06-01 18:16:40 +0200 |
|---|---|---|
| committer | Jan Špaček <[email protected]> | 2024-06-16 21:11:55 +0200 |
| commit | 94007ce6e0fc59e374902eadcc31616e56068e43 (patch) | |
| tree | 014302ef421d4cfdc6e816737793f3ad147d7bc1 /embassy-stm32/src/timer | |
| parent | 1a2c8cecded9805970dc63f495723c690c01397e (diff) | |
stm32/gpio: refactor AfType
Diffstat (limited to 'embassy-stm32/src/timer')
| -rw-r--r-- | embassy-stm32/src/timer/complementary_pwm.rs | 7 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/input_capture.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/pwm_input.rs | 10 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/qei.rs | 6 | ||||
| -rw-r--r-- | embassy-stm32/src/timer/simple_pwm.rs | 6 |
5 files changed, 16 insertions, 21 deletions
diff --git a/embassy-stm32/src/timer/complementary_pwm.rs b/embassy-stm32/src/timer/complementary_pwm.rs index a892646cf..46ccbf3df 100644 --- a/embassy-stm32/src/timer/complementary_pwm.rs +++ b/embassy-stm32/src/timer/complementary_pwm.rs | |||
| @@ -32,9 +32,10 @@ macro_rules! complementary_channel_impl { | |||
| 32 | into_ref!(pin); | 32 | into_ref!(pin); |
| 33 | critical_section::with(|_| { | 33 | critical_section::with(|_| { |
| 34 | pin.set_low(); | 34 | pin.set_low(); |
| 35 | pin.set_as_af(pin.af_num(), output_type.into()); | 35 | pin.set_as_af( |
| 36 | #[cfg(gpio_v2)] | 36 | pin.af_num(), |
| 37 | pin.set_speed(crate::gpio::Speed::VeryHigh); | 37 | crate::gpio::AfType::output(output_type, crate::gpio::Speed::VeryHigh), |
| 38 | ); | ||
| 38 | }); | 39 | }); |
| 39 | ComplementaryPwmPin { | 40 | ComplementaryPwmPin { |
| 40 | _pin: pin.map_into(), | 41 | _pin: pin.map_into(), |
diff --git a/embassy-stm32/src/timer/input_capture.rs b/embassy-stm32/src/timer/input_capture.rs index 0258d4077..341ac2c04 100644 --- a/embassy-stm32/src/timer/input_capture.rs +++ b/embassy-stm32/src/timer/input_capture.rs | |||
| @@ -12,7 +12,7 @@ use super::{ | |||
| 12 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, | 12 | CaptureCompareInterruptHandler, Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, |
| 13 | GeneralInstance4Channel, | 13 | GeneralInstance4Channel, |
| 14 | }; | 14 | }; |
| 15 | use crate::gpio::{AFType, AnyPin, Pull}; | 15 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 16 | use crate::interrupt::typelevel::{Binding, Interrupt}; | 16 | use crate::interrupt::typelevel::{Binding, Interrupt}; |
| 17 | use crate::time::Hertz; | 17 | use crate::time::Hertz; |
| 18 | use crate::Peripheral; | 18 | use crate::Peripheral; |
| @@ -38,11 +38,9 @@ macro_rules! channel_impl { | |||
| 38 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { | 38 | ($new_chx:ident, $channel:ident, $pin_trait:ident) => { |
| 39 | impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> { | 39 | impl<'d, T: GeneralInstance4Channel> CapturePin<'d, T, $channel> { |
| 40 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] | 40 | #[doc = concat!("Create a new ", stringify!($channel), " capture pin instance.")] |
| 41 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, pull_type: Pull) -> Self { | 41 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd, pull: Pull) -> Self { |
| 42 | into_ref!(pin); | 42 | into_ref!(pin); |
| 43 | 43 | pin.set_as_af(pin.af_num(), AfType::input(pull)); | |
| 44 | pin.set_as_af_pull(pin.af_num(), AFType::Input, pull_type); | ||
| 45 | |||
| 46 | CapturePin { | 44 | CapturePin { |
| 47 | _pin: pin.map_into(), | 45 | _pin: pin.map_into(), |
| 48 | phantom: PhantomData, | 46 | phantom: PhantomData, |
diff --git a/embassy-stm32/src/timer/pwm_input.rs b/embassy-stm32/src/timer/pwm_input.rs index dcf098a78..e3eb6042a 100644 --- a/embassy-stm32/src/timer/pwm_input.rs +++ b/embassy-stm32/src/timer/pwm_input.rs | |||
| @@ -4,7 +4,7 @@ use embassy_hal_internal::into_ref; | |||
| 4 | 4 | ||
| 5 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; | 5 | use super::low_level::{CountingMode, InputCaptureMode, InputTISelection, SlaveMode, Timer, TriggerSource}; |
| 6 | use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel}; | 6 | use super::{Channel, Channel1Pin, Channel2Pin, GeneralInstance4Channel}; |
| 7 | use crate::gpio::{AFType, Pull}; | 7 | use crate::gpio::{AfType, Pull}; |
| 8 | use crate::time::Hertz; | 8 | use crate::time::Hertz; |
| 9 | use crate::Peripheral; | 9 | use crate::Peripheral; |
| 10 | 10 | ||
| @@ -19,12 +19,12 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 19 | pub fn new( | 19 | pub fn new( |
| 20 | tim: impl Peripheral<P = T> + 'd, | 20 | tim: impl Peripheral<P = T> + 'd, |
| 21 | pin: impl Peripheral<P = impl Channel1Pin<T>> + 'd, | 21 | pin: impl Peripheral<P = impl Channel1Pin<T>> + 'd, |
| 22 | pull_type: Pull, | 22 | pull: Pull, |
| 23 | freq: Hertz, | 23 | freq: Hertz, |
| 24 | ) -> Self { | 24 | ) -> Self { |
| 25 | into_ref!(pin); | 25 | into_ref!(pin); |
| 26 | 26 | ||
| 27 | pin.set_as_af_pull(pin.af_num(), AFType::Input, pull_type); | 27 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 28 | 28 | ||
| 29 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) | 29 | Self::new_inner(tim, freq, Channel::Ch1, Channel::Ch2) |
| 30 | } | 30 | } |
| @@ -33,12 +33,12 @@ impl<'d, T: GeneralInstance4Channel> PwmInput<'d, T> { | |||
| 33 | pub fn new_alt( | 33 | pub fn new_alt( |
| 34 | tim: impl Peripheral<P = T> + 'd, | 34 | tim: impl Peripheral<P = T> + 'd, |
| 35 | pin: impl Peripheral<P = impl Channel2Pin<T>> + 'd, | 35 | pin: impl Peripheral<P = impl Channel2Pin<T>> + 'd, |
| 36 | pull_type: Pull, | 36 | pull: Pull, |
| 37 | freq: Hertz, | 37 | freq: Hertz, |
| 38 | ) -> Self { | 38 | ) -> Self { |
| 39 | into_ref!(pin); | 39 | into_ref!(pin); |
| 40 | 40 | ||
| 41 | pin.set_as_af_pull(pin.af_num(), AFType::Input, pull_type); | 41 | pin.set_as_af(pin.af_num(), AfType::input(pull)); |
| 42 | 42 | ||
| 43 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) | 43 | Self::new_inner(tim, freq, Channel::Ch2, Channel::Ch1) |
| 44 | } | 44 | } |
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs index ab9879be6..fc5835414 100644 --- a/embassy-stm32/src/timer/qei.rs +++ b/embassy-stm32/src/timer/qei.rs | |||
| @@ -7,7 +7,7 @@ use stm32_metapac::timer::vals; | |||
| 7 | 7 | ||
| 8 | use super::low_level::Timer; | 8 | use super::low_level::Timer; |
| 9 | use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; | 9 | use super::{Channel1Pin, Channel2Pin, GeneralInstance4Channel}; |
| 10 | use crate::gpio::{AFType, AnyPin}; | 10 | use crate::gpio::{AfType, AnyPin, Pull}; |
| 11 | use crate::Peripheral; | 11 | use crate::Peripheral; |
| 12 | 12 | ||
| 13 | /// Counting direction | 13 | /// Counting direction |
| @@ -37,9 +37,7 @@ macro_rules! channel_impl { | |||
| 37 | into_ref!(pin); | 37 | into_ref!(pin); |
| 38 | critical_section::with(|_| { | 38 | critical_section::with(|_| { |
| 39 | pin.set_low(); | 39 | pin.set_low(); |
| 40 | pin.set_as_af(pin.af_num(), AFType::Input); | 40 | pin.set_as_af(pin.af_num(), AfType::input(Pull::None)); |
| 41 | #[cfg(gpio_v2)] | ||
| 42 | pin.set_speed(crate::gpio::Speed::VeryHigh); | ||
| 43 | }); | 41 | }); |
| 44 | QeiPin { | 42 | QeiPin { |
| 45 | _pin: pin.map_into(), | 43 | _pin: pin.map_into(), |
diff --git a/embassy-stm32/src/timer/simple_pwm.rs b/embassy-stm32/src/timer/simple_pwm.rs index b54e9a0d6..b7771bd64 100644 --- a/embassy-stm32/src/timer/simple_pwm.rs +++ b/embassy-stm32/src/timer/simple_pwm.rs | |||
| @@ -6,7 +6,7 @@ use embassy_hal_internal::{into_ref, PeripheralRef}; | |||
| 6 | 6 | ||
| 7 | use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; | 7 | use super::low_level::{CountingMode, OutputCompareMode, OutputPolarity, Timer}; |
| 8 | use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel}; | 8 | use super::{Channel, Channel1Pin, Channel2Pin, Channel3Pin, Channel4Pin, GeneralInstance4Channel}; |
| 9 | use crate::gpio::{AnyPin, OutputType}; | 9 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 10 | use crate::time::Hertz; | 10 | use crate::time::Hertz; |
| 11 | use crate::Peripheral; | 11 | use crate::Peripheral; |
| 12 | 12 | ||
| @@ -35,9 +35,7 @@ macro_rules! channel_impl { | |||
| 35 | into_ref!(pin); | 35 | into_ref!(pin); |
| 36 | critical_section::with(|_| { | 36 | critical_section::with(|_| { |
| 37 | pin.set_low(); | 37 | pin.set_low(); |
| 38 | pin.set_as_af(pin.af_num(), output_type.into()); | 38 | pin.set_as_af(pin.af_num(), AfType::output(output_type, Speed::VeryHigh)); |
| 39 | #[cfg(gpio_v2)] | ||
| 40 | pin.set_speed(crate::gpio::Speed::VeryHigh); | ||
| 41 | }); | 39 | }); |
| 42 | PwmPin { | 40 | PwmPin { |
| 43 | _pin: pin.map_into(), | 41 | _pin: pin.map_into(), |
