From 7d9e554a8d7053f5e21527e88fa19ddd8cfd62d6 Mon Sep 17 00:00:00 2001 From: tmk Date: Wed, 3 Feb 2021 12:46:05 +0900 Subject: [PATCH] ibmpc_usb: Fix keyboard reset sequence Wait 3 sec for keyboard to be settled or until keyboard sends anything Fix for BTC-5161 AT/XT auto-select: The keyboard requires reset to start AT mode even if it already sends AA. https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#btc-5161 --- converter/ibmpc_usb/ibmpc_usb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/converter/ibmpc_usb/ibmpc_usb.c b/converter/ibmpc_usb/ibmpc_usb.c index 34f36a63..f554ff4d 100644 --- a/converter/ibmpc_usb/ibmpc_usb.c +++ b/converter/ibmpc_usb/ibmpc_usb.c @@ -169,8 +169,6 @@ uint8_t matrix_scan(void) switch (state) { case INIT: - ibmpc_host_disable(); - xprintf("I%u ", timer_read()); keyboard_kind = NONE; keyboard_id = 0x0000; @@ -183,17 +181,20 @@ uint8_t matrix_scan(void) state = WAIT_SETTLE; break; case WAIT_SETTLE: + // Reset when keyboad sends something + if (ibmpc_host_recv() != -1) { + state = AT_RESET; + } + // wait for keyboard to settle after plugin - if (timer_elapsed(init_time) > 1000) { + if (timer_elapsed(init_time) > 3000) { state = AT_RESET; } break; case AT_RESET: - ibmpc_host_isr_clear(); - ibmpc_host_enable(); - wait_ms(1); // keyboard can't respond to command without this + xprintf("A%u ", timer_read()); - // SKIDATA-2-DE(and some other keyboards?) stores 'Code Set' setting in nonvlatile memory + // SKIDATA-2-DE(and some other keyboards?) stores 'Code Set' setting in nonvolatile memory // and keeps it until receiving reset. Sending reset here may be useful to clear it, perhaps. // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-AT-Keyboard-Protocol#select-alternate-scan-codesf0 @@ -203,7 +204,6 @@ uint8_t matrix_scan(void) } else { state = XT_RESET; } - xprintf("A%u ", timer_read()); break; case XT_RESET: // Reset XT-initialize keyboard