Interface to access to Avago ADNS-9500 laser mouse sensors.

Dependencies:   mbed

Revision:
2:ee0c13ef1320
Parent:
1:fa3052be61b5
Child:
3:898ed1944119
--- a/adns9500.hpp	Mon Feb 13 11:39:24 2012 +0000
+++ b/adns9500.hpp	Thu Mar 22 15:04:33 2012 +0000
@@ -32,18 +32,22 @@
 #define ADNS9500_IF_LASER_FAULT(x)          (bool)(x & 0x40)
 #define ADNS9500_IF_RUNNING_SROM_CODE(x)    (bool)(x & 0x80)
 #define ADNS9500_IF_OBSERVATION_TEST(x)     (bool)(x & ADNS9500_OBSERVATION_CHECK_BITS)
-#define ADNS9500_UINT16(ub, lb)             ((uint16_t)ub << 8 | (uint16_t)lb)
+#define ADNS9500_UINT16(ub, lb)             (((uint16_t)ub << 8) + (uint16_t)lb)
+#define ADNS9500_INT16(ub, lb)              ((((int16_t)(int8_t)ub) << 8) + (int16_t)lb)
 
 namespace adns9500
 {
     // Maximum SPI clock frequency supported by the sensor
-    const int MAX_SPI_FREQUENCY = 2000000;
+    const int MAX_SPI_FREQUENCY = 200;
     
     // Internal oscillator norminal frequency
     const int INTERNAL_OSCILLATOR_FREQUENCY = 47000000;
     
     // Number of pixels per frame
     const int NUMBER_OF_PIXELS_PER_FRAME = 900;
+    
+    // Maximum surface quality
+    const int MAX_SURFACE_QUALITY = 676;    // 169 * 4
 
     //
     // Sensor registers
@@ -101,12 +105,20 @@
     
     struct MotionData
     {
+        MotionData()
+            : motion(0), observation(0), dx(0), dy(0), dxMM(0), dyMM(0),
+              surfaceQuality(0), averagePixel(0), maximumPixel(0),
+              minimumPixel(0), shutter(0), framePeriod(0)
+        {}
+    
         int motion;
         int observation;
         int dx;
         int dy;
-        int squal;
-        int pixelSum;
+        float dxMM;
+        float dyMM;
+        int surfaceQuality;
+        float averagePixel;
         int maximumPixel;
         int minimumPixel;
         int shutter;
@@ -281,12 +293,27 @@
             SPI spi_;
             InterruptIn motion_;
             DigitalOut ncs_;
-            
+
             bool enabled_;            
-            int dx_, dy_;
             int xCpi_, yCpi_;
             
             FunctionPointer motionTrigger_;
+            
+            //
+            // Write a byte to the specified register
+            //
+            // @param address The register address
+            // @param value The value to be written to the register
+            //
+            void spiSend(Register address, int value);
+
+            //
+            // Read a byte from the specified register
+            //
+            // @param address The register address
+            // @return The value of the register
+            //
+            int spiReceive(Register address);
     };
 }