PixArt Optical Finger Navigation, OFN, library for A350 sensor. Initial release v1.0.
Fork of Pixart_OFN_A by
Revision 0:4237dc1f43b4, committed 2019-02-27
- Comitter:
- PixArtHC
- Date:
- Wed Feb 27 21:08:43 2019 +0000
- Commit message:
- PixArt Optical Finger Navigation, OFN, library for A350 sensor. Initial release v1.0.
Changed in this revision
diff -r 000000000000 -r 4237dc1f43b4 Build_info.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Build_info.h Wed Feb 27 21:08:43 2019 +0000 @@ -0,0 +1,12 @@ +#ifndef __BUILD_INFO_H__ +#define __BUILD_INFO_H__ + +//#define DEBUG +//#define USE_CALLBACK + +#define FW_VERSION "v1.0" +#define HW_VERSION "P-AFX-5049M-02-Rev1" +#define PRODUCT "Optical Finger Navigation (OFN)" +#define MODEL "A350" + +#endif
diff -r 000000000000 -r 4237dc1f43b4 Pixart_OFN.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pixart_OFN.cpp Wed Feb 27 21:08:43 2019 +0000 @@ -0,0 +1,109 @@ +/* PixArt Optical Finger Navigation, OFN, sensor driver. + * By PixArt Imaging Inc. + * Primary Engineer: Hill Chen (PixArt USA) + * + * License: Apache-2.0; http://www.apache.org/licenses/LICENSE-2.0 + */ + +#include "mbed.h" +#include "Pixart_OFN.h" + +//Pixart_OFN::Pixart_OFN(I2C *i2c, float Period, bool &Result){ +Pixart_OFN::Pixart_OFN(I2C *i2c, Serial *pc, float Period, bool &Result){ + m_pc = pc; + pc->baud (115200); wait_ms(500); + + DEBUG_PRINT("\r\n >> Constructor"); + print_build_info(); + + m_i2c = i2c; + m_i2c->frequency(400000); + + m_Period = Period; + + Result = Sensor_Init(); + + DEBUG_PRINT("\r\n << Constructor"); +} + +bool Pixart_OFN::Sensor_Init(){ + DEBUG_PRINT("\r\n >> Sensor Init"); + + writeRegister(0x3A, 0x5A); //Soft-reset the chip. + if(readRegister(0x00) != PXI_WMI){ + DEBUG_PRINT("\r\n << Sensor_Init (Fail)"); + return false; + } + + totalX = 0; totalY = 0; + load(initialize, initialize_size); +#ifdef USE_CALLBACK + m_ticker.attach(callback(this, &Pixart_OFN::periodicCallback), m_Period); +#endif + DEBUG_PRINT("\r\n << Sensor_Init (Success)"); + + return true; +} + +void Pixart_OFN::periodicCallback(){ + DEBUG_PRINT("\r\n >> Callback"); + + if(readRegister(0x02) & 0x80){ + grabData(); + printData(); + } + + DEBUG_PRINT("\r\n << Callback"); +} + +void Pixart_OFN::writeRegister(uint8_t addr, uint8_t data){ + char data_write[2]; + + data_write[0] = addr; + data_write[1] = data; + m_i2c->write(I2C_ADDR, data_write, 2, 0); +} + +uint8_t Pixart_OFN::readRegister(uint8_t addr){ + char data_write[2]; + char data_read[2]; + + data_write[0] = addr; + m_i2c->write(I2C_ADDR, data_write, 1, 0); + m_i2c->read(I2C_ADDR, data_read, 1, 0); + + return data_read[0]; +} + +void Pixart_OFN::load(const uint8_t array[][2], uint8_t arraySize){ + for(uint8_t q = 0; q < arraySize; q++) + { + writeRegister(array[q][0], array[q][1]); //Writes the given array of registers/data. + } +} + +void Pixart_OFN::grabData(void){ + deltaX = readRegister(0x03); //Grabs data from the proper registers. + deltaY = readRegister(0x04); + writeRegister(0x02, 0x00); //Clear EVENT and motion registers. +} + +void Pixart_OFN::printData(void){ + if((deltaX != 0) || (deltaY != 0)) //If there is deltaX or deltaY movement, print the data. + { + totalX += deltaX; + totalY += deltaY; + + m_pc->printf("deltaX: %d\t\t\tdeltaY: %d\n\r", deltaX, deltaY); //Prints each individual count of deltaX and deltaY. + m_pc->printf("X-axis Counts: %d\t\tY-axis Counts: %d\n\r", totalX, totalY); //Prints the total movement made during runtime. + } + + deltaX = 0; //Resets deltaX and Y values to zero, otherwise previous data is stored until overwritten. + deltaY = 0; +} + +void Pixart_OFN::print_build_info(){ + m_pc->printf("\r\n\n PixArt Mbed eval code, %s, %s", PRODUCT, MODEL); + m_pc->printf("\r\n Fw version: %s, Hw version: %s, mbed version: %d", FW_VERSION, HW_VERSION, MBED_VERSION); + m_pc->printf("\r\n Build time: %s %s\r\n", __TIME__, __DATE__); +}
diff -r 000000000000 -r 4237dc1f43b4 Pixart_OFN.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pixart_OFN.h Wed Feb 27 21:08:43 2019 +0000 @@ -0,0 +1,52 @@ +/* PixArt Optical Finger Navigation, OFN, sensor driver. + * By PixArt Imaging Inc. + * Primary Engineer: Hill Chen (PixArt USA) + * + * License: Apache-2.0; http://www.apache.org/licenses/LICENSE-2.0 + */ + +#include "Build_info.h" + +#ifdef DEBUG + #define DEBUG_PRINT(...) m_pc->printf(__VA_ARGS__) +#else + #define DEBUG_PRINT(...) {} +#endif + +#define P_ADDR (0x57 << 1) //A350 I2C address, A1/A0 = high +#define I2C_ADDR P_ADDR +#define PXI_WMI 0x88 + +class Pixart_OFN +{ + private: + Serial *m_pc; + I2C *m_i2c; + Ticker m_ticker; + float m_Period; + + int8_t deltaX, deltaY; + int totalX, totalY; + + bool Sensor_Init(); + //void periodicCallback(); + + void writeRegister(uint8_t addr, uint8_t data); + uint8_t readRegister(uint8_t addr); + + void load(const uint8_t array[][2], uint8_t arraySize); + void grabData(void); + void printData(void); + + public: + Pixart_OFN(I2C *i2c, float Period, bool &Result); + Pixart_OFN(I2C *i2c, Serial *pc, float Period, bool &Result); + void periodicCallback(); + void print_build_info(); +}; + +const uint8_t initialize[][2] = { + { 0xC9, 0x61 }, //OFN Engine settings. + //{ 0x6C, 0xA0 }, //Set GPIO pin as button input. +}; +#define initialize_size (sizeof(initialize)/sizeof(initialize[0]))