diff --git a/converter/ibmpc_usb/ibmpc_usb.cpp b/converter/ibmpc_usb/ibmpc_usb.cpp index a17ed342..06e87e63 100644 --- a/converter/ibmpc_usb/ibmpc_usb.cpp +++ b/converter/ibmpc_usb/ibmpc_usb.cpp @@ -171,11 +171,15 @@ uint8_t IBMPCConverter::process_interface(void) // when recv error, neither send error nor buffer full if (!(ibmpc.error & (IBMPC_ERR_SEND | IBMPC_ERR_FULL))) { - // keyboard init again if (state == LOOP) { - xprintf("[RST] "); + // Reset state = ERROR; } + if (ibmpc.error == IBMPC_ERR_PARITY_AA) { + // AT/XT Auto-Switching support + // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-Keyboard-Converter#atxt-auto-switching + state = ERROR_PARITY_AA; + } } // clear or process error @@ -205,15 +209,9 @@ uint8_t IBMPCConverter::process_interface(void) switch (state) { case INIT: xprintf("I%u ", timer_read()); - keyboard_kind = NONE; - keyboard_id = 0x0000; - current_protocol = 0; - - matrix_clear(); - init_time = timer_read(); - state = WAIT_SETTLE; ibmpc.host_enable(); + state = WAIT_SETTLE; break; case WAIT_SETTLE: while (ibmpc.host_recv() != -1) ; // read data @@ -606,8 +604,22 @@ MOUSE_DONE: } } break; + case ERROR_PARITY_AA: + { + xprintf("P%u ", timer_read()); + // AT/XT Auto-Switching support: Send Resend command to select AT + uint16_t code = ibmpc.host_send(0xFE); + if (0xAA == code) { + state = READ_ID; + break; + } + } + // FALL THROUGH case ERROR: - // something goes wrong + xprintf("E%u ", timer_read()); + // reinit state + init(); + matrix_clear(); clear_keyboard(); state = INIT; break; diff --git a/converter/ibmpc_usb/ibmpc_usb.hpp b/converter/ibmpc_usb/ibmpc_usb.hpp index 26ad2984..f8d27dcf 100644 --- a/converter/ibmpc_usb/ibmpc_usb.hpp +++ b/converter/ibmpc_usb/ibmpc_usb.hpp @@ -28,6 +28,10 @@ class IBMPCConverter { } void init(void) { + keyboard_id = 0x0000; + keyboard_kind = NONE; + current_protocol = 0; + matrix_clear(); ibmpc.host_init(); } @@ -64,6 +68,7 @@ class IBMPCConverter { SETUP, LOOP, ERROR, + ERROR_PARITY_AA, } state = INIT; enum CS1_state {