├── Goodix.cpp ├── Goodix.h ├── GoodixFW.h ├── GoodixStructs.h ├── LICENSE ├── README.md ├── examples ├── GT911_avr_touch │ └── GT911_avr_touch.ino └── GT911_esp_touch │ └── GT911_esp_touch.ino └── img └── lenovoTC.jpg /Goodix.cpp: -------------------------------------------------------------------------------- 1 | #include "Goodix.h" 2 | #include "Wire.h" 3 | 4 | #ifndef ICACHE_RAM_ATTR 5 | #define ICACHE_RAM_ATTR 6 | #endif 7 | 8 | // Interrupt handling 9 | volatile uint8_t goodixIRQ = 0; 10 | 11 | void ICACHE_RAM_ATTR _goodix_irq_handler() { 12 | noInterrupts(); 13 | goodixIRQ = 1; 14 | interrupts(); 15 | } 16 | 17 | 18 | // Implementation 19 | Goodix::Goodix() { 20 | 21 | } 22 | 23 | void Goodix::setHandler(void (*handler)(int8_t, GTPoint*)) { 24 | touchHandler = handler; 25 | } 26 | 27 | bool Goodix::begin(uint8_t interruptPin, uint8_t resetPin, uint8_t addr) { 28 | intPin = interruptPin; 29 | rstPin = resetPin; 30 | i2cAddr = addr; 31 | 32 | // Take chip some time to start 33 | msSleep(300); 34 | bool result = reset(); 35 | msSleep(200); 36 | 37 | return result; 38 | } 39 | 40 | 41 | bool Goodix::reset() { 42 | msSleep(1); 43 | 44 | pinOut(intPin); 45 | pinOut(rstPin); 46 | 47 | pinHold(intPin); 48 | pinHold(rstPin); 49 | 50 | /* begin select I2C slave addr */ 51 | 52 | /* T2: > 10ms */ 53 | msSleep(11); 54 | 55 | /* HIGH: 0x28/0x29 (0x14 7bit), LOW: 0xBA/0xBB (0x5D 7bit) */ 56 | pinSet(intPin, i2cAddr == GOODIX_I2C_ADDR_28); 57 | 58 | /* T3: > 100us */ 59 | usSleep(110); 60 | pinIn(rstPin); 61 | //if (!pinCheck(rstPin, HIGH)) 62 | // return false; 63 | 64 | /* T4: > 5ms */ 65 | msSleep(6); 66 | pinHold(intPin); 67 | /* end select I2C slave addr */ 68 | 69 | /* T5: 50ms */ 70 | msSleep(51); 71 | pinIn(intPin); // INT pin has no pullups so simple set to floating input 72 | 73 | attachInterrupt(intPin, _goodix_irq_handler, RISING); 74 | // detachInterrupt(intPin, _goodix_irq_handler); 75 | 76 | return true; 77 | } 78 | 79 | /** 80 | Read goodix touchscreen version 81 | set 4 chars + zero productID to target 82 | */ 83 | uint8_t Goodix::productID(char *target) { 84 | uint8_t error; 85 | uint8_t buf[4]; 86 | 87 | error = read(GOODIX_REG_ID, buf, 4); 88 | if (error) { 89 | return error; 90 | } 91 | 92 | memcpy(target, buf, 4); 93 | target[4] = 0; 94 | 95 | return 0; 96 | } 97 | 98 | /** 99 | goodix_i2c_test - I2C test function to check if the device answers. 100 | 101 | @client: the i2c client 102 | */ 103 | uint8_t Goodix::test() { 104 | uint8_t testByte; 105 | return read(GOODIX_REG_CONFIG_DATA, &testByte, 1); 106 | } 107 | 108 | uint8_t Goodix::calcChecksum(uint8_t* buf, uint8_t len) { 109 | uint8_t ccsum = 0; 110 | for (uint8_t i = 0; i < len; i++) { 111 | ccsum += buf[i]; 112 | } 113 | //ccsum %= 256; 114 | ccsum = (~ccsum) + 1; 115 | return ccsum; 116 | } 117 | 118 | uint8_t Goodix::readChecksum() { 119 | uint16_t aStart = GT_REG_CFG; 120 | uint16_t aStop = 0x80FE; 121 | uint8_t len = aStop - aStart + 1; 122 | uint8_t buf[len]; 123 | 124 | read(aStart, buf, len); 125 | return calcChecksum(buf, len); 126 | } 127 | 128 | uint8_t Goodix::fwResolution(uint16_t maxX, uint16_t maxY) { 129 | uint8_t len = 0x8100 - GT_REG_CFG + 1; 130 | uint8_t cfg[len]; 131 | read(GT_REG_CFG, cfg, len); 132 | 133 | cfg[1] = (maxX & 0xff); 134 | cfg[2] = (maxX >> 8); 135 | cfg[3] = (maxY & 0xff); 136 | cfg[4] = (maxY >> 8); 137 | cfg[len - 2] = calcChecksum(cfg, len - 2); 138 | cfg[len - 1] = 1; 139 | 140 | write(GT_REG_CFG, cfg, len); 141 | } 142 | 143 | GTConfig* Goodix::readConfig() { 144 | read(GT_REG_CFG, (uint8_t *) &config, sizeof(config)); 145 | return &config; 146 | } 147 | 148 | GTInfo* Goodix::readInfo() { 149 | read(GT_REG_DATA, (uint8_t *) &info, sizeof(config)); 150 | return &info; 151 | } 152 | 153 | void Goodix::armIRQ() { 154 | attachInterrupt(intPin, _goodix_irq_handler, RISING); 155 | } 156 | 157 | void Goodix::onIRQ() { 158 | //uint8_t buf[1 + GOODIX_CONTACT_SIZE * GOODIX_MAX_CONTACTS]; 159 | int8_t contacts; 160 | 161 | contacts = readInput(points); 162 | if (contacts < 0) 163 | return; 164 | 165 | if (contacts > 0) { 166 | touchHandler(contacts, (GTPoint *)points); 167 | /* 168 | Serial.print("Contacts: "); 169 | Serial.println(contacts); 170 | 171 | for (uint8_t i = 0; i < contacts; i++) { 172 | Serial.print("C "); 173 | Serial.print(i); 174 | Serial.print(": #"); 175 | Serial.print(points[i].trackId); 176 | Serial.print(" "); 177 | Serial.print(points[i].x); 178 | Serial.print(", "); 179 | Serial.print(points[i].y); 180 | Serial.print(" s."); 181 | Serial.print(points[i].size); 182 | Serial.println(); 183 | } 184 | */ 185 | } 186 | 187 | //Serial.println(&points[1 + GOODIX_CONTACT_SIZE * i]); 188 | // goodix_ts_report_touch(&points[1 + GOODIX_CONTACT_SIZE * i]); 189 | 190 | write(GOODIX_READ_COORD_ADDR, 0); 191 | /*struct goodix_ts_data *ts = dev_id; 192 | 193 | goodix_process_events(ts); 194 | 195 | write(GOODIX_READ_COORD_ADDR, 0); 196 | //if (write(GOODIX_READ_COORD_ADDR, 0) < 0) 197 | // dev_err(&ts->client->dev, "I2C write end_cmd error\n"); 198 | 199 | return IRQ_HANDLED; 200 | */ 201 | } 202 | 203 | void Goodix::loop() { 204 | noInterrupts(); 205 | uint8_t irq = goodixIRQ; 206 | goodixIRQ = 0; 207 | interrupts(); 208 | 209 | if (irq) { 210 | onIRQ(); 211 | } 212 | } 213 | #define EAGAIN 100 // Try again error 214 | 215 | int16_t Goodix::readInput(uint8_t *data) { 216 | int touch_num; 217 | int error; 218 | 219 | uint8_t regState[1]; 220 | 221 | error = read(GOODIX_READ_COORD_ADDR, regState, 1); 222 | //log_printf("regState: %#06x\n", regState); 223 | 224 | if (error) { 225 | //dev_err(&ts->client->dev, "I2C transfer error: %d\n", error); 226 | return -error; 227 | } 228 | 229 | if (!(regState[0] & 0x80)) 230 | return -EAGAIN; 231 | 232 | touch_num = regState[0] & 0x0f; 233 | //if (touch_num > ts->max_touch_num) 234 | // return -EPROTO; 235 | 236 | //log_printf("touch num: %d\n", touch_num); 237 | 238 | if (touch_num > 0) { 239 | /* data += 1 + GOODIX_CONTACT_SIZE; 240 | error = read(GOODIX_READ_COORD_ADDR + 1 + GOODIX_CONTACT_SIZE, data, 241 | GOODIX_CONTACT_SIZE * (touch_num - 1)); 242 | */ 243 | error = read(GOODIX_READ_COORD_ADDR + 1, data, GOODIX_CONTACT_SIZE * (touch_num)); 244 | 245 | if (error) 246 | return -error; 247 | } 248 | 249 | return touch_num; 250 | } 251 | 252 | //----- Utils ----- 253 | void Goodix::i2cStart(uint16_t reg) { 254 | Wire.beginTransmission(i2cAddr); 255 | Wire.write(highByte(reg)); 256 | Wire.write(lowByte(reg)); 257 | } 258 | 259 | void Goodix::i2cRestart() { 260 | Wire.endTransmission(false); 261 | Wire.beginTransmission(i2cAddr); 262 | } 263 | 264 | uint8_t Goodix::i2cStop() { 265 | return Wire.endTransmission(true); 266 | } 267 | 268 | uint8_t Goodix::write(uint16_t reg, uint8_t *buf, size_t len) { 269 | uint8_t error; 270 | uint16_t startPos = 0; 271 | 272 | while (startPos < len) { 273 | i2cStart(reg + startPos); 274 | startPos += Wire.write(buf + startPos, len - startPos); 275 | error = Wire.endTransmission(); 276 | if (error) 277 | return error; 278 | } 279 | return 0; 280 | } 281 | 282 | uint8_t Goodix::write(uint16_t reg, uint8_t buf) { 283 | i2cStart(reg); 284 | Wire.write(buf); 285 | return Wire.endTransmission(); 286 | } 287 | 288 | uint8_t Goodix::read(uint16_t reg, uint8_t *buf, size_t len) { 289 | uint8_t res; 290 | 291 | i2cStart(reg); 292 | 293 | res = Wire.endTransmission(false); 294 | if (res != GOODIX_OK) { 295 | return res; 296 | } 297 | 298 | uint16_t pos = 0, prevPos = 0; 299 | size_t readLen = 0; 300 | uint8_t maxErrs = 3; 301 | 302 | while (pos < len) { 303 | readLen = Wire.requestFrom(i2cAddr, (len - pos)); 304 | 305 | prevPos = pos; 306 | while (Wire.available()) { 307 | buf[pos] = Wire.read(); 308 | pos++; 309 | } 310 | 311 | if (prevPos == pos) 312 | maxErrs--; 313 | 314 | if (maxErrs <= 0) { 315 | break; 316 | } 317 | delay(0); 318 | } 319 | return 0; 320 | } 321 | 322 | void Goodix::pinOut(uint8_t pin) { 323 | pinMode(pin, OUTPUT); 324 | } 325 | 326 | void Goodix::pinIn(uint8_t pin) { 327 | pinMode(pin, INPUT); 328 | } 329 | 330 | void Goodix::pinSet(uint8_t pin, uint8_t level) { 331 | digitalWrite(pin, level); 332 | } 333 | 334 | void Goodix::pinHold(uint8_t pin) { 335 | pinSet(pin, LOW); 336 | } 337 | 338 | bool Goodix::pinCheck(uint8_t pin, uint8_t level) { 339 | return digitalRead(pin) == level; 340 | } 341 | 342 | void Goodix::msSleep(uint16_t milliseconds) { 343 | delay(milliseconds); 344 | } 345 | 346 | void Goodix::usSleep(uint16_t microseconds) { 347 | delayMicroseconds(microseconds); 348 | } 349 | 350 | 351 | -------------------------------------------------------------------------------- /Goodix.h: -------------------------------------------------------------------------------- 1 | #ifndef _GOODIX_H_ 2 | #define _GOODIX_H_ 3 | 4 | #include 5 | #include "GoodixStructs.h" 6 | 7 | #define GOODIX_OK 0 8 | 9 | // 0x28/0x29 (0x14 7bit) 10 | #define GOODIX_I2C_ADDR_28 0x14 11 | // 0xBA/0xBB (0x5D 7bit) 12 | #define GOODIX_I2C_ADDR_BA 0x5D 13 | 14 | #define GOODIX_MAX_HEIGHT 4096 15 | #define GOODIX_MAX_WIDTH 4096 16 | #define GOODIX_INT_TRIGGER 1 17 | #define GOODIX_CONTACT_SIZE 8 18 | #define GOODIX_MAX_CONTACTS 10 19 | 20 | #define GOODIX_CONFIG_MAX_LENGTH 240 21 | #define GOODIX_CONFIG_911_LENGTH 186 22 | #define GOODIX_CONFIG_967_LENGTH 228 23 | 24 | /* Register defines */ 25 | #define GT_REG_CMD 0x8040 26 | 27 | #define GT_REG_CFG 0x8047 28 | #define GT_REG_DATA 0x8140 29 | 30 | 31 | // Write only registers 32 | #define GOODIX_REG_COMMAND 0x8040 33 | #define GOODIX_REG_LED_CONTROL 0x8041 34 | #define GOODIX_REG_PROXIMITY_EN 0x8042 35 | 36 | // Read/write registers 37 | // The version number of the configuration file 38 | #define GOODIX_REG_CONFIG_DATA 0x8047 39 | // X output maximum value (LSB 2 bytes) 40 | #define GOODIX_REG_MAX_X 0x8048 41 | // Y output maximum value (LSB 2 bytes) 42 | #define GOODIX_REG_MAX_Y 0x804A 43 | // Maximum number of output contacts: 1~5 (4 bit value 3:0, 7:4 is reserved) 44 | #define GOODIX_REG_MAX_TOUCH 0x804C 45 | 46 | // Module switch 1 47 | // 7:6 Reserved, 5:4 Stretch rank, 3 X2Y, 2 SITO (Single sided ITO touch screen), 1:0 INT Trigger mode */ 48 | #define GOODIX_REG_MOD_SW1 0x804D 49 | // Module switch 2 50 | // 7:1 Reserved, 0 Touch key */ 51 | #define GOODIX_REG_MOD_SW2 0x804E 52 | 53 | // Number of debuffs fingers press/release 54 | #define GOODIX_REG_SHAKE_CNT 0x804F 55 | 56 | // ReadOnly registers (device and coordinates info) 57 | // Product ID (LSB 4 bytes, GT9110: 0x06 0x00 0x00 0x09) 58 | #define GOODIX_REG_ID 0x8140 59 | // Firmware version (LSB 2 bytes) 60 | #define GOODIX_REG_FW_VER 0x8144 61 | 62 | // Current output X resolution (LSB 2 bytes) 63 | #define GOODIX_READ_X_RES 0x8146 64 | // Current output Y resolution (LSB 2 bytes) 65 | #define GOODIX_READ_Y_RES 0x8148 66 | // Module vendor ID 67 | #define GOODIX_READ_VENDOR_ID 0x814A 68 | 69 | #define GOODIX_READ_COORD_ADDR 0x814E 70 | 71 | /* Commands for REG_COMMAND */ 72 | //0: read coordinate state 73 | #define GOODIX_CMD_READ 0x00 74 | // 1: difference value original value 75 | #define GOODIX_CMD_DIFFVAL 0x01 76 | // 2: software reset 77 | #define GOODIX_CMD_SOFTRESET 0x02 78 | // 3: Baseline update 79 | #define GOODIX_CMD_BASEUPDATE 0x03 80 | // 4: Benchmark calibration 81 | #define GOODIX_CMD_CALIBRATE 0x04 82 | // 5: Off screen (send other invalid) 83 | #define GOODIX_CMD_SCREEN_OFF 0x05 84 | 85 | /* When data needs to be sent, the host sends command 0x21 to GT9x, 86 | * enabling GT911 to enter "Approach mode" and work as a transmitting terminal */ 87 | #define GOODIX_CMD_HOTKNOT_TX 0x21 88 | 89 | #define RESOLUTION_LOC 1 90 | #define MAX_CONTACTS_LOC 5 91 | #define TRIGGER_LOC 6 92 | 93 | class Goodix { 94 | public: 95 | uint8_t i2cAddr; 96 | struct GTConfig config; 97 | struct GTInfo info; 98 | uint8_t points[GOODIX_MAX_CONTACTS*GOODIX_CONTACT_SIZE]; //points buffer 99 | 100 | Goodix(); 101 | 102 | void setHandler(void (*handler)(int8_t, GTPoint*)); 103 | 104 | bool begin(uint8_t interruptPin, uint8_t resetPin, uint8_t addr=GOODIX_I2C_ADDR_BA); 105 | bool reset(); 106 | uint8_t test(); 107 | void loop(); 108 | 109 | uint8_t write(uint16_t reg, uint8_t *buf, size_t len); 110 | uint8_t write(uint16_t reg, uint8_t value); 111 | uint8_t read(uint16_t reg, uint8_t *buf, size_t len); 112 | 113 | uint8_t calcChecksum(uint8_t* buf, uint8_t len); 114 | uint8_t readChecksum(); 115 | 116 | uint8_t fwResolution(uint16_t maxX, uint16_t maxY); 117 | 118 | GTConfig* readConfig(); 119 | GTInfo* readInfo(); 120 | 121 | uint8_t productID(char *buf); 122 | 123 | int16_t readInput(uint8_t *data); 124 | 125 | //--- Private routines --- 126 | private: 127 | uint8_t intPin, rstPin; 128 | void (*touchHandler)(int8_t, GTPoint*); 129 | 130 | void debugPin(uint8_t level); 131 | void armIRQ(); 132 | void onIRQ(); 133 | 134 | //--- utils --- 135 | void usSleep(uint16_t microseconds); 136 | void msSleep(uint16_t milliseconds); 137 | 138 | void pinIn(uint8_t pin); 139 | void pinOut(uint8_t pin); 140 | void pinSet(uint8_t pin, uint8_t level); 141 | 142 | // Used with pulled-up lines, set pin mode to out, write LOW 143 | void pinHold(uint8_t pin); 144 | 145 | // Check pin level 146 | bool pinCheck(uint8_t pin, uint8_t level); 147 | 148 | void i2cStart(uint16_t reg); 149 | void i2cRestart(); 150 | uint8_t i2cStop(); 151 | }; 152 | 153 | #endif 154 | -------------------------------------------------------------------------------- /GoodixFW.h: -------------------------------------------------------------------------------- 1 | uint8_t g911xFW[] = { 2 | 0x42, 3 | 0xD0, 0x02, 0x00, 0x05, 0x05, 0x75, 0x01, 0x01, 0x0F, 0x24, 4 | 0x0F, 0x64, 0x3C, 0x03, 0x05, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 5 | 0x00, 0x16, 0x19, 0x1C, 0x14, 0x8C, 0x0E, 0x0E, 0x24, 0x00, 0x31, 6 | 0x0D, 0x00, 0x00, 0x00, 0x83, 0x33, 0x1D, 0x00, 0x41, 0x00, 0x00, 7 | 0x00, 0x00, 0x00, 0x08, 0x0A, 0x00, 0x2B, 0x1C, 0x3C, 0x94, 0xD5, 8 | 0x03, 0x08, 0x00, 0x00, 0x04, 0x93, 0x1E, 0x00, 0x82, 0x23, 0x00, 9 | 0x74, 0x29, 0x00, 0x69, 0x2F, 0x00, 0x5F, 0x37, 0x00, 0x5F, 0x20, 10 | 0x40, 0x60, 0x00, 0xF0, 0x40, 0x30, 0x55, 0x50, 0x27, 0x00, 0x00, 11 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x19, 0x00, 0x00, 13 | 0x50, 0x50, 0x02, 0x04, 0x06, 0x08, 0x0A, 0x0C, 0x0E, 0x10, 0x12, 14 | 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 15 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D, 16 | 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x24, 0x26, 0x28, 0x29, 0x2A, 0x1C, 17 | 0x18, 0x16, 0x14, 0x13, 0x12, 0x10, 0x0F, 0x0C, 0x0A, 0x08, 0x06, 18 | 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 19 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0x01}; 20 | 21 | 22 | -------------------------------------------------------------------------------- /GoodixStructs.h: -------------------------------------------------------------------------------- 1 | typedef struct GTInfo { 2 | // 0x8140-0x814A 3 | char productId[4]; 4 | uint16_t fwId; 5 | uint16_t xResolution; 6 | uint16_t yResolution; 7 | uint8_t vendorId; 8 | }; 9 | 10 | struct GTPoint { 11 | // 0x814F-0x8156, ... 0x8176 (5 points) 12 | uint8_t trackId; 13 | uint16_t x; 14 | uint16_t y; 15 | uint16_t area; 16 | uint8_t reserved; 17 | }; 18 | 19 | struct GTLevelConfig { 20 | uint8_t touch; // Threshold of touch grow out of nothing 21 | uint8_t leave; // Threshold of touch decrease to nothing 22 | }; 23 | 24 | struct GTStylusConfig { 25 | uint8_t txGain; 26 | uint8_t rxGain; 27 | uint8_t dumpShift; 28 | GTLevelConfig level; 29 | uint8_t control; //Pen mode escape time out period (Unit: Sec) 30 | }; 31 | 32 | struct GTFreqHoppingConfig { 33 | uint16_t hoppingBitFreq; 34 | uint8_t hoppingFactor; 35 | }; 36 | 37 | struct GTKeyConfig { 38 | // Key position: 0-255 valid 39 | // 0 means no touch, it means independent touch key when 4 of the keys are 8 multiples 40 | uint8_t pos1; 41 | uint8_t pos2; 42 | uint8_t pos3; 43 | uint8_t pos4; 44 | uint8_t area; 45 | GTLevelConfig level; 46 | uint8_t sens12; 47 | uint8_t sens34; 48 | uint8_t restrain; 49 | }; 50 | 51 | struct GTConfig { 52 | // start at 0x8047 53 | uint8_t configVersion; 54 | uint16_t xResolution; 55 | uint16_t yResolution; 56 | // 0x804C 57 | uint8_t touchNumber; // 3:0 Touch No.: 1~10 58 | 59 | // 7:6 Reserved, 5:4 Stretch rank, 3 X2Y, 2 Sito 60 | // 1:0 INT trig method: 00-rising, 01-falling, 02-low level, 03-high level enquiry 61 | uint8_t moduleSwitch1; 62 | uint8_t moduleSwitch2; // bit0 TouchKey 63 | uint8_t shakeCount; // 3:0 Finger shake count 64 | // 0x8050 65 | // 7:6 First filter, 5:0 Normal filter (filtering value of original coordinate window, coefficiency is 1) 66 | uint8_t filter; 67 | uint8_t largeTouch; 68 | uint8_t noiseReduction; 69 | GTLevelConfig screenLevel; 70 | 71 | uint8_t lowPowerControl; // Time to low power consumption (0~15s) 72 | uint8_t refreshRate; // Coordinate report rate (Cycle: 5+N ms) 73 | uint8_t xThreshold; //res 74 | uint8_t yThreshold; //res 75 | uint8_t xSpeedLimit; //res 76 | uint8_t ySpeedLimit; //res 77 | uint8_t vSpace; // 4bit top/bottom (coefficient 32) 78 | uint8_t hSpace; // 4bit left/right 79 | //0x805D-0x8061 80 | uint8_t stretchRate; //Level of weak stretch (Strtch X/16 Pitch) 81 | uint8_t stretchR0; // Interval 1 coefficient 82 | uint8_t stretchR1; // Interval 2 coefficient 83 | uint8_t stretchR2; // Interval 3 coefficient 84 | uint8_t stretchRM; // All intervals base number 85 | 86 | uint8_t drvGroupANum; 87 | uint8_t drvGroupBNum; 88 | uint8_t sensorNum; 89 | uint8_t freqAFactor; 90 | uint8_t freqBFactor; 91 | // 0x8067 92 | uint16_t pannelBitFreq; //Baseband of Driver group A\B (1526HZ 2 | #include "Goodix.h" 3 | 4 | // INT_PIN will be used with attachInterrupt(intPin, _goodix_irq_handler, RISING), so select it properly for Your board 5 | #define INT_PIN 2 6 | #define RST_PIN 5 7 | 8 | Goodix touch = Goodix(); 9 | 10 | // AVR hasn't printf in Serial, so we dedfine it here 11 | const size_t log_printf(const char *format, ...) { 12 | va_list arg; 13 | va_start(arg, format); 14 | char temp[64]; 15 | char* buffer = temp; 16 | size_t len = vsnprintf(temp, sizeof(temp), format, arg); 17 | va_end(arg); 18 | if (len > sizeof(temp) - 1) { 19 | buffer = (char *) malloc(len+1); 20 | //buffer = new char[len + 1]; 21 | if (!buffer) { 22 | return 0; 23 | } 24 | va_start(arg, format); 25 | vsnprintf(buffer, len + 1, format, arg); 26 | va_end(arg); 27 | } 28 | //len = write((const uint8_t*) buffer, len); 29 | Serial.print(buffer); 30 | if (buffer != temp) { 31 | free(buffer); 32 | //delete[] buffer; 33 | } 34 | return len; 35 | } 36 | 37 | void handleTouch(int8_t contacts, GTPoint *points) { 38 | log_printf("Contacts: %d\n", contacts); 39 | for (uint8_t i = 0; i < contacts; i++) { 40 | log_printf("C%d: #%d %d,%d s:%d\n", i, points[i].trackId, points[i].x, points[i].y, points[i].area); 41 | yield(); 42 | } 43 | } 44 | 45 | void touchStart() { 46 | if (touch.begin(INT_PIN, RST_PIN)!=true) { 47 | Serial.println("! Module reset failed"); 48 | } else { 49 | Serial.println("Module reset OK"); 50 | } 51 | 52 | Serial.print("Check ACK on addr request on 0x"); 53 | Serial.print(touch.i2cAddr, HEX); 54 | 55 | Wire.beginTransmission(touch.i2cAddr); 56 | int error = Wire.endTransmission(); 57 | if (error == 0) { 58 | Serial.println(": SUCCESS"); 59 | } else { 60 | Serial.print(": ERROR #"); 61 | Serial.println(error); 62 | } 63 | } 64 | 65 | void setup() { 66 | Serial.begin(115200); 67 | Serial.println("\nGoodix GT911x touch driver"); 68 | 69 | Wire.setClock(400000); 70 | Wire.begin(); 71 | delay(300); 72 | 73 | touch.setHandler(handleTouch); 74 | touchStart(); 75 | } 76 | 77 | void loop() { 78 | touch.loop(); 79 | delay(1); 80 | } -------------------------------------------------------------------------------- /examples/GT911_esp_touch/GT911_esp_touch.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Goodix.h" 3 | 4 | // D5 D6 pins are defined on boards like WeMOS, You can redefine it to numeric values 5 | #define INT_PIN D6 6 | #define RST_PIN D5 7 | 8 | 9 | Goodix touch = Goodix(); 10 | 11 | void handleTouch(int8_t contacts, GTPoint *points) { 12 | Serial.printf("Contacts: %d\n", contacts); 13 | for (uint8_t i = 0; i < contacts; i++) { 14 | Serial.printf("C%d: #%d %d,%d s:%d\n", i, points[i].trackId, points[i].x, points[i].y, points[i].area); 15 | yield(); 16 | } 17 | } 18 | 19 | void touchStart() { 20 | if (touch.begin(INT_PIN, RST_PIN)!=true) { 21 | Serial.println("! Module reset failed"); 22 | } else { 23 | Serial.println("Module reset OK"); 24 | } 25 | 26 | Serial.print("Check ACK on addr request on 0x"); 27 | Serial.print(touch.i2cAddr, HEX); 28 | 29 | Wire.beginTransmission(touch.i2cAddr); 30 | int error = Wire.endTransmission(); 31 | if (error == 0) { 32 | Serial.println(": SUCCESS"); 33 | } else { 34 | Serial.print(": ERROR #"); 35 | Serial.println(error); 36 | } 37 | } 38 | 39 | void setup() { 40 | Serial.begin(115200); 41 | Serial.println("\nGoodix GT911x touch driver"); 42 | 43 | Wire.setClock(400000); 44 | Wire.begin(); 45 | delay(300); 46 | 47 | touch.setHandler(handleTouch); 48 | touchStart(); 49 | } 50 | 51 | void loop() { 52 | touch.loop(); 53 | delay(1); 54 | } -------------------------------------------------------------------------------- /img/lenovoTC.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nik-sharky/arduino-goodix/a4ea4c1d3988ab53ba2e1307ab744e430b161baf/img/lenovoTC.jpg --------------------------------------------------------------------------------