aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/low_level.rs
diff options
context:
space:
mode:
authorGabriel Smith <[email protected]>2025-04-02 18:30:06 +0000
committerGabriel Smith <[email protected]>2025-04-04 17:40:22 +0000
commitf8e5c902665edf02f78fbb223ce14b3743fc543b (patch)
tree5c79ed00031deb8b2159e208ab4d90542803df34 /embassy-stm32/src/timer/low_level.rs
parenteee2d8c84d318b36a80759aad26e2303965c0565 (diff)
stm32/timer: Support one pulse mode
Currently does not support output pins so it really is only useful to create delayed interrupts based on external signals.
Diffstat (limited to 'embassy-stm32/src/timer/low_level.rs')
-rw-r--r--embassy-stm32/src/timer/low_level.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/embassy-stm32/src/timer/low_level.rs b/embassy-stm32/src/timer/low_level.rs
index 5b0c95109..524c64c14 100644
--- a/embassy-stm32/src/timer/low_level.rs
+++ b/embassy-stm32/src/timer/low_level.rs
@@ -425,6 +425,36 @@ impl<'d, T: GeneralInstance1Channel> Timer<'d, T> {
425 TimerBits::Bits32 => self.regs_gp32_unchecked().arr().read(), 425 TimerBits::Bits32 => self.regs_gp32_unchecked().arr().read(),
426 } 426 }
427 } 427 }
428
429 /// Set the max compare value.
430 ///
431 /// An update event is generated to load the new value. The update event is
432 /// generated such that it will not cause an interrupt or DMA request.
433 pub fn set_max_compare_value(&self, ticks: u32) {
434 match T::BITS {
435 TimerBits::Bits16 => {
436 let arr = unwrap!(u16::try_from(ticks));
437
438 let regs = self.regs_1ch();
439 regs.arr().write(|r| r.set_arr(arr));
440
441 regs.cr1().modify(|r| r.set_urs(vals::Urs::COUNTER_ONLY));
442 regs.egr().write(|r| r.set_ug(true));
443 regs.cr1().modify(|r| r.set_urs(vals::Urs::ANY_EVENT));
444 }
445 #[cfg(not(stm32l0))]
446 TimerBits::Bits32 => {
447 let arr = ticks;
448
449 let regs = self.regs_gp32_unchecked();
450 regs.arr().write_value(arr);
451
452 regs.cr1().modify(|r| r.set_urs(vals::Urs::COUNTER_ONLY));
453 regs.egr().write(|r| r.set_ug(true));
454 regs.cr1().modify(|r| r.set_urs(vals::Urs::ANY_EVENT));
455 }
456 }
457 }
428} 458}
429 459
430impl<'d, T: GeneralInstance2Channel> Timer<'d, T> { 460impl<'d, T: GeneralInstance2Channel> Timer<'d, T> {