-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Experimental: Automatic power domain handling for displays/RGB #1775
base: main
Are you sure you want to change the base?
Changes from all commits
abc36d9
bcce93a
2a242c2
0a218a5
655295c
7a345eb
2ebc94d
a091207
edf7b80
a7d37d3
a2c2cc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -296,9 +296,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 | ||||||||
depends on !ZMK_POWER_DOMAINS | ||||||||
|
||||||||
config ZMK_RGB_UNDERGLOW_BRT_MIN | ||||||||
int "RGB underglow minimum brightness in percent" | ||||||||
|
@@ -361,6 +368,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 | ||||||||
|
||||||||
|
@@ -435,23 +443,37 @@ 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 | ||||||||
select DEVICE_DEPS_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 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Perhaps you know of some better way to wall this off for boards which don't have an external power cutoff? It's already a bit of a thorn in the side of STM32/RP2040. |
||||||||
|
||||||||
config ZMK_PM | ||||||||
bool | ||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -6,7 +6,6 @@ | |||||
|
||||||
/dts-v1/; | ||||||
#include <nordic/nrf52840_qiaa.dtsi> | ||||||
#include "arduino_pro_micro_pins.dtsi" | ||||||
#include "puchi_ble_v1-pinctrl.dtsi" | ||||||
|
||||||
/ { | ||||||
|
@@ -18,6 +17,7 @@ | |||||
zephyr,sram = &sram0; | ||||||
zephyr,flash = &flash0; | ||||||
zmk,battery = &vbatt; | ||||||
zmk,default-power-domain = &core_power_domain; | ||||||
}; | ||||||
|
||||||
leds { | ||||||
|
@@ -33,6 +33,14 @@ | |||||
control-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; | ||||||
}; | ||||||
|
||||||
core_power_domain: core_power_domain { | ||||||
compatible = "power-domain-gpio", "power-domain"; | ||||||
startup-delay-us = <50000>; | ||||||
off-on-delay-us = <50000>; | ||||||
enable-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; | ||||||
zephyr,pm-device-runtime-auto; | ||||||
}; | ||||||
|
||||||
vbatt: vbatt { | ||||||
compatible = "zmk,battery-voltage-divider"; | ||||||
io-channels = <&adc 2>; | ||||||
|
@@ -79,7 +87,7 @@ zephyr_udc0: &usbd { | |||||
&flash0 { | ||||||
/* | ||||||
* For more information, see: | ||||||
* http://docs.zephyrproject.org/latest/devices/dts/flash_partitions.html | ||||||
* http: //docs.zephyrproject.org/latest/devices/dts/flash_partitions.html | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
partitions { | ||||||
compatible = "fixed-partitions"; | ||||||
|
@@ -111,3 +119,6 @@ zephyr_udc0: &usbd { | |||||
}; | ||||||
}; | ||||||
}; | ||||||
|
||||||
// Included at the end to ensure the power domain DTS node exists | ||||||
#include "arduino_pro_micro_pins.dtsi" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_ZMK_POWER_DOMAINS=y |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,4 +63,4 @@ encoder: &qdec0 { | |
|
||
wakeup-sources = <&soft_off_direct_kscan>; | ||
}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,11 +22,17 @@ nice_view_spi: &arduino_spi { | |||||
// on the bus, properly picking up the first `cs-gpios` specifier. | ||||||
ls0xx@0 { | ||||||
reg = <0>; | ||||||
|
||||||
power-domain = <&core_power_domain>; | ||||||
zephyr,pm-device-runtime-auto; | ||||||
}; | ||||||
|
||||||
led_strip: ws2812@0 { | ||||||
compatible = "worldsemi,ws2812-spi"; | ||||||
|
||||||
power-domain = <&rgb_power>; | ||||||
zephyr,pm-device-runtime-auto; | ||||||
|
||||||
/* SPI */ | ||||||
reg = <0>; /* ignored, but necessary for SPI bindings */ | ||||||
spi-max-frequency = <4000000>; | ||||||
|
@@ -37,26 +43,35 @@ nice_view_spi: &arduino_spi { | |||||
spi-zero-frame = <0x40>; | ||||||
|
||||||
color-mapping = <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE>; | ||||||
|
||||||
}; | ||||||
}; | ||||||
|
||||||
/ { | ||||||
chosen { | ||||||
zmk,backlight = &backlight; | ||||||
zmk,underglow = &led_strip; | ||||||
zephyr,display = &oled; | ||||||
zmk,display-default-power-domain = &core_power_domain; | ||||||
}; | ||||||
|
||||||
core_power_domain: core_power_domain { | ||||||
// The "power-domain" compatible is needed for any PDs used for that have dynamic deps, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
// e.g. for displays or RGB not assigned to the PD in the devicetree statically. | ||||||
compatible = "power-domain-gpio", "power-domain"; | ||||||
startup-delay-us = <2000>; | ||||||
off-on-delay-us = <2000>; | ||||||
enable-gpios = <&arduino_header 0 GPIO_ACTIVE_LOW>; | ||||||
zephyr,pm-device-runtime-auto; | ||||||
}; | ||||||
|
||||||
// Commented out until we add more powerful power domain support | ||||||
// external_power { | ||||||
// compatible = "zmk,ext-power-generic"; | ||||||
// init-delay-ms = <200>; | ||||||
// control-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; | ||||||
// }; | ||||||
|
||||||
rgb_power { | ||||||
compatible = "zmk,ext-power-generic"; | ||||||
init-delay-ms = <200>; | ||||||
control-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; | ||||||
rgb_power: rgb_power { | ||||||
compatible = "power-domain-gpio"; | ||||||
startup-delay-us = <200>; | ||||||
off-on-delay-us = <2000>; | ||||||
enable-gpios = <&arduino_header 1 GPIO_ACTIVE_LOW>; | ||||||
power-domain = <&core_power_domain>; | ||||||
zephyr,pm-device-runtime-auto; | ||||||
}; | ||||||
|
||||||
backlight: gpioleds { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion builds on my previous one.