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
IQS62x.h@17:2d46eabb129e, 2017-05-15 (annotated)
- Committer:
- AzqDev
- Date:
- Mon May 15 19:52:57 2017 +0000
- Revision:
- 17:2d46eabb129e
- Parent:
- 16:b77c819f6c6a
- Child:
- 18:b85048ec91d2
weblinks
Who changed what in which revision?
User | Revision | Line number | New 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 | 17:2d46eabb129e | 5 | // ProxFusion 5-minute YouTube video: https://youtu.be/l7tO2ra5y74 |
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 */ |
AzqDev | 0:ce75ae1e8fc7 | 19 | #define IQS_I2C_DATA_PIN I2C_SDA /* on NUCLEO boards this is marked as SDA/D14 on CN5 */ |
AzqDev | 0:ce75ae1e8fc7 | 20 | #define IQS_READY_PIN D2 /* on NUCLEO boards this is marked as D2 on CN9 */ |
AzqDev | 1:2f08ab339e17 | 21 | #endif |
AzqDev | 0:ce75ae1e8fc7 | 22 | |
AzqDev | 0:ce75ae1e8fc7 | 23 | #define I2C_ADR (0x44 << 1) /* I2C address of IQS62x */ |
AzqDev | 0:ce75ae1e8fc7 | 24 | #define I2CSPEED 100000 /* I2C clock speed */ |
AzqDev | 0:ce75ae1e8fc7 | 25 | #define NUMBER_OF_REGISTERS 224 /* number of registers to read from IQS62x */ |
AzqDev | 0:ce75ae1e8fc7 | 26 | #define I2CBufferSize 256 /* size of I2C read buffer */ |
AzqDev | 0:ce75ae1e8fc7 | 27 | |
AzqDev | 0:ce75ae1e8fc7 | 28 | class IQS62xIO { // basic IQS62x block read and write |
AzqDev | 0:ce75ae1e8fc7 | 29 | public: |
AzqDev | 0:ce75ae1e8fc7 | 30 | I2C i2c; // I2C interface |
AzqDev | 0:ce75ae1e8fc7 | 31 | DigitalIn IQSready; // ready pin |
AzqDev | 0:ce75ae1e8fc7 | 32 | const static int I2Cspeed = I2CSPEED; // I2C clock rate |
AzqDev | 0:ce75ae1e8fc7 | 33 | int I2CErrorCount; // number of I2C errors |
AzqDev | 14:2514595e2753 | 34 | int IQSframes; // number of reads we've done |
AzqDev | 12:5a9bbbd6e312 | 35 | char I2CBuffer [I2CBufferSize]; // I2C read buffer |
AzqDev | 12:5a9bbbd6e312 | 36 | |
AzqDev | 14:2514595e2753 | 37 | char writeFlag [I2CBufferSize]; // to remember our if we wrote to this register |
AzqDev | 14:2514595e2753 | 38 | char lastWrite [I2CBufferSize]; // to remember what we wrote to this register |
AzqDev | 14:2514595e2753 | 39 | char lastRead [I2CBufferSize]; // to remember what we read from this register |
AzqDev | 14:2514595e2753 | 40 | char readChanges [I2CBufferSize]; // to log changes from previous read |
AzqDev | 14:2514595e2753 | 41 | char readChangesEver [I2CBufferSize]; // to log changes from previous read BUT this one never forgets a change |
AzqDev | 14:2514595e2753 | 42 | char writeChanges [I2CBufferSize]; // to log changes from what we wrote |
AzqDev | 12:5a9bbbd6e312 | 43 | |
AzqDev | 0:ce75ae1e8fc7 | 44 | char * registers; // pointer to I2C read buffer |
AzqDev | 0:ce75ae1e8fc7 | 45 | IQS62xIO(); // constructor |
AzqDev | 0:ce75ae1e8fc7 | 46 | |
AzqDev | 7:5e7ea07265d9 | 47 | void writeRegister(int address, int data); // write a byte to a register |
AzqDev | 0:ce75ae1e8fc7 | 48 | void configure(); // write configuration registers of the IQS62x |
AzqDev | 11:4d6d1da5bd31 | 49 | void readIqsRegisters(int start, int count); // starting at "start" read count registers |
AzqDev | 12:5a9bbbd6e312 | 50 | void waitForIqsReady(); // wait for IQS62x ready signal |
AzqDev | 16:b77c819f6c6a | 51 | char * getTable( int ); // fetch one of the tables containing changes in register values |
AzqDev | 16:b77c819f6c6a | 52 | // an enumerated type we use in main to select one of the tables of changes |
AzqDev | 16:b77c819f6c6a | 53 | }; |
AzqDev | 16:b77c819f6c6a | 54 | |
AzqDev | 16:b77c819f6c6a | 55 | // used with getTable() |
AzqDev | 16:b77c819f6c6a | 56 | enum changeType { |
AzqDev | 16:b77c819f6c6a | 57 | color_nothing=0, // no change table selected |
AzqDev | 16:b77c819f6c6a | 58 | color_any_register_that_ever_changed=1, // a table to flag any register that ever changed |
AzqDev | 16:b77c819f6c6a | 59 | 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 | 60 | color_any_register_that_was_written_or_initialized=3, // a table to flag any register we wrote to or initialized |
AzqDev | 16:b77c819f6c6a | 61 | 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 | 62 | }; |