Browse Source

refactor: Move to new PM API/Kconfig settings.

xmkb
Peter Johanson 3 years ago committed by Pete Johanson
parent
commit
79ab60dfe5
  1. 1
      app/CMakeLists.txt
  2. 4
      app/Kconfig
  3. 16
      app/src/activity.c
  4. 34
      app/src/power.c

1
app/CMakeLists.txt

@ -22,7 +22,6 @@ zephyr_linker_sources(RODATA include/linker/zmk-events.ld) @@ -22,7 +22,6 @@ zephyr_linker_sources(RODATA include/linker/zmk-events.ld)
# Add your source file to the "app" target. This must come after
# find_package(Zephyr) which defines the target.
target_include_directories(app PRIVATE include)
target_sources_ifdef(CONFIG_ZMK_SLEEP app PRIVATE src/power.c)
target_sources(app PRIVATE src/stdlib.c)
target_sources(app PRIVATE src/activity.c)
target_sources(app PRIVATE src/kscan.c)

4
app/Kconfig

@ -372,10 +372,6 @@ config ZMK_SLEEP @@ -372,10 +372,6 @@ config ZMK_SLEEP
if ZMK_SLEEP
choice SYS_PM_POLICY
default PM_POLICY_APP
endchoice
config PM_DEVICE
default y

16
app/src/activity.c

@ -7,7 +7,7 @@ @@ -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); @@ -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) { @@ -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);

34
app/src/power.c

@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
/*
* 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>
#include <zmk/activity.h>
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) */
}
struct pm_state_info pm_policy_next_state(int32_t ticks) {
if (zmk_activity_get_state() == ZMK_ACTIVITY_SLEEP && !is_usb_power_present()) {
return (struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0};
}
return (struct pm_state_info){PM_STATE_ACTIVE, 0, 0};
}
__weak bool pm_policy_low_power_devices(enum pm_state state) { return pm_is_sleep_state(state); }
Loading…
Cancel
Save