Skip to content

Commit 790940a

Browse files
committed
stm32: use typelevel timer type
1 parent b8afe4f commit 790940a

File tree

10 files changed

+138
-168
lines changed

10 files changed

+138
-168
lines changed

embassy-stm32/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased - ReleaseDate
99

10+
- change: stm32: use typelevel timer type to allow dma for 32 bit timers
1011
- fix: fix incorrect handling of split interrupts in timer driver
1112
- feat: allow granular stop for regular usart
1213
- feat: Add continuous waveform method to SimplePWM

embassy-stm32/src/fmt.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ macro_rules! error {
206206
};
207207
}
208208

209+
#[cfg(feature = "defmt")]
210+
trait_set::trait_set! {
211+
pub trait Debuggable = Debug + defmt::Format;
212+
}
213+
214+
#[cfg(not(feature = "defmt"))]
215+
trait_set::trait_set! {
216+
pub trait Debuggable = Debug;
217+
}
218+
209219
#[cfg(feature = "defmt")]
210220
#[collapse_debuginfo(yes)]
211221
macro_rules! unwrap {

embassy-stm32/src/timer/complementary_pwm.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,9 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
178178
/// This value depends on the configured frequency and the timer's clock rate from RCC.
179179
pub fn get_max_duty(&self) -> u16 {
180180
if self.inner.get_counting_mode().is_center_aligned() {
181-
self.inner.get_max_compare_value() as u16
181+
unwrap!(self.inner.get_max_compare_value().try_into())
182182
} else {
183-
self.inner.get_max_compare_value() as u16 + 1
183+
unwrap!(self.inner.get_max_compare_value().try_into()) + 1
184184
}
185185
}
186186

@@ -189,7 +189,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
189189
/// The value ranges from 0 for 0% duty, to [`get_max_duty`](Self::get_max_duty) for 100% duty, both included.
190190
pub fn set_duty(&mut self, channel: Channel, duty: u16) {
191191
assert!(duty <= self.get_max_duty());
192-
self.inner.set_compare_value(channel, duty as _)
192+
self.inner.set_compare_value(channel, duty.into())
193193
}
194194

195195
/// Set the output polarity for a given channel.
@@ -220,7 +220,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
220220
///
221221
/// Note:
222222
/// you will need to provide corresponding TIMx_UP DMA channel to use this method.
223-
pub async fn waveform_up(&mut self, dma: Peri<'_, impl super::UpDma<T>>, channel: Channel, duty: &[u16]) {
223+
pub async fn waveform_up(&mut self, dma: Peri<'_, impl super::UpDma<T>>, channel: Channel, duty: &[T::Word]) {
224224
self.inner.enable_channel(channel, true);
225225
self.inner.enable_update_dma(true);
226226
self.inner.setup_update_dma(dma, channel, duty).await;
@@ -261,7 +261,7 @@ impl<'d, T: AdvancedInstance4Channel> ComplementaryPwm<'d, T> {
261261
dma: Peri<'_, impl super::UpDma<T>>,
262262
starting_channel: Channel,
263263
ending_channel: Channel,
264-
duty: &[u16],
264+
duty: &[T::Word],
265265
) {
266266
self.inner.enable_update_dma(true);
267267
self.inner
@@ -291,20 +291,20 @@ impl<'d, T: AdvancedInstance4Channel> embedded_hal_02::Pwm for ComplementaryPwm<
291291
}
292292

293293
fn get_duty(&self, channel: Self::Channel) -> Self::Duty {
294-
self.inner.get_compare_value(channel) as u16
294+
unwrap!(self.inner.get_compare_value(channel).try_into())
295295
}
296296

297297
fn get_max_duty(&self) -> Self::Duty {
298298
if self.inner.get_counting_mode().is_center_aligned() {
299-
self.inner.get_max_compare_value() as u16
299+
unwrap!(self.inner.get_max_compare_value().try_into())
300300
} else {
301-
self.inner.get_max_compare_value() as u16 + 1
301+
unwrap!(self.inner.get_max_compare_value().try_into()) + 1
302302
}
303303
}
304304

305305
fn set_duty(&mut self, channel: Self::Channel, duty: Self::Duty) {
306306
assert!(duty <= self.get_max_duty());
307-
self.inner.set_compare_value(channel, duty as u32)
307+
self.inner.set_compare_value(channel, unwrap!(duty.try_into()))
308308
}
309309

310310
fn set_period<P>(&mut self, period: P)

embassy-stm32/src/timer/input_capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'d, T: GeneralInstance4Channel> InputCapture<'d, T> {
9797

9898
/// Get capture value for a channel.
9999
pub fn get_capture_value(&self, channel: Channel) -> u32 {
100-
self.inner.get_capture_value(channel)
100+
self.inner.get_capture_value(channel).into()
101101
}
102102

103103
/// Get input interrupt.

0 commit comments

Comments
 (0)