aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-03-28 17:59:44 +1100
committerGitHub <noreply@github.com>2021-03-28 17:59:44 +1100
commit2ae38e9c43cc689be65f04ea5c101b9f46a38c5e (patch)
tree918b2c9d8a87513edf5a5aec9f930f626c16d179
parent0d1162f1809bc9828d9b4655b8d3cf3db60c4b55 (diff)
downloadqmk_firmware-2ae38e9c43cc689be65f04ea5c101b9f46a38c5e.tar.gz
qmk_firmware-2ae38e9c43cc689be65f04ea5c101b9f46a38c5e.zip
LED Matrix: Config functions (#12361)
-rw-r--r--quantum/led_matrix.c160
-rw-r--r--quantum/led_matrix.h32
-rw-r--r--tmk_core/common/keyboard.c6
3 files changed, 104 insertions, 94 deletions
diff --git a/quantum/led_matrix.c b/quantum/led_matrix.c
index ceb236809..ec8ff852d 100644
--- a/quantum/led_matrix.c
+++ b/quantum/led_matrix.c
@@ -24,6 +24,8 @@
24#include <string.h> 24#include <string.h>
25#include <math.h> 25#include <math.h>
26 26
27#include <lib/lib8tion/lib8tion.h>
28
27led_eeconfig_t led_matrix_eeconfig; 29led_eeconfig_t led_matrix_eeconfig;
28 30
29#ifndef MAX 31#ifndef MAX
@@ -211,23 +213,6 @@ __attribute__((weak)) void led_matrix_indicators_kb(void) {}
211 213
212__attribute__((weak)) void led_matrix_indicators_user(void) {} 214__attribute__((weak)) void led_matrix_indicators_user(void) {}
213 215
214// void led_matrix_set_indicator_index(uint8_t *index, uint8_t row, uint8_t column)
215// {
216// if (row >= MATRIX_ROWS)
217// {
218// // Special value, 255=none, 254=all
219// *index = row;
220// }
221// else
222// {
223// // This needs updated to something like
224// // uint8_t led[8];
225// // uint8_t led_count = map_row_column_to_led(row, column, led);
226// // for(uint8_t i = 0; i < led_count; i++)
227// map_row_column_to_led(row, column, index);
228// }
229// }
230
231void led_matrix_init(void) { 216void led_matrix_init(void) {
232 led_matrix_driver.init(); 217 led_matrix_driver.init();
233 218
@@ -254,109 +239,108 @@ void led_matrix_init(void) {
254 eeconfig_debug_led_matrix(); // display current eeprom values 239 eeconfig_debug_led_matrix(); // display current eeprom values
255} 240}
256 241
257// Deals with the messy details of incrementing an integer
258static uint8_t increment(uint8_t value, uint8_t step, uint8_t min, uint8_t max) {
259 int16_t new_value = value;
260 new_value += step;
261 return MIN(MAX(new_value, min), max);
262}
263
264static uint8_t decrement(uint8_t value, uint8_t step, uint8_t min, uint8_t max) {
265 int16_t new_value = value;
266 new_value -= step;
267 return MIN(MAX(new_value, min), max);
268}
269
270// void *backlight_get_custom_key_value_eeprom_address(uint8_t led) {
271// // 3 bytes per value
272// return EECONFIG_LED_MATRIX + (led * 3);
273// }
274
275// void backlight_get_key_value(uint8_t led, uint8_t *value) {
276// void *address = backlight_get_custom_key_value_eeprom_address(led);
277// value = eeprom_read_byte(address);
278// }
279
280// void backlight_set_key_value(uint8_t row, uint8_t column, uint8_t value) {
281// uint8_t led[8];
282// uint8_t led_count = map_row_column_to_led(row, column, led);
283// for(uint8_t i = 0; i < led_count; i++) {
284// if (led[i] < DRIVER_LED_TOTAL) {
285// void *address = backlight_get_custom_key_value_eeprom_address(led[i]);
286// eeprom_update_byte(address, value);
287// }
288// }
289// }
290
291uint32_t led_matrix_get_tick(void) { return g_tick; } 242uint32_t led_matrix_get_tick(void) { return g_tick; }
292 243
293void led_matrix_toggle(void) { 244void led_matrix_toggle_eeprom_helper(bool write_to_eeprom) {
294 led_matrix_eeconfig.enable ^= 1; 245 led_matrix_eeconfig.enable ^= 1;
295 eeconfig_update_led_matrix(); 246 if (write_to_eeprom) {
247 eeconfig_update_led_matrix();
248 }
249 dprintf("led matrix toggle [%s]: led_matrix_eeconfig.enable = %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.enable);
296} 250}
251void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); }
252void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); }
297 253
298void led_matrix_enable(void) { 254void led_matrix_enable(void) {
299 led_matrix_eeconfig.enable = 1; 255 led_matrix_enable_noeeprom();
300 eeconfig_update_led_matrix(); 256 eeconfig_update_led_matrix();
301} 257}
302 258
303void led_matrix_enable_noeeprom(void) { led_matrix_eeconfig.enable = 1; } 259void led_matrix_enable_noeeprom(void) { led_matrix_eeconfig.enable = 1; }
304 260
305void led_matrix_disable(void) { 261void led_matrix_disable(void) {
306 led_matrix_eeconfig.enable = 0; 262 led_matrix_disable_noeeprom();
307 eeconfig_update_led_matrix(); 263 eeconfig_update_led_matrix();
308} 264}
309 265
310void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; } 266void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; }
311 267
312void led_matrix_step(void) { 268uint8_t led_matrix_is_enabled(void) { return led_matrix_eeconfig.enable; }
313 led_matrix_eeconfig.mode++;
314 if (led_matrix_eeconfig.mode >= LED_MATRIX_EFFECT_MAX) {
315 led_matrix_eeconfig.mode = 1;
316 }
317 eeconfig_update_led_matrix();
318}
319 269
320void led_matrix_step_reverse(void) { 270void led_matrix_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
321 led_matrix_eeconfig.mode--; 271 if (!led_matrix_eeconfig.enable) {
322 if (led_matrix_eeconfig.mode < 1) { 272 return;
273 }
274 if (mode < 1) {
275 led_matrix_eeconfig.mode = 1;
276 } else if (mode >= LED_MATRIX_EFFECT_MAX) {
323 led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1; 277 led_matrix_eeconfig.mode = LED_MATRIX_EFFECT_MAX - 1;
278 } else {
279 led_matrix_eeconfig.mode = mode;
324 } 280 }
325 eeconfig_update_led_matrix(); 281 if (write_to_eeprom) {
282 eeconfig_update_led_matrix();
283 }
284 dprintf("led matrix mode [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.mode);
326} 285}
286void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); }
287void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); }
327 288
328void led_matrix_increase_val(void) { 289uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; }
329 led_matrix_eeconfig.val = increment(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS);
330 eeconfig_update_led_matrix();
331}
332 290
333void led_matrix_decrease_val(void) { 291void led_matrix_step_helper(bool write_to_eeprom) {
334 led_matrix_eeconfig.val = decrement(led_matrix_eeconfig.val, 8, 0, LED_MATRIX_MAXIMUM_BRIGHTNESS); 292 uint8_t mode = led_matrix_eeconfig.mode + 1;
335 eeconfig_update_led_matrix(); 293 led_matrix_mode_eeprom_helper((mode < LED_MATRIX_EFFECT_MAX) ? mode : 1, write_to_eeprom);
336} 294}
295void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); }
296void led_matrix_step(void) { led_matrix_step_helper(true); }
337 297
338void led_matrix_increase_speed(void) { 298void led_matrix_step_reverse_helper(bool write_to_eeprom) {
339 led_matrix_eeconfig.speed = increment(led_matrix_eeconfig.speed, 1, 0, 3); 299 uint8_t mode = led_matrix_eeconfig.mode - 1;
340 eeconfig_update_led_matrix(); // EECONFIG needs to be increased to support this 300 led_matrix_mode_eeprom_helper((mode < 1) ? LED_MATRIX_EFFECT_MAX - 1 : mode, write_to_eeprom);
341} 301}
302void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); }
303void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); }
342 304
343void led_matrix_decrease_speed(void) { 305void led_matrix_set_val_eeprom_helper(uint8_t val, bool write_to_eeprom) {
344 led_matrix_eeconfig.speed = decrement(led_matrix_eeconfig.speed, 1, 0, 3); 306 if (!led_matrix_eeconfig.enable) {
345 eeconfig_update_led_matrix(); // EECONFIG needs to be increased to support this 307 return;
308 }
309 led_matrix_eeconfig.val = (val > LED_MATRIX_MAXIMUM_BRIGHTNESS) ? LED_MATRIX_MAXIMUM_BRIGHTNESS : val;
310 if (write_to_eeprom) {
311 eeconfig_update_led_matrix();
312 }
313 dprintf("led matrix set val [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.val);
346} 314}
315void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); }
316void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); }
317
318uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; }
319
320void led_matrix_increase_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qadd8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); }
321void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); }
322void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); }
347 323
348void led_matrix_mode(uint8_t mode, bool eeprom_write) { 324void led_matrix_decrease_val_helper(bool write_to_eeprom) { led_matrix_set_val_eeprom_helper(qsub8(led_matrix_eeconfig.val, LED_MATRIX_VAL_STEP), write_to_eeprom); }
349 led_matrix_eeconfig.mode = mode; 325void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); }
350 if (eeprom_write) { 326void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); }
327
328void led_matrix_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
329 led_matrix_eeconfig.speed = speed;
330 if (write_to_eeprom) {
351 eeconfig_update_led_matrix(); 331 eeconfig_update_led_matrix();
352 } 332 }
333 dprintf("led matrix set speed [%s]: %u\n", (write_to_eeprom) ? "EEPROM" : "NOEEPROM", led_matrix_eeconfig.speed);
353} 334}
335void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); }
336void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); }
354 337
355uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } 338uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; }
356 339
357void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_eeconfig.val = val; } 340void led_matrix_increase_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qadd8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); }
341void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); }
342void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); }
358 343
359void led_matrix_set_value(uint8_t val) { 344void led_matrix_decrease_speed_helper(bool write_to_eeprom) { led_matrix_set_speed_eeprom_helper(qsub8(led_matrix_eeconfig.speed, LED_MATRIX_SPD_STEP), write_to_eeprom); }
360 led_matrix_set_value_noeeprom(val); 345void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); }
361 eeconfig_update_led_matrix(); 346void led_matrix_decrease_speed(void) { led_matrix_decrease_speed_helper(true); }
362}
diff --git a/quantum/led_matrix.h b/quantum/led_matrix.h
index e4322a150..fd7ef7d29 100644
--- a/quantum/led_matrix.h
+++ b/quantum/led_matrix.h
@@ -28,6 +28,14 @@
28# include "is31fl3731-simple.h" 28# include "is31fl3731-simple.h"
29#endif 29#endif
30 30
31#ifndef LED_MATRIX_LED_FLUSH_LIMIT
32# define LED_MATRIX_LED_FLUSH_LIMIT 16
33#endif
34
35#ifndef LED_MATRIX_LED_PROCESS_LIMIT
36# define LED_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5
37#endif
38
31enum led_matrix_effects { 39enum led_matrix_effects {
32 LED_MATRIX_UNIFORM_BRIGHTNESS = 1, 40 LED_MATRIX_UNIFORM_BRIGHTNESS = 1,
33 // All new effects go above this line 41 // All new effects go above this line
@@ -38,7 +46,7 @@ void led_matrix_set_index_value(int index, uint8_t value);
38void led_matrix_set_index_value_all(uint8_t value); 46void led_matrix_set_index_value_all(uint8_t value);
39 47
40// This runs after another backlight effect and replaces 48// This runs after another backlight effect and replaces
41// colors already set 49// values already set
42void led_matrix_indicators(void); 50void led_matrix_indicators(void);
43void led_matrix_indicators_kb(void); 51void led_matrix_indicators_kb(void);
44void led_matrix_indicators_user(void); 52void led_matrix_indicators_user(void);
@@ -62,21 +70,33 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
62uint32_t led_matrix_get_tick(void); 70uint32_t led_matrix_get_tick(void);
63 71
64void led_matrix_toggle(void); 72void led_matrix_toggle(void);
73void led_matrix_toggle_noeeprom(void);
65void led_matrix_enable(void); 74void led_matrix_enable(void);
66void led_matrix_enable_noeeprom(void); 75void led_matrix_enable_noeeprom(void);
67void led_matrix_disable(void); 76void led_matrix_disable(void);
68void led_matrix_disable_noeeprom(void); 77void led_matrix_disable_noeeprom(void);
78uint8_t led_matrix_is_enabled(void);
79void led_matrix_mode(uint8_t mode);
80void led_matrix_mode_noeeprom(uint8_t mode);
81uint8_t led_matrix_get_mode(void);
69void led_matrix_step(void); 82void led_matrix_step(void);
83void led_matrix_step_noeeprom(void);
70void led_matrix_step_reverse(void); 84void led_matrix_step_reverse(void);
85void led_matrix_step_reverse_noeeprom(void);
86void led_matrix_set_val(uint8_t val);
87void led_matrix_set_val_noeeprom(uint8_t val);
88uint8_t led_matrix_get_val(void);
71void led_matrix_increase_val(void); 89void led_matrix_increase_val(void);
90void led_matrix_increase_val_noeeprom(void);
72void led_matrix_decrease_val(void); 91void led_matrix_decrease_val(void);
92void led_matrix_decrease_val_noeeprom(void);
93void led_matrix_set_speed(uint8_t speed);
94void led_matrix_set_speed_noeeprom(uint8_t speed);
95uint8_t led_matrix_get_speed(void);
73void led_matrix_increase_speed(void); 96void led_matrix_increase_speed(void);
97void led_matrix_increase_speed_noeeprom(void);
74void led_matrix_decrease_speed(void); 98void led_matrix_decrease_speed(void);
75void led_matrix_mode(uint8_t mode, bool eeprom_write); 99void led_matrix_decrease_speed_noeeprom(void);
76void led_matrix_mode_noeeprom(uint8_t mode);
77uint8_t led_matrix_get_mode(void);
78void led_matrix_set_value(uint8_t mode);
79void led_matrix_set_value_noeeprom(uint8_t mode);
80 100
81typedef struct { 101typedef struct {
82 /* Perform any initialisation required for the other driver functions to work. */ 102 /* Perform any initialisation required for the other driver functions to work. */
diff --git a/tmk_core/common/keyboard.c b/tmk_core/common/keyboard.c
index 65d9e00c7..e473806b2 100644
--- a/tmk_core/common/keyboard.c
+++ b/tmk_core/common/keyboard.c
@@ -49,6 +49,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
49#ifdef RGBLIGHT_ENABLE 49#ifdef RGBLIGHT_ENABLE
50# include "rgblight.h" 50# include "rgblight.h"
51#endif 51#endif
52#ifdef LED_MATRIX_ENABLE
53# include "led_matrix.h"
54#endif
52#ifdef RGB_MATRIX_ENABLE 55#ifdef RGB_MATRIX_ENABLE
53# include "rgb_matrix.h" 56# include "rgb_matrix.h"
54#endif 57#endif
@@ -412,6 +415,9 @@ MATRIX_LOOP_END:
412 rgblight_task(); 415 rgblight_task();
413#endif 416#endif
414 417
418#ifdef LED_MATRIX_ENABLE
419 led_matrix_task();
420#endif
415#ifdef RGB_MATRIX_ENABLE 421#ifdef RGB_MATRIX_ENABLE
416 rgb_matrix_task(); 422 rgb_matrix_task();
417#endif 423#endif