Skip to content

Commit d5035f4

Browse files
authored
Merge pull request #44 from braun-embedded/rtc
RTC bugfix and improvements
2 parents fbf587e + 5ad4d02 commit d5035f4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub use embedded_hal::{
22
prelude::*,
33
digital::v2::*,
44
adc::OneShot as _,
5+
timer::Cancel as _,
56
watchdog::{
67
Watchdog as _,
78
WatchdogEnable as _,

src/rtc.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,18 @@ impl Default for Interrupts {
453453

454454

455455
/// The RTC wakeup timer
456+
///
457+
/// This timer can be used in two ways:
458+
/// 1. Continually call `wait` until it returns `Ok(())`.
459+
/// 2. Set up the RTC interrupt.
460+
///
461+
/// If you use an interrupt, you should still call `wait` once, after the
462+
/// interrupt fired. This should return `Ok(())` immediately. Doing this will
463+
/// reset the timer flag. If you don't do this, the interrupt will not fire
464+
/// again, if you go to sleep.
465+
///
466+
/// You don't need to call `wait`, if you call `cancel`, as that also resets the
467+
/// flag. Restarting the timer by calling `start` will also reset the flag.
456468
pub struct WakeupTimer<'r> {
457469
rtc: &'r mut RTC,
458470
}
@@ -469,13 +481,15 @@ impl timer::CountDown for WakeupTimer<'_> {
469481
///
470482
/// # Panics
471483
///
472-
/// The `delay` argument supports 17 bits. Panics, if a value larger than
473-
/// 17 bits is passed.
484+
/// The `delay` argument must be in the range `1 <= delay <= 2^17`.
485+
/// Panics, if `delay` is outside of that range.
474486
fn start<T>(&mut self, delay: T)
475487
where T: Into<Self::Time>
476488
{
477489
let delay = delay.into();
478-
assert!(delay < 2^17);
490+
assert!(1 <= delay && delay <= 2^17);
491+
492+
let delay = delay - 1;
479493

480494
// Can't panic, as the error type is `Void`.
481495
self.cancel().unwrap();
@@ -535,7 +549,6 @@ impl timer::Cancel for WakeupTimer<'_> {
535549

536550
// Clear wakeup timer flag
537551
rtc.isr.modify(|_, w| w.wutf().clear_bit());
538-
// while self.rtc.isr.read().wutf().bit_is_set() {}
539552

540553
// According to the reference manual, section 26.7.4, the WUTF flag
541554
// must be cleared at least 1.5 RTCCLK periods "before WUTF is set

0 commit comments

Comments
 (0)