Skip to content

Commit 516c713

Browse files
committed
SysMonoTimerExt
1 parent 74213da commit 516c713

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3030

3131
### Removed
3232
- `i2s-audio-out-dma.rs` example, too difficult to fix.
33+
- Add `SysMonoTimerExt` helper trait [#497]
34+
35+
[#497]: https://github.com/stm32-rs/stm32f4xx-hal/pull/497
3336

3437
## [v0.13.2] - 2022-05-16
3538

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repository = "https://github.com/stm32-rs/stm32f4xx-hal"
2323
version = "0.13.2"
2424

2525
[package.metadata.docs.rs]
26-
features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd"]
26+
features = ["stm32f429", "usb_fs", "can", "i2s", "fsmc_lcd", "rtic"]
2727
targets = ["thumbv7em-none-eabihf"]
2828

2929
[dependencies]
@@ -44,6 +44,7 @@ display-interface = { version = "0.4.1", optional = true }
4444
fugit = "0.3.5"
4545
fugit-timer = "0.1.3"
4646
rtic-monotonic = { version = "1.0", optional = true }
47+
systick-monotonic = { version = "1.0", optional = true }
4748
bitflags = "1.3.2"
4849
embedded-storage = "0.2"
4950

@@ -355,7 +356,7 @@ uart8 = []
355356
uart9 = []
356357
uart10 = []
357358

358-
rtic = ["rtic-monotonic"]
359+
rtic = ["rtic-monotonic", "systick-monotonic"]
359360

360361
[profile.dev]
361362
debug = true

src/prelude.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,7 @@ pub use crate::time::U32Ext as _stm32f4xx_hal_time_U32Ext;
7575
#[cfg(feature = "rtic")]
7676
pub use crate::timer::MonoTimerExt as _stm32f4xx_hal_timer_MonoTimerExt;
7777
pub use crate::timer::PwmExt as _stm32f4xx_hal_timer_PwmExt;
78+
#[cfg(feature = "rtic")]
79+
pub use crate::timer::SysMonoTimerExt as _stm32f4xx_hal_timer_SysMonoTimerExt;
7880
pub use crate::timer::SysTimerExt as _stm32f4xx_hal_timer_SysCounterExt;
7981
pub use crate::timer::TimerExt as _stm32f4xx_hal_timer_TimerExt;

src/timer/monotonic.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::rcc::Clocks;
44
use core::ops::{Deref, DerefMut};
55
pub use fugit::{self, ExtU32};
66
use rtic_monotonic::Monotonic;
7+
use systick_monotonic::Systick;
78

89
pub struct MonoTimer<TIM, const FREQ: u32>(FTimer<TIM, FREQ>);
910

@@ -48,6 +49,19 @@ where
4849
}
4950
}
5051

52+
pub trait SysMonoTimerExt: Sized {
53+
fn monotonic<const FREQ: u32>(self, clocks: &Clocks) -> Systick<FREQ>;
54+
fn monotonic_us(self, clocks: &Clocks) -> Systick<1_000_000> {
55+
self.monotonic::<1_000_000>(clocks)
56+
}
57+
}
58+
59+
impl SysMonoTimerExt for crate::pac::SYST {
60+
fn monotonic<const FREQ: u32>(self, clocks: &Clocks) -> Systick<FREQ> {
61+
Systick::new(self, clocks.hclk().raw())
62+
}
63+
}
64+
5165
impl<TIM, const FREQ: u32> FTimer<TIM, FREQ>
5266
where
5367
TIM: Instance + General<Width = u32> + WithPwm,

0 commit comments

Comments
 (0)