ibmpc_usb: AT/XT Auto-Switching keyboard support

Prefer selecting AT protocool to XT
Send resend command 'FE' to keyboard that starts with 'AA' including parity error
https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-Keyboard-Converter#atxt-auto-switching
This commit is contained in:
tmk 2021-10-25 15:15:01 +09:00
parent eea8b36f0d
commit 16ff313820
2 changed files with 27 additions and 10 deletions

View file

@ -171,11 +171,15 @@ uint8_t IBMPCConverter::process_interface(void)
// when recv error, neither send error nor buffer full // when recv error, neither send error nor buffer full
if (!(ibmpc.error & (IBMPC_ERR_SEND | IBMPC_ERR_FULL))) { if (!(ibmpc.error & (IBMPC_ERR_SEND | IBMPC_ERR_FULL))) {
// keyboard init again
if (state == LOOP) { if (state == LOOP) {
xprintf("[RST] "); // Reset
state = ERROR; 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 // clear or process error
@ -205,15 +209,9 @@ uint8_t IBMPCConverter::process_interface(void)
switch (state) { switch (state) {
case INIT: case INIT:
xprintf("I%u ", timer_read()); xprintf("I%u ", timer_read());
keyboard_kind = NONE;
keyboard_id = 0x0000;
current_protocol = 0;
matrix_clear();
init_time = timer_read(); init_time = timer_read();
state = WAIT_SETTLE;
ibmpc.host_enable(); ibmpc.host_enable();
state = WAIT_SETTLE;
break; break;
case WAIT_SETTLE: case WAIT_SETTLE:
while (ibmpc.host_recv() != -1) ; // read data while (ibmpc.host_recv() != -1) ; // read data
@ -606,8 +604,22 @@ MOUSE_DONE:
} }
} }
break; 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: case ERROR:
// something goes wrong xprintf("E%u ", timer_read());
// reinit state
init();
matrix_clear();
clear_keyboard(); clear_keyboard();
state = INIT; state = INIT;
break; break;

View file

@ -28,6 +28,10 @@ class IBMPCConverter {
} }
void init(void) { void init(void) {
keyboard_id = 0x0000;
keyboard_kind = NONE;
current_protocol = 0;
matrix_clear();
ibmpc.host_init(); ibmpc.host_init();
} }
@ -64,6 +68,7 @@ class IBMPCConverter {
SETUP, SETUP,
LOOP, LOOP,
ERROR, ERROR,
ERROR_PARITY_AA,
} state = INIT; } state = INIT;
enum CS1_state { enum CS1_state {