Created
November 4, 2022 15:32
-
-
Save lucasmontec/0a29ce962ee3bac458b191ec16b4266f to your computer and use it in GitHub Desktop.
Issue with GUI library using touch on a GT911
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define LGFX_USE_V1 // v1.0.0 | |
#define GT911_ADDR1 (uint8_t)0x5D | |
#define GT911_ADDR2 (uint8_t)0x14 | |
#include <LovyanGFX.hpp> | |
// ESP32 LovyanGFX | |
class LGFX : public lgfx::LGFX_Device | |
{ | |
lgfx::Panel_ST7796 _panel_instance; | |
lgfx::Bus_SPI _bus_instance; | |
lgfx::Light_PWM _light_instance; | |
lgfx::Touch_GT911 _touch_instance; | |
public: | |
LGFX(void) | |
{ | |
{ | |
auto cfg = _bus_instance.config(); | |
// SPI | |
cfg.spi_host = HSPI_HOST; // This display is hooked into HSPI (GPIO 13,12,14,15) | |
// ESP-IDF VSPI_HOST , HSPI_HOST SPI2_HOST , SPI3_HOST | |
cfg.spi_mode = 0; // SPI (0 ~ 3) | |
cfg.freq_write = 55000000; // SPI (80MHz, 80MHz) | |
cfg.freq_read = 20000000; // SPI | |
cfg.spi_3wire = false; // MOSI true | |
cfg.use_lock = true; // true | |
cfg.dma_channel = 1; // DMA / 1=1ch / 2=ch / SPI_DMA_CH_AUTO=) | |
// ESP-IDF DMA SPI_DMA_CH_AUTO 1ch,2ch | |
cfg.pin_sclk = 14; // SPI SCLK | |
cfg.pin_mosi = 13; // SPI MOSI | |
cfg.pin_miso = 12; // SPI MISO (-1 = disable) | |
cfg.pin_dc = 2; // SPI D/C (-1 = disable) | |
// SD SPI | |
_bus_instance.config(cfg); | |
_panel_instance.setBus(&_bus_instance); | |
} | |
{ | |
auto cfg = _panel_instance.config(); | |
cfg.pin_cs = 15; // CS (-1 = disable) | |
cfg.pin_rst = 2; // RST (-1 = disable) | |
cfg.pin_busy = -1; // BUSY (-1 = disable) | |
cfg.panel_width = 320; | |
cfg.panel_height = 480; | |
cfg.offset_x = 0; | |
cfg.offset_y = 0; | |
cfg.offset_rotation = 0; // 0~7 (4~7) | |
cfg.dummy_read_pixel = 8; | |
cfg.dummy_read_bits = 1; | |
cfg.readable = true; // true | |
cfg.invert = false; // true | |
cfg.rgb_order = false; // true | |
cfg.dlen_16bit = false; // 16bit SPI true | |
cfg.bus_shared = true; // SD true(drawJpgFile) | |
_panel_instance.config(cfg); | |
} | |
{ | |
auto cfg = _light_instance.config(); | |
cfg.pin_bl = 27; | |
cfg.invert = false; | |
cfg.freq = 44100; | |
cfg.pwm_channel = 7; | |
_light_instance.config(cfg); | |
_panel_instance.setLight(&_light_instance); | |
} | |
{ | |
auto cfg = _touch_instance.config(); | |
cfg.x_min = 0; // Minimum X value (raw value) obtained from touch screen | |
cfg.x_max = 319; // Maximum X value (raw value) obtained from the touch screen | |
cfg.y_min = 0; // Minimum Y value (raw value) obtained from touch screen | |
cfg.y_max = 479; // Maximum Y value (raw value) obtained from the touch screen | |
cfg.bus_shared = false; // Set to true if you are using the same bus as the screen | |
cfg.offset_rotation = 0;// Adjustment when the display and touch orientation do not match Set with a value from 0 to 7 | |
cfg.pin_rst = 25; | |
cfg.pin_int = 21; // Pin number to which INT is connected | |
cfg.i2c_port = 1; // I2C(0 or 1) Must be 1 to use Wire library not Wire1 (I tested with Wire and it read) | |
cfg.i2c_addr = GT911_ADDR1; // I2C | |
cfg.pin_sda = 33; // SDA | |
cfg.pin_scl = 32; // SCL | |
cfg.freq = 400000; // I2C | |
_touch_instance.config(cfg); | |
_panel_instance.setTouch(&_touch_instance); | |
} | |
setPanel(&_panel_instance); | |
} | |
}; | |
LGFX display; | |
void setup(void) | |
{ | |
Serial.begin(115200); | |
// SPI | |
display.init(); | |
display.setTextSize((std::max(display.width(), display.height()) + 255) >> 8); | |
if (display.touch()) | |
{ | |
if (display.width() < display.height()) display.setRotation(display.getRotation() ^ 1); | |
display.setTextDatum(textdatum_t::middle_center); | |
display.drawString("touch touchy.", display.width()>>1, display.height() >> 1); | |
display.setTextDatum(textdatum_t::top_left); | |
std::uint16_t fg = TFT_WHITE; | |
std::uint16_t bg = TFT_BLACK; | |
if (display.isEPD()) std::swap(fg, bg); | |
display.calibrateTouch(nullptr, fg, bg, std::max(display.width(), display.height()) >> 3); | |
} | |
display.fillScreen(TFT_BLACK); | |
} | |
uint32_t count = ~0; | |
void loop(void) | |
{ | |
display.startWrite(); | |
display.setRotation(++count & 7); | |
display.setColorDepth((count & 8) ? 16 : 24); | |
display.setTextColor(TFT_WHITE); | |
display.drawNumber(display.getRotation(), 16, 0); | |
display.setTextColor(0xFF0000U); | |
display.drawString("R", 30, 16); | |
display.setTextColor(0x00FF00U); | |
display.drawString("G", 40, 16); | |
display.setTextColor(0x0000FFU); | |
display.drawString("B", 50, 16); | |
display.drawRect(30,30,display.width()-60,display.height()-60,count*7); | |
display.drawFastHLine(0, 0, 10); | |
display.endWrite(); | |
int32_t x, y; | |
if (display.getTouch(&x, &y)) { | |
display.fillRect(x-2, y-2, 5, 5, count*7); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment