diff options
author | Ryan <fauxpark@gmail.com> | 2021-03-28 17:59:44 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-28 17:59:44 +1100 |
commit | 2ae38e9c43cc689be65f04ea5c101b9f46a38c5e (patch) | |
tree | 918b2c9d8a87513edf5a5aec9f930f626c16d179 | |
parent | 0d1162f1809bc9828d9b4655b8d3cf3db60c4b55 (diff) | |
download | qmk_firmware-2ae38e9c43cc689be65f04ea5c101b9f46a38c5e.tar.gz qmk_firmware-2ae38e9c43cc689be65f04ea5c101b9f46a38c5e.zip |
LED Matrix: Config functions (#12361)
-rw-r--r-- | quantum/led_matrix.c | 160 | ||||
-rw-r--r-- | quantum/led_matrix.h | 32 | ||||
-rw-r--r-- | tmk_core/common/keyboard.c | 6 |
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 | |||
27 | led_eeconfig_t led_matrix_eeconfig; | 29 | led_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 | |||
231 | void led_matrix_init(void) { | 216 | void 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 | ||
258 | static 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 | |||
264 | static 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 | |||
291 | uint32_t led_matrix_get_tick(void) { return g_tick; } | 242 | uint32_t led_matrix_get_tick(void) { return g_tick; } |
292 | 243 | ||
293 | void led_matrix_toggle(void) { | 244 | void 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 | } |
251 | void led_matrix_toggle_noeeprom(void) { led_matrix_toggle_eeprom_helper(false); } | ||
252 | void led_matrix_toggle(void) { led_matrix_toggle_eeprom_helper(true); } | ||
297 | 253 | ||
298 | void led_matrix_enable(void) { | 254 | void 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 | ||
303 | void led_matrix_enable_noeeprom(void) { led_matrix_eeconfig.enable = 1; } | 259 | void led_matrix_enable_noeeprom(void) { led_matrix_eeconfig.enable = 1; } |
304 | 260 | ||
305 | void led_matrix_disable(void) { | 261 | void 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 | ||
310 | void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; } | 266 | void led_matrix_disable_noeeprom(void) { led_matrix_eeconfig.enable = 0; } |
311 | 267 | ||
312 | void led_matrix_step(void) { | 268 | uint8_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 | ||
320 | void led_matrix_step_reverse(void) { | 270 | void 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 | } |
286 | void led_matrix_mode_noeeprom(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, false); } | ||
287 | void led_matrix_mode(uint8_t mode) { led_matrix_mode_eeprom_helper(mode, true); } | ||
327 | 288 | ||
328 | void led_matrix_increase_val(void) { | 289 | uint8_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 | ||
333 | void led_matrix_decrease_val(void) { | 291 | void 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 | } |
295 | void led_matrix_step_noeeprom(void) { led_matrix_step_helper(false); } | ||
296 | void led_matrix_step(void) { led_matrix_step_helper(true); } | ||
337 | 297 | ||
338 | void led_matrix_increase_speed(void) { | 298 | void 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 | } |
302 | void led_matrix_step_reverse_noeeprom(void) { led_matrix_step_reverse_helper(false); } | ||
303 | void led_matrix_step_reverse(void) { led_matrix_step_reverse_helper(true); } | ||
342 | 304 | ||
343 | void led_matrix_decrease_speed(void) { | 305 | void 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 | } |
315 | void led_matrix_set_val_noeeprom(uint8_t val) { led_matrix_set_val_eeprom_helper(val, false); } | ||
316 | void led_matrix_set_val(uint8_t val) { led_matrix_set_val_eeprom_helper(val, true); } | ||
317 | |||
318 | uint8_t led_matrix_get_val(void) { return led_matrix_eeconfig.val; } | ||
319 | |||
320 | void 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); } | ||
321 | void led_matrix_increase_val_noeeprom(void) { led_matrix_increase_val_helper(false); } | ||
322 | void led_matrix_increase_val(void) { led_matrix_increase_val_helper(true); } | ||
347 | 323 | ||
348 | void led_matrix_mode(uint8_t mode, bool eeprom_write) { | 324 | void 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; | 325 | void led_matrix_decrease_val_noeeprom(void) { led_matrix_decrease_val_helper(false); } |
350 | if (eeprom_write) { | 326 | void led_matrix_decrease_val(void) { led_matrix_decrease_val_helper(true); } |
327 | |||
328 | void 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 | } |
335 | void led_matrix_set_speed_noeeprom(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, false); } | ||
336 | void led_matrix_set_speed(uint8_t speed) { led_matrix_set_speed_eeprom_helper(speed, true); } | ||
354 | 337 | ||
355 | uint8_t led_matrix_get_mode(void) { return led_matrix_eeconfig.mode; } | 338 | uint8_t led_matrix_get_speed(void) { return led_matrix_eeconfig.speed; } |
356 | 339 | ||
357 | void led_matrix_set_value_noeeprom(uint8_t val) { led_matrix_eeconfig.val = val; } | 340 | void 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); } |
341 | void led_matrix_increase_speed_noeeprom(void) { led_matrix_increase_speed_helper(false); } | ||
342 | void led_matrix_increase_speed(void) { led_matrix_increase_speed_helper(true); } | ||
358 | 343 | ||
359 | void led_matrix_set_value(uint8_t val) { | 344 | void 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); | 345 | void led_matrix_decrease_speed_noeeprom(void) { led_matrix_decrease_speed_helper(false); } |
361 | eeconfig_update_led_matrix(); | 346 | void 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 | |||
31 | enum led_matrix_effects { | 39 | enum 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); | |||
38 | void led_matrix_set_index_value_all(uint8_t value); | 46 | void 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 |
42 | void led_matrix_indicators(void); | 50 | void led_matrix_indicators(void); |
43 | void led_matrix_indicators_kb(void); | 51 | void led_matrix_indicators_kb(void); |
44 | void led_matrix_indicators_user(void); | 52 | void led_matrix_indicators_user(void); |
@@ -62,21 +70,33 @@ bool process_led_matrix(uint16_t keycode, keyrecord_t *record); | |||
62 | uint32_t led_matrix_get_tick(void); | 70 | uint32_t led_matrix_get_tick(void); |
63 | 71 | ||
64 | void led_matrix_toggle(void); | 72 | void led_matrix_toggle(void); |
73 | void led_matrix_toggle_noeeprom(void); | ||
65 | void led_matrix_enable(void); | 74 | void led_matrix_enable(void); |
66 | void led_matrix_enable_noeeprom(void); | 75 | void led_matrix_enable_noeeprom(void); |
67 | void led_matrix_disable(void); | 76 | void led_matrix_disable(void); |
68 | void led_matrix_disable_noeeprom(void); | 77 | void led_matrix_disable_noeeprom(void); |
78 | uint8_t led_matrix_is_enabled(void); | ||
79 | void led_matrix_mode(uint8_t mode); | ||
80 | void led_matrix_mode_noeeprom(uint8_t mode); | ||
81 | uint8_t led_matrix_get_mode(void); | ||
69 | void led_matrix_step(void); | 82 | void led_matrix_step(void); |
83 | void led_matrix_step_noeeprom(void); | ||
70 | void led_matrix_step_reverse(void); | 84 | void led_matrix_step_reverse(void); |
85 | void led_matrix_step_reverse_noeeprom(void); | ||
86 | void led_matrix_set_val(uint8_t val); | ||
87 | void led_matrix_set_val_noeeprom(uint8_t val); | ||
88 | uint8_t led_matrix_get_val(void); | ||
71 | void led_matrix_increase_val(void); | 89 | void led_matrix_increase_val(void); |
90 | void led_matrix_increase_val_noeeprom(void); | ||
72 | void led_matrix_decrease_val(void); | 91 | void led_matrix_decrease_val(void); |
92 | void led_matrix_decrease_val_noeeprom(void); | ||
93 | void led_matrix_set_speed(uint8_t speed); | ||
94 | void led_matrix_set_speed_noeeprom(uint8_t speed); | ||
95 | uint8_t led_matrix_get_speed(void); | ||
73 | void led_matrix_increase_speed(void); | 96 | void led_matrix_increase_speed(void); |
97 | void led_matrix_increase_speed_noeeprom(void); | ||
74 | void led_matrix_decrease_speed(void); | 98 | void led_matrix_decrease_speed(void); |
75 | void led_matrix_mode(uint8_t mode, bool eeprom_write); | 99 | void led_matrix_decrease_speed_noeeprom(void); |
76 | void led_matrix_mode_noeeprom(uint8_t mode); | ||
77 | uint8_t led_matrix_get_mode(void); | ||
78 | void led_matrix_set_value(uint8_t mode); | ||
79 | void led_matrix_set_value_noeeprom(uint8_t mode); | ||
80 | 100 | ||
81 | typedef struct { | 101 | typedef 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 |