Skip to content
82 changes: 57 additions & 25 deletions GSL1680.ino
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
// Original comments:
// driver for the GSL1680 touch panel
// Information gleaned from https://github.com/rastersoft/gsl1680.git 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
// As was some test code.
// This is for that 800X480 display and the 480x272 from buydisplay.com
// ------
// Modified by Helge Langehaug with help from https://forum.pjrc.com/threads/26256-Has-anyone-tried-running-the-GSL16880-capacitive-touchscreen-controller-with-Teensy3

/*
Pin outs
the FPC on the touch panel is six pins, pin 1 is to the left pin 6 to the right with the display facing up

pin | function | Arduino Uno
-----------------------------
1 | SCL | A5
2 | SDA | A4
3 | VDD (3v3) | 3v3
4 | Wake | 4
5 | Int | 2
6 | Gnd | gnd
pin | function | Arduino Mega | Arduino Uno
--------------------------------------------
1 | SCL | SCL(21) | A5
2 | SDA | SDA(20) | A4
3 | VDD (3v3) | 3v3 | 3v3
4 | Wake | 4 | 4
5 | Int | 2 | 2
6 | Gnd | gnd | gnd
*/
#include <Wire.h>
#include "Arduino.h"

// set this for teensy3
#define BIGFLASH

#define GET_FAR_ADDRESS(var) \
({ \
uint_farptr_t tmp; \
\
__asm__ __volatile__( \
\
"ldi %A0, lo8(%1)" "\n\t" \
"ldi %B0, hi8(%1)" "\n\t" \
"ldi %C0, hh8(%1)" "\n\t" \
"clr %D0" "\n\t" \
: \
"=d" (tmp) \
: \
"p" (&(var)) \
); \
tmp; \
})


// TODO define for other resolution
#ifndef BIGFLASH
#include "gslfw.h" // this is compacted format made by compress_data.c
Expand Down Expand Up @@ -190,25 +211,29 @@ void load_fw(void)
}

#else

void load_fw(void)
{
{
uint8_t addr;
uint8_t Wrbuf[4];
uint source_line = 0;
uint source_len = sizeof(GSLX680_FW) / sizeof(struct fw_data);

uint16_t source_line = 0;
uint16_t source_len = sizeof(GSLX680_FW) / sizeof(struct fw_data);
Serial.print("Firmware size: "); Serial.println(sizeof(GSLX680_FW));
Serial.print("Line numbers : "); Serial.println(source_len);

for (source_line = 0; source_line < source_len; source_line++) {
addr = GSLX680_FW[source_line].offset;
Wrbuf[0] = (char)(GSLX680_FW[source_line].val & 0x000000ff);
Wrbuf[1] = (char)((GSLX680_FW[source_line].val & 0x0000ff00) >> 8);
Wrbuf[2] = (char)((GSLX680_FW[source_line].val & 0x00ff0000) >> 16);
Wrbuf[3] = (char)((GSLX680_FW[source_line].val & 0xff000000) >> 24);

addr = pgm_read_byte_far(GET_FAR_ADDRESS(GSLX680_FW[0].offset)+source_line*5);

Wrbuf[0] = (char) (pgm_read_dword_far(GET_FAR_ADDRESS(GSLX680_FW[0].val)+source_line*5) & 0x000000ff);

i2c_write(addr, Wrbuf, 4);
Wrbuf[1] = (char) ((pgm_read_dword_far(GET_FAR_ADDRESS(GSLX680_FW[0].val)+source_line*5) & 0x0000ff00) >> 8);
Wrbuf[2] = (char) ((pgm_read_dword_far(GET_FAR_ADDRESS(GSLX680_FW[0].val)+source_line*5) & 0x00ff0000) >> 16);
Wrbuf[3] = (char) ((pgm_read_dword_far(GET_FAR_ADDRESS(GSLX680_FW[0].val)+source_line*5) & 0xff000000) >> 24);

i2c_write(addr, Wrbuf, 4);
}
}

#endif

void startup_chip(void)
Expand All @@ -228,16 +253,22 @@ void init_chip()
digitalWrite(WAKE, LOW);
delay(50);
digitalWrite(WAKE, HIGH);
delay(30);
delay(10);

// CTP startup sequence
Serial.println("clr reg");
clr_reg();
delay(50);

Serial.println("reset_chip");
reset_chip();
delay(10);

Serial.println("load_fw");
load_fw();
//startup_chip();
delay(50);

startup_chip();
Serial.println("reset_chip2");
reset_chip();
Serial.println("startup_chip");
Expand Down Expand Up @@ -290,7 +321,7 @@ void setup() {
pinMode(WAKE, OUTPUT);
digitalWrite(WAKE, LOW);
pinMode(INTRPT, INPUT_PULLUP);
delay(100);
delay(10);
Wire.begin();
init_chip();

Expand All @@ -303,14 +334,15 @@ void setup() {

void loop() {
if(digitalRead(INTRPT) == HIGH) {
digitalWrite(LED, led);
led= !led;
//digitalWrite(LED, led);
//led= !led;
int n= read_data();
for(int i=0; i<n; i++){
Serial.print(ts_event.coords[i].finger); Serial.print(" "), Serial.print(ts_event.coords[i].x); Serial.print(" "), Serial.print(ts_event.coords[i].y);
Serial.println("");
}
Serial.println("---");
}

}

11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# GSL1680
Arduino library for the GSL1680 touch panel controller
Arduino library for the GSL1680 touch panel controller.

Currently just a test sketch, hard coded for the 800x640 5" panel.
Currently works for Arduino MEGA and hardcoded for 800x640 5" capacitive touch panel from BuyDisplay.

The firmware file is big so it needed to be compressed to fit in an Uno flash memory.
The firmware file is big so it needed to be compressed to fit in an Uno flash memory (currently not tested)

Once tested and working I'll convert to a library, and have a #define for the two version of firmware
for the 5" panels from buydisplay.com.
Fork of wolfmanjm/GSL1680 and updated to work with Arduino Mega, ref. discussions on: https://forum.pjrc.com/threads/26256-Has-anyone-tried-running-the-GSL16880-capacitive-touchscreen-controller-with-Teensy3

Blog entry: https://weatherhelge.wordpress.com/2015/02/09/5-capacitive-touch-panel-with-gsl1680-upn-running-with-arduino/
Loading