Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(power) Add additional idle options #2398

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ config ZMK_BLE_EXPERIMENTAL_CONN
bool "Experimental BLE connection changes"
help
Enables a combination of settings that are planned to be default in future versions of ZMK
to improve connection stability. This includes changes to timing on BLE pairing initiation,
restores use of the updated/new LLCP implementation, and disables 2M PHY support.
to improve connection stability.

config ZMK_BLE_EXPERIMENTAL_SEC
bool "Experimental BLE security changes"
Expand Down Expand Up @@ -407,6 +406,10 @@ config ZMK_IDLE_TIMEOUT
int "Milliseconds of inactivity before entering idle state (OLED shutoff, etc)"
default 30000

config ZMK_IDLE_USB
bool "Allow idling while connected to USB"
default y

config ZMK_SLEEP
bool "Enable deep sleep support"
depends on HAS_POWEROFF
Expand All @@ -430,6 +433,10 @@ config ZMK_EXT_POWER
bool "Enable support to control external power output"
default y

config ZMK_EXT_POWER_IDLE_OFF
bool "Turn off external power while idle"
depends on ZMK_EXT_POWER

config ZMK_PM
bool

Expand Down
26 changes: 24 additions & 2 deletions app/src/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/events/sensor_event.h>

#include <zmk/pm.h>
#include <drivers/ext_power.h>

#include <zmk/activity.h>

Expand Down Expand Up @@ -60,8 +61,17 @@ int set_state(enum zmk_activity_state state) {
enum zmk_activity_state zmk_activity_get_state(void) { return activity_state; }

int activity_event_listener(const zmk_event_t *eh) {
#if IS_ENABLED(CONFIG_ZMK_EXT_POWER_IDLE_OFF)
if (activity_state == ZMK_ACTIVITY_IDLE) {
const struct device *ext_power = device_get_binding("EXT_POWER");
if (ext_power == NULL) {
LOG_ERR("Unable to retrieve ext_power device on idle wake.");
} else {
ext_power_enable(ext_power);
}
}
#endif /* IS_ENABLED(CONFIG_ZMK_EXT_POWER_IDLE_OFF) */
activity_last_uptime = k_uptime_get();

return set_state(ZMK_ACTIVITY_ACTIVE);
}

Expand All @@ -82,7 +92,19 @@ void activity_work_handler(struct k_work *work) {
sys_poweroff();
} else
#endif /* IS_ENABLED(CONFIG_ZMK_SLEEP) */
if (inactive_time > MAX_IDLE_MS) {
if (inactive_time > MAX_IDLE_MS
#if !IS_ENABLED(CONFIG_ZMK_IDLE_USB)
&& !is_usb_power_present()
#endif /* IS_ENABLED(CONFIG_ZMK_IDLE_USB) */
) {
#if IS_ENABLED(CONFIG_ZMK_EXT_POWER_IDLE_OFF)
const struct device *ext_power = device_get_binding("EXT_POWER");
if (ext_power == NULL) {
LOG_ERR("Unable to retrieve ext_power device on entering idle.");
} else {
ext_power_disable(ext_power);
}
#endif /* IS_ENABLED(CONFIG_ZMK_EXT_POWER_IDLE_OFF) */
set_state(ZMK_ACTIVITY_IDLE);
}
}
Expand Down
8 changes: 5 additions & 3 deletions docs/docs/config/power.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/
| Config | Type | Description | Default |
| ------------------------------- | ---- | ----------------------------------------------------- | ------- |
| `CONFIG_ZMK_IDLE_TIMEOUT` | int | Milliseconds of inactivity before entering idle state | 30000 |
| `CONFIG_ZMK_IDLE_USB` | bool | Enable idling while connected to USB power | y |
| `CONFIG_ZMK_SLEEP` | bool | Enable deep sleep support | n |
| `CONFIG_ZMK_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 |

Expand All @@ -44,9 +45,10 @@ Driver for enabling or disabling power to peripherals such as displays and light

Definition file: [zmk/app/Kconfig](https://github.com/zmkfirmware/zmk/blob/main/app/Kconfig)

| Config | Type | Description | Default |
| ---------------------- | ---- | ----------------------------------------------- | ------- |
| `CONFIG_ZMK_EXT_POWER` | bool | Enable support to control external power output | y |
| Config | Type | Description | Default |
| ------------------------------- | ---- | ----------------------------------------------- | ------- |
| `CONFIG_ZMK_EXT_POWER` | bool | Enable support to control external power output | y |
| `CONFIG_ZMK_EXT_POWER_IDLE_OFF` | bool | Turn off external power while idle | n |

### Devicetree

Expand Down