diff options
| author | Drashna Jaelre <drashna@live.com> | 2020-04-29 01:22:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-29 10:22:28 +0200 |
| commit | 86c4c4e91de20b3f928300cfab617963c31699f9 (patch) | |
| tree | 15580381612f1b30568ef98a941f3f7220215feb /quantum | |
| parent | 5f5c2a219c2ae87534d203ef12e61482cac47a70 (diff) | |
| download | qmk_firmware-86c4c4e91de20b3f928300cfab617963c31699f9.tar.gz qmk_firmware-86c4c4e91de20b3f928300cfab617963c31699f9.zip | |
Convert clipping variables in rgblight.c to a structure (#7720)
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/rgblight.c | 73 | ||||
| -rw-r--r-- | quantum/rgblight.h | 19 |
2 files changed, 52 insertions, 40 deletions
diff --git a/quantum/rgblight.c b/quantum/rgblight.c index cc35b01ed..ef46f231f 100644 --- a/quantum/rgblight.c +++ b/quantum/rgblight.c | |||
| @@ -107,23 +107,19 @@ LED_TYPE led[RGBLED_NUM]; | |||
| 107 | rgblight_segment_t const *const *rgblight_layers = NULL; | 107 | rgblight_segment_t const *const *rgblight_layers = NULL; |
| 108 | #endif | 108 | #endif |
| 109 | 109 | ||
| 110 | static uint8_t clipping_start_pos = 0; | 110 | rgblight_ranges_t rgblight_ranges = { 0, RGBLED_NUM, 0, RGBLED_NUM, RGBLED_NUM }; |
| 111 | static uint8_t clipping_num_leds = RGBLED_NUM; | ||
| 112 | static uint8_t effect_start_pos = 0; | ||
| 113 | static uint8_t effect_end_pos = RGBLED_NUM; | ||
| 114 | static uint8_t effect_num_leds = RGBLED_NUM; | ||
| 115 | 111 | ||
| 116 | void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { | 112 | void rgblight_set_clipping_range(uint8_t start_pos, uint8_t num_leds) { |
| 117 | clipping_start_pos = start_pos; | 113 | rgblight_ranges.clipping_start_pos = start_pos; |
| 118 | clipping_num_leds = num_leds; | 114 | rgblight_ranges.clipping_num_leds = num_leds; |
| 119 | } | 115 | } |
| 120 | 116 | ||
| 121 | void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { | 117 | void rgblight_set_effect_range(uint8_t start_pos, uint8_t num_leds) { |
| 122 | if (start_pos >= RGBLED_NUM) return; | 118 | if (start_pos >= RGBLED_NUM) return; |
| 123 | if (start_pos + num_leds > RGBLED_NUM) return; | 119 | if (start_pos + num_leds > RGBLED_NUM) return; |
| 124 | effect_start_pos = start_pos; | 120 | rgblight_ranges.effect_start_pos = start_pos; |
| 125 | effect_end_pos = start_pos + num_leds; | 121 | rgblight_ranges.effect_end_pos = start_pos + num_leds; |
| 126 | effect_num_leds = num_leds; | 122 | rgblight_ranges.effect_num_leds = num_leds; |
| 127 | } | 123 | } |
| 128 | 124 | ||
| 129 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { | 125 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { |
| @@ -468,15 +464,15 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w | |||
| 468 | # else | 464 | # else |
| 469 | uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; | 465 | uint8_t range = RGBLED_GRADIENT_RANGES[delta / 2]; |
| 470 | # endif | 466 | # endif |
| 471 | for (uint8_t i = 0; i < effect_num_leds; i++) { | 467 | for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 472 | uint8_t _hue = ((uint16_t)i * (uint16_t)range) / effect_num_leds; | 468 | uint8_t _hue = ((uint16_t)i * (uint16_t)range) / rgblight_ranges.effect_num_leds; |
| 473 | if (direction) { | 469 | if (direction) { |
| 474 | _hue = hue + _hue; | 470 | _hue = hue + _hue; |
| 475 | } else { | 471 | } else { |
| 476 | _hue = hue - _hue; | 472 | _hue = hue - _hue; |
| 477 | } | 473 | } |
| 478 | dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); | 474 | dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); |
| 479 | sethsv(_hue, sat, val, (LED_TYPE *)&led[i + effect_start_pos]); | 475 | sethsv(_hue, sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); |
| 480 | } | 476 | } |
| 481 | rgblight_set(); | 477 | rgblight_set(); |
| 482 | } | 478 | } |
| @@ -530,7 +526,7 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) { | |||
| 530 | return; | 526 | return; |
| 531 | } | 527 | } |
| 532 | 528 | ||
| 533 | for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { | 529 | for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { |
| 534 | led[i].r = r; | 530 | led[i].r = r; |
| 535 | led[i].g = g; | 531 | led[i].g = g; |
| 536 | led[i].b = b; | 532 | led[i].b = b; |
| @@ -664,10 +660,15 @@ static void rgblight_layers_write(void) { | |||
| 664 | } | 660 | } |
| 665 | #endif | 661 | #endif |
| 666 | 662 | ||
| 663 | __attribute__((weak)) | ||
| 664 | void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { | ||
| 665 | ws2812_setleds(start_led, num_leds); | ||
| 666 | } | ||
| 667 | |||
| 667 | #ifndef RGBLIGHT_CUSTOM_DRIVER | 668 | #ifndef RGBLIGHT_CUSTOM_DRIVER |
| 668 | void rgblight_set(void) { | 669 | void rgblight_set(void) { |
| 669 | LED_TYPE *start_led; | 670 | LED_TYPE *start_led; |
| 670 | uint16_t num_leds = clipping_num_leds; | 671 | uint8_t num_leds = rgblight_ranges.clipping_num_leds; |
| 671 | 672 | ||
| 672 | # ifdef RGBLIGHT_LAYERS | 673 | # ifdef RGBLIGHT_LAYERS |
| 673 | if (rgblight_layers != NULL) { | 674 | if (rgblight_layers != NULL) { |
| @@ -676,7 +677,7 @@ void rgblight_set(void) { | |||
| 676 | # endif | 677 | # endif |
| 677 | 678 | ||
| 678 | if (!rgblight_config.enable) { | 679 | if (!rgblight_config.enable) { |
| 679 | for (uint8_t i = effect_start_pos; i < effect_end_pos; i++) { | 680 | for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { |
| 680 | led[i].r = 0; | 681 | led[i].r = 0; |
| 681 | led[i].g = 0; | 682 | led[i].g = 0; |
| 682 | led[i].b = 0; | 683 | led[i].b = 0; |
| @@ -691,9 +692,9 @@ void rgblight_set(void) { | |||
| 691 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | 692 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| 692 | led0[i] = led[pgm_read_byte(&led_map[i])]; | 693 | led0[i] = led[pgm_read_byte(&led_map[i])]; |
| 693 | } | 694 | } |
| 694 | start_led = led0 + clipping_start_pos; | 695 | start_led = led0 + rgblight_ranges.clipping_start_pos; |
| 695 | # else | 696 | # else |
| 696 | start_led = led + clipping_start_pos; | 697 | start_led = led + rgblight_ranges.clipping_start_pos; |
| 697 | # endif | 698 | # endif |
| 698 | 699 | ||
| 699 | # ifdef RGBW | 700 | # ifdef RGBW |
| @@ -701,7 +702,7 @@ void rgblight_set(void) { | |||
| 701 | convert_rgb_to_rgbw(&start_led[i]); | 702 | convert_rgb_to_rgbw(&start_led[i]); |
| 702 | } | 703 | } |
| 703 | # endif | 704 | # endif |
| 704 | ws2812_setleds(start_led, num_leds); | 705 | rgblight_call_driver(start_led, num_leds); |
| 705 | } | 706 | } |
| 706 | #endif | 707 | #endif |
| 707 | 708 | ||
| @@ -961,9 +962,9 @@ void rgblight_effect_rainbow_swirl(animation_status_t *anim) { | |||
| 961 | uint8_t hue; | 962 | uint8_t hue; |
| 962 | uint8_t i; | 963 | uint8_t i; |
| 963 | 964 | ||
| 964 | for (i = 0; i < effect_num_leds; i++) { | 965 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 965 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / effect_num_leds * i + anim->current_hue); | 966 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / rgblight_ranges.effect_num_leds * i + anim->current_hue); |
| 966 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); | 967 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); |
| 967 | } | 968 | } |
| 968 | rgblight_set(); | 969 | rgblight_set(); |
| 969 | 970 | ||
| @@ -991,7 +992,7 @@ void rgblight_effect_snake(animation_status_t *anim) { | |||
| 991 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 992 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 992 | if (anim->pos == 0) { // restart signal | 993 | if (anim->pos == 0) { // restart signal |
| 993 | if (increment == 1) { | 994 | if (increment == 1) { |
| 994 | pos = effect_num_leds - 1; | 995 | pos = rgblight_ranges.effect_num_leds - 1; |
| 995 | } else { | 996 | } else { |
| 996 | pos = 0; | 997 | pos = 0; |
| 997 | } | 998 | } |
| @@ -999,8 +1000,8 @@ void rgblight_effect_snake(animation_status_t *anim) { | |||
| 999 | } | 1000 | } |
| 1000 | # endif | 1001 | # endif |
| 1001 | 1002 | ||
| 1002 | for (i = 0; i < effect_num_leds; i++) { | 1003 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1003 | LED_TYPE *ledp = led + i + effect_start_pos; | 1004 | LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; |
| 1004 | ledp->r = 0; | 1005 | ledp->r = 0; |
| 1005 | ledp->g = 0; | 1006 | ledp->g = 0; |
| 1006 | ledp->b = 0; | 1007 | ledp->b = 0; |
| @@ -1013,7 +1014,7 @@ void rgblight_effect_snake(animation_status_t *anim) { | |||
| 1013 | k = k % RGBLED_NUM; | 1014 | k = k % RGBLED_NUM; |
| 1014 | } | 1015 | } |
| 1015 | if (k < 0) { | 1016 | if (k < 0) { |
| 1016 | k = k + effect_num_leds; | 1017 | k = k + rgblight_ranges.effect_num_leds; |
| 1017 | } | 1018 | } |
| 1018 | if (i == k) { | 1019 | if (i == k) { |
| 1019 | sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val * (RGBLIGHT_EFFECT_SNAKE_LENGTH - j) / RGBLIGHT_EFFECT_SNAKE_LENGTH), ledp); | 1020 | sethsv(rgblight_config.hue, rgblight_config.sat, (uint8_t)(rgblight_config.val * (RGBLIGHT_EFFECT_SNAKE_LENGTH - j) / RGBLIGHT_EFFECT_SNAKE_LENGTH), ledp); |
| @@ -1023,7 +1024,7 @@ void rgblight_effect_snake(animation_status_t *anim) { | |||
| 1023 | rgblight_set(); | 1024 | rgblight_set(); |
| 1024 | if (increment == 1) { | 1025 | if (increment == 1) { |
| 1025 | if (pos - 1 < 0) { | 1026 | if (pos - 1 < 0) { |
| 1026 | pos = effect_num_leds - 1; | 1027 | pos = rgblight_ranges.effect_num_leds - 1; |
| 1027 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 1028 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 1028 | anim->pos = 0; | 1029 | anim->pos = 0; |
| 1029 | # endif | 1030 | # endif |
| @@ -1034,7 +1035,7 @@ void rgblight_effect_snake(animation_status_t *anim) { | |||
| 1034 | # endif | 1035 | # endif |
| 1035 | } | 1036 | } |
| 1036 | } else { | 1037 | } else { |
| 1037 | pos = (pos + 1) % effect_num_leds; | 1038 | pos = (pos + 1) % rgblight_ranges.effect_num_leds; |
| 1038 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) | 1039 | # if defined(RGBLIGHT_SPLIT) && !defined(RGBLIGHT_SPLIT_NO_ANIMATION_SYNC) |
| 1039 | anim->pos = pos; | 1040 | anim->pos = pos; |
| 1040 | # endif | 1041 | # endif |
| @@ -1060,7 +1061,7 @@ void rgblight_effect_knight(animation_status_t *anim) { | |||
| 1060 | } | 1061 | } |
| 1061 | # endif | 1062 | # endif |
| 1062 | // Set all the LEDs to 0 | 1063 | // Set all the LEDs to 0 |
| 1063 | for (i = effect_start_pos; i < effect_end_pos; i++) { | 1064 | for (i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { |
| 1064 | led[i].r = 0; | 1065 | led[i].r = 0; |
| 1065 | led[i].g = 0; | 1066 | led[i].g = 0; |
| 1066 | led[i].b = 0; | 1067 | led[i].b = 0; |
| @@ -1070,7 +1071,7 @@ void rgblight_effect_knight(animation_status_t *anim) { | |||
| 1070 | } | 1071 | } |
| 1071 | // Determine which LEDs should be lit up | 1072 | // Determine which LEDs should be lit up |
| 1072 | for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { | 1073 | for (i = 0; i < RGBLIGHT_EFFECT_KNIGHT_LED_NUM; i++) { |
| 1073 | cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % effect_num_leds + effect_start_pos; | 1074 | cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % rgblight_ranges.effect_num_leds + rgblight_ranges.effect_start_pos; |
| 1074 | 1075 | ||
| 1075 | if (i >= low_bound && i <= high_bound) { | 1076 | if (i >= low_bound && i <= high_bound) { |
| 1076 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); | 1077 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); |
| @@ -1107,9 +1108,9 @@ void rgblight_effect_christmas(animation_status_t *anim) { | |||
| 1107 | uint8_t i; | 1108 | uint8_t i; |
| 1108 | 1109 | ||
| 1109 | anim->current_offset = (anim->current_offset + 1) % 2; | 1110 | anim->current_offset = (anim->current_offset + 1) % 2; |
| 1110 | for (i = 0; i < effect_num_leds; i++) { | 1111 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1111 | hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; | 1112 | hue = 0 + ((i / RGBLIGHT_EFFECT_CHRISTMAS_STEP + anim->current_offset) % 2) * 85; |
| 1112 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + effect_start_pos]); | 1113 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); |
| 1113 | } | 1114 | } |
| 1114 | rgblight_set(); | 1115 | rgblight_set(); |
| 1115 | } | 1116 | } |
| @@ -1148,11 +1149,11 @@ void rgblight_effect_rgbtest(animation_status_t *anim) { | |||
| 1148 | 1149 | ||
| 1149 | #ifdef RGBLIGHT_EFFECT_ALTERNATING | 1150 | #ifdef RGBLIGHT_EFFECT_ALTERNATING |
| 1150 | void rgblight_effect_alternating(animation_status_t *anim) { | 1151 | void rgblight_effect_alternating(animation_status_t *anim) { |
| 1151 | for (int i = 0; i < effect_num_leds; i++) { | 1152 | for (int i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1152 | LED_TYPE *ledp = led + i + effect_start_pos; | 1153 | LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; |
| 1153 | if (i < effect_num_leds / 2 && anim->pos) { | 1154 | if (i < rgblight_ranges.effect_num_leds / 2 && anim->pos) { |
| 1154 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); | 1155 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); |
| 1155 | } else if (i >= effect_num_leds / 2 && !anim->pos) { | 1156 | } else if (i >= rgblight_ranges.effect_num_leds / 2 && !anim->pos) { |
| 1156 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); | 1157 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); |
| 1157 | } else { | 1158 | } else { |
| 1158 | sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); | 1159 | sethsv(rgblight_config.hue, rgblight_config.sat, 0, ledp); |
diff --git a/quantum/rgblight.h b/quantum/rgblight.h index 97882c5b2..b1585b158 100644 --- a/quantum/rgblight.h +++ b/quantum/rgblight.h | |||
| @@ -130,7 +130,7 @@ enum RGBLIGHT_EFFECT_MODE { | |||
| 130 | # endif | 130 | # endif |
| 131 | 131 | ||
| 132 | # ifndef RGBLIGHT_EFFECT_KNIGHT_LED_NUM | 132 | # ifndef RGBLIGHT_EFFECT_KNIGHT_LED_NUM |
| 133 | # define RGBLIGHT_EFFECT_KNIGHT_LED_NUM (effect_num_leds) | 133 | # define RGBLIGHT_EFFECT_KNIGHT_LED_NUM (rgblight_ranges.effect_num_leds) |
| 134 | # endif | 134 | # endif |
| 135 | 135 | ||
| 136 | # ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL | 136 | # ifndef RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL |
| @@ -160,9 +160,7 @@ enum RGBLIGHT_EFFECT_MODE { | |||
| 160 | # include <stdint.h> | 160 | # include <stdint.h> |
| 161 | # include <stdbool.h> | 161 | # include <stdbool.h> |
| 162 | # include "eeconfig.h" | 162 | # include "eeconfig.h" |
| 163 | # ifndef RGBLIGHT_CUSTOM_DRIVER | 163 | # include "ws2812.h" |
| 164 | # include "ws2812.h" | ||
| 165 | # endif | ||
| 166 | # include "color.h" | 164 | # include "color.h" |
| 167 | # include "rgblight_list.h" | 165 | # include "rgblight_list.h" |
| 168 | 166 | ||
| @@ -230,6 +228,19 @@ typedef struct _rgblight_status_t { | |||
| 230 | # endif | 228 | # endif |
| 231 | } rgblight_status_t; | 229 | } rgblight_status_t; |
| 232 | 230 | ||
| 231 | /* | ||
| 232 | * Structure for RGB Light clipping ranges | ||
| 233 | */ | ||
| 234 | typedef struct _rgblight_ranges_t { | ||
| 235 | uint8_t clipping_start_pos; | ||
| 236 | uint8_t clipping_num_leds; | ||
| 237 | uint8_t effect_start_pos; | ||
| 238 | uint8_t effect_end_pos; | ||
| 239 | uint8_t effect_num_leds; | ||
| 240 | } rgblight_ranges_t; | ||
| 241 | |||
| 242 | extern rgblight_ranges_t rgblight_ranges; | ||
| 243 | |||
| 233 | /* === Utility Functions ===*/ | 244 | /* === Utility Functions ===*/ |
| 234 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); | 245 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); |
| 235 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check | 246 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check |
