lvgl_example Touch interrupt method https://github.com/Xinyuan-LilyGO/T-Deck/issues/42
This commit is contained in:
@@ -8,8 +8,46 @@
|
|||||||
static void slider_event_cb(lv_event_t *e);
|
static void slider_event_cb(lv_event_t *e);
|
||||||
static lv_obj_t *slider_label;
|
static lv_obj_t *slider_label;
|
||||||
|
|
||||||
TouchLib touch = TouchLib(Wire, BOARD_I2C_SDA, BOARD_I2C_SCL, GT911_SLAVE_ADDRESS1);
|
|
||||||
TFT_eSPI tft;
|
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
|
// LilyGo T-Deck control backlight chip has 16 levels of adjustment range
|
||||||
@@ -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 );
|
lv_disp_flush_ready( disp );
|
||||||
}
|
}
|
||||||
|
|
||||||
static volatile bool touch_irq = false;
|
|
||||||
|
|
||||||
static bool getTouch(int16_t &x, int16_t &y)
|
static bool getTouch(int16_t &x, int16_t &y)
|
||||||
{
|
{
|
||||||
|
if (! digitalRead(BOARD_TOUCH_INT))return false;
|
||||||
uint8_t rotation = tft.getRotation();
|
uint8_t rotation = tft.getRotation();
|
||||||
if (!touch.read()) {
|
if (!touch->read()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
TP_Point t = touch.getPoint(0);
|
TP_Point t = touch->getPoint(0);
|
||||||
switch (rotation) {
|
switch (rotation) {
|
||||||
case 1:
|
case 1:
|
||||||
x = t.y;
|
x = t.y;
|
||||||
@@ -191,9 +229,19 @@ void setup()
|
|||||||
tft.fillScreen(TFT_BLACK);
|
tft.fillScreen(TFT_BLACK);
|
||||||
|
|
||||||
// Set touch int input
|
// Set touch int input
|
||||||
pinMode(BOARD_TOUCH_INT, INPUT); delay(20);
|
pinMode(BOARD_TOUCH_INT, INPUT);
|
||||||
|
delay(20);
|
||||||
|
|
||||||
touch.init();
|
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();
|
||||||
|
|
||||||
setupLvgl();
|
setupLvgl();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user