forked from mirrors/qmk_userspace
Clean up RGB LED type (#21859)
This commit is contained in:
parent
1e3095f9cc
commit
41bd4e35a0
63 changed files with 222 additions and 243 deletions
|
@ -115,7 +115,7 @@ animation_status_t animation_status = {};
|
|||
#endif
|
||||
|
||||
#ifndef LED_ARRAY
|
||||
LED_TYPE led[RGBLED_NUM];
|
||||
rgb_led_t led[RGBLED_NUM];
|
||||
# define LED_ARRAY led
|
||||
#endif
|
||||
|
||||
|
@ -144,17 +144,17 @@ __attribute__((weak)) RGB rgblight_hsv_to_rgb(HSV hsv) {
|
|||
return hsv_to_rgb(hsv);
|
||||
}
|
||||
|
||||
void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
|
||||
void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) {
|
||||
HSV hsv = {hue, sat, val};
|
||||
RGB rgb = rgblight_hsv_to_rgb(hsv);
|
||||
setrgb(rgb.r, rgb.g, rgb.b, led1);
|
||||
}
|
||||
|
||||
void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1) {
|
||||
void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1) {
|
||||
sethsv_raw(hue, sat, val > RGBLIGHT_LIMIT_VAL ? RGBLIGHT_LIMIT_VAL : val, led1);
|
||||
}
|
||||
|
||||
void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
|
||||
void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1) {
|
||||
led1->r = r;
|
||||
led1->g = g;
|
||||
led1->b = b;
|
||||
|
@ -516,7 +516,7 @@ void rgblight_decrease_speed_noeeprom(void) {
|
|||
|
||||
void rgblight_sethsv_noeeprom_old(uint8_t hue, uint8_t sat, uint8_t val) {
|
||||
if (rgblight_config.enable) {
|
||||
LED_TYPE tmp_led;
|
||||
rgb_led_t tmp_led;
|
||||
sethsv(hue, sat, val, &tmp_led);
|
||||
rgblight_setrgb(tmp_led.r, tmp_led.g, tmp_led.b);
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w
|
|||
rgblight_status.base_mode = mode_base_table[rgblight_config.mode];
|
||||
if (rgblight_config.mode == RGBLIGHT_MODE_STATIC_LIGHT) {
|
||||
// same static color
|
||||
LED_TYPE tmp_led;
|
||||
rgb_led_t tmp_led;
|
||||
#ifdef RGBLIGHT_LAYERS_RETAIN_VAL
|
||||
// needed for rgblight_layers_write() to get the new val, since it reads rgblight_config.val
|
||||
rgblight_config.val = val;
|
||||
|
@ -576,7 +576,7 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w
|
|||
_hue = hue - _hue;
|
||||
}
|
||||
dprintf("rgblight rainbow set hsv: %d,%d,%d,%u\n", i, _hue, direction, range);
|
||||
sethsv(_hue, sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]);
|
||||
sethsv(_hue, sat, val, (rgb_led_t *)&led[i + rgblight_ranges.effect_start_pos]);
|
||||
}
|
||||
# ifdef RGBLIGHT_LAYERS_RETAIN_VAL
|
||||
// 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) {
|
|||
return;
|
||||
}
|
||||
|
||||
LED_TYPE tmp_led;
|
||||
rgb_led_t tmp_led;
|
||||
sethsv(hue, sat, val, &tmp_led);
|
||||
rgblight_setrgb_at(tmp_led.r, tmp_led.g, tmp_led.b, index);
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ void rgblight_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start,
|
|||
return;
|
||||
}
|
||||
|
||||
LED_TYPE tmp_led;
|
||||
rgb_led_t tmp_led;
|
||||
sethsv(hue, sat, val, &tmp_led);
|
||||
rgblight_setrgb_range(tmp_led.r, tmp_led.g, tmp_led.b, start, end);
|
||||
}
|
||||
|
@ -786,8 +786,8 @@ static void rgblight_layers_write(void) {
|
|||
break; // No more segments
|
||||
}
|
||||
// Write segment.count LEDs
|
||||
LED_TYPE *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)];
|
||||
for (LED_TYPE *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) {
|
||||
rgb_led_t *const limit = &led[MIN(segment.index + segment.count, RGBLED_NUM)];
|
||||
for (rgb_led_t *led_ptr = &led[segment.index]; led_ptr < limit; led_ptr++) {
|
||||
# ifdef RGBLIGHT_LAYERS_RETAIN_VAL
|
||||
sethsv(segment.hue, segment.sat, current_val, led_ptr);
|
||||
# else
|
||||
|
@ -897,15 +897,15 @@ void rgblight_wakeup(void) {
|
|||
|
||||
#endif
|
||||
|
||||
__attribute__((weak)) void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) {
|
||||
__attribute__((weak)) void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) {
|
||||
ws2812_setleds(start_led, num_leds);
|
||||
}
|
||||
|
||||
#ifndef RGBLIGHT_CUSTOM_DRIVER
|
||||
|
||||
void rgblight_set(void) {
|
||||
LED_TYPE *start_led;
|
||||
uint8_t num_leds = rgblight_ranges.clipping_num_leds;
|
||||
rgb_led_t *start_led;
|
||||
uint8_t num_leds = rgblight_ranges.clipping_num_leds;
|
||||
|
||||
if (!rgblight_config.enable) {
|
||||
for (uint8_t i = rgblight_ranges.effect_start_pos; i < rgblight_ranges.effect_end_pos; i++) {
|
||||
|
@ -931,7 +931,7 @@ void rgblight_set(void) {
|
|||
# endif
|
||||
|
||||
# ifdef RGBLIGHT_LED_MAP
|
||||
LED_TYPE led0[RGBLED_NUM];
|
||||
rgb_led_t led0[RGBLED_NUM];
|
||||
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
|
||||
led0[i] = led[pgm_read_byte(&led_map[i])];
|
||||
}
|
||||
|
@ -1230,7 +1230,7 @@ void rgblight_effect_rainbow_swirl(animation_status_t *anim) {
|
|||
|
||||
for (i = 0; i < rgblight_ranges.effect_num_leds; i++) {
|
||||
hue = (RGBLIGHT_RAINBOW_SWIRL_RANGE / rgblight_ranges.effect_num_leds * i + anim->current_hue);
|
||||
sethsv(hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]);
|
||||
sethsv(hue, rgblight_config.sat, rgblight_config.val, (rgb_led_t *)&led[i + rgblight_ranges.effect_start_pos]);
|
||||
}
|
||||
rgblight_set();
|
||||
|
||||
|
@ -1267,10 +1267,10 @@ void rgblight_effect_snake(animation_status_t *anim) {
|
|||
# endif
|
||||
|
||||
for (i = 0; i < rgblight_ranges.effect_num_leds; i++) {
|
||||
LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos;
|
||||
ledp->r = 0;
|
||||
ledp->g = 0;
|
||||
ledp->b = 0;
|
||||
rgb_led_t *ledp = led + i + rgblight_ranges.effect_start_pos;
|
||||
ledp->r = 0;
|
||||
ledp->g = 0;
|
||||
ledp->b = 0;
|
||||
# ifdef RGBW
|
||||
ledp->w = 0;
|
||||
# endif
|
||||
|
@ -1340,7 +1340,7 @@ void rgblight_effect_knight(animation_status_t *anim) {
|
|||
cur = (i + RGBLIGHT_EFFECT_KNIGHT_OFFSET) % rgblight_ranges.effect_num_leds + rgblight_ranges.effect_start_pos;
|
||||
|
||||
if (i >= low_bound && i <= high_bound) {
|
||||
sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (LED_TYPE *)&led[cur]);
|
||||
sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, (rgb_led_t *)&led[cur]);
|
||||
} else {
|
||||
led[cur].r = 0;
|
||||
led[cur].g = 0;
|
||||
|
@ -1392,7 +1392,7 @@ void rgblight_effect_christmas(animation_status_t *anim) {
|
|||
|
||||
for (i = 0; i < rgblight_ranges.effect_num_leds; i++) {
|
||||
uint8_t local_hue = (i / RGBLIGHT_EFFECT_CHRISTMAS_STEP) % 2 ? hue : hue_green - hue;
|
||||
sethsv(local_hue, rgblight_config.sat, val, (LED_TYPE *)&led[i + rgblight_ranges.effect_start_pos]);
|
||||
sethsv(local_hue, rgblight_config.sat, val, (rgb_led_t *)&led[i + rgblight_ranges.effect_start_pos]);
|
||||
}
|
||||
rgblight_set();
|
||||
|
||||
|
@ -1415,7 +1415,7 @@ void rgblight_effect_rgbtest(animation_status_t *anim) {
|
|||
uint8_t b;
|
||||
|
||||
if (maxval == 0) {
|
||||
LED_TYPE tmp_led;
|
||||
rgb_led_t tmp_led;
|
||||
sethsv(0, 255, RGBLIGHT_LIMIT_VAL, &tmp_led);
|
||||
maxval = tmp_led.r;
|
||||
}
|
||||
|
@ -1439,7 +1439,7 @@ void rgblight_effect_rgbtest(animation_status_t *anim) {
|
|||
#ifdef RGBLIGHT_EFFECT_ALTERNATING
|
||||
void rgblight_effect_alternating(animation_status_t *anim) {
|
||||
for (int i = 0; i < rgblight_ranges.effect_num_leds; i++) {
|
||||
LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos;
|
||||
rgb_led_t *ledp = led + i + rgblight_ranges.effect_start_pos;
|
||||
if (i < rgblight_ranges.effect_num_leds / 2 && anim->pos) {
|
||||
sethsv(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, ledp);
|
||||
} else if (i >= rgblight_ranges.effect_num_leds / 2 && !anim->pos) {
|
||||
|
@ -1512,7 +1512,7 @@ void rgblight_effect_twinkle(animation_status_t *anim) {
|
|||
// This LED is off, and was NOT selected to start brightening
|
||||
}
|
||||
|
||||
LED_TYPE *ledp = led + i + rgblight_ranges.effect_start_pos;
|
||||
rgb_led_t *ledp = led + i + rgblight_ranges.effect_start_pos;
|
||||
sethsv(c->h, c->s, c->v, ledp);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue