aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--converter/adb_usb/matrix.c69
-rw-r--r--protocol/adb.h5
2 files changed, 40 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
47static bool _matrix_is_modified = false; 44static 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)
51static uint8_t *matrix; 48static uint8_t matrix[MATRIX_ROWS];
52static uint8_t _matrix0[MATRIX_ROWS];
53#else 49#else
54static uint16_t *matrix; 50static uint16_t matrix[MATRIX_ROWS];
55static uint16_t _matrix0[MATRIX_ROWS];
56#endif 51#endif
57 52
58#ifdef MATRIX_HAS_GHOST 53#ifdef MATRIX_HAS_GHOST
59static bool matrix_has_ghost_in_row(uint8_t row); 54static bool matrix_has_ghost_in_row(uint8_t row);
60#endif 55#endif
61static void _register_key(uint8_t key); 56static void register_key(uint8_t key);
62 57
63 58
64inline 59inline
@@ -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
145bool matrix_is_modified(void) 144bool matrix_is_modified(void)
146{ 145{
147 return _matrix_is_modified; 146 return is_modified;
148} 147}
149 148
150inline 149inline
@@ -177,6 +176,7 @@ uint16_t matrix_get_row(uint8_t row)
177 176
178void matrix_print(void) 177void 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
231inline 231inline
232static void _register_key(uint8_t key) 232static 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}
diff --git a/protocol/adb.h b/protocol/adb.h
index 177f41394..1e4ca4013 100644
--- a/protocol/adb.h
+++ b/protocol/adb.h
@@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE.
38#ifndef ADB_H 38#ifndef ADB_H
39#define ADB_H 39#define ADB_H
40 40
41#include <stdint.h>
41#include <stdbool.h> 42#include <stdbool.h>
42 43
43#if !(defined(ADB_PORT) && \ 44#if !(defined(ADB_PORT) && \
@@ -47,6 +48,10 @@ POSSIBILITY OF SUCH DAMAGE.
47# error "ADB port setting is required in config.h" 48# error "ADB port setting is required in config.h"
48#endif 49#endif
49 50
51#define ADB_POWER 0x7F
52#define ADB_CAPS 0x39
53
54
50// ADB host 55// ADB host
51void adb_host_init(void); 56void adb_host_init(void);
52bool adb_host_psw(void); 57bool adb_host_psw(void);