]> git.friedersdorff.com Git - max/tmk_keyboard.git/commitdiff
Fix ps2_host_recv_response
authortmk <nobody@nowhere>
Tue, 26 Nov 2013 05:31:57 +0000 (14:31 +0900)
committertmk <nobody@nowhere>
Tue, 26 Nov 2013 05:31:57 +0000 (14:31 +0900)
common/print.h
converter/ps2_usb/matrix.c
protocol/ps2_busywait.c

index a828328b6e15c645d36dbe933d1e04c1dab53a52..930e84be99d555871aec946f27cf2c49f909eb76 100644 (file)
 #endif
 #define println(s)              print_P(PSTR(s "\n"))
 
-#ifndef AVR_LIBC_PRINTF
-#define printf(f, ...)          xprintf(f, ##__VA_ARGS__)
-#endif
-
 /* for old name */
 #define pdec(data)              print_dec(data)
 #define pdec16(data)            print_dec(data)
index a4c27f5d5bd1b7ad7e13a41a7a3f42c36960772f..aa0c38c68d56067094e1122364d8efdac334f8ba 100644 (file)
@@ -217,7 +217,7 @@ uint8_t matrix_scan(void)
                         if (code < 0x80) {
                             matrix_make(code);
                         } else {
-                            printf("unexpected scan code at INIT: %02X\n", code);
+                            xprintf("unexpected scan code at INIT: %02X\n", code);
                             clear_keyboard();
                         }
                         state = INIT;
@@ -239,7 +239,7 @@ uint8_t matrix_scan(void)
                         if (code < 0x80) {
                             matrix_make(code|0x80);
                         } else {
-                            printf("unexpected scan code at E0: %02X\n", code);
+                            xprintf("unexpected scan code at E0: %02X\n", code);
                             clear_keyboard();
                         }
                         state = INIT;
@@ -259,7 +259,7 @@ uint8_t matrix_scan(void)
                     if (code < 0x80) {
                         matrix_break(code);
                     } else {
-                        printf("unexpected scan code at F0: %02X\n", code);
+                        xprintf("unexpected scan code at F0: %02X\n", code);
                         clear_keyboard();
                     }
                     state = INIT;
@@ -275,7 +275,7 @@ uint8_t matrix_scan(void)
                         if (code < 0x80) {
                             matrix_break(code|0x80);
                         } else {
-                            printf("unexpected scan code at E0_F0: %02X\n", code);
+                            xprintf("unexpected scan code at E0_F0: %02X\n", code);
                             clear_keyboard();
                         }
                         state = INIT;
@@ -371,7 +371,7 @@ uint8_t matrix_scan(void)
 
     if (ps2_error > PS2_ERR_STARTBIT3) {
         uint8_t ret = ps2_host_send(PS2_RESEND);
-        printf("Resend: %02X\n", ret);
+        xprintf("Resend: %02X\n", ret);
     }
     return 1;
 }
index 1e2925889576df5bc089fd9232b9af8fdf4d2d89..5ab377877ec9a0e3e4e9046f00f03e68c81214a7 100644 (file)
@@ -104,6 +104,7 @@ uint8_t ps2_host_send(uint8_t data)
     WAIT(clock_hi, 50, 8);
     WAIT(data_hi, 50, 9);
 
+    inhibit();
     res = ps2_host_recv_response();
 ERROR:
     inhibit();
@@ -113,12 +114,14 @@ ERROR:
 /* receive data when host want else inhibit communication */
 uint8_t ps2_host_recv_response(void)
 {
-    // TODO:
     // Command might take 20ms to response([3]p.21)
     // TrackPoint might take 25ms ([5]2.7)
+    // 250 * 100us(wait for start bit in ps2_host_recv)
     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;
 }
 
@@ -172,7 +175,7 @@ uint8_t ps2_host_recv(void)
     return data;
 ERROR:
     if (ps2_error > PS2_ERR_STARTBIT3) {
-        printf("x%02X\n", ps2_error);
+        xprintf("x%02X\n", ps2_error);
     }
     inhibit();
     return 0;