Skip to content

Commit

Permalink
lvgl_example Touch interrupt method #42
Browse files Browse the repository at this point in the history
  • Loading branch information
lewisxhe committed Sep 4, 2024
1 parent f979f22 commit 12f6864
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions examples/lvgl_example/lvgl_example.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,46 @@
static void slider_event_cb(lv_event_t *e);
static lv_obj_t *slider_label;

TouchLib touch = TouchLib(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, GT911_SLAVE_ADDRESS1);
TFT_eSPI tft;
TouchLib *touch = NULL;
uint8_t touchAddress = GT911_SLAVE_ADDRESS2;

void scanDevices(TwoWire *w)
{
uint8_t err, addr;
int nDevices = 0;
uint32_t start = 0;
for (addr = 1; addr < 127; addr++) {
start = millis();
w->beginTransmission(addr); delay(2);
err = w->endTransmission();
if (err == 0) {
nDevices++;
Serial.print("I2C device found at address 0x");
if (addr < 16) {
Serial.print("0");
}
Serial.print(addr, HEX);
Serial.println(" !");

if (addr == GT911_SLAVE_ADDRESS2) {
touchAddress = GT911_SLAVE_ADDRESS2;
Serial.println("Find GT911 Drv Slave address: 0x14");
} else if (addr == GT911_SLAVE_ADDRESS1) {
touchAddress = GT911_SLAVE_ADDRESS1;
Serial.println("Find GT911 Drv Slave address: 0x5D");
}
} else if (err == 4) {
Serial.print("Unknow error at address 0x");
if (addr < 16) {
Serial.print("0");
}
Serial.println(addr, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
}


// LilyGo T-Deck control backlight chip has 16 levels of adjustment range
Expand Down Expand Up @@ -54,15 +92,15 @@ static void disp_flush( lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *
lv_disp_flush_ready( disp );
}

static volatile bool touch_irq = false;

static bool getTouch(int16_t &x, int16_t &y)
{
if (! digitalRead(BOARD_TOUCH_INT))return false;
uint8_t rotation = tft.getRotation();
if (!touch.read()) {
if (!touch->read()) {
return false;
}
TP_Point t = touch.getPoint(0);
TP_Point t = touch->getPoint(0);
switch (rotation) {
case 1:
x = t.y;
Expand Down Expand Up @@ -191,9 +229,19 @@ void setup()
tft.fillScreen(TFT_BLACK);

// Set touch int input
pinMode(BOARD_TOUCH_INT, INPUT); delay(20);
pinMode(BOARD_TOUCH_INT, INPUT);
delay(20);

Wire.begin(BOARD_I2C_SDA, BOARD_I2C_SCL);


// Two touch screens, the difference between them is the device address,
// use ScanDevices to get the existing I2C address
scanDevices(&Wire);

touch = new TouchLib(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, touchAddress);

touch.init();
touch->init();

setupLvgl();

Expand Down

0 comments on commit 12f6864

Please sign in to comment.