-
Notifications
You must be signed in to change notification settings - Fork 4
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
base: master
Are you sure you want to change the base?
Changes from all commits
7540c64
e66837b
bc76db1
3b6aefa
2fabd24
defa205
d4313a4
4bc4769
76c30c0
9b941db
610cc81
bc2d630
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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]; | ||
|
||
int i; | ||
for (i = 0; i < 4; ++i) { | ||
Wire.write(REG[i]); | ||
Wire.write(DATA[i]); | ||
delay(TIMER[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
@@ -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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, no more |
||
} | ||
|
||
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() | ||
|
@@ -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() | ||
|
@@ -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(); | ||
} | ||
} | ||
|
||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment.
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