@@ -11,29 +11,9 @@ use crate::pac::{rtc0, Interrupt, NVIC, RTC0, RTC1};
11
11
#[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
12
12
use crate :: pac:: RTC2 ;
13
13
14
- // Zero Size Type State structs
15
-
16
- /// The RTC has been stopped.
17
- pub struct Stopped ;
18
- /// The RTC has been started.
19
- pub struct Started ;
20
-
21
14
/// An opaque high level interface to an RTC peripheral.
22
- pub struct Rtc < T , M > {
15
+ pub struct Rtc < T > {
23
16
periph : T ,
24
- _mode : M ,
25
- }
26
-
27
- impl < T > Rtc < T , Stopped >
28
- where
29
- T : Instance ,
30
- {
31
- pub fn new ( rtc : T ) -> Self {
32
- Rtc {
33
- periph : rtc,
34
- _mode : Stopped ,
35
- }
36
- }
37
17
}
38
18
39
19
/// Interrupts/Events that can be generated by the RTCn peripheral.
@@ -54,30 +34,34 @@ pub enum RtcCompareReg {
54
34
Compare3 ,
55
35
}
56
36
57
- impl < T , M > Rtc < T , M >
37
+ impl < T > Rtc < T >
58
38
where
59
39
T : Instance ,
60
40
{
41
+ /// Creates a new RTC peripheral instance with a 12 bits prescaler.
42
+ /// fRTC = 32_768 / (`prescaler` + 1 )
43
+ pub fn new ( rtc : T , prescaler : u32 ) -> Result < Self , Error > {
44
+ if prescaler >= ( 1 << 12 ) {
45
+ return Err ( Error :: PrescalerOutOfRange ) ;
46
+ }
47
+
48
+ unsafe { rtc. prescaler . write ( |w| w. bits ( prescaler) ) } ;
49
+
50
+ Ok ( Rtc { periph : rtc } )
51
+ }
52
+
61
53
/// Enable/start the Real Time Counter.
62
- pub fn enable_counter ( self ) -> Rtc < T , Started > {
54
+ pub fn enable_counter ( & self ) {
63
55
unsafe {
64
56
self . periph . tasks_start . write ( |w| w. bits ( 1 ) ) ;
65
57
}
66
- Rtc {
67
- periph : self . periph ,
68
- _mode : Started ,
69
- }
70
58
}
71
59
72
60
/// Disable/stop the Real Time Counter.
73
- pub fn disable_counter ( self ) -> Rtc < T , Stopped > {
61
+ pub fn disable_counter ( & self ) {
74
62
unsafe {
75
63
self . periph . tasks_stop . write ( |w| w. bits ( 1 ) ) ;
76
64
}
77
- Rtc {
78
- periph : self . periph ,
79
- _mode : Stopped ,
80
- }
81
65
}
82
66
83
67
/// Enable the generation of a hardware interrupt from a given stimulus.
@@ -234,23 +218,6 @@ pub enum Error {
234
218
CompareOutOfRange ,
235
219
}
236
220
237
- impl < T > Rtc < T , Stopped >
238
- where
239
- T : Instance ,
240
- {
241
- /// Set the prescaler for the RTC peripheral. 12 bits of range.
242
- /// fRTC = 32_768 / (`prescaler` + 1 )
243
- pub fn set_prescaler ( & mut self , prescaler : u32 ) -> Result < ( ) , Error > {
244
- if prescaler >= ( 1 << 12 ) {
245
- return Err ( Error :: PrescalerOutOfRange ) ;
246
- }
247
-
248
- unsafe { self . periph . prescaler . write ( |w| w. bits ( prescaler) ) } ;
249
-
250
- Ok ( ( ) )
251
- }
252
- }
253
-
254
221
/// Implemented by all RTC instances.
255
222
pub trait Instance : Deref < Target = rtc0:: RegisterBlock > {
256
223
/// The interrupt associated with this RTC instance.
0 commit comments