From a9bce90c6090803a728592ae7ea563e2f3286e38 Mon Sep 17 00:00:00 2001 From: Ethan Apodaca Date: Wed, 2 Mar 2016 23:34:13 -0800 Subject: [PATCH] Mostly working. Is unstable, will emit bad codes after a while. --- converter/xt_usb/matrix.c | 129 ++++++++++--------------------- tmk_core/protocol/xt_interrupt.c | 51 ++++-------- 2 files changed, 56 insertions(+), 124 deletions(-) diff --git a/converter/xt_usb/matrix.c b/converter/xt_usb/matrix.c index 4218e39b..92fa6935 100644 --- a/converter/xt_usb/matrix.c +++ b/converter/xt_usb/matrix.c @@ -140,7 +140,6 @@ uint8_t matrix_scan(void) } uint8_t code = xt_host_recv(); - if (code) xprintf("%X\r\n", code); switch (state) { case INIT: switch (code) { @@ -150,19 +149,13 @@ uint8_t matrix_scan(void) case 0xE1: state = E1; break; - case 0x00: - break; default: // normal key make - if (code < 0x80) { + if (code < 0x80 && code != 0x00) { xprintf("make: %X\r\n", code); matrix_make(code); - } else if (code > 0x80 && code < 0xFF) { + } else if (code > 0x80 && code < 0xFF && code != 0x00) { xprintf("break %X\r\n", code); matrix_break(code - 0x80); - } else { - matrix_clear(); - clear_keyboard(); - xprintf("unexpected scan code at INIT: %02X\n", code); } state = INIT; } @@ -175,114 +168,72 @@ uint8_t matrix_scan(void) case 0xB7: state = E0_B7; break; - case 0x00: - state = INIT; - break; default: - if (code < 0x80) { + if (code < 0x80 && code != 0x00) { matrix_make(move_codes(code)); - } else if (code > 0x80 && code < 0xFF) { + } else if (code > 0x80 && code < 0xFF && code != 0x00) { matrix_break(move_codes(code - 0x80)); - } else { - matrix_clear(); - clear_keyboard(); - xprintf("unexpected scan code at E0: %02X\n", code); } state = INIT; } break; case E0_2A: - switch (code) { - case 0xE0: - state = E0_2A_E0; - break; - default: - state = INIT; - } + if(code == 0xE0) + state = E0_2A_E0; + else + state = INIT; break; case E0_2A_E0: - switch (code) { - case 0x37: - matrix_make(PRINT_SCREEN); - break; - default: - state = INIT; - } + if(code == 0x37) + matrix_make(PRINT_SCREEN); + else + state = INIT; break; case E0_B7: - switch (code) { - case 0xE0: - state = E0_B7; - break; - default: - state = INIT; - } + if(code == 0xE0) + state = E0_B7; + else + state = INIT; break; case E0_B7_E0: - switch (code) { - case 0xAA: - matrix_break(PRINT_SCREEN); - break; - default: - state = INIT; - } + if(code == 0xAA) + matrix_break(PRINT_SCREEN); + else + state = INIT; break; case E1: - switch (code) { - case 0x1D: - state = E1_1D; - break; - default: - state = INIT; - } + if (code == 0x1D) + state = E1_1D; + else + state = INIT; break; case E1_1D: - switch (code) { - case 0x45: - state = E1_1D_45; - break; - default: - state = INIT; - } + if(code == 0x45) + state = E1_1D_45; + else + state = INIT; break; case E1_1D_45: - switch (code) { - case 0xE1: - state = E1_1D_45_E1; - break; - default: - state = INIT; - } + if(code == 0xE1) + state = E1_1D_45_E1; + else + state = INIT; break; case E1_1D_45_E1: - switch (code) { - case 0x9D: - state = E1_1D_45_E1_9D; - break; - default: - state = INIT; - } + if(code == 0x9D) + state = E1_1D_45_E1_9D; + else + state = INIT; break; case E1_1D_45_E1_9D: - switch (code) { - case 0xC5: - matrix_make(PAUSE); - break; - default: - state = INIT; - } + if(code == 0xC5) + matrix_make(PAUSE); + else + state = INIT; break; default: state = INIT; } - - // TODO: request RESEND when error occurs? -/* - if (PS2_IS_FAILED(ps2_error)) { - uint8_t ret = ps2_host_send(PS2_RESEND); - xprintf("Resend: %02X\n", ret); - } -*/ return 1; } diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c index 2a351c5b..94b47db4 100644 --- a/tmk_core/protocol/xt_interrupt.c +++ b/tmk_core/protocol/xt_interrupt.c @@ -66,47 +66,28 @@ uint8_t xt_host_recv(void) ISR(XT_INT_VECT) { - static enum { - INIT, - BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, - STOP, - } state = INIT; + static uint8_t state = 0; static uint8_t data = 0; - // wait for clock falling edge - if(state != INIT) - wait_clock_lo(70); - switch (state) { - case INIT: - if (data_in()) - state++; - break; - case BIT0: - case BIT1: - case BIT2: - case BIT3: - case BIT4: - case BIT5: - case BIT6: - case BIT7: + if (state == 0) { + if (data_in()) state++; - data >>= 1; - if (data_in()) { - data |= 0x80; - } - break; - case STOP: - if (!data_in()) - goto DONE; - pbuf_enqueue(data); - goto DONE; - break; - default: - goto DONE; + } else if (state >= 1 && state <= 8) { + wait_clock_lo(20); + data >>= 1; + if (data_in()) + data |= 0x80; + if (state == 8) + goto END; + state++; + } else { + goto DONE; } goto RETURN; +END: + pbuf_enqueue(data); DONE: - state = INIT; + state = 0; data = 0; RETURN: return; -- 2.39.3