A library to interface to the PAW3102DB optical mouse sensor. It cannot write to the sensor as of yet.

Files at this revision

API Documentation at this revision

Comitter:
Pinski1
Date:
Mon Jun 13 19:03:22 2011 +0000
Commit message:
Initial Release, bugs expected

Changed in this revision

PAW3102DB.cpp Show annotated file Show diff for this revision Revisions of this file
PAW3102DB.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r dda73f38c264 PAW3102DB.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PAW3102DB.cpp	Mon Jun 13 19:03:22 2011 +0000
@@ -0,0 +1,55 @@
+#include "PAW3102DB.h"
+#include "mbed.h"
+
+PAW3102DB::PAW3102DB(PinName pMOSI, PinName pMISO, PinName pSCK): sensor(pMOSI, pMISO, pSCK) {
+    MOSI = pMOSI;
+    MISO = pMISO;
+    SCK = pSCK;
+    
+    sensor.frequency(10000000); // set it to 10MHz
+    sensor.format(8, 3); // send 8 bits, change on falling, read on rising
+    sensor.slave_format(8); // 8 bits returned
+}
+
+unsigned char PAW3102DB::read(unsigned char address) {
+    return (char)sensor.write(address & 0x7F);
+}
+
+unsigned short PAW3102DB::getProductID(void) {
+    return (sensor.write(PRODUCT_ID2) << 4) | (sensor.write(PRODUCT_ID3) >> 4);
+}
+
+unsigned short PAW3102DB::getResolution(void) {
+    unsigned short resolution = 0;
+    unsigned char buffer = sensor.write(MOTION_STATUS);
+    buffer = (buffer >> 4) & 0x03;
+    switch (buffer)
+    {
+        case 0:
+            resolution = 1000;
+            break;
+        case 1:
+            resolution = 1200;
+            break;
+        case 2:
+            resolution = 1600;
+            break;
+        case 3:
+            resolution = 800;
+            break;
+        default:
+            break;    
+    }
+    return resolution;
+}
+
+signed char PAW3102DB::getDeltaX(void) {
+    signed char buffer = read(DELTA_X);
+    buffer *= -1; // dirty hack
+    return buffer;     
+}
+signed char PAW3102DB::getDeltaY(void) {
+    signed char buffer = read(DELTA_Y);
+    buffer *= -1; // dirty hack
+    return buffer;   
+}    
diff -r 000000000000 -r dda73f38c264 PAW3102DB.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PAW3102DB.h	Mon Jun 13 19:03:22 2011 +0000
@@ -0,0 +1,46 @@
+
+
+
+
+
+#ifndef MBED_PAW3102DB_H
+#define MBED_PAW3102DB_H
+
+#include "mbed.h"
+
+/* Register Aliases */
+#define CONFIGURATION 0x1B
+#define OPERATION_MODE2 0x1A
+#define IMAGE_QUALITY2 0x19
+#define DELTA_Y2 0x18
+#define DELTA_X2 0x17
+#define MOTION_STATUS 0x16
+#define PRODUCT_ID3 0x15
+#define PRODUCT_ID2 0x14
+#define WRITE_PROTECT 0x12
+#define IMAGE_QUALITY 0x04
+#define DELTA_X 0x03
+#define DELTA_Y 0x02
+#define PRODUCT_ID1 0x01
+#define OPERATION_MODE1 0x00
+
+class PAW3102DB {
+    private:
+        SPIHalfDuplex sensor;
+        PinName MOSI;
+        PinName MISO;
+        PinName SCK;
+        
+    public:
+        PAW3102DB(PinName pMOSI, PinName pMISO, PinName pSCK);
+        unsigned char read(unsigned char address);
+        
+        signed char getDeltaX(void);
+        signed char getDeltaY(void);
+        
+        unsigned short getProductID(void);
+        unsigned short getResolution(void);
+
+};
+
+#endif
\ No newline at end of file