From 3da2111df6439ddf106a3b64ac6be5677dde9fbc Mon Sep 17 00:00:00 2001 From: Stefan Kerkmann Date: Mon, 1 Apr 2024 14:16:29 +0200 Subject: [PATCH] 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 --- platforms/suspend.c | 20 ++++++++++++++++++-- platforms/suspend.h | 3 +++ quantum/keyboard.c | 4 +++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/platforms/suspend.c b/platforms/suspend.c index fea23cbd02b..0818a726ce1 100644 --- a/platforms/suspend.c +++ b/platforms/suspend.c @@ -4,6 +4,8 @@ #include "suspend.h" #include "matrix.h" +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 +46,22 @@ bool suspend_wakeup_condition(void) { matrix_power_up(); matrix_scan(); matrix_power_down(); + + bool wakeup = false; for (uint8_t r = 0; r < MATRIX_ROWS; r++) { - if (matrix_get_row(r)) return true; + wakeup_matrix[r] = matrix_get_row(r); + wakeup |= wakeup_matrix[r] != 0; + } + + return wakeup; +} + +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; } diff --git a/platforms/suspend.h b/platforms/suspend.h index e4f7f39ddb8..762bef12dbc 100644 --- a/platforms/suspend.h +++ b/platforms/suspend.h @@ -14,6 +14,9 @@ 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 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 diff --git a/quantum/keyboard.c b/quantum/keyboard.c index fccdaf29905..42087c75d38 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -32,6 +32,7 @@ along with this program. If not, see . #include "sendchar.h" #include "eeconfig.h" #include "action_layer.h" +#include "suspend.h" #ifdef BOOTMAGIC_ENABLE # include "bootmagic.h" #endif @@ -554,6 +555,7 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) { #if defined(RGB_MATRIX_ENABLE) rgb_matrix_handle_key_event(row, col, pressed); #endif + wakeup_matrix_handle_key_event(row, col, pressed); } /** @@ -617,7 +619,7 @@ static bool matrix_task(void) { if (row_changes & col_mask) { const bool key_pressed = current_row & col_mask; - if (process_keypress) { + if (process_keypress && !keypress_is_wakeup_key(row, col)) { action_exec(MAKE_KEYEVENT(row, col, key_pressed)); }