]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - converter/ibmpc_usb/ibmpc_usb.c
Merge remote-tracking branch 'tmk/master'
[max/tmk_keyboard.git] / converter / ibmpc_usb / ibmpc_usb.c
index 99248d83c301a84159f77a749be3715b664ab768..cf1ab0b747bf5ffb1e519722a2c10ffba6988043 100644 (file)
@@ -129,31 +129,39 @@ uint8_t matrix_scan(void)
 
 
     if (ibmpc_error) {
-        xprintf("\nERR:%02X\n", ibmpc_error);
+        xprintf("\nERR:%02X ISR:%04X ", ibmpc_error, ibmpc_isr_debug);
 
         // 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("init\n");
+                xprintf("[RST] ");
                 state = INIT;
             }
         }
 
         // clear or process error
         ibmpc_error = IBMPC_ERR_NONE;
-    }
-
-    // check ISR state debug
-    if (ibmpc_isr_debug) {
-        xprintf("\nISR:%04X\n", ibmpc_isr_debug);
         ibmpc_isr_debug = 0;
     }
 
-    // check protocol AT/XT
-    if (ibmpc_protocol != current_protocol) {
-        xprintf("\nPROTO:%02X\n", ibmpc_protocol);
+    // check protocol change AT/XT
+    if (ibmpc_protocol && ibmpc_protocol != current_protocol) {
+        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;
     }
 
     switch (state) {
@@ -297,7 +305,7 @@ uint8_t matrix_scan(void)
                 keyboard_kind = PC_AT;
             }
 
-            xprintf("ID:%04X(%d)\n", keyboard_id, keyboard_kind);
+            xprintf("\nID:%04X(%d) ", keyboard_id, keyboard_kind);
 
             state = SETUP;
             break;
@@ -333,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;
                 }
 
@@ -759,10 +761,7 @@ static int8_t process_cs2(uint8_t code)
                     break;
                 case 0xAA:  // Self-test passed
                 case 0xFC:  // Self-test failed
-                    // reset or plugin-in new keyboard
-                    state = INIT;
-                    return -1;
-                    break;
+                    // replug or unstable connection probably
                 default:    // normal key make
                     state = INIT;
                     if (code < 0x80) {
@@ -948,7 +947,7 @@ static int8_t process_cs3(uint8_t code)
                         matrix_make(code);
                     } else {
                         xprintf("!CS3_READY!\n");
-                        //return -1;
+                        return -1;
                     }
             }
             break;
@@ -992,7 +991,7 @@ static int8_t process_cs3(uint8_t code)
                         matrix_break(code);
                     } else {
                         xprintf("!CS3_F0!\n");
-                        //return -1;
+                        return -1;
                     }
             }
             break;