summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--keyboards/anavi/macropad8/keyboard.json2
-rw-r--r--platforms/suspend.c35
-rw-r--r--platforms/suspend.h4
-rw-r--r--quantum/keyboard.c8
-rw-r--r--tmk_core/protocol/chibios/chibios.c3
-rw-r--r--tmk_core/protocol/lufa/lufa.c3
-rw-r--r--tmk_core/protocol/vusb/protocol.c3
7 files changed, 50 insertions, 8 deletions
diff --git a/keyboards/anavi/macropad8/keyboard.json b/keyboards/anavi/macropad8/keyboard.json
index 8073a038a2..2fb24e58bb 100644
--- a/keyboards/anavi/macropad8/keyboard.json
+++ b/keyboards/anavi/macropad8/keyboard.json
@@ -20,10 +20,8 @@
20 "breathing": true, 20 "breathing": true,
21 "rainbow_mood": true, 21 "rainbow_mood": true,
22 "rainbow_swirl": true, 22 "rainbow_swirl": true,
23 "snake": true,
24 "knight": true, 23 "knight": true,
25 "static_gradient": true, 24 "static_gradient": true,
26 "rgb_test": true,
27 "alternating": true, 25 "alternating": true,
28 "twinkle": true 26 "twinkle": true
29 } 27 }
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
7extern matrix_row_t matrix_previous[MATRIX_ROWS];
8static 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
60void 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
72bool keypress_is_wakeup_key(uint8_t row, uint8_t col) {
73 return (wakeup_matrix[row] & ((matrix_row_t)1 << col));
74}
75
76void 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);
14void suspend_power_down_kb(void); 14void suspend_power_down_kb(void);
15void suspend_power_down_quantum(void); 15void suspend_power_down_quantum(void);
16 16
17bool keypress_is_wakeup_key(uint8_t row, uint8_t col);
18void update_matrix_state_after_wakeup(void);
19void 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
diff --git a/quantum/keyboard.c b/quantum/keyboard.c
index ce8c8efa68..e0c9373165 100644
--- a/quantum/keyboard.c
+++ b/quantum/keyboard.c
@@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
33#include "sendchar.h" 33#include "sendchar.h"
34#include "eeconfig.h" 34#include "eeconfig.h"
35#include "action_layer.h" 35#include "action_layer.h"
36#include "suspend.h"
36#ifdef BOOTMAGIC_ENABLE 37#ifdef BOOTMAGIC_ENABLE
37# include "bootmagic.h" 38# include "bootmagic.h"
38#endif 39#endif
@@ -563,6 +564,7 @@ void switch_events(uint8_t row, uint8_t col, bool pressed) {
563#if defined(RGB_MATRIX_ENABLE) 564#if defined(RGB_MATRIX_ENABLE)
564 rgb_matrix_handle_key_event(row, col, pressed); 565 rgb_matrix_handle_key_event(row, col, pressed);
565#endif 566#endif
567 wakeup_matrix_handle_key_event(row, col, pressed);
566} 568}
567 569
568/** 570/**
@@ -578,6 +580,8 @@ static inline void generate_tick_event(void) {
578 } 580 }
579} 581}
580 582
583matrix_row_t matrix_previous[MATRIX_ROWS];
584
581/** 585/**
582 * @brief This task scans the keyboards matrix and processes any key presses 586 * @brief This task scans the keyboards matrix and processes any key presses
583 * that occur. 587 * that occur.
@@ -591,8 +595,6 @@ static bool matrix_task(void) {
591 return false; 595 return false;
592 } 596 }
593 597
594 static matrix_row_t matrix_previous[MATRIX_ROWS];
595
596 matrix_scan(); 598 matrix_scan();
597 bool matrix_changed = false; 599 bool matrix_changed = false;
598 for (uint8_t row = 0; row < MATRIX_ROWS && !matrix_changed; row++) { 600 for (uint8_t row = 0; row < MATRIX_ROWS && !matrix_changed; row++) {
@@ -626,7 +628,7 @@ static bool matrix_task(void) {
626 if (row_changes & col_mask) { 628 if (row_changes & col_mask) {
627 const bool key_pressed = current_row & col_mask; 629 const bool key_pressed = current_row & col_mask;
628 630
629 if (process_keypress) { 631 if (process_keypress && !keypress_is_wakeup_key(row, col)) {
630 action_exec(MAKE_KEYEVENT(row, col, key_pressed)); 632 action_exec(MAKE_KEYEVENT(row, col, key_pressed));
631 } 633 }
632 634
diff --git a/tmk_core/protocol/chibios/chibios.c b/tmk_core/protocol/chibios/chibios.c
index 5720bc3c4c..b8cded99fc 100644
--- a/tmk_core/protocol/chibios/chibios.c
+++ b/tmk_core/protocol/chibios/chibios.c
@@ -191,6 +191,9 @@ void protocol_pre_task(void) {
191 // 191 //
192 // Pause for a while to let things settle... 192 // Pause for a while to let things settle...
193 wait_ms(USB_SUSPEND_WAKEUP_DELAY); 193 wait_ms(USB_SUSPEND_WAKEUP_DELAY);
194 // ...and then update the wakeup matrix again as the waking key
195 // might have been released during the delay
196 update_matrix_state_after_wakeup();
194# endif 197# endif
195 } 198 }
196 } 199 }
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c
index e13f4b548e..3e442ba033 100644
--- a/tmk_core/protocol/lufa/lufa.c
+++ b/tmk_core/protocol/lufa/lufa.c
@@ -826,6 +826,9 @@ void protocol_pre_task(void) {
826 // 826 //
827 // Pause for a while to let things settle... 827 // Pause for a while to let things settle...
828 wait_ms(USB_SUSPEND_WAKEUP_DELAY); 828 wait_ms(USB_SUSPEND_WAKEUP_DELAY);
829 // ...and then update the wakeup matrix again as the waking key
830 // might have been released during the delay
831 update_matrix_state_after_wakeup();
829# endif 832# endif
830 } 833 }
831 } 834 }
diff --git a/tmk_core/protocol/vusb/protocol.c b/tmk_core/protocol/vusb/protocol.c
index e2d0c4112e..b95750306a 100644
--- a/tmk_core/protocol/vusb/protocol.c
+++ b/tmk_core/protocol/vusb/protocol.c
@@ -125,6 +125,9 @@ void protocol_pre_task(void) {
125 // 125 //
126 // Pause for a while to let things settle... 126 // Pause for a while to let things settle...
127 wait_ms(USB_SUSPEND_WAKEUP_DELAY); 127 wait_ms(USB_SUSPEND_WAKEUP_DELAY);
128 // ...and then update the wakeup matrix again as the waking key
129 // might have been released during the delay
130 update_matrix_state_after_wakeup();
128# endif 131# endif
129 } 132 }
130 } 133 }