]> git.friedersdorff.com Git - max/tmk_keyboard.git/blobdiff - protocol/ps2.c
Add build options of ps2_mouse
[max/tmk_keyboard.git] / protocol / ps2.c
index 8a05916210d77b4741c060c543a45fad75a102e2..4c6c2fcb27b379b3e37b0f8e8adc5e66e237c5af 100644 (file)
@@ -89,8 +89,9 @@ uint8_t ps2_error = PS2_ERR_NONE;
 
 void ps2_host_init(void)
 {
-#ifdef PS2_INT_ENABLE
-    PS2_INT_ENABLE();
+#ifdef PS2_USE_INT
+    PS2_INT_INIT();
+    PS2_INT_ON();
     idle();
 #else
     inhibit();
@@ -103,17 +104,17 @@ uint8_t ps2_host_send(uint8_t data)
     uint8_t res = 0;
     bool parity = true;
     ps2_error = PS2_ERR_NONE;
-#ifdef PS2_INT_DISABLE
-    PS2_INT_DISABLE();
+#ifdef PS2_USE_INT
+    PS2_INT_OFF();
 #endif
     /* terminate a transmission if we have */
     inhibit();
-    _delay_us(100);
+    _delay_us(200); // at least 100us
 
     /* start bit [1] */
     data_lo();
     clock_hi();
-    WAIT(clock_lo, 15000, 1);
+    WAIT(clock_lo, 20000, 10);   // may take 15ms at most until device starts clocking
     /* data [2-9] */
     for (uint8_t i = 0; i < 8; i++) {
         _delay_us(15);
@@ -144,8 +145,8 @@ uint8_t ps2_host_send(uint8_t data)
 
     res = ps2_host_recv_response();
 ERROR:
-#ifdef PS2_INT_ENABLE
-    PS2_INT_ENABLE();
+#ifdef PS2_USE_INT
+    PS2_INT_ON();
     idle();
 #else
     inhibit();
@@ -166,21 +167,21 @@ uint8_t ps2_host_recv_response(void)
     idle();
 
     /* wait start bit */
-    wait_clock_lo(2000);
+    wait_clock_lo(25000);    // command response may take 20 ms at most
     data = recv_data();
 
     inhibit();
     return data;
 }
 
-#ifndef PS2_INT_VECT
+#ifndef PS2_USE_INT
 uint8_t ps2_host_recv(void)
 {
     return ps2_host_recv_response();
 }
 #else
 /* ring buffer to store ps/2 key data */
-#define PBUF_SIZE 8
+#define PBUF_SIZE 32
 static uint8_t pbuf[PBUF_SIZE];
 static uint8_t pbuf_head = 0;
 static uint8_t pbuf_tail = 0;