]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk_core/protocol/ibmpc.c
ibmpc: Protocol detection between AT and XT
[max/tmk_keyboard.git] / tmk_core / protocol / ibmpc.c
index 9553e7ee1cfee3ae385bfad463bddafe99c4c362..2f5f70f59ac3701c89778489fe8aebc76f32f78c 100644 (file)
@@ -56,7 +56,7 @@ POSSIBILITY OF SUCH DAMAGE.
 } while (0)
 
 
-volatile uint8_t ibmpc_protocol = IBMPC_PROTOCOL_AT;
+volatile uint8_t ibmpc_protocol = IBMPC_PROTOCOL_NO;
 volatile uint8_t ibmpc_error = IBMPC_ERR_NONE;
 
 /* 2-byte buffer for data received from keyhboard
@@ -97,8 +97,6 @@ int16_t ibmpc_host_send(uint8_t data)
     bool parity = true;
     ibmpc_error = IBMPC_ERR_NONE;
 
-    if (ibmpc_protocol == IBMPC_PROTOCOL_XT) return -1;
-
     dprintf("w%02X ", data);
 
     IBMPC_INT_OFF();
@@ -268,8 +266,8 @@ ISR(IBMPC_INT_VECT)
             break;
         case 0b11000000:
             // XT_Clone-done
-            recv_data = recv_data<<8;
-            recv_data |= (isr_state>>8) & 0xFF;
+            isr_state = isr_state>>8;
+            ibmpc_protocol = IBMPC_PROTOCOL_XT_CLONE;
             goto DONE;
             break;
         case 0b10100000:    // ^2
@@ -284,8 +282,8 @@ ISR(IBMPC_INT_VECT)
                     goto NEXT;
                 } else {
                     // no stop bit: XT_IBM-done
-                    recv_data = recv_data<<8;
-                    recv_data |= (isr_state>>8) & 0xFF;
+                    isr_state = isr_state>>8;
+                    ibmpc_protocol = IBMPC_PROTOCOL_XT_IBM;
                     goto DONE;
                 }
              }
@@ -294,10 +292,10 @@ ISR(IBMPC_INT_VECT)
         case 0b10010000:
         case 0b01010000:
         case 0b11010000:
-            // TODO: parity check?
             // AT-done
-            recv_data = recv_data<<8;
-            recv_data |= (isr_state>>6) & 0xFF;
+            // TODO: parity check?
+            isr_state = isr_state>>6;
+            ibmpc_protocol = IBMPC_PROTOCOL_AT;
             goto DONE;
             break;
         case 0b01100000:
@@ -318,7 +316,16 @@ ERROR:
     recv_data = 0xFF00; // clear data and scancode of error 0x00
     return;
 DONE:
-    // TODO: process error code: 0x00(AT), 0xFF(XT) in particular
+    if ((isr_state & 0x00FF) == 0x00FF) {
+        // receive error code 0xFF
+        ibmpc_error = IBMPC_ERR_FF;
+    }
+    if ((recv_data & 0xFF00) != 0xFF00) {
+        // buffer full and overwritten
+        ibmpc_error = IBMPC_ERR_FULL;
+    }
+    recv_data = recv_data<<8;
+    recv_data |= isr_state & 0xFF;
     isr_state = 0x8000;  // clear to next data
 NEXT:
     return;