Skip to content

Commit 2b27399

Browse files
authored
rtc: split alarm value and enable into separate methods
1 parent a9d4b5a commit 2b27399

File tree

3 files changed

+35
-24
lines changed

3 files changed

+35
-24
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
- Added `rcc::Lsco` to use the low-speed oscillator output.
1010
- Added `Rtc::calibrate_lp` to calibrate the RTC.
1111
- Added `Rtc::recalibration_pending`.
12+
- Added `Rtc::is_alarm_{a,b}_en`.
13+
14+
## Changed
15+
- `Rtc.alarm_{a,b}` returns `Alarm` instead of `Option<Alarm>`.
1216

1317
### Fixed
1418
- Fixed a documentation bug in `rtc::Alarm`. Values are masked if `true`, but the documentation indicated they are masked if `false`.

hal/src/rtc/mod.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -576,18 +576,21 @@ impl Rtc {
576576
self.rtc.alrabinr.write(|w| w.ss().bits(alarm.ss));
577577
}
578578

579+
/// Returns `true` if alarm A is enabled.
580+
#[inline]
581+
#[must_use]
582+
pub fn is_alarm_a_en(&self) -> bool {
583+
self.rtc.cr.read().alrae().is_enabled()
584+
}
585+
579586
/// Get the value of alarm A.
580-
///
581-
/// Returns `None` if the alarm is not set.
582-
pub fn alarm_a(&self) -> Option<Alarm> {
583-
if self.rtc.cr.read().alrae().is_disabled() {
584-
None
585-
} else {
586-
Some(Alarm {
587-
val: self.rtc.alrmar.read().bits(),
588-
ss: self.rtc.alrabinr.read().ss().bits(),
589-
ss_mask: self.rtc.alrmassr.read().maskss().bits(),
590-
})
587+
#[inline]
588+
#[must_use]
589+
pub fn alarm_a(&self) -> Alarm {
590+
Alarm {
591+
val: self.rtc.alrmar.read().bits(),
592+
ss: self.rtc.alrabinr.read().ss().bits(),
593+
ss_mask: self.rtc.alrmassr.read().maskss().bits(),
591594
}
592595
}
593596

@@ -612,18 +615,21 @@ impl Rtc {
612615
self.rtc.alrbbinr.write(|w| w.ss().bits(alarm.ss));
613616
}
614617

618+
/// Returns `true` if alarm B is enabled.
619+
#[inline]
620+
#[must_use]
621+
pub fn is_alarm_b_en(&self) -> bool {
622+
self.rtc.cr.read().alrbe().is_enabled()
623+
}
624+
615625
/// Get the value of alarm B.
616-
///
617-
/// Returns `None` if the alarm is not set.
618-
pub fn alarm_b(&self) -> Option<Alarm> {
619-
if self.rtc.cr.read().alrbe().is_disabled() {
620-
None
621-
} else {
622-
Some(Alarm {
623-
val: self.rtc.alrmbr.read().bits(),
624-
ss: self.rtc.alrbbinr.read().ss().bits(),
625-
ss_mask: self.rtc.alrmbssr.read().maskss().bits(),
626-
})
626+
#[inline]
627+
#[must_use]
628+
pub fn alarm_b(&self) -> Alarm {
629+
Alarm {
630+
val: self.rtc.alrmbr.read().bits(),
631+
ss: self.rtc.alrbbinr.read().ss().bits(),
632+
ss_mask: self.rtc.alrmbssr.read().maskss().bits(),
627633
}
628634
}
629635

testsuite/src/rtc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ mod tests {
198198
while ta.rcc.bdcr.read().lserdy().is_not_ready() {}
199199
let mut rtc: Rtc = test_set_date_time_with_clk(rtc::Clk::Lse);
200200

201-
defmt::assert_eq!(rtc.alarm_a(), None);
201+
defmt::assert!(!rtc.is_alarm_a_en());
202202

203203
let alarm: Alarm = Alarm::from(unwrap!(rtc.time()) + Duration::seconds(1))
204204
.set_days_mask(true)
@@ -223,6 +223,7 @@ mod tests {
223223
}
224224
}
225225

226-
defmt::assert_eq!(rtc.alarm_a(), Some(alarm));
226+
defmt::assert!(rtc.is_alarm_a_en());
227+
defmt::assert_eq!(rtc.alarm_a(), alarm);
227228
}
228229
}

0 commit comments

Comments
 (0)