Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #7 Correction / If SHUTDOWN (WAKE pin) feature is not needed, the pin can be leave unconnected Issue #9 #8

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
87 changes: 50 additions & 37 deletions GSL1680.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,35 @@ GSL1680::GSL1680(bool error, bool info) {
GSL1680_DEBUG_INFO = info;
}

void GSL1680::begin(uint8_t WAKE, uint8_t INTRPT)
void GSL1680::begin(uint8_t INTRPT)
{
begin(-1, INTRPT);
}

void GSL1680::begin(int16_t WAKE, uint8_t INTRPT)
{
SERIAL_INFORMATION.println("GSL1680: Start boot up sequence");
pinMode(WAKE, OUTPUT); //
digitalWrite(WAKE, LOW); //

if(WAKE >= 0) {
pinMode(WAKE, OUTPUT); //
digitalWrite(WAKE, LOW); //
} else {
SERIAL_INFORMATION.println("WAKE pin is not being used, need to leave it disconnected");
}

pinMode(INTRPT, INPUT_PULLUP); // Startup sequence PIN part
delay(100);

SERIAL_INFORMATION.println("Toggle Wake");
if(WAKE >= 0) {
SERIAL_INFORMATION.println("Toggle Wake");
digitalWrite(WAKE, HIGH);
delay(50);
digitalWrite(WAKE, LOW);
delay(50);
digitalWrite(WAKE, HIGH);
delay(30);

}

Wire.begin();

// CTP startup sequence
Expand All @@ -77,20 +90,14 @@ void GSL1680::clear_reg()
uint8_t DATA[4] = {0x88, 0x01, 0x04, 0x00};
uint8_t TIMER[4] = {20, 5, 5, 20};

Wire.beginTransmission(I2CADDR);
uint8_t _data[1];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of an array of 1, just make it an uint8_t


int i;
for (i = 0; i < 4; ++i) {
Wire.write(REG[i]);
Wire.write(DATA[i]);
delay(TIMER[i]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a delay here? I don't have the hardware anymore but I remember spending a lot of time figuring out the timings, it wouldn't work otherwise

_data[0] = DATA[i];

datasend(REG[i], _data, 1);
}

int r = Wire.endTransmission();
if (r != 0){
SERIAL_ERROR.print("i2c write error: "); SERIAL_ERROR.print(r); SERIAL_ERROR.print(" "); SERIAL_ERROR.println(REG[i], HEX);
}

}

void GSL1680::reset()
Expand All @@ -99,24 +106,19 @@ void GSL1680::reset()
uint8_t DATA[2] = {0x88, 0x04};
uint8_t TIMER[2] = {20, 10};

Wire.beginTransmission(I2CADDR);
uint8_t _data[1];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


int i;
for (i = 0; i < 2; ++i) {
Wire.write(REG[i]);
Wire.write(DATA[i]);
delay(TIMER[i]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, no more delay?

}

int r = Wire.endTransmission();
if (r != 0){
SERIAL_ERROR.print("i2c write error: "); SERIAL_ERROR.print(r); SERIAL_ERROR.print(" "); SERIAL_ERROR.println(REG[i], HEX);
_data[0] = DATA[i];

datasend(REG[i], _data, 1);
}

uint8_t DATA_2[4] = {0};

datasend (0xBC, DATA_2, 4);
delay(10);
delayMicroseconds(1500); // software reset takes ~1 ms
}

void GSL1680::loadfw()
Expand All @@ -138,15 +140,9 @@ void GSL1680::loadfw()

void GSL1680::startchip()
{
Wire.beginTransmission(I2CADDR);

Wire.write(0xE0); //Registre
Wire.write(0x00); //DATA

int r = Wire.endTransmission();
if (r != 0){
SERIAL_ERROR.print("i2c write error: "); SERIAL_ERROR.print(r); SERIAL_ERROR.print(" "); SERIAL_ERROR.println(0xE0, HEX);
}
uint8_t _data[1] = {0};

datasend(0xE0, _data, 1);
}

void GSL1680::sleep()
Expand All @@ -165,8 +161,17 @@ void GSL1680::datasend(uint8_t REG, uint8_t DATA[], uint16_t NB)
}

int r = Wire.endTransmission();
if (r != 0) {
SERIAL_ERROR.print("i2c write error: "); SERIAL_ERROR.print(r); SERIAL_ERROR.print(" "); SERIAL_ERROR.println(REG, HEX);
if (r != 0){
if(r == 5) {
SERIAL_ERROR.println("i2c write error: timeout");
} else {
SERIAL_ERROR.print("i2c write error: ");
SERIAL_ERROR.print(r);
SERIAL_ERROR.print(" ");
SERIAL_ERROR.println(REG, HEX);
}

SERIAL_ERROR.println();
}
}

Expand All @@ -179,8 +184,16 @@ uint8_t GSL1680::dataread()
Wire.write(DATA_REG);

int n = Wire.endTransmission();

if (n != 0) {
SERIAL_ERROR.print("i2c write error: "); SERIAL_ERROR.print(n); SERIAL_ERROR.print(" "); SERIAL_ERROR.println(DATA_REG, HEX);
if(n == 5) {
SERIAL_ERROR.println("i2c write error: timeout");
} else {
SERIAL_ERROR.print("i2c write error: ");
SERIAL_ERROR.print(n);
SERIAL_ERROR.print(" ");
SERIAL_ERROR.println(DATA_REG, HEX);
}
Comment on lines +189 to +196
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code is in 2 places, could you make a function out of it?

}

n = Wire.requestFrom(I2CADDR, 24);
Expand Down
3 changes: 2 additions & 1 deletion GSL1680.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class GSL1680 {
GSL1680();
GSL1680(bool error, bool info);

void begin(uint8_t WAKE, uint8_t INTRPT);
void begin(int16_t WAKE, uint8_t INTRPT); /* If you don't use this pin, leave WAKE=-1 */
void begin(uint8_t INTRPT); /* If you don't use the pin WAKE */
uint8_t dataread();
uint8_t readFingerID(int NB);
uint32_t readFingerX(int NB);
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ pin | function | Arduino Uno

Warning : Firmware is really heavy so this library cannot be used in some Arduino boards

[Tested with ESP32 DEV KIT V1]
- Note: Wake pin is optional
- INT pin is recommended, or multiple readings must be made to be sure of the data.

## Thanks
Information gleaned from https://github.com/rastersoft/gsl1680 and various other sources
Firmware for the specific panel was found here: http://www.buydisplay.com/default/5-inch-tft-lcd-module-800x480-display-w-controller-i2c-serial-spi
Expand Down