Clean up RGB LED type (#21859)

This commit is contained in:
Ryan 2023-09-04 10:19:59 +10:00 committed by GitHub
parent 1e3095f9cc
commit 41bd4e35a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
63 changed files with 222 additions and 243 deletions

View File

@ -370,9 +370,9 @@ If you need to change your RGB lighting in code, for example in a macro to chang
Example:
```c
sethsv(HSV_WHITE, (LED_TYPE *)&led[0]); // led 0
sethsv(HSV_RED, (LED_TYPE *)&led[1]); // led 1
sethsv(HSV_GREEN, (LED_TYPE *)&led[2]); // led 2
sethsv(HSV_WHITE, (rgb_led_t *)&led[0]); // led 0
sethsv(HSV_RED, (rgb_led_t *)&led[1]); // led 1
sethsv(HSV_GREEN, (rgb_led_t *)&led[2]); // led 2
rgblight_set(); // Utility functions do not call rgblight_set() automatically, so they need to be called explicitly.
```

View File

@ -61,18 +61,18 @@ void static apa102_end_frame(uint16_t num_leds);
void static apa102_send_frame(uint8_t red, uint8_t green, uint8_t blue, uint8_t brightness);
void static apa102_send_byte(uint8_t byte);
void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds) {
LED_TYPE *end = start_led + num_leds;
void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds) {
rgb_led_t *end = start_led + num_leds;
apa102_start_frame();
for (LED_TYPE *led = start_led; led < end; led++) {
for (rgb_led_t *led = start_led; led < end; led++) {
apa102_send_frame(led->r, led->g, led->b, apa102_led_brightness);
}
apa102_end_frame(num_leds);
}
// Overwrite the default rgblight_call_driver to use apa102 driver
void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds) {
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds) {
apa102_setleds(start_led, num_leds);
}

View File

@ -37,5 +37,5 @@ extern uint8_t apa102_led_brightness;
* - Set the data-out pin as output
* - Send out the LED data
*/
void apa102_setleds(LED_TYPE *start_led, uint16_t num_leds);
void apa102_setleds(rgb_led_t *start_led, uint16_t num_leds);
void apa102_set_brightness(uint8_t brightness);

View File

@ -73,4 +73,4 @@
* - Send out the LED data
* - Wait 50us to reset the LEDs
*/
void ws2812_setleds(LED_TYPE *ledarray, uint16_t number_of_leds);
void ws2812_setleds(rgb_led_t *ledarray, uint16_t number_of_leds);

View File

@ -7,7 +7,7 @@
#include "color.h"
static inline void rgblite_setrgb(RGB rgb) {
LED_TYPE leds[RGBLED_NUM] = {{.r = rgb.r, .g = rgb.g, .b = rgb.b}};
rgb_led_t leds[RGBLED_NUM] = {{.r = rgb.r, .g = rgb.g, .b = rgb.b}};
ws2812_setleds(leds, RGBLED_NUM);
}

View File

@ -7,7 +7,7 @@
#include "color.h"
static inline void rgblite_setrgb(RGB rgb) {
LED_TYPE leds[RGBLED_NUM] = {{.r = rgb.r, .g = rgb.g, .b = rgb.b}};
rgb_led_t leds[RGBLED_NUM] = {{.r = rgb.r, .g = rgb.g, .b = rgb.b}};
ws2812_setleds(leds, RGBLED_NUM);
}

View File

@ -85,7 +85,7 @@ uint8_t remap[16] = {
void refresh_leds(void) {
for (uint8_t index = 0; index < 16; ++index) {
uint8_t tile = tiles[index];
setrgb(r[tile], g[tile], b[tile], (LED_TYPE *)&led[remap[index]]);
setrgb(r[tile], g[tile], b[tile], (rgb_led_t *)&led[remap[index]]);
}
rgblight_set();
}

View File

@ -341,10 +341,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
//キー毎に時間差で色が変化していく
if (aqours_next_color_timer_count % NEXT_CHANGE_TARGET_TIME == 0) {
if (target_col < MATRIX_COLS) {
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (LED_TYPE *)&led[target_col]);
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (LED_TYPE *)&led[11 - target_col]);
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (LED_TYPE *)&led[12 + target_col]);
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (LED_TYPE *)&led[23 - target_col]);
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (rgb_led_t *)&led[target_col]);
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (rgb_led_t *)&led[11 - target_col]);
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (rgb_led_t *)&led[12 + target_col]);
sethsv(aqours_h[aqours_num], aqours_s[aqours_num], aqours_v[aqours_num], (rgb_led_t *)&led[23 - target_col]);
target_col++;
rgblight_set();
}

View File

@ -172,7 +172,7 @@ void clueboard_set_midi_led(uint8_t base_oct, uint8_t val)
uint8_t sat = 255;
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
sethsv(oct_hues[base_oct], sat, val, (LED_TYPE *)&led[i]);
sethsv(oct_hues[base_oct], sat, val, (rgb_led_t *)&led[i]);
}
uint8_t next_oct = base_oct < MAX_OCT ? base_oct + 1 : base_oct;
@ -183,11 +183,11 @@ void clueboard_set_midi_led(uint8_t base_oct, uint8_t val)
for (uint8_t i = 0; i < 3; i++) {
sethsv(next_hue, next_sat, next_val, (LED_TYPE *)&led[i]);
sethsv(next_hue, next_sat, next_val, (rgb_led_t *)&led[i]);
}
for (uint8_t i = 11; i < 14; i++) {
sethsv(next_hue, next_sat, next_val, (LED_TYPE *)&led[i]);
sethsv(next_hue, next_sat, next_val, (rgb_led_t *)&led[i]);
}
rgblight_set();

View File

@ -70,9 +70,9 @@ void keyboard_post_init_user(void) {
extern rgblight_config_t rgblight_config;
extern void rgblight_layers_write(void);
extern void indicator_write(LED_TYPE *start_led, uint8_t num_leds);
extern void indicator_write(rgb_led_t *start_led, uint8_t num_leds);
void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds)
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
{
ws2812_setleds(start_led, RGBLED_NUM-RGB_INDICATOR_NUM);

View File

@ -20,7 +20,7 @@
#define ws2812_setleds_pin indicator_setleds_pin
#include "ws2812_bitbang.c"
void indicator_write(LED_TYPE *start_led, uint8_t num_leds)
void indicator_write(rgb_led_t *start_led, uint8_t num_leds)
{
indicator_setleds(start_led, num_leds);
}

View File

@ -22,7 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# include "ergodox_ez.h"
void rgblight_call_driver(LED_TYPE *led, uint8_t led_num) {
void rgblight_call_driver(rgb_led_t *led, uint8_t led_num) {
i2c_init();
i2c_start(0x84, ERGODOX_EZ_I2C_TIMEOUT);
int i = 0;

View File

@ -154,15 +154,15 @@ int aqours_color_v[] = {255, 255, 255, 255, 255, 255, 200, 255, 255};
void LED_default_set(void) {
sethsv(aqours_color_h[2], aqours_color_s[2], aqours_color_v[2], (LED_TYPE *)&led[0]);
sethsv(aqours_color_h[7], aqours_color_s[7], aqours_color_v[7], (LED_TYPE *)&led[1]);
sethsv(aqours_color_h[1], aqours_color_s[1], aqours_color_v[1], (LED_TYPE *)&led[2]);
sethsv(aqours_color_h[5], aqours_color_s[5], aqours_color_v[5], (LED_TYPE *)&led[3]);
sethsv(aqours_color_h[8], aqours_color_s[8], aqours_color_v[8], (LED_TYPE *)&led[4]);
sethsv(aqours_color_h[6], aqours_color_s[6], aqours_color_v[6], (LED_TYPE *)&led[5]);
sethsv(aqours_color_h[0], aqours_color_s[0], aqours_color_v[0], (LED_TYPE *)&led[6]);
sethsv(aqours_color_h[4], aqours_color_s[4], aqours_color_v[4], (LED_TYPE *)&led[7]);
sethsv(aqours_color_h[3], aqours_color_s[3], aqours_color_v[3], (LED_TYPE *)&led[8]);
sethsv(aqours_color_h[2], aqours_color_s[2], aqours_color_v[2], (rgb_led_t *)&led[0]);
sethsv(aqours_color_h[7], aqours_color_s[7], aqours_color_v[7], (rgb_led_t *)&led[1]);
sethsv(aqours_color_h[1], aqours_color_s[1], aqours_color_v[1], (rgb_led_t *)&led[2]);
sethsv(aqours_color_h[5], aqours_color_s[5], aqours_color_v[5], (rgb_led_t *)&led[3]);
sethsv(aqours_color_h[8], aqours_color_s[8], aqours_color_v[8], (rgb_led_t *)&led[4]);
sethsv(aqours_color_h[6], aqours_color_s[6], aqours_color_v[6], (rgb_led_t *)&led[5]);
sethsv(aqours_color_h[0], aqours_color_s[0], aqours_color_v[0], (rgb_led_t *)&led[6]);
sethsv(aqours_color_h[4], aqours_color_s[4], aqours_color_v[4], (rgb_led_t *)&led[7]);
sethsv(aqours_color_h[3], aqours_color_s[3], aqours_color_v[3], (rgb_led_t *)&led[8]);
rgblight_set();
@ -171,7 +171,7 @@ void LED_default_set(void) {
void LED_layer_set(int aqours_index) {
for (int c = 0; c < 9; c++) {
sethsv(aqours_color_h[aqours_index], aqours_color_s[aqours_index], aqours_color_v[aqours_index], (LED_TYPE *)&led[c]);
sethsv(aqours_color_h[aqours_index], aqours_color_s[aqours_index], aqours_color_v[aqours_index], (rgb_led_t *)&led[c]);
}
rgblight_set();
}

View File

@ -1,7 +1,7 @@
#include "ws2812.h"
#include "rgbsps.h"
cRGB led[RGBSPS_NUM];
rgb_led_t led[RGBSPS_NUM];
void rgbsps_set(uint8_t index, uint8_t r, uint8_t g, uint8_t b) {
led[index].r = r;

View File

@ -49,19 +49,19 @@ bool led_update_kb(led_t led_state) {
bool res = led_update_user(led_state);
if (res) {
if (led_state.caps_lock) {
sethsv_raw(HSV_CAPS, (LED_TYPE *)&led[0]);
sethsv_raw(HSV_CAPS, (rgb_led_t *)&led[0]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[0]);
sethsv(HSV_BLACK, (rgb_led_t *)&led[0]);
}
if (led_state.num_lock) {
sethsv_raw(HSV_NLCK, (LED_TYPE *)&led[1]);
sethsv_raw(HSV_NLCK, (rgb_led_t *)&led[1]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[1]);
sethsv(HSV_BLACK, (rgb_led_t *)&led[1]);
}
if (led_state.scroll_lock) {
sethsv_raw(HSV_SCRL, (LED_TYPE *)&led[2]);
sethsv_raw(HSV_SCRL, (rgb_led_t *)&led[2]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[2]);
sethsv(HSV_BLACK, (rgb_led_t *)&led[2]);
}
rgblight_set();
}
@ -83,7 +83,7 @@ void keyboard_post_init_user(void) {
__attribute__ ((weak))
void hbcp_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
LED_TYPE tmp_led;
rgb_led_t tmp_led;
sethsv_raw(hue, sat, val, &tmp_led);
for (uint8_t i = start; i < end; i++) {
led[i] = tmp_led;

View File

@ -79,19 +79,19 @@ void matrix_scan_user(void) {
// The first three LEDs are used as indicators for CAPS_LOCK, NUM_LOCK and SCROLL_LOCK.
bool led_update_user(led_t led_state) {
if (led_state.caps_lock) {
sethsv_raw(HSV_SOFT_RED, (LED_TYPE *)&led[0]);
sethsv_raw(HSV_SOFT_RED, (rgb_led_t *)&led[0]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[0]);
sethsv(HSV_BLACK, (rgb_led_t *)&led[0]);
}
if (led_state.num_lock) {
sethsv_raw(HSV_WARM_WHITE, (LED_TYPE *)&led[1]);
sethsv_raw(HSV_WARM_WHITE, (rgb_led_t *)&led[1]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[1]);
sethsv(HSV_BLACK, (rgb_led_t *)&led[1]);
}
if (led_state.scroll_lock) {
sethsv_raw(HSV_SOFT_BLUE, (LED_TYPE *)&led[2]);
sethsv_raw(HSV_SOFT_BLUE, (rgb_led_t *)&led[2]);
} else {
sethsv(HSV_BLACK, (LED_TYPE *)&led[2]);
sethsv(HSV_BLACK, (rgb_led_t *)&led[2]);
}
rgblight_set();
return false;

View File

@ -39,26 +39,26 @@ static uint8_t isRecording = 0;
# if RGBLED_NUM < 3
# error we need at least 3 RGB LEDs!
# endif
static cRGB led[RGBLED_NUM] = {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}};
static rgb_led_t led[RGBLED_NUM] = {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}};
# define BRIGHT 32
# define DIM 6
static const cRGB black = {.r = 0, .g = 0, .b = 0};
static const rgb_led_t black = {.r = 0, .g = 0, .b = 0};
static const __attribute__((unused)) cRGB green = {.r = 0, .g = BRIGHT, .b = 0};
static const __attribute__((unused)) cRGB lgreen = {.r = 0, .g = DIM, .b = 0};
static const __attribute__((unused)) rgb_led_t green = {.r = 0, .g = BRIGHT, .b = 0};
static const __attribute__((unused)) rgb_led_t lgreen = {.r = 0, .g = DIM, .b = 0};
static const __attribute__((unused)) cRGB red = {.r = BRIGHT, .g = 0, .b = 0};
static const __attribute__((unused)) cRGB lred = {.r = DIM, .g = 0, .b = 0};
static const __attribute__((unused)) rgb_led_t red = {.r = BRIGHT, .g = 0, .b = 0};
static const __attribute__((unused)) rgb_led_t lred = {.r = DIM, .g = 0, .b = 0};
static const __attribute__((unused)) cRGB blue = {.r = 0, .g = 0, .b = BRIGHT};
static const __attribute__((unused)) cRGB lblue = {.r = 0, .g = 0, .b = DIM};
static const __attribute__((unused)) rgb_led_t blue = {.r = 0, .g = 0, .b = BRIGHT};
static const __attribute__((unused)) rgb_led_t lblue = {.r = 0, .g = 0, .b = DIM};
static const __attribute__((unused)) cRGB turq = {.r = 0, .g = BRIGHT, .b = BRIGHT};
static const __attribute__((unused)) cRGB lturq = {.r = 0, .g = DIM, .b = DIM};
static const __attribute__((unused)) rgb_led_t turq = {.r = 0, .g = BRIGHT, .b = BRIGHT};
static const __attribute__((unused)) rgb_led_t lturq = {.r = 0, .g = DIM, .b = DIM};
static const __attribute__((unused)) cRGB white = {.r = BRIGHT, .g = BRIGHT, .b = BRIGHT};
static const __attribute__((unused)) rgb_led_t white = {.r = BRIGHT, .g = BRIGHT, .b = BRIGHT};
static led_t led_state;
static uint8_t layer;

View File

@ -162,7 +162,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
/** Set just 4 LEDs closest to the user. Slightly less annoying to bystanders.*/
void rgbflag(uint8_t r, uint8_t g, uint8_t b, uint8_t rr, uint8_t gg, uint8_t bb) {
LED_TYPE *target_led = user_rgb_mode ? shadowed_led : led;
rgb_led_t *target_led = user_rgb_mode ? shadowed_led : led;
for (int i = 0; i < RGBLED_NUM; i++) {
switch (i) {
case 12: case 13:

View File

@ -157,7 +157,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
#define C_ORG 0xFF, 0x93, 0x00
void rgbflag(uint8_t r, uint8_t g, uint8_t b, uint8_t rr, uint8_t gg, uint8_t bb) {
LED_TYPE *target_led = user_rgb_mode ? shadowed_led : led;
rgb_led_t *target_led = user_rgb_mode ? shadowed_led : led;
for (int i = 0; i < RGBLED_NUM; i++) {
switch (i) {
case 10: case 11:

View File

@ -217,7 +217,7 @@ void keyboard_post_init_user(void) {
rgblight_sethsv_noeeprom(50, 255, 100);
rgblight_mode_noeeprom(RGBLIGHT_EFFECT_BREATHING + 2);
// Init the second LED to a static color:
setrgb(225, 185, 0, (LED_TYPE *)&led[1]);
setrgb(225, 185, 0, (rgb_led_t *)&led[1]);
rgblight_set();
#endif // RGBLIGHT_ENABLE
}
@ -232,7 +232,7 @@ layer_state_t layer_state_set_user(layer_state_t state){
if (layer_state_cmp(state, 3)) {
led1r = 200;
}
setrgb(led1r, led1g, led1b, (LED_TYPE *)&led[1]);
setrgb(led1r, led1g, led1b, (rgb_led_t *)&led[1]);
rgblight_set();
#endif //RGBLIGHT_ENABLE
return state;

View File

@ -217,7 +217,7 @@ void keyboard_post_init_user(void) {
rgblight_sethsv_noeeprom(50, 255, 100);
rgblight_mode_noeeprom(RGBLIGHT_EFFECT_BREATHING + 2);
// Init the second LED to a static color:
setrgb(225, 185, 0, (LED_TYPE *)&led[1]);
setrgb(225, 185, 0, (rgb_led_t *)&led[1]);
rgblight_set();
#endif // RGBLIGHT_ENABLE
}
@ -232,7 +232,7 @@ layer_state_t layer_state_set_user(layer_state_t state){
if (layer_state_cmp(state, 3)) {
led1r = 200;
}
setrgb(led1r, led1g, led1b, (LED_TYPE *)&led[1]);
setrgb(led1r, led1g, led1b, (rgb_led_t *)&led[1]);
rgblight_set();
#endif //RGBLIGHT_ENABLE
return state;

View File

@ -148,7 +148,7 @@ bool rgb_matrix_indicators_kb(void) {
// ==========================================================================
# if WS2812_LED_TOTAL > 0
LED_TYPE rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
# endif
static void rgb_matrix_driver_init(void) {

View File

@ -148,7 +148,7 @@ bool rgb_matrix_indicators_kb(void) {
// ==========================================================================
# if WS2812_LED_TOTAL > 0
LED_TYPE rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
# endif
static void rgb_matrix_driver_init(void) {

View File

@ -144,7 +144,7 @@ bool rgb_matrix_indicators_kb(void) {
// ==========================================================================
# if WS2812_LED_TOTAL > 0
LED_TYPE rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
rgb_led_t rgb_matrix_ws2812_array[WS2812_LED_TOTAL];
# endif
static void rgb_matrix_driver_init(void) {

View File

@ -41,15 +41,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
layer_state_t layer_state_set_user(layer_state_t state) {
switch (get_highest_layer(state)) {
case 0:
sethsv(HSV_WHITE, (LED_TYPE *)&led[0]);
sethsv(HSV_WHITE, (rgb_led_t *)&led[0]);
rgblight_set();
break;
case 1:
sethsv(HSV_GREEN, (LED_TYPE *)&led[0]);
sethsv(HSV_GREEN, (rgb_led_t *)&led[0]);
rgblight_set();
break;
case 2:
sethsv(HSV_BLUE, (LED_TYPE *)&led[0]);
sethsv(HSV_BLUE, (rgb_led_t *)&led[0]);
rgblight_set();
break;
}

View File

@ -41,15 +41,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
layer_state_t layer_state_set_user(layer_state_t state) {
switch (get_highest_layer(state)) {
case 0:
sethsv(HSV_WHITE, (LED_TYPE *)&led[0]);
sethsv(HSV_WHITE, (rgb_led_t *)&led[0]);
rgblight_set();
break;
case 1:
sethsv(HSV_GREEN, (LED_TYPE *)&led[0]);
sethsv(HSV_GREEN, (rgb_led_t *)&led[0]);
rgblight_set();
break;
case 2:
sethsv(HSV_BLUE, (LED_TYPE *)&led[0]);
sethsv(HSV_BLUE, (rgb_led_t *)&led[0]);
rgblight_set();
break;
}

View File

@ -66,7 +66,7 @@ const aw9523b_led g_aw9523b_leds[AW9523B_RGB_NUM] = {
{AW9523B_P07_PWM, AW9523B_P06_PWM, AW9523B_P05_PWM},
};
void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds)
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
{
uint8_t num = num_leds < AW9523B_RGB_NUM ? num_leds : AW9523B_RGB_NUM;

View File

@ -357,7 +357,7 @@ static void custom_effects(void)
effect_funcs[rgb_ring.effect]();
}
void rgblight_call_driver(LED_TYPE *start_led, uint8_t num_leds)
void rgblight_call_driver(rgb_led_t *start_led, uint8_t num_leds)
{
if (rgb_ring.state != RING_STATE_QMK) {
return;

View File

@ -20,7 +20,7 @@ extern rgblight_config_t rgblight_config;
#if RGBLED_NUM < 7
#error "MUST set the RGBLED_NUM bigger than 7"
#endif
LED_TYPE noah_leds[RGBLED_NUM];
rgb_led_t noah_leds[RGBLED_NUM];
static bool noah_led_mode = false;
void rgblight_set(void) {
memset(&noah_leds[0], 0, sizeof(noah_leds));

View File

@ -25,7 +25,7 @@
// Variables for controlling front LED application
uint8_t fled_mode; // Mode for front LEDs
uint8_t fled_val; // Brightness for front leds (0 - 255)
LED_TYPE fleds[2]; // Front LED rgb values for indicator mode use
rgb_led_t fleds[2]; // Front LED rgb values for indicator mode use
// Layer indicator colors
__attribute__ ((weak))

Some files were not shown because too many files have changed in this diff Show More