diff --git a/app/Kconfig b/app/Kconfig index 86ff0461..02b6f829 100644 --- a/app/Kconfig +++ b/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 diff --git a/app/src/display/Kconfig b/app/src/display/Kconfig index 1cde0fe4..de8e4a01 100644 --- a/app/src/display/Kconfig +++ b/app/src/display/Kconfig @@ -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 diff --git a/app/src/display/main.c b/app/src/display/main.c index 870945c3..fe276903 100644 --- a/app/src/display/main.c +++ b/app/src/display/main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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(); diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 7f5bdc54..f14bbc8f 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -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,