Skip to content

Commit

Permalink
suspend: update wake up matrix after wake up delay
Browse files Browse the repository at this point in the history
If USB_SUSPEND_WAKEUP_DELAY is set, the keyboard sleeps during wake up -
which can be up to multiple seconds. To not miss any key releases the
wake up matrix is updated with the current state of the matrix - only
resetting the keys that have been released.

Signed-off-by: Stefan Kerkmann <[email protected]>
  • Loading branch information
KarlK90 committed Oct 12, 2024
1 parent fe35558 commit 71521d7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions platforms/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ bool suspend_wakeup_condition(void) {
return wakeup;
}

void wakeup_matrix_update(void) {
matrix_power_up();
matrix_scan();
matrix_power_down();

for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
matrix_row_t matrix_row = matrix_get_row(row);
matrix_row_t col_mask = 1;
for (uint8_t col = 0; col < MATRIX_COLS; col++, col_mask <<= 1) {
wakeup_matrix_handle_key_event(row, col, matrix_row & col_mask);
}
}
}

bool keypress_is_wakeup_key(uint8_t row, uint8_t col) {
return (wakeup_matrix[row] & ((matrix_row_t)1 << col));
}
Expand Down
1 change: 1 addition & 0 deletions platforms/suspend.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ void suspend_power_down_kb(void);
void suspend_power_down_quantum(void);

bool keypress_is_wakeup_key(uint8_t row, uint8_t col);
void wakeup_matrix_update(void);
void wakeup_matrix_handle_key_event(uint8_t row, uint8_t col, bool pressed);

#ifndef USB_SUSPEND_WAKEUP_DELAY
Expand Down
3 changes: 3 additions & 0 deletions tmk_core/protocol/chibios/chibios.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ void protocol_pre_task(void) {
//
// Pause for a while to let things settle...
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
// ...and then update the wakeup matrix again as the waking key
// might have been released during the delay
wakeup_matrix_update();
# endif
}
}
Expand Down
3 changes: 3 additions & 0 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@ void protocol_pre_task(void) {
//
// Pause for a while to let things settle...
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
// ...and then update the wakeup matrix again as the waking key
// might have been released during the delay
wakeup_matrix_update();
# endif
}
}
Expand Down
3 changes: 3 additions & 0 deletions tmk_core/protocol/vusb/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ void protocol_pre_task(void) {
//
// Pause for a while to let things settle...
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
// ...and then update the wakeup matrix again as the waking key
// might have been released during the delay
wakeup_matrix_update();
# endif
}
}
Expand Down

0 comments on commit 71521d7

Please sign in to comment.