PMT9123 OTS on Nucleo (Initial Release)

Fork of Pixart_9123_Nucleo_Library by PixArt Imaging

Committer:
pixus_mbed
Date:
Thu May 11 17:32:04 2017 +0000
Revision:
0:7aefc9ab3301
PMT9123 OTS on Nucleo (Initial Release)

Who changed what in which revision?

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