Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: allow locking the matrix state #18852

Merged
merged 9 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 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_can_read
*
* Allows overriding when matrix scanning operations should be executed.
*/
__attribute__((weak)) bool matrix_can_read(void) {
return true;
}

/** \brief keyboard_setup
*
* FIXME: needs doc
Expand Down Expand Up @@ -449,10 +457,14 @@ static inline void generate_tick_event(void) {
* @return false Matrix didn't change
*/
static bool matrix_task(void) {
if (!matrix_can_read()) {
generate_tick_event();
return false;
}

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 @@ -46,6 +46,8 @@ void matrix_setup(void);
void matrix_init(void);
/* scan all key states on matrix */
uint8_t matrix_scan(void);
/* whether matrix scanning operations should be executed */
bool matrix_can_read(void);
/* whether a switch is on */
bool matrix_is_on(uint8_t row, uint8_t col);
/* matrix state on row */
Expand Down