splitkb.com

Controllering the on–board RGB LED

Use the Liatris' RGB LED to display your keyboard's status and other state changes.
Warning: This feature requires modifying your keymap's C code. It is not available in Via/Vial.
Warning: Due to current QMK software limitations, you cannot control both on-controller and on-keyboard RGB at the same time.

Do you like red, green, and blue? Fear not! The Liatris supports all three of them- and everything in between. All of that on the controller itself!

Setup

The onboard RGB LED is a WS2812B-2020 connected to pin 25. To let QMK control it, add the following to your rules.mk:

RGBLIGHT_ENABLE = yes # Enables QMK's RGB code  
WS2812_DRIVER = vendor # Use the RP2040's PIO interface

Additionally, add the following to your config.h:

#undef WS2812_DI_PIN  
#define WS2812_DI_PIN 25  
#undef RGBLED_NUM  
#define RGBLED_NUM 1

If you are using a split keyboard, add the following to config.h instead:

#undef WS2812_DI_PIN  
#define WS2812_DI_PIN 25  
#undef RGBLED_NUM  
#define RGBLED_NUM 2  
#undef RGBLED_SPLIT  
#define RGBLED_SPLIT {1, 1}

Usage

Initialization

Add the following code to your keymap.c to initialize the LED to to the proper state:

void keyboard_post_init_user(void) {  
    // Initialize RGB to static black  
    rgblight_enable_noeeprom();  
    rgblight_sethsv_noeeprom(HSV_BLACK);  
    rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);  
}

Setting the colour

To set the LED to a certain color, you can use the rgblight_setrgb_at(r, g, b, index) function.

For example, if you want to set the LED to red, add the following code to your keymap.c:

void housekeeping_task_user(void) {  
    rgblight_setrgb_at(255, 0, 0, 0);  
}

Instead of manually using an RGB triplet you can also use some shorthands. The following code does exactly the same:

void housekeeping_task_user(void) {  
    rgblight_setrgb_at(RGB_RED, 0);  
}

Set colour only one side

The index parameter determines which LED to set. For a unibody keyboard this will always be 0, but you can use different values for split keyboards. Use index 0 to set the LED on the left half and index 1 for the right half.

For example, the following code will set the left side to red and the right side to green:

void housekeeping_task_user(void) {  
    rgblight_setrgb_at(RGB_RED, 0);  
    rgblight_setrgb_at(RGB_GREEN, 1);  
}

One thing to keep in mind is that the RGB code is executed per side. This means that you might need extra data sync options to get access to the right variables on the secondary side.

Lock states

We can also use the RGB LED to show the value of the regular keyboard LEDs.

The following code will make the LED red if Caps Lock is enabled, green if Num Lock is enabled, and blue if Scroll Lock is enabled. If multiple lock states are enabled it'll display them both, so Caps+Num will show as red+green=yellow.

void housekeeping_task_user(void) {  
    led_t led_state = host_keyboard_led_state();  
    uint8_t red = led_state.caps_lock ? 255 : 0;  
    uint8_t green = led_state.num_lock ? 255 : 0;  
    uint8_t blue = led_state.scroll_lock ? 255 : 0;  
    rgblight_setrgb_at(red, green, blue, 0);  
}

We could also use a different approach. For example, we could use the left LED for Caps Lock and the right LED for Num Lock. To do this we need to sync the LED state between keyboard halves, so add the following to your config.h:

#define SPLIT_LED_STATE_ENABLE

As usual, add this to your keymap.c:

void housekeeping_task_user(void) {  
    led_t led_state = host_keyboard_led_state();  
  
    if (led_state.caps_lock) {  
        rgblight_setrgb_at(RGB_BLUE, 0);  
    } else {  
        rgblight_setrgb_at(RGB_BLACK, 0);  
    }  
  
    if (led_state.num_lock) {  
        rgblight_setrgb_at(RGB_BLUE, 1);  
    } else {  
        rgblight_setrgb_at(RGB_BLACK, 1);  
    }  
}

Set colour based on layer

We could also use the LED to indicate what layer we are currently in.

void housekeeping_task_user(void) {  
    switch (get_highest_layer(layer_state | default_layer_state)) {  
        case 0:  
            // Default layer  
            rgblight_setrgb_at(RGB_BLACK, 0);  
            break;  
        case 1:  
            rgblight_setrgb_at(RGB_RED, 0);  
            break;  
        case 2:  
            rgblight_setrgb_at(RGB_GREEN, 0);  
            break;  
        case 3:  
            rgblight_setrgb_at(RGB_BLUE, 0);  
            break;  
    }  
}

If you wish to do this on the secondary side, don't forget to change the index to 1 and add the following to your config.h:

#define SPLIT_LAYER_STATE_ENABLE

Questions? Help us improve!
Do you have questions after reading the documentation? Do you have feedback about this page, or about the documentation in general? Please send us an email. You can use the buttons below which will open your mail client or app with a template, or send your mail to support@splitkb.com.