Browse Source

fix(sleep): use pm_power_state_force for proper device power management

xmkb
Nick Winans 3 years ago committed by Pete Johanson
parent
commit
54747a52f9
  1. 4
      app/src/activity.c
  2. 4
      app/src/ext_power_generic.c

4
app/src/activity.c

@ -68,9 +68,9 @@ void activity_work_handler(struct k_work *work) {
int32_t inactive_time = current - activity_last_uptime; int32_t inactive_time = current - activity_last_uptime;
#if IS_ENABLED(CONFIG_ZMK_SLEEP) #if IS_ENABLED(CONFIG_ZMK_SLEEP)
if (inactive_time > MAX_SLEEP_MS && !is_usb_power_present()) { if (inactive_time > MAX_SLEEP_MS && !is_usb_power_present()) {
// Put devices in low power mode before sleeping // Put devices in suspend power mode before sleeping
set_state(ZMK_ACTIVITY_SLEEP); set_state(ZMK_ACTIVITY_SLEEP);
pm_power_state_set((struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); pm_power_state_force(0U, (struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});
} else } else
#endif /* IS_ENABLED(CONFIG_ZMK_SLEEP) */ #endif /* IS_ENABLED(CONFIG_ZMK_SLEEP) */
if (inactive_time > MAX_IDLE_MS) { if (inactive_time > MAX_IDLE_MS) {

4
app/src/ext_power_generic.c

@ -176,10 +176,10 @@ static int ext_power_generic_init(const struct device *dev) {
#ifdef CONFIG_PM_DEVICE #ifdef CONFIG_PM_DEVICE
static int ext_power_generic_pm_action(const struct device *dev, enum pm_device_action action) { static int ext_power_generic_pm_action(const struct device *dev, enum pm_device_action action) {
switch (action) { switch (action) {
case PM_DEVICE_ACTION_TURN_ON: case PM_DEVICE_ACTION_RESUME:
ext_power_generic_enable(dev); ext_power_generic_enable(dev);
return 0; return 0;
case PM_DEVICE_ACTION_TURN_OFF: case PM_DEVICE_ACTION_SUSPEND:
ext_power_generic_disable(dev); ext_power_generic_disable(dev);
return 0; return 0;
default: default:

Loading…
Cancel
Save