]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - converter/ibmpc_usb/ibmpc_usb.c
ibmpc_usb: Add Z-150 AT support
[max/tmk_keyboard.git] / converter / ibmpc_usb / ibmpc_usb.c
index 6879bf803c786541016814ae2993d5348f131ae5..9347793f877dc8a0313c8bafb97f6437dc17b452 100644 (file)
@@ -55,6 +55,9 @@ static uint16_t read_keyboard_id(void)
     uint16_t id = 0;
     int16_t  code = 0;
 
+    // temporary fix Z-150 AT should response with ID
+    if (ibmpc_protocol == IBMPC_PROTOCOL_AT_Z150) return 0xFFFD;
+
     // Disable
     //code = ibmpc_host_send(0xF5);
 
@@ -135,6 +138,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 +148,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;
     }
@@ -191,9 +207,10 @@ uint8_t matrix_scan(void)
         case XT_RESET:
             // Reset XT-initialize keyboard
             // XT: hard reset 500ms for IBM XT Type-1 keyboard and clones
-            // XT: soft reset 20ms min(clock Lo)
-            ibmpc_host_disable();   // soft reset: inihibit(clock Lo/Data Hi)
-            IBMPC_RST_LO();         // hard reset: reset pin Lo
+            // XT: soft reset 20ms min
+            // https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-XT-Keyboard-Protocol#keyboard-soft-reset
+            ibmpc_host_disable();   // soft reset: Clock Lo/Data Hi
+            IBMPC_RST_LO();         // hard reset: Reset pin Lo
 
             init_time = timer_read();
             state = XT_RESET_WAIT;
@@ -204,9 +221,9 @@ uint8_t matrix_scan(void)
             }
             break;
         case XT_RESET_DONE:
-            IBMPC_RST_HIZ();        // hard reset: reset pin HiZ
+            IBMPC_RST_HIZ();        // hard reset: Reset pin HiZ
             ibmpc_host_isr_clear();
-            ibmpc_host_enable();    // soft reset: idle(clock Hi/Data Hi)
+            ibmpc_host_enable();    // soft reset: idle(Clock Hi/Data Hi)
 
             xprintf("X%u ", timer_read());
             init_time = timer_read();
@@ -262,6 +279,8 @@ uint8_t matrix_scan(void)
                 keyboard_kind = PC_XT;
             } else if (0xFFFE == keyboard_id) {     // CodeSet2 PS/2 fails to response?
                 keyboard_kind = PC_AT;
+            } else if (0xFFFD == keyboard_id) {     // Zenith Z-150 AT
+                keyboard_kind = PC_AT_Z150;
             } else if (0x00FF == keyboard_id) {     // Mouse is not supported
                 xprintf("Mouse: not supported\n");
                 keyboard_kind = NONE;
@@ -304,6 +323,9 @@ uint8_t matrix_scan(void)
                 case PC_AT:
                     led_set(host_keyboard_leds());
                     break;
+                case PC_AT_Z150:
+                    // TODO: do not set indicators temporarily for debug
+                    break;
                 case PC_TERMINAL:
                     // Set all keys to make/break type
                     ibmpc_host_send(0xF8);
@@ -328,17 +350,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;
                 }
 
@@ -347,6 +363,7 @@ uint8_t matrix_scan(void)
                         if (process_cs1(code) == -1) state = INIT;
                         break;
                     case PC_AT:
+                    case PC_AT_Z150:
                         if (process_cs2(code) == -1) state = INIT;
                         break;
                     case PC_TERMINAL:
@@ -514,7 +531,7 @@ static int8_t process_cs1(uint8_t code)
     static enum {
         INIT,
         E0,
-        // Pause: E1 1D 45, E1 9D C5 [a] (TODO: test)
+        // Pause: E1 1D 45, E1 9D C5 [a]
         E1,
         E1_1D,
         E1_9D,
@@ -571,7 +588,8 @@ static int8_t process_cs1(uint8_t code)
         case E1_1D:
             switch (code) {
                 case 0x45:
-                    matrix_make(0x55);
+                    matrix_make(0x55); // Pause
+                    state = INIT;
                     break;
                 default:
                     state = INIT;
@@ -580,8 +598,9 @@ static int8_t process_cs1(uint8_t code)
             break;
         case E1_9D:
             switch (code) {
-                case 0x45:
-                    matrix_break(0x55);
+                case 0xC5:
+                    matrix_break(0x55); // Pause
+                    state = INIT;
                     break;
                 default:
                     state = INIT;