X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Fxt_interrupt.c;h=1bdb519c2eb05cfbc2534c94f8b11d6385e98550;hb=97782dd59e2966b568cdb7a58adaa988acc79d9b;hp=08af1b9a17c34ac44c04f40f8cf3b6bedaad519c;hpb=136d55a249bb581f7bf6fc7765f1da7c22c8a344;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c index 08af1b9a..1bdb519c 100644 --- a/tmk_core/protocol/xt_interrupt.c +++ b/tmk_core/protocol/xt_interrupt.c @@ -39,10 +39,20 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include "pbuff.h" #include "xt.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) { @@ -55,7 +65,7 @@ void xt_host_init(void) #endif /* soft reset: pull clock line down for 20ms */ - XT_DATA_LO(); + XT_DATA_IN(); XT_CLOCK_LO(); _delay_ms(20); @@ -69,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; } } @@ -97,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: @@ -111,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; }