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

Layer LED Indicators Implementation Guide Needed #2786

Closed
TimoWielink opened this issue Jan 21, 2025 · 2 comments
Closed

Layer LED Indicators Implementation Guide Needed #2786

TimoWielink opened this issue Jan 21, 2025 · 2 comments

Comments

@TimoWielink
Copy link

TimoWielink commented Jan 21, 2025

I am looking for some help to see if it's possible to Implement simple LED indicators to show which layer is currently active on a custom keyboard.

Hardware Setup

  • Board: nice_nano_v2
  • LED Connections:
    • Layer 0 LED: P1.13 (GPIO1_13)
    • Layer 1 LED: P0.09 (GPIO0_09)
    • Layer 2 LED: P1.11 (GPIO1_11)

Current Implementation

LED Node Definition (.overlay)

layer_leds {
    compatible = "gpio-leds";
    layer0_led: layer0_led {
        gpios = <&gpio1 13 GPIO_ACTIVE_HIGH>;
        status = "okay";
    };
    layer1_led: layer1_led {
        gpios = <&gpio0 9 GPIO_ACTIVE_HIGH>;
        status = "okay";
    };
    layer2_led: layer2_led {
        gpios = <&gpio1 11 GPIO_ACTIVE_HIGH>;
        status = "okay";
    };
};

Behavior Attempt (.keymap)

behaviors {
    layer0_led_on: layer0_led_on {
        compatible = "zmk,behavior-output";
        #binding-cells = <0>;
        gpios = <&layer0_led>;
        output-high;
    };
    // ... similar definitions for other LEDs ...
};

macros {
    to_layer0: to_layer0 {
        compatible = "zmk,behavior-macro";
        #binding-cells = <0>;
        bindings = <&to DEFAULT>, <&layer0_led_on>, <&layer1_led_off>, <&layer2_led_off>;
    };
    // ... similar definitions for other layers ...
};

Configuration (.conf)

CONFIG_GPIO=y
CONFIG_LED=y
CONFIG_LED_GPIO=y
CONFIG_ZMK_MACRO=y

Current Error

devicetree error: binding controller <Node /behaviors/layer0_led_on in '/tmp/zmk-config/zephyr/misc/empty_file.c'> for <Node /macros/to_layer0 in '/tmp/zmk-config/zephyr/misc/empty_file.c'> lacks binding

Questions

  1. What is the correct way to implement LED layer indicators in ZMK?
  2. Is there a specific behavior type we should use for GPIO LED control?
  3. Are there any example implementations we can reference?

Additional Context

We've tried various approaches including:

  • zmk,behavior-gpio
  • zmk,behavior-output
  • zmk,behavior-led-control
  • Direct GPIO references and LED node references

The goal is to have the corresponding LED turn on for the active layer while turning off the LEDs for other layers. Any guidance on the proper way to implement this functionality would be greatly appreciated!

@caksoylar
Copy link
Contributor

caksoylar commented Jan 21, 2025

What is the correct way to implement LED layer indicators in ZMK?

A small module is probably what I'd go for for maintainability, but see the answers below.

Is there a specific behavior type we should use for GPIO LED control?

  • Backlight behavior can control GPIO LEDs (doesn't have to be PWM) but it doesn't support multiple different instances for different LEDs
  • Underglow only works for smart LED strips, not GPIO-based LEDs
  • External power control also works with toggling only one pin

So no, there is no good built-in solution to toggle multiple different GPIOs.

Are there any example implementations we can reference?

There is a community-based solution: @elpekenin's userspace has two functions that you can combine to achieve this:

  • A layer callbacks feature that triggers a listed behavior on layer on/off (another alternative here)
  • A behavior to control individual GPIOs called &gpio

The examples in the README combine the two to essentially create layer indicator LEDs.

As an aside, all the available behaviors are documented in the docs: https://zmk.dev/docs/keymaps/behaviors. The ones you tried don't exist, otherwise they'd be documented.

@TimoWielink
Copy link
Author

@caksoylar Thank you! I was able to get something working with Elpekenin example.

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

No branches or pull requests

2 participants