]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
ibmpc: Fix stop bit check code in ISR
authortmk <hasu@tmk-kbd.com>
Thu, 23 Jan 2020 15:44:27 +0000 (00:44 +0900)
committertmk <hasu@tmk-kbd.com>
Sat, 29 Feb 2020 08:29:55 +0000 (17:29 +0900)
removing function call makes prologue/epilogue shorter

tmk_core/protocol/ibmpc.c

index f6c5e5c3727193e5da0606c4b4fe15ed520db3f0..f74a387da95d195c162e994204e89da7ce77793b 100644 (file)
@@ -191,6 +191,8 @@ int16_t ibmpc_host_recv_response(void)
     return data;
 }
 
+// NOTE: to read data line early as possible:
+// write naked ISR with asembly code to read the line and call C func to do other job?
 ISR(IBMPC_INT_VECT)
 {
     uint8_t dbit;
@@ -240,16 +242,23 @@ ISR(IBMPC_INT_VECT)
             goto DONE;
             break;
         case 0b10100000:
-            // XT IBM-done or AT-midway
-            // wait and check for clock of AT stop bit
-            if (wait_clock_hi(100) && wait_clock_lo(100)) { // FIXME this makes ISR prologe long
-                // AT-midway
-                return;
-            } else {
-                // XT-IBM-done
-                recv_data = (isr_data>>8) & 0xFF;
-                goto DONE;
-            }
+            {
+                uint8_t us = 150;
+                // wait for rising and falling edge of AT stop bit
+                while (!(IBMPC_CLOCK_PIN&(1<<IBMPC_CLOCK_BIT)) && us) { wait_us(1); us--; }
+                while (  IBMPC_CLOCK_PIN&(1<<IBMPC_CLOCK_BIT)  && us) { wait_us(1); us--; }
+
+                if (us) {
+                    // found stop bit: return immediately and process the stop bit in ISR
+                    // AT-midway
+                    return;
+                } else {
+                    // no stop bit
+                    // XT-IBM-done
+                    recv_data = (isr_data>>8) & 0xFF;
+                    goto DONE;
+                }
+             }
             break;
         case 0b00010000:
         case 0b10010000: