Library to read and write Azoteq IQS6xx device registers via I2C.

Dependents:   IQS620_HelloWorld IQS622_HelloWorld IQS624_HelloWorld IQS621_HelloWorld ... more

Library: IQS62x

Library to read and write Azoteq IQS6xx device registers via I2C.

Supported Devices

Components / IQS620A
Ultra low power sensor for magnetic field, capacitive touch and inductive proximity. Empowers next-generation user interfaces.

Components / IQS621
Azoteq IQS621 ultra low power sensor for ambient light, magnetic field, capacitance and inductive proximity. Empowers next-generation user interfaces.

Components / IQS622
Azoteq IQS622 ultra low power sensor for ambient light, active (reflective) IR, magnetic field, capacitance and inductive proximity. Empowers next-generation user interfaces.

Components / IQS624
Ultra low power sensor for rotating magnetic field, capacitive touch, and inductive proximity. Empowers next-generation user interfaces.

Handy Table of ProxFusion Device Features


ALS = Ambient Light Sensor PIR = Passive Infrared

/media/uploads/AzqDev/mbed-azoteq-proxfusion-handy-table-of-product-features.jpg

Revision:
14:2514595e2753
Parent:
13:71f8ee16a3a1
Child:
15:6a2f52b5ac46
--- a/IQS62x.cpp	Sat May 13 09:26:47 2017 +0000
+++ b/IQS62x.cpp	Sat May 13 10:12:37 2017 +0000
@@ -15,14 +15,16 @@
 {
     registers = I2CBuffer; // pointer to the receive buffer
     I2CErrorCount = 0; // reset I2C error count
+    IQSframes = 0; // reset number of reads
     i2c.frequency( I2Cspeed ); // I2C clock frequency
 
     // this uses memory but is very handy in diagnostics
-    memset(writeFlag,    0, I2CBufferSize); // a table to remmber if we wrote to a register
-    memset(lastWrite,    0, I2CBufferSize); // a table to remember what we wrote to a register
-    memset(lastRead,     0, I2CBufferSize); // a table to remmber what we read the previous read cycle
-    memset(readChanges,  0, I2CBufferSize); // a table to mark up any registers that changed since the previous read
-    memset(writeChanges, 0, I2CBufferSize); // a table to mark up any registers that differs from what was written to it
+    memset(writeFlag,        0, I2CBufferSize); // a table to remmber if we wrote to a register
+    memset(lastWrite,        0, I2CBufferSize); // a table to remember what we wrote to a register
+    memset(lastRead,         0, I2CBufferSize); // a table to remmber what we read the previous read cycle
+    memset(readChanges,      0, I2CBufferSize); // a table to mark up any registers that changed since the previous read
+    memset(readChangesEver,  0, I2CBufferSize); // a table to mark up any registers that changed BUT never forget
+    memset(writeChanges,     0, I2CBufferSize); // a table to mark up any registers that differs from what was written to it
 }
 
 // write a single byte to an IQS62x register
@@ -53,6 +55,7 @@
 void IQS62xIO::readIqsRegisters(int start, int count)
 {
     memset(I2CBuffer,0x55,I2CBufferSize); // "clear" i2c receive buffer
+    IQSframes++; // count frames
     waitForIqsReady();
     char i2c_start_address [1];
     i2c_start_address[0] = start & 0xff;
@@ -72,14 +75,16 @@
     // we build two tables:
     // writeChanges[i] is set to 1 if the register content differs from what we wrote to it
     // readChanges[i] is set to 1 if the register value differs from the previously read value
+    if (IQSframes < 20) memset(readChangesEver,0,I2CBufferSize); // clear this until we have had 20 full reads
     for(int i=0; i<I2CBufferSize; i++) {
         if (writeFlag[i] == 1) { // only if we previously wrote to this register we check it
             if( I2CBuffer[i] != lastWrite[i] ) 
             writeChanges[i]=1; // if register different from what we wrote, mark it
         }
-        if ( I2CBuffer[i] != lastRead[i] )
+        if ( I2CBuffer[i] != lastRead[i] ) {
             readChanges[i]=20; // if register differs from previous read, highlight it for 20 read cycles
-        else {
+            if (readChangesEver[i] < 127) readChangesEver[i]++; // count changes up to 127 and never forget
+        } else {
             if (readChanges[i] > 0) readChanges[i]--; // bring it closer to zero
         }
     }