Skip to content

Commit b35caf0

Browse files
committed
Updated RGB Matrix to respond to electrical events instead of key events
1 parent 09ced83 commit b35caf0

File tree

7 files changed

+54
-45
lines changed

7 files changed

+54
-45
lines changed

docs/ja/understanding_qmk.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
147147
* [`bool process_haptic(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/2cee371bf125a6ec541dd7c5a809573facc7c456/drivers/haptic/haptic.c#L216)
148148
* [`bool process_record_kb(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/keyboards/clueboard/card/card.c#L20)
149149
* [`bool process_record_user(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/keyboards/clueboard/card/keymaps/default/keymap.c#L58)
150-
* [`bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/rgb_matrix.c#L139)
151150
* [`bool process_midi(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_midi.c#L81)
152151
* [`bool process_audio(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_audio.c#L19)
153152
* [`bool process_steno(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_steno.c#L160)

docs/understanding_qmk.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ The `process_record()` function itself is deceptively simple, but hidden within
142142
* [`bool process_haptic(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/2cee371bf125a6ec541dd7c5a809573facc7c456/drivers/haptic/haptic.c#L216)
143143
* [`bool process_record_kb(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/keyboards/clueboard/card/card.c#L20)
144144
* [`bool process_record_user(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/keyboards/clueboard/card/keymaps/default/keymap.c#L58)
145-
* [`bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/rgb_matrix.c#L139)
146145
* [`bool process_midi(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_midi.c#L81)
147146
* [`bool process_audio(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_audio.c#L19)
148147
* [`bool process_steno(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_steno.c#L160)

quantum/quantum.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ bool process_record_quantum(keyrecord_t *record) {
225225
#ifdef HAPTIC_ENABLE
226226
process_haptic(keycode, record) &&
227227
#endif // HAPTIC_ENABLE
228-
#if defined(RGB_MATRIX_ENABLE)
229-
process_rgb_matrix(keycode, record) &&
230-
#endif
231228
#if defined(VIA_ENABLE)
232229
process_record_via(keycode, record) &&
233230
#endif
@@ -639,9 +636,6 @@ void matrix_init_quantum() {
639636
#ifdef AUDIO_ENABLE
640637
audio_init();
641638
#endif
642-
#ifdef RGB_MATRIX_ENABLE
643-
rgb_matrix_init();
644-
#endif
645639
#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
646640
unicode_input_mode_init();
647641
#endif
@@ -696,10 +690,6 @@ void matrix_scan_quantum() {
696690
led_matrix_task();
697691
#endif
698692

699-
#ifdef RGB_MATRIX_ENABLE
700-
rgb_matrix_task();
701-
#endif
702-
703693
#ifdef WPM_ENABLE
704694
decay_wpm();
705695
#endif

quantum/rgb_matrix.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,24 +184,25 @@ void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {
184184

185185
void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { rgb_matrix_driver.set_color_all(red, green, blue); }
186186

187-
bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
187+
void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
188+
#ifndef RGB_MATRIX_SPLIT
189+
if (!is_keyboard_master()) return;
190+
#endif
188191
#if RGB_DISABLE_TIMEOUT > 0
189-
if (record->event.pressed) {
190-
rgb_anykey_timer = 0;
191-
}
192+
rgb_anykey_timer = 0;
192193
#endif // RGB_DISABLE_TIMEOUT > 0
193194

194195
#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
195196
uint8_t led[LED_HITS_TO_REMEMBER];
196197
uint8_t led_count = 0;
197198

198199
# if defined(RGB_MATRIX_KEYRELEASES)
199-
if (!record->event.pressed)
200+
if (!pressed)
200201
# elif defined(RGB_MATRIX_KEYPRESSES)
201-
if (record->event.pressed)
202+
if (pressed)
202203
# endif // defined(RGB_MATRIX_KEYRELEASES)
203204
{
204-
led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
205+
led_count = rgb_matrix_map_row_column_to_led(row, col, led);
205206
}
206207

207208
if (last_hit_buffer.count + led_count > LED_HITS_TO_REMEMBER) {
@@ -224,11 +225,9 @@ bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
224225

225226
#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
226227
if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) {
227-
process_rgb_matrix_typing_heatmap(record);
228+
process_rgb_matrix_typing_heatmap(row, col);
228229
}
229230
#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
230-
231-
return true;
232231
}
233232

234233
void rgb_matrix_test(void) {

quantum/rgb_matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
9898
void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
9999
void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue);
100100

101-
bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record);
101+
void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed);
102102

103103
void rgb_matrix_task(void);
104104

quantum/rgb_matrix_animations/typing_heatmap_anim.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ RGB_MATRIX_EFFECT(TYPING_HEATMAP)
66
# define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 25
77
# endif
88

9-
void process_rgb_matrix_typing_heatmap(keyrecord_t* record) {
10-
uint8_t row = record->event.key.row;
11-
uint8_t col = record->event.key.col;
9+
void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) {
1210
uint8_t m_row = row - 1;
1311
uint8_t p_row = row + 1;
1412
uint8_t m_col = col - 1;

tmk_core/common/keyboard.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5454
#ifdef RGBLIGHT_ENABLE
5555
# include "rgblight.h"
5656
#endif
57+
#ifdef RGB_MATRIX_ENABLE
58+
# include "rgb_matrix.h"
59+
#endif
5760
#ifdef ENCODER_ENABLE
5861
# include "encoder.h"
5962
#endif
@@ -306,6 +309,9 @@ void keyboard_init(void) {
306309
#ifdef RGBLIGHT_ENABLE
307310
rgblight_init();
308311
#endif
312+
#ifdef RGB_MATRIX_ENABLE
313+
rgb_matrix_init();
314+
#endif
309315
#ifdef ENCODER_ENABLE
310316
encoder_init();
311317
#endif
@@ -333,6 +339,17 @@ void keyboard_init(void) {
333339
keyboard_post_init_kb(); /* Always keep this last */
334340
}
335341

342+
/** \brief key_event_task
343+
*
344+
* This function is responsible for calling into other systems when they need to respond to electrical switch press events.
345+
* This is differnet than keycode events as no layer processing, or filtering occurs.
346+
*/
347+
void switch_events(uint8_t row, uint8_t col, bool pressed) {
348+
#if defined(RGB_MATRIX_ENABLE)
349+
process_rgb_matrix(row, col, pressed);
350+
#endif
351+
}
352+
336353
/** \brief Keyboard task: Do keyboard routine jobs
337354
*
338355
* Do routine keyboard jobs:
@@ -363,32 +380,35 @@ void keyboard_task(void) {
363380
uint8_t matrix_changed = matrix_scan();
364381
if (matrix_changed) last_matrix_activity_trigger();
365382

366-
if (should_process_keypress()) {
367-
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
368-
matrix_row = matrix_get_row(r);
369-
matrix_change = matrix_row ^ matrix_prev[r];
370-
if (matrix_change) {
383+
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
384+
matrix_row = matrix_get_row(r);
385+
matrix_change = matrix_row ^ matrix_prev[r];
386+
if (matrix_change) {
371387
#ifdef MATRIX_HAS_GHOST
372-
if (has_ghost_in_row(r, matrix_row)) {
373-
continue;
374-
}
388+
if (has_ghost_in_row(r, matrix_row)) {
389+
continue;
390+
}
375391
#endif
376-
if (debug_matrix) matrix_print();
377-
matrix_row_t col_mask = 1;
378-
for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) {
379-
if (matrix_change & col_mask) {
392+
if (debug_matrix) matrix_print();
393+
matrix_row_t col_mask = 1;
394+
for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) {
395+
if (matrix_change & col_mask) {
396+
if (should_process_keypress()) {
380397
action_exec((keyevent_t){
381398
.key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & col_mask), .time = (timer_read() | 1) /* time should not be 0 */
382399
});
383-
// record a processed key
384-
matrix_prev[r] ^= col_mask;
400+
}
401+
// record a processed key
402+
matrix_prev[r] ^= col_mask;
403+
404+
switch_events(r, c, (matrix_row & col_mask));
405+
385406
#ifdef QMK_KEYS_PER_SCAN
386-
// only jump out if we have processed "enough" keys.
387-
if (++keys_processed >= QMK_KEYS_PER_SCAN)
407+
// only jump out if we have processed "enough" keys.
408+
if (++keys_processed >= QMK_KEYS_PER_SCAN)
388409
#endif
389-
// process a key per task call
390-
goto MATRIX_LOOP_END;
391-
}
410+
// process a key per task call
411+
goto MATRIX_LOOP_END;
392412
}
393413
}
394414
}
@@ -410,6 +430,10 @@ void keyboard_task(void) {
410430
rgblight_task();
411431
#endif
412432

433+
#ifdef RGB_MATRIX_ENABLE
434+
rgb_matrix_task();
435+
#endif
436+
413437
#if defined(BACKLIGHT_ENABLE)
414438
# if defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)
415439
backlight_task();

0 commit comments

Comments
 (0)