diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-03-23 01:38:51 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2024-03-23 01:38:51 +0100 |
| commit | 2bca875b5f72578cbd20404010d174795d263313 (patch) | |
| tree | a5d2175fdb8c7d10e298e5b5eaad70fe9301e5ee /embassy-stm32/src/rtc | |
| parent | 389cbc0a77daea15decae706818f104d89446020 (diff) | |
stm32: use private_bounds for sealed traits.
Diffstat (limited to 'embassy-stm32/src/rtc')
| -rw-r--r-- | embassy-stm32/src/rtc/datetime.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/mod.rs | 53 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v2.rs | 5 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v3.rs | 6 |
4 files changed, 30 insertions, 36 deletions
diff --git a/embassy-stm32/src/rtc/datetime.rs b/embassy-stm32/src/rtc/datetime.rs index 2bad79923..bab8cf4a3 100644 --- a/embassy-stm32/src/rtc/datetime.rs +++ b/embassy-stm32/src/rtc/datetime.rs | |||
| @@ -4,7 +4,7 @@ use chrono::{Datelike, NaiveDate, Timelike, Weekday}; | |||
| 4 | #[cfg(any(feature = "defmt", feature = "time"))] | 4 | #[cfg(any(feature = "defmt", feature = "time"))] |
| 5 | use crate::peripherals::RTC; | 5 | use crate::peripherals::RTC; |
| 6 | #[cfg(any(feature = "defmt", feature = "time"))] | 6 | #[cfg(any(feature = "defmt", feature = "time"))] |
| 7 | use crate::rtc::sealed::Instance; | 7 | use crate::rtc::SealedInstance; |
| 8 | 8 | ||
| 9 | /// Represents an instant in time that can be substracted to compute a duration | 9 | /// Represents an instant in time that can be substracted to compute a duration |
| 10 | pub struct RtcInstant { | 10 | pub struct RtcInstant { |
diff --git a/embassy-stm32/src/rtc/mod.rs b/embassy-stm32/src/rtc/mod.rs index 169505501..00abe9356 100644 --- a/embassy-stm32/src/rtc/mod.rs +++ b/embassy-stm32/src/rtc/mod.rs | |||
| @@ -31,7 +31,6 @@ pub use _version::*; | |||
| 31 | use embassy_hal_internal::Peripheral; | 31 | use embassy_hal_internal::Peripheral; |
| 32 | 32 | ||
| 33 | use crate::peripherals::RTC; | 33 | use crate::peripherals::RTC; |
| 34 | use crate::rtc::sealed::Instance; | ||
| 35 | 34 | ||
| 36 | #[allow(dead_code)] | 35 | #[allow(dead_code)] |
| 37 | #[repr(u8)] | 36 | #[repr(u8)] |
| @@ -212,7 +211,7 @@ impl Rtc { | |||
| 212 | /// Create a new RTC instance. | 211 | /// Create a new RTC instance. |
| 213 | 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 { |
| 214 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] | 213 | #[cfg(not(any(stm32l0, stm32f3, stm32l1, stm32f0, stm32f2)))] |
| 215 | <RTC as crate::rcc::sealed::RccPeripheral>::enable_and_reset(); | 214 | <RTC as crate::rcc::SealedRccPeripheral>::enable_and_reset(); |
| 216 | 215 | ||
| 217 | let mut this = Self { | 216 | let mut this = Self { |
| 218 | #[cfg(feature = "low-power")] | 217 | #[cfg(feature = "low-power")] |
| @@ -437,7 +436,7 @@ impl Rtc { | |||
| 437 | .fpr(0) | 436 | .fpr(0) |
| 438 | .modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); | 437 | .modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); |
| 439 | 438 | ||
| 440 | <RTC as crate::rtc::sealed::Instance>::WakeupInterrupt::unpend(); | 439 | <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::unpend(); |
| 441 | }); | 440 | }); |
| 442 | } | 441 | } |
| 443 | 442 | ||
| @@ -449,8 +448,8 @@ impl Rtc { | |||
| 449 | use crate::interrupt::typelevel::Interrupt; | 448 | use crate::interrupt::typelevel::Interrupt; |
| 450 | use crate::pac::EXTI; | 449 | use crate::pac::EXTI; |
| 451 | 450 | ||
| 452 | <RTC as crate::rtc::sealed::Instance>::WakeupInterrupt::unpend(); | 451 | <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::unpend(); |
| 453 | unsafe { <RTC as crate::rtc::sealed::Instance>::WakeupInterrupt::enable() }; | 452 | unsafe { <RTC as crate::rtc::SealedInstance>::WakeupInterrupt::enable() }; |
| 454 | 453 | ||
| 455 | EXTI.rtsr(0).modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); | 454 | EXTI.rtsr(0).modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); |
| 456 | EXTI.imr(0).modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); | 455 | EXTI.imr(0).modify(|w| w.set_line(RTC::EXTI_WAKEUP_LINE, true)); |
| @@ -477,34 +476,30 @@ pub(crate) fn bcd2_to_byte(bcd: (u8, u8)) -> u8 { | |||
| 477 | tmp + (value & 0x0F) | 476 | tmp + (value & 0x0F) |
| 478 | } | 477 | } |
| 479 | 478 | ||
| 480 | pub(crate) mod sealed { | 479 | trait SealedInstance { |
| 481 | use crate::pac::rtc::Rtc; | 480 | const BACKUP_REGISTER_COUNT: usize; |
| 482 | 481 | ||
| 483 | pub trait Instance { | 482 | #[cfg(feature = "low-power")] |
| 484 | const BACKUP_REGISTER_COUNT: usize; | 483 | const EXTI_WAKEUP_LINE: usize; |
| 485 | |||
| 486 | #[cfg(feature = "low-power")] | ||
| 487 | const EXTI_WAKEUP_LINE: usize; | ||
| 488 | 484 | ||
| 489 | #[cfg(feature = "low-power")] | 485 | #[cfg(feature = "low-power")] |
| 490 | type WakeupInterrupt: crate::interrupt::typelevel::Interrupt; | 486 | type WakeupInterrupt: crate::interrupt::typelevel::Interrupt; |
| 491 | 487 | ||
| 492 | fn regs() -> Rtc { | 488 | fn regs() -> crate::pac::rtc::Rtc { |
| 493 | crate::pac::RTC | 489 | crate::pac::RTC |
| 494 | } | 490 | } |
| 495 | 491 | ||
| 496 | /// Read content of the backup register. | 492 | /// Read content of the backup register. |
| 497 | /// | 493 | /// |
| 498 | /// The registers retain their values during wakes from standby mode or system resets. They also | 494 | /// The registers retain their values during wakes from standby mode or system resets. They also |
| 499 | /// retain their value when Vdd is switched off as long as V_BAT is powered. | 495 | /// retain their value when Vdd is switched off as long as V_BAT is powered. |
| 500 | fn read_backup_register(rtc: &Rtc, register: usize) -> Option<u32>; | 496 | fn read_backup_register(rtc: &crate::pac::rtc::Rtc, register: usize) -> Option<u32>; |
| 501 | 497 | ||
| 502 | /// Set content of the backup register. | 498 | /// Set content of the backup register. |
| 503 | /// | 499 | /// |
| 504 | /// The registers retain their values during wakes from standby mode or system resets. They also | 500 | /// The registers retain their values during wakes from standby mode or system resets. They also |
| 505 | /// retain their value when Vdd is switched off as long as V_BAT is powered. | 501 | /// retain their value when Vdd is switched off as long as V_BAT is powered. |
| 506 | fn write_backup_register(rtc: &Rtc, register: usize, value: u32); | 502 | fn write_backup_register(rtc: &crate::pac::rtc::Rtc, register: usize, value: u32); |
| 507 | 503 | ||
| 508 | // fn apply_config(&mut self, rtc_config: RtcConfig); | 504 | // fn apply_config(&mut self, rtc_config: RtcConfig); |
| 509 | } | ||
| 510 | } | 505 | } |
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index 1eda097a7..92f9de846 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | use stm32_metapac::rtc::vals::{Osel, Pol}; | 1 | use stm32_metapac::rtc::vals::{Osel, Pol}; |
| 2 | 2 | ||
| 3 | use super::sealed; | 3 | use super::SealedInstance; |
| 4 | use crate::pac::rtc::Rtc; | 4 | use crate::pac::rtc::Rtc; |
| 5 | use crate::peripherals::RTC; | 5 | use crate::peripherals::RTC; |
| 6 | use crate::rtc::sealed::Instance; | ||
| 7 | 6 | ||
| 8 | #[allow(dead_code)] | 7 | #[allow(dead_code)] |
| 9 | impl super::Rtc { | 8 | impl super::Rtc { |
| @@ -126,7 +125,7 @@ impl super::Rtc { | |||
| 126 | } | 125 | } |
| 127 | } | 126 | } |
| 128 | 127 | ||
| 129 | impl sealed::Instance for crate::peripherals::RTC { | 128 | impl SealedInstance for crate::peripherals::RTC { |
| 130 | const BACKUP_REGISTER_COUNT: usize = 20; | 129 | const BACKUP_REGISTER_COUNT: usize = 20; |
| 131 | 130 | ||
| 132 | #[cfg(all(feature = "low-power", stm32f4))] | 131 | #[cfg(all(feature = "low-power", stm32f4))] |
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index 3d44a52ff..8a78d16e1 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs | |||
| @@ -1,9 +1,9 @@ | |||
| 1 | use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Key, Osel, Pol, TampalrmType}; | 1 | use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Key, Osel, Pol, TampalrmType}; |
| 2 | 2 | ||
| 3 | use super::{sealed, RtcCalibrationCyclePeriod}; | 3 | use super::RtcCalibrationCyclePeriod; |
| 4 | use crate::pac::rtc::Rtc; | 4 | use crate::pac::rtc::Rtc; |
| 5 | use crate::peripherals::RTC; | 5 | use crate::peripherals::RTC; |
| 6 | use crate::rtc::sealed::Instance; | 6 | use crate::rtc::SealedInstance; |
| 7 | 7 | ||
| 8 | impl super::Rtc { | 8 | impl super::Rtc { |
| 9 | /// Applies the RTC config | 9 | /// Applies the RTC config |
| @@ -126,7 +126,7 @@ impl super::Rtc { | |||
| 126 | } | 126 | } |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | impl sealed::Instance for crate::peripherals::RTC { | 129 | impl SealedInstance for crate::peripherals::RTC { |
| 130 | const BACKUP_REGISTER_COUNT: usize = 32; | 130 | const BACKUP_REGISTER_COUNT: usize = 32; |
| 131 | 131 | ||
| 132 | #[cfg(all(feature = "low-power", stm32g4))] | 132 | #[cfg(all(feature = "low-power", stm32g4))] |
