Skip to content

Commit 7d19bee

Browse files
committed
improve RTC documentation
1 parent d19a96c commit 7d19bee

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

src/rtc.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
11
/*!
22
Real time clock
3-
4-
A continuously running clock that counts seconds. It is part of the backup domain which means
5-
that the counter is not affected by system resets or standby mode. If Vbat is connected, it is
6-
not reset even if the rest of the device is powered off. This allows it to be used to wake the
7-
CPU when it is in low power mode.
8-
9-
Since it is part of the backup domain, write access to it must be enabled before the RTC can be
10-
used. See `backup_domain` for more details.
11-
12-
See examples/rtc.rs and examples/blinky_rtc.rs for usage examples.
133
*/
14-
154
use crate::pac::{RCC, RTC};
165

176
use crate::backup_domain::BackupDomain;
@@ -23,8 +12,22 @@ use core::convert::Infallible;
2312
const LSE_HERTZ: u32 = 32_768;
2413

2514
/**
26-
Interface to the real time clock
15+
Real time clock
16+
17+
A continuously running clock that counts seconds¹. It is part of the backup domain which means
18+
that the counter is not affected by system resets or standby mode. If Vbat is connected, it is
19+
not reset even if the rest of the device is powered off. This allows it to be used to wake the
20+
CPU when it is in low power mode.
21+
22+
23+
See [examples/rtc.rs] and [examples/blinky_rtc.rs] for usage examples.
24+
25+
1: Unless configured to another frequency using [select_frequency](struct.Rtc.html#method.select_frequency)
26+
27+
[examples/rtc.rs]: https://github.com/stm32-rs/stm32f1xx-hal/blob/v0.6.1/examples/rtc.rs
28+
[examples/blinky_rtc.rs]: https://github.com/stm32-rs/stm32f1xx-hal/blob/v0.6.1/examples/blinky_rtc.rs
2729
*/
30+
2831
pub struct Rtc {
2932
regs: RTC,
3033
}
@@ -33,6 +36,12 @@ impl Rtc {
3336
/**
3437
Initialises the RTC. The `BackupDomain` struct is created by
3538
`Rcc.bkp.constrain()`.
39+
40+
The frequency is set to 1 Hz.
41+
42+
Since the RTC is part of the backup domain, The RTC counter is not reset by normal resets or
43+
power cycles where (VBAT) still has power. Use [set_time](#method.set_time) if you want to
44+
reset the counter.
3645
*/
3746
pub fn rtc(regs: RTC, bkp: &mut BackupDomain) -> Self {
3847
let mut result = Rtc { regs };
@@ -123,15 +132,17 @@ impl Rtc {
123132
self.clear_alarm_flag();
124133
}
125134

126-
/// Enables the RTCALARM interrupt
135+
/// Enables the RTC interrupt to trigger when the counter reaches the alarm value. In addition,
136+
/// if the EXTI controller has been set up correctly, this function also enables the RTCALARM
137+
/// interrupt.
127138
pub fn listen_alarm(&mut self) {
128139
// Enable alarm interrupt
129140
self.perform_write(|s| {
130141
s.regs.crh.modify(|_, w| w.alrie().set_bit());
131142
})
132143
}
133144

134-
/// Disables the RTCALARM interrupt
145+
/// Stops the RTC alarm from triggering the RTC and RTCALARM interrupts
135146
pub fn unlisten_alarm(&mut self) {
136147
// Disable alarm interrupt
137148
self.perform_write(|s| {
@@ -147,7 +158,7 @@ impl Rtc {
147158
self.regs.cnth.read().bits() << 16 | self.regs.cntl.read().bits()
148159
}
149160

150-
/// Enables the RTC second interrupt
161+
/// Enables triggering the RTC interrupt every time the RTC counter is increased
151162
pub fn listen_seconds(&mut self) {
152163
self.perform_write(|s| s.regs.crh.modify(|_, w| w.secie().set_bit()))
153164
}

0 commit comments

Comments
 (0)