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
|
config SPI
|
||||||
default y
|
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
|
config ZMK_RGB_UNDERGLOW_EXT_POWER
|
||||||
bool "RGB underglow toggling also controls external 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
|
config ZMK_RGB_UNDERGLOW_BRT_MIN
|
||||||
int "RGB underglow minimum brightness in percent"
|
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"
|
bool "Turn off RGB underglow when USB is disconnected"
|
||||||
depends on USB_DEVICE_STACK
|
depends on USB_DEVICE_STACK
|
||||||
|
|
||||||
|
|
||||||
#ZMK_RGB_UNDERGLOW
|
#ZMK_RGB_UNDERGLOW
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
@ -412,23 +420,36 @@ config ZMK_SLEEP
|
||||||
depends on HAS_POWEROFF
|
depends on HAS_POWEROFF
|
||||||
select POWEROFF
|
select POWEROFF
|
||||||
select ZMK_PM_DEVICE_SUSPEND_RESUME
|
select ZMK_PM_DEVICE_SUSPEND_RESUME
|
||||||
|
select PM_DEVICE
|
||||||
imply USB
|
imply USB
|
||||||
|
|
||||||
if ZMK_SLEEP
|
|
||||||
|
|
||||||
config PM_DEVICE
|
|
||||||
default y
|
|
||||||
|
|
||||||
config ZMK_IDLE_SLEEP_TIMEOUT
|
config ZMK_IDLE_SLEEP_TIMEOUT
|
||||||
int "Milliseconds of inactivity before entering deep sleep"
|
int "Milliseconds of inactivity before entering deep sleep"
|
||||||
|
depends on ZMK_SLEEP
|
||||||
default 900000
|
default 900000
|
||||||
|
|
||||||
#ZMK_SLEEP
|
config ZMK_POWER_DOMAINS
|
||||||
endif
|
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
|
config ZMK_EXT_POWER
|
||||||
bool "Enable support to control external power output"
|
bool "Enable support to control external power output"
|
||||||
default y
|
default y if !ZMK_POWER_DOMAINS
|
||||||
|
|
||||||
config ZMK_PM
|
config ZMK_PM
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -13,6 +13,11 @@ config ZMK_DISPLAY_BLANK_ON_IDLE
|
||||||
bool "Blank display on idle"
|
bool "Blank display on idle"
|
||||||
default y if SSD1306
|
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
|
if LV_USE_THEME_MONO
|
||||||
|
|
||||||
config ZMK_DISPLAY_INVERT
|
config ZMK_DISPLAY_INVERT
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
|
#include <zephyr/pm/device.h>
|
||||||
#include <zephyr/pm/device_runtime.h>
|
#include <zephyr/pm/device_runtime.h>
|
||||||
#include <zephyr/devicetree.h>
|
#include <zephyr/devicetree.h>
|
||||||
|
|
||||||
|
@ -118,6 +119,19 @@ void initialize_display(struct k_work *work) {
|
||||||
return;
|
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;
|
initialized = true;
|
||||||
|
|
||||||
initialize_theme();
|
initialize_theme();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <zephyr/device.h>
|
#include <zephyr/device.h>
|
||||||
#include <zephyr/init.h>
|
#include <zephyr/init.h>
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/pm/device.h>
|
||||||
#include <zephyr/pm/device_runtime.h>
|
#include <zephyr/pm/device_runtime.h>
|
||||||
#include <zephyr/settings/settings.h>
|
#include <zephyr/settings/settings.h>
|
||||||
|
|
||||||
|
@ -254,6 +255,20 @@ static int zmk_rgb_underglow_init(void) {
|
||||||
}
|
}
|
||||||
#endif
|
#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){
|
state = (struct rgb_underglow_state){
|
||||||
color : {
|
color : {
|
||||||
h : CONFIG_ZMK_RGB_UNDERGLOW_HUE_START,
|
h : CONFIG_ZMK_RGB_UNDERGLOW_HUE_START,
|
||||||
|
|
Loading…
Add table
Reference in a new issue