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] suspend: suppress wake up keypress #23389

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
34 changes: 32 additions & 2 deletions platforms/suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -44,8 +46,36 @@ 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;
}

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));
}

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;
}
4 changes: 4 additions & 0 deletions platforms/suspend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 wakeup_matrix_update(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
4 changes: 3 additions & 1 deletion quantum/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "sendchar.h"
#include "eeconfig.h"
#include "action_layer.h"
#include "suspend.h"
#ifdef BOOTMAGIC_ENABLE
# include "bootmagic.h"
#endif
Expand Down Expand Up @@ -505,6 +506,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);
}

/**
Expand Down Expand Up @@ -568,7 +570,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));
}

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