Skip to content
9 changes: 9 additions & 0 deletions app/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,15 @@ config ZMK_IDLE_SLEEP_TIMEOUT
int "Milliseconds of inactivity before entering deep sleep"
default 900000

config ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED
bool "Prevent sleeping while the active BT profile is connected"
depends on ZMK_BLE
default n
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I missed; can you remove? See #2161

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default n


config ZMK_SLEEP_PREVENT_WHILE_USB_POWERED
bool "Prevent sleeping while USB power is connected"
default y

endif # ZMK_SLEEP

config ZMK_EXT_POWER
Expand Down
17 changes: 15 additions & 2 deletions app/src/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL);
#include <zmk/usb.h>
#endif

#if IS_ENABLED(CONFIG_ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED)
#include <zmk/ble.h>
#endif

#if IS_ENABLED(CONFIG_ZMK_POINTING)
#include <zephyr/input/input.h>
#endif
Expand Down Expand Up @@ -75,7 +79,16 @@ 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 && !is_usb_power_present()) {
bool prevent_sleep =
IS_ENABLED(CONFIG_ZMK_SLEEP_PREVENT_WHILE_USB_POWERED) && is_usb_power_present();
#if IS_ENABLED(CONFIG_ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED)
#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
prevent_sleep |= zmk_ble_active_profile_is_connected();
#else
prevent_sleep |= zmk_split_bt_peripheral_is_connected();
#endif
#endif
if (inactive_time > MAX_SLEEP_MS && !prevent_sleep) {
// Put devices in suspend power mode before sleeping
set_state(ZMK_ACTIVITY_SLEEP);

Expand Down Expand Up @@ -124,4 +137,4 @@ INPUT_CALLBACK_DEFINE(NULL, activity_input_listener, NULL);

#endif

SYS_INIT(activity_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
SYS_INIT(activity_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
18 changes: 11 additions & 7 deletions docs/docs/config/power.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


---
title: Power Management Configuration
sidebar_label: Power Management
Expand All @@ -14,12 +16,14 @@ Configuration for entering [low power states](../features/low-power-states.md) w

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

| Config | Type | Description | Default |
| ------------------------------- | ---- | ------------------------------------------------------------------- | ------- |
| `CONFIG_ZMK_IDLE_TIMEOUT` | int | Milliseconds of inactivity before entering idle state | 30000 |
| `CONFIG_ZMK_SLEEP` | bool | Enable deep sleep support | n |
| `CONFIG_ZMK_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 |
| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap or dedicated hardware | n |
| Config | Type | Description | Default |
| ----------------------------------------------------- | ---- | ------------------------------------------------------------------------------------------------------------------------------------------ | ------- |
| `CONFIG_ZMK_IDLE_TIMEOUT` | int | Milliseconds of inactivity before entering idle state | 30000 |
| `CONFIG_ZMK_SLEEP` | bool | Enable deep sleep support | n |
| `CONFIG_ZMK_IDLE_SLEEP_TIMEOUT` | int | Milliseconds of inactivity before entering deep sleep | 900000 |
| `CONFIG_ZMK_PM_SOFT_OFF` | bool | Enable soft off functionality from the keymap or dedicated hardware | n |
| `CONFIG_ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED` | bool | Prevent sleeping while the active BT profile is connected. If the device loses connection after the sleep timer, it will sleep immediately | n |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `CONFIG_ZMK_BLE_PREVENT_SLEEP_WHILE_ACTIVE_CONNECTED` | bool | Prevent sleeping while the active BT profile is connected. If the device loses connection after the sleep timer, it will sleep immediately | n |
| `CONFIG_ZMK_SLEEP_PREVENT_WHILE_BLE_CONNECTED` | bool | Prevent sleeping while the active BT profile is connected. If the device loses connection after the sleep timer, it will sleep immediately | n |

mismatching the Kconfig file; also will need a prettier pass to fix table formatting

| `CONFIG_ZMK_USB_PREVENT_SLEEP_WHILE_POWERED` | bool | Prevent sleeping while USB power is connected | y |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `CONFIG_ZMK_USB_PREVENT_SLEEP_WHILE_POWERED` | bool | Prevent sleeping while USB power is connected | y |
| `CONFIG_ZMK_SLEEP_PREVENT_WHILE_USB_POWERED` | bool | Prevent sleeping while USB power is connected | y |


## External Power Control

Expand Down Expand Up @@ -70,4 +74,4 @@ Applies to: `compatible = "zmk,soft-off-wakeup-sources"`

| Property | Type | Description |
| ---------------- | ------------- | ------------------------------------------------------------------------------------------------- |
| `wakeup-sources` | phandle array | List of devices to enable during the shutdown process to be sure they can later wake the keyboard |
| `wakeup-sources` | phandle array | List of devices to enable during the shutdown process to be sure they can later wake the keyboard |
Loading