aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Diamond <josh@windowoffire.com>2020-05-13 16:39:05 -0400
committerGitHub <noreply@github.com>2020-05-13 21:39:05 +0100
commita8a8bf0ff3d6e1c9637079b925b30cf7eb8913fd (patch)
tree3e7f1d53536711151fb7f8aebe63ab4d41f1d298
parentfadd3cb4617fe7e48c802c4470a50df36e6c5109 (diff)
downloadqmk_firmware-a8a8bf0ff3d6e1c9637079b925b30cf7eb8913fd.tar.gz
qmk_firmware-a8a8bf0ff3d6e1c9637079b925b30cf7eb8913fd.zip
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>
-rw-r--r--docs/config_options.md3
-rw-r--r--docs/feature_rgblight.md2
-rw-r--r--quantum/rgblight.c4
-rw-r--r--quantum/rgblight.h17
4 files changed, 22 insertions, 4 deletions
diff --git a/docs/config_options.md b/docs/config_options.md
index f76685702..b96079e60 100644
--- a/docs/config_options.md
+++ b/docs/config_options.md
@@ -192,6 +192,9 @@ If you define these options you will enable the associated feature, which may in
192 * run RGB animations 192 * run RGB animations
193* `#define RGBLIGHT_LAYERS` 193* `#define RGBLIGHT_LAYERS`
194 * 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. 194 * 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.
195* `#define RGBLIGHT_MAX_LAYERS`
196 * Defaults to 8. Can be expanded up to 32 if more [lighting layers](feature_rgblight.md?id=lighting-layers) are needed.
197 * Note: Increasing the maximum will increase the firmware size and slow sync on split keyboards.
195* `#define RGBLIGHT_LAYER_BLINK` 198* `#define RGBLIGHT_LAYER_BLINK`
196 * 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). 199 * 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).
197* `#define RGBLED_NUM 12` 200* `#define RGBLED_NUM 12`
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md
index 045d97775..7e54bfef3 100644
--- a/docs/feature_rgblight.md
+++ b/docs/feature_rgblight.md
@@ -186,6 +186,8 @@ it easy to use your underglow LEDs as status indicators to show which keyboard l
186 186
187### Defining Lighting Layers :id=defining-lighting-layers 187### Defining Lighting Layers :id=defining-lighting-layers
188 188
189By 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.
190
189To 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: 191To 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:
190 192
191```c 193```c
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 4f227794f..64123774c 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -613,7 +613,7 @@ void rgblight_sethsv_slave(uint8_t hue, uint8_t sat, uint8_t val) { rgblight_set
613 613
614#ifdef RGBLIGHT_LAYERS 614#ifdef RGBLIGHT_LAYERS
615void rgblight_set_layer_state(uint8_t layer, bool enabled) { 615void rgblight_set_layer_state(uint8_t layer, bool enabled) {
616 uint8_t mask = 1 << layer; 616 rgblight_layer_mask_t mask = 1 << layer;
617 if (enabled) { 617 if (enabled) {
618 rgblight_status.enabled_layer_mask |= mask; 618 rgblight_status.enabled_layer_mask |= mask;
619 } else { 619 } else {
@@ -627,7 +627,7 @@ void rgblight_set_layer_state(uint8_t layer, bool enabled) {
627} 627}
628 628
629bool rgblight_get_layer_state(uint8_t layer) { 629bool rgblight_get_layer_state(uint8_t layer) {
630 uint8_t mask = 1 << layer; 630 rgblight_layer_mask_t mask = 1 << layer;
631 return (rgblight_status.enabled_layer_mask & mask) != 0; 631 return (rgblight_status.enabled_layer_mask & mask) != 0;
632} 632}
633 633
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index f93a30c5a..6fc3b6f17 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -196,7 +196,20 @@ typedef struct {
196# define RGBLIGHT_END_SEGMENT_INDEX (255) 196# define RGBLIGHT_END_SEGMENT_INDEX (255)
197# define RGBLIGHT_END_SEGMENTS \ 197# define RGBLIGHT_END_SEGMENTS \
198 { RGBLIGHT_END_SEGMENT_INDEX, 0, 0, 0 } 198 { RGBLIGHT_END_SEGMENT_INDEX, 0, 0, 0 }
199# define RGBLIGHT_MAX_LAYERS 8 199# ifndef RGBLIGHT_MAX_LAYERS
200# define RGBLIGHT_MAX_LAYERS 8
201# endif
202# if RGBLIGHT_MAX_LAYERS <= 0
203# error invalid RGBLIGHT_MAX_LAYERS value (must be >= 1)
204# elif RGBLIGHT_MAX_LAYERS <= 8
205typedef uint8_t rgblight_layer_mask_t;
206# elif RGBLIGHT_MAX_LAYERS <= 16
207typedef uint16_t rgblight_layer_mask_t;
208# elif RGBLIGHT_MAX_LAYERS <= 32
209typedef uint32_t rgblight_layer_mask_t;
210# else
211# error invalid RGBLIGHT_MAX_LAYERS value (must be <= 32)
212# endif
200# define RGBLIGHT_LAYER_SEGMENTS(...) \ 213# define RGBLIGHT_LAYER_SEGMENTS(...) \
201 { __VA_ARGS__, RGBLIGHT_END_SEGMENTS } 214 { __VA_ARGS__, RGBLIGHT_END_SEGMENTS }
202# define RGBLIGHT_LAYERS_LIST(...) \ 215# define RGBLIGHT_LAYERS_LIST(...) \
@@ -247,7 +260,7 @@ typedef struct _rgblight_status_t {
247 uint8_t change_flags; 260 uint8_t change_flags;
248# endif 261# endif
249# ifdef RGBLIGHT_LAYERS 262# ifdef RGBLIGHT_LAYERS
250 uint8_t enabled_layer_mask; 263 rgblight_layer_mask_t enabled_layer_mask;
251# endif 264# endif
252} rgblight_status_t; 265} rgblight_status_t;
253 266