@@ -23,7 +23,7 @@ pub enum Error {
23
23
/// Real Time Clock peripheral
24
24
pub struct Rtc {
25
25
/// RTC Peripheral register definition
26
- pub regs : RTC ,
26
+ rtc : RTC ,
27
27
}
28
28
29
29
#[ cfg( feature = "defmt" ) ]
@@ -47,22 +47,22 @@ impl Rtc {
47
47
/// The `bypass` argument is `true` if you're using an external oscillator that
48
48
/// doesn't connect to `OSC32_IN`, such as a MEMS resonator.
49
49
pub fn new (
50
- regs : RTC ,
50
+ rtc : RTC ,
51
51
prediv_s : u16 ,
52
52
prediv_a : u8 ,
53
53
bypass : bool ,
54
54
apb1 : & mut APB1 ,
55
55
bdcr : & mut BDCR ,
56
56
pwr : & mut PWR ,
57
57
) -> Self {
58
- let mut result = Self { regs } ;
58
+ let mut result = Self { rtc } ;
59
59
60
60
enable_lse ( bdcr, bypass) ;
61
61
unlock ( apb1, pwr) ;
62
62
enable ( bdcr) ;
63
63
result. set_24h_fmt ( ) ;
64
64
65
- result. regs . prer . modify ( |_, w| {
65
+ result. rtc . prer . modify ( |_, w| {
66
66
w. prediv_s ( ) . bits ( prediv_s) ;
67
67
w. prediv_a ( ) . bits ( prediv_a)
68
68
} ) ;
@@ -72,22 +72,22 @@ impl Rtc {
72
72
73
73
/// Sets calendar clock to 24 hr format
74
74
pub fn set_24h_fmt ( & mut self ) {
75
- self . regs . cr . modify ( |_, w| w. fmt ( ) . set_bit ( ) ) ;
75
+ self . rtc . cr . modify ( |_, w| w. fmt ( ) . set_bit ( ) ) ;
76
76
}
77
77
/// Sets calendar clock to 12 hr format
78
78
pub fn set_12h_fmt ( & mut self ) {
79
- self . regs . cr . modify ( |_, w| w. fmt ( ) . clear_bit ( ) ) ;
79
+ self . rtc . cr . modify ( |_, w| w. fmt ( ) . clear_bit ( ) ) ;
80
80
}
81
81
82
82
/// Reads current hour format selection
83
83
pub fn is_24h_fmt ( & self ) -> bool {
84
- self . regs . cr . read ( ) . fmt ( ) . bit ( )
84
+ self . rtc . cr . read ( ) . fmt ( ) . bit ( )
85
85
}
86
86
87
87
/// Release the RTC peripheral
88
88
pub fn free ( self ) -> RTC {
89
89
// TODO(Sh3Rm4n): Disable peripheral before releasing it.
90
- self . regs
90
+ self . rtc
91
91
}
92
92
93
93
/// As described in Section 27.3.7 in RM0316,
@@ -98,20 +98,20 @@ impl Rtc {
98
98
F : FnMut ( & mut RTC ) ,
99
99
{
100
100
// Disable write protection
101
- self . regs . wpr . write ( |w| unsafe { w. bits ( 0xCA ) } ) ;
102
- self . regs . wpr . write ( |w| unsafe { w. bits ( 0x53 ) } ) ;
101
+ self . rtc . wpr . write ( |w| unsafe { w. bits ( 0xCA ) } ) ;
102
+ self . rtc . wpr . write ( |w| unsafe { w. bits ( 0x53 ) } ) ;
103
103
// Enter init mode
104
- let isr = self . regs . isr . read ( ) ;
104
+ let isr = self . rtc . isr . read ( ) ;
105
105
if isr. initf ( ) . bit_is_clear ( ) {
106
- self . regs . isr . modify ( |_, w| w. init ( ) . set_bit ( ) ) ;
107
- while self . regs . isr . read ( ) . initf ( ) . bit_is_clear ( ) { }
106
+ self . rtc . isr . modify ( |_, w| w. init ( ) . set_bit ( ) ) ;
107
+ while self . rtc . isr . read ( ) . initf ( ) . bit_is_clear ( ) { }
108
108
}
109
109
// Invoke closure
110
- closure ( & mut self . regs ) ;
110
+ closure ( & mut self . rtc ) ;
111
111
// Exit init mode
112
- self . regs . isr . modify ( |_, w| w. init ( ) . clear_bit ( ) ) ;
112
+ self . rtc . isr . modify ( |_, w| w. init ( ) . clear_bit ( ) ) ;
113
113
// wait for last write to be done
114
- while !self . regs . isr . read ( ) . initf ( ) . bit_is_clear ( ) { }
114
+ while !self . rtc . isr . read ( ) . initf ( ) . bit_is_clear ( ) { }
115
115
}
116
116
}
117
117
@@ -125,7 +125,7 @@ impl Rtcc for Rtc {
125
125
let ( ht, hu) = bcd2_encode ( time. hour ( ) ) ?;
126
126
let ( mnt, mnu) = bcd2_encode ( time. minute ( ) ) ?;
127
127
let ( st, su) = bcd2_encode ( time. second ( ) ) ?;
128
- self . regs . tr . write ( |w| {
128
+ self . rtc . tr . write ( |w| {
129
129
w. ht ( ) . bits ( ht) ;
130
130
w. hu ( ) . bits ( hu) ;
131
131
w. mnt ( ) . bits ( mnt) ;
@@ -143,7 +143,7 @@ impl Rtcc for Rtc {
143
143
return Err ( Error :: InvalidInputData ) ;
144
144
}
145
145
let ( st, su) = bcd2_encode ( seconds as u32 ) ?;
146
- self . modify ( |regs| regs . tr . modify ( |_, w| w. st ( ) . bits ( st) . su ( ) . bits ( su) ) ) ;
146
+ self . modify ( |rtc| rtc . tr . modify ( |_, w| w. st ( ) . bits ( st) . su ( ) . bits ( su) ) ) ;
147
147
148
148
Ok ( ( ) )
149
149
}
@@ -153,7 +153,7 @@ impl Rtcc for Rtc {
153
153
return Err ( Error :: InvalidInputData ) ;
154
154
}
155
155
let ( mnt, mnu) = bcd2_encode ( minutes as u32 ) ?;
156
- self . modify ( |regs| regs . tr . modify ( |_, w| w. mnt ( ) . bits ( mnt) . mnu ( ) . bits ( mnu) ) ) ;
156
+ self . modify ( |rtc| rtc . tr . modify ( |_, w| w. mnt ( ) . bits ( mnt) . mnu ( ) . bits ( mnu) ) ) ;
157
157
158
158
Ok ( ( ) )
159
159
}
@@ -165,7 +165,7 @@ impl Rtcc for Rtc {
165
165
Hours :: AM ( _h) | Hours :: PM ( _h) => self . set_12h_fmt ( ) ,
166
166
}
167
167
168
- self . regs . tr . modify ( |_, w| w. ht ( ) . bits ( ht) . hu ( ) . bits ( hu) ) ;
168
+ self . rtc . tr . modify ( |_, w| w. ht ( ) . bits ( ht) . hu ( ) . bits ( hu) ) ;
169
169
170
170
Ok ( ( ) )
171
171
}
@@ -174,7 +174,7 @@ impl Rtcc for Rtc {
174
174
if !( 1 ..=7 ) . contains ( & weekday) {
175
175
return Err ( Error :: InvalidInputData ) ;
176
176
}
177
- self . modify ( |regs| regs . dr . modify ( |_, w| unsafe { w. wdu ( ) . bits ( weekday) } ) ) ;
177
+ self . modify ( |rtc| rtc . dr . modify ( |_, w| unsafe { w. wdu ( ) . bits ( weekday) } ) ) ;
178
178
179
179
Ok ( ( ) )
180
180
}
@@ -184,7 +184,7 @@ impl Rtcc for Rtc {
184
184
return Err ( Error :: InvalidInputData ) ;
185
185
}
186
186
let ( dt, du) = bcd2_encode ( day as u32 ) ?;
187
- self . modify ( |regs| regs . dr . modify ( |_, w| w. dt ( ) . bits ( dt) . du ( ) . bits ( du) ) ) ;
187
+ self . modify ( |rtc| rtc . dr . modify ( |_, w| w. dt ( ) . bits ( dt) . du ( ) . bits ( du) ) ) ;
188
188
189
189
Ok ( ( ) )
190
190
}
@@ -194,7 +194,7 @@ impl Rtcc for Rtc {
194
194
return Err ( Error :: InvalidInputData ) ;
195
195
}
196
196
let ( mt, mu) = bcd2_encode ( month as u32 ) ?;
197
- self . modify ( |regs| regs . dr . modify ( |_, w| w. mt ( ) . bit ( mt > 0 ) . mu ( ) . bits ( mu) ) ) ;
197
+ self . modify ( |rtc| rtc . dr . modify ( |_, w| w. mt ( ) . bit ( mt > 0 ) . mu ( ) . bits ( mu) ) ) ;
198
198
199
199
Ok ( ( ) )
200
200
}
@@ -204,7 +204,7 @@ impl Rtcc for Rtc {
204
204
return Err ( Error :: InvalidInputData ) ;
205
205
}
206
206
let ( yt, yu) = bcd2_encode ( year as u32 ) ?;
207
- self . modify ( |regs| regs . dr . modify ( |_, w| w. yt ( ) . bits ( yt) . yu ( ) . bits ( yu) ) ) ;
207
+ self . modify ( |rtc| rtc . dr . modify ( |_, w| w. yt ( ) . bits ( yt) . yu ( ) . bits ( yu) ) ) ;
208
208
209
209
Ok ( ( ) )
210
210
}
@@ -220,7 +220,7 @@ impl Rtcc for Rtc {
220
220
let ( mt, mu) = bcd2_encode ( date. month ( ) ) ?;
221
221
let ( dt, du) = bcd2_encode ( date. day ( ) ) ?;
222
222
223
- self . regs . dr . write ( |w| {
223
+ self . rtc . dr . write ( |w| {
224
224
w. dt ( ) . bits ( dt) ;
225
225
w. du ( ) . bits ( du) ;
226
226
w. mt ( ) . bit ( mt > 0 ) ;
@@ -246,7 +246,7 @@ impl Rtcc for Rtc {
246
246
let ( mnt, mnu) = bcd2_encode ( date. minute ( ) ) ?;
247
247
let ( st, su) = bcd2_encode ( date. second ( ) ) ?;
248
248
249
- self . regs . dr . write ( |w| {
249
+ self . rtc . dr . write ( |w| {
250
250
w. dt ( ) . bits ( dt) ;
251
251
w. du ( ) . bits ( du) ;
252
252
w. mt ( ) . bit ( mt > 0 ) ;
@@ -255,7 +255,7 @@ impl Rtcc for Rtc {
255
255
w. yu ( ) . bits ( yu)
256
256
} ) ;
257
257
258
- self . regs . tr . write ( |w| {
258
+ self . rtc . tr . write ( |w| {
259
259
w. ht ( ) . bits ( ht) ;
260
260
w. hu ( ) . bits ( hu) ;
261
261
w. mnt ( ) . bits ( mnt) ;
@@ -269,19 +269,19 @@ impl Rtcc for Rtc {
269
269
}
270
270
271
271
fn get_seconds ( & mut self ) -> Result < u8 , Self :: Error > {
272
- let tr = self . regs . tr . read ( ) ;
272
+ let tr = self . rtc . tr . read ( ) ;
273
273
let seconds = bcd2_decode ( tr. st ( ) . bits ( ) , tr. su ( ) . bits ( ) ) ;
274
274
Ok ( seconds as u8 )
275
275
}
276
276
277
277
fn get_minutes ( & mut self ) -> Result < u8 , Self :: Error > {
278
- let tr = self . regs . tr . read ( ) ;
278
+ let tr = self . rtc . tr . read ( ) ;
279
279
let minutes = bcd2_decode ( tr. mnt ( ) . bits ( ) , tr. mnu ( ) . bits ( ) ) ;
280
280
Ok ( minutes as u8 )
281
281
}
282
282
283
283
fn get_hours ( & mut self ) -> Result < Hours , Self :: Error > {
284
- let tr = self . regs . tr . read ( ) ;
284
+ let tr = self . rtc . tr . read ( ) ;
285
285
let hours = bcd2_decode ( tr. ht ( ) . bits ( ) , tr. hu ( ) . bits ( ) ) ;
286
286
if self . is_24h_fmt ( ) {
287
287
return Ok ( Hours :: H24 ( hours as u8 ) ) ;
@@ -306,26 +306,26 @@ impl Rtcc for Rtc {
306
306
}
307
307
308
308
fn get_weekday ( & mut self ) -> Result < u8 , Self :: Error > {
309
- let dr = self . regs . dr . read ( ) ;
309
+ let dr = self . rtc . dr . read ( ) ;
310
310
let weekday = bcd2_decode ( dr. wdu ( ) . bits ( ) , 0x00 ) ;
311
311
Ok ( weekday as u8 )
312
312
}
313
313
314
314
fn get_day ( & mut self ) -> Result < u8 , Self :: Error > {
315
- let dr = self . regs . dr . read ( ) ;
315
+ let dr = self . rtc . dr . read ( ) ;
316
316
let day = bcd2_decode ( dr. dt ( ) . bits ( ) , dr. du ( ) . bits ( ) ) ;
317
317
Ok ( day as u8 )
318
318
}
319
319
320
320
fn get_month ( & mut self ) -> Result < u8 , Self :: Error > {
321
- let dr = self . regs . dr . read ( ) ;
321
+ let dr = self . rtc . dr . read ( ) ;
322
322
let mt: u8 = if dr. mt ( ) . bit ( ) { 1 } else { 0 } ;
323
323
let month = bcd2_decode ( mt, dr. mu ( ) . bits ( ) ) ;
324
324
Ok ( month as u8 )
325
325
}
326
326
327
327
fn get_year ( & mut self ) -> Result < u16 , Self :: Error > {
328
- let dr = self . regs . dr . read ( ) ;
328
+ let dr = self . rtc . dr . read ( ) ;
329
329
let year = bcd2_decode ( dr. yt ( ) . bits ( ) , dr. yu ( ) . bits ( ) ) ;
330
330
Ok ( year as u16 )
331
331
}
0 commit comments