refactor: Move to new PM API/Kconfig settings.

This commit is contained in:
Peter Johanson
2021-11-05 04:22:46 +00:00
committed by Pete Johanson
parent 6287819fcc
commit 79ab60dfe5
4 changed files with 14 additions and 41 deletions

View File

@@ -7,7 +7,7 @@
#include <device.h>
#include <init.h>
#include <kernel.h>
#include <power/power.h>
#include <pm/pm.h>
#include <logging/log.h>
@@ -20,6 +20,18 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/activity.h>
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
#include <zmk/usb.h>
#endif
bool is_usb_power_present() {
#if IS_ENABLED(CONFIG_USB_DEVICE_STACK)
return zmk_usb_is_powered();
#else
return false;
#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK) */
}
static enum zmk_activity_state activity_state;
static uint32_t activity_last_uptime;
@@ -55,7 +67,7 @@ void activity_work_handler(struct k_work *work) {
int32_t current = k_uptime_get();
int32_t inactive_time = current - activity_last_uptime;
#if IS_ENABLED(CONFIG_ZMK_SLEEP)
if (inactive_time > MAX_SLEEP_MS) {
if (inactive_time > MAX_SLEEP_MS && !is_usb_power_present()) {
// Put devices in low power mode before sleeping
pm_power_state_force((struct pm_state_info){PM_STATE_STANDBY, 0, 0});
set_state(ZMK_ACTIVITY_SLEEP);