WS2812 API rework (#24364)
* Begin WS2812 API rework * Move RGBW conversion, clean up color.h, fix RGBW for AVR bitbang * Formatting & update PS2AVRGB I2C driver (untested) * Tested ARM bitbang RGB+RGBW * Tested ARM SPI RGB - RGBW not working * Tested ARM PWM RGB+RGBW * Tested RP2040 PIO driver RGB+RGBW * Update RGBLight * Formatting * Fix BM60HSRGB rev2 * Fix oddforge/vea * Fix 1k and XD002 RGBLite * Fix model_m/mschwingen * Fix handwired/promethium * Rename `WS2812_LED_TOTAL` for BM60HSRGB * Fix work_louder boards * Fix dawn60 * Fix rgbkb/pan * Fix neson_design/700e and n6 * Fix ergodox_ez/shine * ergodox_ez/shine: invert indices for left half * Fix matrix/abelx * Fix matrix/m20add * Remove custom rgblight driver for matrix/noah - should be done with lighting layers * Fix LED indexes for RGBLight split * Rename `convert_rgb_to_rgbw()` to `ws2812_rgb_to_rgbw()` * Update WS2812 API docs * `ergodox_ez/shine`: simplify LED index calculation * LED/RGB Matrix: Add weak function for LED index resolution * Bandaid fix for RGB Matrix splits not using WS2812 * `steelseries/prime_plus`: redo custom RGBLight driver * Update keyboards/steelseries/prime_plus/rgblight_custom.c Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com> --------- Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									43e82ed5c7
								
							
						
					
					
						commit
						208ebf54a9
					
				
					 61 changed files with 649 additions and 672 deletions
				
			
		| 
						 | 
				
			
			@ -65,6 +65,7 @@
 | 
			
		|||
# define MODELM_LED_SCROLLOCK MODELM_LED3
 | 
			
		||||
# define MODELM_LED_NUMLOCK   MODELM_LED1
 | 
			
		||||
#elif defined(KEYBOARD_ibm_model_m_mschwingen_led_ws2812)
 | 
			
		||||
# define WS2812_LED_COUNT 3
 | 
			
		||||
#else
 | 
			
		||||
# error one of MODELM_LEDS_FFC, MODELM_LEDS_WIRED or MODELM_LEDS_WS2812 must be set!
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,27 +39,10 @@ static uint8_t  isRecording = 0;
 | 
			
		|||
#    if RGBLIGHT_LED_COUNT < 3
 | 
			
		||||
#        error we need at least 3 RGB LEDs!
 | 
			
		||||
#    endif
 | 
			
		||||
static rgb_led_t led[RGBLIGHT_LED_COUNT] = {{255, 255, 255}, {255, 255, 255}, {255, 255, 255}};
 | 
			
		||||
 | 
			
		||||
#    define BRIGHT 32
 | 
			
		||||
#    define DIM 6
 | 
			
		||||
 | 
			
		||||
static const rgb_led_t black = {.r = 0, .g = 0, .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)) 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)) 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)) 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)) rgb_led_t white = {.r = BRIGHT, .g = BRIGHT, .b = BRIGHT};
 | 
			
		||||
 | 
			
		||||
static led_t   led_state;
 | 
			
		||||
static uint8_t layer;
 | 
			
		||||
static uint8_t default_layer;
 | 
			
		||||
| 
						 | 
				
			
			@ -81,17 +64,15 @@ void sleep_led_enable(void) {
 | 
			
		|||
    suspend_active = true;
 | 
			
		||||
    gpio_write_pin_low(MODELM_STATUS_LED);
 | 
			
		||||
#ifdef KEYBOARD_ibm_model_m_mschwingen_led_ws2812
 | 
			
		||||
    led[0] = black;
 | 
			
		||||
    led[1] = black;
 | 
			
		||||
    led[2] = black;
 | 
			
		||||
    ws2812_setleds(led, RGBLIGHT_LED_COUNT);
 | 
			
		||||
    ws2812_set_color_all(0, 0, 0);
 | 
			
		||||
    ws2812_flush();
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void keyboard_pre_init_kb(void) {
 | 
			
		||||
#ifdef KEYBOARD_ibm_model_m_mschwingen_led_ws2812
 | 
			
		||||
    ws2812_init();
 | 
			
		||||
    ws2812_setleds(led, RGBLIGHT_LED_COUNT);
 | 
			
		||||
    ws2812_flush();
 | 
			
		||||
#else
 | 
			
		||||
    /* Set status LEDs pins to output and Low (on) */
 | 
			
		||||
    gpio_set_pin_output(MODELM_LED_CAPSLOCK);
 | 
			
		||||
| 
						 | 
				
			
			@ -121,35 +102,59 @@ void keyboard_pre_init_kb(void) {
 | 
			
		|||
#ifdef KEYBOARD_ibm_model_m_mschwingen_led_ws2812
 | 
			
		||||
static void led_update_rgb(void) {
 | 
			
		||||
    if (isRecording && blink_state) {
 | 
			
		||||
        led[0] = white;
 | 
			
		||||
        ws2812_set_color(0, BRIGHT, BRIGHT, BRIGHT);
 | 
			
		||||
    } else {
 | 
			
		||||
        switch (default_layer) {
 | 
			
		||||
            case 0:
 | 
			
		||||
                led[0] = led_state.num_lock ? blue : lblue;
 | 
			
		||||
                if (led_state.num_lock) {
 | 
			
		||||
                    ws2812_set_color(0, 0, 0, BRIGHT);
 | 
			
		||||
                } else {
 | 
			
		||||
                    ws2812_set_color(0, 0, 0, DIM);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
            case 1:
 | 
			
		||||
                led[0] = led_state.num_lock ? green : black;
 | 
			
		||||
                if (led_state.num_lock) {
 | 
			
		||||
                    ws2812_set_color(0, 0, BRIGHT, 0);
 | 
			
		||||
                } else {
 | 
			
		||||
                    ws2812_set_color(0, 0, 0, 0);
 | 
			
		||||
                }
 | 
			
		||||
                break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    led[1] = led_state.caps_lock ? green : black;
 | 
			
		||||
    if (led_state.caps_lock) {
 | 
			
		||||
        ws2812_set_color(1, 0, BRIGHT, 0);
 | 
			
		||||
    } else {
 | 
			
		||||
        ws2812_set_color(1, 0, 0, 0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch (layer) {
 | 
			
		||||
        case 0:
 | 
			
		||||
        case 1:
 | 
			
		||||
        default:
 | 
			
		||||
            led[2] = led_state.scroll_lock ? green : black;
 | 
			
		||||
            if (led_state.scroll_lock) {
 | 
			
		||||
                ws2812_set_color(2, 0, BRIGHT, 0);
 | 
			
		||||
            } else {
 | 
			
		||||
                ws2812_set_color(2, 0, 0, 0);
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case 2:
 | 
			
		||||
            led[2] = led_state.scroll_lock ? red : lred;
 | 
			
		||||
            if (led_state.scroll_lock) {
 | 
			
		||||
                ws2812_set_color(2, BRIGHT, 0, 0);
 | 
			
		||||
            } else {
 | 
			
		||||
                ws2812_set_color(2, DIM, 0, 0);
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case 3:
 | 
			
		||||
            led[2] = led_state.scroll_lock ? turq : lturq;
 | 
			
		||||
            if (led_state.scroll_lock) {
 | 
			
		||||
                ws2812_set_color(2, 0, BRIGHT, BRIGHT);
 | 
			
		||||
            } else {
 | 
			
		||||
                ws2812_set_color(2, 0, DIM, DIM);
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
    if (!suspend_active) {
 | 
			
		||||
	ws2812_setleds(led, RGBLIGHT_LED_COUNT);
 | 
			
		||||
        ws2812_flush();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue