From 05795cb0034e885bec37f782cfc6bddcae262637 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 26 Nov 2014 11:25:45 +0900 Subject: Compensate timer during prower down --- keyboard/hhkb_rn42/matrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'keyboard/hhkb_rn42/matrix.c') diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c index c6c444ff52..513a271e4e 100644 --- a/keyboard/hhkb_rn42/matrix.c +++ b/keyboard/hhkb_rn42/matrix.c @@ -186,6 +186,6 @@ void matrix_power_down(void) { if (USB_DeviceState == DEVICE_STATE_Configured) return; if (timer_elapsed32(matrix_last_modified) <= MATRIX_POWER_SAVE) return; KEY_POWER_OFF(); - suspend_power_down(WDTO_15MS); + suspend_power_down(); matrix_power = false; } -- cgit v1.2.3 From 9179246a1d69024449829218aa7fb967d8ccc3f5 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 26 Nov 2014 11:42:53 +0900 Subject: Fix USB plug-in while BT mode falls to be enumerated --- keyboard/hhkb_rn42/matrix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'keyboard/hhkb_rn42/matrix.c') diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c index 513a271e4e..22becd1050 100644 --- a/keyboard/hhkb_rn42/matrix.c +++ b/keyboard/hhkb_rn42/matrix.c @@ -183,7 +183,7 @@ void matrix_power_up(void) { void matrix_power_down(void) { if (!matrix_power) return; // doesn't power save while USB connection is active - if (USB_DeviceState == DEVICE_STATE_Configured) return; + if (USB_DeviceState != DEVICE_STATE_Unattached) return; if (timer_elapsed32(matrix_last_modified) <= MATRIX_POWER_SAVE) return; KEY_POWER_OFF(); suspend_power_down(); -- cgit v1.2.3 From ebe437325872045e0b99469f83cb9e877e98112c Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 3 Dec 2014 15:50:02 +0900 Subject: Fix power saving while USB suspended - doesn't pwoer save while Bluetooth turns on --- keyboard/hhkb_rn42/matrix.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'keyboard/hhkb_rn42/matrix.c') diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c index 22becd1050..fb96997944 100644 --- a/keyboard/hhkb_rn42/matrix.c +++ b/keyboard/hhkb_rn42/matrix.c @@ -35,7 +35,6 @@ along with this program. If not, see . // matrix power saving #define MATRIX_POWER_SAVE 10000 static uint32_t matrix_last_modified = 0; -static bool matrix_power = true; // matrix state buffer(1:on, 0:off) static matrix_row_t *matrix; @@ -80,7 +79,8 @@ uint8_t matrix_scan(void) matrix_prev = matrix; matrix = tmp; - matrix_power_up(); + // 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); @@ -136,7 +136,14 @@ uint8_t matrix_scan(void) } if (matrix[row] ^ matrix_prev[row]) matrix_last_modified = timer_read32(); } - matrix_power_down(); + // 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(); + } return 1; } @@ -176,16 +183,8 @@ void matrix_print(void) } void matrix_power_up(void) { - if (matrix_power) return; KEY_POWER_ON(); - matrix_power = true; } void matrix_power_down(void) { - if (!matrix_power) return; - // doesn't power save while USB connection is active - if (USB_DeviceState != DEVICE_STATE_Unattached) return; - if (timer_elapsed32(matrix_last_modified) <= MATRIX_POWER_SAVE) return; KEY_POWER_OFF(); - suspend_power_down(); - matrix_power = false; } -- cgit v1.2.3 From 099701dd3130d433244b3a4102f36f547aec25ae Mon Sep 17 00:00:00 2001 From: tmk Date: Fri, 16 Jan 2015 10:21:18 +0900 Subject: hhkb: Integrate RN-42 support, remove hhkb_rn42 --- keyboard/hhkb_rn42/matrix.c | 190 -------------------------------------------- 1 file changed, 190 deletions(-) delete mode 100644 keyboard/hhkb_rn42/matrix.c (limited to 'keyboard/hhkb_rn42/matrix.c') diff --git a/keyboard/hhkb_rn42/matrix.c b/keyboard/hhkb_rn42/matrix.c deleted file mode 100644 index fb96997944..0000000000 --- a/keyboard/hhkb_rn42/matrix.c +++ /dev/null @@ -1,190 +0,0 @@ -/* -Copyright 2011 Jun Wako - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -/* - * scan matrix - */ -#include -#include -#include -#include "print.h" -#include "debug.h" -#include "util.h" -#include "timer.h" -#include "matrix.h" -#include "hhkb_avr.h" -#include -#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; -static matrix_row_t _matrix0[MATRIX_ROWS]; -static matrix_row_t _matrix1[MATRIX_ROWS]; - - -inline -uint8_t matrix_rows(void) -{ - return MATRIX_ROWS; -} - -inline -uint8_t matrix_cols(void) -{ - return MATRIX_COLS; -} - -void matrix_init(void) -{ -#ifdef DEBUG - debug_enable = true; - debug_keyboard = true; -#endif - - KEY_INIT(); - - // initialize matrix state: all keys off - for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; - for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix1[i] = 0x00; - matrix = _matrix0; - matrix_prev = _matrix1; -} - -uint8_t matrix_scan(void) -{ - uint8_t *tmp; - - tmp = matrix_prev; - matrix_prev = matrix; - matrix = tmp; - - // 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); - _delay_us(5); - - // Not sure this is needed. This just emulates HHKB controller's behaviour. - if (matrix_prev[row] & (1< 20/(1000000/TIMER_RAW_FREQ)) { - matrix[row] = matrix_prev[row]; - } - - _delay_us(5); - KEY_PREV_OFF(); - KEY_UNABLE(); - - // NOTE: KEY_STATE keep its state in 20us after KEY_ENABLE. - // 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(); - } - return 1; -} - -bool matrix_is_modified(void) -{ - for (uint8_t i = 0; i < MATRIX_ROWS; i++) { - if (matrix[i] != matrix_prev[i]) - return true; - } - return false; -} - -inline -bool matrix_has_ghost(void) -{ - return false; -} - -inline -bool matrix_is_on(uint8_t row, uint8_t col) -{ - return (matrix[row] & (1<