Library for PMT9123 for Nordic nRF51

Fork of Pixart_OTS_PMT9123 by PixArt Imaging

Committer:
pixus_mbed
Date:
Mon May 08 22:51:47 2017 +0000
Revision:
0:31779183b108
Initial Release for PMT9123 on mbed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pixus_mbed 0:31779183b108 1
pixus_mbed 0:31779183b108 2 /* The callback function when motion happen
pixus_mbed 0:31779183b108 3
pixus_mbed 0:31779183b108 4 */
pixus_mbed 0:31779183b108 5 typedef void (*OTSCallback)(int16_t value);
pixus_mbed 0:31779183b108 6
pixus_mbed 0:31779183b108 7 // Helper macro
pixus_mbed 0:31779183b108 8 #define BIT_CLEAR(REG,MASK) (REG &= ~MASK)
pixus_mbed 0:31779183b108 9 #define BIT_SET(REG,MASK) (REG |= MASK)
pixus_mbed 0:31779183b108 10 #define IS_BIT_CLEAR(REG,MASK) ((REG & MASK)==0x00)
pixus_mbed 0:31779183b108 11 #define IS_BIT_SET(REG,MASK) ((REG & MASK)==MASK)
pixus_mbed 0:31779183b108 12
pixus_mbed 0:31779183b108 13 class Pixart_OTS
pixus_mbed 0:31779183b108 14 {
pixus_mbed 0:31779183b108 15 private:
pixus_mbed 0:31779183b108 16 Ticker m_ticker;
pixus_mbed 0:31779183b108 17 I2C *m_i2c;
pixus_mbed 0:31779183b108 18 //Serial *m_pc;
pixus_mbed 0:31779183b108 19 int m_Period;
pixus_mbed 0:31779183b108 20 uint8_t m_Address;
pixus_mbed 0:31779183b108 21 bool m_WriteEnable;
pixus_mbed 0:31779183b108 22
pixus_mbed 0:31779183b108 23 OTSCallback m_OTSCallback;
pixus_mbed 0:31779183b108 24 void periodicCallback(void);
pixus_mbed 0:31779183b108 25 bool PMT9123_init();
pixus_mbed 0:31779183b108 26 void PMT9123_ReadMotion();
pixus_mbed 0:31779183b108 27
pixus_mbed 0:31779183b108 28 // Internal read and write function that is only single transaction
pixus_mbed 0:31779183b108 29 void writeRegister(uint8_t addr, uint8_t data);
pixus_mbed 0:31779183b108 30 uint8_t readRegister(uint8_t addr);
pixus_mbed 0:31779183b108 31
pixus_mbed 0:31779183b108 32 public:
pixus_mbed 0:31779183b108 33 /*
pixus_mbed 0:31779183b108 34 * The initial function for Gesture class
pixus_mbed 0:31779183b108 35 * i2c ==> The I2C object from outside, the clock rate should be 400k
pixus_mbed 0:31779183b108 36 * Period ==> The polling rate for gesture, in ms
pixus_mbed 0:31779183b108 37 * callback ==> The call back function for gesture status
pixus_mbed 0:31779183b108 38 * Result ==> The result for initialize
pixus_mbed 0:31779183b108 39 */
pixus_mbed 0:31779183b108 40 Pixart_OTS(I2C *i2c, int Period,OTSCallback callback,bool &Result);
pixus_mbed 0:31779183b108 41
pixus_mbed 0:31779183b108 42 // Public register read and write function, which include steps to ensure successful write and read
pixus_mbed 0:31779183b108 43 uint8_t Register_Write(uint8_t addr, uint8_t data);
pixus_mbed 0:31779183b108 44 uint8_t Register_Read(uint8_t addr);
pixus_mbed 0:31779183b108 45 };