this is a first compilation of a library for IQS5xx. For now, it work with the iqs572ev02 devellopment board. The code is inspired with the sample code provide by Azotech. I have some issu with the interrupt pin RDY, which seem to be high even I don't touch de board.

Dependencies:   mbed

main.cpp

Committer:
skydarc
Date:
2020-01-01
Revision:
0:4907da2299a4
Child:
1:65f5b13e6177

File content as of revision 0:4907da2299a4:

#include "mbed.h"
#include <IQS5xx.h>

/***** Object Declarations *****/
IQS5xx trackPad(p28, p27, p17);

DigitalOut led1(LED1);
DigitalOut led3(LED3);
DigitalOut led4(LED4);

DigitalIn rdy(p17);
//InterruptIn rdyInter(p17);

void ISR1() { //this is the response to interrupt, i.e. the ISR
    led3 = !led3;
}

int main() {
    
    /*
    //rdy.mode(PullUp);
    
    I2C i2c(p28,p27);
    i2c.frequency(400000);
    
    //////////////////
    //AcknowledgeReset
    //////////////////
    
    //write
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x04);
    i2c.write(0x31);
    i2c.write(0x80);
    i2c.stop();
    
    //////////////
    // get version
    //////////////
    
    //read
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x00);
    i2c.write(0x00);
    i2c.start();
    i2c.write((0x74<<1) + 0x01);
    int test0 = i2c.read(1);
    int test1 = i2c.read(1);
    int test2 = i2c.read(1);
    int test3 = i2c.read(1);
    int test4 = i2c.read(1);
    int test5 = i2c.read(0);
    i2c.stop();
    // out
    printf("Product %d ", (test0<<8)+test1); 
    printf("Project %d ", (test2<<8)+test3);
    printf("Version %d.%d\n", test4, test5); 
    
    ////////////////
    //get swipe dist
    ////////////////
    
    //write
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x06);
    i2c.write(0xC1);
    i2c.write(0x00);
    i2c.write(0xB4);
    i2c.stop();
    //read
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x06);
    i2c.write(0xC1);
    i2c.start();
    i2c.write((0x74<<1) + 0x01);
    test0 = i2c.read(1);
    test1 = i2c.read(0);
    i2c.stop();
    printf("Swp init dist. : %d\n", (test0<<8)+test1); 
    
    ////////////
    //Rx mapping
    ////////////
    
    //read
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x06);
    i2c.write(0x3F);
    i2c.start();
    i2c.write((0x74<<1) + 0x01);
    test0 = i2c.read(1);
    test1 = i2c.read(1);
    test2 = i2c.read(1);
    test3 = i2c.read(1);
    test4 = i2c.read(1);
    test5 = i2c.read(1);
    int test6 = i2c.read(1);
    int test7 = i2c.read(0);
    i2c.stop();
    printf("mapping Rx : %d, %d, %d, %d, %d, %d, %d, %d\n", test0, test1, test2, test3, test4, test5, test6, test7); 
    
    ////////////
    //Tx mapping
    ////////////
    
    //read
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x06);
    i2c.write(0x49);
    i2c.start();
    i2c.write((0x74<<1) + 0x01);
    test0 = i2c.read(1);
    test1 = i2c.read(1);
    test2 = i2c.read(1);
    test3 = i2c.read(1);
    test4 = i2c.read(1);
    test5 = i2c.read(1);
    test6 = i2c.read(1);
    test7 = i2c.read(0);
    i2c.stop();
    printf("mapping Tx : %d, %d, %d, %d, %d, %d, %d, %d\n", test0, test1, test2, test3, test4, test5, test6, test7); 
    
    /////////////////////
    //nombre cannaux Rx : 
    /////////////////////
    
    //read
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x06);
    i2c.write(0x3D);
    i2c.start();
    i2c.write((0x74<<1) + 0x01);
    test0 = i2c.read(0);
    i2c.stop();
    printf("nombre cannaux Rx : %d\n", test0); 
    
    /////////////////////
    //nombre cannaux Tx : 
    /////////////////////
    
    //read
    i2c.start();
    i2c.write(0x74<<1);
    i2c.write(0x06);
    i2c.write(0x3E);
    i2c.start();
    i2c.write((0x74<<1) + 0x01);
    test0 = i2c.read(0);
    i2c.stop();
    printf("nombre cannaux Tx : %d\n", test0); */
    
    //rdyInter.rise(&ISR1);
    
    trackPad.AcknowledgeReset();
    
    trackPad.checkVersion();
    
    while(1) {
        
        uint8_t ui8TempData[30], i;
  
        while(!rdy) {
            led4 = 1;
            wait(0.05);
            led4 = 0;
            wait(0.05);    
        }
        
        trackPad.I2C_Read(GestureEvents0_adr, &trackPad.Data_Buff[0], 44);
        
        if((trackPad.Data_Buff[3] & SNAP_TOGGLE) != 0) {
            
            // If there was a change in a snap status, then read the snap status 
            // bytes additionally. Keep previous valus to identify a state change
            //
            trackPad.I2C_Read(SnapStatus_adr, &ui8TempData[0], 30);
            for(i = 0; i < 15; i++) {
                trackPad.ui16PrevSnap[i] = trackPad.ui16SnapStatus[i];
                trackPad.ui16SnapStatus[i] = ((uint16_t)(ui8TempData[2*i])<<8) + (uint16_t)ui8TempData[(2*i)+1];
            }
        }
        
        //
        // Terminate the communication session, so that the IQS5xx can continue 
        // with sensing and processing
        //
        trackPad.Close_Comms();
        //
        // Process received data 
        //
        trackPad.Process_XY();

        led1 = 1;
        wait(0.01);
        led1 = 0;
        wait(0.01);  
    }  
}