1
0

Fix ps2_host_recv_response

This commit is contained in:
tmk 2013-11-26 14:31:57 +09:00
parent 084bdb977e
commit 00c71f2d21
2 changed files with 7 additions and 8 deletions

View File

@ -40,10 +40,6 @@
#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)

View File

@ -104,6 +104,7 @@ uint8_t ps2_host_send(uint8_t data)
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();
@ -113,12 +114,14 @@ ERROR:
/* 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; uint8_t try = 250;
while (try-- && (data = ps2_host_recv())) ; do {
data = ps2_host_recv();
} while (try-- && ps2_error);
return data; return data;
} }
@ -172,7 +175,7 @@ uint8_t ps2_host_recv(void)
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;