diff options
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/color.c | 2 | ||||
-rw-r--r-- | quantum/color.h | 37 | ||||
-rw-r--r-- | quantum/rgb_matrix/rgb_matrix_drivers.c | 4 | ||||
-rw-r--r-- | quantum/rgblight/rgblight.c | 50 | ||||
-rw-r--r-- | quantum/rgblight/rgblight.h | 8 |
5 files changed, 40 insertions, 61 deletions
diff --git a/quantum/color.c b/quantum/color.c index 767155c9db..395383f428 100644 --- a/quantum/color.c +++ b/quantum/color.c @@ -110,7 +110,7 @@ RGB hsv_to_rgb_nocie(HSV hsv) { } #ifdef RGBW -void convert_rgb_to_rgbw(LED_TYPE *led) { +void convert_rgb_to_rgbw(rgb_led_t *led) { // Determine lowest value in all three colors, put that into // the white channel and then shift all colors by that amount led->w = MIN(led->r, MIN(led->g, led->b)); diff --git a/quantum/color.h b/quantum/color.h index 135ad623b5..a0414a291f 100644 --- a/quantum/color.h +++ b/quantum/color.h @@ -83,12 +83,6 @@ # pragma pack(push, 1) #endif -#ifdef RGBW -# define LED_TYPE cRGBW -#else -# define LED_TYPE RGB -#endif - #define WS2812_BYTE_ORDER_RGB 0 #define WS2812_BYTE_ORDER_GRB 1 #define WS2812_BYTE_ORDER_BGR 2 @@ -97,26 +91,7 @@ # define WS2812_BYTE_ORDER WS2812_BYTE_ORDER_GRB #endif -typedef struct PACKED { -#if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB) - uint8_t g; - uint8_t r; - uint8_t b; -#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_RGB) - uint8_t r; - uint8_t g; - uint8_t b; -#elif (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_BGR) - uint8_t b; - uint8_t g; - uint8_t r; -#endif -} cRGB; - -typedef cRGB RGB; - -// WS2812 specific layout -typedef struct PACKED { +typedef struct PACKED rgb_led_t { #if (WS2812_BYTE_ORDER == WS2812_BYTE_ORDER_GRB) uint8_t g; uint8_t r; @@ -130,10 +105,14 @@ typedef struct PACKED { uint8_t g; uint8_t r; #endif +#ifdef RGBW uint8_t w; -} cRGBW; +#endif +} rgb_led_t; + +typedef rgb_led_t RGB; -typedef struct PACKED { +typedef struct PACKED HSV { uint8_t h; uint8_t s; uint8_t v; @@ -146,5 +125,5 @@ typedef struct PACKED { RGB hsv_to_rgb(HSV hsv); RGB hsv_to_rgb_nocie(HSV hsv); #ifdef RGBW -void convert_rgb_to_rgbw(LED_TYPE *led); +void convert_rgb_to_rgbw(rgb_led_t *led); #endif diff --git a/quantum/rgb_matrix/rgb_matrix_drivers.c b/quantum/rgb_matrix/rgb_matrix_drivers.c index 695ecc78a4..cd0e80cc24 100644 --- a/quantum/rgb_matrix/rgb_matrix_drivers.c +++ b/quantum/rgb_matrix/rgb_matrix_drivers.c @@ -426,8 +426,8 @@ const rgb_matrix_driver_t rgb_matrix_driver = { # endif // LED color buffer -LED_TYPE rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT]; -bool ws2812_dirty = false; +rgb_led_t rgb_matrix_ws2812_array[RGB_MATRIX_LED_COUNT]; +bool ws2812_dirty = false; static void init(void) { ws2812_dirty = false; 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 = {}; #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); } 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); #endif -extern LED_TYPE led[RGBLED_NUM]; +extern rgb_led_t led[RGBLED_NUM]; extern const uint8_t RGBLED_BREATHING_INTERVALS[4] PROGMEM; extern const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[3] PROGMEM; @@ -283,9 +283,9 @@ typedef struct _rgblight_ranges_t { extern rgblight_ranges_t rgblight_ranges; /* === Utility Functions ===*/ -void sethsv(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); -void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1); // without RGBLIGHT_LIMIT_VAL check -void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1); +void sethsv(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1); +void sethsv_raw(uint8_t hue, uint8_t sat, uint8_t val, rgb_led_t *led1); // without RGBLIGHT_LIMIT_VAL check +void setrgb(uint8_t r, uint8_t g, uint8_t b, rgb_led_t *led1); /* === Low level Functions === */ void rgblight_set(void); |