44
55use crate :: bb;
66use crate :: pac:: rtc:: { dr, tr} ;
7- use crate :: pac:: { self , rcc :: RegisterBlock , PWR , RCC , RTC } ;
7+ use crate :: pac:: { self , PWR , RCC , RTC } ;
88use crate :: rcc:: Enable ;
99use core:: fmt;
1010use fugit:: RateExtU32 ;
@@ -152,28 +152,28 @@ impl Rtc {
152152 // Enable write protect
153153
154154 unsafe {
155- let rcc = & ( * RCC :: ptr ( ) ) ;
155+ let mut rcc = RCC :: steal ( ) ;
156156 // As per the sample code, unlock comes first. (Enable PWR and DBP)
157- result. unlock ( rcc, pwr) ;
157+ result. unlock ( & mut rcc, pwr) ;
158158 match result. clock_source {
159159 ClockSource :: Lse ( mode) => {
160160 // If necessary, enable the LSE.
161161 if rcc. bdcr ( ) . read ( ) . lserdy ( ) . bit_is_clear ( ) {
162- result. enable_lse ( rcc, mode) ;
162+ result. enable_lse ( & mut rcc, mode) ;
163163 }
164164 // Set clock source to LSE.
165165 rcc. bdcr ( ) . modify ( |_, w| w. rtcsel ( ) . lse ( ) ) ;
166166 }
167167 ClockSource :: Lsi => {
168168 // If necessary, enable the LSE.
169169 if rcc. csr ( ) . read ( ) . lsirdy ( ) . bit_is_clear ( ) {
170- result. enable_lsi ( rcc) ;
170+ result. enable_lsi ( & mut rcc) ;
171171 }
172172 // Set clock source to LSI.
173173 rcc. bdcr ( ) . modify ( |_, w| w. rtcsel ( ) . lsi ( ) ) ;
174174 }
175175 }
176- result. enable ( rcc) ;
176+ result. enable ( & mut rcc) ;
177177 }
178178
179179 result. modify ( true , |regs| {
@@ -191,7 +191,7 @@ impl Rtc {
191191
192192 /// Enable the low frequency external oscillator. This is the only mode currently
193193 /// 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 ) {
195195 unsafe {
196196 // Force a reset of the backup domain.
197197 self . backup_reset ( rcc) ;
@@ -221,15 +221,15 @@ impl Rtc {
221221 Self :: with_config ( regs, pwr, ClockSource :: Lsi , prediv_s, prediv_a)
222222 }
223223
224- fn enable_lsi ( & mut self , rcc : & RegisterBlock ) {
224+ fn enable_lsi ( & mut self , rcc : & mut RCC ) {
225225 // Force a reset of the backup domain.
226226 self . backup_reset ( rcc) ;
227227 // Enable the LSI.
228228 rcc. csr ( ) . modify ( |_, w| w. lsion ( ) . on ( ) ) ;
229229 while rcc. csr ( ) . read ( ) . lsirdy ( ) . is_not_ready ( ) { }
230230 }
231231
232- fn unlock ( & mut self , rcc : & RegisterBlock , pwr : & mut PWR ) {
232+ fn unlock ( & mut self , rcc : & mut RCC , pwr : & mut PWR ) {
233233 // Enable the backup interface
234234 // Set APB1 - Bit 28 (PWREN)
235235 PWR :: enable ( rcc) ;
@@ -238,7 +238,7 @@ impl Rtc {
238238 pwr. cr ( ) . modify ( |_, w| w. dbp ( ) . set_bit ( ) ) ;
239239 }
240240
241- fn backup_reset ( & mut self , rcc : & RegisterBlock ) {
241+ fn backup_reset ( & mut self , rcc : & mut RCC ) {
242242 unsafe {
243243 // Set BDCR - Bit 16 (BDRST)
244244 bb:: set ( rcc. bdcr ( ) , 16 ) ;
@@ -247,7 +247,7 @@ impl Rtc {
247247 }
248248 }
249249
250- fn enable ( & mut self , rcc : & RegisterBlock ) {
250+ fn enable ( & mut self , rcc : & mut RCC ) {
251251 // Start the actual RTC.
252252 // Set BDCR - Bit 15 (RTCEN)
253253 unsafe {
0 commit comments