PixArt Optical Finger Navigation, OFN, library for PAW3007 sensor. Initial release v1.0.

Fork of Pixart_OFN by Hill Chen

Files at this revision

API Documentation at this revision

Comitter:
PixArtHC
Date:
Tue Feb 26 18:57:35 2019 +0000
Commit message:
PixArt Optical Finger Navigation, OFN, library for PAW3007 sensor. Initial release v1.0.

Changed in this revision

Build_info.h Show annotated file Show diff for this revision Revisions of this file
Pixart_OFN.cpp Show annotated file Show diff for this revision Revisions of this file
Pixart_OFN.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a4065043fd57 Build_info.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Build_info.h	Tue Feb 26 18:57:35 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  "PIX1762_v1.0"
+#define PRODUCT     "Optical Finger Navigation (OFN)"
+#define MODEL       "PAW3007"
+
+#endif
diff -r 000000000000 -r a4065043fd57 Pixart_OFN.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pixart_OFN.cpp	Tue Feb 26 18:57:35 2019 +0000
@@ -0,0 +1,110 @@
+/* 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(0x7F, 0x00);
+    writeRegister(0x06, 0x82);      //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 a4065043fd57 Pixart_OFN.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pixart_OFN.h	Tue Feb 26 18:57:35 2019 +0000
@@ -0,0 +1,69 @@
+/* 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  (0x33 << 1) //P3003 I2C address, ID1/ID0 = low
+#define I2C_ADDR P_ADDR
+#define PXI_WMI 0x30
+
+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] = {
+    //OFN Engine settings.
+    { 0x09,0x5A }, 
+    { 0x7F,0x01 }, 
+    { 0x23,0x1E }, 
+    { 0x2E,0x48 }, 
+    { 0x7F,0x00 }, 
+    { 0x0D,0x0A },  //IQ_TH
+    { 0x1D,0x1B }, 
+    { 0x2A,0x82 }, 
+    { 0x2B,0x78 }, 
+    { 0x2C,0x50 }, 
+    { 0x2D,0x46 }, 
+    { 0x3D,0xA1 },    
+    { 0x4C,0x90 },
+    { 0x4D,0x18 },  
+    { 0x4F,0x10 }, 
+    { 0x56,0x00 }, 
+    { 0x7A,0x35 }, 
+    { 0x09,0x00 },
+};
+#define initialize_size (sizeof(initialize)/sizeof(initialize[0]))