Browse Source

Allow expanding from 8 to 32 RGB Lighting Layers (#8941)

* Allow 16 lighting layers

* Require #define RGBLIGHT_LAYERS_16 to enable 16 layers

* Override RGBLIGHT_MAX_LAYERS to set maximum number of lighting layers

* Enforce lower bound on RGBLIGHT_MAX_LAYERS

Co-Authored-By: Takeshi ISHII <2170248+mtei@users.noreply.github.com>

* Fix an error in the check for valid RGBLIGHT_MAX_LAYERS

* Don't use bitfield / PACKED, as it causes bloat

* Update documentation re: up to 32 lighting layers

* Run cformat

* Add note about increasing FW size in docs/config_options.md

Co-authored-by: Drashna Jaelre <drashna@live.com>

* Remove no-longer-valid comment

* Add doc note that split sync will be slower

Co-authored-by: Takeshi ISHII <2170248+mtei@users.noreply.github.com>
Co-authored-by: Drashna Jaelre <drashna@live.com>
pull/9092/head 0.8.156
Joshua Diamond 4 years ago
committed by GitHub
parent
commit
a8a8bf0ff3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 4 deletions
  1. +3
    -0
      docs/config_options.md
  2. +2
    -0
      docs/feature_rgblight.md
  3. +2
    -2
      quantum/rgblight.c
  4. +15
    -2
      quantum/rgblight.h

+ 3
- 0
docs/config_options.md View File

@ -192,6 +192,9 @@ If you define these options you will enable the associated feature, which may in
* run RGB animations
* `#define RGBLIGHT_LAYERS`
* Lets you define [lighting layers](feature_rgblight.md?id=lighting-layers) that can be toggled on or off. Great for showing the current keyboard layer or caps lock state.
* `#define RGBLIGHT_MAX_LAYERS`
* Defaults to 8. Can be expanded up to 32 if more [lighting layers](feature_rgblight.md?id=lighting-layers) are needed.
* Note: Increasing the maximum will increase the firmware size and slow sync on split keyboards.
* `#define RGBLIGHT_LAYER_BLINK`
* Adds ability to [blink](feature_rgblight.md?id=lighting-layer-blink) a lighting layer for a specified number of milliseconds (e.g. to acknowledge an action).
* `#define RGBLED_NUM 12`


+ 2
- 0
docs/feature_rgblight.md View File

@ -186,6 +186,8 @@ it easy to use your underglow LEDs as status indicators to show which keyboard l
### Defining Lighting Layers :id=defining-lighting-layers
By default, 8 layers are possible. This can be expanded to as many as 32 by overriding the definition of `RGBLIGHT_MAX_LAYERS` in `config.h` (e.g. `#define RGBLIGHT_MAX_LAYERS 32`). Please note, if you use a split keyboard, you will need to flash both sides of the split after changing this. Also, increasing the maximum will increase the firmware size, and will slow sync on split keyboards.
To define a layer, we modify `keymap.c` to list out LED ranges and the colors we want to overlay on them using an array of `rgblight_segment_t` using the `RGBLIGHT_LAYER_SEGMENTS` macro. We can define multiple layers and enable/disable them independently:
```c


+ 2
- 2
quantum/rgblight.c View File

@ -613,7 +613,7 @@ void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_set
#ifdef RGBLIGHT_LAYERS
void rgblight_set_layer_state(uint8_t layer, bool enabled) {
uint8_t mask = 1 << layer;
rgblight_layer_mask_t mask = 1 << layer;
if (enabled) {
rgblight_status.enabled_layer_mask |= mask;
} else {
@ -627,7 +627,7 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) {
}
bool rgblight_get_layer_state(uint8_t layer) {
uint8_t mask = 1 << layer;
rgblight_layer_mask_t mask = 1 << layer;
return (rgblight_status.enabled_layer_mask & mask) != 0;
}


+ 15
- 2
quantum/rgblight.h View File

@ -196,7 +196,20 @@ typedef struct {
# define RGBLIGHT_END_SEGMENT_INDEX (255)
# define RGBLIGHT_END_SEGMENTS \
{ RGBLIGHT_END_SEGMENT_INDEX, 0, 0, 0 }
# define RGBLIGHT_MAX_LAYERS 8
# ifndef RGBLIGHT_MAX_LAYERS
# define RGBLIGHT_MAX_LAYERS 8
# endif
# if RGBLIGHT_MAX_LAYERS <= 0
# error invalid RGBLIGHT_MAX_LAYERS value (must be >= 1)
# elif RGBLIGHT_MAX_LAYERS <= 8
typedef uint8_t rgblight_layer_mask_t;
# elif RGBLIGHT_MAX_LAYERS <= 16
typedef uint16_t rgblight_layer_mask_t;
# elif RGBLIGHT_MAX_LAYERS <= 32
typedef uint32_t rgblight_layer_mask_t;
# else
# error invalid RGBLIGHT_MAX_LAYERS value (must be <= 32)
# endif
# define RGBLIGHT_LAYER_SEGMENTS(...) \
{ __VA_ARGS__, RGBLIGHT_END_SEGMENTS }
# define RGBLIGHT_LAYERS_LIST(...) \
@ -247,7 +260,7 @@ typedef struct _rgblight_status_t {
uint8_t change_flags;
# endif
# ifdef RGBLIGHT_LAYERS
uint8_t enabled_layer_mask;
rgblight_layer_mask_t enabled_layer_mask;
# endif
} rgblight_status_t;


Loading…
Cancel
Save