diff options
author | Erovia <Erovia@users.noreply.github.com> | 2019-02-15 15:52:04 +0100 |
---|---|---|
committer | MechMerlin <30334081+mechmerlin@users.noreply.github.com> | 2019-02-15 06:52:04 -0800 |
commit | 642f6cf14f2bcc91af61b0d64b4ad0632622dc7a (patch) | |
tree | 61722ebd3669dd26b8e87d72be7cc33b348e41ea /quantum | |
parent | f3bdd436a3e8e37e274fcd1147eb13e05b24fe98 (diff) | |
download | qmk_firmware-642f6cf14f2bcc91af61b0d64b4ad0632622dc7a.tar.gz qmk_firmware-642f6cf14f2bcc91af61b0d64b4ad0632622dc7a.zip |
Add support for using ranges for RGB (#4981)
* Add support for using ranges for RGB
This patch adds support for controlling continuous ranges of RGB LEDs.
Helper functions for split boards are also available.
* RGB Range: Use hardware-platform agnostic wait
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/rgblight.c | 36 | ||||
-rw-r--r-- | quantum/rgblight.h | 6 |
2 files changed, 42 insertions, 0 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index 30f7d75286..d42a1d2e59 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) { rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); } +void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end) { + if (!rgblight_config.enable || start < 0 || start >= end || end > RGBLED_NUM) { return; } + + for (uint8_t i = start; i < end; i++) { + led[i].r = r; + led[i].g = g; + led[i].b = b; + } + rgblight_set(); + wait_ms(1); +} + +void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) { + if (!rgblight_config.enable) { return; } + + LED_TYPE tmp_led; + sethsv(hue, sat, val, &tmp_led); + rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); +} + +void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b) { + rgblight_setrgb_range(r, g, b, 0 , (uint8_t) RGBLED_NUM/2); +} + +void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b) { + rgblight_setrgb_range(r, g, b, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); +} + +void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val) { + rgblight_sethsv_range(hue, sat, val, 0, (uint8_t) RGBLED_NUM/2); +} + +void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val) { + rgblight_sethsv_range(hue, sat, val, (uint8_t) RGBLED_NUM/2, (uint8_t) RGBLED_NUM); +} + #ifndef RGBLIGHT_CUSTOM_DRIVER void rgblight_set(void) { if (rgblight_config.enable) { diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 03534bd311..aa608d4240 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h @@ -187,6 +187,12 @@ uint8_t rgblight_get_val(void); void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b); void rgblight_setrgb_at(uint8_t r, uint8_t g, uint8_t b, uint8_t index); void rgblight_sethsv_at(uint16_t hue, uint8_t sat, uint8_t val, uint8_t index); +void rgblight_setrgb_range(uint8_t r, uint8_t g, uint8_t b, uint8_t start, uint8_t end); +void rgblight_sethsv_range(uint16_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end); +void rgblight_setrgb_master(uint8_t r, uint8_t g, uint8_t b); +void rgblight_setrgb_slave(uint8_t r, uint8_t g, uint8_t b); +void rgblight_sethsv_master(uint16_t hue, uint8_t sat, uint8_t val); +void rgblight_sethsv_slave(uint16_t hue, uint8_t sat, uint8_t val); uint32_t eeconfig_read_rgblight(void); void eeconfig_update_rgblight(uint32_t val); |