diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-03-26 16:01:37 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2025-03-27 15:18:06 +0100 |
| commit | d41eeeae79388f219bf6a84e2f7bde9f6b532516 (patch) | |
| tree | 678b6fc732216e529dc38e6f65b72a309917ac32 /embassy-stm32/src/hrtim | |
| parent | 9edf5b7f049f95742b60b041e4443967d8a6b708 (diff) | |
Remove Peripheral trait, rename PeripheralRef->Peri.
Diffstat (limited to 'embassy-stm32/src/hrtim')
| -rw-r--r-- | embassy-stm32/src/hrtim/mod.rs | 26 | ||||
| -rw-r--r-- | embassy-stm32/src/hrtim/traits.rs | 4 |
2 files changed, 14 insertions, 16 deletions
diff --git a/embassy-stm32/src/hrtim/mod.rs b/embassy-stm32/src/hrtim/mod.rs index d9b7c16fb..1d0594125 100644 --- a/embassy-stm32/src/hrtim/mod.rs +++ b/embassy-stm32/src/hrtim/mod.rs | |||
| @@ -4,12 +4,12 @@ mod traits; | |||
| 4 | 4 | ||
| 5 | use core::marker::PhantomData; | 5 | use core::marker::PhantomData; |
| 6 | 6 | ||
| 7 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 7 | use embassy_hal_internal::Peri; |
| 8 | pub use traits::Instance; | 8 | pub use traits::Instance; |
| 9 | 9 | ||
| 10 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; | 10 | use crate::gpio::{AfType, AnyPin, OutputType, Speed}; |
| 11 | use crate::rcc; | ||
| 11 | use crate::time::Hertz; | 12 | use crate::time::Hertz; |
| 12 | use crate::{rcc, Peripheral}; | ||
| 13 | 13 | ||
| 14 | /// HRTIM burst controller instance. | 14 | /// HRTIM burst controller instance. |
| 15 | pub struct BurstController<T: Instance> { | 15 | pub struct BurstController<T: Instance> { |
| @@ -62,13 +62,13 @@ pub trait AdvancedChannel<T: Instance>: SealedAdvancedChannel<T> {} | |||
| 62 | 62 | ||
| 63 | /// HRTIM PWM pin. | 63 | /// HRTIM PWM pin. |
| 64 | pub struct PwmPin<'d, T, C> { | 64 | pub struct PwmPin<'d, T, C> { |
| 65 | _pin: PeripheralRef<'d, AnyPin>, | 65 | _pin: Peri<'d, AnyPin>, |
| 66 | phantom: PhantomData<(T, C)>, | 66 | phantom: PhantomData<(T, C)>, |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /// HRTIM complementary PWM pin. | 69 | /// HRTIM complementary PWM pin. |
| 70 | pub struct ComplementaryPwmPin<'d, T, C> { | 70 | pub struct ComplementaryPwmPin<'d, T, C> { |
| 71 | _pin: PeripheralRef<'d, AnyPin>, | 71 | _pin: Peri<'d, AnyPin>, |
| 72 | phantom: PhantomData<(T, C)>, | 72 | phantom: PhantomData<(T, C)>, |
| 73 | } | 73 | } |
| 74 | 74 | ||
| @@ -76,8 +76,7 @@ macro_rules! advanced_channel_impl { | |||
| 76 | ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { | 76 | ($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => { |
| 77 | impl<'d, T: Instance> PwmPin<'d, T, $channel<T>> { | 77 | impl<'d, T: Instance> PwmPin<'d, T, $channel<T>> { |
| 78 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] | 78 | #[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")] |
| 79 | pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self { | 79 | pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self { |
| 80 | into_ref!(pin); | ||
| 81 | critical_section::with(|_| { | 80 | critical_section::with(|_| { |
| 82 | pin.set_low(); | 81 | pin.set_low(); |
| 83 | pin.set_as_af( | 82 | pin.set_as_af( |
| @@ -86,7 +85,7 @@ macro_rules! advanced_channel_impl { | |||
| 86 | ); | 85 | ); |
| 87 | }); | 86 | }); |
| 88 | PwmPin { | 87 | PwmPin { |
| 89 | _pin: pin.map_into(), | 88 | _pin: pin.into(), |
| 90 | phantom: PhantomData, | 89 | phantom: PhantomData, |
| 91 | } | 90 | } |
| 92 | } | 91 | } |
| @@ -94,8 +93,7 @@ macro_rules! advanced_channel_impl { | |||
| 94 | 93 | ||
| 95 | impl<'d, T: Instance> ComplementaryPwmPin<'d, T, $channel<T>> { | 94 | impl<'d, T: Instance> ComplementaryPwmPin<'d, T, $channel<T>> { |
| 96 | #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] | 95 | #[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance.")] |
| 97 | pub fn $new_chx(pin: impl Peripheral<P = impl $complementary_pin_trait<T>> + 'd) -> Self { | 96 | pub fn $new_chx(pin: Peri<'d, impl $complementary_pin_trait<T>>) -> Self { |
| 98 | into_ref!(pin); | ||
| 99 | critical_section::with(|_| { | 97 | critical_section::with(|_| { |
| 100 | pin.set_low(); | 98 | pin.set_low(); |
| 101 | pin.set_as_af( | 99 | pin.set_as_af( |
| @@ -104,7 +102,7 @@ macro_rules! advanced_channel_impl { | |||
| 104 | ); | 102 | ); |
| 105 | }); | 103 | }); |
| 106 | ComplementaryPwmPin { | 104 | ComplementaryPwmPin { |
| 107 | _pin: pin.map_into(), | 105 | _pin: pin.into(), |
| 108 | phantom: PhantomData, | 106 | phantom: PhantomData, |
| 109 | } | 107 | } |
| 110 | } | 108 | } |
| @@ -129,7 +127,7 @@ advanced_channel_impl!(new_chf, ChF, 5, ChannelFPin, ChannelFComplementaryPin); | |||
| 129 | 127 | ||
| 130 | /// Struct used to divide a high resolution timer into multiple channels | 128 | /// Struct used to divide a high resolution timer into multiple channels |
| 131 | pub struct AdvancedPwm<'d, T: Instance> { | 129 | pub struct AdvancedPwm<'d, T: Instance> { |
| 132 | _inner: PeripheralRef<'d, T>, | 130 | _inner: Peri<'d, T>, |
| 133 | /// Master instance. | 131 | /// Master instance. |
| 134 | pub master: Master<T>, | 132 | pub master: Master<T>, |
| 135 | /// Burst controller. | 133 | /// Burst controller. |
| @@ -154,7 +152,7 @@ impl<'d, T: Instance> AdvancedPwm<'d, T> { | |||
| 154 | /// | 152 | /// |
| 155 | /// This splits the HRTIM into its constituent parts, which you can then use individually. | 153 | /// This splits the HRTIM into its constituent parts, which you can then use individually. |
| 156 | pub fn new( | 154 | pub fn new( |
| 157 | tim: impl Peripheral<P = T> + 'd, | 155 | tim: Peri<'d, T>, |
| 158 | _cha: Option<PwmPin<'d, T, ChA<T>>>, | 156 | _cha: Option<PwmPin<'d, T, ChA<T>>>, |
| 159 | _chan: Option<ComplementaryPwmPin<'d, T, ChA<T>>>, | 157 | _chan: Option<ComplementaryPwmPin<'d, T, ChA<T>>>, |
| 160 | _chb: Option<PwmPin<'d, T, ChB<T>>>, | 158 | _chb: Option<PwmPin<'d, T, ChB<T>>>, |
| @@ -171,9 +169,7 @@ impl<'d, T: Instance> AdvancedPwm<'d, T> { | |||
| 171 | Self::new_inner(tim) | 169 | Self::new_inner(tim) |
| 172 | } | 170 | } |
| 173 | 171 | ||
| 174 | fn new_inner(tim: impl Peripheral<P = T> + 'd) -> Self { | 172 | fn new_inner(tim: Peri<'d, T>) -> Self { |
| 175 | into_ref!(tim); | ||
| 176 | |||
| 177 | rcc::enable_and_reset::<T>(); | 173 | rcc::enable_and_reset::<T>(); |
| 178 | 174 | ||
| 179 | #[cfg(stm32f334)] | 175 | #[cfg(stm32f334)] |
diff --git a/embassy-stm32/src/hrtim/traits.rs b/embassy-stm32/src/hrtim/traits.rs index 75f9971e2..6c0661146 100644 --- a/embassy-stm32/src/hrtim/traits.rs +++ b/embassy-stm32/src/hrtim/traits.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | use embassy_hal_internal::PeripheralType; | ||
| 2 | |||
| 1 | use crate::rcc::RccPeripheral; | 3 | use crate::rcc::RccPeripheral; |
| 2 | use crate::time::Hertz; | 4 | use crate::time::Hertz; |
| 3 | 5 | ||
| @@ -153,7 +155,7 @@ pub(crate) trait SealedInstance: RccPeripheral { | |||
| 153 | 155 | ||
| 154 | /// HRTIM instance trait. | 156 | /// HRTIM instance trait. |
| 155 | #[allow(private_bounds)] | 157 | #[allow(private_bounds)] |
| 156 | pub trait Instance: SealedInstance + 'static {} | 158 | pub trait Instance: SealedInstance + PeripheralType + 'static {} |
| 157 | 159 | ||
| 158 | foreach_interrupt! { | 160 | foreach_interrupt! { |
| 159 | ($inst:ident, hrtim, HRTIM, MASTER, $irq:ident) => { | 161 | ($inst:ident, hrtim, HRTIM, MASTER, $irq:ident) => { |
