aboutsummaryrefslogtreecommitdiff
path: root/embassy-mspm0/src/timer.rs
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2025-03-21 13:32:14 +0000
committerGitHub <[email protected]>2025-03-21 13:32:14 +0000
commite29be82c8bc1b7e2dbf9f58dad4229d12968e1b4 (patch)
tree4ae9e7b784c82b96bcf870c3f61c62abad8a3811 /embassy-mspm0/src/timer.rs
parentfecb7a2b2b6f1953a2fe57557cb83d063ab5eea4 (diff)
parent91684a11c8a15b62a773a1ace40791fcf80fdad2 (diff)
Merge pull request #3966 from i509VCB/mspm0-init
Embassy for MSPM0
Diffstat (limited to 'embassy-mspm0/src/timer.rs')
-rw-r--r--embassy-mspm0/src/timer.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/embassy-mspm0/src/timer.rs b/embassy-mspm0/src/timer.rs
new file mode 100644
index 000000000..4441e5640
--- /dev/null
+++ b/embassy-mspm0/src/timer.rs
@@ -0,0 +1,48 @@
1#![macro_use]
2
3/// Amount of bits of a timer.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6pub enum TimerBits {
7 /// 16 bits.
8 Bits16,
9 /// 32 bits.
10 Bits32,
11}
12
13#[allow(private_bounds)]
14pub trait Timer: SealedTimer + 'static {
15 /// Amount of bits this timer has.
16 const BITS: TimerBits;
17}
18
19pub(crate) trait SealedTimer {
20 /// Registers for this timer.
21 ///
22 /// This is a raw pointer to the register block. The actual register block layout varies depending on the
23 /// timer type.
24 fn regs() -> *mut ();
25
26 /// Enable the interrupt corresponding to this timer.
27 unsafe fn enable_interrupt();
28}
29
30macro_rules! impl_timer {
31 ($name: ident, $bits: ident) => {
32 impl crate::timer::SealedTimer for crate::peripherals::$name {
33 fn regs() -> *mut () {
34 crate::pac::$name.as_ptr()
35 }
36
37 unsafe fn enable_interrupt() {
38 use embassy_hal_internal::interrupt::InterruptExt;
39 crate::interrupt::$name.unpend();
40 crate::interrupt::$name.enable();
41 }
42 }
43
44 impl crate::timer::Timer for crate::peripherals::$name {
45 const BITS: crate::timer::TimerBits = crate::timer::TimerBits::$bits;
46 }
47 };
48}