Skip to content

Commit 3507c24

Browse files
committed
Do not auto-enter low-power suspend, expose method to user
Setting LP_MODE instantly does not allow user application to prepare for the low power mode, disable clocks, peripherals, etc. Also, self-powered devices may not want to enter low-power mode during host suspend.
1 parent 8820c52 commit 3507c24

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/bus.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,27 @@ impl<USB: UsbPeripheral> UsbBus<USB> {
7171
regs.cntr.modify(|_, w| w.pdwn().bit(pdwn));
7272
});
7373
}
74+
75+
/// Enter suspend low-power mode
76+
///
77+
/// This should be used when in suspend mode if low-power mode needs to be entered during
78+
/// suspend (bus-powered device). Application should call this when it is ready to decrease
79+
/// power consumption to meet power consumption requirements of the USB suspend condition
80+
/// (e.g. disable system clocks or reduce their frequency). When wake up event is received
81+
/// low power mode will be automatically disabled.
82+
///
83+
/// Will not enter low-power mode if not in suspend state. Returns `true` if entered.
84+
pub fn suspend_low_power_mode(&self) -> bool {
85+
interrupt::free(|cs| {
86+
let regs = self.regs.borrow(cs);
87+
if regs.cntr.read().fsusp().is_suspend() {
88+
regs.cntr.modify(|_, w| w.lpmode().set_bit());
89+
true
90+
} else {
91+
false
92+
}
93+
})
94+
}
7495
}
7596

7697
impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
@@ -285,7 +306,7 @@ impl<USB: UsbPeripheral> usb_device::bus::UsbBus for UsbBus<USB> {
285306
self.regs
286307
.borrow(cs)
287308
.cntr
288-
.modify(|_, w| w.fsusp().set_bit().lpmode().set_bit());
309+
.modify(|_, w| w.fsusp().set_bit());
289310
});
290311
}
291312

0 commit comments

Comments
 (0)