PS2 Library

Dependents:   Pong Brickbreaker

Committer:
wjohnsto
Date:
Sun Feb 27 23:34:31 2011 +0000
Revision:
0:ce15490e89e9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wjohnsto 0:ce15490e89e9 1 /**
wjohnsto 0:ce15490e89e9 2 * PS/2 mouse interface control class (Version 0.0.1)
wjohnsto 0:ce15490e89e9 3 *
wjohnsto 0:ce15490e89e9 4 * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems)
wjohnsto 0:ce15490e89e9 5 * http://shinta.main.jp/
wjohnsto 0:ce15490e89e9 6 */
wjohnsto 0:ce15490e89e9 7
wjohnsto 0:ce15490e89e9 8 #ifndef _PS2MS_H_
wjohnsto 0:ce15490e89e9 9 #define _PS2MS_H_
wjohnsto 0:ce15490e89e9 10
wjohnsto 0:ce15490e89e9 11 #include "mbed.h"
wjohnsto 0:ce15490e89e9 12
wjohnsto 0:ce15490e89e9 13 /**
wjohnsto 0:ce15490e89e9 14 * PS/2 mouse interface control class.
wjohnsto 0:ce15490e89e9 15 */
wjohnsto 0:ce15490e89e9 16 class PS2MS {
wjohnsto 0:ce15490e89e9 17 public:
wjohnsto 0:ce15490e89e9 18 /**
wjohnsto 0:ce15490e89e9 19 * Create.
wjohnsto 0:ce15490e89e9 20 *
wjohnsto 0:ce15490e89e9 21 * @param clk_pin Clock pin.
wjohnsto 0:ce15490e89e9 22 * @param dat_pin Data pin.
wjohnsto 0:ce15490e89e9 23 */
wjohnsto 0:ce15490e89e9 24 PS2MS(PinName clk_pin, PinName dat_pin);
wjohnsto 0:ce15490e89e9 25
wjohnsto 0:ce15490e89e9 26 /**
wjohnsto 0:ce15490e89e9 27 * Destory.
wjohnsto 0:ce15490e89e9 28 */
wjohnsto 0:ce15490e89e9 29 virtual ~PS2MS();
wjohnsto 0:ce15490e89e9 30
wjohnsto 0:ce15490e89e9 31 /**
wjohnsto 0:ce15490e89e9 32 * Get a data from a PS/2 device.
wjohnsto 0:ce15490e89e9 33 *
wjohnsto 0:ce15490e89e9 34 * @return A data from a PS/2 device.
wjohnsto 0:ce15490e89e9 35 */
wjohnsto 0:ce15490e89e9 36 virtual int getc(void);
wjohnsto 0:ce15490e89e9 37
wjohnsto 0:ce15490e89e9 38 /**
wjohnsto 0:ce15490e89e9 39 * Set timeout.
wjohnsto 0:ce15490e89e9 40 *
wjohnsto 0:ce15490e89e9 41 * @param ms Timeout ms.
wjohnsto 0:ce15490e89e9 42 */
wjohnsto 0:ce15490e89e9 43 virtual void setTimeout(int ms);
wjohnsto 0:ce15490e89e9 44
wjohnsto 0:ce15490e89e9 45 private:
wjohnsto 0:ce15490e89e9 46 static const int RINGBUFSIZ = 1024;
wjohnsto 0:ce15490e89e9 47 InterruptIn clk; /**< Interrupt input for CLK. */
wjohnsto 0:ce15490e89e9 48 DigitalIn dat; /**< Digital input for DAT. */
wjohnsto 0:ce15490e89e9 49 Timeout wdt; /**< Watch dog timer. */
wjohnsto 0:ce15490e89e9 50 Timer tot; /**< Timeout timer. */
wjohnsto 0:ce15490e89e9 51 int timeout; /**< Timeout[ms] for getc(). */
wjohnsto 0:ce15490e89e9 52
wjohnsto 0:ce15490e89e9 53 typedef struct {
wjohnsto 0:ce15490e89e9 54 int bitcnt;
wjohnsto 0:ce15490e89e9 55 int cStart;
wjohnsto 0:ce15490e89e9 56 int cEnd;
wjohnsto 0:ce15490e89e9 57 uint8_t buffer[RINGBUFSIZ];
wjohnsto 0:ce15490e89e9 58 } work_t;
wjohnsto 0:ce15490e89e9 59 work_t work;
wjohnsto 0:ce15490e89e9 60
wjohnsto 0:ce15490e89e9 61 void func_timeout(void);
wjohnsto 0:ce15490e89e9 62 void func_fall(void);
wjohnsto 0:ce15490e89e9 63
wjohnsto 0:ce15490e89e9 64 void init_work(void);
wjohnsto 0:ce15490e89e9 65 };
wjohnsto 0:ce15490e89e9 66
wjohnsto 0:ce15490e89e9 67 #endif