aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/feature_rgblight.md68
-rw-r--r--quantum/rgblight.c36
-rw-r--r--quantum/rgblight.h6
3 files changed, 79 insertions, 31 deletions
diff --git a/docs/feature_rgblight.md b/docs/feature_rgblight.md
index 52d5c5fe8..23b6f1c94 100644
--- a/docs/feature_rgblight.md
+++ b/docs/feature_rgblight.md
@@ -148,37 +148,43 @@ const uint16_t RGBLED_GRADIENT_RANGES[] PROGMEM = {360, 240, 180, 120, 90};
148 148
149If you need to change your RGB lighting in code, for example in a macro to change the color whenever you switch layers, QMK provides a set of functions to assist you. See [`rgblight.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight.h) for the full list, but the most commonly used functions include: 149If you need to change your RGB lighting in code, for example in a macro to change the color whenever you switch layers, QMK provides a set of functions to assist you. See [`rgblight.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight.h) for the full list, but the most commonly used functions include:
150 150
151|Function |Description | 151|Function |Description |
152|-----------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------| 152|--------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
153|`rgblight_enable()` |Turn LEDs on, based on their previous state | 153|`rgblight_enable()` |Turn LEDs on, based on their previous state |
154|`rgblight_enable_noeeprom()` |Turn LEDs on, based on their previous state (not written to EEPROM) | 154|`rgblight_enable_noeeprom()` |Turn LEDs on, based on their previous state (not written to EEPROM) |
155|`rgblight_disable()` |Turn LEDs off | 155|`rgblight_disable()` |Turn LEDs off |
156|`rgblight_disable_noeeprom()` |Turn LEDs off (not written to EEPROM) | 156|`rgblight_disable_noeeprom()` |Turn LEDs off (not written to EEPROM) |
157|`rgblight_mode(x)` |Set the mode, if RGB animations are enabled | 157|`rgblight_mode(x)` |Set the mode, if RGB animations are enabled |
158|`rgblight_mode_noeeprom(x)` |Set the mode, if RGB animations are enabled (not written to EEPROM) | 158|`rgblight_mode_noeeprom(x)` |Set the mode, if RGB animations are enabled (not written to EEPROM) |
159|`rgblight_setrgb(r, g, b)` |Set all LEDs to the given RGB value where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) | 159|`rgblight_setrgb(r, g, b)` |Set all LEDs to the given RGB value where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) |
160|`rgblight_setrgb_at(r, g, b, led)` |Set a single LED to the given RGB value, where `r`/`g`/`b` are between 0 and 255 and `led` is between 0 and `RGBLED_NUM` (not written to EEPROM) | 160|`rgblight_setrgb_at(r, g, b, led)` |Set a single LED to the given RGB value, where `r`/`g`/`b` are between 0 and 255 and `led` is between 0 and `RGBLED_NUM` (not written to EEPROM) |
161|`rgblight_sethsv(h, s, v)` |Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 | 161|`rgblight_setrgb_range(r, g, b, start, end)`|Set a continuous range of LEDs to the given RGB value, where `r`/`g`/`b` are between 0 and 255 and `start`(included) and `stop`(excluded) are between 0 and `RGBLED_NUM` (not written to EEPROM)|
162|`rgblight_sethsv_noeeprom(h, s, v)`|Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 (not written to EEPROM) | 162|`rgblight_setrgb_master(r, g, b)` |Set the LEDs on the master side to the given RGB value, where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) |
163|`rgblight_sethsv_at(h, s, v, led)` |Set a single LED to the given HSV value, where `h` is between 0 and 360, `s`/`v` are between 0 and 255, and `led` is between 0 and `RGBLED_NUM` (not written to EEPROM)| 163|`rgblight_setrgb_slave(r, g, b)` |Set the LEDs on the slave side to the given RGB value, where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) |
164|`rgblight_toggle()` |Toggle all LEDs between on and off | 164|`rgblight_sethsv(h, s, v)` |Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 |
165|`rgblight_toggle_noeeprom()` |Toggle all LEDs between on and off (not written to EEPROM) | 165|`rgblight_sethsv_noeeprom(h, s, v)` |Set all LEDs to the given HSV value where `h` is between 0 and 360 and `s`/`v` are between 0 and 255 (not written to EEPROM) |
166|`rgblight_step()` |Change the mode to the next RGB animation in the list of enabled RGB animations | 166|`rgblight_sethsv_at(h, s, v, led)` |Set a single LED to the given HSV value, where `h` is between 0 and 360, `s`/`v` are between 0 and 255, and `led` is between 0 and `RGBLED_NUM` (not written to EEPROM)|
167|`rgblight_step_noeeprom()` |Change the mode to the next RGB animation in the list of enabled RGB animations (not written to EEPROM) | 167|`rgblight_sethsv_range(h, s, v, start, end)`|Set a continuous range of LEDs to the given HSV value, where `h` is between 0 and 360, `s`/`v` are between 0 and 255, and `start`(included) and `stop`(excluded) are between 0 and `RGBLED_NUM` (not written to EEPROM)|
168|`rgblight_step_reverse()` |Change the mode to the previous RGB animation in the list of enabled RGB animations | 168|`rgblight_sethsv_master(h, s, v)` |Set the LEDs on the master side to the given HSV value, where `h` is between 0 and 360, `s`/`v` are between 0 and 255 (not written to EEPROM) |
169|`rgblight_step_reverse_noeeprom()` |Change the mode to the previous RGB animation in the list of enabled RGB animations (not written to EEPROM) | 169|`rgblight_sethsv_slave(h, s, v)` |Set the LEDs on the slave side to the given HSV value, where `h` is between 0 and 360, `s`/`v` are between 0 and 255 (not written to EEPROM) |
170|`rgblight_increase_hue()` |Increase the hue for all LEDs. This wraps around at maximum hue | 170|`rgblight_toggle()` |Toggle all LEDs between on and off |
171|`rgblight_increase_hue_noeeprom()` |Increase the hue for all LEDs. This wraps around at maximum hue (not written to EEPROM) | 171|`rgblight_toggle_noeeprom()` |Toggle all LEDs between on and off (not written to EEPROM) |
172|`rgblight_decrease_hue()` |Decrease the hue for all LEDs. This wraps around at minimum hue | 172|`rgblight_step()` |Change the mode to the next RGB animation in the list of enabled RGB animations |
173|`rgblight_decrease_hue_noeeprom()` |Decrease the hue for all LEDs. This wraps around at minimum hue (not written to EEPROM) | 173|`rgblight_step_noeeprom()` |Change the mode to the next RGB animation in the list of enabled RGB animations (not written to EEPROM) |
174|`rgblight_increase_sat()` |Increase the saturation for all LEDs. This wraps around at maximum saturation | 174|`rgblight_step_reverse()` |Change the mode to the previous RGB animation in the list of enabled RGB animations |
175|`rgblight_increase_sat_noeeprom()` |Increase the saturation for all LEDs. This wraps around at maximum saturation (not written to EEPROM) | 175|`rgblight_step_reverse_noeeprom()` |Change the mode to the previous RGB animation in the list of enabled RGB animations (not written to EEPROM) |
176|`rgblight_decrease_sat()` |Decrease the saturation for all LEDs. This wraps around at minimum saturation | 176|`rgblight_increase_hue()` |Increase the hue for all LEDs. This wraps around at maximum hue |
177|`rgblight_decrease_sat_noeeprom()` |Decrease the saturation for all LEDs. This wraps around at minimum saturation (not written to EEPROM) | 177|`rgblight_increase_hue_noeeprom()` |Increase the hue for all LEDs. This wraps around at maximum hue (not written to EEPROM) |
178|`rgblight_increase_val()` |Increase the value for all LEDs. This wraps around at maximum value | 178|`rgblight_decrease_hue()` |Decrease the hue for all LEDs. This wraps around at minimum hue |
179|`rgblight_increase_val_noeeprom()` |Increase the value for all LEDs. This wraps around at maximum value (not written to EEPROM) | 179|`rgblight_decrease_hue_noeeprom()` |Decrease the hue for all LEDs. This wraps around at minimum hue (not written to EEPROM) |
180|`rgblight_decrease_val()` |Decrease the value for all LEDs. This wraps around at minimum value | 180|`rgblight_increase_sat()` |Increase the saturation for all LEDs. This wraps around at maximum saturation |
181|`rgblight_decrease_val_noeeprom()` |Decrease the value for all LEDs. This wraps around at minimum value (not written to EEPROM) | 181|`rgblight_increase_sat_noeeprom()` |Increase the saturation for all LEDs. This wraps around at maximum saturation (not written to EEPROM) |
182|`rgblight_decrease_sat()` |Decrease the saturation for all LEDs. This wraps around at minimum saturation |
183|`rgblight_decrease_sat_noeeprom()` |Decrease the saturation for all LEDs. This wraps around at minimum saturation (not written to EEPROM) |
184|`rgblight_increase_val()` |Increase the value for all LEDs. This wraps around at maximum value |
185|`rgblight_increase_val_noeeprom()` |Increase the value for all LEDs. This wraps around at maximum value (not written to EEPROM) |
186|`rgblight_decrease_val()` |Decrease the value for all LEDs. This wraps around at minimum value |
187|`rgblight_decrease_val_noeeprom()` |Decrease the value for all LEDs. This wraps around at minimum value (not written to EEPROM) |
182 188
183Additionally, [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight_list.h) defines several predefined shortcuts for various colors. Feel free to add to this list! 189Additionally, [`rgblight_list.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight_list.h) defines several predefined shortcuts for various colors. Feel free to add to this list!
184 190
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 30f7d7528..d42a1d2e5 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -611,6 +611,42 @@ void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index) {
611 rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); 611 rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
612} 612}
613 613
614void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) {
615 if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; }
616
617 for (uint8_t i = start; i < end; i++) {
618 led[i].r = r;
619 led[i].g = g;
620 led[i].b = b;
621 }
622 rgblight_set();
623 wait_ms(1);
624}
625
626void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
627 if (!rgblight_config.enable) { return; }
628
629 LED_TYPE tmp_led;
630 sethsv(hue, sat, val, &tmp_led);
631 rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end);
632}
633
634void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) {
635 rgblight_setrgb_range(r, g, b, 0 , (uint8_t) RGBLED_NUM/2);
636}
637
638void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) {
639 rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
640}
641
642void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val) {
643 rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2);
644}
645
646void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val) {
647 rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM);
648}
649
614#ifndef RGBLIGHT_CUSTOM_DRIVER 650#ifndef RGBLIGHT_CUSTOM_DRIVER
615void rgblight_set(void) { 651void rgblight_set(void) {
616 if (rgblight_config.enable) { 652 if (rgblight_config.enable) {
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index 03534bd31..aa608d424 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -187,6 +187,12 @@ uint8_t rgblight_get_val(void);
187void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b); 187void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b);
188void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index); 188void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index);
189void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index); 189void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index);
190void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end);
191void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end);
192void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b);
193void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b);
194void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val);
195void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val);
190 196
191uint32_t eeconfig_read_rgblight(void); 197uint32_t eeconfig_read_rgblight(void);
192void eeconfig_update_rgblight(uint32_t val); 198void eeconfig_update_rgblight(uint32_t val);