From 90e070b427e28b83eb6b55620e2dee6627075374 Mon Sep 17 00:00:00 2001 From: ReFil <31960031+ReFil@users.noreply.github.com> Date: Sat, 25 Jun 2022 15:56:36 +0100 Subject: [PATCH 1/2] feat(underglow): Add RGB auto off timeout on idle and on usb disconnect Two new options for functionality to enable/disable RGB for USB status or idle events. Co-authored-by: Pete Johanson Co-authored-by: ReFil --- app/Kconfig | 7 +++++ app/src/rgb_underglow.c | 63 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/app/Kconfig b/app/Kconfig index 4bcd88b0..f89d3279 100644 --- a/app/Kconfig +++ b/app/Kconfig @@ -243,6 +243,13 @@ config ZMK_RGB_UNDERGLOW_ON_START bool "RGB underglow starts on by default" default y +config ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE + bool "Turn off RGB underglow when keyboard goes into idle state" + +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 diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 517da1b8..25d4466e 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -19,6 +19,12 @@ #include +#include +#include +#include +#include +#include + LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); #define STRIP_LABEL DT_LABEL(DT_CHOSEN(zmk_underglow)) @@ -265,7 +271,13 @@ static int zmk_rgb_underglow_init(const struct device *_arg) { settings_load_subtree("rgb/underglow"); #endif - k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); +#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB) + state.on = zmk_usb_is_powered(); +#endif + + if (state.on) { + k_timer_start(&underglow_tick, K_NO_WAIT, K_MSEC(50)); + } return 0; } @@ -444,4 +456,53 @@ int zmk_rgb_underglow_change_spd(int direction) { return zmk_rgb_underglow_save_state(); } +#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE) || \ + IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB) +static int rgb_underglow_auto_state(bool *prev_state, bool new_state) { + if (state.on == new_state) { + return 0; + } + if (new_state) { + state.on = *prev_state; + *prev_state = false; + return zmk_rgb_underglow_on(); + } else { + state.on = false; + *prev_state = true; + return zmk_rgb_underglow_off(); + } +} + +static int rgb_underglow_event_listener(const zmk_event_t *eh) { + +#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE) + if (as_zmk_activity_state_changed(eh)) { + static bool prev_state = false; + return rgb_underglow_auto_state(&prev_state, + zmk_activity_get_state() == ZMK_ACTIVITY_ACTIVE); + } +#endif + +#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB) + if (as_zmk_usb_conn_state_changed(eh)) { + static bool prev_state = false; + return rgb_underglow_auto_state(&prev_state, zmk_usb_is_powered()); + } +#endif + + return -ENOTSUP; +} + +ZMK_LISTENER(rgb_underglow, rgb_underglow_event_listener); +#endif // IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE) || + // IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB) + +#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE) +ZMK_SUBSCRIPTION(rgb_underglow, zmk_activity_state_changed); +#endif + +#if IS_ENABLED(CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_USB) +ZMK_SUBSCRIPTION(rgb_underglow, zmk_usb_conn_state_changed); +#endif + SYS_INIT(zmk_rgb_underglow_init, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY); From da209c453eac57b9bb3818a81ad9b20345618c4b Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Mon, 20 Jun 2022 03:54:19 +0000 Subject: [PATCH 2/2] refactor(shields): Remove res max Kconfigs * Horizontal/Vertical resolution max is now defaulted from the DTS chosen display automatically, so remove the duplication in our shield Kconfig. --- app/boards/shields/corne/Kconfig.defconfig | 6 ------ app/boards/shields/elephant42/Kconfig.defconfig | 6 ------ app/boards/shields/jorne/Kconfig.defconfig | 6 ------ app/boards/shields/knob_goblin/Kconfig.defconfig | 6 ------ app/boards/shields/kyria/Kconfig.defconfig | 6 ------ app/boards/shields/leeloo/Kconfig.defconfig | 5 ----- app/boards/shields/lily58/Kconfig.defconfig | 6 ------ app/boards/shields/lotus58/Kconfig.defconfig | 6 ------ app/boards/shields/microdox/Kconfig.defconfig | 6 ------ app/boards/shields/murphpad/Kconfig.defconfig | 6 ------ app/boards/shields/nibble/Kconfig.defconfig | 6 ------ app/boards/shields/sofle/Kconfig.defconfig | 6 ------ app/boards/shields/tidbit/Kconfig.defconfig | 6 ------ app/boards/shields/zodiark/Kconfig.defconfig | 6 ------ 14 files changed, 83 deletions(-) diff --git a/app/boards/shields/corne/Kconfig.defconfig b/app/boards/shields/corne/Kconfig.defconfig index 31ca73fd..9160555c 100644 --- a/app/boards/shields/corne/Kconfig.defconfig +++ b/app/boards/shields/corne/Kconfig.defconfig @@ -28,12 +28,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/elephant42/Kconfig.defconfig b/app/boards/shields/elephant42/Kconfig.defconfig index 051e3e89..1e93762c 100644 --- a/app/boards/shields/elephant42/Kconfig.defconfig +++ b/app/boards/shields/elephant42/Kconfig.defconfig @@ -31,12 +31,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/jorne/Kconfig.defconfig b/app/boards/shields/jorne/Kconfig.defconfig index 8d4dfb99..64eb32b8 100644 --- a/app/boards/shields/jorne/Kconfig.defconfig +++ b/app/boards/shields/jorne/Kconfig.defconfig @@ -29,12 +29,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/knob_goblin/Kconfig.defconfig b/app/boards/shields/knob_goblin/Kconfig.defconfig index 07df5996..300fb4eb 100644 --- a/app/boards/shields/knob_goblin/Kconfig.defconfig +++ b/app/boards/shields/knob_goblin/Kconfig.defconfig @@ -21,12 +21,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/kyria/Kconfig.defconfig b/app/boards/shields/kyria/Kconfig.defconfig index 2995daac..0da8a18d 100644 --- a/app/boards/shields/kyria/Kconfig.defconfig +++ b/app/boards/shields/kyria/Kconfig.defconfig @@ -29,12 +29,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 64 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/leeloo/Kconfig.defconfig b/app/boards/shields/leeloo/Kconfig.defconfig index a3f4eff3..a4295d1e 100644 --- a/app/boards/shields/leeloo/Kconfig.defconfig +++ b/app/boards/shields/leeloo/Kconfig.defconfig @@ -31,11 +31,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/lily58/Kconfig.defconfig b/app/boards/shields/lily58/Kconfig.defconfig index 7da758cd..a5e6fbe8 100644 --- a/app/boards/shields/lily58/Kconfig.defconfig +++ b/app/boards/shields/lily58/Kconfig.defconfig @@ -29,12 +29,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/lotus58/Kconfig.defconfig b/app/boards/shields/lotus58/Kconfig.defconfig index d108d7d8..57ae5ef6 100644 --- a/app/boards/shields/lotus58/Kconfig.defconfig +++ b/app/boards/shields/lotus58/Kconfig.defconfig @@ -31,12 +31,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/microdox/Kconfig.defconfig b/app/boards/shields/microdox/Kconfig.defconfig index 461e7c32..7bf40b8b 100644 --- a/app/boards/shields/microdox/Kconfig.defconfig +++ b/app/boards/shields/microdox/Kconfig.defconfig @@ -31,12 +31,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/murphpad/Kconfig.defconfig b/app/boards/shields/murphpad/Kconfig.defconfig index 8e205a8e..9f491564 100644 --- a/app/boards/shields/murphpad/Kconfig.defconfig +++ b/app/boards/shields/murphpad/Kconfig.defconfig @@ -21,12 +21,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/nibble/Kconfig.defconfig b/app/boards/shields/nibble/Kconfig.defconfig index 2df1d812..a1683f3a 100644 --- a/app/boards/shields/nibble/Kconfig.defconfig +++ b/app/boards/shields/nibble/Kconfig.defconfig @@ -25,12 +25,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/sofle/Kconfig.defconfig b/app/boards/shields/sofle/Kconfig.defconfig index bfa7c3a5..69dac3f2 100644 --- a/app/boards/shields/sofle/Kconfig.defconfig +++ b/app/boards/shields/sofle/Kconfig.defconfig @@ -31,12 +31,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/tidbit/Kconfig.defconfig b/app/boards/shields/tidbit/Kconfig.defconfig index 177e2675..013a0a7c 100644 --- a/app/boards/shields/tidbit/Kconfig.defconfig +++ b/app/boards/shields/tidbit/Kconfig.defconfig @@ -22,12 +22,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 32 - config LVGL_VDB_SIZE default 64 diff --git a/app/boards/shields/zodiark/Kconfig.defconfig b/app/boards/shields/zodiark/Kconfig.defconfig index 7780abd2..76bfcbd4 100644 --- a/app/boards/shields/zodiark/Kconfig.defconfig +++ b/app/boards/shields/zodiark/Kconfig.defconfig @@ -31,12 +31,6 @@ endif # ZMK_DISPLAY if LVGL -config LVGL_HOR_RES_MAX - default 128 - -config LVGL_VER_RES_MAX - default 64 - config LVGL_VDB_SIZE default 64