Skip to content

Commit

Permalink
Updated RGB Matrix to respond to electrical events instead of key events
Browse files Browse the repository at this point in the history
  • Loading branch information
XScorpion2 committed Feb 7, 2021
1 parent 09ced83 commit b35caf0
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 45 deletions.
1 change: 0 additions & 1 deletion docs/ja/understanding_qmk.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
* [`bool process_haptic(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/2cee371bf125a6ec541dd7c5a809573facc7c456/drivers/haptic/haptic.c#L216)
* [`bool process_record_kb(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/keyboards/clueboard/card/card.c#L20)
* [`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)
* [`bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/rgb_matrix.c#L139)
* [`bool process_midi(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_midi.c#L81)
* [`bool process_audio(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_audio.c#L19)
* [`bool process_steno(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_steno.c#L160)
Expand Down
1 change: 0 additions & 1 deletion docs/understanding_qmk.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ The `process_record()` function itself is deceptively simple, but hidden within
* [`bool process_haptic(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/2cee371bf125a6ec541dd7c5a809573facc7c456/drivers/haptic/haptic.c#L216)
* [`bool process_record_kb(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/keyboards/clueboard/card/card.c#L20)
* [`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)
* [`bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/rgb_matrix.c#L139)
* [`bool process_midi(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_midi.c#L81)
* [`bool process_audio(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_audio.c#L19)
* [`bool process_steno(uint16_t keycode, keyrecord_t *record)`](https://github.com/qmk/qmk_firmware/blob/e1203a222bb12ab9733916164a000ef3ac48da93/quantum/process_keycode/process_steno.c#L160)
Expand Down
10 changes: 0 additions & 10 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef HAPTIC_ENABLE
process_haptic(keycode, record) &&
#endif // HAPTIC_ENABLE
#if defined(RGB_MATRIX_ENABLE)
process_rgb_matrix(keycode, record) &&
#endif
#if defined(VIA_ENABLE)
process_record_via(keycode, record) &&
#endif
Expand Down Expand Up @@ -639,9 +636,6 @@ void matrix_init_quantum() {
#ifdef AUDIO_ENABLE
audio_init();
#endif
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_init();
#endif
#if defined(UNICODE_ENABLE) || defined(UNICODEMAP_ENABLE) || defined(UCIS_ENABLE)
unicode_input_mode_init();
#endif
Expand Down Expand Up @@ -696,10 +690,6 @@ void matrix_scan_quantum() {
led_matrix_task();
#endif

#ifdef RGB_MATRIX_ENABLE
rgb_matrix_task();
#endif

#ifdef WPM_ENABLE
decay_wpm();
#endif
Expand Down
19 changes: 9 additions & 10 deletions quantum/rgb_matrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,25 @@ void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) {

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

bool process_rgb_matrix(uint16_t keycode, keyrecord_t *record) {
void process_rgb_matrix(uint8_t row, uint8_t col, bool pressed) {
#ifndef RGB_MATRIX_SPLIT
if (!is_keyboard_master()) return;
#endif
#if RGB_DISABLE_TIMEOUT > 0
if (record->event.pressed) {
rgb_anykey_timer = 0;
}
rgb_anykey_timer = 0;
#endif // RGB_DISABLE_TIMEOUT > 0

#ifdef RGB_MATRIX_KEYREACTIVE_ENABLED
uint8_t led[LED_HITS_TO_REMEMBER];
uint8_t led_count = 0;

# if defined(RGB_MATRIX_KEYRELEASES)
if (!record->event.pressed)
if (!pressed)
# elif defined(RGB_MATRIX_KEYPRESSES)
if (record->event.pressed)
if (pressed)
# endif // defined(RGB_MATRIX_KEYRELEASES)
{
led_count = rgb_matrix_map_row_column_to_led(record->event.key.row, record->event.key.col, led);
led_count = rgb_matrix_map_row_column_to_led(row, col, led);
}

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

#if defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)
if (rgb_matrix_config.mode == RGB_MATRIX_TYPING_HEATMAP) {
process_rgb_matrix_typing_heatmap(record);
process_rgb_matrix_typing_heatmap(row, col);
}
#endif // defined(RGB_MATRIX_FRAMEBUFFER_EFFECTS) && !defined(DISABLE_RGB_MATRIX_TYPING_HEATMAP)

return true;
}

void rgb_matrix_test(void) {
Expand Down
2 changes: 1 addition & 1 deletion quantum/rgb_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ uint8_t rgb_matrix_map_row_column_to_led(uint8_t row, uint8_t column, uint8_t *l
void rgb_matrix_set_color(int index, uint8_t red, uint8_t green, uint8_t blue);
void rgb_matrix_set_color_all(uint8_t red, uint8_t green, uint8_t blue);

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

void rgb_matrix_task(void);

Expand Down
4 changes: 1 addition & 3 deletions quantum/rgb_matrix_animations/typing_heatmap_anim.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ RGB_MATRIX_EFFECT(TYPING_HEATMAP)
# define RGB_MATRIX_TYPING_HEATMAP_DECREASE_DELAY_MS 25
# endif

void process_rgb_matrix_typing_heatmap(keyrecord_t* record) {
uint8_t row = record->event.key.row;
uint8_t col = record->event.key.col;
void process_rgb_matrix_typing_heatmap(uint8_t row, uint8_t col) {
uint8_t m_row = row - 1;
uint8_t p_row = row + 1;
uint8_t m_col = col - 1;
Expand Down
62 changes: 43 additions & 19 deletions tmk_core/common/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef RGBLIGHT_ENABLE
# include "rgblight.h"
#endif
#ifdef RGB_MATRIX_ENABLE
# include "rgb_matrix.h"
#endif
#ifdef ENCODER_ENABLE
# include "encoder.h"
#endif
Expand Down Expand Up @@ -306,6 +309,9 @@ void keyboard_init(void) {
#ifdef RGBLIGHT_ENABLE
rgblight_init();
#endif
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_init();
#endif
#ifdef ENCODER_ENABLE
encoder_init();
#endif
Expand Down Expand Up @@ -333,6 +339,17 @@ void keyboard_init(void) {
keyboard_post_init_kb(); /* Always keep this last */
}

/** \brief key_event_task
*
* This function is responsible for calling into other systems when they need to respond to electrical switch press events.
* This is differnet than keycode events as no layer processing, or filtering occurs.
*/
void switch_events(uint8_t row, uint8_t col, bool pressed) {
#if defined(RGB_MATRIX_ENABLE)
process_rgb_matrix(row, col, pressed);
#endif
}

/** \brief Keyboard task: Do keyboard routine jobs
*
* Do routine keyboard jobs:
Expand Down Expand Up @@ -363,32 +380,35 @@ void keyboard_task(void) {
uint8_t matrix_changed = matrix_scan();
if (matrix_changed) last_matrix_activity_trigger();

if (should_process_keypress()) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
matrix_row = matrix_get_row(r);
matrix_change = matrix_row ^ matrix_prev[r];
if (matrix_change) {
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
matrix_row = matrix_get_row(r);
matrix_change = matrix_row ^ matrix_prev[r];
if (matrix_change) {
#ifdef MATRIX_HAS_GHOST
if (has_ghost_in_row(r, matrix_row)) {
continue;
}
if (has_ghost_in_row(r, matrix_row)) {
continue;
}
#endif
if (debug_matrix) matrix_print();
matrix_row_t col_mask = 1;
for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) {
if (matrix_change & col_mask) {
if (debug_matrix) matrix_print();
matrix_row_t col_mask = 1;
for (uint8_t c = 0; c < MATRIX_COLS; c++, col_mask <<= 1) {
if (matrix_change & col_mask) {
if (should_process_keypress()) {
action_exec((keyevent_t){
.key = (keypos_t){.row = r, .col = c}, .pressed = (matrix_row & col_mask), .time = (timer_read() | 1) /* time should not be 0 */
});
// record a processed key
matrix_prev[r] ^= col_mask;
}
// record a processed key
matrix_prev[r] ^= col_mask;

switch_events(r, c, (matrix_row & col_mask));

#ifdef QMK_KEYS_PER_SCAN
// only jump out if we have processed "enough" keys.
if (++keys_processed >= QMK_KEYS_PER_SCAN)
// only jump out if we have processed "enough" keys.
if (++keys_processed >= QMK_KEYS_PER_SCAN)
#endif
// process a key per task call
goto MATRIX_LOOP_END;
}
// process a key per task call
goto MATRIX_LOOP_END;
}
}
}
Expand All @@ -410,6 +430,10 @@ void keyboard_task(void) {
rgblight_task();
#endif

#ifdef RGB_MATRIX_ENABLE
rgb_matrix_task();
#endif

#if defined(BACKLIGHT_ENABLE)
# if defined(BACKLIGHT_PIN) || defined(BACKLIGHT_PINS)
backlight_task();
Expand Down

0 comments on commit b35caf0

Please sign in to comment.