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
Handy Table of ProxFusion Device Features
ALS = Ambient Light Sensor PIR = Passive Infrared
Revision 0:ce75ae1e8fc7, committed 2017-02-04
- Comitter:
- AzqDev
- Date:
- Sat Feb 04 07:19:09 2017 +0000
- Child:
- 1:2f08ab339e17
- Commit message:
- Initial commit
Changed in this revision
| IQS62x.cpp | Show annotated file Show diff for this revision Revisions of this file |
| IQS62x.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IQS62x.cpp Sat Feb 04 07:19:09 2017 +0000
@@ -0,0 +1,55 @@
+// A class library for Azoteq IQS62x devices
+#include "IQS62x.h"
+
+// constructor
+IQS62xIO::IQS62xIO() :
+ i2c( IQS_I2C_DATA_PIN, IQS_I2C_CLOCK_PIN ), // first run the constructor for mbed class I2C
+ IQSready( IQS_READY_PIN ) // first run the constructor for mbed class DigitalIn
+{
+ registers = I2CBuffer; // pointer to the receive buffer
+ I2CErrorCount = 0; // reset I2C error count
+ i2c.frequency( I2Cspeed ); // I2C clock frequency
+}
+
+// write some configuration data to the IQS62x
+void IQS62xIO::configure() {
+ const static char system_register_setup_data [] = { 0xd0, 0x40 };
+ int numberOfBytes = sizeof( system_register_setup_data );
+ waitForReady();
+ // clear the reset bit in register 0xd0
+ if(0!=i2c.write(I2C_ADR,system_register_setup_data,numberOfBytes,false))
+ I2CErrorCount++;
+}
+
+// read all registers from the IQS62x
+void IQS62xIO::readAll() {
+ waitForReady();
+ const static char i2c_start_address [] = { 0x0 };
+ int numberOfBytes = sizeof( i2c_start_address );
+ // write 0 to the IQS62x address register
+ if(0!=i2c.write(I2C_ADR,i2c_start_address,numberOfBytes,false))
+ I2CErrorCount++;
+ waitForReady();
+ memset(I2CBuffer,0x55,I2CBufferSize); // "clear" i2c receive buffer
+ numberOfBytes = NUMBER_OF_REGISTERS;
+ // read register values into a buffer
+ if(0!=i2c.read(I2C_ADR,I2CBuffer,numberOfBytes,false))
+ I2CErrorCount++;
+}
+
+// wait for IQS62x to provide a ready signal (low) on IQS62x_ready pin
+void IQS62xIO::waitForReady() {
+ int timeout=0;
+ while (1) {
+ if(IQSready==1) break;
+ if (timeout++ > 1000000) goto fatal_error;
+ }
+ timeout=0;
+ while (1) {
+ if(IQSready==0) break;
+ if (timeout++ > 1000000) goto fatal_error;
+ }
+ return;
+ fatal_error:
+ error ("Fatal Error: IQS62x ready pin is not toggling");
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/IQS62x.h Sat Feb 04 07:19:09 2017 +0000
@@ -0,0 +1,29 @@
+// A class library for Azoteq IQS62x devices
+#include "mbed.h"
+
+// Verify these 3 pin definitions if your hardware is not on the list of tested boards
+// If your board has an Arduino interface the definitions below will likely work
+
+#define IQS_I2C_CLOCK_PIN I2C_SCL /* on NUCLEO boards this is marked as SCL/D15 on CN5 */
+#define IQS_I2C_DATA_PIN I2C_SDA /* on NUCLEO boards this is marked as SDA/D14 on CN5 */
+#define IQS_READY_PIN D2 /* on NUCLEO boards this is marked as D2 on CN9 */
+
+#define I2C_ADR (0x44 << 1) /* I2C address of IQS62x */
+#define I2CSPEED 100000 /* I2C clock speed */
+#define NUMBER_OF_REGISTERS 224 /* number of registers to read from IQS62x */
+#define I2CBufferSize 256 /* size of I2C read buffer */
+
+class IQS62xIO { // basic IQS62x block read and write
+ public:
+ I2C i2c; // I2C interface
+ DigitalIn IQSready; // ready pin
+ const static int I2Cspeed = I2CSPEED; // I2C clock rate
+ int I2CErrorCount; // number of I2C errors
+ char I2CBuffer [I2CBufferSize]; // I2C read buffer
+ char * registers; // pointer to I2C read buffer
+ IQS62xIO(); // constructor
+
+ void configure(); // write configuration registers of the IQS62x
+ void readAll(); // read all registers from the IQS62x
+ void waitForReady(); // wait for IQS62x ready signal
+};
\ No newline at end of file
IQS624
IQS620A
IQS620A-EVAL-1
IQS621
IQS621-EVAL-1
IQS622
IQS622-EVAL-1
IQS624-EVAL-1