Driver for the AT42QT1070

Files at this revision

API Documentation at this revision

Comitter:
messi1
Date:
Tue Dec 22 21:45:00 2015 +0000
Parent:
1:38001f05dab3
Commit message:
The driver is now working

Changed in this revision

include/at42qt1070.h Show annotated file Show diff for this revision Revisions of this file
src/at42qt1070.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/include/at42qt1070.h	Sun Dec 20 19:38:45 2015 +0000
+++ b/include/at42qt1070.h	Tue Dec 22 21:45:00 2015 +0000
@@ -34,8 +34,6 @@
 #define AT42QT1070_I2C_BUS 0
 #define AT42QT1070_DEFAULT_I2C_ADDR 0x1b
 
-namespace upm
-{
 /**
  * @brief Atmel* AT42QT1070 QTouch* Sensor library
  * @defgroup at42qt1070 libupm-at42qt1070
@@ -126,18 +124,18 @@
         REG_DI5 = 51,
         REG_DI6 = 52,
 
-        REG_GUARD = 53, // FastOutDI/Max Cal/Guard channel
-        REG_LP = 54,    // low power
-        REG_MAXON = 55, // max on duration
+        REG_GUARD     = 53, // FastOutDI/Max Cal/Guard channel
+        REG_LP        = 54, // low power
+        REG_MAXON     = 55, // max on duration
         REG_CALIBRATE = 56,
-        REG_RESET = 57
+        REG_RESET     = 57
     } AT42QT1070_REG_T;
 
     // detection register bits
     typedef enum {
-        DET_TOUCH = 0x01,
+        DET_TOUCH     = 0x01,
         // 0x02-0x20 reserved
-        DET_OVERFLOW = 0x40,
+        DET_OVERFLOW  = 0x40,
         DET_CALIBRATE = 0x80
     } AT42QT1070_DET_T;
 
@@ -148,7 +146,7 @@
      * @param bus I2C bus to use
      * @param address Address for this sensor
      */
-    AT42QT1070(PinName sda, PinName sck, int bus, uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR);
+    AT42QT1070(PinName sda, PinName sck, uint8_t address = AT42QT1070_DEFAULT_I2C_ADDR);
 
     /**
      * AT42QT1070 destructor
@@ -302,4 +300,3 @@
     mbed::I2C        _i2cPort;
     uint8_t          _addr;
 };
-}
\ No newline at end of file
--- a/src/at42qt1070.cpp	Sun Dec 20 19:38:45 2015 +0000
+++ b/src/at42qt1070.cpp	Tue Dec 22 21:45:00 2015 +0000
@@ -29,18 +29,16 @@
 
 #include "at42qt1070.h"
 
-using namespace upm;
 using namespace std;
 
 const uint8_t AVE_KEY_MAX = 6;
 const uint8_t AKS_KEY_MAX = 3;
  
 
-AT42QT1070::AT42QT1070(PinName sda, PinName scl, int bus, uint8_t address):
-_i2cPort(sda, scl)
+AT42QT1070::AT42QT1070(PinName sda, PinName scl, uint8_t address)
+    :_i2cPort(sda, scl),
+    _addr(address<<1)
 {
-    _addr = address;
-
     _i2cPort.frequency(400000);
 
     if (readChipID() != 0x2E) {
@@ -48,8 +46,8 @@
     }
 
     _buttonStates = 0;
-    _calibrating = false;
-    _overflow = false;
+    _calibrating  = false;
+    _overflow     = false;
 }
 
 //--------------------------------------------------------------------------------
@@ -85,7 +83,7 @@
 {    
     char data = 0;
     const char cmd = reg;
-    _i2cPort.write(_addr, &cmd, 1, true );
+    _i2cPort.write(_addr, &cmd, 1);
     _i2cPort.read(_addr, &data, 1);
     
     return data;
@@ -98,7 +96,7 @@
     char data[]  = {0, 0};
     const char cmd = reg;
     
-    _i2cPort.write(_addr, &cmd, 1, true );
+    _i2cPort.write(_addr, &cmd, 1);
     _i2cPort.read(_addr, data, 2);  
     res = data[1]<<8 & data[0];