2020-10-02 16:09:38 +10:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 The ZMK Contributors
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <zephyr.h>
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <power/power.h>
|
|
|
|
|
|
|
|
#include <logging/log.h>
|
|
|
|
|
|
|
|
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
|
|
|
|
|
|
|
|
#include <zmk/usb.h>
|
2020-12-01 16:52:32 +11:00
|
|
|
#include <zmk/activity.h>
|
2020-10-02 16:09:38 +10:00
|
|
|
|
|
|
|
bool is_usb_power_present() {
|
|
|
|
#ifdef CONFIG_USB
|
2020-10-12 09:03:21 +11:00
|
|
|
return zmk_usb_is_powered();
|
2020-10-02 16:09:38 +10:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif /* CONFIG_USB */
|
|
|
|
}
|
|
|
|
|
2021-06-19 19:57:33 +10:00
|
|
|
struct pm_state_info pm_policy_next_state(int32_t ticks) {
|
2020-12-01 16:52:32 +11:00
|
|
|
if (zmk_activity_get_state() == ZMK_ACTIVITY_SLEEP && !is_usb_power_present()) {
|
2021-06-19 19:57:33 +10:00
|
|
|
return (struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0};
|
2020-10-02 16:09:38 +10:00
|
|
|
}
|
|
|
|
|
2021-06-19 19:57:33 +10:00
|
|
|
return (struct pm_state_info){PM_STATE_ACTIVE, 0, 0};
|
2020-10-02 16:09:38 +10:00
|
|
|
}
|
2020-12-16 06:22:16 +11:00
|
|
|
|
2021-06-19 19:57:33 +10:00
|
|
|
__weak bool pm_policy_low_power_devices(enum pm_state state) { return pm_is_sleep_state(state); }
|