[Core] suspend: suppress wake up keypress (#23389)
* suspend: suppress wake up keypress Waking the host from suspend is done by pressing any key on the keyboard, the regular key codes assigned to the keys are not important and must not be sent - otherwise they usually end up in password prompts as ghost characters that have to be deleted again. This commit adds suppression for all keys pressed at the time of wake up. Once a key is released it functions as a regular key again. Signed-off-by: Stefan Kerkmann <karlk90@pm.me> * suspend: update wake up matrix after wake up delay If USB_SUSPEND_WAKEUP_DELAY is set, the keyboard sleeps during wake up - which can be up to multiple seconds. To handle key presses and releases in that time frame we have to handle the following cases: 1. Key not pressed before suspend, and not pressed after wakeup → do nothing (normal case). 2. Key not pressed before suspend, but pressed after wakeup → set the wakeup_matrix bit to 1 (so that the press and release events would be suppressed). 3. Key pressed before suspend, but not pressed after wakeup → do nothing (the release event will be generated on the first matrix_task() call after the wakeup). 4. Key pressed before suspend, and still pressed after wakeup → do nothing (the release event will be generated some time later). Signed-off-by: Stefan Kerkmann <karlk90@pm.me> Co-authored-by: Sergey Vlasov <sigprof@gmail.com> * keyboards: anavi: macropad8: disable snake and rgb_test effects ...to shrink the binary size.
This commit is contained in:
parent
1ddcf57382
commit
c68e4dec10
7 changed files with 50 additions and 8 deletions
|
|
@ -4,6 +4,9 @@
|
|||
#include "suspend.h"
|
||||
#include "matrix.h"
|
||||
|
||||
extern matrix_row_t matrix_previous[MATRIX_ROWS];
|
||||
static matrix_row_t wakeup_matrix[MATRIX_ROWS];
|
||||
|
||||
// TODO: Move to more correct location
|
||||
__attribute__((weak)) void matrix_power_up(void) {}
|
||||
__attribute__((weak)) void matrix_power_down(void) {}
|
||||
|
|
@ -44,8 +47,34 @@ bool suspend_wakeup_condition(void) {
|
|||
matrix_power_up();
|
||||
matrix_scan();
|
||||
matrix_power_down();
|
||||
for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
|
||||
if (matrix_get_row(r)) return true;
|
||||
|
||||
bool wakeup = false;
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
wakeup_matrix[row] = matrix_get_row(row);
|
||||
wakeup |= wakeup_matrix[row] != 0;
|
||||
}
|
||||
|
||||
return wakeup;
|
||||
}
|
||||
|
||||
void update_matrix_state_after_wakeup(void) {
|
||||
matrix_power_up();
|
||||
matrix_scan();
|
||||
matrix_power_down();
|
||||
|
||||
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||
const matrix_row_t current_row = matrix_get_row(row);
|
||||
wakeup_matrix[row] |= current_row & ~matrix_previous[row];
|
||||
matrix_previous[row] |= current_row;
|
||||
}
|
||||
}
|
||||
|
||||
bool keypress_is_wakeup_key(uint8_t row, uint8_t col) {
|
||||
return (wakeup_matrix[row] & ((matrix_row_t)1 << col));
|
||||
}
|
||||
|
||||
void wakeup_matrix_handle_key_event(uint8_t row, uint8_t col, bool pressed) {
|
||||
if (!pressed) {
|
||||
wakeup_matrix[row] &= ~((matrix_row_t)1 << col);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ void suspend_power_down_user(void);
|
|||
void suspend_power_down_kb(void);
|
||||
void suspend_power_down_quantum(void);
|
||||
|
||||
bool keypress_is_wakeup_key(uint8_t row, uint8_t col);
|
||||
void update_matrix_state_after_wakeup(void);
|
||||
void wakeup_matrix_handle_key_event(uint8_t row, uint8_t col, bool pressed);
|
||||
|
||||
#ifndef USB_SUSPEND_WAKEUP_DELAY
|
||||
# define USB_SUSPEND_WAKEUP_DELAY 0
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue