From 188ce5b4560f3161cacc8443f4cfa8fb30a7c6c5 Mon Sep 17 00:00:00 2001 From: Sean Kelley Date: Sun, 10 Mar 2024 00:46:41 -0800 Subject: [PATCH] indicator-underglow: allow omissions; allow right-hand battery indicators. This commit does two things: 1. Provides default values for all indicator-underglow properties, which allows you to omit them entirely if you do not want that indicator. 2. Allows the right side to specify battery indicators. I changed the phrasing of the battery left/right properties to be self/other instead. For (2), note that this currently does not work with the default Glove80 definition for the magic (indicator) key, since the right side does not received the macro-wrapped `&rgb_ug RGB_STATUS` keypress. See the usptream issue https://github.com/zmkfirmware/zmk/issues/1494 for more. (I resolved this for my own build by incorporating the changes from https://github.com/zmkfirmware/zmk/pull/1630.) --- app/boards/arm/glove80/glove80_lh.dts | 4 +- app/boards/arm/glove80/glove80_rh.dts | 20 +++++++- .../bindings/zmk,underglow-indicators.yaml | 22 ++++----- app/src/rgb_underglow.c | 46 ++++++++++--------- 4 files changed, 57 insertions(+), 35 deletions(-) diff --git a/app/boards/arm/glove80/glove80_lh.dts b/app/boards/arm/glove80/glove80_lh.dts index 43b620a3cbc..bff3dbd5f22 100644 --- a/app/boards/arm/glove80/glove80_lh.dts +++ b/app/boards/arm/glove80/glove80_lh.dts @@ -54,8 +54,8 @@ underglow_indicators: underglow-indicators { compatible = "zmk,underglow-indicators"; layer-state = <35 29 23 17 11 6>; - bat-lhs = <36 30 24 18 12 7>; - bat-rhs = <37 31 25 19 13 8>; + bat-self = <36 30 24 18 12 7>; + bat-other = <37 31 25 19 13 8>; capslock = <22>; numlock = <16>; scrolllock = <10>; diff --git a/app/boards/arm/glove80/glove80_rh.dts b/app/boards/arm/glove80/glove80_rh.dts index 6f108d74763..66a6dca1668 100644 --- a/app/boards/arm/glove80/glove80_rh.dts +++ b/app/boards/arm/glove80/glove80_rh.dts @@ -4,7 +4,6 @@ * SPDX-License-Identifier: MIT */ - #include "glove80.dtsi" #include "glove80_rh-pinctrl.dtsi" @@ -18,6 +17,7 @@ zmk,underglow = &led_strip; zmk,backlight = &back_led_backlight; zmk,battery = &vbatt; + zmk,underglow-indicators = &underglow_indicators; }; back_led_backlight: pwmleds { @@ -37,6 +37,24 @@ vbatt: vbatt { compatible = "zmk,battery-nrf-vddh"; }; + +/* + MoErgo 40 LEDs + + 10 16 22 28 34 + 6 11 17 23 29 35 + 7 12 18 24 30 36 + 8 13 19 25 31 37 + 9 14 20 26 32 38 + 15 21 27 33 39 + 2 1 0 + 5 4 3 +*/ + + underglow_indicators: underglow-indicators { + compatible = "zmk,underglow-indicators"; + // Default: no indicators. Only `bat-self` is supported at the moment. + }; }; &spi3 { diff --git a/app/dts/bindings/zmk,underglow-indicators.yaml b/app/dts/bindings/zmk,underglow-indicators.yaml index d5cdde80a9a..42cb8368273 100644 --- a/app/dts/bindings/zmk,underglow-indicators.yaml +++ b/app/dts/bindings/zmk,underglow-indicators.yaml @@ -6,30 +6,30 @@ description: Underglow indicators compatible: "zmk,underglow-indicators" properties: - bat-lhs: + bat-self: type: array - required: true - bat-rhs: + default: [] + bat-other: type: array - required: true + default: [] capslock: type: int - required: true + default: -1 numlock: type: int - required: true + default: -1 scrolllock: type: int - required: true + default: -1 layer-state: type: array - required: true + default: [] ble-state: type: array - required: true + default: [] usb-state: type: int - required: true + default: -1 output-fallback: type: int - required: true + default: -1 diff --git a/app/src/rgb_underglow.c b/app/src/rgb_underglow.c index 5bc6a8277da..ce77c992549 100644 --- a/app/src/rgb_underglow.c +++ b/app/src/rgb_underglow.c @@ -273,8 +273,8 @@ static int zmk_led_generate_status(void) { return 0; } const uint8_t underglow_layer_state[] = DT_PROP(UNDERGLOW_INDICATORS, layer_state); const uint8_t underglow_ble_state[] = DT_PROP(UNDERGLOW_INDICATORS, ble_state); -const uint8_t underglow_bat_lhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_lhs); -const uint8_t underglow_bat_rhs[] = DT_PROP(UNDERGLOW_INDICATORS, bat_rhs); +const uint8_t underglow_bat_self[] = DT_PROP(UNDERGLOW_INDICATORS, bat_self); +const uint8_t underglow_bat_other[] = DT_PROP(UNDERGLOW_INDICATORS, bat_other); #define HEXRGB(R, G, B) \ ((struct led_rgb){ \ @@ -327,31 +327,32 @@ static int zmk_led_generate_status(void) { } // BATTERY STATUS - zmk_led_battery_level(zmk_battery_state_of_charge(), underglow_bat_lhs, - DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_lhs)); + zmk_led_battery_level(zmk_battery_state_of_charge(), underglow_bat_self, + DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_self)); #if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_CENTRAL_BATTERY_LEVEL_FETCHING) uint8_t peripheral_level = 0; int rc = zmk_split_get_peripheral_battery_level(0, &peripheral_level); if (rc == 0) { - zmk_led_battery_level(peripheral_level, underglow_bat_rhs, - DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs)); + zmk_led_battery_level(peripheral_level, underglow_bat_other, + DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_other)); } else if (rc == -ENOTCONN) { - zmk_led_fill(red, underglow_bat_rhs, DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_rhs)); + zmk_led_fill(red, underglow_bat_other, DT_PROP_LEN(UNDERGLOW_INDICATORS, bat_other)); } else if (rc == -EINVAL) { LOG_ERR("Invalid peripheral index requested for battery level read: 0"); } #endif +#if !IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_ROLE_CENTRAL) // CAPSLOCK/NUMLOCK/SCROLLOCK STATUS zmk_hid_indicators_t led_flags = zmk_hid_indicators_get_current_profile(); - if (led_flags & ZMK_LED_CAPSLOCK_BIT) + if (led_flags & ZMK_LED_CAPSLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, capslock) != -1) status_pixels[DT_PROP(UNDERGLOW_INDICATORS, capslock)] = red; - if (led_flags & ZMK_LED_NUMLOCK_BIT) + if (led_flags & ZMK_LED_NUMLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, numlock) != -1) status_pixels[DT_PROP(UNDERGLOW_INDICATORS, numlock)] = red; - if (led_flags & ZMK_LED_SCROLLLOCK_BIT) + if (led_flags & ZMK_LED_SCROLLLOCK_BIT && DT_PROP(UNDERGLOW_INDICATORS, scrolllock) != -1) status_pixels[DT_PROP(UNDERGLOW_INDICATORS, scrolllock)] = red; // LAYER STATUS @@ -362,7 +363,7 @@ static int zmk_led_generate_status(void) { struct zmk_endpoint_instance active_endpoint = zmk_endpoints_selected(); - if (!zmk_endpoints_preferred_transport_is_active()) + if (DT_PROP(UNDERGLOW_INDICATORS, output_fallback) != -1 && !zmk_endpoints_preferred_transport_is_active()) status_pixels[DT_PROP(UNDERGLOW_INDICATORS, output_fallback)] = red; int active_ble_profile_index = zmk_ble_active_profile_index(); @@ -382,17 +383,20 @@ static int zmk_led_generate_status(void) { } } - enum zmk_usb_conn_state usb_state = zmk_usb_get_conn_state(); - if (usb_state == ZMK_USB_CONN_HID && - active_endpoint.transport == ZMK_TRANSPORT_USB) { // connected AND active - status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = white; - } else if (usb_state == ZMK_USB_CONN_HID) { // connected - status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = dull_green; - } else if (usb_state == ZMK_USB_CONN_POWERED) { // powered - status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = red; - } else if (usb_state == ZMK_USB_CONN_NONE) { // disconnected - status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = lilac; + if (DT_PROP(UNDERGLOW_INDICATORS, usb_state) != -1) { + enum zmk_usb_conn_state usb_state = zmk_usb_get_conn_state(); + if (usb_state == ZMK_USB_CONN_HID && + active_endpoint.transport == ZMK_TRANSPORT_USB) { // connected AND active + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = white; + } else if (usb_state == ZMK_USB_CONN_HID) { // connected + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = dull_green; + } else if (usb_state == ZMK_USB_CONN_POWERED) { // powered + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = red; + } else if (usb_state == ZMK_USB_CONN_NONE) { // disconnected + status_pixels[DT_PROP(UNDERGLOW_INDICATORS, usb_state)] = lilac; + } } +#endif int16_t blend = 256; if (state.status_animation_step < (500 / 25)) {