A test program for PS2 library.

Dependencies:   mbed

Revision:
1:e5eac8a97060
Parent:
0:aabf6427c82e
Child:
2:b06d5cea5b11
--- a/main.cpp	Sun Aug 29 11:09:48 2010 +0000
+++ b/main.cpp	Mon Sep 13 23:00:29 2010 +0000
@@ -6,24 +6,61 @@
  */
 
 #include "mbed.h"
-#include "PS2.h"
+#include "PS2_Reader.h"
+#include "PS2_Writer.h"
 
-PS2 ps2kb(p17, p18);
+Ticker tick;
+DigitalOut led(LED1);
+
+void func_tick() {
+    led = !led;
+}
 
 int main() {
+    tick.attach_us(&func_tick, 200 * 1000);
+
+    {
+        PS2_Writer ps2ms_write(p15, p16);
+        ps2ms_write.write(0xff);
+        ps2ms_write.write(0xff);
+        ps2ms_write.write(0xff);
+        ps2ms_write.write(0xf3);
+        ps2ms_write.write(0xc8);
+        ps2ms_write.write(0xf3);
+        ps2ms_write.write(0x64);
+        ps2ms_write.write(0xf3);
+        ps2ms_write.write(0x50);
+        ps2ms_write.write(0xf4);
+    }
+
+    PS2_Reader ps2kb(p11, p12, PS2_Reader::TIMEOUT_US_KEYBOARD);
+    PS2_Reader ps2ms(p15, p16, PS2_Reader::TIMEOUT_US_MOUSE);
+
+    uint8_t buf[1024];
+
     while (1) {
         /*
          * Keyboard.
          */
-        if (ps2kb.exists()) {
-            uint8_t buf[32];
-            int n = ps2kb.getData(buf, sizeof(buf));
-            printf("KB:");
-            for (int i = 0; i < n; i++) {
+        const int nkb = ps2kb.read(buf, sizeof(buf));
+        if (0 < nkb) {
+            printf("KB[%02d]:", nkb);
+            for (int i = 0; i < nkb; i++) {
                 printf("%02X ", buf[i]);
             }
             printf("\n");
         }
-        wait_ms(100);
+        /*
+         * Mouse.
+         */
+        const int nms = ps2ms.read(buf, sizeof(buf));
+        if (0 < nms) {
+            printf("MS[%02d]:", nms);
+            for (int i = 0; i < nms; i++) {
+                printf("%02X ", buf[i]);
+            }
+            printf("\n");
+        }
+        wait_ms(20);
     }
 }