PS2 keyboard

Dependents:   uVGAII_WebBrowser

Committer:
yaolu23
Date:
Wed Mar 12 16:15:14 2014 +0000
Revision:
0:33c8907eb27a
na

Who changed what in which revision?

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