diff options
| author | Ryan <fauxpark@gmail.com> | 2023-09-04 10:19:59 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-04 01:19:59 +0100 |
| commit | 41bd4e35a09cc50f45112074d2b776254a3a17f8 (patch) | |
| tree | 9258c5ad40dda232e3b8271942b436bdafa6f115 /quantum/rgblight | |
| parent | 1e3095f9cce45fab0a566e692b1ff1c2047cfa08 (diff) | |
Clean up RGB LED type (#21859)
Diffstat (limited to 'quantum/rgblight')
| -rw-r--r-- | quantum/rgblight/rgblight.c | 50 | ||||
| -rw-r--r-- | quantum/rgblight/rgblight.h | 8 |
2 files changed, 29 insertions, 29 deletions
diff --git a/quantum/rgblight/rgblight.c b/quantum/rgblight/rgblight.c index 158112f31d..70672ceb8f 100644 --- a/quantum/rgblight/rgblight.c +++ b/quantum/rgblight/rgblight.c | |||
| @@ -115,7 +115,7 @@ animation_status_t animation_status = {}; | |||
| 115 | #endif | 115 | #endif |
| 116 | 116 | ||
| 117 | #ifndef LED_ARRAY | 117 | #ifndef LED_ARRAY |
| 118 | LED_TYPE led[RGBLED_NUM]; | 118 | rgb_led_t led[RGBLED_NUM]; |
| 119 | # define LED_ARRAY led | 119 | # define LED_ARRAY led |
| 120 | #endif | 120 | #endif |
| 121 | 121 | ||
| @@ -144,17 +144,17 @@ __attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) { | |||
| 144 | return hsv_to_rgb(hsv); | 144 | return hsv_to_rgb(hsv); |
| 145 | } | 145 | } |
| 146 | 146 | ||
| 147 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { | 147 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) { |
| 148 | HSV hsv = {hue, sat, val}; | 148 | HSV hsv = {hue, sat, val}; |
| 149 | RGB rgb = rgblight_hsv_to_rgb(hsv); | 149 | RGB rgb = rgblight_hsv_to_rgb(hsv); |
| 150 | setrgb(rgb.r, rgb.g, rgb.b, led1); | 150 | setrgb(rgb.r, rgb.g, rgb.b, led1); |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) { | 153 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) { |
| 154 | sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1); | 154 | sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1); |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) { | 157 | void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1) { |
| 158 | led1->r = r; | 158 | led1->r = r; |
| 159 | led1->g = g; | 159 | led1->g = g; |
| 160 | led1->b = b; | 160 | led1->b = b; |
| @@ -516,7 +516,7 @@ void rgblight_decrease_speed_noeeprom(void) { | |||
| 516 | 516 | ||
| 517 | void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { | 517 | void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) { |
| 518 | if (rgblight_config.enable) { | 518 | if (rgblight_config.enable) { |
| 519 | LED_TYPE tmp_led; | 519 | rgb_led_t tmp_led; |
| 520 | sethsv(hue, sat, val, &tmp_led); | 520 | sethsv(hue, sat, val, &tmp_led); |
| 521 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); | 521 | rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b); |
| 522 | } | 522 | } |
| @@ -532,7 +532,7 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w | |||
| 532 | rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; | 532 | rgblight_status.base_mode = mode_base_table[rgblight_config.mode]; |
| 533 | if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { | 533 | if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) { |
| 534 | // same static color | 534 | // same static color |
| 535 | LED_TYPE tmp_led; | 535 | rgb_led_t tmp_led; |
| 536 | #ifdef RGBLIGHT_LAYERS_RETAIN_VAL | 536 | #ifdef RGBLIGHT_LAYERS_RETAIN_VAL |
| 537 | // needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val | 537 | // needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val |
| 538 | rgblight_config.val = val; | 538 | rgblight_config.val = val; |
| @@ -576,7 +576,7 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w | |||
| 576 | _hue = hue - _hue; | 576 | _hue = hue - _hue; |
| 577 | } | 577 | } |
| 578 | dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); | 578 | dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range); |
| 579 | sethsv(_hue, sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); | 579 | sethsv(_hue, sat, val, (rgb_led_t *)&led[i + rgblight_ranges.effect_start_pos]); |
| 580 | } | 580 | } |
| 581 | # ifdef RGBLIGHT_LAYERS_RETAIN_VAL | 581 | # ifdef RGBLIGHT_LAYERS_RETAIN_VAL |
| 582 | // needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val | 582 | // needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val |
| @@ -679,7 +679,7 @@ void rgblight_sethsv_at(uint8_t hue, uint8_t sat, uint8_t val, uint8_t index) { | |||
| 679 | return; | 679 | return; |
| 680 | } | 680 | } |
| 681 | 681 | ||
| 682 | LED_TYPE tmp_led; | 682 | rgb_led_t tmp_led; |
| 683 | sethsv(hue, sat, val, &tmp_led); | 683 | sethsv(hue, sat, val, &tmp_led); |
| 684 | rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); | 684 | rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index); |
| 685 | } | 685 | } |
| @@ -717,7 +717,7 @@ void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, | |||
| 717 | return; | 717 | return; |
| 718 | } | 718 | } |
| 719 | 719 | ||
| 720 | LED_TYPE tmp_led; | 720 | rgb_led_t tmp_led; |
| 721 | sethsv(hue, sat, val, &tmp_led); | 721 | sethsv(hue, sat, val, &tmp_led); |
| 722 | rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); | 722 | rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end); |
| 723 | } | 723 | } |
| @@ -786,8 +786,8 @@ static void rgblight_layers_write(void) { | |||
| 786 | break; // No more segments | 786 | break; // No more segments |
| 787 | } | 787 | } |
| 788 | // Write segment.count LEDs | 788 | // Write segment.count LEDs |
| 789 | LED_TYPE *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; | 789 | rgb_led_t *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)]; |
| 790 | for (LED_TYPE *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) { | 790 | for (rgb_led_t *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) { |
| 791 | # ifdef RGBLIGHT_LAYERS_RETAIN_VAL | 791 | # ifdef RGBLIGHT_LAYERS_RETAIN_VAL |
| 792 | sethsv(segment.hue, segment.sat, current_val, led_ptr); | 792 | sethsv(segment.hue, segment.sat, current_val, led_ptr); |
| 793 | # else | 793 | # else |
| @@ -897,15 +897,15 @@ void rgblight_wakeup(void) { | |||
| 897 | 897 | ||
| 898 | #endif | 898 | #endif |
| 899 | 899 | ||
| 900 | __attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) { | 900 | __attribute__((weak)) void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) { |
| 901 | ws2812_setleds(start_led, num_leds); | 901 | ws2812_setleds(start_led, num_leds); |
| 902 | } | 902 | } |
| 903 | 903 | ||
| 904 | #ifndef RGBLIGHT_CUSTOM_DRIVER | 904 | #ifndef RGBLIGHT_CUSTOM_DRIVER |
| 905 | 905 | ||
| 906 | void rgblight_set(void) { | 906 | void rgblight_set(void) { |
| 907 | LED_TYPE *start_led; | 907 | rgb_led_t *start_led; |
| 908 | uint8_t num_leds = rgblight_ranges.clipping_num_leds; | 908 | uint8_t num_leds = rgblight_ranges.clipping_num_leds; |
| 909 | 909 | ||
| 910 | if (!rgblight_config.enable) { | 910 | if (!rgblight_config.enable) { |
| 911 | for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { | 911 | for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) { |
| @@ -931,7 +931,7 @@ void rgblight_set(void) { | |||
| 931 | # endif | 931 | # endif |
| 932 | 932 | ||
| 933 | # ifdef RGBLIGHT_LED_MAP | 933 | # ifdef RGBLIGHT_LED_MAP |
| 934 | LED_TYPE led0[RGBLED_NUM]; | 934 | rgb_led_t led0[RGBLED_NUM]; |
| 935 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { | 935 | for (uint8_t i = 0; i < RGBLED_NUM; i++) { |
| 936 | led0[i] = led[pgm_read_byte(&led_map[i])]; | 936 | led0[i] = led[pgm_read_byte(&led_map[i])]; |
| 937 | } | 937 | } |
| @@ -1230,7 +1230,7 @@ void rgblight_effect_rainbow_swirl(animation_status_t *anim) { | |||
| 1230 | 1230 | ||
| 1231 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { | 1231 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1232 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / rgblight_ranges.effect_num_leds * i + anim->current_hue); | 1232 | hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / rgblight_ranges.effect_num_leds * i + anim->current_hue); |
| 1233 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); | 1233 | sethsv(hue, rgblight_config.sat, rgblight_config.val, (rgb_led_t *)&led[i + rgblight_ranges.effect_start_pos]); |
| 1234 | } | 1234 | } |
| 1235 | rgblight_set(); | 1235 | rgblight_set(); |
| 1236 | 1236 | ||
| @@ -1267,10 +1267,10 @@ void rgblight_effect_snake(animation_status_t *anim) { | |||
| 1267 | # endif | 1267 | # endif |
| 1268 | 1268 | ||
| 1269 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { | 1269 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1270 | LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; | 1270 | rgb_led_t *ledp = led + i + rgblight_ranges.effect_start_pos; |
| 1271 | ledp->r = 0; | 1271 | ledp->r = 0; |
| 1272 | ledp->g = 0; | 1272 | ledp->g = 0; |
| 1273 | ledp->b = 0; | 1273 | ledp->b = 0; |
| 1274 | # ifdef RGBW | 1274 | # ifdef RGBW |
| 1275 | ledp->w = 0; | 1275 | ledp->w = 0; |
| 1276 | # endif | 1276 | # endif |
| @@ -1340,7 +1340,7 @@ void rgblight_effect_knight(animation_status_t *anim) { | |||
| 1340 | cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % rgblight_ranges.effect_num_leds + rgblight_ranges.effect_start_pos; | 1340 | cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % rgblight_ranges.effect_num_leds + rgblight_ranges.effect_start_pos; |
| 1341 | 1341 | ||
| 1342 | if (i >= low_bound && i <= high_bound) { | 1342 | if (i >= low_bound && i <= high_bound) { |
| 1343 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]); | 1343 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (rgb_led_t *)&led[cur]); |
| 1344 | } else { | 1344 | } else { |
| 1345 | led[cur].r = 0; | 1345 | led[cur].r = 0; |
| 1346 | led[cur].g = 0; | 1346 | led[cur].g = 0; |
| @@ -1392,7 +1392,7 @@ void rgblight_effect_christmas(animation_status_t *anim) { | |||
| 1392 | 1392 | ||
| 1393 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { | 1393 | for (i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1394 | uint8_t local_hue = (i / RGBLIGHT_EFFECT_CHRISTMAS_STEP) % 2 ? hue : hue_green - hue; | 1394 | uint8_t local_hue = (i / RGBLIGHT_EFFECT_CHRISTMAS_STEP) % 2 ? hue : hue_green - hue; |
| 1395 | sethsv(local_hue, rgblight_config.sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]); | 1395 | sethsv(local_hue, rgblight_config.sat, val, (rgb_led_t *)&led[i + rgblight_ranges.effect_start_pos]); |
| 1396 | } | 1396 | } |
| 1397 | rgblight_set(); | 1397 | rgblight_set(); |
| 1398 | 1398 | ||
| @@ -1415,7 +1415,7 @@ void rgblight_effect_rgbtest(animation_status_t *anim) { | |||
| 1415 | uint8_t b; | 1415 | uint8_t b; |
| 1416 | 1416 | ||
| 1417 | if (maxval == 0) { | 1417 | if (maxval == 0) { |
| 1418 | LED_TYPE tmp_led; | 1418 | rgb_led_t tmp_led; |
| 1419 | sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); | 1419 | sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led); |
| 1420 | maxval = tmp_led.r; | 1420 | maxval = tmp_led.r; |
| 1421 | } | 1421 | } |
| @@ -1439,7 +1439,7 @@ void rgblight_effect_rgbtest(animation_status_t *anim) { | |||
| 1439 | #ifdef RGBLIGHT_EFFECT_ALTERNATING | 1439 | #ifdef RGBLIGHT_EFFECT_ALTERNATING |
| 1440 | void rgblight_effect_alternating(animation_status_t *anim) { | 1440 | void rgblight_effect_alternating(animation_status_t *anim) { |
| 1441 | for (int i = 0; i < rgblight_ranges.effect_num_leds; i++) { | 1441 | for (int i = 0; i < rgblight_ranges.effect_num_leds; i++) { |
| 1442 | LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; | 1442 | rgb_led_t *ledp = led + i + rgblight_ranges.effect_start_pos; |
| 1443 | if (i < rgblight_ranges.effect_num_leds / 2 && anim->pos) { | 1443 | if (i < rgblight_ranges.effect_num_leds / 2 && anim->pos) { |
| 1444 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); | 1444 | sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp); |
| 1445 | } else if (i >= rgblight_ranges.effect_num_leds / 2 && !anim->pos) { | 1445 | } else if (i >= rgblight_ranges.effect_num_leds / 2 && !anim->pos) { |
| @@ -1512,7 +1512,7 @@ void rgblight_effect_twinkle(animation_status_t *anim) { | |||
| 1512 | // This LED is off, and was NOT selected to start brightening | 1512 | // This LED is off, and was NOT selected to start brightening |
| 1513 | } | 1513 | } |
| 1514 | 1514 | ||
| 1515 | LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos; | 1515 | rgb_led_t *ledp = led + i + rgblight_ranges.effect_start_pos; |
| 1516 | sethsv(c->h, c->s, c->v, ledp); | 1516 | sethsv(c->h, c->s, c->v, ledp); |
| 1517 | } | 1517 | } |
| 1518 | 1518 | ||
diff --git a/quantum/rgblight/rgblight.h b/quantum/rgblight/rgblight.h index 001058f962..450caf603e 100644 --- a/quantum/rgblight/rgblight.h +++ b/quantum/rgblight/rgblight.h | |||
| @@ -233,7 +233,7 @@ void rgblight_unblink_all_but_layer(uint8_t layer); | |||
| 233 | 233 | ||
| 234 | #endif | 234 | #endif |
| 235 | 235 | ||
| 236 | extern LED_TYPE led[RGBLED_NUM]; | 236 | extern rgb_led_t led[RGBLED_NUM]; |
| 237 | 237 | ||
| 238 | extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; | 238 | extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; |
| 239 | extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM; | 239 | extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM; |
| @@ -283,9 +283,9 @@ typedef struct _rgblight_ranges_t { | |||
| 283 | extern rgblight_ranges_t rgblight_ranges; | 283 | extern rgblight_ranges_t rgblight_ranges; |
| 284 | 284 | ||
| 285 | /* === Utility Functions ===*/ | 285 | /* === Utility Functions ===*/ |
| 286 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); | 286 | void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1); |
| 287 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check | 287 | void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1); // without RGBLIGHT_LIMIT_VAL check |
| 288 | void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); | 288 | void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1); |
| 289 | 289 | ||
| 290 | /* === Low level Functions === */ | 290 | /* === Low level Functions === */ |
| 291 | void rgblight_set(void); | 291 | void rgblight_set(void); |
