@@ -20,36 +20,18 @@ pub struct Rtc<T, M> {
20
20
_mode : M ,
21
21
}
22
22
23
- /// An extension trait for constructing the high level interface
24
- pub trait RtcExt : Deref < Target = rtc0:: RegisterBlock > + Sized {
25
- // The interrupt that belongs to this RTC instance.
26
- const INTERRUPT : Interrupt ;
27
-
28
- fn constrain ( self ) -> Rtc < Self , Stopped > ;
29
- }
30
-
31
- macro_rules! impl_rtc_ext {
32
- ( $( $rtc: ident, ) * ) => {
33
- $(
34
- impl RtcExt for $rtc {
35
- const INTERRUPT : Interrupt = Interrupt :: $rtc;
36
-
37
- fn constrain( self ) -> Rtc <$rtc, Stopped > {
38
- Rtc {
39
- periph: self ,
40
- _mode: Stopped ,
41
- }
42
- }
43
- }
44
- ) +
23
+ impl < T > Rtc < T , Stopped >
24
+ where
25
+ T : Instance ,
26
+ {
27
+ pub fn new ( rtc : T ) -> Self {
28
+ Rtc {
29
+ periph : rtc,
30
+ _mode : Stopped ,
31
+ }
45
32
}
46
33
}
47
34
48
- impl_rtc_ext ! ( RTC0 , RTC1 , ) ;
49
-
50
- #[ cfg( not( feature = "52810" ) ) ]
51
- impl_rtc_ext ! ( RTC2 , ) ;
52
-
53
35
/// Interrupts/Events that can be generated by the RTCn peripheral
54
36
pub enum RtcInterrupt {
55
37
Tick ,
@@ -70,7 +52,7 @@ pub enum RtcCompareReg {
70
52
71
53
impl < T , M > Rtc < T , M >
72
54
where
73
- T : RtcExt ,
55
+ T : Instance ,
74
56
{
75
57
/// Enable/start the Real Time Counter
76
58
pub fn enable_counter ( self ) -> Rtc < T , Started > {
@@ -221,7 +203,7 @@ pub enum Error {
221
203
222
204
impl < T > Rtc < T , Stopped >
223
205
where
224
- T : RtcExt ,
206
+ T : Instance ,
225
207
{
226
208
/// Set the prescaler for the RTC peripheral. 12 bits of range.
227
209
/// fRTC = 32_768 / (`prescaler` + 1 )
@@ -235,3 +217,25 @@ where
235
217
Ok ( ( ) )
236
218
}
237
219
}
220
+
221
+
222
+ /// Implemented by all RTC instances
223
+ pub trait Instance : Deref < Target = rtc0:: RegisterBlock > {
224
+ /// This interrupt associated with this RTC instance
225
+ const INTERRUPT : Interrupt ;
226
+ }
227
+
228
+ macro_rules! impl_instance {
229
+ ( $( $name: ident, ) * ) => {
230
+ $(
231
+ impl Instance for $name {
232
+ const INTERRUPT : Interrupt = Interrupt :: $name;
233
+ }
234
+ ) *
235
+ }
236
+ }
237
+
238
+ impl_instance ! ( RTC0 , RTC1 , ) ;
239
+
240
+ #[ cfg( not( feature = "52810" ) ) ]
241
+ impl_instance ! ( RTC2 , ) ;
0 commit comments