nik-sharky / arduino-goodix

Arduino goodix touch screen driver
MIT License
29 stars 21 forks source link

how to config the resolutions. #1

Open microyumcc opened 6 years ago

microyumcc commented 6 years ago

Hi, thanks for your code, when i run with my TP, but the X/Y point was inaccuracy, how to config it? thank you.

nik-sharky commented 6 years ago

Hi, try to call readInfo(), obtain GTInfo struct and check resolutions that chip use. Is inaccuracy too much? Also it can be swapped top-down, left-right, in this case You need to subtract position from resolution.

microyumcc commented 6 years ago

Hi, thank you for your answer, my touch screen is 800x480, how to set the resolutions?

nik-sharky commented 6 years ago

What resolution You receive from chip in GTInfo?

microyumcc commented 6 years ago

received 1024x600 from GTInfo

microyumcc commented 6 years ago

i use touch.loop(), when touched, i received the result as below: Contacts: 1 C 0: #129 4864, 34816 s.5888 Contacts: 1 C 0: #129 16128, 10496 s.7936 Contacts: 1 C 0: #129 16128, 10496 s.7936 Contacts: 1 C 0: #129 16128, 10496 s.7936 Contacts: 1 C 0: #129 16128, 10496 s.7936

nik-sharky commented 6 years ago

Oh, it's problem in code on gitHub, it was early prototype version and incorrect read data from registers. Can check and update it after work ~7h.

microyumcc commented 6 years ago

ok, i will check it, thanks for your support.

nik-sharky commented 6 years ago

Commit changes, but can't check on hardware right now, can't find FPC bread-board. log.h can be found here: https://github.com/ploys/arduino-logger

microyumcc commented 6 years ago

sorry for this late reply, i have rechecked, but there has some issue about compiling:

Build options changed, rebuilding all libraries/arduino-goodix-master/Goodix.cpp.o (symbol from plugin): In function _goodix_irq_handler()': (.text+0x0): multiple definition of_log_printf(char const*, ...)' sketch/GT911_touch.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here collect2: error: ld returned 1 exit status exit status 1 Error compiling for board Arduino/Genuino Uno.

microyumcc commented 6 years ago

i changed the log printf to Serial.print, now i get the right result: point: 0 x:516 y:428 s:20 point: 1 x:226 y:14 s:14 point: 2 x:404 y:14 s:15 point: 3 x:538 y:77 s:12 point: 4 x:677 y:219 s:13

looks like the resolution was 1024*600. how can i set the right resolution?

thank you very much for your help!

nik-sharky commented 6 years ago

You should write config to chip (GoodixFW.h an example from linux driver), config structure described in GTConfig, xResolution and yResolution is what You need.

touch.write(GOODIX_REG_CONFIG_DATA, g911xFW, sizeof(g911xFW));

As I remember, last byte of config is checksum, which calculated like this: You can check that config is correctly written by read 0x80FF register, checksums should be equal.

void checksum() { uint16_t aStart = 0x8047; uint16_t aStop = 0x80FE; uint8_t len = aStop-aStart; uint8_t buf[len];

// buf here is config

uint8_t ccsum=0; for (uint8_t i=0; i<len; i++) { ccsum += buf[i]; } ccsum = (~ccsum) + 1;

uint8_t cbuf[1]; touch.read(0x80FF, cbuf, 1);

Serial.println(); Serial.print("CSum calculated "); Serial.println(ccsum, HEX); Serial.print("CSum register "); Serial.println(cbuf[0], HEX); }

I don't remember tat my checksum works correctly, so check it :)

nik-sharky commented 6 years ago

I use https://github.com/hadess/gt9xx/blob/master/specifications/GT928%20Datashet%20English.pdf this datasheet when write it. Pay attention at 80FF and 8100 regs.

microyumcc commented 6 years ago

sorry, i dont understand, touch.write(GOODIX_REG_CONFIG_DATA, g911xFW, sizeof(g911xFW)); just need this function to write the config data to clip, right? as i know, the g911xFW contain the resolution config. but how can i config the GTConfig? also use touch.write?

nik-sharky commented 6 years ago

"just need this function to write the config data to clip, right?" Right, You should change config with Your resolution values, calculate and set proper checksum to it and write it to chip using touch.write method.

It will be good to save Your current config from chip. You can do it using touch.read starting from GOODIX_REG_CONFIG_DATA (0x8047) register to 0x80FF register.

GTConfig describes content of g911xFW array For example: uint8_t g911xFW[] = { 0x42, 0xD0, 0x02, 0x00, 0x05, ... 0x9C, 0x01};

uint8_t configVersion = 0x42; uint16_t xResolution = 0xD002; // from LSB is 0x02D0 =720 uint16_t yResolution = 0x0005; // from LSB is 0x0500 = 1280
0x9C - config checksum 0x01 - say chip that it should update config

touch.write - write data to chip registers, starting from GOODIX_REG_CONFIG_DATA (0x8047) register number.

microyumcc commented 6 years ago

thank you, the checksum result is D5 uint8_t configVersion = 0x43; uint16_t xResolution = 0x2003; // from LSB is 0x0320 =800 uint16_t yResolution = 0xE001; // from LSB is 0x01E0 = 480

so.. uint8_t g911xFW[] = { 0x43, 0x20, 0x03, 0xE0, 0x01, ... 0xd5, 0x01};

right?

then i use touch.write(GOODIX_REG_CONFIG_DATA, g911xFW, sizeof(g911xFW)); but also can not modify the resolution, read the config also as before.

nik-sharky commented 6 years ago

Maybe checksum is incorrect, can check it after work, try to recalculate cs from existing chip config and compare with written in cs register to understand is it cs problem or other.

Also I can try to check after work.

microyumcc commented 6 years ago

is it possible that the write() have problem? because i think i got the right config data. and also i rechecked the checksum with other fine library about GT9XX. the result of checksum is the same as other library. so i think the checksum is no problem.

nik-sharky commented 6 years ago

Possible. Try to change in uint8_t Goodix::write(uint16_t reg, uint8_t *buf, size_t len) error = Wire.endTransmission(); to error = Wire.endTransmission(false); and add Wire.endTransmission() at the end of method after all data was written.

microyumcc commented 6 years ago

while (startPos<len) { i2cStart(reg+startPos); startPos += Wire.write(buf+startPos, len-startPos);
error = Wire.endTransmission(false); if (error) return error; } Wire.endTransmission(); return 0;

i have changed and retest it. but there has no error return.

nik-sharky commented 6 years ago

Does it works now?

Change Wire.endTransmission(); return 0; to return Wire.endTransmission();

to return error

microyumcc commented 6 years ago

sorry! no. also can not write the config. and i change to return Wire.endTransmission(); also no errors return. i was confused o(╯□╰)o

i try to write a single config, also not success. i use touch.write(0x8040, 5) can close the TP, but can not write 0x8048 and other address for resolutions.

nik-sharky commented 6 years ago

Can You write here config that You read from chip in hex? With checksum from 80FF register.

microyumcc commented 6 years ago

yes, i also try to write this config from read chip.

nik-sharky commented 6 years ago

I found FPC adapter so can check now. Write dump of config from Your chip here please.

nik-sharky commented 6 years ago

You can use this for debug:

void dumpRegs(uint16_t first, uint16_t last) { uint8_t len = last-first+1;
uint8_t buf[len]; uint16_t reg = first;

uint8_t res = touch.read(first, buf, len); if (res != GOODIX_OK) { Serial.print("Error #"); Serial.println(res); return; }

Serial.print("0x"); Serial.println(reg, HEX); Serial.println("----------"); uint8_t t=0; for (uint8_t i=0; i<len; i++) {
Serial.print("0x"); Serial.print(buf[i], HEX); Serial.print(", "); t++; if (t>=16) { Serial.println(); t=0; } } Serial.println(); Serial.println("----------"); Serial.print("0x"); Serial.println(last, HEX); }

nik-sharky commented 6 years ago

Just call dumpRegs(0x8047, 0x8100);

microyumcc commented 6 years ago

thats great, but im sorry, because now is 1:20am . i was out of my office.

but can u write the config success with ur touch panel?

nik-sharky commented 6 years ago

Check now.

An example of config dump from my lenovo tab touch. uint8_t g911xLenovoTab[] = {0x81, 0x80, 0x7, 0xB0, 0x4, 0xA, 0xD, 0x20, 0x1, 0x8, 0x28, 0x5, 0x50, 0x32, 0x3, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x1A, 0x1D, 0x14, 0x95, 0x35, 0xFF, 0x46, 0x48, 0x31, 0xD, 0x0, 0x0, 0x0, 0x80, 0x3, 0x1D, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1D, 0x59, 0x94, 0xC5, 0x2, 0x8, 0x0, 0x0, 0x4, 0xFF, 0xFF, 0xFF, 0xC3, 0x28, 0x0, 0xA0, 0x33, 0x0, 0xFF, 0xFF, 0x0, 0x75, 0x50, 0x0, 0x75, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x7F, 0xC0, 0x0, 0x0, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x88};

nik-sharky commented 6 years ago

Works, chip save config in internal memory, maybe you forgot set 0x8100 to 1 on config write.

Also add some methods for write new resolution to chip config, You can use it as reference for making config changes.

microyumcc commented 6 years ago

thanks for your patience!

i try to write, but also no change! this is my setup functions:

void setup() { Serial.begin(115200); //log_println("\nGoodix GT911x touch driver");

Wire.setClock(400000); Wire.begin(); delay(300); touch.setHandler(handleTouch); touchStart(); dumpRegs(0x8047, 0x8100); //touch.write(GOODIX_REG_CONFIG_DATA, g911xFW, sizeof(g911xFW)); touch.fwResolution(1024, 800); }

nik-sharky commented 6 years ago

Looks normal, should work. Which chip version do You use 911, 9110 or other?

microyumcc commented 6 years ago

its 911.

Orma07 commented 5 years ago

Hello, I also have this problem. I cannot write any registes of the GT911. Even the registers that are outsider the configuration range of addresses. The weird thing is: I can read correctly the GT911 registers! But I cannot write them.

Another weird thing is that register 0x8047 is equal to 95 (correspondig to ASCII "_") while the maximum available value should be 90 (corresponding to ASCII "Z").

Does anyone know what the issue may be?? Thanks.

ellion270 commented 4 years ago

This is a problem with the wire library in arduino. Internal data buffer for more than 32 bytes

ellion270 commented 4 years ago

You need to use the twi.c library

hadiinfo commented 4 years ago

Hi Ellion270

I am trying to compile this for for Arduino Mega 2560 and I get error. Are you saying that wire library should not be used? Where can I get twi.c ?

Thanks