Skip to content

Commit 9e49fd3

Browse files
Adding Tokens so that peripherals that share bits in the RCC can know that they have been enabled without taking ownership of their respective rec struct. (#48)
fixes #47
1 parent 144bca6 commit 9e49fd3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/rcc/rec.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,21 @@ pub enum LowPowerMode {
100100
Enabled,
101101
}
102102

103+
/// A Token to represent a peripheral has been enabled
104+
pub struct Token<P> {
105+
ph: PhantomData<P>,
106+
}
107+
108+
/// A trait to represent that a peripheral can be turned into a token
109+
pub trait RecTokenizer: ResetEnable + Sized {
110+
/// Turns the ResetEnable into a token
111+
fn tokenize(self) -> Token<Self> {
112+
self.enable().reset();
113+
114+
Token { ph: PhantomData {} }
115+
}
116+
}
117+
103118
impl Rcc {
104119
/// Returns all the peripherals resets / enables / kernel clocks.
105120
///
@@ -459,6 +474,14 @@ macro_rules! variant_return_type {
459474
};
460475
}
461476

477+
macro_rules! tokenable {
478+
($($TK:ty),*) => {
479+
$(
480+
impl RecTokenizer for $TK {}
481+
)*
482+
};
483+
}
484+
462485
// Enumerate all peripherals and optional clock multiplexers
463486
//
464487
// Peripherals are grouped by bus for convenience. Each bus is specified like:
@@ -646,3 +669,5 @@ peripheral_reset_and_enable_control! {
646669
I3c2 [kernel clk: I3c2(Variant) I3C ccipr4 "I3C2"]
647670
];
648671
}
672+
673+
tokenable!(Fdcan);

0 commit comments

Comments
 (0)