A version of the PS/2 library customized for MbedConsole. Also includes a few things that make it's behavior easier to control and a few bug fixes.

Dependents:   MbedConsole

Fork of PS2 by Shinichiro Nakamura

Revision:
1:823c2798e398
Parent:
0:7ee6afa15d51
--- a/PS2.h	Tue Aug 31 11:25:34 2010 +0000
+++ b/PS2.h	Wed Sep 29 14:11:44 2010 +0000
@@ -9,7 +9,6 @@
 #define _PS2_H_
 
 #include "mbed.h"
-#include "Semaphore.h"
 
 /**
  * PS/2 interface control class.
@@ -19,70 +18,29 @@
     /**
      * Create.
      *
-     * @param clkinpin Input pin for clock.
-     * @param datinpin Input pin for data.
+     * @param clk_pin Clock pin.
+     * @param dat_pin Data pin.
      */
-    PS2(PinName clkin_pin, PinName datin_pin, PinName clkout_pin = NC, PinName datout_pin = NC);
+    PS2(PinName clk_pin, PinName dat_pin);
 
     /**
      * Destory.
      */
-    ~PS2();
-
-    /**
-     * Check exists a data.
-     *
-     * @return true if a data exists.
-     */
-    bool exists(void);
+    virtual ~PS2();
 
     /**
-     * Get a data into a buffer.
+     * Get a data from a PS/2 device.
      *
-     * @param buf A pointer to a buffer.
-     * @param bufsiz A size of the buffer.
-     *
-     * @return Number of a byte size.
+     * @return A data from a PS/2 device.
      */
-    int getData(uint8_t *buf, size_t bufsiz);
-
-private:
-    InterruptIn clkin;
-    DigitalIn datin;
-    DigitalOut clkout;
-    DigitalOut datout;
-    Timeout timeout;
-    Semaphore sem;
-    int writepoint;
-    int readpoint;
-    static const int TIMEOUT_US = 10 * 1000;
-    static const int RINGBUFSIZ = 16;
-    static const int DATABUFSIZ = 32;
+    virtual int getc(void) = 0;
 
-    typedef enum {
-        Idle,
-        Reading,
-        Writing
-    } State;
-
-    typedef struct {
-        State state;
-        int bitcnt;
-        int bytecnt;
-        int errcnt;
-        uint8_t buffer[DATABUFSIZ];
-    } work_t;
-    work_t work;
-
-    typedef struct {
-        int bytecnt;
-        uint8_t buffer[DATABUFSIZ];
-    } data_t;
-    data_t ringbuffer[RINGBUFSIZ];
-
-    void func_timeout(void);
-    void func_fall(void);
-    void init_work(void);
+    /**
+     * Set timeout.
+     *
+     * @param ms Timeout ms.
+     */
+    virtual void setTimeout(int ms) = 0;
 };
 
 #endif