X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=tmk_core%2Fprotocol%2Fxt_interrupt.c;h=1bdb519c2eb05cfbc2534c94f8b11d6385e98550;hb=d7548097fc3b37d6aaf4f36abae10fa475ea611c;hp=05afefd36017ffdd30d5716857a16f2ded695d2a;hpb=42199c90f8475ca8474a298b349057994a1beb49;p=max%2Ftmk_keyboard.git diff --git a/tmk_core/protocol/xt_interrupt.c b/tmk_core/protocol/xt_interrupt.c index 05afefd3..1bdb519c 100644 --- a/tmk_core/protocol/xt_interrupt.c +++ b/tmk_core/protocol/xt_interrupt.c @@ -1,5 +1,6 @@ /* -Copyright 2010,2011,2012,2013 Jun WAKO +Copyright 2018 Jun WAKO +Copyright 2016 Ethan Apodaca 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,28 @@ 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 #include #include -#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) { XT_INT_INIT(); + XT_INT_OFF(); /* hard reset */ #ifdef XT_RESET @@ -58,20 +65,26 @@ void xt_host_init(void) #endif /* soft reset: pull clock line down for 20ms */ - XT_INT_OFF(); - data_lo(); clock_lo(); + XT_DATA_IN(); + XT_CLOCK_LO(); _delay_ms(20); - data_in(); clock_in(); + + /* input mode with pullup */ + XT_CLOCK_IN(); + XT_DATA_IN(); + XT_INT_ON(); } /* 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; } } @@ -89,14 +102,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 (XT_CLOCK_READ()) return; switch (state) { case START: @@ -109,8 +122,12 @@ ISR(XT_INT_VECT) data |= 0x80; break; } - if (++state == END) { - pbuf_enqueue(data); + if (state++ == BIT7) { + ringbuf_put(&rb, data); + if (ringbuf_is_full(&rb)) { + XT_DATA_LO(); // inhibit keyboard sending + print("Full"); + } state = START; data = 0; }