1
0

Mostly working. Is unstable, will emit bad codes after a while.

This commit is contained in:
Ethan Apodaca 2016-03-02 23:34:13 -08:00
parent 3def1c3065
commit a9bce90c60
2 changed files with 56 additions and 124 deletions

View File

@ -140,7 +140,6 @@ uint8_t matrix_scan(void)
} }
uint8_t code = xt_host_recv(); uint8_t code = xt_host_recv();
if (code) xprintf("%X\r\n", code);
switch (state) { switch (state) {
case INIT: case INIT:
switch (code) { switch (code) {
@ -150,19 +149,13 @@ uint8_t matrix_scan(void)
case 0xE1: case 0xE1:
state = E1; state = E1;
break; break;
case 0x00:
break;
default: // normal key make default: // normal key make
if (code < 0x80) { if (code < 0x80 && code != 0x00) {
xprintf("make: %X\r\n", code); xprintf("make: %X\r\n", code);
matrix_make(code); matrix_make(code);
} else if (code > 0x80 && code < 0xFF) { } else if (code > 0x80 && code < 0xFF && code != 0x00) {
xprintf("break %X\r\n", code); xprintf("break %X\r\n", code);
matrix_break(code - 0x80); matrix_break(code - 0x80);
} else {
matrix_clear();
clear_keyboard();
xprintf("unexpected scan code at INIT: %02X\n", code);
} }
state = INIT; state = INIT;
} }
@ -175,114 +168,72 @@ uint8_t matrix_scan(void)
case 0xB7: case 0xB7:
state = E0_B7; state = E0_B7;
break; break;
case 0x00:
state = INIT;
break;
default: default:
if (code < 0x80) { if (code < 0x80 && code != 0x00) {
matrix_make(move_codes(code)); matrix_make(move_codes(code));
} else if (code > 0x80 && code < 0xFF) { } else if (code > 0x80 && code < 0xFF && code != 0x00) {
matrix_break(move_codes(code - 0x80)); matrix_break(move_codes(code - 0x80));
} else {
matrix_clear();
clear_keyboard();
xprintf("unexpected scan code at E0: %02X\n", code);
} }
state = INIT; state = INIT;
} }
break; break;
case E0_2A: case E0_2A:
switch (code) { if(code == 0xE0)
case 0xE0: state = E0_2A_E0;
state = E0_2A_E0; else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E0_2A_E0: case E0_2A_E0:
switch (code) { if(code == 0x37)
case 0x37: matrix_make(PRINT_SCREEN);
matrix_make(PRINT_SCREEN); else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E0_B7: case E0_B7:
switch (code) { if(code == 0xE0)
case 0xE0: state = E0_B7;
state = E0_B7; else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E0_B7_E0: case E0_B7_E0:
switch (code) { if(code == 0xAA)
case 0xAA: matrix_break(PRINT_SCREEN);
matrix_break(PRINT_SCREEN); else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E1: case E1:
switch (code) { if (code == 0x1D)
case 0x1D: state = E1_1D;
state = E1_1D; else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E1_1D: case E1_1D:
switch (code) { if(code == 0x45)
case 0x45: state = E1_1D_45;
state = E1_1D_45; else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E1_1D_45: case E1_1D_45:
switch (code) { if(code == 0xE1)
case 0xE1: state = E1_1D_45_E1;
state = E1_1D_45_E1; else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E1_1D_45_E1: case E1_1D_45_E1:
switch (code) { if(code == 0x9D)
case 0x9D: state = E1_1D_45_E1_9D;
state = E1_1D_45_E1_9D; else
break; state = INIT;
default:
state = INIT;
}
break; break;
case E1_1D_45_E1_9D: case E1_1D_45_E1_9D:
switch (code) { if(code == 0xC5)
case 0xC5: matrix_make(PAUSE);
matrix_make(PAUSE); else
break; state = INIT;
default:
state = INIT;
}
break; break;
default: default:
state = INIT; state = INIT;
} }
// TODO: request RESEND when error occurs?
/*
if (PS2_IS_FAILED(ps2_error)) {
uint8_t ret = ps2_host_send(PS2_RESEND);
xprintf("Resend: %02X\n", ret);
}
*/
return 1; return 1;
} }

View File

@ -66,47 +66,28 @@ uint8_t xt_host_recv(void)
ISR(XT_INT_VECT) ISR(XT_INT_VECT)
{ {
static enum { static uint8_t state = 0;
INIT,
BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7,
STOP,
} state = INIT;
static uint8_t data = 0; static uint8_t data = 0;
// wait for clock falling edge
if(state != INIT)
wait_clock_lo(70);
switch (state) { if (state == 0) {
case INIT: if (data_in())
if (data_in())
state++;
break;
case BIT0:
case BIT1:
case BIT2:
case BIT3:
case BIT4:
case BIT5:
case BIT6:
case BIT7:
state++; state++;
data >>= 1; } else if (state >= 1 && state <= 8) {
if (data_in()) { wait_clock_lo(20);
data |= 0x80; data >>= 1;
} if (data_in())
break; data |= 0x80;
case STOP: if (state == 8)
if (!data_in()) goto END;
goto DONE; state++;
pbuf_enqueue(data); } else {
goto DONE; goto DONE;
break;
default:
goto DONE;
} }
goto RETURN; goto RETURN;
END:
pbuf_enqueue(data);
DONE: DONE:
state = INIT; state = 0;
data = 0; data = 0;
RETURN: RETURN:
return; return;