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