underglow-layer: track layer changes with event & battery life optimization

I tried using event instead of the 25ms underglow_tick to update the underglow on
layer change only. That didn't improve the battery life much....
The second change is cutting off the led strip power if the underglow is
not defined for a layer. Power is restored if a layer with rgb is
activated, and cut off as soon as the layer is disabled.
This, on the other hand, improves the battery life a lot, especially if you
don't use rgb on your base layer.
If you are using rgb on your base layer, setting
CONFIG_ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE is highly recommended.
This commit is contained in:
darknao 2024-05-08 02:07:54 +02:00 committed by afiqzudinhadi
parent 6f9a411793
commit 0ca086a845
8 changed files with 61 additions and 16 deletions

View file

@ -0,0 +1,16 @@
/*
* Copyright (c) 2022 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/
#pragma once
#include <zephyr/kernel.h>
#include <zmk/event_manager.h>
struct zmk_split_peripheral_layer_changed {
uint32_t layers;
};
ZMK_EVENT_DECLARE(zmk_split_peripheral_layer_changed);

View file

@ -14,5 +14,5 @@
(DT_FOREACH_CHILD(DT_INST(0, zmk_underglow_layer), ZMK_RGB_CHILD_LEN_PLUS_ONE) 0)
const int zmk_rgbmap_id(uint8_t layer);
uint32_t *rgb_underglow_get_bindings(void);
uint8_t rgb_underglow_top_layer(void);
uint32_t *rgb_underglow_get_bindings(uint8_t layer);
uint8_t rgb_underglow_top_layer_with_state(uint32_t state_to_test);