Skip to content

Commit

Permalink
Merge remote-tracking branch 'dexter93/matrix_lock' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
dexter93 committed Nov 5, 2022
2 parents 27cbe2b + 25f91c7 commit c32f88b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ __attribute__((weak)) void keyboard_post_init_kb(void) {
keyboard_post_init_user();
}

/** \brief matrix_available
*
* Override this function if you have a condition where matrix tasks should not be available
*/
__attribute__((weak)) bool matrix_available(void) {
return true;
}

/** \brief keyboard_setup
*
* FIXME: needs doc
Expand Down Expand Up @@ -449,11 +457,17 @@ static inline void generate_tick_event(void) {
* @return false Matrix didn't change
*/
static bool matrix_task(void) {
bool matrix_changed = false;

if (!matrix_available()) {
generate_tick_event();
return matrix_changed;
}

static matrix_row_t matrix_previous[MATRIX_ROWS];

matrix_scan();

bool matrix_changed = false;
for (uint8_t row = 0; row < MATRIX_ROWS && !matrix_changed; row++) {
matrix_changed |= matrix_previous[row] ^ matrix_get_row(row);
}
Expand Down
2 changes: 2 additions & 0 deletions quantum/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
#endif
/* scan all key states on matrix */
uint8_t matrix_scan(void);
/* whether matrix tasks are available */
bool matrix_available(void);
/* whether a switch is on */
bool matrix_is_on(uint8_t row, uint8_t col);
/* matrix state on row */
Expand Down

0 comments on commit c32f88b

Please sign in to comment.