diff --git a/converter/adb_usb/matrix.c b/converter/adb_usb/matrix.c
index 4d1b9e9aa5..18e71aa497 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,48 +89,53 @@ 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_enable && codes) {
+ 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<
#include
#if !(defined(ADB_PORT) && \
@@ -47,6 +48,10 @@ POSSIBILITY OF SUCH DAMAGE.
# error "ADB port setting is required in config.h"
#endif
+#define ADB_POWER 0x7F
+#define ADB_CAPS 0x39
+
+
// ADB host
void adb_host_init(void);
bool adb_host_psw(void);