4
4
5
5
use crate :: bb;
6
6
use crate :: pac:: rtc:: { dr, tr} ;
7
- use crate :: pac:: { self , rcc :: RegisterBlock , PWR , RCC , RTC } ;
7
+ use crate :: pac:: { self , PWR , RCC , RTC } ;
8
8
use crate :: rcc:: Enable ;
9
9
use core:: fmt;
10
10
use fugit:: RateExtU32 ;
@@ -152,28 +152,28 @@ impl Rtc {
152
152
// Enable write protect
153
153
154
154
unsafe {
155
- let rcc = & ( * RCC :: ptr ( ) ) ;
155
+ let mut rcc = RCC :: steal ( ) ;
156
156
// As per the sample code, unlock comes first. (Enable PWR and DBP)
157
- result. unlock ( rcc, pwr) ;
157
+ result. unlock ( & mut rcc, pwr) ;
158
158
match result. clock_source {
159
159
ClockSource :: Lse ( mode) => {
160
160
// If necessary, enable the LSE.
161
161
if rcc. bdcr ( ) . read ( ) . lserdy ( ) . bit_is_clear ( ) {
162
- result. enable_lse ( rcc, mode) ;
162
+ result. enable_lse ( & mut rcc, mode) ;
163
163
}
164
164
// Set clock source to LSE.
165
165
rcc. bdcr ( ) . modify ( |_, w| w. rtcsel ( ) . lse ( ) ) ;
166
166
}
167
167
ClockSource :: Lsi => {
168
168
// If necessary, enable the LSE.
169
169
if rcc. csr ( ) . read ( ) . lsirdy ( ) . bit_is_clear ( ) {
170
- result. enable_lsi ( rcc) ;
170
+ result. enable_lsi ( & mut rcc) ;
171
171
}
172
172
// Set clock source to LSI.
173
173
rcc. bdcr ( ) . modify ( |_, w| w. rtcsel ( ) . lsi ( ) ) ;
174
174
}
175
175
}
176
- result. enable ( rcc) ;
176
+ result. enable ( & mut rcc) ;
177
177
}
178
178
179
179
result. modify ( true , |regs| {
@@ -191,7 +191,7 @@ impl Rtc {
191
191
192
192
/// Enable the low frequency external oscillator. This is the only mode currently
193
193
/// supported, to avoid exposing the `CR` and `CRS` registers.
194
- fn enable_lse ( & mut self , rcc : & RegisterBlock , mode : LSEClockMode ) {
194
+ fn enable_lse ( & mut self , rcc : & mut RCC , mode : LSEClockMode ) {
195
195
unsafe {
196
196
// Force a reset of the backup domain.
197
197
self . backup_reset ( rcc) ;
@@ -221,15 +221,15 @@ impl Rtc {
221
221
Self :: with_config ( regs, pwr, ClockSource :: Lsi , prediv_s, prediv_a)
222
222
}
223
223
224
- fn enable_lsi ( & mut self , rcc : & RegisterBlock ) {
224
+ fn enable_lsi ( & mut self , rcc : & mut RCC ) {
225
225
// Force a reset of the backup domain.
226
226
self . backup_reset ( rcc) ;
227
227
// Enable the LSI.
228
228
rcc. csr ( ) . modify ( |_, w| w. lsion ( ) . on ( ) ) ;
229
229
while rcc. csr ( ) . read ( ) . lsirdy ( ) . is_not_ready ( ) { }
230
230
}
231
231
232
- fn unlock ( & mut self , rcc : & RegisterBlock , pwr : & mut PWR ) {
232
+ fn unlock ( & mut self , rcc : & mut RCC , pwr : & mut PWR ) {
233
233
// Enable the backup interface
234
234
// Set APB1 - Bit 28 (PWREN)
235
235
PWR :: enable ( rcc) ;
@@ -238,7 +238,7 @@ impl Rtc {
238
238
pwr. cr ( ) . modify ( |_, w| w. dbp ( ) . set_bit ( ) ) ;
239
239
}
240
240
241
- fn backup_reset ( & mut self , rcc : & RegisterBlock ) {
241
+ fn backup_reset ( & mut self , rcc : & mut RCC ) {
242
242
unsafe {
243
243
// Set BDCR - Bit 16 (BDRST)
244
244
bb:: set ( rcc. bdcr ( ) , 16 ) ;
@@ -247,7 +247,7 @@ impl Rtc {
247
247
}
248
248
}
249
249
250
- fn enable ( & mut self , rcc : & RegisterBlock ) {
250
+ fn enable ( & mut self , rcc : & mut RCC ) {
251
251
// Start the actual RTC.
252
252
// Set BDCR - Bit 15 (RTCEN)
253
253
unsafe {
0 commit comments