aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--quantum/rgb_matrix.c48
-rw-r--r--quantum/rgb_matrix.h39
-rw-r--r--tmk_core/common/eeconfig.c3
-rw-r--r--tmk_core/common/eeconfig.h6
-rw-r--r--users/xulkal/process_records.c4
5 files changed, 35 insertions, 65 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c
index d20daf5e4..f170cfc1b 100644
--- a/quantum/rgb_matrix.c
+++ b/quantum/rgb_matrix.c
@@ -66,10 +66,6 @@
66 #define RGB_DISABLE_WHEN_USB_SUSPENDED false 66 #define RGB_DISABLE_WHEN_USB_SUSPENDED false
67#endif 67#endif
68 68
69#ifndef EECONFIG_RGB_MATRIX
70 #define EECONFIG_RGB_MATRIX EECONFIG_RGBLIGHT
71#endif
72
73#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX 69#if !defined(RGB_MATRIX_MAXIMUM_BRIGHTNESS) || RGB_MATRIX_MAXIMUM_BRIGHTNESS > UINT8_MAX
74 #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS 70 #undef RGB_MATRIX_MAXIMUM_BRIGHTNESS
75 #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX 71 #define RGB_MATRIX_MAXIMUM_BRIGHTNESS UINT8_MAX
@@ -116,12 +112,12 @@ uint8_t rgb_frame_buffer[MATRIX_ROWS][MATRIX_COLS] = {{0}};
116 static last_hit_t last_hit_buffer; 112 static last_hit_t last_hit_buffer;
117#endif // RGB_MATRIX_KEYREACTIVE_ENABLED 113#endif // RGB_MATRIX_KEYREACTIVE_ENABLED
118 114
119uint32_t eeconfig_read_rgb_matrix(void) { 115void eeconfig_read_rgb_matrix(void) {
120 return eeprom_read_dword(EECONFIG_RGB_MATRIX); 116 eeprom_read_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config));
121} 117}
122 118
123void eeconfig_update_rgb_matrix(uint32_t val) { 119void eeconfig_update_rgb_matrix(void) {
124 eeprom_update_dword(EECONFIG_RGB_MATRIX, val); 120 eeprom_update_block(&rgb_matrix_config, EECONFIG_RGB_MATRIX, sizeof(rgb_matrix_config));
125} 121}
126 122
127void eeconfig_update_rgb_matrix_default(void) { 123void eeconfig_update_rgb_matrix_default(void) {
@@ -130,7 +126,7 @@ void eeconfig_update_rgb_matrix_default(void) {
130 rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE; 126 rgb_matrix_config.mode = RGB_MATRIX_STARTUP_MODE;
131 rgb_matrix_config.hsv = (HSV){ 0, UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS }; 127 rgb_matrix_config.hsv = (HSV){ 0, UINT8_MAX, RGB_MATRIX_MAXIMUM_BRIGHTNESS };
132 rgb_matrix_config.speed = UINT8_MAX / 2; 128 rgb_matrix_config.speed = UINT8_MAX / 2;
133 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 129 eeconfig_update_rgb_matrix();
134} 130}
135 131
136void eeconfig_debug_rgb_matrix(void) { 132void eeconfig_debug_rgb_matrix(void) {
@@ -431,12 +427,10 @@ void rgb_matrix_init(void) {
431 eeconfig_update_rgb_matrix_default(); 427 eeconfig_update_rgb_matrix_default();
432 } 428 }
433 429
434 rgb_matrix_config.raw = eeconfig_read_rgb_matrix(); 430 eeconfig_read_rgb_matrix();
435 rgb_matrix_config.speed = UINT8_MAX / 2; //EECONFIG needs to be increased to support this
436 if (!rgb_matrix_config.mode) { 431 if (!rgb_matrix_config.mode) {
437 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n"); 432 dprintf("rgb_matrix_init_drivers rgb_matrix_config.mode = 0. Write default values to EEPROM.\n");
438 eeconfig_update_rgb_matrix_default(); 433 eeconfig_update_rgb_matrix_default();
439 rgb_matrix_config.raw = eeconfig_read_rgb_matrix();
440 } 434 }
441 eeconfig_debug_rgb_matrix(); // display current eeprom values 435 eeconfig_debug_rgb_matrix(); // display current eeprom values
442} 436}
@@ -448,12 +442,12 @@ void rgb_matrix_set_suspend_state(bool state) {
448void rgb_matrix_toggle(void) { 442void rgb_matrix_toggle(void) {
449 rgb_matrix_config.enable ^= 1; 443 rgb_matrix_config.enable ^= 1;
450 rgb_task_state = STARTING; 444 rgb_task_state = STARTING;
451 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 445 eeconfig_update_rgb_matrix();
452} 446}
453 447
454void rgb_matrix_enable(void) { 448void rgb_matrix_enable(void) {
455 rgb_matrix_enable_noeeprom(); 449 rgb_matrix_enable_noeeprom();
456 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 450 eeconfig_update_rgb_matrix();
457} 451}
458 452
459void rgb_matrix_enable_noeeprom(void) { 453void rgb_matrix_enable_noeeprom(void) {
@@ -464,7 +458,7 @@ void rgb_matrix_enable_noeeprom(void) {
464 458
465void rgb_matrix_disable(void) { 459void rgb_matrix_disable(void) {
466 rgb_matrix_disable_noeeprom(); 460 rgb_matrix_disable_noeeprom();
467 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 461 eeconfig_update_rgb_matrix();
468} 462}
469 463
470void rgb_matrix_disable_noeeprom(void) { 464void rgb_matrix_disable_noeeprom(void) {
@@ -478,7 +472,7 @@ void rgb_matrix_step(void) {
478 if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX) 472 if (rgb_matrix_config.mode >= RGB_MATRIX_EFFECT_MAX)
479 rgb_matrix_config.mode = 1; 473 rgb_matrix_config.mode = 1;
480 rgb_task_state = STARTING; 474 rgb_task_state = STARTING;
481 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 475 eeconfig_update_rgb_matrix();
482} 476}
483 477
484void rgb_matrix_step_reverse(void) { 478void rgb_matrix_step_reverse(void) {
@@ -486,49 +480,49 @@ void rgb_matrix_step_reverse(void) {
486 if (rgb_matrix_config.mode < 1) 480 if (rgb_matrix_config.mode < 1)
487 rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; 481 rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1;
488 rgb_task_state = STARTING; 482 rgb_task_state = STARTING;
489 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 483 eeconfig_update_rgb_matrix();
490} 484}
491 485
492void rgb_matrix_increase_hue(void) { 486void rgb_matrix_increase_hue(void) {
493 rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP; 487 rgb_matrix_config.hsv.h += RGB_MATRIX_HUE_STEP;
494 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 488 eeconfig_update_rgb_matrix();
495} 489}
496 490
497void rgb_matrix_decrease_hue(void) { 491void rgb_matrix_decrease_hue(void) {
498 rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP; 492 rgb_matrix_config.hsv.h -= RGB_MATRIX_HUE_STEP;
499 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 493 eeconfig_update_rgb_matrix();
500} 494}
501 495
502void rgb_matrix_increase_sat(void) { 496void rgb_matrix_increase_sat(void) {
503 rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); 497 rgb_matrix_config.hsv.s = qadd8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
504 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 498 eeconfig_update_rgb_matrix();
505} 499}
506 500
507void rgb_matrix_decrease_sat(void) { 501void rgb_matrix_decrease_sat(void) {
508 rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP); 502 rgb_matrix_config.hsv.s = qsub8(rgb_matrix_config.hsv.s, RGB_MATRIX_SAT_STEP);
509 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 503 eeconfig_update_rgb_matrix();
510} 504}
511 505
512void rgb_matrix_increase_val(void) { 506void rgb_matrix_increase_val(void) {
513 rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); 507 rgb_matrix_config.hsv.v = qadd8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
514 if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS) 508 if (rgb_matrix_config.hsv.v > RGB_MATRIX_MAXIMUM_BRIGHTNESS)
515 rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS; 509 rgb_matrix_config.hsv.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
516 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 510 eeconfig_update_rgb_matrix();
517} 511}
518 512
519void rgb_matrix_decrease_val(void) { 513void rgb_matrix_decrease_val(void) {
520 rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP); 514 rgb_matrix_config.hsv.v = qsub8(rgb_matrix_config.hsv.v, RGB_MATRIX_VAL_STEP);
521 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 515 eeconfig_update_rgb_matrix();
522} 516}
523 517
524void rgb_matrix_increase_speed(void) { 518void rgb_matrix_increase_speed(void) {
525 rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); 519 rgb_matrix_config.speed = qadd8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
526 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this 520 eeconfig_update_rgb_matrix();
527} 521}
528 522
529void rgb_matrix_decrease_speed(void) { 523void rgb_matrix_decrease_speed(void) {
530 rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP); 524 rgb_matrix_config.speed = qsub8(rgb_matrix_config.speed, RGB_MATRIX_SPD_STEP);
531 eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this 525 eeconfig_update_rgb_matrix();
532} 526}
533 527
534led_flags_t rgb_matrix_get_flags(void) { 528led_flags_t rgb_matrix_get_flags(void) {
@@ -542,7 +536,7 @@ void rgb_matrix_set_flags(led_flags_t flags) {
542void rgb_matrix_mode(uint8_t mode) { 536void rgb_matrix_mode(uint8_t mode) {
543 rgb_matrix_config.mode = mode; 537 rgb_matrix_config.mode = mode;
544 rgb_task_state = STARTING; 538 rgb_task_state = STARTING;
545 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 539 eeconfig_update_rgb_matrix();
546} 540}
547 541
548void rgb_matrix_mode_noeeprom(uint8_t mode) { 542void rgb_matrix_mode_noeeprom(uint8_t mode) {
@@ -555,7 +549,7 @@ uint8_t rgb_matrix_get_mode(void) {
555 549
556void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) { 550void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val) {
557 rgb_matrix_sethsv_noeeprom(hue, sat, val); 551 rgb_matrix_sethsv_noeeprom(hue, sat, val);
558 eeconfig_update_rgb_matrix(rgb_matrix_config.raw); 552 eeconfig_update_rgb_matrix();
559} 553}
560 554
561void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) { 555void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h
index 96a8b7662..749926822 100644
--- a/quantum/rgb_matrix.h
+++ b/quantum/rgb_matrix.h
@@ -56,12 +56,6 @@
56 56
57#define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue 57#define RGB_MATRIX_TEST_LED_FLAGS() if (!HAS_ANY_FLAGS(g_led_config.flags[i], params->flags)) continue
58 58
59typedef struct
60{
61 HSV color;
62 uint8_t index;
63} rgb_indicator;
64
65enum rgb_matrix_effects { 59enum rgb_matrix_effects {
66 RGB_MATRIX_NONE = 0, 60 RGB_MATRIX_NONE = 0,
67 61
@@ -87,11 +81,18 @@ enum rgb_matrix_effects {
87 RGB_MATRIX_EFFECT_MAX 81 RGB_MATRIX_EFFECT_MAX
88}; 82};
89 83
84void eeconfig_update_rgb_matrix_default(void);
85
86uint8_t rgb_matrix_map_row_column_to_led_kb(uint8_t row, uint8_t column, uint8_t *led_i);
90uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i); 87uint8_t rgb_matrix_map_row_column_to_led( uint8_t row, uint8_t column, uint8_t *led_i);
91 88
92void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue ); 89void rgb_matrix_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
93void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue ); 90void rgb_matrix_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
94 91
92bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
93
94void rgb_matrix_task(void);
95
95// This runs after another backlight effect and replaces 96// This runs after another backlight effect and replaces
96// colors already set 97// colors already set
97void rgb_matrix_indicators(void); 98void rgb_matrix_indicators(void);
@@ -99,37 +100,14 @@ void rgb_matrix_indicators_kb(void);
99void rgb_matrix_indicators_user(void); 100void rgb_matrix_indicators_user(void);
100 101
101void rgb_matrix_init(void); 102void rgb_matrix_init(void);
102void rgb_matrix_setup_drivers(void);
103 103
104void rgb_matrix_set_suspend_state(bool state); 104void rgb_matrix_set_suspend_state(bool state);
105void rgb_matrix_set_indicator_state(uint8_t state);
106
107
108void rgb_matrix_task(void);
109
110// This should not be called from an interrupt
111// (eg. from a timer interrupt).
112// Call this while idle (in between matrix scans).
113// If the buffer is dirty, it will update the driver with the buffer.
114void rgb_matrix_update_pwm_buffers(void);
115
116bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
117
118void rgb_matrix_increase(void);
119void rgb_matrix_decrease(void);
120
121// void *backlight_get_key_color_eeprom_address(uint8_t led);
122// void backlight_get_key_color( uint8_t led, HSV *hsv );
123// void backlight_set_key_color( uint8_t row, uint8_t column, HSV hsv );
124
125void rgb_matrix_toggle(void); 105void rgb_matrix_toggle(void);
126void rgb_matrix_enable(void); 106void rgb_matrix_enable(void);
127void rgb_matrix_enable_noeeprom(void); 107void rgb_matrix_enable_noeeprom(void);
128void rgb_matrix_disable(void); 108void rgb_matrix_disable(void);
129void rgb_matrix_disable_noeeprom(void); 109void rgb_matrix_disable_noeeprom(void);
130void rgb_matrix_step(void); 110void rgb_matrix_step(void);
131void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
132void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
133void rgb_matrix_step_reverse(void); 111void rgb_matrix_step_reverse(void);
134void rgb_matrix_increase_hue(void); 112void rgb_matrix_increase_hue(void);
135void rgb_matrix_decrease_hue(void); 113void rgb_matrix_decrease_hue(void);
@@ -144,6 +122,8 @@ void rgb_matrix_set_flags(led_flags_t flags);
144void rgb_matrix_mode(uint8_t mode); 122void rgb_matrix_mode(uint8_t mode);
145void rgb_matrix_mode_noeeprom(uint8_t mode); 123void rgb_matrix_mode_noeeprom(uint8_t mode);
146uint8_t rgb_matrix_get_mode(void); 124uint8_t rgb_matrix_get_mode(void);
125void rgb_matrix_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
126void rgb_matrix_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);
147 127
148#ifndef RGBLIGHT_ENABLE 128#ifndef RGBLIGHT_ENABLE
149#define rgblight_toggle() rgb_matrix_toggle() 129#define rgblight_toggle() rgb_matrix_toggle()
@@ -166,7 +146,6 @@ uint8_t rgb_matrix_get_mode(void);
166#define rgblight_mode(mode) rgb_matrix_mode(mode) 146#define rgblight_mode(mode) rgb_matrix_mode(mode)
167#define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode) 147#define rgblight_mode_noeeprom(mode) rgb_matrix_mode_noeeprom(mode)
168#define rgblight_get_mode() rgb_matrix_get_mode() 148#define rgblight_get_mode() rgb_matrix_get_mode()
169
170#endif 149#endif
171 150
172typedef struct { 151typedef struct {
diff --git a/tmk_core/common/eeconfig.c b/tmk_core/common/eeconfig.c
index 30dc7a48d..4f440abc9 100644
--- a/tmk_core/common/eeconfig.c
+++ b/tmk_core/common/eeconfig.c
@@ -47,9 +47,8 @@ void eeconfig_init_quantum(void) {
47 eeprom_update_byte(EECONFIG_STENOMODE, 0); 47 eeprom_update_byte(EECONFIG_STENOMODE, 0);
48 eeprom_update_dword(EECONFIG_HAPTIC, 0); 48 eeprom_update_dword(EECONFIG_HAPTIC, 0);
49 eeprom_update_byte(EECONFIG_VELOCIKEY, 0); 49 eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
50#ifdef EECONFIG_RGB_MATRIX
51 eeprom_update_dword(EECONFIG_RGB_MATRIX, 0); 50 eeprom_update_dword(EECONFIG_RGB_MATRIX, 0);
52#endif 51 eeprom_update_byte(EECONFIG_RGB_MATRIX_SPEED, 0);
53 52
54 eeconfig_init_kb(); 53 eeconfig_init_kb();
55} 54}
diff --git a/tmk_core/common/eeconfig.h b/tmk_core/common/eeconfig.h
index 0ac3dff07..3100041b4 100644
--- a/tmk_core/common/eeconfig.h
+++ b/tmk_core/common/eeconfig.h
@@ -37,12 +37,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
37#define EECONFIG_UNICODEMODE (uint8_t *)12 37#define EECONFIG_UNICODEMODE (uint8_t *)12
38#define EECONFIG_STENOMODE (uint8_t *)13 38#define EECONFIG_STENOMODE (uint8_t *)13
39// EEHANDS for two handed boards 39// EEHANDS for two handed boards
40#define EECONFIG_HANDEDNESS (uint8_t *)14 40#define EECONFIG_HANDEDNESS (uint8_t *)14
41#define EECONFIG_KEYBOARD (uint32_t *)15 41#define EECONFIG_KEYBOARD (uint32_t *)15
42#define EECONFIG_USER (uint32_t *)19 42#define EECONFIG_USER (uint32_t *)19
43#define EECONFIG_VELOCIKEY (uint8_t *)23 43#define EECONFIG_VELOCIKEY (uint8_t *)23
44 44
45#define EECONFIG_HAPTIC (uint32_t*)24 45#define EECONFIG_HAPTIC (uint32_t *)24
46#define EECONFIG_RGB_MATRIX (uint32_t *)28
47#define EECONFIG_RGB_MATRIX_SPEED (uint8_t *)32
46 48
47/* debug bit */ 49/* debug bit */
48#define EECONFIG_DEBUG_ENABLE (1<<0) 50#define EECONFIG_DEBUG_ENABLE (1<<0)
diff --git a/users/xulkal/process_records.c b/users/xulkal/process_records.c
index 115623caa..2c5d2a4e7 100644
--- a/users/xulkal/process_records.c
+++ b/users/xulkal/process_records.c
@@ -2,10 +2,6 @@
2#include "custom_keycodes.h" 2#include "custom_keycodes.h"
3#include "timer_utils.h" 3#include "timer_utils.h"
4 4
5#if defined(RGB_MATRIX_ENABLE)
6extern void eeconfig_update_rgb_matrix_default(void);
7#endif
8
9#ifdef TRILAYER_ENABLED 5#ifdef TRILAYER_ENABLED
10uint32_t layer_state_set_user(uint32_t state) 6uint32_t layer_state_set_user(uint32_t state)
11{ 7{