1
0
Fork 0

[MERGE][Core] Add dirty chunk checking for all RGB and LED drivers (24872)

This commit is contained in:
Drashna Jael're 2025-01-26 04:52:39 -08:00
parent 0324612c37
commit 4a138dd93c
Signed by: drashna
GPG key ID: DBA1FD3A860D1B11
28 changed files with 690 additions and 286 deletions

View file

@ -25,6 +25,7 @@
#include <util/delay.h>
#include "ws2812.h"
#include "pin_defs.h"
#include <stdbool.h>
#define pinmask(pin) (_BV((pin)&0xF))
@ -152,6 +153,7 @@ static inline void ws2812_sendarray_mask(uint8_t *data, uint16_t datlen, uint8_t
}
ws2812_led_t ws2812_leds[WS2812_LED_COUNT];
bool ws2812_dirty = false;
void ws2812_init(void) {
DDRx_ADDRESS(WS2812_DI_PIN) |= pinmask(WS2812_DI_PIN);
@ -161,6 +163,7 @@ void ws2812_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
ws2812_leds[index].r = red;
ws2812_leds[index].g = green;
ws2812_leds[index].b = blue;
ws2812_dirty = true;
#if defined(WS2812_RGBW)
ws2812_rgb_to_rgbw(&ws2812_leds[index]);
#endif
@ -173,6 +176,8 @@ void ws2812_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
}
void ws2812_flush(void) {
if (!ws2812_dirty) return;
ws2812_dirty = false;
uint8_t masklo = ~(pinmask(WS2812_DI_PIN)) & PORTx_ADDRESS(WS2812_DI_PIN);
uint8_t maskhi = pinmask(WS2812_DI_PIN) | PORTx_ADDRESS(WS2812_DI_PIN);

View file

@ -1,6 +1,7 @@
// Copyright 2024 QMK
// SPDX-License-Identifier: GPL-2.0-or-later
#include <stdbool.h>
#include "ws2812.h"
#include "i2c_master.h"
@ -17,6 +18,7 @@
#endif
ws2812_led_t ws2812_leds[WS2812_LED_COUNT];
bool ws2812_dirty = false;
void ws2812_init(void) {
i2c_init();
@ -26,6 +28,7 @@ void ws2812_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
ws2812_leds[index].r = red;
ws2812_leds[index].g = green;
ws2812_leds[index].b = blue;
ws2812_dirty = true;
}
void ws2812_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
@ -35,5 +38,7 @@ void ws2812_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
}
void ws2812_flush(void) {
if (!ws2812_dirty) return;
ws2812_dirty = false;
i2c_transmit(WS2812_I2C_ADDRESS, (uint8_t *)ws2812_leds, WS2812_LED_COUNT * sizeof(ws2812_led_t), WS2812_I2C_TIMEOUT);
}