diff options
Diffstat (limited to 'platforms')
| -rw-r--r-- | platforms/suspend.c | 35 | ||||
| -rw-r--r-- | platforms/suspend.h | 4 |
2 files changed, 36 insertions, 3 deletions
diff --git a/platforms/suspend.c b/platforms/suspend.c index fea23cbd02..4756796ea4 100644 --- a/platforms/suspend.c +++ b/platforms/suspend.c | |||
| @@ -4,6 +4,9 @@ | |||
| 4 | #include "suspend.h" | 4 | #include "suspend.h" |
| 5 | #include "matrix.h" | 5 | #include "matrix.h" |
| 6 | 6 | ||
| 7 | extern matrix_row_t matrix_previous[MATRIX_ROWS]; | ||
| 8 | static matrix_row_t wakeup_matrix[MATRIX_ROWS]; | ||
| 9 | |||
| 7 | // TODO: Move to more correct location | 10 | // TODO: Move to more correct location |
| 8 | __attribute__((weak)) void matrix_power_up(void) {} | 11 | __attribute__((weak)) void matrix_power_up(void) {} |
| 9 | __attribute__((weak)) void matrix_power_down(void) {} | 12 | __attribute__((weak)) void matrix_power_down(void) {} |
| @@ -44,8 +47,34 @@ bool suspend_wakeup_condition(void) { | |||
| 44 | matrix_power_up(); | 47 | matrix_power_up(); |
| 45 | matrix_scan(); | 48 | matrix_scan(); |
| 46 | matrix_power_down(); | 49 | matrix_power_down(); |
| 47 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | 50 | |
| 48 | if (matrix_get_row(r)) return true; | 51 | bool wakeup = false; |
| 52 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 53 | wakeup_matrix[row] = matrix_get_row(row); | ||
| 54 | wakeup |= wakeup_matrix[row] != 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | return wakeup; | ||
| 58 | } | ||
| 59 | |||
| 60 | void update_matrix_state_after_wakeup(void) { | ||
| 61 | matrix_power_up(); | ||
| 62 | matrix_scan(); | ||
| 63 | matrix_power_down(); | ||
| 64 | |||
| 65 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 66 | const matrix_row_t current_row = matrix_get_row(row); | ||
| 67 | wakeup_matrix[row] |= current_row & ~matrix_previous[row]; | ||
| 68 | matrix_previous[row] |= current_row; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | bool keypress_is_wakeup_key(uint8_t row, uint8_t col) { | ||
| 73 | return (wakeup_matrix[row] & ((matrix_row_t)1 << col)); | ||
| 74 | } | ||
| 75 | |||
| 76 | void wakeup_matrix_handle_key_event(uint8_t row, uint8_t col, bool pressed) { | ||
| 77 | if (!pressed) { | ||
| 78 | wakeup_matrix[row] &= ~((matrix_row_t)1 << col); | ||
| 49 | } | 79 | } |
| 50 | return false; | ||
| 51 | } | 80 | } |
diff --git a/platforms/suspend.h b/platforms/suspend.h index e4f7f39ddb..3a7f51f9f0 100644 --- a/platforms/suspend.h +++ b/platforms/suspend.h | |||
| @@ -14,6 +14,10 @@ void suspend_power_down_user(void); | |||
| 14 | void suspend_power_down_kb(void); | 14 | void suspend_power_down_kb(void); |
| 15 | void suspend_power_down_quantum(void); | 15 | void suspend_power_down_quantum(void); |
| 16 | 16 | ||
| 17 | bool keypress_is_wakeup_key(uint8_t row, uint8_t col); | ||
| 18 | void update_matrix_state_after_wakeup(void); | ||
| 19 | void wakeup_matrix_handle_key_event(uint8_t row, uint8_t col, bool pressed); | ||
| 20 | |||
| 17 | #ifndef USB_SUSPEND_WAKEUP_DELAY | 21 | #ifndef USB_SUSPEND_WAKEUP_DELAY |
| 18 | # define USB_SUSPEND_WAKEUP_DELAY 0 | 22 | # define USB_SUSPEND_WAKEUP_DELAY 0 |
| 19 | #endif | 23 | #endif |
