Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Led Double Buffer #23625

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions data/mappings/info_config.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"LED_MATRIX_DEFAULT_ON": {"info_key": "led_matrix.default.on", "value_type": "bool"},
"LED_MATRIX_DEFAULT_VAL": {"info_key": "led_matrix.default.val", "value_type": "int"},
"LED_MATRIX_DEFAULT_SPD": {"info_key": "led_matrix.default.speed", "value_type": "int"},
"LED_MATRIX_DOUBLE_BUFFER": {"info_key": "led_matrix.double_buffer", "value_type": "flag"},

// Locking Switch
"LOCKING_SUPPORT_ENABLE": {"info_key": "qmk.locking.enabled", "value_type": "flag"},
Expand Down Expand Up @@ -152,6 +153,7 @@
"RGB_MATRIX_DEFAULT_SAT": {"info_key": "rgb_matrix.default.sat", "value_type": "int"},
"RGB_MATRIX_DEFAULT_VAL": {"info_key": "rgb_matrix.default.val", "value_type": "int"},
"RGB_MATRIX_DEFAULT_SPD": {"info_key": "rgb_matrix.default.speed", "value_type": "int"},
"RGB_MATRIX_DOUBLE_BUFFER": {"info_key": "rgb_matrix.double_buffer", "value_type": "flag"},

// RGBLight
"RGBLED_SPLIT": {"info_key": "rgblight.split_count", "value_type": "array.int"},
Expand All @@ -172,6 +174,7 @@
"RGBLIGHT_DEFAULT_SAT": {"info_key": "rgblight.default.sat", "value_type": "int"},
"RGBLIGHT_DEFAULT_VAL": {"info_key": "rgblight.default.val", "value_type": "int"},
"RGBLIGHT_DEFAULT_SPD": {"info_key": "rgblight.default.speed", "value_type": "int"},
"RGBLIGHT_DOUBLE_BUFFER": {"info_key": "rgblight.double_buffer", "value_type": "flag"},

// Secure
"SECURE_IDLE_TIMEOUT": {"info_key": "secure.idle_timeout", "value_type": "int"},
Expand Down
1 change: 1 addition & 0 deletions docs/features/led_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ For inspiration and examples, check out the built-in effects under `quantum/led_
#define LED_MATRIX_DEFAULT_FLAGS LED_FLAG_ALL // Sets the default LED flags, if none has been set
#define LED_MATRIX_SPLIT { X, Y } // (Optional) For split keyboards, the number of LEDs connected on each half. X = left, Y = Right.
// If reactive effects are enabled, you also will want to enable SPLIT_TRANSPORT_MIRROR
#define LED_MATRIX_DOUBLE_BUFFER // Use double buffer when rendering
```

## EEPROM storage {#eeprom-storage}
Expand Down
1 change: 1 addition & 0 deletions docs/features/rgb_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ These are defined in [`color.h`](https://github.com/qmk/qmk_firmware/blob/master
#define RGB_MATRIX_SPLIT { X, Y } // (Optional) For split keyboards, the number of LEDs connected on each half. X = left, Y = Right.
// If reactive effects are enabled, you also will want to enable SPLIT_TRANSPORT_MIRROR
#define RGB_TRIGGER_ON_KEYDOWN // Triggers RGB keypress events on key down. This makes RGB control feel more responsive. This may cause RGB to not function properly on some boards
#define RGB_MATRIX_DOUBLE_BUFFER // Use double buffer when rendering
```

## EEPROM storage {#eeprom-storage}
Expand Down
30 changes: 16 additions & 14 deletions docs/features/rgblight.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,22 @@ These keycodes cannot be used with functions like `tap_code16()` as they are not

Your RGB lighting can be configured by placing these `#define`s in your `config.h`:

|Define |Default |Description |
|---------------------------|----------------------------|---------------------------------------------------------------------------------------------------------------------------|
|`RGBLIGHT_HUE_STEP` |`8` |The number of steps to cycle through the hue by |
|`RGBLIGHT_SAT_STEP` |`17` |The number of steps to increment the saturation by |
|`RGBLIGHT_VAL_STEP` |`17` |The number of steps to increment the brightness by |
|`RGBLIGHT_LIMIT_VAL` |`255` |The maximum brightness level |
|`RGBLIGHT_SLEEP` |*Not defined* |If defined, the RGB lighting will be switched off when the host goes to sleep |
|`RGBLIGHT_SPLIT` |*Not defined* |If defined, synchronization functionality for split keyboards is added |
|`RGBLIGHT_DEFAULT_MODE` |`RGBLIGHT_MODE_STATIC_LIGHT`|The default mode to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_HUE` |`0` (red) |The default hue to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_SAT` |`UINT8_MAX` (255) |The default saturation to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_VAL` |`RGBLIGHT_LIMIT_VAL` |The default value (brightness) to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_SPD` |`0` |The default speed to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_ON` |`true` |Enable RGB lighting upon clearing the EEPROM |
|Define |Default |Description |
|---------------------------|----------------------------|-------------------------------------------------------------------------------|
|`RGBLIGHT_HUE_STEP` |`8` |The number of steps to cycle through the hue by |
|`RGBLIGHT_SAT_STEP` |`17` |The number of steps to increment the saturation by |
|`RGBLIGHT_VAL_STEP` |`17` |The number of steps to increment the brightness by |
|`RGBLIGHT_LIMIT_VAL` |`255` |The maximum brightness level |
|`RGBLIGHT_SLEEP` |*Not defined* |If defined, the RGB lighting will be switched off when the host goes to sleep |
|`RGBLIGHT_SPLIT` |*Not defined* |If defined, synchronization functionality for split keyboards is added |
|`RGBLIGHT_DEFAULT_MODE` |`RGBLIGHT_MODE_STATIC_LIGHT`|The default mode to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_HUE` |`0` (red) |The default hue to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_SAT` |`UINT8_MAX` (255) |The default saturation to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_VAL` |`RGBLIGHT_LIMIT_VAL` |The default value (brightness) to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_SPD` |`0` |The default speed to use upon clearing the EEPROM |
|`RGBLIGHT_DEFAULT_ON` |`true` |Enable RGB lighting upon clearing the EEPROM |
|`RGBLIGHT_DOUBLE_BUFFER` |*Not defined* |If defined, use double buffer when rendering |


## Effects and Animations

Expand Down
8 changes: 8 additions & 0 deletions quantum/led_matrix/led_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

#include <lib/lib8tion/lib8tion.h>

#ifdef LED_MATRIX_DOUBLE_BUFFER
# define led_matrix_driver led_matrix_driver_wrapper
#endif

#ifndef LED_MATRIX_CENTER
const led_point_t k_led_matrix_center = {112, 32};
#else
Expand Down Expand Up @@ -631,3 +635,7 @@ void led_matrix_set_flags(led_flags_t flags) {
void led_matrix_set_flags_noeeprom(led_flags_t flags) {
led_matrix_set_flags_eeprom_helper(flags, false);
}

#ifdef LED_MATRIX_DOUBLE_BUFFER
# undef led_matrix_driver
#endif
Xelus22 marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions quantum/led_matrix/led_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,37 @@ const led_matrix_driver_t led_matrix_driver = {
};

#endif

#ifdef LED_MATRIX_DOUBLE_BUFFER

static uint8_t led_buffer[LED_MATRIX_LED_COUNT];

void led_matrix_driver_init(void) {
led_matrix_driver.init();
}

void led_matrix_driver_flush(void) {
for (uint16_t i = 0; i < led_matrix_LED_COUNT; i++) {
led_matrix_driver.set_color(i, led_buffer[i]);
}
led_matrix_driver.flush();
}

void led_matrix_driver_set_color(int index, uint8_t value) {
led_buffer[index] = value;
}

void led_matrix_driver_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
for (uint16_t i = 0; i < LED_MATRIX_LED_COUNT; i++) {
led_matrix_driver_set_color(i, red, green, blue);
}
}

const led_matrix_driver_t led_matrix_driver_wrapper = {
.init = led_matrix_driver_init,
.flush = led_matrix_driver_flush,
.set_color = led_matrix_driver_set_color,
.set_color_all = led_matrix_driver_set_color_all,
};

#endif
4 changes: 4 additions & 0 deletions quantum/led_matrix/led_matrix_drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ typedef struct {
void (*flush)(void);
} led_matrix_driver_t;

#ifdef LED_MATRIX_DOUBLE_BUFFER
extern const led_matrix_driver_t led_matrix_driver_wrapper;
#endif

extern const led_matrix_driver_t led_matrix_driver;
8 changes: 8 additions & 0 deletions quantum/rgb_matrix/rgb_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

#include <lib/lib8tion/lib8tion.h>

#ifdef RGB_MATRIX_DOUBLE_BUFFER
# define rgb_matrix_driver rgb_matrix_driver_wrapper
#endif

#ifndef RGB_MATRIX_CENTER
const led_point_t k_rgb_matrix_center = {112, 32};
#else
Expand Down Expand Up @@ -717,3 +721,7 @@ void rgb_matrix_set_flags(led_flags_t flags) {
void rgb_matrix_set_flags_noeeprom(led_flags_t flags) {
rgb_matrix_set_flags_eeprom_helper(flags, false);
}

#ifdef RGB_MATRIX_DOUBLE_BUFFER
# undef rgb_matrix_driver
#endif
Xelus22 marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions quantum/rgb_matrix/rgb_matrix_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,37 @@ const rgb_matrix_driver_t rgb_matrix_driver = {
};

#endif

#ifdef RGB_MATRIX_DOUBLE_BUFFER

static rgb_t led_buffer[RGB_MATRIX_LED_COUNT];

void rgb_matrix_driver_init(void) {
rgb_matrix_driver.init();
}

void rgb_matrix_driver_flush(void) {
for (uint16_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
rgb_matrix_driver.set_color(i, led_buffer[i].r, led_buffer[i].g, led_buffer[i].b);
}
rgb_matrix_driver.flush();
}

void rgb_matrix_driver_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
led_buffer[index] = (rgb_t){.r = red, .g = green, .b = blue};
}

void rgb_matrix_driver_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
for (uint16_t i = 0; i < RGB_MATRIX_LED_COUNT; i++) {
rgb_matrix_driver_set_color(i, red, green, blue);
}
}

const rgb_matrix_driver_t rgb_matrix_driver_wrapper = {
.init = rgb_matrix_driver_init,
.flush = rgb_matrix_driver_flush,
.set_color = rgb_matrix_driver_set_color,
.set_color_all = rgb_matrix_driver_set_color_all,
};

#endif
4 changes: 4 additions & 0 deletions quantum/rgb_matrix/rgb_matrix_drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ typedef struct {
void (*flush)(void);
} rgb_matrix_driver_t;

#ifdef RGB_MATRIX_DOUBLE_BUFFER
extern const rgb_matrix_driver_t rgb_matrix_driver_wrapper;
#endif

extern const rgb_matrix_driver_t rgb_matrix_driver;
11 changes: 10 additions & 1 deletion quantum/rgblight/rgblight.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2016-2017 Yang Liu

Check failure on line 1 in quantum/rgblight/rgblight.c

View workflow job for this annotation

GitHub Actions / lint

Requires Formatting
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -24,6 +24,11 @@
#include "util.h"
#include "led_tables.h"
#include <lib/lib8tion/lib8tion.h>

#ifdef RGBLIGHT_DOUBLE_BUFFER
# define rgblight_driver rgblight_driver_wrapper
#endif

#ifdef EEPROM_ENABLE
# include "eeprom.h"
#endif
Expand Down Expand Up @@ -1398,7 +1403,7 @@

for (uint8_t i = 0; i < rgblight_ranges.effect_num_leds; i++) {
TwinkleState *t = &(led_twinkle_state[i]);
hsv_t * c = &(t->hsv);
hsv_t *c = &(t->hsv);
Xelus22 marked this conversation as resolved.
Show resolved Hide resolved

if (!random_color) {
c->h = rgblight_config.hue;
Expand Down Expand Up @@ -1491,3 +1496,7 @@
}

#endif

#ifdef RGBLIGHT_DOUBLE_BUFFER
# undef rgblight_driver
#endif
Xelus22 marked this conversation as resolved.
Show resolved Hide resolved
34 changes: 34 additions & 0 deletions quantum/rgblight/rgblight_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,37 @@ const rgblight_driver_t rgblight_driver = {
};

#endif

#ifdef RGBLIGHT_DOUBLE_BUFFER

static rgb_t led_buffer[RGBLIGHT_LED_COUNT];

void rgblight_driver_init(void) {
rgblight_driver.init();
}

void rgblight_driver_flush(void) {
for (uint16_t i = 0; i < RGBLIGHT_LED_COUNT; i++) {
rgblight_driver.set_color(i, led_buffer[i].r, led_buffer[i].g, led_buffer[i].b);
}
rgblight_driver.flush();
}

void rgblight_driver_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
led_buffer[index] = (rgb_t){.r = red, .g = green, .b = blue};
}

void rgblight_driver_set_color_all(uint8_t red, uint8_t green, uint8_t blue) {
for (uint16_t i = 0; i < RGBLIGHT_LED_COUNT; i++) {
rgb_matrix_driver_set_color(i, red, green, blue);
}
}

const rgblight_driver_t rgblight_driver_wrapper = {
.init = rgblight_driver_init,
.flush = rgblight_driver_flush,
.set_color = rgblight_driver_set_color,
.set_color_all = rgblight_driver_set_color_all,
};

#endif
4 changes: 4 additions & 0 deletions quantum/rgblight/rgblight_drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ typedef struct {
void (*flush)(void);
} rgblight_driver_t;

#ifdef RGBLIGHT_DOUBLE_BUFFER
extern const rgblight_driver_t rgblight_driver_wrapper;
#endif

extern const rgblight_driver_t rgblight_driver;
Loading