feat(power): Add power domain config
* High level ZMK_POWER_DOMAINS for the feature. * ZMK_POWER_DOMAINS_DYNAMIC_DEFAULT config setting to have various subsystems add their respective devices to the chosen `zmk,default-power-domain` on init.
This commit is contained in:
parent
5ccc0b94ca
commit
ce511cb769
4 changed files with 64 additions and 9 deletions
39
app/Kconfig
39
app/Kconfig
|
@ -273,9 +273,16 @@ if ZMK_RGB_UNDERGLOW
|
|||
config SPI
|
||||
default y
|
||||
|
||||
|
||||
config ZMK_RGB_UNDERGLOW_DEFAULT_POWER_DOMAIN
|
||||
bool "Auto-assign the RGB underglow to the default power domain"
|
||||
default y
|
||||
depends on ZMK_POWER_DOMAINS_DYNAMIC_DEFAULT
|
||||
|
||||
config ZMK_RGB_UNDERGLOW_EXT_POWER
|
||||
bool "RGB underglow toggling also controls external power"
|
||||
default y if !POWER_DOMAIN
|
||||
default y
|
||||
depends on !ZMK_POWER_DOMAINS
|
||||
|
||||
config ZMK_RGB_UNDERGLOW_BRT_MIN
|
||||
int "RGB underglow minimum brightness in percent"
|
||||
|
@ -338,6 +345,7 @@ config ZMK_RGB_UNDERGLOW_AUTO_OFF_USB
|
|||
bool "Turn off RGB underglow when USB is disconnected"
|
||||
depends on USB_DEVICE_STACK
|
||||
|
||||
|
||||
#ZMK_RGB_UNDERGLOW
|
||||
endif
|
||||
|
||||
|
@ -412,23 +420,36 @@ config ZMK_SLEEP
|
|||
depends on HAS_POWEROFF
|
||||
select POWEROFF
|
||||
select ZMK_PM_DEVICE_SUSPEND_RESUME
|
||||
select PM_DEVICE
|
||||
imply USB
|
||||
|
||||
if ZMK_SLEEP
|
||||
|
||||
config PM_DEVICE
|
||||
default y
|
||||
|
||||
config ZMK_IDLE_SLEEP_TIMEOUT
|
||||
int "Milliseconds of inactivity before entering deep sleep"
|
||||
depends on ZMK_SLEEP
|
||||
default 900000
|
||||
|
||||
#ZMK_SLEEP
|
||||
endif
|
||||
config ZMK_POWER_DOMAINS
|
||||
bool "Enable automatic power domain handling"
|
||||
default n
|
||||
select PM_DEVICE
|
||||
select PM_DEVICE_POWER_DOMAIN
|
||||
select PM_DEVICE_RUNTIME
|
||||
select POWER_DOMAIN
|
||||
select POWER_DOMAIN_GPIO
|
||||
|
||||
config ZMK_POWER_DOMAINS_DYNAMIC_DEFAULT
|
||||
bool "Enable assigning peripherals to the chosen default power domain"
|
||||
default n
|
||||
depends on ZMK_POWER_DOMAINS
|
||||
select PM_DEVICE_POWER_DOMAIN_DYNAMIC
|
||||
|
||||
# Default this to 2, the most common scenario for this for ZMK is RGB + OLED
|
||||
config PM_DEVICE_POWER_DOMAIN_DYNAMIC_NUM
|
||||
default 2
|
||||
|
||||
config ZMK_EXT_POWER
|
||||
bool "Enable support to control external power output"
|
||||
default y
|
||||
default y if !ZMK_POWER_DOMAINS
|
||||
|
||||
config ZMK_PM
|
||||
bool
|
||||
|
|
|
@ -13,6 +13,11 @@ config ZMK_DISPLAY_BLANK_ON_IDLE
|
|||
bool "Blank display on idle"
|
||||
default y if SSD1306
|
||||
|
||||
config ZMK_DISPLAY_DEFAULT_POWER_DOMAIN
|
||||
bool "Auto-assign the display to the default power domain"
|
||||
default y
|
||||
depends on ZMK_POWER_DOMAINS_DYNAMIC_DEFAULT
|
||||
|
||||
if LV_USE_THEME_MONO
|
||||
|
||||
config ZMK_DISPLAY_INVERT
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
#include <zephyr/pm/device_runtime.h>
|
||||
#include <zephyr/devicetree.h>
|
||||
|
||||
|
@ -118,6 +119,19 @@ void initialize_display(struct k_work *work) {
|
|||
return;
|
||||
}
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_DISPLAY_DEFAULT_POWER_DOMAIN) && DT_HAS_CHOSEN(zmk_default_power_domain)
|
||||
|
||||
pm_device_runtime_enable(display);
|
||||
if (!pm_device_on_power_domain(display)) {
|
||||
int rc =
|
||||
pm_device_power_domain_add(display, DEVICE_DT_GET(DT_CHOSEN(zmk_default_power_domain)));
|
||||
if (rc < 0) {
|
||||
LOG_ERR("Failed to add the display to the default power domain (0x%02x)", -rc);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
initialized = true;
|
||||
|
||||
initialize_theme();
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <zephyr/device.h>
|
||||
#include <zephyr/init.h>
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/pm/device.h>
|
||||
#include <zephyr/pm/device_runtime.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
|
||||
|
@ -254,6 +255,20 @@ static int zmk_rgb_underglow_init(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_DEFAULT_POWER_DOMAIN) && \
|
||||
DT_HAS_CHOSEN(zmk_default_power_domain)
|
||||
|
||||
pm_device_runtime_enable(led_strip);
|
||||
if (!pm_device_on_power_domain(led_strip)) {
|
||||
int rc = pm_device_power_domain_add(led_strip,
|
||||
DEVICE_DT_GET(DT_CHOSEN(zmk_default_power_domain)));
|
||||
if (rc < 0) {
|
||||
LOG_ERR("Failed to add the LED strip to the default power domain (0x%02x)", -rc);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
state = (struct rgb_underglow_state){
|
||||
color : {
|
||||
h : CONFIG_ZMK_RGB_UNDERGLOW_HUE_START,
|
||||
|
|
Loading…
Add table
Reference in a new issue