X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;f=ps2.c;h=8a05916210d77b4741c060c543a45fad75a102e2;hb=0dde25e81cc06ed6331c030839b7048c69fc9c84;hp=52ee1691fbe2b5ac5eab58a4498d66d95cb81795;hpb=239bdbf41936566c0ae5b0cbd8c6bf7dd824f7fb;p=max%2Ftmk_keyboard.git diff --git a/ps2.c b/ps2.c index 52ee1691..8a059162 100644 --- a/ps2.c +++ b/ps2.c @@ -1,5 +1,5 @@ /* -Copyright (c) 2010,2011 Jun WAKO +Copyright 2010,2011 Jun WAKO This software is licensed with a Modified BSD License. All of this is supposed to be Free Software, Open Source, DFSG-free, @@ -34,6 +34,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #include #include #include @@ -187,6 +188,9 @@ static inline void pbuf_enqueue(uint8_t data) { if (!data) return; + + uint8_t sreg = SREG; + cli(); uint8_t next = (pbuf_head + 1) % PBUF_SIZE; if (next != pbuf_tail) { pbuf[pbuf_head] = data; @@ -194,10 +198,12 @@ static inline void pbuf_enqueue(uint8_t data) } else { debug("pbuf: full\n"); } + SREG = sreg; } static inline uint8_t pbuf_dequeue(void) { uint8_t val = 0; + uint8_t sreg = SREG; cli(); if (pbuf_head != pbuf_tail) { @@ -205,22 +211,30 @@ static inline uint8_t pbuf_dequeue(void) pbuf_tail = (pbuf_tail + 1) % PBUF_SIZE; } SREG = sreg; + return val; } /* get data received by interrupt */ uint8_t ps2_host_recv(void) { - // TODO: release clock line after 100us when inhibited by error if (ps2_error) { + print("x"); + phex(ps2_error); ps2_host_send(0xFE); // request to resend ps2_error = PS2_ERR_NONE; } + idle(); return pbuf_dequeue(); } +#if 0 #define DEBUGP_INIT() do { DDRC = 0xFF; } while (0) #define DEBUGP(x) do { PORTC = x; } while (0) +#else +#define DEBUGP_INIT() +#define DEBUGP(x) +#endif ISR(PS2_INT_VECT) { static enum { @@ -281,7 +295,7 @@ ISR(PS2_INT_VECT) } goto RETURN; ERROR: - DEBUGP(0xFF); + DEBUGP(0x0F); inhibit(); ps2_error = state; DONE: