diff options
| -rw-r--r-- | kbc.c | 21 |
1 files changed, 15 insertions, 6 deletions
@@ -60,13 +60,21 @@ enum state { STATE_KEYMATIC_RECHECK, STATE_KEYMATIC_RECLOSE, #ifdef KILLSWITCH STATE_ERROR, #endif }; -static volatile enum state state, nextstate, toutstate; + +/* state is the current system state */ +static volatile enum state state; + +/* system will advance to nextstate on return to main, if nextstate is != STATE_NONE */ +static volatile enum state nextstate; + +/* system will advance to toutstate on timeout. */ +static volatile enum state toutstate; static void power_up() { DDRD = D_PWR; PORTD = D_DATA | D_CLK; } @@ -106,13 +114,13 @@ static void dbg_wr(uint8_t what) if (dbgpos < sizeof(dbgtx)) dbgtx[dbgpos++] = what; SPCR = (1 << SPIE) | (1 << SPE); sei(); } -ISR(SIG_SPI) +ISR(SPI_STC_vect) { if (dbgpos) { SPDR = dbgtx[0]; for (uint8_t c = 0; c < sizeof(dbgtx); c++) dbgtx[c] = dbgtx[c + 1]; dbgpos--; @@ -398,13 +406,13 @@ static void state_enter(void) if (send_byte(0xf9) != 0xfa) break; #endif nextstate = STATE_IDLE; break; case STATE_IDLE: - memset(&code, 0, sizeof(code)); + memset(code, 0, sizeof(code)); toutstate = STATE_IDLEBLINK; statecntr = WAIT_IDLE; nextstate = STATE_FAILURE; if (send_byte(0xed) != 0xfa) break; if (send_byte(0x00) != 0xfa) @@ -484,13 +492,13 @@ static void state_enter(void) break; break; #endif } } -ISR(SIG_OVERFLOW0) +ISR(TIMER0_OVF_vect) { if (!--cntr) { cntr = CNTRTOP; PORTB = B_OPEN | B_CLOSE | B_BEEP; @@ -533,12 +541,13 @@ static void handle_keypress(uint8_t data) uint8_t ascii = '_'; uint8_t c; if (release) { pressed = 0; release = 0; + e0 = 0; return; } if (data == pressed) return; if (data == 0xe0) { @@ -600,26 +609,26 @@ static void handle_keypress(uint8_t data) PORTB &= ~(B_OPEN | B_BEEP); } cntr = CNTR_KEYMATIC; nextstate = STATE_ACCEPT; } - memset(&code, 0, sizeof(code)); + memset(code, 0, sizeof(code)); return; } for (c = 0; c < sizeof(code) - 1; c++) code[c] = code[c + 1]; code[c] = ascii; PORTB &= ~B_BEEP; cntr = CNTR_BEEP; nextstate = STATE_INPUT; } -ISR(SIG_USART_RECV) +ISR(USART_RX_vect) { uint8_t data = UDR0; dbg_wr(0x80 | (data & 0x3f)); dbg_wr(0x84 | (data >> 6)); |
