]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - tmk_core/protocol/xt_interrupt.c
xt_usb: Change ring buffer and control Data line
[max/tmk_keyboard.git] / tmk_core / protocol / xt_interrupt.c
index 525dbcf2c318b451177a6aa18253c1a02beaf81b..ebaa436b382636e06cc3922006c8a3146e5ce104 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,18 +36,23 @@ 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"
+#include "ringbuf.h"
+
+
+#define BUF_SIZE 16
+static uint8_t buf[BUF_SIZE];
+static ringbuf_t rb = {
+    .buffer = buf,
+    .head = 0,
+    .tail = 0,
+    .size_mask = BUF_SIZE - 1
+};
 
 void xt_host_init(void)
 {
@@ -73,10 +79,12 @@ void xt_host_init(void)
 /* get data received by interrupt */
 uint8_t xt_host_recv(void)
 {
-    if (pbuf_has_data()) {
-        return pbuf_dequeue();
-    } else {
+    if (ringbuf_is_empty(&rb)) {
         return 0;
+    } else {
+        int16_t d = ringbuf_get(&rb);
+        XT_DATA_IN();  // ready to receive from keyboard
+        return d;
     }
 }
 
@@ -101,7 +109,7 @@ ISR(XT_INT_VECT)
     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 (XT_CLOCK_READ()) return;
 
     switch (state) {
         case START:
@@ -115,7 +123,11 @@ ISR(XT_INT_VECT)
             break;
     }
     if (state++ == BIT7) {
-        pbuf_enqueue(data);
+        ringbuf_put(&rb, data);
+        if (ringbuf_is_full(&rb)) {
+            XT_DATA_LO();  // inhibit keyboard sending
+            print("Full");
+        }
         state = START;
         data = 0;
     }