aboutsummaryrefslogtreecommitdiff
path: root/quantum/led_matrix.c
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 /quantum/led_matrix.c
parent69bc465aced1d2d4f28ef0319e78ea7096f3fda0 (diff)
downloadqmk_firmware-40c314fe5c99d6d85039e6155723d2c2506d0d7f.tar.gz
qmk_firmware-40c314fe5c99d6d85039e6155723d2c2506d0d7f.zip
LED Matrix: Implement CIE1931 curve (#12417)
Diffstat (limited to 'quantum/led_matrix.c')
-rw-r--r--quantum/led_matrix.c38
1 files changed, 29 insertions, 9 deletions
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) {