diff options
| author | tmk <nobody@nowhere> | 2012-09-20 12:52:45 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2012-09-20 12:52:45 +0900 |
| commit | d8ce19abd06ee9274cee883a379504eba9b470a5 (patch) | |
| tree | 6f0bde40a973af6e0f899cc3a0e4fab6d2ba63c1 /converter/adb_usb | |
| parent | dd0017558e8c582760d9eb0adb2c12a04765b4c5 (diff) | |
| download | qmk_firmware-d8ce19abd06ee9274cee883a379504eba9b470a5.tar.gz qmk_firmware-d8ce19abd06ee9274cee883a379504eba9b470a5.zip | |
To prevent key stuck clear matrix array when ADB error occurs.
Diffstat (limited to 'converter/adb_usb')
| -rw-r--r-- | converter/adb_usb/matrix.c | 69 |
1 files changed, 35 insertions, 34 deletions
diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c index 4d1b9e9aa..18e71aa49 100644 --- a/converter/adb_usb/matrix.c +++ b/converter/adb_usb/matrix.c | |||
| @@ -38,27 +38,22 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 38 | # error "MATRIX_ROWS must not exceed 255" | 38 | # error "MATRIX_ROWS must not exceed 255" |
| 39 | #endif | 39 | #endif |
| 40 | 40 | ||
| 41 | #define CAPS 0x39 | 41 | #define ADB_CAPS_UP (ADB_CAPS | 0x80) |
| 42 | #define CAPS_UP (CAPS | 0x80) | ||
| 43 | #define ROW(key) ((key)>>3&0x0F) | ||
| 44 | #define COL(key) ((key)&0x07) | ||
| 45 | 42 | ||
| 46 | 43 | ||
| 47 | static bool _matrix_is_modified = false; | 44 | static bool is_modified = false; |
| 48 | 45 | ||
| 49 | // matrix state buffer(1:on, 0:off) | 46 | // matrix state buffer(1:on, 0:off) |
| 50 | #if (MATRIX_COLS <= 8) | 47 | #if (MATRIX_COLS <= 8) |
| 51 | static uint8_t *matrix; | 48 | static uint8_t matrix[MATRIX_ROWS]; |
| 52 | static uint8_t _matrix0[MATRIX_ROWS]; | ||
| 53 | #else | 49 | #else |
| 54 | static uint16_t *matrix; | 50 | static uint16_t matrix[MATRIX_ROWS]; |
| 55 | static uint16_t _matrix0[MATRIX_ROWS]; | ||
| 56 | #endif | 51 | #endif |
| 57 | 52 | ||
| 58 | #ifdef MATRIX_HAS_GHOST | 53 | #ifdef MATRIX_HAS_GHOST |
| 59 | static bool matrix_has_ghost_in_row(uint8_t row); | 54 | static bool matrix_has_ghost_in_row(uint8_t row); |
| 60 | #endif | 55 | #endif |
| 61 | static void _register_key(uint8_t key); | 56 | static void register_key(uint8_t key); |
| 62 | 57 | ||
| 63 | 58 | ||
| 64 | inline | 59 | inline |
| @@ -78,8 +73,7 @@ void matrix_init(void) | |||
| 78 | adb_host_init(); | 73 | adb_host_init(); |
| 79 | 74 | ||
| 80 | // initialize matrix state: all keys off | 75 | // initialize matrix state: all keys off |
| 81 | for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00; | 76 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; |
| 82 | matrix = _matrix0; | ||
| 83 | 77 | ||
| 84 | print_enable = true; | 78 | print_enable = true; |
| 85 | debug_enable = true; | 79 | debug_enable = true; |
| @@ -95,48 +89,53 @@ uint8_t matrix_scan(void) | |||
| 95 | uint16_t codes; | 89 | uint16_t codes; |
| 96 | uint8_t key0, key1; | 90 | uint8_t key0, key1; |
| 97 | 91 | ||
| 98 | _matrix_is_modified = false; | 92 | is_modified = false; |
| 99 | codes = adb_host_kbd_recv(); | 93 | codes = adb_host_kbd_recv(); |
| 100 | key0 = codes>>8; | 94 | key0 = codes>>8; |
| 101 | key1 = codes&0xFF; | 95 | key1 = codes&0xFF; |
| 102 | 96 | ||
| 103 | if (debug_enable && codes) { | 97 | if (debug_matrix && codes) { |
| 104 | print("adb_host_kbd_recv: "); phex16(codes); print("\n"); | 98 | print("adb_host_kbd_recv: "); phex16(codes); print("\n"); |
| 105 | } | 99 | } |
| 106 | 100 | ||
| 107 | #ifdef MATRIX_HAS_LOCKING_CAPS | 101 | #ifdef MATRIX_HAS_LOCKING_CAPS |
| 108 | // Send Caps key up event | 102 | // Send Caps key up event |
| 109 | if (matrix_is_on(ROW(CAPS), COL(CAPS))) { | 103 | if (matrix_is_on(MATRIX_ROW(ADB_CAPS), MATRIX_COL(ADB_CAPS))) { |
| 110 | _matrix_is_modified = true; | 104 | register_key(ADB_CAPS_UP); |
| 111 | _register_key(CAPS_UP); | ||
| 112 | } | 105 | } |
| 113 | #endif | 106 | #endif |
| 114 | if (codes == 0) { // no keys | 107 | if (codes == 0) { // no keys |
| 115 | return 0; | 108 | return 0; |
| 116 | } else if (key0 == 0xFF && key1 != 0xFF) { // error | 109 | } else if (codes == 0x7F7F) { // power key press |
| 117 | return codes&0xFF; | 110 | register_key(0x7F); |
| 111 | } else if (codes == 0xFFFF) { // power key release | ||
| 112 | register_key(0xFF); | ||
| 113 | } else if (key0 == 0xFF) { // error | ||
| 114 | if (debug_matrix) print("adb_host_kbd_recv: ERROR(matrix cleared.)\n"); | ||
| 115 | // clear matrix to unregister all keys | ||
| 116 | for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00; | ||
| 117 | return key1; | ||
| 118 | } else { | 118 | } else { |
| 119 | #ifdef MATRIX_HAS_LOCKING_CAPS | 119 | #ifdef MATRIX_HAS_LOCKING_CAPS |
| 120 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { | 120 | if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) { |
| 121 | // Ignore LockingCaps key down event when CAPS LOCK is on | 121 | // Ignore LockingCaps key down event when CAPS LOCK is on |
| 122 | if (key0 == CAPS && (key1 == CAPS || key1 == 0xFF)) return 0; | 122 | if (key0 == ADB_CAPS && (key1 == ADB_CAPS || key1 == 0xFF)) return 0; |
| 123 | if (key0 == CAPS) key0 = key1; | 123 | if (key0 == ADB_CAPS) key0 = key1; |
| 124 | if (key1 == CAPS) key1 = 0xFF; | 124 | if (key1 == ADB_CAPS) key1 = 0xFF; |
| 125 | // Convert LockingCaps key up event into down event | 125 | // Convert LockingCaps key up event into down event |
| 126 | if (key0 == CAPS_UP) key0 = CAPS; | 126 | if (key0 == ADB_CAPS_UP) key0 = ADB_CAPS; |
| 127 | if (key1 == CAPS_UP) key1 = CAPS; | 127 | if (key1 == ADB_CAPS_UP) key1 = ADB_CAPS; |
| 128 | } else { | 128 | } else { |
| 129 | // CAPS LOCK off: | 129 | // ADB_CAPS LOCK off: |
| 130 | // Ignore LockingCaps key up event when CAPS LOCK is off | 130 | // Ignore LockingCaps key up event when ADB_CAPS LOCK is off |
| 131 | if (key0 == CAPS_UP && (key1 == CAPS_UP || key1 == 0xFF)) return 0; | 131 | if (key0 == ADB_CAPS_UP && (key1 == ADB_CAPS_UP || key1 == 0xFF)) return 0; |
| 132 | if (key0 == CAPS_UP) key0 = key1; | 132 | if (key0 == ADB_CAPS_UP) key0 = key1; |
| 133 | if (key1 == CAPS_UP) key1 = 0xFF; | 133 | if (key1 == ADB_CAPS_UP) key1 = 0xFF; |
| 134 | } | 134 | } |
| 135 | #endif | 135 | #endif |
| 136 | _matrix_is_modified = true; | 136 | register_key(key0); |
| 137 | _register_key(key0); | ||
| 138 | if (key1 != 0xFF) // key1 is 0xFF when no second key. | 137 | if (key1 != 0xFF) // key1 is 0xFF when no second key. |
| 139 | _register_key(key1); | 138 | register_key(key1); |
| 140 | } | 139 | } |
| 141 | 140 | ||
| 142 | return 1; | 141 | return 1; |
| @@ -144,7 +143,7 @@ uint8_t matrix_scan(void) | |||
| 144 | 143 | ||
| 145 | bool matrix_is_modified(void) | 144 | bool matrix_is_modified(void) |
| 146 | { | 145 | { |
| 147 | return _matrix_is_modified; | 146 | return is_modified; |
| 148 | } | 147 | } |
| 149 | 148 | ||
| 150 | inline | 149 | inline |
| @@ -177,6 +176,7 @@ uint16_t matrix_get_row(uint8_t row) | |||
| 177 | 176 | ||
| 178 | void matrix_print(void) | 177 | void matrix_print(void) |
| 179 | { | 178 | { |
| 179 | if (!debug_matrix) return; | ||
| 180 | #if (MATRIX_COLS <= 8) | 180 | #if (MATRIX_COLS <= 8) |
| 181 | print("r/c 01234567\n"); | 181 | print("r/c 01234567\n"); |
| 182 | #else | 182 | #else |
| @@ -229,7 +229,7 @@ static bool matrix_has_ghost_in_row(uint8_t row) | |||
| 229 | #endif | 229 | #endif |
| 230 | 230 | ||
| 231 | inline | 231 | inline |
| 232 | static void _register_key(uint8_t key) | 232 | static void register_key(uint8_t key) |
| 233 | { | 233 | { |
| 234 | uint8_t col, row; | 234 | uint8_t col, row; |
| 235 | col = key&0x07; | 235 | col = key&0x07; |
| @@ -239,4 +239,5 @@ static void _register_key(uint8_t key) | |||
| 239 | } else { | 239 | } else { |
| 240 | matrix[row] |= (1<<col); | 240 | matrix[row] |= (1<<col); |
| 241 | } | 241 | } |
| 242 | is_modified = true; | ||
| 242 | } | 243 | } |
