PS/2

Dependents:   Synth Lab3Translator PS2_Keyboard CLI ... more

Files at this revision

API Documentation at this revision

Comitter:
shintamainjp
Date:
Wed Sep 29 22:15:03 2010 +0000
Parent:
1:823c2798e398
Commit message:

Changed in this revision

PS2KB_INIT.cpp Show annotated file Show diff for this revision Revisions of this file
PS2MS.h Show annotated file Show diff for this revision Revisions of this file
PS2MS_INIT.cpp Show annotated file Show diff for this revision Revisions of this file
PS2Mouse.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 823c2798e398 -r a57bbbec16b1 PS2KB_INIT.cpp
--- a/PS2KB_INIT.cpp	Wed Sep 29 14:11:44 2010 +0000
+++ b/PS2KB_INIT.cpp	Wed Sep 29 22:15:03 2010 +0000
@@ -16,6 +16,13 @@
     clk.write(1);
     dat.write(1);
     
+    /*
+     * 0xFF: Reset.
+     * 0xED: Set/Reset status indicators.
+     * 0xF2: Read ID.
+     * 0xF3: Set typematic rate/delay.
+     * 0xF4: Enable.
+     */
     char txdat[12] = "\xFF\xED\x07\xF2\xED\x00\xF3\x20\xF3\x00\xF4";
     const int n = sizeof(txdat);
     int txerrcnt = 0;
diff -r 823c2798e398 -r a57bbbec16b1 PS2MS.h
--- a/PS2MS.h	Wed Sep 29 14:11:44 2010 +0000
+++ b/PS2MS.h	Wed Sep 29 22:15:03 2010 +0000
@@ -43,7 +43,7 @@
     virtual void setTimeout(int ms);
 
 private:
-    static const int RINGBUFSIZ = 512;
+    static const int RINGBUFSIZ = 1024;
     InterruptIn clk;    /**< Interrupt input for CLK. */
     DigitalIn dat;      /**< Digital input for DAT. */
     Timeout wdt;    /**< Watch dog timer. */
diff -r 823c2798e398 -r a57bbbec16b1 PS2MS_INIT.cpp
--- a/PS2MS_INIT.cpp	Wed Sep 29 14:11:44 2010 +0000
+++ b/PS2MS_INIT.cpp	Wed Sep 29 22:15:03 2010 +0000
@@ -16,6 +16,14 @@
     clk.write(1);
     dat.write(1);
 
+    /*
+     * 0xFF: Reset command.
+     * 0xF3: Set sample rate.
+     * 0xF2: Read device type.
+     * 0xE8: Set resolution.
+     * 0xE6: Set scaling.
+     * 0xF4: Enable device.
+     */
     char txdat[17] = "\xFF\xFF\xFF\xF3\xC8\xF3\x64\xF3\x50\xF2\xE8\x03\xE6\xF3\x28\xF4";
     const int n = sizeof(txdat);
     int txerrcnt = 0;
@@ -27,6 +35,11 @@
         if (recv() < 0) {
             rxerrcnt++;
         }
+        if (txdat[i] == 0xF2) {
+            if (recv() < 0) {
+                rxerrcnt++;
+            }
+        }
         if (txdat[i] == 0xFF) {
             if (recv() < 0) {
                 rxerrcnt++;
diff -r 823c2798e398 -r a57bbbec16b1 PS2Mouse.cpp
--- a/PS2Mouse.cpp	Wed Sep 29 14:11:44 2010 +0000
+++ b/PS2Mouse.cpp	Wed Sep 29 22:15:03 2010 +0000
@@ -16,40 +16,43 @@
 
 bool PS2Mouse::processing(mouse_event_t *p) {
     bool emit = false;
-    const int c = ps2ms.getc();
-    if (0 <= c) {
-        switch (cnt % 4) {
-            case 0:
-                mi.byte1.byte = c;
-                break;
-            case 1:
-                mi.byte2.byte = c;
-                break;
-            case 2:
-                mi.byte3.byte = c;
-                break;
-            case 3:
-                mi.byte4.byte = c;
-#if 0
-                printf("[%c:%c:%c] - (%4d,%4d) - <%d:%3d>\n",
-                       mi.byte1.bit.btnLeft ? 'o' : ' ',
-                       mi.byte1.bit.btnMiddle ? 'o' : ' ',
-                       mi.byte1.bit.btnRight ? 'o' : ' ',
-                       mi.byte1.bit.signX ? (-256 + mi.byte2.byte) : mi.byte2.byte,
-                       mi.byte1.bit.signY ? (-256 + mi.byte3.byte) : mi.byte3.byte,
-                       mi.byte4.bit.signZ,
-                       mi.byte4.bit.signZ ? (-128 + mi.byte4.bit.value) : mi.byte4.bit.value);
-#endif
-                p->left = mi.byte1.bit.btnLeft ? true : false;
-                p->center = mi.byte1.bit.btnCenter ? true : false;
-                p->right = mi.byte1.bit.btnRight ? true : false;
-                p->x = mi.byte1.bit.signX ? (-256 + mi.byte2.byte) : mi.byte2.byte;
-                p->y = mi.byte1.bit.signY ? (-256 + mi.byte3.byte) : mi.byte3.byte;
-                p->z = mi.byte4.bit.signZ ? (-128 + mi.byte4.bit.value) : mi.byte4.bit.value;
-                emit = true;
-                break;
+    for (int i = 0; i < 4; i++) {
+        const int c = ps2ms.getc();
+        if (0 <= c) {
+            switch (cnt % 4) {
+                case 0:
+                    mi.byte1.byte = c;
+                    /*
+                     * Check and reset a buffer if state is wrong.
+                     */
+                    if (mi.byte1.bit.always1 == 0) {
+                        cnt = 0;
+                        while (0 <= ps2ms.getc()) {
+                        }
+                    }
+                    break;
+                case 1:
+                    mi.byte2.byte = c;
+                    break;
+                case 2:
+                    mi.byte3.byte = c;
+                    break;
+                case 3:
+                    mi.byte4.byte = c;
+                    /*
+                     * Store a event data.
+                     */
+                    p->left = mi.byte1.bit.btnLeft ? true : false;
+                    p->center = mi.byte1.bit.btnCenter ? true : false;
+                    p->right = mi.byte1.bit.btnRight ? true : false;
+                    p->x = mi.byte1.bit.signX ? (-256 + mi.byte2.byte) : mi.byte2.byte;
+                    p->y = mi.byte1.bit.signY ? (-256 + mi.byte3.byte) : mi.byte3.byte;
+                    p->z = mi.byte4.bit.signZ ? (-128 + mi.byte4.bit.value) : mi.byte4.bit.value;
+                    emit = true;
+                    break;
+            }
+            cnt++;
         }
-        cnt++;
     }
     return emit;
 }