@@ -8,7 +8,7 @@ use crate::pac::{self, rcc::RegisterBlock, PWR, RCC, RTC};
8
8
use crate :: rcc:: Enable ;
9
9
use core:: fmt;
10
10
use core:: marker:: PhantomData ;
11
- use fugit:: { Duration , ExtU32 , Rate , RateExtU32 } ;
11
+ use fugit:: RateExtU32 ;
12
12
use time:: { Date , PrimitiveDateTime , Time , Weekday } ;
13
13
14
14
/// Invalid input error
@@ -541,51 +541,53 @@ impl<CS: FrequencySource> Rtc<CS> {
541
541
)
542
542
}
543
543
544
- /// Configures the wakeup timer to trigger periodically every `interval` seconds
544
+ /// Configures the wakeup timer to trigger periodically every `interval` duration
545
545
///
546
546
/// # Panics
547
547
///
548
- /// Panics if interval is greater than 2¹⁷-1.
548
+ /// Panics if interval is greater than 2¹⁷-1 seconds .
549
549
pub fn enable_wakeup ( & mut self , interval : fugit:: MicrosDurationU64 ) {
550
550
self . modify ( false , |regs| {
551
551
regs. cr . modify ( |_, w| w. wute ( ) . clear_bit ( ) ) ;
552
552
regs. isr . modify ( |_, w| w. wutf ( ) . clear_bit ( ) ) ;
553
553
while regs. isr . read ( ) . wutwf ( ) . bit_is_clear ( ) { }
554
554
555
- if interval < 32u32 . secs :: < 1 , 1_000_000 > ( ) {
555
+ use crate :: pac:: rtc:: cr:: WUCKSEL_A ;
556
+ if interval < fugit:: MicrosDurationU64 :: secs ( 32 ) {
556
557
// Use RTCCLK as the wakeup timer clock source
557
- let frequency: Rate < u64 , 1 , 1 > = ( CS :: frequency ( ) / 2 ) . into ( ) ;
558
- let freq_duration: Duration < u64 , 1 , 1000000 > = frequency. into_duration ( ) ;
558
+ let frequency: fugit :: Hertz < u64 > = ( CS :: frequency ( ) / 2 ) . into ( ) ;
559
+ let freq_duration: fugit :: MicrosDurationU64 = frequency. into_duration ( ) ;
559
560
let ticks_per_interval = interval / freq_duration;
560
561
561
562
let mut prescaler = 0 ;
562
563
while ticks_per_interval >> prescaler > 1 << 16 {
563
564
prescaler += 1 ;
564
565
}
565
566
566
- let prescaler_bits = match prescaler {
567
- 0 => 0b11 , // RTCCLK/2
568
- 1 => 0b10 , // RTCCLK/4
569
- 2 => 0b01 , // RTCCLK/8
570
- 3 => 0b00 , // RTCCLK/16
567
+ let wucksel = match prescaler {
568
+ 0 => WUCKSEL_A :: Div2 ,
569
+ 1 => WUCKSEL_A :: Div4 ,
570
+ 2 => WUCKSEL_A :: Div8 ,
571
+ 3 => WUCKSEL_A :: Div16 ,
571
572
_ => unreachable ! ( "Longer durations should use ck_spre" ) ,
572
573
} ;
573
574
574
575
let interval = u16:: try_from ( ( ticks_per_interval >> prescaler) - 1 ) . unwrap ( ) ;
575
576
576
- regs. cr
577
- . modify ( |_, w| unsafe { w. wucksel ( ) . bits ( prescaler_bits) } ) ;
577
+ regs. cr . modify ( |_, w| w. wucksel ( ) . variant ( wucksel) ) ;
578
578
regs. wutr . write ( |w| w. wut ( ) . bits ( interval) ) ;
579
579
} else {
580
580
// Use ck_spre (1Hz) as the wakeup timer clock source
581
581
let interval = interval. to_secs ( ) ;
582
582
if interval > 1 << 16 {
583
- regs. cr . modify ( |_, w| unsafe { w. wucksel ( ) . bits ( 0b110 ) } ) ;
583
+ regs. cr
584
+ . modify ( |_, w| w. wucksel ( ) . variant ( WUCKSEL_A :: ClockSpareWithOffset ) ) ;
584
585
let interval = u16:: try_from ( interval - ( 1 << 16 ) - 1 )
585
586
. expect ( "Interval was too large for wakeup timer" ) ;
586
587
regs. wutr . write ( |w| w. wut ( ) . bits ( interval) ) ;
587
588
} else {
588
- regs. cr . modify ( |_, w| unsafe { w. wucksel ( ) . bits ( 0b100 ) } ) ;
589
+ regs. cr
590
+ . modify ( |_, w| w. wucksel ( ) . variant ( WUCKSEL_A :: ClockSpare ) ) ;
589
591
let interval = u16:: try_from ( interval - 1 )
590
592
. expect ( "Interval was too large for wakeup timer" ) ;
591
593
regs. wutr . write ( |w| w. wut ( ) . bits ( interval) ) ;
0 commit comments