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

Committer:
mventer
Date:
Wed Mar 21 05:56:22 2018 +0000
Revision:
20:7eb08a52b954
Parent:
18:b85048ec91d2
For use with IQS621_DualPIR_ALS_Temp. Added output line to toggle and corrected spelling in some comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AzqDev 0:ce75ae1e8fc7 1 // A class library for Azoteq IQS62x devices
AzqDev 3:e26d7c502309 2
AzqDev 17:2d46eabb129e 3 // More info on IQS62x sensor ICs: http://www.azoteq.com/products/proxfusion?mbed
AzqDev 3:e26d7c502309 4
AzqDev 18:b85048ec91d2 5 // ProxFusion 5-minute YouTube video: http://bit.ly/proxfusion-video
AzqDev 6:89bdb6f6a5c1 6
AzqDev 0:ce75ae1e8fc7 7 #include "mbed.h"
AzqDev 0:ce75ae1e8fc7 8
AzqDev 0:ce75ae1e8fc7 9 // Verify these 3 pin definitions if your hardware is not on the list of tested boards
AzqDev 0:ce75ae1e8fc7 10
AzqDev 1:2f08ab339e17 11 #if defined (TARGET_LPC1768) || defined (TARGET_LPC11U24)
AzqDev 2:c16cb655d4a4 12 #define IQS_I2C_CLOCK_PIN p27 /* on LPC1768/LPC11U24 this is marked as p10 */
AzqDev 2:c16cb655d4a4 13 #define IQS_I2C_DATA_PIN p28 /* on LPC1768/LPC11U24 this is marked as p9 */
AzqDev 2:c16cb655d4a4 14 #define IQS_READY_PIN p26 /* on LPC1768/LPC11U24 this is marked as p8 */
AzqDev 2:c16cb655d4a4 15
AzqDev 1:2f08ab339e17 16 #else
AzqDev 4:60e891546590 17 // If your board has an Arduino interface the definitions below will likely work, also works for Teensy
AzqDev 0:ce75ae1e8fc7 18 #define IQS_I2C_CLOCK_PIN I2C_SCL /* on NUCLEO boards this is marked as SCL/D15 on CN5 */
mventer 20:7eb08a52b954 19 //#define IQS_I2C_CLOCK_PIN PA_9 /* on NUCLEO boards this is marked as SCL/D15 on CN5 */
AzqDev 0:ce75ae1e8fc7 20 #define IQS_I2C_DATA_PIN I2C_SDA /* on NUCLEO boards this is marked as SDA/D14 on CN5 */
mventer 20:7eb08a52b954 21 //#define IQS_I2C_DATA_PIN PA_10 /* on NUCLEO boards this is marked as SDA/D14 on CN5 */
AzqDev 0:ce75ae1e8fc7 22 #define IQS_READY_PIN D2 /* on NUCLEO boards this is marked as D2 on CN9 */
mventer 20:7eb08a52b954 23 //#define IQS_READY_PIN PA_12 /* on NUCLEO boards this is marked as D2 on CN9 */
AzqDev 1:2f08ab339e17 24 #endif
AzqDev 0:ce75ae1e8fc7 25
AzqDev 0:ce75ae1e8fc7 26 #define I2C_ADR (0x44 << 1) /* I2C address of IQS62x */
AzqDev 0:ce75ae1e8fc7 27 #define I2CSPEED 100000 /* I2C clock speed */
AzqDev 0:ce75ae1e8fc7 28 #define NUMBER_OF_REGISTERS 224 /* number of registers to read from IQS62x */
AzqDev 0:ce75ae1e8fc7 29 #define I2CBufferSize 256 /* size of I2C read buffer */
AzqDev 0:ce75ae1e8fc7 30
AzqDev 0:ce75ae1e8fc7 31 class IQS62xIO { // basic IQS62x block read and write
AzqDev 0:ce75ae1e8fc7 32 public:
AzqDev 0:ce75ae1e8fc7 33 I2C i2c; // I2C interface
AzqDev 0:ce75ae1e8fc7 34 DigitalIn IQSready; // ready pin
AzqDev 0:ce75ae1e8fc7 35 const static int I2Cspeed = I2CSPEED; // I2C clock rate
AzqDev 0:ce75ae1e8fc7 36 int I2CErrorCount; // number of I2C errors
AzqDev 14:2514595e2753 37 int IQSframes; // number of reads we've done
AzqDev 12:5a9bbbd6e312 38 char I2CBuffer [I2CBufferSize]; // I2C read buffer
AzqDev 12:5a9bbbd6e312 39
AzqDev 14:2514595e2753 40 char writeFlag [I2CBufferSize]; // to remember our if we wrote to this register
AzqDev 14:2514595e2753 41 char lastWrite [I2CBufferSize]; // to remember what we wrote to this register
AzqDev 14:2514595e2753 42 char lastRead [I2CBufferSize]; // to remember what we read from this register
AzqDev 14:2514595e2753 43 char readChanges [I2CBufferSize]; // to log changes from previous read
AzqDev 14:2514595e2753 44 char readChangesEver [I2CBufferSize]; // to log changes from previous read BUT this one never forgets a change
AzqDev 14:2514595e2753 45 char writeChanges [I2CBufferSize]; // to log changes from what we wrote
AzqDev 12:5a9bbbd6e312 46
AzqDev 0:ce75ae1e8fc7 47 char * registers; // pointer to I2C read buffer
AzqDev 0:ce75ae1e8fc7 48 IQS62xIO(); // constructor
AzqDev 0:ce75ae1e8fc7 49
AzqDev 7:5e7ea07265d9 50 void writeRegister(int address, int data); // write a byte to a register
AzqDev 0:ce75ae1e8fc7 51 void configure(); // write configuration registers of the IQS62x
AzqDev 11:4d6d1da5bd31 52 void readIqsRegisters(int start, int count); // starting at "start" read count registers
AzqDev 12:5a9bbbd6e312 53 void waitForIqsReady(); // wait for IQS62x ready signal
AzqDev 16:b77c819f6c6a 54 char * getTable( int ); // fetch one of the tables containing changes in register values
AzqDev 16:b77c819f6c6a 55 // an enumerated type we use in main to select one of the tables of changes
AzqDev 16:b77c819f6c6a 56 };
AzqDev 16:b77c819f6c6a 57
AzqDev 16:b77c819f6c6a 58 // used with getTable()
AzqDev 16:b77c819f6c6a 59 enum changeType {
AzqDev 16:b77c819f6c6a 60 color_nothing=0, // no change table selected
AzqDev 16:b77c819f6c6a 61 color_any_register_that_ever_changed=1, // a table to flag any register that ever changed
AzqDev 16:b77c819f6c6a 62 color_any_register_that_changed_in_the_previous_20_reads=2, // a table to flag any register that changed in the last 20 reads
AzqDev 16:b77c819f6c6a 63 color_any_register_that_was_written_or_initialized=3, // a table to flag any register we wrote to or initialized
AzqDev 16:b77c819f6c6a 64 color_any_register_that_was_written_but_then_changed=4 // a table to flag any register we wrote to but then its value changed
AzqDev 16:b77c819f6c6a 65 };