diff options
author | tmk <nobody@nowhere> | 2014-11-23 13:08:05 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2014-11-23 13:08:05 +0900 |
commit | 608ebe2686bdb3fdbd0426731cabdf6082c57b53 (patch) | |
tree | 15d306082db9d53bb9c890f62aeeaf4cdab49712 /common | |
parent | c2d830c07c823c48a17c214b093ec1bab989fb6a (diff) | |
download | qmk_firmware-608ebe2686bdb3fdbd0426731cabdf6082c57b53.tar.gz qmk_firmware-608ebe2686bdb3fdbd0426731cabdf6082c57b53.zip |
Matrix power saving
Diffstat (limited to 'common')
-rw-r--r-- | common/keyboard.c | 23 | ||||
-rw-r--r-- | common/keyboard.h | 3 | ||||
-rw-r--r-- | common/matrix.h | 5 |
3 files changed, 31 insertions, 0 deletions
diff --git a/common/keyboard.c b/common/keyboard.c index 9a809ff4a..dde91a296 100644 --- a/common/keyboard.c +++ b/common/keyboard.c | |||
@@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License | |||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | */ | 16 | */ |
17 | #include <stdint.h> | 17 | #include <stdint.h> |
18 | #include <util/delay.h> | ||
19 | #include <avr/wdt.h> | ||
18 | #include "keyboard.h" | 20 | #include "keyboard.h" |
19 | #include "matrix.h" | 21 | #include "matrix.h" |
20 | #include "keymap.h" | 22 | #include "keymap.h" |
@@ -30,12 +32,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
30 | #include "bootmagic.h" | 32 | #include "bootmagic.h" |
31 | #include "eeconfig.h" | 33 | #include "eeconfig.h" |
32 | #include "backlight.h" | 34 | #include "backlight.h" |
35 | #include "suspend.h" | ||
33 | #ifdef MOUSEKEY_ENABLE | 36 | #ifdef MOUSEKEY_ENABLE |
34 | # include "mousekey.h" | 37 | # include "mousekey.h" |
35 | #endif | 38 | #endif |
36 | #ifdef PS2_MOUSE_ENABLE | 39 | #ifdef PS2_MOUSE_ENABLE |
37 | # include "ps2_mouse.h" | 40 | # include "ps2_mouse.h" |
38 | #endif | 41 | #endif |
42 | #include "lufa.h" | ||
39 | 43 | ||
40 | 44 | ||
41 | #ifdef MATRIX_HAS_GHOST | 45 | #ifdef MATRIX_HAS_GHOST |
@@ -83,7 +87,25 @@ void keyboard_task(void) | |||
83 | static uint8_t led_status = 0; | 87 | static uint8_t led_status = 0; |
84 | matrix_row_t matrix_row = 0; | 88 | matrix_row_t matrix_row = 0; |
85 | matrix_row_t matrix_change = 0; | 89 | matrix_row_t matrix_change = 0; |
90 | static uint32_t last_key_time = 0; | ||
86 | 91 | ||
92 | /* | ||
93 | #define SLEEP_TIME_MS 10000 | ||
94 | // (USB_DeviceState == DEVICE_STATE_Suspended) { | ||
95 | //if (timer_elapsed32(last_key_time) > SLEEP_TIME_MS) { | ||
96 | // TODO: remove LUFA dependent code | ||
97 | if (!USB_IsInitialized && timer_elapsed32(last_key_time) > SLEEP_TIME_MS) { | ||
98 | matrix_power_down(); | ||
99 | // TODO: power down only when no USB connection | ||
100 | // Or it makes USB connection lost or suspended | ||
101 | suspend_power_down(WDTO_15MS); | ||
102 | matrix_power_up(); | ||
103 | } | ||
104 | else { | ||
105 | matrix_power_down(); | ||
106 | matrix_power_up(); | ||
107 | } | ||
108 | */ | ||
87 | matrix_scan(); | 109 | matrix_scan(); |
88 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { | 110 | for (uint8_t r = 0; r < MATRIX_ROWS; r++) { |
89 | matrix_row = matrix_get_row(r); | 111 | matrix_row = matrix_get_row(r); |
@@ -105,6 +127,7 @@ void keyboard_task(void) | |||
105 | }); | 127 | }); |
106 | // record a processed key | 128 | // record a processed key |
107 | matrix_prev[r] ^= ((matrix_row_t)1<<c); | 129 | matrix_prev[r] ^= ((matrix_row_t)1<<c); |
130 | last_key_time = timer_read32(); | ||
108 | // process a key per task call | 131 | // process a key per task call |
109 | goto MATRIX_LOOP_END; | 132 | goto MATRIX_LOOP_END; |
110 | } | 133 | } |
diff --git a/common/keyboard.h b/common/keyboard.h index 60f8a89d1..6442716fc 100644 --- a/common/keyboard.h +++ b/common/keyboard.h | |||
@@ -62,6 +62,9 @@ void keyboard_init(void); | |||
62 | void keyboard_task(void); | 62 | void keyboard_task(void); |
63 | void keyboard_set_leds(uint8_t leds); | 63 | void keyboard_set_leds(uint8_t leds); |
64 | 64 | ||
65 | __attribute__ ((weak)) void matrix_power_up(void) {} | ||
66 | __attribute__ ((weak)) void matrix_power_down(void) {} | ||
67 | |||
65 | #ifdef __cplusplus | 68 | #ifdef __cplusplus |
66 | } | 69 | } |
67 | #endif | 70 | #endif |
diff --git a/common/matrix.h b/common/matrix.h index d1d14a6ea..23fef78f7 100644 --- a/common/matrix.h +++ b/common/matrix.h | |||
@@ -53,4 +53,9 @@ matrix_row_t matrix_get_row(uint8_t row); | |||
53 | void matrix_print(void); | 53 | void matrix_print(void); |
54 | 54 | ||
55 | 55 | ||
56 | /* power control */ | ||
57 | void matrix_power_up(void); | ||
58 | void matrix_power_down(void); | ||
59 | |||
60 | |||
56 | #endif | 61 | #endif |