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.
Fork of PS2 by
PS2.h
- Committer:
- shintamainjp
- Date:
- 2010-08-31
- Revision:
- 0:7ee6afa15d51
- Child:
- 1:823c2798e398
File content as of revision 0:7ee6afa15d51:
/** * PS/2 interface control class (Version 0.0.1) * * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) * http://shinta.main.jp/ */ #ifndef _PS2_H_ #define _PS2_H_ #include "mbed.h" #include "Semaphore.h" /** * PS/2 interface control class. */ class PS2 { public: /** * Create. * * @param clkinpin Input pin for clock. * @param datinpin Input pin for data. */ PS2(PinName clkin_pin, PinName datin_pin, PinName clkout_pin = NC, PinName datout_pin = NC); /** * Destory. */ ~PS2(); /** * Check exists a data. * * @return true if a data exists. */ bool exists(void); /** * Get a data into a buffer. * * @param buf A pointer to a buffer. * @param bufsiz A size of the buffer. * * @return Number of a byte size. */ 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; 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); }; #endif