Skip to content

Commit 309ab99

Browse files
committed
Pass PWR into all low-power modes
This makes all low-power modes with `LowPowerSleepMode`, which already works this way. It's also going to be useful going forward, as it's strictly more flexible for the very little cost of an additional `.0` here and there.
1 parent c42cd08 commit 309ab99

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/pwr.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl PWR {
7070
/// Returns a struct that can be used to enter Sleep mode
7171
pub fn sleep_mode<'r>(&'r mut self, scb: &'r mut SCB) -> SleepMode<'r> {
7272
SleepMode {
73-
pwr: &mut self.0,
73+
pwr: self,
7474
scb,
7575
}
7676
}
@@ -108,7 +108,7 @@ impl PWR {
108108
-> StopMode<'r>
109109
{
110110
StopMode {
111-
pwr: &mut self.0,
111+
pwr: self,
112112
scb,
113113
rcc,
114114
config,
@@ -118,7 +118,7 @@ impl PWR {
118118
/// Returns a struct that can be used to enter Standby mode
119119
pub fn standby_mode<'r>(&'r mut self, scb: &'r mut SCB) -> StandbyMode<'r> {
120120
StandbyMode {
121-
pwr: &mut self.0,
121+
pwr: self,
122122
scb,
123123
}
124124
}
@@ -175,16 +175,16 @@ pub trait PowerMode {
175175
///
176176
/// Please note that entering Sleep mode may change the SCB configuration.
177177
pub struct SleepMode<'r> {
178-
pwr: &'r mut pac::PWR,
178+
pwr: &'r mut PWR,
179179
scb: &'r mut SCB,
180180
}
181181

182182
impl PowerMode for SleepMode<'_> {
183183
fn enter(&mut self) {
184184
#[cfg(feature = "stm32l0x1")]
185-
self.pwr.cr.modify(|_, w| w.lpsdsr().main_mode());
185+
self.pwr.0.cr.modify(|_, w| w.lpsdsr().main_mode());
186186
#[cfg(any(feature = "stm32l0x2", feature = "stm32l0x3"))]
187-
self.pwr.cr.modify(|_, w| w.lpds().clear_bit());
187+
self.pwr.0.cr.modify(|_, w| w.lpds().clear_bit());
188188

189189
self.scb.clear_sleepdeep();
190190

@@ -253,7 +253,7 @@ impl PowerMode for LowPowerSleepMode<'_> {
253253
/// that might require special handling. This is explained in the STM32L0x2
254254
/// Reference Manual, section 6.3.9.
255255
pub struct StopMode<'r> {
256-
pwr: &'r mut pac::PWR,
256+
pwr: &'r mut PWR,
257257
scb: &'r mut SCB,
258258
rcc: &'r mut Rcc,
259259
config: StopModeConfig,
@@ -308,7 +308,7 @@ impl PowerMode for StopMode<'_> {
308308
);
309309

310310
// Configure Stop mode
311-
self.pwr.cr.modify(|_, w|
311+
self.pwr.0.cr.modify(|_, w|
312312
w
313313
// Ultra-low-power mode
314314
.ulp().bit(self.config.ultra_low_power)
@@ -321,7 +321,7 @@ impl PowerMode for StopMode<'_> {
321321
);
322322

323323
// Wait for WUF to be cleared
324-
while self.pwr.csr.read().wuf().bit_is_set() {}
324+
while self.pwr.0.csr.read().wuf().bit_is_set() {}
325325

326326
// Enter Stop mode
327327
asm::dsb();
@@ -355,15 +355,15 @@ pub struct StopModeConfig {
355355
/// it could block forever. Once woken up, the method will not return. Instead,
356356
/// the microcontroller will reset.
357357
pub struct StandbyMode<'r> {
358-
pwr: &'r mut pac::PWR,
358+
pwr: &'r mut PWR,
359359
scb: &'r mut SCB,
360360
}
361361

362362
impl PowerMode for StandbyMode<'_> {
363363
fn enter(&mut self) {
364364
// Configure Standby mode
365365
self.scb.set_sleepdeep();
366-
self.pwr.cr.modify(|_, w|
366+
self.pwr.0.cr.modify(|_, w|
367367
w
368368
// Clear WUF
369369
.cwuf().set_bit()
@@ -372,7 +372,7 @@ impl PowerMode for StandbyMode<'_> {
372372
);
373373

374374
// Wait for WUF to be cleared
375-
while self.pwr.csr.read().wuf().bit_is_set() {}
375+
while self.pwr.0.csr.read().wuf().bit_is_set() {}
376376

377377
// Enter Standby mode
378378
asm::dsb();

0 commit comments

Comments
 (0)