aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-04-07 20:06:11 +1000
committerGitHub <noreply@github.com>2021-04-07 20:06:11 +1000
commit40c314fe5c99d6d85039e6155723d2c2506d0d7f (patch)
tree6c33c10f1e5161a102e31404fdfa19b124e9f452
parent69bc465aced1d2d4f28ef0319e78ea7096f3fda0 (diff)
downloadqmk_firmware-40c314fe5c99d6d85039e6155723d2c2506d0d7f.tar.gz
qmk_firmware-40c314fe5c99d6d85039e6155723d2c2506d0d7f.zip
LED Matrix: Implement CIE1931 curve (#12417)
-rw-r--r--common_features.mk1
-rw-r--r--quantum/led_matrix.c38
-rw-r--r--quantum/led_matrix.h45
3 files changed, 57 insertions, 27 deletions
diff --git a/common_features.mk b/common_features.mk
index 2e2991c64..eb2ea2811 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -233,6 +233,7 @@ endif
233 SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c 233 SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c
234 SRC += $(QUANTUM_DIR)/led_matrix.c 234 SRC += $(QUANTUM_DIR)/led_matrix.c
235 SRC += $(QUANTUM_DIR)/led_matrix_drivers.c 235 SRC += $(QUANTUM_DIR)/led_matrix_drivers.c
236 CIE1931_CURVE := yes
236 237
237 ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731) 238 ifeq ($(strip $(LED_MATRIX_DRIVER)), IS31FL3731)
238 OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE 239 OPT_DEFS += -DIS31FL3731 -DSTM32_I2C -DHAL_USE_I2C=TRUE
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c
index ec8ff852d..e13376455 100644
--- a/quantum/led_matrix.c
+++ b/quantum/led_matrix.c
@@ -23,6 +23,7 @@
23#include "eeprom.h" 23#include "eeprom.h"
24#include <string.h> 24#include <string.h>
25#include <math.h> 25#include <math.h>
26#include "led_tables.h"
26 27
27#include <lib/lib8tion/lib8tion.h> 28#include <lib/lib8tion/lib8tion.h>
28 29
@@ -108,8 +109,10 @@ void eeconfig_debug_led_matrix(void) {
108uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255}; 109uint8_t g_last_led_hit[LED_HITS_TO_REMEMBER] = {255};
109uint8_t g_last_led_count = 0; 110uint8_t g_last_led_count = 0;
110 111
111uint8_t map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) { 112__attribute__((weak)) uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i) { return 0; }
112 uint8_t led_count = 0; 113
114uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
115 uint8_t led_count = led_matrix_map_row_column_to_led_kb(row, column, led_i);
113 uint8_t led_index = g_led_config.matrix_co[row][column]; 116 uint8_t led_index = g_led_config.matrix_co[row][column];
114 if (led_index != NO_LED) { 117 if (led_index != NO_LED) {
115 led_i[led_count] = led_index; 118 led_i[led_count] = led_index;
@@ -120,14 +123,26 @@ uint8_t map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i) {
120 123
121void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); } 124void led_matrix_update_pwm_buffers(void) { led_matrix_driver.flush(); }
122 125
123void led_matrix_set_index_value(int index, uint8_t value) { led_matrix_driver.set_value(index, value); } 126void led_matrix_set_value(int index, uint8_t value) {
127#ifdef USE_CIE1931_CURVE
128 led_matrix_driver.set_value(index, pgm_read_byte(&CIE1931_CURVE[value]));
129#else
130 led_matrix_driver.set_value(index, value);
131#endif
132}
124 133
125void led_matrix_set_index_value_all(uint8_t value) { led_matrix_driver.set_value_all(value); } 134void led_matrix_set_value_all(uint8_t value) {
135#ifdef USE_CIE1931_CURVE
136 led_matrix_driver.set_value_all(pgm_read_byte(&CIE1931_CURVE[value]));
137#else
138 led_matrix_driver.set_value_all(value);
139#endif
140}
126 141
127bool process_led_matrix(uint16_t keycode, keyrecord_t *record) { 142bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
128 if (record->event.pressed) { 143 if (record->event.pressed) {
129 uint8_t led[8]; 144 uint8_t led[8];
130 uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led); 145 uint8_t led_count = led_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
131 if (led_count > 0) { 146 if (led_count > 0) {
132 for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) { 147 for (uint8_t i = LED_HITS_TO_REMEMBER; i > 1; i--) {
133 g_last_led_hit[i - 1] = g_last_led_hit[i - 2]; 148 g_last_led_hit[i - 1] = g_last_led_hit[i - 2];
@@ -140,7 +155,7 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
140 } else { 155 } else {
141#ifdef LED_MATRIX_KEYRELEASES 156#ifdef LED_MATRIX_KEYRELEASES
142 uint8_t led[8]; 157 uint8_t led[8];
143 uint8_t led_count = map_row_column_to_led(record->event.key.row, record->event.key.col, led); 158 uint8_t led_count = led_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
144 for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255; 159 for (uint8_t i = 0; i < led_count; i++) g_key_hit[led[i]] = 255;
145 160
146 g_any_key_hit = 255; 161 g_any_key_hit = 255;
@@ -149,7 +164,14 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
149 return true; 164 return true;
150} 165}
151 166
152void led_matrix_set_suspend_state(bool state) { g_suspend_state = state; } 167void led_matrix_set_suspend_state(bool state) {
168 if (LED_DISABLE_WHEN_USB_SUSPENDED && state) {
169 led_matrix_set_value_all(0); // turn off all LEDs when suspending
170 }
171 g_suspend_state = state;
172}
173
174bool led_matrix_get_suspend_state(void) { return g_suspend_state; }
153 175
154// All LEDs off 176// All LEDs off
155void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); } 177void led_matrix_all_off(void) { led_matrix_set_index_value_all(0); }
@@ -239,8 +261,6 @@ void led_matrix_init(void) {
239 eeconfig_debug_led_matrix(); // display current eeprom values 261 eeconfig_debug_led_matrix(); // display current eeprom values
240} 262}
241 263
242uint32_t led_matrix_get_tick(void) { return g_tick; }
243
244void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) { 264void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
245 led_matrix_eeconfig.enable ^= 1; 265 led_matrix_eeconfig.enable ^= 1;
246 if (write_to_eeprom) { 266 if (write_to_eeprom) {
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h
index fd7ef7d29..ba8f0279a 100644
--- a/quantum/led_matrix.h
+++ b/quantum/led_matrix.h
@@ -36,14 +36,36 @@
36# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 36# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
37#endif 37#endif
38 38
39#if defined(LED_MATRIX_LED_PROCESS_LIMIT) && LED_MATRIX_LED_PROCESS_LIMIT > 0 && LED_MATRIX_LED_PROCESS_LIMIT < DRIVER_LED_TOTAL
40# define LED_MATRIX_USE_LIMITS(min, max) \
41 uint8_t min = LED_MATRIX_LED_PROCESS_LIMIT * params->iter; \
42 uint8_t max = min + LED_MATRIX_LED_PROCESS_LIMIT; \
43 if (max > DRIVER_LED_TOTAL) max = DRIVER_LED_TOTAL;
44#else
45# define LED_MATRIX_USE_LIMITS(min, max) \
46 uint8_t min = 0; \
47 uint8_t max = DRIVER_LED_TOTAL;
48#endif
49
39enum led_matrix_effects { 50enum led_matrix_effects {
40 LED_MATRIX_UNIFORM_BRIGHTNESS = 1, 51 LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
41 // All new effects go above this line 52 // All new effects go above this line
42 LED_MATRIX_EFFECT_MAX 53 LED_MATRIX_EFFECT_MAX
43}; 54};
44 55
45void led_matrix_set_index_value(int index, uint8_t value); 56void eeconfig_update_led_matrix_default(void);
46void led_matrix_set_index_value_all(uint8_t value); 57void eeconfig_update_led_matrix(void);
58void eeconfig_debug_led_matrix(void);
59
60uint8_t led_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
61uint8_t led_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *led_i);
62
63void led_matrix_set_value(int index, uint8_t value);
64void led_matrix_set_value_all(uint8_t value);
65
66bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
67
68void led_matrix_task(void);
47 69
48// This runs after another backlight effect and replaces 70// This runs after another backlight effect and replaces
49// values already set 71// values already set
@@ -52,23 +74,9 @@ void led_matrix_indicators_kb(void);
52void led_matrix_indicators_user(void); 74void led_matrix_indicators_user(void);
53 75
54void led_matrix_init(void); 76void led_matrix_init(void);
55void led_matrix_setup_drivers(void);
56
57void led_matrix_set_suspend_state(bool state);
58void led_matrix_set_indicator_state(uint8_t state);
59
60void led_matrix_task(void);
61
62// This should not be called from an interrupt
63// (eg. from a timer interrupt).
64// Call this while idle (in between matrix scans).
65// If the buffer is dirty, it will update the driver with the buffer.
66void led_matrix_update_pwm_buffers(void);
67
68bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
69
70uint32_t led_matrix_get_tick(void);
71 77
78void led_matrix_set_suspend_state(bool state);
79bool led_matrix_get_suspend_state(void);
72void led_matrix_toggle(void); 80void led_matrix_toggle(void);
73void led_matrix_toggle_noeeprom(void); 81void led_matrix_toggle_noeeprom(void);
74void led_matrix_enable(void); 82void led_matrix_enable(void);
@@ -114,4 +122,5 @@ extern const led_matrix_driver_t led_matrix_driver;
114 122
115extern led_eeconfig_t led_matrix_eeconfig; 123extern led_eeconfig_t led_matrix_eeconfig;
116 124
125extern bool g_suspend_state;
117extern led_config_t g_led_config; 126extern led_config_t g_led_config;