Skip to content

Commit c49398a

Browse files
committed
low_power remove wucksel enum
1 parent af9bfe5 commit c49398a

File tree

1 file changed

+13
-56
lines changed

1 file changed

+13
-56
lines changed

embassy-stm32/src/rtc/low_power.rs

Lines changed: 13 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::pac::rtc::vals::Wucksel;
12
#[cfg(feature = "time")]
23
use embassy_time::{Duration, TICK_HZ};
34

@@ -58,60 +59,16 @@ impl core::ops::Sub for RtcInstant {
5859
}
5960
}
6061

61-
#[repr(u8)]
62-
#[derive(Clone, Copy, Debug)]
63-
pub(crate) enum WakeupPrescaler {
64-
Div2 = 2,
65-
Div4 = 4,
66-
Div8 = 8,
67-
Div16 = 16,
68-
}
69-
70-
#[cfg(any(
71-
stm32f4, stm32l0, stm32g4, stm32l4, stm32l5, stm32wb, stm32h5, stm32g0, stm32u5, stm32u0, stm32wba, stm32wlex
72-
))]
73-
impl From<WakeupPrescaler> for crate::pac::rtc::vals::Wucksel {
74-
fn from(val: WakeupPrescaler) -> Self {
75-
use crate::pac::rtc::vals::Wucksel;
76-
77-
match val {
78-
WakeupPrescaler::Div2 => Wucksel::DIV2,
79-
WakeupPrescaler::Div4 => Wucksel::DIV4,
80-
WakeupPrescaler::Div8 => Wucksel::DIV8,
81-
WakeupPrescaler::Div16 => Wucksel::DIV16,
82-
}
83-
}
84-
}
85-
86-
#[cfg(any(
87-
stm32f4, stm32l0, stm32g4, stm32l4, stm32l5, stm32wb, stm32h5, stm32g0, stm32u5, stm32u0, stm32wba, stm32wlex
88-
))]
89-
impl From<crate::pac::rtc::vals::Wucksel> for WakeupPrescaler {
90-
fn from(val: crate::pac::rtc::vals::Wucksel) -> Self {
91-
use crate::pac::rtc::vals::Wucksel;
92-
93-
match val {
94-
Wucksel::DIV2 => WakeupPrescaler::Div2,
95-
Wucksel::DIV4 => WakeupPrescaler::Div4,
96-
Wucksel::DIV8 => WakeupPrescaler::Div8,
97-
Wucksel::DIV16 => WakeupPrescaler::Div16,
98-
_ => unreachable!(),
99-
}
100-
}
101-
}
102-
103-
impl WakeupPrescaler {
104-
pub fn compute_min(val: u32) -> Self {
105-
*[
106-
WakeupPrescaler::Div2,
107-
WakeupPrescaler::Div4,
108-
WakeupPrescaler::Div8,
109-
WakeupPrescaler::Div16,
110-
]
111-
.iter()
112-
.find(|psc| **psc as u32 > val)
113-
.unwrap_or(&WakeupPrescaler::Div16)
114-
}
62+
fn wucksel_compute_min(val: u32) -> (Wucksel, u32) {
63+
*[
64+
(Wucksel::DIV2, 2),
65+
(Wucksel::DIV4, 4),
66+
(Wucksel::DIV8, 8),
67+
(Wucksel::DIV16, 16),
68+
]
69+
.iter()
70+
.find(|(_, psc)| *psc as u32 > val)
71+
.unwrap_or(&(Wucksel::DIV16, 16))
11572
}
11673

11774
impl Rtc {
@@ -138,7 +95,7 @@ impl Rtc {
13895
let requested_duration = requested_duration.as_ticks().clamp(0, u32::MAX as u64);
13996
let rtc_hz = Self::frequency().0 as u64;
14097
let rtc_ticks = requested_duration * rtc_hz / TICK_HZ;
141-
let prescaler = WakeupPrescaler::compute_min((rtc_ticks / u16::MAX as u64) as u32);
98+
let (wucksel, prescaler) = wucksel_compute_min((rtc_ticks / u16::MAX as u64) as u32);
14299

143100
// adjust the rtc ticks to the prescaler and subtract one rtc tick
144101
let rtc_ticks = rtc_ticks / prescaler as u64;
@@ -159,7 +116,7 @@ impl Rtc {
159116
while !regs.icsr().read().wutwf() {}
160117
}
161118

162-
regs.cr().modify(|w| w.set_wucksel(prescaler.into()));
119+
regs.cr().modify(|w| w.set_wucksel(wucksel));
163120
regs.wutr().write(|w| w.set_wut(rtc_ticks));
164121
regs.cr().modify(|w| w.set_wute(true));
165122
regs.cr().modify(|w| w.set_wutie(true));

0 commit comments

Comments
 (0)