X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=converter%2Fadb_usb%2Fmatrix.c;h=18e71aa49786aca2c06ce4d848995b87675d867f;hb=db024b6b1803eb752070422e7240b1ffe52d39f6;hp=a2367af56a52c74a461d35121c48d3900a062735;hpb=afb08462085132acf7a1962522952f7dbf064519;p=max%2Ftmk_keyboard.git
diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index a2367af5..18e71aa4 100644
--- a/converter/adb_usb/matrix.c
+++ b/converter/adb_usb/matrix.c
@@ -38,27 +38,22 @@ along with this program. If not, see .
# error "MATRIX_ROWS must not exceed 255"
#endif
-#define CAPS 0x39
-#define CAPS_UP (CAPS | 0x80)
-#define ROW(key) ((key)>>3&0x0F)
-#define COL(key) ((key)&0x07)
+#define ADB_CAPS_UP (ADB_CAPS | 0x80)
-static bool _matrix_is_modified = false;
+static bool is_modified = false;
// matrix state buffer(1:on, 0:off)
#if (MATRIX_COLS <= 8)
-static uint8_t *matrix;
-static uint8_t _matrix0[MATRIX_ROWS];
+static uint8_t matrix[MATRIX_ROWS];
#else
-static uint16_t *matrix;
-static uint16_t _matrix0[MATRIX_ROWS];
+static uint16_t matrix[MATRIX_ROWS];
#endif
#ifdef MATRIX_HAS_GHOST
static bool matrix_has_ghost_in_row(uint8_t row);
#endif
-static void _register_key(uint8_t key);
+static void register_key(uint8_t key);
inline
@@ -78,8 +73,7 @@ void matrix_init(void)
adb_host_init();
// initialize matrix state: all keys off
- for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
- matrix = _matrix0;
+ for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
print_enable = true;
debug_enable = true;
@@ -95,55 +89,61 @@ uint8_t matrix_scan(void)
uint16_t codes;
uint8_t key0, key1;
- _matrix_is_modified = false;
+ is_modified = false;
codes = adb_host_kbd_recv();
key0 = codes>>8;
key1 = codes&0xFF;
+ if (debug_matrix && codes) {
+ print("adb_host_kbd_recv: "); phex16(codes); print("\n");
+ }
+
#ifdef MATRIX_HAS_LOCKING_CAPS
// Send Caps key up event
- if (matrix_is_on(ROW(CAPS), COL(CAPS))) {
- _matrix_is_modified = true;
- _register_key(CAPS_UP);
+ if (matrix_is_on(MATRIX_ROW(ADB_CAPS), MATRIX_COL(ADB_CAPS))) {
+ register_key(ADB_CAPS_UP);
}
#endif
if (codes == 0) { // no keys
return 0;
- } else if (key0 == 0xFF && key1 != 0xFF) { // error
- return codes&0xFF;
+ } else if (codes == 0x7F7F) { // power key press
+ register_key(0x7F);
+ } else if (codes == 0xFFFF) { // power key release
+ register_key(0xFF);
+ } else if (key0 == 0xFF) { // error
+ if (debug_matrix) print("adb_host_kbd_recv: ERROR(matrix cleared.)\n");
+ // clear matrix to unregister all keys
+ for (uint8_t i=0; i < MATRIX_ROWS; i++) matrix[i] = 0x00;
+ return key1;
} else {
#ifdef MATRIX_HAS_LOCKING_CAPS
if (host_keyboard_leds() & (1<