@@ -11,29 +11,9 @@ use crate::pac::{rtc0, Interrupt, NVIC, RTC0, RTC1};
1111#[ cfg( any( feature = "52832" , feature = "52833" , feature = "52840" ) ) ]
1212use crate :: pac:: RTC2 ;
1313
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-
2114/// An opaque high level interface to an RTC peripheral.
22- pub struct Rtc < T , M > {
15+ pub struct Rtc < T > {
2316 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- }
3717}
3818
3919/// Interrupts/Events that can be generated by the RTCn peripheral.
@@ -54,30 +34,34 @@ pub enum RtcCompareReg {
5434 Compare3 ,
5535}
5636
57- impl < T , M > Rtc < T , M >
37+ impl < T > Rtc < T >
5838where
5939 T : Instance ,
6040{
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+
6153 /// Enable/start the Real Time Counter.
62- pub fn enable_counter ( self ) -> Rtc < T , Started > {
54+ pub fn enable_counter ( & self ) {
6355 unsafe {
6456 self . periph . tasks_start . write ( |w| w. bits ( 1 ) ) ;
6557 }
66- Rtc {
67- periph : self . periph ,
68- _mode : Started ,
69- }
7058 }
7159
7260 /// Disable/stop the Real Time Counter.
73- pub fn disable_counter ( self ) -> Rtc < T , Stopped > {
61+ pub fn disable_counter ( & self ) {
7462 unsafe {
7563 self . periph . tasks_stop . write ( |w| w. bits ( 1 ) ) ;
7664 }
77- Rtc {
78- periph : self . periph ,
79- _mode : Stopped ,
80- }
8165 }
8266
8367 /// Enable the generation of a hardware interrupt from a given stimulus.
@@ -234,23 +218,6 @@ pub enum Error {
234218 CompareOutOfRange ,
235219}
236220
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-
254221/// Implemented by all RTC instances.
255222pub trait Instance : Deref < Target = rtc0:: RegisterBlock > {
256223 /// The interrupt associated with this RTC instance.
0 commit comments