diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-12-18 19:11:13 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-12-18 19:11:23 +0100 |
| commit | 124478c5e9df16f0930d019c6f0db358666b3249 (patch) | |
| tree | 9c2ed7fe64b273efdd84f5952516b64a0b5f8566 /embassy-stm32/src/rtc | |
| parent | 59d2977c0aef1104138473252fe8d84e3550e378 (diff) | |
stm32: more docs.
Diffstat (limited to 'embassy-stm32/src/rtc')
| -rw-r--r-- | embassy-stm32/src/rtc/datetime.rs | 12 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/mod.rs | 12 |
2 files changed, 17 insertions, 7 deletions
diff --git a/embassy-stm32/src/rtc/datetime.rs b/embassy-stm32/src/rtc/datetime.rs index f4e86dd87..ef92fa4bb 100644 --- a/embassy-stm32/src/rtc/datetime.rs +++ b/embassy-stm32/src/rtc/datetime.rs | |||
| @@ -104,45 +104,51 @@ pub struct DateTime { | |||
| 104 | } | 104 | } |
| 105 | 105 | ||
| 106 | impl DateTime { | 106 | impl DateTime { |
| 107 | /// Get the year (0..=4095) | ||
| 107 | pub const fn year(&self) -> u16 { | 108 | pub const fn year(&self) -> u16 { |
| 108 | self.year | 109 | self.year |
| 109 | } | 110 | } |
| 110 | 111 | ||
| 112 | /// Get the month (1..=12, 1 is January) | ||
| 111 | pub const fn month(&self) -> u8 { | 113 | pub const fn month(&self) -> u8 { |
| 112 | self.month | 114 | self.month |
| 113 | } | 115 | } |
| 114 | 116 | ||
| 117 | /// Get the day (1..=31) | ||
| 115 | pub const fn day(&self) -> u8 { | 118 | pub const fn day(&self) -> u8 { |
| 116 | self.day | 119 | self.day |
| 117 | } | 120 | } |
| 118 | 121 | ||
| 122 | /// Get the day of week | ||
| 119 | pub const fn day_of_week(&self) -> DayOfWeek { | 123 | pub const fn day_of_week(&self) -> DayOfWeek { |
| 120 | self.day_of_week | 124 | self.day_of_week |
| 121 | } | 125 | } |
| 122 | 126 | ||
| 127 | /// Get the hour (0..=23) | ||
| 123 | pub const fn hour(&self) -> u8 { | 128 | pub const fn hour(&self) -> u8 { |
| 124 | self.hour | 129 | self.hour |
| 125 | } | 130 | } |
| 126 | 131 | ||
| 132 | /// Get the minute (0..=59) | ||
| 127 | pub const fn minute(&self) -> u8 { | 133 | pub const fn minute(&self) -> u8 { |
| 128 | self.minute | 134 | self.minute |
| 129 | } | 135 | } |
| 130 | 136 | ||
| 137 | /// Get the second (0..=59) | ||
| 131 | pub const fn second(&self) -> u8 { | 138 | pub const fn second(&self) -> u8 { |
| 132 | self.second | 139 | self.second |
| 133 | } | 140 | } |
| 134 | 141 | ||
| 142 | /// Create a new DateTime with the given information. | ||
| 135 | pub fn from( | 143 | pub fn from( |
| 136 | year: u16, | 144 | year: u16, |
| 137 | month: u8, | 145 | month: u8, |
| 138 | day: u8, | 146 | day: u8, |
| 139 | day_of_week: u8, | 147 | day_of_week: DayOfWeek, |
| 140 | hour: u8, | 148 | hour: u8, |
| 141 | minute: u8, | 149 | minute: u8, |
| 142 | second: u8, | 150 | second: u8, |
| 143 | ) -> Result<Self, Error> { | 151 | ) -> Result<Self, Error> { |
| 144 | let day_of_week = day_of_week_from_u8(day_of_week)?; | ||
| 145 | |||
| 146 | if year > 4095 { | 152 | if year > 4095 { |
| 147 | Err(Error::InvalidYear) | 153 | Err(Error::InvalidYear) |
| 148 | } else if month < 1 || month > 12 { | 154 | } else if month < 1 || month > 12 { |
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index b4315f535..fa359cdae 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -9,9 +9,9 @@ use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | |||
| 9 | #[cfg(feature = "low-power")] | 9 | #[cfg(feature = "low-power")] |
| 10 | use embassy_sync::blocking_mutex::Mutex; | 10 | use embassy_sync::blocking_mutex::Mutex; |
| 11 | 11 | ||
| 12 | use self::datetime::day_of_week_to_u8; | ||
| 13 | #[cfg(not(rtc_v2f2))] | 12 | #[cfg(not(rtc_v2f2))] |
| 14 | use self::datetime::RtcInstant; | 13 | use self::datetime::RtcInstant; |
| 14 | use self::datetime::{day_of_week_from_u8, day_of_week_to_u8}; | ||
| 15 | pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError}; | 15 | pub use self::datetime::{DateTime, DayOfWeek, Error as DateTimeError}; |
| 16 | use crate::pac::rtc::regs::{Dr, Tr}; | 16 | use crate::pac::rtc::regs::{Dr, Tr}; |
| 17 | use crate::time::Hertz; | 17 | use crate::time::Hertz; |
| @@ -102,7 +102,7 @@ pub enum RtcError { | |||
| 102 | NotRunning, | 102 | NotRunning, |
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | pub struct RtcTimeProvider { | 105 | pub(crate) struct RtcTimeProvider { |
| 106 | _private: (), | 106 | _private: (), |
| 107 | } | 107 | } |
| 108 | 108 | ||
| @@ -127,7 +127,7 @@ impl RtcTimeProvider { | |||
| 127 | let minute = bcd2_to_byte((tr.mnt(), tr.mnu())); | 127 | let minute = bcd2_to_byte((tr.mnt(), tr.mnu())); |
| 128 | let hour = bcd2_to_byte((tr.ht(), tr.hu())); | 128 | let hour = bcd2_to_byte((tr.ht(), tr.hu())); |
| 129 | 129 | ||
| 130 | let weekday = dr.wdu(); | 130 | let weekday = day_of_week_from_u8(dr.wdu()).map_err(RtcError::InvalidDateTime)?; |
| 131 | let day = bcd2_to_byte((dr.dt(), dr.du())); | 131 | let day = bcd2_to_byte((dr.dt(), dr.du())); |
| 132 | let month = bcd2_to_byte((dr.mt() as u8, dr.mu())); | 132 | let month = bcd2_to_byte((dr.mt() as u8, dr.mu())); |
| 133 | let year = bcd2_to_byte((dr.yt(), dr.yu())) as u16 + 1970_u16; | 133 | let year = bcd2_to_byte((dr.yt(), dr.yu())) as u16 + 1970_u16; |
| @@ -171,6 +171,7 @@ pub struct Rtc { | |||
| 171 | _private: (), | 171 | _private: (), |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | /// RTC configuration. | ||
| 174 | #[non_exhaustive] | 175 | #[non_exhaustive] |
| 175 | #[derive(Copy, Clone, PartialEq)] | 176 | #[derive(Copy, Clone, PartialEq)] |
| 176 | pub struct RtcConfig { | 177 | pub struct RtcConfig { |
| @@ -188,6 +189,7 @@ impl Default for RtcConfig { | |||
| 188 | } | 189 | } |
| 189 | } | 190 | } |
| 190 | 191 | ||
| 192 | /// Calibration cycle period. | ||
| 191 | #[derive(Copy, Clone, Debug, PartialEq)] | 193 | #[derive(Copy, Clone, Debug, PartialEq)] |
| 192 | #[repr(u8)] | 194 | #[repr(u8)] |
| 193 | pub enum RtcCalibrationCyclePeriod { | 195 | pub enum RtcCalibrationCyclePeriod { |
| @@ -206,6 +208,7 @@ impl Default for RtcCalibrationCyclePeriod { | |||
| 206 | } | 208 | } |
| 207 | 209 | ||
| 208 | impl Rtc { | 210 | impl Rtc { |
| 211 | /// Create a new RTC instance. | ||
| 209 | pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self { | 212 | pub fn new(_rtc: impl Peripheral<P = RTC>, rtc_config: RtcConfig) -> Self { |
| 210 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] | 213 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] |
| 211 | <RTC as crate::rcc::sealed::RccPeripheral>::enable_and_reset(); | 214 | <RTC as crate::rcc::sealed::RccPeripheral>::enable_and_reset(); |
| @@ -240,7 +243,7 @@ impl Rtc { | |||
| 240 | } | 243 | } |
| 241 | 244 | ||
| 242 | /// Acquire a [`RtcTimeProvider`] instance. | 245 | /// Acquire a [`RtcTimeProvider`] instance. |
| 243 | pub const fn time_provider(&self) -> RtcTimeProvider { | 246 | pub(crate) const fn time_provider(&self) -> RtcTimeProvider { |
| 244 | RtcTimeProvider { _private: () } | 247 | RtcTimeProvider { _private: () } |
| 245 | } | 248 | } |
| 246 | 249 | ||
| @@ -315,6 +318,7 @@ impl Rtc { | |||
| 315 | }) | 318 | }) |
| 316 | } | 319 | } |
| 317 | 320 | ||
| 321 | /// Number of backup registers of this instance. | ||
| 318 | pub const BACKUP_REGISTER_COUNT: usize = RTC::BACKUP_REGISTER_COUNT; | 322 | pub const BACKUP_REGISTER_COUNT: usize = RTC::BACKUP_REGISTER_COUNT; |
| 319 | 323 | ||
| 320 | /// Read content of the backup register. | 324 | /// Read content of the backup register. |
