Browse Source

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

master
Ethan Apodaca 8 years ago
parent
commit
a9bce90c60
2 changed files with 56 additions and 124 deletions
  1. 40
    89
      converter/xt_usb/matrix.c
  2. 16
    35
      tmk_core/protocol/xt_interrupt.c

+ 40
- 89
converter/xt_usb/matrix.c View File

} }


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) {
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;
} }
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) {
case 0xE0:
state = E0_2A_E0;
break;
default:
state = INIT;
}
if(code == 0xE0)
state = E0_2A_E0;
else
state = INIT;
break; break;
case E0_2A_E0: case E0_2A_E0:
switch (code) {
case 0x37:
matrix_make(PRINT_SCREEN);
break;
default:
state = INIT;
}
if(code == 0x37)
matrix_make(PRINT_SCREEN);
else
state = INIT;
break; break;
case E0_B7: case E0_B7:
switch (code) {
case 0xE0:
state = E0_B7;
break;
default:
state = INIT;
}
if(code == 0xE0)
state = E0_B7;
else
state = INIT;
break; break;
case E0_B7_E0: case E0_B7_E0:
switch (code) {
case 0xAA:
matrix_break(PRINT_SCREEN);
break;
default:
state = INIT;
}
if(code == 0xAA)
matrix_break(PRINT_SCREEN);
else
state = INIT;
break; break;
case E1: case E1:
switch (code) {
case 0x1D:
state = E1_1D;
break;
default:
state = INIT;
}
if (code == 0x1D)
state = E1_1D;
else
state = INIT;
break; break;
case E1_1D: case E1_1D:
switch (code) {
case 0x45:
state = E1_1D_45;
break;
default:
state = INIT;
}
if(code == 0x45)
state = E1_1D_45;
else
state = INIT;
break; break;
case E1_1D_45: case E1_1D_45:
switch (code) {
case 0xE1:
state = E1_1D_45_E1;
break;
default:
state = INIT;
}
if(code == 0xE1)
state = E1_1D_45_E1;
else
state = INIT;
break; break;
case E1_1D_45_E1: case E1_1D_45_E1:
switch (code) {
case 0x9D:
state = E1_1D_45_E1_9D;
break;
default:
state = INIT;
}
if(code == 0x9D)
state = E1_1D_45_E1_9D;
else
state = INIT;
break; break;
case E1_1D_45_E1_9D: case E1_1D_45_E1_9D:
switch (code) {
case 0xC5:
matrix_make(PAUSE);
break;
default:
state = INIT;
}
if(code == 0xC5)
matrix_make(PAUSE);
else
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;
} }



+ 16
- 35
tmk_core/protocol/xt_interrupt.c View File



ISR(XT_INT_VECT) ISR(XT_INT_VECT)
{ {
static enum {
INIT,
BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7,
STOP,
} state = INIT;
static uint8_t state = 0;
static uint8_t data = 0; static uint8_t data = 0;
// wait for clock falling edge
if(state != INIT)
wait_clock_lo(70);


switch (state) {
case INIT:
if (data_in())
state++;
break;
case BIT0:
case BIT1:
case BIT2:
case BIT3:
case BIT4:
case BIT5:
case BIT6:
case BIT7:
if (state == 0) {
if (data_in())
state++; state++;
data >>= 1;
if (data_in()) {
data |= 0x80;
}
break;
case STOP:
if (!data_in())
goto DONE;
pbuf_enqueue(data);
goto DONE;
break;
default:
goto DONE;
} else if (state >= 1 && state <= 8) {
wait_clock_lo(20);
data >>= 1;
if (data_in())
data |= 0x80;
if (state == 8)
goto END;
state++;
} else {
goto DONE;
} }
goto RETURN; goto RETURN;
END:
pbuf_enqueue(data);
DONE: DONE:
state = INIT;
state = 0;
data = 0; data = 0;
RETURN: RETURN:
return; return;