Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: IQS620_HelloWorld IQS622_HelloWorld IQS624_HelloWorld IQS621_HelloWorld ... more
IQS62x.cpp
- Committer:
- AzqDev
- Date:
- 2017-05-12
- Revision:
- 7:5e7ea07265d9
- Parent:
- 6:89bdb6f6a5c1
- Child:
- 8:f9c71b39c602
File content as of revision 7:5e7ea07265d9:
// A class library for Azoteq IQS62x devices
// 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.
// More info on IQS624 sensor IC: http://www.azoteq.com/products/proxfusion/iqs624?mbed
// IQS624 1-minute youtube video: http://bit.ly/IQS624Video
#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 a single byte to an IQS62x register
void IQS62xIO::writeRegister(int address, int data) {
char twoBytes [2];
int numberOfBytes = 2;
twoBytes[0] = address & 0xff;
twoBytes[1] = data & 0xff;
waitForReady();
if(0!=i2c.write(I2C_ADR,twoBytes,numberOfBytes,false))
I2CErrorCount++;
}
// configure the IQS62x
// declared __weak so we can override it with more complex configuration routines.
__weak void IQS62xIO::configure() {
writeRegister(0xd0,0x40); // simplest config : just acknowledge/clear the reset flag
}
// 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");
}
IQS624
IQS620A
IQS620A-EVAL-1
IQS621
IQS621-EVAL-1
IQS622
IQS622-EVAL-1
IQS624-EVAL-1