]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
ibmpc_usb: Add 'protocol change detection'
authortmk <hasu@tmk-kbd.com>
Tue, 12 May 2020 12:59:02 +0000 (21:59 +0900)
committertmk <hasu@tmk-kbd.com>
Wed, 13 May 2020 05:47:18 +0000 (14:47 +0900)
for better keybaord hotswap support

converter/ibmpc_usb/ibmpc_usb.c
tmk_core/protocol/ibmpc.h

index 6879bf803c786541016814ae2993d5348f131ae5..cf1ab0b747bf5ffb1e519722a2c10ffba6988043 100644 (file)
@@ -135,6 +135,7 @@ uint8_t matrix_scan(void)
         if (!(ibmpc_error & (IBMPC_ERR_SEND | IBMPC_ERR_FULL))) {
             // keyboard init again
             if (state == LOOP) {
+                xprintf("[RST] ");
                 state = INIT;
             }
         }
@@ -144,9 +145,21 @@ uint8_t matrix_scan(void)
         ibmpc_isr_debug = 0;
     }
 
-    // check protocol AT/XT
+    // check protocol change AT/XT
     if (ibmpc_protocol && ibmpc_protocol != current_protocol) {
-        xprintf("\nPROTO:%02X ISR:%04X ", ibmpc_protocol, ibmpc_isr_debug);
+        xprintf("\nPRT:%02X ISR:%04X ", ibmpc_protocol, ibmpc_isr_debug);
+
+        // protocol change between AT and XT indicates that
+        // keyboard is hotswapped or something goes wrong.
+        // This requires initializing keyboard again probably.
+        if (((current_protocol&IBMPC_PROTOCOL_XT) && (ibmpc_protocol&IBMPC_PROTOCOL_AT)) ||
+            ((current_protocol&IBMPC_PROTOCOL_AT) && (ibmpc_protocol&IBMPC_PROTOCOL_XT))) {
+            if (state == LOOP) {
+                xprintf("[CHG] ");
+                state = INIT;
+            }
+        }
+
         current_protocol = ibmpc_protocol;
         ibmpc_isr_debug = 0;
     }
@@ -328,17 +341,11 @@ uint8_t matrix_scan(void)
                 // Scan Code Set 2 and 3: 0x00
                 // Buffer full(IBMPC_ERR_FULL): 0xFF
                 if (code == 0x00 || code == 0xFF) {
-                    xprintf("\n!OVERRUN![");
-
-                    // read and ignore data
-                    do {
-                        wait_ms(10);
-                    } while ((code = ibmpc_host_recv()) != -1);
-                    xprintf("]\n");
-
                     // clear stuck keys
                     matrix_clear();
                     clear_keyboard();
+
+                    xprintf("\n[OVR] ");
                     break;
                 }
 
index 9039b89b1199adbc38b483aa90394dedb0285398..c994ddb63b6321e7f7628423eeba90f3a65a6c17 100644 (file)
@@ -71,10 +71,11 @@ POSSIBILITY OF SUCH DAMAGE.
 #define IBMPC_SET_LED     0xED
 
 #define IBMPC_PROTOCOL_NO       0
-#define IBMPC_PROTOCOL_AT       1
-#define IBMPC_PROTOCOL_XT_IBM   2
-#define IBMPC_PROTOCOL_XT_CLONE 3
-#define IBMPC_PROTOCOL_XT_ERROR 4
+#define IBMPC_PROTOCOL_AT       0x10
+#define IBMPC_PROTOCOL_XT       0x20
+#define IBMPC_PROTOCOL_XT_IBM   0x21
+#define IBMPC_PROTOCOL_XT_CLONE 0x22
+#define IBMPC_PROTOCOL_XT_ERROR 0x23
 
 // Error numbers
 #define IBMPC_ERR_NONE        0