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:
AzqDev
Date:
Fri May 12 05:01:18 2017 +0000
Revision:
9:7c2666dfbc9a
Parent:
8:f9c71b39c602
Child:
10:8fdac52881aa
Added OVERRIDE_CONFIGURE

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 2:c16cb655d4a4 3 // Copyright 2017 Azoteq. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
AzqDev 2:c16cb655d4a4 4
AzqDev 7:5e7ea07265d9 5 // More info on IQS624 sensor IC: http://www.azoteq.com/products/proxfusion/iqs624?mbed
AzqDev 3:e26d7c502309 6
AzqDev 6:89bdb6f6a5c1 7 // IQS624 1-minute youtube video: http://bit.ly/IQS624Video
AzqDev 5:653138b5cae9 8
AzqDev 0:ce75ae1e8fc7 9 #include "IQS62x.h"
AzqDev 0:ce75ae1e8fc7 10
AzqDev 0:ce75ae1e8fc7 11 // constructor
AzqDev 0:ce75ae1e8fc7 12 IQS62xIO::IQS62xIO() :
AzqDev 0:ce75ae1e8fc7 13 i2c( IQS_I2C_DATA_PIN, IQS_I2C_CLOCK_PIN ), // first run the constructor for mbed class I2C
AzqDev 0:ce75ae1e8fc7 14 IQSready( IQS_READY_PIN ) // first run the constructor for mbed class DigitalIn
AzqDev 0:ce75ae1e8fc7 15 {
AzqDev 0:ce75ae1e8fc7 16 registers = I2CBuffer; // pointer to the receive buffer
AzqDev 0:ce75ae1e8fc7 17 I2CErrorCount = 0; // reset I2C error count
AzqDev 0:ce75ae1e8fc7 18 i2c.frequency( I2Cspeed ); // I2C clock frequency
AzqDev 0:ce75ae1e8fc7 19 }
AzqDev 0:ce75ae1e8fc7 20
AzqDev 7:5e7ea07265d9 21 // write a single byte to an IQS62x register
AzqDev 7:5e7ea07265d9 22 void IQS62xIO::writeRegister(int address, int data) {
AzqDev 7:5e7ea07265d9 23 char twoBytes [2];
AzqDev 7:5e7ea07265d9 24 int numberOfBytes = 2;
AzqDev 7:5e7ea07265d9 25 twoBytes[0] = address & 0xff;
AzqDev 7:5e7ea07265d9 26 twoBytes[1] = data & 0xff;
AzqDev 0:ce75ae1e8fc7 27 waitForReady();
AzqDev 7:5e7ea07265d9 28 if(0!=i2c.write(I2C_ADR,twoBytes,numberOfBytes,false))
AzqDev 0:ce75ae1e8fc7 29 I2CErrorCount++;
AzqDev 0:ce75ae1e8fc7 30 }
AzqDev 0:ce75ae1e8fc7 31
AzqDev 7:5e7ea07265d9 32 // configure the IQS62x
AzqDev 8:f9c71b39c602 33 #include "deviceType.h" // to check if we should override the configuration definition
AzqDev 8:f9c71b39c602 34 #ifndef OVERRIDE_CONFIGURE
AzqDev 9:7c2666dfbc9a 35 // if there is no override for configure() then we use this simple version
AzqDev 8:f9c71b39c602 36 void IQS62xIO::configure() {
AzqDev 7:5e7ea07265d9 37 writeRegister(0xd0,0x40); // simplest config : just acknowledge/clear the reset flag
AzqDev 7:5e7ea07265d9 38 }
AzqDev 8:f9c71b39c602 39 #endif
AzqDev 7:5e7ea07265d9 40
AzqDev 0:ce75ae1e8fc7 41 // read all registers from the IQS62x
AzqDev 0:ce75ae1e8fc7 42 void IQS62xIO::readAll() {
AzqDev 0:ce75ae1e8fc7 43 waitForReady();
AzqDev 0:ce75ae1e8fc7 44 const static char i2c_start_address [] = { 0x0 };
AzqDev 0:ce75ae1e8fc7 45 int numberOfBytes = sizeof( i2c_start_address );
AzqDev 0:ce75ae1e8fc7 46 // write 0 to the IQS62x address register
AzqDev 0:ce75ae1e8fc7 47 if(0!=i2c.write(I2C_ADR,i2c_start_address,numberOfBytes,false))
AzqDev 0:ce75ae1e8fc7 48 I2CErrorCount++;
AzqDev 0:ce75ae1e8fc7 49 waitForReady();
AzqDev 0:ce75ae1e8fc7 50 memset(I2CBuffer,0x55,I2CBufferSize); // "clear" i2c receive buffer
AzqDev 0:ce75ae1e8fc7 51 numberOfBytes = NUMBER_OF_REGISTERS;
AzqDev 0:ce75ae1e8fc7 52 // read register values into a buffer
AzqDev 0:ce75ae1e8fc7 53 if(0!=i2c.read(I2C_ADR,I2CBuffer,numberOfBytes,false))
AzqDev 0:ce75ae1e8fc7 54 I2CErrorCount++;
AzqDev 0:ce75ae1e8fc7 55 }
AzqDev 0:ce75ae1e8fc7 56
AzqDev 0:ce75ae1e8fc7 57 // wait for IQS62x to provide a ready signal (low) on IQS62x_ready pin
AzqDev 0:ce75ae1e8fc7 58 void IQS62xIO::waitForReady() {
AzqDev 0:ce75ae1e8fc7 59 int timeout=0;
AzqDev 0:ce75ae1e8fc7 60 while (1) {
AzqDev 0:ce75ae1e8fc7 61 if(IQSready==1) break;
AzqDev 0:ce75ae1e8fc7 62 if (timeout++ > 1000000) goto fatal_error;
AzqDev 0:ce75ae1e8fc7 63 }
AzqDev 0:ce75ae1e8fc7 64 timeout=0;
AzqDev 0:ce75ae1e8fc7 65 while (1) {
AzqDev 0:ce75ae1e8fc7 66 if(IQSready==0) break;
AzqDev 0:ce75ae1e8fc7 67 if (timeout++ > 1000000) goto fatal_error;
AzqDev 0:ce75ae1e8fc7 68 }
AzqDev 0:ce75ae1e8fc7 69 return;
AzqDev 0:ce75ae1e8fc7 70 fatal_error:
AzqDev 0:ce75ae1e8fc7 71 error ("Fatal Error: IQS62x ready pin is not toggling");
AzqDev 0:ce75ae1e8fc7 72 }