Skip to content

Commit c450c29

Browse files
committed
Update HRTIM pins to be configurable
1 parent 4bff7ce commit c450c29

File tree

2 files changed

+81
-7
lines changed

2 files changed

+81
-7
lines changed

embassy-stm32/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
* **Fix(stm32h5):** Prevent a HardFault crash on STM32H5 devices by changing `uid()` to return `[u8; 12]` by value instead of a reference. (Fixes #2696)
1212
## Unreleased - ReleaseDate
1313

14+
- feat: stm32/hrtim add new_chx_with_config to provide pin configuration
1415
- fix flash erase on L4 & L5
1516
- fix: Fixed STM32H5 builds requiring time feature
1617
- feat: Derive Clone, Copy for QSPI Config

embassy-stm32/src/hrtim/mod.rs

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub use traits::Instance;
1010
use crate::gpio::{AfType, AnyPin, OutputType, Speed};
1111
use crate::rcc;
1212
use crate::time::Hertz;
13+
pub use crate::timer::simple_pwm::PwmPinConfig;
1314

1415
/// HRTIM burst controller instance.
1516
pub struct BurstController<T: Instance> {
@@ -73,7 +74,7 @@ pub struct ComplementaryPwmPin<'d, T, C> {
7374
}
7475

7576
macro_rules! advanced_channel_impl {
76-
($new_chx:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => {
77+
($new_chx:ident, $new_chx_with_config:ident, $channel:tt, $ch_num:expr, $pin_trait:ident, $complementary_pin_trait:ident) => {
7778
impl<'d, T: Instance> PwmPin<'d, T, $channel<T>> {
7879
#[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance.")]
7980
pub fn $new_chx(pin: Peri<'d, impl $pin_trait<T>>) -> Self {
@@ -86,6 +87,21 @@ macro_rules! advanced_channel_impl {
8687
phantom: PhantomData,
8788
}
8889
}
90+
91+
#[doc = concat!("Create a new ", stringify!($channel), " PWM pin instance with a specific configuration.")]
92+
pub fn $new_chx_with_config(
93+
pin: Peri<'d, impl $pin_trait<T>>,
94+
pin_config: PwmPinConfig,
95+
) -> Self {
96+
critical_section::with(|_| {
97+
pin.set_low();
98+
set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed));
99+
});
100+
PwmPin {
101+
_pin: pin.into(),
102+
phantom: PhantomData,
103+
}
104+
}
89105
}
90106

91107
impl<'d, T: Instance> ComplementaryPwmPin<'d, T, $channel<T>> {
@@ -100,6 +116,21 @@ macro_rules! advanced_channel_impl {
100116
phantom: PhantomData,
101117
}
102118
}
119+
120+
#[doc = concat!("Create a new ", stringify!($channel), " complementary PWM pin instance with a specific configuration.")]
121+
pub fn $new_chx_with_config(
122+
pin: Peri<'d, impl $complementary_pin_trait<T>>,
123+
pin_config: PwmPinConfig,
124+
) -> Self {
125+
critical_section::with(|_| {
126+
pin.set_low();
127+
set_as_af!(pin, AfType::output(pin_config.output_type, pin_config.speed));
128+
});
129+
ComplementaryPwmPin {
130+
_pin: pin.into(),
131+
phantom: PhantomData,
132+
}
133+
}
103134
}
104135

105136
impl<T: Instance> SealedAdvancedChannel<T> for $channel<T> {
@@ -111,13 +142,55 @@ macro_rules! advanced_channel_impl {
111142
};
112143
}
113144

114-
advanced_channel_impl!(new_cha, ChA, 0, ChannelAPin, ChannelAComplementaryPin);
115-
advanced_channel_impl!(new_chb, ChB, 1, ChannelBPin, ChannelBComplementaryPin);
116-
advanced_channel_impl!(new_chc, ChC, 2, ChannelCPin, ChannelCComplementaryPin);
117-
advanced_channel_impl!(new_chd, ChD, 3, ChannelDPin, ChannelDComplementaryPin);
118-
advanced_channel_impl!(new_che, ChE, 4, ChannelEPin, ChannelEComplementaryPin);
145+
advanced_channel_impl!(
146+
new_cha,
147+
new_cha_with_config,
148+
ChA,
149+
0,
150+
ChannelAPin,
151+
ChannelAComplementaryPin
152+
);
153+
advanced_channel_impl!(
154+
new_chb,
155+
new_chb_with_config,
156+
ChB,
157+
1,
158+
ChannelBPin,
159+
ChannelBComplementaryPin
160+
);
161+
advanced_channel_impl!(
162+
new_chc,
163+
new_chc_with_config,
164+
ChC,
165+
2,
166+
ChannelCPin,
167+
ChannelCComplementaryPin
168+
);
169+
advanced_channel_impl!(
170+
new_chd,
171+
new_chd_with_config,
172+
ChD,
173+
3,
174+
ChannelDPin,
175+
ChannelDComplementaryPin
176+
);
177+
advanced_channel_impl!(
178+
new_che,
179+
new_che_with_config,
180+
ChE,
181+
4,
182+
ChannelEPin,
183+
ChannelEComplementaryPin
184+
);
119185
#[cfg(hrtim_v2)]
120-
advanced_channel_impl!(new_chf, ChF, 5, ChannelFPin, ChannelFComplementaryPin);
186+
advanced_channel_impl!(
187+
new_chf,
188+
new_chf_with_config,
189+
ChF,
190+
5,
191+
ChannelFPin,
192+
ChannelFComplementaryPin
193+
);
121194

122195
/// Struct used to divide a high resolution timer into multiple channels
123196
pub struct AdvancedPwm<'d, T: Instance> {

0 commit comments

Comments
 (0)