]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk_core/protocol/xt_interrupt.c
xt_usb: Remove xt_io.h
[max/tmk_keyboard.git] / tmk_core / protocol / xt_interrupt.c
index 5531464d742c2342f5beef62d1ced098e61eb053..08af1b9a17c34ac44c04f40f8cf3b6bedaad519c 100644 (file)
@@ -1,5 +1,6 @@
 /*
-Copyright 2010,2011,2012,2013 Jun WAKO <wakojun@gmail.com>
+Copyright 2018 Jun WAKO <wakojun@gmail.com>
+Copyright 2016 Ethan Apodaca <papodaca@gmail.com>
 
 This software is licensed with a Modified BSD License.
 All of this is supposed to be Free Software, Open Source, DFSG-free,
@@ -35,22 +36,18 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 */
 
-/*
- * PS/2 protocol Pin interrupt version
- */
-
 #include <stdbool.h>
 #include <avr/interrupt.h>
 #include <util/delay.h>
 #include "pbuff.h"
 #include "xt.h"
-#include "xt_io.h"
 #include "wait.h"
 #include "print.h"
 
 void xt_host_init(void)
 {
     XT_INT_INIT();
+    XT_INT_OFF();
 
     /* hard reset */
 #ifdef XT_RESET
@@ -58,10 +55,14 @@ void xt_host_init(void)
 #endif
 
     /* soft reset: pull clock line down for 20ms */
-    XT_INT_OFF();
-    data_lo(); clock_lo();
+    XT_DATA_LO();
+    XT_CLOCK_LO();
     _delay_ms(20);
-    data_in(); clock_in();
+
+    /* input mode with pullup */
+    XT_CLOCK_IN();
+    XT_DATA_IN();
+
     XT_INT_ON();
 }
 
@@ -89,13 +90,14 @@ ISR(XT_INT_VECT)
      * https://github.com/tmk/tmk_keyboard/wiki/IBM-PC-XT-Keyboard-Protocol
      */
     static enum {
-        START, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7, END
+        START, BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7
     } state = START;
     static uint8_t data = 0;
 
-    uint8_t dbit = data_in();
+    uint8_t dbit = XT_DATA_READ();
+
     // This is needed if using PCINT which can be called on both falling and rising edge
-    if (clock_in()) return;
+    //if (clock_in()) return;
 
     switch (state) {
         case START:
@@ -108,7 +110,7 @@ ISR(XT_INT_VECT)
                 data |= 0x80;
             break;
     }
-    if (++state == END) {
+    if (state++ == BIT7) {
         pbuf_enqueue(data);
         state = START;
         data = 0;