Skip to content
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

Per key/layer RGB underglow for 24.12 #36

Open
wants to merge 14 commits into
base: zmk-update
Choose a base branch
from

Conversation

darknao
Copy link

@darknao darknao commented Dec 30, 2024

This adds per key / per layer RGB underglow configuration on top of 24.12.
It's mainly based on @valdur mod with additional changes to make it configurable via devicetree.

This supersedes #30.

It includes:

  • Valdur's RGB mod
  • Refactor, move configuration to devicetree, and some battery life optimization
  • feat(split): Increase split interval during idle #682 from ZMK upstream

How to use:
More instructions are available on my config repo.
TLDR: Add and customize this snippet to the Custom Device-tree field in the layout editor:

#include <dt-bindings/zmk/rgb_colors.h>
/ {
    underglow-layer {
        compatible  = "zmk,underglow-layer";

        // example of RGB layer for the Lower keymap layer
        lower {
            bindings = <
                ______ ______ ______ ______ ______                                                          ______ ______ ______ ______ ______
                PURPLE   PINK   PINK   PINK   PINK   PINK                                            ______   GOLD ORANGE ORANGE ORANGE    RED
                PURPLE ______ ______ ORANGE ______ ______                                            ______ YELLOW YELLOW YELLOW ORANGE ______
                PURPLE ______ ORANGE    RED ORANGE ______                                            ______ YELLOW YELLOW YELLOW ORANGE ______
                  BLUE ______    RED    RED    RED ______ ______ ______ ______  ______ ______ ______ ______ YELLOW YELLOW YELLOW    RED   BLUE
                ______ ______ ORANGE ORANGE ORANGE        ______  GREEN ______  ______ ______ ______        YELLOW YELLOW YELLOW    RED ______
                >;
            layer-id = <LAYER_Lower>;
        };

        // This defines another RGB layer
        another-layer {
            bindings = < [...] >;
            layer-id = <LAYER_Name>;
        };
    };
};

______ means the RGB is off. You can use predefined color name or RGB hex code like 0xFF0000 for red.
Full example on the Layout Editor here

To preserve battery life, I recommend enabling the ZMK_RGB_UNDERGLOW_AUTO_OFF_IDLE KConfig to automatically turn off underglow after ZMK_IDLE_TIMEOUT ms (default to 30 seconds).
From my limited experience, you can expect around one week of battery life with no RGB on the base layer.

darknao and others added 12 commits December 30, 2024 13:25
…zation

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.
@helto4real
Copy link

Thanks for your work on this. I tried your PR and everything seem to work with the Glorious Engrammer v40. I enjoy finally being able to set RGB values individually.

In preparation for the re-do of zmkfirmware#2036 events that are useful for displays/indicators on the peripheral should be compiled on both sides so they can be raised on both sides
@gillamkid
Copy link

I tested using the Glove80 Layout Editor and was it worked for me! My layout can be seen here: https://dev.glove80.com/#/layout/user/6de3c382-9ced-4de8-a1a4-368b26e09d3f

Is this a feature that will make it into ZMK or Glove80 main or will it will it likely stay as a PR?

@darknao
Copy link
Author

darknao commented Jan 4, 2025

Is this a feature that will make it into ZMK or Glove80 main or will it will it likely stay as a PR?

My plan is to open a similar PR on ZMK, and see if I can work on getting it merged.
There are a few things that I need to clean up first, such as glove80-specific pieces of code, but I think I'm almost done with that.

@darknao
Copy link
Author

darknao commented Jan 4, 2025

The latest update introduces some breaking changes:

  • New format for the RGB binding: Underglow color is now set with &ug COLOR instead of just COLOR. This allows some advanced functionalities by using behavior, just like for keymap.
  • You can set underglow colors based on HID indicators such as NumLock, CapsLock & ScrollLock with the following behaviors:
    • &ug_nl COLOR_OFF COLOR_ON set the RGB according to the NumLock state.
    • &ug_cl COLOR_OFF COLOR_ON is for CapsLock.
    • &ug_sl COLOR_OFF COLOR_ON is for ScrollLock.
  • The HID indicators require the CONFIG_ZMK_SPLIT_PERIPHERAL_HID_INDICATORS Kconfig set. Without it, only the left side can use them. (That Kconfig is now set by default)
  • The old ______ (RGB off, 5 underscores) was renamed to ___ (3 underscores).

@gillamkid
Copy link

gillamkid commented Jan 7, 2025

I used the latest pr36 rgb 20250106120812 version on the Glove80 Layout Editor today (with the new &ug way of doing things) and it worked for me!

This is my Layout: https://dev.glove80.com/#/layout/user/c458ddd6-cac3-4269-a578-a1d9cd506e94

@dbosky
Copy link

dbosky commented Jan 10, 2025

Did anybody try to enable HID_POINTING and EXPERIMENTAL_RGB_LAYER on Engrammer v40 with this FW? RGB works for me but for some reason mouse is not. I did factory reset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants