![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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.
main.cpp@0:4907da2299a4, 2020-01-01 (annotated)
- Committer:
- skydarc
- Date:
- Wed Jan 01 12:51:18 2020 +0000
- Revision:
- 0:4907da2299a4
- Child:
- 1:65f5b13e6177
this is a first compil 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 t
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
skydarc | 0:4907da2299a4 | 1 | #include "mbed.h" |
skydarc | 0:4907da2299a4 | 2 | #include <IQS5xx.h> |
skydarc | 0:4907da2299a4 | 3 | |
skydarc | 0:4907da2299a4 | 4 | /***** Object Declarations *****/ |
skydarc | 0:4907da2299a4 | 5 | IQS5xx trackPad(p28, p27, p17); |
skydarc | 0:4907da2299a4 | 6 | |
skydarc | 0:4907da2299a4 | 7 | DigitalOut led1(LED1); |
skydarc | 0:4907da2299a4 | 8 | DigitalOut led3(LED3); |
skydarc | 0:4907da2299a4 | 9 | DigitalOut led4(LED4); |
skydarc | 0:4907da2299a4 | 10 | |
skydarc | 0:4907da2299a4 | 11 | DigitalIn rdy(p17); |
skydarc | 0:4907da2299a4 | 12 | //InterruptIn rdyInter(p17); |
skydarc | 0:4907da2299a4 | 13 | |
skydarc | 0:4907da2299a4 | 14 | void ISR1() { //this is the response to interrupt, i.e. the ISR |
skydarc | 0:4907da2299a4 | 15 | led3 = !led3; |
skydarc | 0:4907da2299a4 | 16 | } |
skydarc | 0:4907da2299a4 | 17 | |
skydarc | 0:4907da2299a4 | 18 | int main() { |
skydarc | 0:4907da2299a4 | 19 | |
skydarc | 0:4907da2299a4 | 20 | /* |
skydarc | 0:4907da2299a4 | 21 | //rdy.mode(PullUp); |
skydarc | 0:4907da2299a4 | 22 | |
skydarc | 0:4907da2299a4 | 23 | I2C i2c(p28,p27); |
skydarc | 0:4907da2299a4 | 24 | i2c.frequency(400000); |
skydarc | 0:4907da2299a4 | 25 | |
skydarc | 0:4907da2299a4 | 26 | ////////////////// |
skydarc | 0:4907da2299a4 | 27 | //AcknowledgeReset |
skydarc | 0:4907da2299a4 | 28 | ////////////////// |
skydarc | 0:4907da2299a4 | 29 | |
skydarc | 0:4907da2299a4 | 30 | //write |
skydarc | 0:4907da2299a4 | 31 | i2c.start(); |
skydarc | 0:4907da2299a4 | 32 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 33 | i2c.write(0x04); |
skydarc | 0:4907da2299a4 | 34 | i2c.write(0x31); |
skydarc | 0:4907da2299a4 | 35 | i2c.write(0x80); |
skydarc | 0:4907da2299a4 | 36 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 37 | |
skydarc | 0:4907da2299a4 | 38 | ////////////// |
skydarc | 0:4907da2299a4 | 39 | // get version |
skydarc | 0:4907da2299a4 | 40 | ////////////// |
skydarc | 0:4907da2299a4 | 41 | |
skydarc | 0:4907da2299a4 | 42 | //read |
skydarc | 0:4907da2299a4 | 43 | i2c.start(); |
skydarc | 0:4907da2299a4 | 44 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 45 | i2c.write(0x00); |
skydarc | 0:4907da2299a4 | 46 | i2c.write(0x00); |
skydarc | 0:4907da2299a4 | 47 | i2c.start(); |
skydarc | 0:4907da2299a4 | 48 | i2c.write((0x74<<1) + 0x01); |
skydarc | 0:4907da2299a4 | 49 | int test0 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 50 | int test1 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 51 | int test2 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 52 | int test3 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 53 | int test4 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 54 | int test5 = i2c.read(0); |
skydarc | 0:4907da2299a4 | 55 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 56 | // out |
skydarc | 0:4907da2299a4 | 57 | printf("Product %d ", (test0<<8)+test1); |
skydarc | 0:4907da2299a4 | 58 | printf("Project %d ", (test2<<8)+test3); |
skydarc | 0:4907da2299a4 | 59 | printf("Version %d.%d\n", test4, test5); |
skydarc | 0:4907da2299a4 | 60 | |
skydarc | 0:4907da2299a4 | 61 | //////////////// |
skydarc | 0:4907da2299a4 | 62 | //get swipe dist |
skydarc | 0:4907da2299a4 | 63 | //////////////// |
skydarc | 0:4907da2299a4 | 64 | |
skydarc | 0:4907da2299a4 | 65 | //write |
skydarc | 0:4907da2299a4 | 66 | i2c.start(); |
skydarc | 0:4907da2299a4 | 67 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 68 | i2c.write(0x06); |
skydarc | 0:4907da2299a4 | 69 | i2c.write(0xC1); |
skydarc | 0:4907da2299a4 | 70 | i2c.write(0x00); |
skydarc | 0:4907da2299a4 | 71 | i2c.write(0xB4); |
skydarc | 0:4907da2299a4 | 72 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 73 | //read |
skydarc | 0:4907da2299a4 | 74 | i2c.start(); |
skydarc | 0:4907da2299a4 | 75 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 76 | i2c.write(0x06); |
skydarc | 0:4907da2299a4 | 77 | i2c.write(0xC1); |
skydarc | 0:4907da2299a4 | 78 | i2c.start(); |
skydarc | 0:4907da2299a4 | 79 | i2c.write((0x74<<1) + 0x01); |
skydarc | 0:4907da2299a4 | 80 | test0 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 81 | test1 = i2c.read(0); |
skydarc | 0:4907da2299a4 | 82 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 83 | printf("Swp init dist. : %d\n", (test0<<8)+test1); |
skydarc | 0:4907da2299a4 | 84 | |
skydarc | 0:4907da2299a4 | 85 | //////////// |
skydarc | 0:4907da2299a4 | 86 | //Rx mapping |
skydarc | 0:4907da2299a4 | 87 | //////////// |
skydarc | 0:4907da2299a4 | 88 | |
skydarc | 0:4907da2299a4 | 89 | //read |
skydarc | 0:4907da2299a4 | 90 | i2c.start(); |
skydarc | 0:4907da2299a4 | 91 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 92 | i2c.write(0x06); |
skydarc | 0:4907da2299a4 | 93 | i2c.write(0x3F); |
skydarc | 0:4907da2299a4 | 94 | i2c.start(); |
skydarc | 0:4907da2299a4 | 95 | i2c.write((0x74<<1) + 0x01); |
skydarc | 0:4907da2299a4 | 96 | test0 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 97 | test1 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 98 | test2 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 99 | test3 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 100 | test4 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 101 | test5 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 102 | int test6 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 103 | int test7 = i2c.read(0); |
skydarc | 0:4907da2299a4 | 104 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 105 | printf("mapping Rx : %d, %d, %d, %d, %d, %d, %d, %d\n", test0, test1, test2, test3, test4, test5, test6, test7); |
skydarc | 0:4907da2299a4 | 106 | |
skydarc | 0:4907da2299a4 | 107 | //////////// |
skydarc | 0:4907da2299a4 | 108 | //Tx mapping |
skydarc | 0:4907da2299a4 | 109 | //////////// |
skydarc | 0:4907da2299a4 | 110 | |
skydarc | 0:4907da2299a4 | 111 | //read |
skydarc | 0:4907da2299a4 | 112 | i2c.start(); |
skydarc | 0:4907da2299a4 | 113 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 114 | i2c.write(0x06); |
skydarc | 0:4907da2299a4 | 115 | i2c.write(0x49); |
skydarc | 0:4907da2299a4 | 116 | i2c.start(); |
skydarc | 0:4907da2299a4 | 117 | i2c.write((0x74<<1) + 0x01); |
skydarc | 0:4907da2299a4 | 118 | test0 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 119 | test1 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 120 | test2 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 121 | test3 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 122 | test4 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 123 | test5 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 124 | test6 = i2c.read(1); |
skydarc | 0:4907da2299a4 | 125 | test7 = i2c.read(0); |
skydarc | 0:4907da2299a4 | 126 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 127 | printf("mapping Tx : %d, %d, %d, %d, %d, %d, %d, %d\n", test0, test1, test2, test3, test4, test5, test6, test7); |
skydarc | 0:4907da2299a4 | 128 | |
skydarc | 0:4907da2299a4 | 129 | ///////////////////// |
skydarc | 0:4907da2299a4 | 130 | //nombre cannaux Rx : |
skydarc | 0:4907da2299a4 | 131 | ///////////////////// |
skydarc | 0:4907da2299a4 | 132 | |
skydarc | 0:4907da2299a4 | 133 | //read |
skydarc | 0:4907da2299a4 | 134 | i2c.start(); |
skydarc | 0:4907da2299a4 | 135 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 136 | i2c.write(0x06); |
skydarc | 0:4907da2299a4 | 137 | i2c.write(0x3D); |
skydarc | 0:4907da2299a4 | 138 | i2c.start(); |
skydarc | 0:4907da2299a4 | 139 | i2c.write((0x74<<1) + 0x01); |
skydarc | 0:4907da2299a4 | 140 | test0 = i2c.read(0); |
skydarc | 0:4907da2299a4 | 141 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 142 | printf("nombre cannaux Rx : %d\n", test0); |
skydarc | 0:4907da2299a4 | 143 | |
skydarc | 0:4907da2299a4 | 144 | ///////////////////// |
skydarc | 0:4907da2299a4 | 145 | //nombre cannaux Tx : |
skydarc | 0:4907da2299a4 | 146 | ///////////////////// |
skydarc | 0:4907da2299a4 | 147 | |
skydarc | 0:4907da2299a4 | 148 | //read |
skydarc | 0:4907da2299a4 | 149 | i2c.start(); |
skydarc | 0:4907da2299a4 | 150 | i2c.write(0x74<<1); |
skydarc | 0:4907da2299a4 | 151 | i2c.write(0x06); |
skydarc | 0:4907da2299a4 | 152 | i2c.write(0x3E); |
skydarc | 0:4907da2299a4 | 153 | i2c.start(); |
skydarc | 0:4907da2299a4 | 154 | i2c.write((0x74<<1) + 0x01); |
skydarc | 0:4907da2299a4 | 155 | test0 = i2c.read(0); |
skydarc | 0:4907da2299a4 | 156 | i2c.stop(); |
skydarc | 0:4907da2299a4 | 157 | printf("nombre cannaux Tx : %d\n", test0); */ |
skydarc | 0:4907da2299a4 | 158 | |
skydarc | 0:4907da2299a4 | 159 | //rdyInter.rise(&ISR1); |
skydarc | 0:4907da2299a4 | 160 | |
skydarc | 0:4907da2299a4 | 161 | trackPad.AcknowledgeReset(); |
skydarc | 0:4907da2299a4 | 162 | |
skydarc | 0:4907da2299a4 | 163 | trackPad.checkVersion(); |
skydarc | 0:4907da2299a4 | 164 | |
skydarc | 0:4907da2299a4 | 165 | while(1) { |
skydarc | 0:4907da2299a4 | 166 | |
skydarc | 0:4907da2299a4 | 167 | uint8_t ui8TempData[30], i; |
skydarc | 0:4907da2299a4 | 168 | |
skydarc | 0:4907da2299a4 | 169 | while(!rdy) { |
skydarc | 0:4907da2299a4 | 170 | led4 = 1; |
skydarc | 0:4907da2299a4 | 171 | wait(0.05); |
skydarc | 0:4907da2299a4 | 172 | led4 = 0; |
skydarc | 0:4907da2299a4 | 173 | wait(0.05); |
skydarc | 0:4907da2299a4 | 174 | } |
skydarc | 0:4907da2299a4 | 175 | |
skydarc | 0:4907da2299a4 | 176 | trackPad.I2C_Read(GestureEvents0_adr, &trackPad.Data_Buff[0], 44); |
skydarc | 0:4907da2299a4 | 177 | |
skydarc | 0:4907da2299a4 | 178 | if((trackPad.Data_Buff[3] & SNAP_TOGGLE) != 0) { |
skydarc | 0:4907da2299a4 | 179 | |
skydarc | 0:4907da2299a4 | 180 | // If there was a change in a snap status, then read the snap status |
skydarc | 0:4907da2299a4 | 181 | // bytes additionally. Keep previous valus to identify a state change |
skydarc | 0:4907da2299a4 | 182 | // |
skydarc | 0:4907da2299a4 | 183 | trackPad.I2C_Read(SnapStatus_adr, &ui8TempData[0], 30); |
skydarc | 0:4907da2299a4 | 184 | for(i = 0; i < 15; i++) { |
skydarc | 0:4907da2299a4 | 185 | trackPad.ui16PrevSnap[i] = trackPad.ui16SnapStatus[i]; |
skydarc | 0:4907da2299a4 | 186 | trackPad.ui16SnapStatus[i] = ((uint16_t)(ui8TempData[2*i])<<8) + (uint16_t)ui8TempData[(2*i)+1]; |
skydarc | 0:4907da2299a4 | 187 | } |
skydarc | 0:4907da2299a4 | 188 | } |
skydarc | 0:4907da2299a4 | 189 | |
skydarc | 0:4907da2299a4 | 190 | // |
skydarc | 0:4907da2299a4 | 191 | // Terminate the communication session, so that the IQS5xx can continue |
skydarc | 0:4907da2299a4 | 192 | // with sensing and processing |
skydarc | 0:4907da2299a4 | 193 | // |
skydarc | 0:4907da2299a4 | 194 | trackPad.Close_Comms(); |
skydarc | 0:4907da2299a4 | 195 | // |
skydarc | 0:4907da2299a4 | 196 | // Process received data |
skydarc | 0:4907da2299a4 | 197 | // |
skydarc | 0:4907da2299a4 | 198 | trackPad.Process_XY(); |
skydarc | 0:4907da2299a4 | 199 | |
skydarc | 0:4907da2299a4 | 200 | led1 = 1; |
skydarc | 0:4907da2299a4 | 201 | wait(0.01); |
skydarc | 0:4907da2299a4 | 202 | led1 = 0; |
skydarc | 0:4907da2299a4 | 203 | wait(0.01); |
skydarc | 0:4907da2299a4 | 204 | } |
skydarc | 0:4907da2299a4 | 205 | } |
skydarc | 0:4907da2299a4 | 206 |