diff options
author | tmk <hasu@tmk-kbd.com> | 2015-01-16 10:21:18 +0900 |
---|---|---|
committer | tmk <hasu@tmk-kbd.com> | 2015-01-16 10:21:18 +0900 |
commit | 099701dd3130d433244b3a4102f36f547aec25ae (patch) | |
tree | 3624044b5dede28f377e262f66d4f90963e0870d /keyboard/hhkb/matrix.c | |
parent | ce6698865046c2d5e5fae73a74323048036e7d44 (diff) |
hhkb: Integrate RN-42 support, remove hhkb_rn42
Diffstat (limited to 'keyboard/hhkb/matrix.c')
-rw-r--r-- | keyboard/hhkb/matrix.c | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/keyboard/hhkb/matrix.c b/keyboard/hhkb/matrix.c index b0af4baa52..fb96997944 100644 --- a/keyboard/hhkb/matrix.c +++ b/keyboard/hhkb/matrix.c @@ -27,8 +27,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #include "timer.h" #include "matrix.h" #include "hhkb_avr.h" +#include <avr/wdt.h> +#include "suspend.h" +#include "lufa.h" +// matrix power saving +#define MATRIX_POWER_SAVE 10000 +static uint32_t matrix_last_modified = 0; + // matrix state buffer(1:on, 0:off) static matrix_row_t *matrix; static matrix_row_t *matrix_prev; @@ -72,7 +79,8 @@ uint8_t matrix_scan(void) matrix_prev = matrix; matrix = tmp; - KEY_POWER_ON(); + // power on + if (!KEY_POWER_STATE()) KEY_POWER_ON(); for (uint8_t row = 0; row < MATRIX_ROWS; row++) { for (uint8_t col = 0; col < MATRIX_COLS; col++) { KEY_SELECT(row, col); @@ -126,8 +134,16 @@ uint8_t matrix_scan(void) // This takes 25us or more to make sure KEY_STATE returns to idle state. _delay_us(75); } + if (matrix[row] ^ matrix_prev[row]) matrix_last_modified = timer_read32(); + } + // power off + if (KEY_POWER_STATE() && + (USB_DeviceState == DEVICE_STATE_Suspended || + USB_DeviceState == DEVICE_STATE_Unattached ) && + timer_elapsed32(matrix_last_modified) > MATRIX_POWER_SAVE) { + KEY_POWER_OFF(); + suspend_power_down(); } - KEY_POWER_OFF(); return 1; } @@ -165,3 +181,10 @@ void matrix_print(void) xprintf("%02X: %08b\n", row, bitrev(matrix_get_row(row))); } } + +void matrix_power_up(void) { + KEY_POWER_ON(); +} +void matrix_power_down(void) { + KEY_POWER_OFF(); +} |