From 0ccb8079aec3a9bd7609776be1c9529556e970f1 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Tue, 2 Jan 2024 18:56:37 -0700 Subject: [PATCH] kbscan: Do not read matrix if lid is closed Pull the lid check out to the loop to avoid accessing the matrix when we know we do not need the data. It is left in kbscan (instead of simply disabling reading) to clear the state of the matrix data. The lid check for wake is removed as it will never be true. Signed-off-by: Tim Crawford --- src/board/system76/common/kbscan.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/board/system76/common/kbscan.c b/src/board/system76/common/kbscan.c index 272289c..8b6a066 100644 --- a/src/board/system76/common/kbscan.c +++ b/src/board/system76/common/kbscan.c @@ -81,11 +81,6 @@ void kbscan_init(void) { // Read the state of the row for the selected column. static inline uint8_t kbscan_get_row(void) { - // Report all keys as released when lid is closed - if (!lid_state) { - return 0; - } - // Invert KSI for positive logic of pressed keys. return ~KSI; } @@ -160,7 +155,7 @@ static void hardware_hotkey(uint16_t key) { bool kbscan_press(uint16_t key, bool pressed, uint8_t *layer) { // Wake from sleep on keypress - if (pressed && lid_state && (power_state == POWER_STATE_S3)) { + if (pressed && (power_state == POWER_STATE_S3)) { pmc_swi(); } @@ -308,8 +303,13 @@ void kbscan_event(void) { // Read the current state of the hardware matrix for (uint8_t i = 0; i < KM_OUT; i++) { - kbscan_set_column(i); - matrix_curr[i] = kbscan_get_row(); + if (!lid_state) { + // Report all keys as released when lid is closed + matrix_curr[i] = 0; + } else { + kbscan_set_column(i); + matrix_curr[i] = kbscan_get_row(); + } } kbscan_disable_reading();