Skip to content

Commit ed04de1

Browse files
committed
Add methods to set/clear LPSDSR
This makes the code a bit nicer, and will also enable re-use going forward.
1 parent 309ab99 commit ed04de1

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/pwr.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ impl PWR {
122122
scb,
123123
}
124124
}
125+
126+
/// Private method to set LPSDSR
127+
fn set_lpsdsr(&mut self) {
128+
#[cfg(feature = "stm32l0x1")]
129+
self.0.cr.modify(|_, w| w.lpsdsr().low_power_mode());
130+
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
131+
self.0.cr.modify(|_, w| w.lpds().set_bit());
132+
}
133+
134+
/// Private method to clear LPSDSR
135+
fn clear_lpsdsr(&mut self) {
136+
#[cfg(feature = "stm32l0x1")]
137+
self.0.cr.modify(|_, w| w.lpsdsr().main_mode());
138+
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
139+
self.0.cr.modify(|_, w| w.lpds().clear_bit());
140+
}
125141
}
126142

127143

@@ -181,11 +197,7 @@ pub struct SleepMode<'r> {
181197

182198
impl PowerMode for SleepMode<'_> {
183199
fn enter(&mut self) {
184-
#[cfg(feature = "stm32l0x1")]
185-
self.pwr.0.cr.modify(|_, w| w.lpsdsr().main_mode());
186-
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
187-
self.pwr.0.cr.modify(|_, w| w.lpds().clear_bit());
188-
200+
self.pwr.clear_lpsdsr();
189201
self.scb.clear_sleepdeep();
190202

191203
asm::dsb();
@@ -217,11 +229,7 @@ impl PowerMode for LowPowerSleepMode<'_> {
217229
let old_vcore = self.pwr.get_vcore_range();
218230
self.pwr.switch_vcore_range(VcoreRange::Range2);
219231

220-
#[cfg(feature = "stm32l0x1")]
221-
self.pwr.0.cr.modify(|_, w| w.lpsdsr().low_power_mode());
222-
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
223-
self.pwr.0.cr.modify(|_, w| w.lpds().set_bit());
224-
232+
self.pwr.set_lpsdsr();
225233
self.scb.clear_sleepdeep();
226234

227235
asm::dsb();

0 commit comments

Comments
 (0)