Skip to content

Commit

Permalink
sn32 rgb driver: add individual channel color correction
Browse files Browse the repository at this point in the history
LED output differs depending on the module used, as well as the
current limiting setup. Introduce a luminosity correction factor
that will limit output on overdriven channels, allowing fine
tuning through PWM scaling.
  • Loading branch information
dexter93 committed Jan 3, 2024
1 parent 2065a0e commit 456a43a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
20 changes: 12 additions & 8 deletions drivers/led/sn32/rgb_matrix_sn32f2xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ void sn32f2xx_flush(void) {
}

void sn32f2xx_set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
uint8_t color_r = r * SN32_LED_OUTPUT_LUMINOSITY_R;
uint8_t color_g = g * SN32_LED_OUTPUT_LUMINOSITY_G;
uint8_t color_b = b * SN32_LED_OUTPUT_LUMINOSITY_B;

#ifdef UNDERGLOW_RBG
bool flip_gb = false;
for (uint8_t led_id = 0; led_id < UNDERGLOW_LEDS; led_id++) {
Expand All @@ -631,23 +635,23 @@ void sn32f2xx_set_color(int index, uint8_t r, uint8_t g, uint8_t b) {
}
}
if (flip_gb) {
if (led_state_buf[index].r == r && led_state_buf[index].b == g && led_state_buf[index].g == b) {
if (led_state_buf[index].r == color_r && led_state_buf[index].b == color_g && led_state_buf[index].g == color_b) {
return;
}

led_state_buf[index].r = r;
led_state_buf[index].b = g;
led_state_buf[index].g = b;
led_state_buf[index].r = color_r;
led_state_buf[index].b = color_g;
led_state_buf[index].g = color_b;
led_state_buf_update_required = true;
} else {
#endif // UNDERGLOW_RBG
if (led_state_buf[index].r == r && led_state_buf[index].b == b && led_state_buf[index].g == g) {
if (led_state_buf[index].r == color_r && led_state_buf[index].b == color_b && led_state_buf[index].g == color_g) {
return;
}

led_state_buf[index].r = r;
led_state_buf[index].b = b;
led_state_buf[index].g = g;
led_state_buf[index].r = color_r;
led_state_buf[index].b = color_b;
led_state_buf[index].g = color_g;
led_state_buf_update_required = true;
#ifdef UNDERGLOW_RBG
}
Expand Down
10 changes: 10 additions & 0 deletions drivers/led/sn32/sn32f2xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
#include <stdint.h>
#include <stdbool.h>

#if !defined(SN32_LED_OUTPUT_LUMINOSITY_R)
# define SN32_LED_OUTPUT_LUMINOSITY_R 1
#endif
#if !defined(SN32_LED_OUTPUT_LUMINOSITY_G)
# define SN32_LED_OUTPUT_LUMINOSITY_G 1
#endif
#if !defined(SN32_LED_OUTPUT_LUMINOSITY_B)
# define SN32_LED_OUTPUT_LUMINOSITY_B 1
#endif

#if defined(RGB_MATRIX_SN32F2XX)
# define SN32F2XX_LED_COUNT RGB_MATRIX_LED_COUNT
#endif
Expand Down

0 comments on commit 456a43a

Please sign in to comment.