Browse Source

Fix ps2_host_recv_response

keymap_in_eeprom
tmk 10 years ago
parent
commit
9d26053f1c
3 changed files with 12 additions and 13 deletions
  1. 0
    4
      common/print.h
  2. 5
    5
      converter/ps2_usb/matrix.c
  3. 7
    4
      protocol/ps2_busywait.c

+ 0
- 4
common/print.h View File

#endif #endif
#define println(s) print_P(PSTR(s "\n")) #define println(s) print_P(PSTR(s "\n"))


#ifndef AVR_LIBC_PRINTF
#define printf(f, ...) xprintf(f, ##__VA_ARGS__)
#endif

/* for old name */ /* for old name */
#define pdec(data) print_dec(data) #define pdec(data) print_dec(data)
#define pdec16(data) print_dec(data) #define pdec16(data) print_dec(data)

+ 5
- 5
converter/ps2_usb/matrix.c View File

if (code < 0x80) { if (code < 0x80) {
matrix_make(code); matrix_make(code);
} else { } else {
printf("unexpected scan code at INIT: %02X\n", code);
xprintf("unexpected scan code at INIT: %02X\n", code);
clear_keyboard(); clear_keyboard();
} }
state = INIT; state = INIT;
if (code < 0x80) { if (code < 0x80) {
matrix_make(code|0x80); matrix_make(code|0x80);
} else { } else {
printf("unexpected scan code at E0: %02X\n", code);
xprintf("unexpected scan code at E0: %02X\n", code);
clear_keyboard(); clear_keyboard();
} }
state = INIT; state = INIT;
if (code < 0x80) { if (code < 0x80) {
matrix_break(code); matrix_break(code);
} else { } else {
printf("unexpected scan code at F0: %02X\n", code);
xprintf("unexpected scan code at F0: %02X\n", code);
clear_keyboard(); clear_keyboard();
} }
state = INIT; state = INIT;
if (code < 0x80) { if (code < 0x80) {
matrix_break(code|0x80); matrix_break(code|0x80);
} else { } else {
printf("unexpected scan code at E0_F0: %02X\n", code);
xprintf("unexpected scan code at E0_F0: %02X\n", code);
clear_keyboard(); clear_keyboard();
} }
state = INIT; state = INIT;


if (ps2_error > PS2_ERR_STARTBIT3) { if (ps2_error > PS2_ERR_STARTBIT3) {
uint8_t ret = ps2_host_send(PS2_RESEND); uint8_t ret = ps2_host_send(PS2_RESEND);
printf("Resend: %02X\n", ret);
xprintf("Resend: %02X\n", ret);
} }
return 1; return 1;
} }

+ 7
- 4
protocol/ps2_busywait.c View File

WAIT(clock_hi, 50, 8); WAIT(clock_hi, 50, 8);
WAIT(data_hi, 50, 9); WAIT(data_hi, 50, 9);


inhibit();
res = ps2_host_recv_response(); res = ps2_host_recv_response();
ERROR: ERROR:
inhibit(); inhibit();
/* receive data when host want else inhibit communication */ /* receive data when host want else inhibit communication */
uint8_t ps2_host_recv_response(void) uint8_t ps2_host_recv_response(void)
{ {
// TODO:
// Command might take 20ms to response([3]p.21) // Command might take 20ms to response([3]p.21)
// TrackPoint might take 25ms ([5]2.7) // TrackPoint might take 25ms ([5]2.7)
// 250 * 100us(wait for start bit in ps2_host_recv)
uint8_t data = 0; uint8_t data = 0;
uint8_t try = 200;
while (try-- && (data = ps2_host_recv())) ;
uint8_t try = 250;
do {
data = ps2_host_recv();
} while (try-- && ps2_error);
return data; return data;
} }


return data; return data;
ERROR: ERROR:
if (ps2_error > PS2_ERR_STARTBIT3) { if (ps2_error > PS2_ERR_STARTBIT3) {
printf("x%02X\n", ps2_error);
xprintf("x%02X\n", ps2_error);
} }
inhibit(); inhibit();
return 0; return 0;