From d72e9080460e0dd1e6b14baef2c91a51ef785196 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Fri, 4 Apr 2025 13:30:31 +0000 Subject: [PATCH 01/25] remove duplicate HAS_LP5562 introduced by #6422 --- src/detect/ScanI2CTwoWire.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 230271b94..9781cbf56 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -227,9 +227,6 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) type = PMU_AXP192_AXP2101; } break; -#ifdef HAS_LP5562 - SCAN_SIMPLE_CASE(LP5562_ADDR, LP5562, "LP5562", (uint8_t)addr.address); -#endif case BME_ADDR: case BME_ADDR_ALTERNATE: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xD0), 1); // GET_ID From f7bc4d82c749d8dcb30becd6f89fec6c78bf7b00 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 12 Apr 2025 12:59:09 +0000 Subject: [PATCH 02/25] add ST7796 --- src/configuration.h | 2 ++ src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 8 ++++-- src/graphics/Screen.cpp | 50 ++++++++++++++++++++++++++++++++--- src/graphics/Screen.h | 2 ++ src/graphics/ScreenFonts.h | 2 +- src/graphics/images.h | 2 +- src/main.cpp | 2 +- src/mesh/NodeDB.cpp | 2 +- variants/tbeam/platformio.ini | 10 ++++--- variants/tbeam/variant.h | 33 ++++++++++++++++++++--- 11 files changed, 96 insertions(+), 18 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index d319ddb0a..4138d6950 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -187,6 +187,8 @@ along with this program. If not, see . // Touchscreen // ----------------------------------------------------------------------------- #define FT6336U_ADDR 0x48 +#define CST226SE_ADDR 0x1A +#define CST226SE_ADDR_ALT 0x5A // ----------------------------------------------------------------------------- // BIAS-T Generator diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index c363db1b5..e43bc7017 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -71,6 +71,7 @@ class ScanI2C DPS310, LTR390UV, TCA8418KB, + CST226SE, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 9781cbf56..b9db60029 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -439,8 +439,12 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) #endif case MLX90614_ADDR_DEF: - registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0e), 1); - if (registerValue == 0x5a) { + // Do we have the MLX90614 or the MPR121KB or the CST226SE + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x06), 1); + if (registerValue == 0xAB) { + type = CST226SE; + logFoundDevice("CST226SE", (uint8_t)addr.address); + } else if (getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0e), 1) == 0x5a) { type = MLX90614; logFoundDevice("MLX90614", (uint8_t)addr.address); } else { diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 8075dd468..a153d9519 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1104,7 +1104,7 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const NodeStat char usersString[20]; snprintf(usersString, sizeof(usersString), "%d/%d", nodeStatus->getNumOnline(), nodeStatus->getNumTotal()); #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x, y + 3, 8, 8, imgUser); #else @@ -1525,6 +1525,8 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ #if defined(ESP_PLATFORM) && defined(USE_ST7789) SPIClass SPI1(HSPI); +#elif defined(ESP_PLATFORM) && defined(USE_ST7796) +SPIClass SPI3(VSPI); #endif Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_OledType screenType, OLEDDISPLAY_GEOMETRY geometry) @@ -1541,6 +1543,13 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O #else dispdev = new ST7789Spi(&SPI1, ST7789_RESET, ST7789_RS, ST7789_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); #endif +#elif defined(USE_ST7796) +#ifdef ESP_PLATFORM + dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT, ST7796_SDA, + ST7796_MISO, ST7796_SCK); +#else + dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); +#endif #elif defined(USE_SSD1306) dispdev = new SSD1306Wire(address.address, -1, -1, geometry, (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); @@ -1632,6 +1641,17 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) pinMode(VTFT_LEDA, OUTPUT); digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON); #endif +#endif +#ifdef USE_ST7796 + pinMode(VTFT_CTRL, OUTPUT); + digitalWrite(VTFT_CTRL, LOW); + ui->init(); +#ifdef ESP_PLATFORM + analogWrite(VTFT_LEDA, BRIGHTNESS_DEFAULT); +#else + pinMode(VTFT_LEDA, OUTPUT); + digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON); +#endif #endif enabled = true; setInterval(0); // Draw ASAP @@ -1666,6 +1686,22 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) nrf_gpio_cfg_default(ST7789_NSS); #endif #endif +#ifdef USE_ST7796 + SPI3.end(); +#if defined(ARCH_ESP32) + pinMode(VTFT_LEDA, ANALOG); + pinMode(VTFT_CTRL, ANALOG); + pinMode(ST7796_RESET, ANALOG); + pinMode(ST7796_RS, ANALOG); + pinMode(ST7796_NSS, ANALOG); +#else + nrf_gpio_cfg_default(VTFT_LEDA); + nrf_gpio_cfg_default(VTFT_CTRL); + nrf_gpio_cfg_default(ST7796_RESET); + nrf_gpio_cfg_default(ST7796_RS); + nrf_gpio_cfg_default(ST7796_NSS); +#endif +#endif #ifdef T_WATCH_S3 PMU->disablePowerOutput(XPOWERS_ALDO2); @@ -1695,6 +1731,10 @@ void Screen::setup() // Heltec T114 and T190: honor a custom text color, if defined in variant.h static_cast(dispdev)->setRGB(TFT_MESH); #endif +#if defined(USE_ST7796) && defined(TFT_MESH) + // Custom text color, if defined in variant.h + static_cast(dispdev)->setRGB(TFT_MESH); +#endif // Initialising the UI will init the display too. ui->init(); @@ -1755,6 +1795,8 @@ void Screen::setup() static_cast(dispdev)->flipScreenVertically(); #elif defined(USE_ST7789) static_cast(dispdev)->flipScreenVertically(); +#elif defined(USE_ST7796) + static_cast(dispdev)->flipScreenVertically(); #else dispdev->flipScreenVertically(); #endif @@ -2490,7 +2532,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 if (!Throttle::isWithinTimespanMs(storeForwardModule->lastHeartbeat, (storeForwardModule->heartbeatInterval * 1200))) { // no heartbeat, overlap a bit #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgQuestionL1); @@ -2502,7 +2544,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 #endif } else { #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8, imgSFL1); @@ -2517,7 +2559,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } else { // TODO: Raspberry Pi supports more than just the one screen size #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL1); diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index ce416156f..1f63d1fe6 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -47,6 +47,8 @@ class Screen #include #elif defined(USE_ST7789) #include +#elif defined(USE_ST7796) +#include #else // the SH1106/SSD1306 variant is auto-detected #include diff --git a/src/graphics/ScreenFonts.h b/src/graphics/ScreenFonts.h index 079a3e282..0c76f756a 100644 --- a/src/graphics/ScreenFonts.h +++ b/src/graphics/ScreenFonts.h @@ -65,7 +65,7 @@ #endif #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) // The screen is bigger so use bigger fonts #define FONT_SMALL FONT_MEDIUM_LOCAL // Height: 19 diff --git a/src/graphics/images.h b/src/graphics/images.h index b757dcf30..db5fd710e 100644 --- a/src/graphics/images.h +++ b/src/graphics/images.h @@ -21,7 +21,7 @@ const uint8_t bluetoothConnectedIcon[36] PROGMEM = {0xfe, 0x01, 0xff, 0x03, 0x03 #endif #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff}; const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f}; diff --git a/src/main.cpp b/src/main.cpp index bfbd73a43..8695ecbd0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -934,7 +934,7 @@ void setup() // Don't call screen setup until after nodedb is setup (because we need // the current region name) #if defined(ST7701_CS) || defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || \ - defined(ST7789_CS) || defined(HX8357_CS) || defined(USE_ST7789) + defined(ST7789_CS) || defined(HX8357_CS) || defined(USE_ST7789) || defined(USE_ST7796) screen->setup(); #elif defined(ARCH_PORTDUINO) if (screen_found.port != ScanI2C::I2CPort::NO_I2C || settingsMap[displayPanel]) { diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index c89abbe74..7ebe6b8bd 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -595,7 +595,7 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) config.bluetooth.fixed_pin = defaultBLEPin; #if defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7789_CS) || \ - defined(HX8357_CS) || defined(USE_ST7789) + defined(HX8357_CS) || defined(USE_ST7789) || defined(USE_ST7796) bool hasScreen = true; #ifdef HELTEC_MESH_NODE_T114 uint32_t st7789_id = get_st7789_id(ST7789_NSS, ST7789_SCK, ST7789_SDA, ST7789_RS, ST7789_RESET); diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index 9049836a3..a8b95d91b 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -3,10 +3,12 @@ extends = esp32_base board = ttgo-t-beam board_check = true -lib_deps = - ${esp32_base.lib_deps} -build_flags = - ${esp32_base.build_flags} -D TBEAM_V10 -I variants/tbeam +lib_deps = ${esp32_base.lib_deps} + lewisxhe/SensorLib@0.2.0 ; touchscreen addon + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.1.zip ; display addon +build_flags = ${esp32_base.build_flags} + -DTBEAM_V10 + -Ivariants/tbeam -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 8771c20d2..07056f5cf 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -6,10 +6,10 @@ #define BUTTON_PIN 38 // The middle button GPIO on the T-Beam // #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented // anywhere. -#define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. +// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. -#define LED_STATE_ON 0 // State when LED is lit -#define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 +// #define LED_STATE_ON 0 // State when LED is lit +// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 // TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if // not found then probe for SX1262 @@ -42,4 +42,29 @@ #define GPS_UBLOX #define GPS_RX_PIN 34 #define GPS_TX_PIN 12 -// #define GPS_DEBUG \ No newline at end of file +// #define GPS_DEBUG + +// Display addon +#define HAS_CST226SE +#define USE_ST7796 +#define ST7796_NSS 25 +#define ST7796_RS 13 // DC +#define ST7796_SDA 14 // MOSI +#define ST7796_SCK 15 +#define ST7796_RESET 2 +#define ST7796_MISO -1 +#define ST7796_BUSY -1 +#define VTFT_CTRL 7 +#define VTFT_LEDA 4 +#define TFT_BACKLIGHT_ON HIGH +#define ST7796_SPI_HOST VSPI_HOST +#define SPI_FREQUENCY 10000000 +#define SPI_READ_FREQUENCY 10000000 +#define TFT_HEIGHT 222 +#define TFT_WIDTH 480 +#define TFT_OFFSET_X 0 +#define TFT_OFFSET_Y 0 +// #define TFT_OFFSET_ROTATION 0 +// #define SCREEN_ROTATE +// #define SCREEN_TRANSITION_FRAMERATE 5 +#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes \ No newline at end of file From 251c00671295c45d20b3fcddb238ebea47240dd4 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 12 Apr 2025 16:31:22 +0000 Subject: [PATCH 03/25] changes to get display centered+lib update --- src/graphics/Screen.cpp | 5 +---- variants/tbeam/platformio.ini | 2 +- variants/tbeam/variant.h | 13 +++++-------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index a153d9519..01ff06218 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1643,8 +1643,6 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) #endif #endif #ifdef USE_ST7796 - pinMode(VTFT_CTRL, OUTPUT); - digitalWrite(VTFT_CTRL, LOW); ui->init(); #ifdef ESP_PLATFORM analogWrite(VTFT_LEDA, BRIGHTNESS_DEFAULT); @@ -1690,7 +1688,6 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) SPI3.end(); #if defined(ARCH_ESP32) pinMode(VTFT_LEDA, ANALOG); - pinMode(VTFT_CTRL, ANALOG); pinMode(ST7796_RESET, ANALOG); pinMode(ST7796_RS, ANALOG); pinMode(ST7796_NSS, ANALOG); @@ -1796,7 +1793,7 @@ void Screen::setup() #elif defined(USE_ST7789) static_cast(dispdev)->flipScreenVertically(); #elif defined(USE_ST7796) - static_cast(dispdev)->flipScreenVertically(); + static_cast(dispdev)->mirrorScreen(); #else dispdev->flipScreenVertically(); #endif diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index a8b95d91b..294eea61f 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -5,7 +5,7 @@ board = ttgo-t-beam board_check = true lib_deps = ${esp32_base.lib_deps} lewisxhe/SensorLib@0.2.0 ; touchscreen addon - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.1.zip ; display addon + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon build_flags = ${esp32_base.build_flags} -DTBEAM_V10 -Ivariants/tbeam diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 07056f5cf..78a1d8115 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -45,7 +45,10 @@ // #define GPS_DEBUG // Display addon +#define HAS_TOUCHSCREEN 1 +#define USE_VIRTUAL_KEYBOARD 1 #define HAS_CST226SE +#define SCREEN_TOUCH_INT 35 #define USE_ST7796 #define ST7796_NSS 25 #define ST7796_RS 13 // DC @@ -54,17 +57,11 @@ #define ST7796_RESET 2 #define ST7796_MISO -1 #define ST7796_BUSY -1 -#define VTFT_CTRL 7 #define VTFT_LEDA 4 #define TFT_BACKLIGHT_ON HIGH #define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 10000000 -#define SPI_READ_FREQUENCY 10000000 +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 -#define TFT_OFFSET_X 0 -#define TFT_OFFSET_Y 0 -// #define TFT_OFFSET_ROTATION 0 -// #define SCREEN_ROTATE -// #define SCREEN_TRANSITION_FRAMERATE 5 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes \ No newline at end of file From cd438a853448085dee1e50a3ce182026a5755e14 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sun, 13 Apr 2025 08:20:59 +0000 Subject: [PATCH 04/25] seperated from tbeam --- variants/tbeam/platformio.ini | 2 - variants/tbeam/variant.h | 30 ++------------- variants/tbeam_TFT/platformio.ini | 14 +++++++ variants/tbeam_TFT/variant.h | 63 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 variants/tbeam_TFT/platformio.ini create mode 100644 variants/tbeam_TFT/variant.h diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index 294eea61f..4db99d1cb 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -4,8 +4,6 @@ extends = esp32_base board = ttgo-t-beam board_check = true lib_deps = ${esp32_base.lib_deps} - lewisxhe/SensorLib@0.2.0 ; touchscreen addon - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon build_flags = ${esp32_base.build_flags} -DTBEAM_V10 -Ivariants/tbeam diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 78a1d8115..8771c20d2 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -6,10 +6,10 @@ #define BUTTON_PIN 38 // The middle button GPIO on the T-Beam // #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented // anywhere. -// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. +#define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. -// #define LED_STATE_ON 0 // State when LED is lit -// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 +#define LED_STATE_ON 0 // State when LED is lit +#define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 // TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if // not found then probe for SX1262 @@ -42,26 +42,4 @@ #define GPS_UBLOX #define GPS_RX_PIN 34 #define GPS_TX_PIN 12 -// #define GPS_DEBUG - -// Display addon -#define HAS_TOUCHSCREEN 1 -#define USE_VIRTUAL_KEYBOARD 1 -#define HAS_CST226SE -#define SCREEN_TOUCH_INT 35 -#define USE_ST7796 -#define ST7796_NSS 25 -#define ST7796_RS 13 // DC -#define ST7796_SDA 14 // MOSI -#define ST7796_SCK 15 -#define ST7796_RESET 2 -#define ST7796_MISO -1 -#define ST7796_BUSY -1 -#define VTFT_LEDA 4 -#define TFT_BACKLIGHT_ON HIGH -#define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 40000000 -#define SPI_READ_FREQUENCY 16000000 -#define TFT_HEIGHT 222 -#define TFT_WIDTH 480 -#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes \ No newline at end of file +// #define GPS_DEBUG \ No newline at end of file diff --git a/variants/tbeam_TFT/platformio.ini b/variants/tbeam_TFT/platformio.ini new file mode 100644 index 000000000..0c25c1706 --- /dev/null +++ b/variants/tbeam_TFT/platformio.ini @@ -0,0 +1,14 @@ +; The 1.0 release of the TBEAM board +[env:tbeam_TFT] +extends = esp32_base +board = ttgo-t-beam +board_check = true +lib_deps = ${esp32_base.lib_deps} + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon +build_flags = ${esp32_base.build_flags} + -DTBEAM_V10 + -Ivariants/tbeam_TFT + -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. + -DBOARD_HAS_PSRAM + -mfix-esp32-psram-cache-issue +upload_speed = 921600 \ No newline at end of file diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h new file mode 100644 index 000000000..65d242e7c --- /dev/null +++ b/variants/tbeam_TFT/variant.h @@ -0,0 +1,63 @@ +// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep + +#define I2C_SDA 21 +#define I2C_SCL 22 + +// Display addon +#define USE_ST7796 +#define ST7796_NSS 25 +#define ST7796_RS 13 // DC +#define ST7796_SDA 14 // MOSI +#define ST7796_SCK 15 +#define ST7796_RESET 2 +#define ST7796_MISO -1 +#define ST7796_BUSY -1 +#define VTFT_LEDA 4 +#define TFT_BACKLIGHT_ON HIGH +#define ST7796_SPI_HOST VSPI_HOST +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 16000000 +#define TFT_HEIGHT 222 +#define TFT_WIDTH 480 +#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes + +#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam +// #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented +// anywhere. +// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. + +// #define LED_STATE_ON 0 // State when LED is lit +// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 + +// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if +// not found then probe for SX1262 +#define USE_RF95 // RFM95/SX127x +#define USE_SX1262 +#define USE_SX1268 + +#define LORA_DIO0 26 // a No connect on the SX1262 module +#define LORA_RESET 23 +#define LORA_DIO1 33 // SX1262 IRQ +#define LORA_DIO2 32 // SX1262 BUSY +#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled + +#ifdef USE_SX1262 +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +// Not really an E22 but TTGO seems to be trying to clone that +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface +// code) +#endif + +// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts +// and waking from light sleep +// #define PMU_IRQ 35 +#define HAS_AXP192 +#define GPS_UBLOX +#define GPS_RX_PIN 34 +#define GPS_TX_PIN 12 +// #define GPS_DEBUG \ No newline at end of file From d454a440862d3eb7e78be795f2996218c54a7f7b Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sun, 13 Apr 2025 08:52:59 +0000 Subject: [PATCH 05/25] forgot the simple scan case --- src/detect/ScanI2CTwoWire.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index b9db60029..740649a1b 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -434,6 +434,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) SCAN_SIMPLE_CASE(MAX1704X_ADDR, MAX17048, "MAX17048", (uint8_t)addr.address); SCAN_SIMPLE_CASE(DFROBOT_RAIN_ADDR, DFROBOT_RAIN, "DFRobot Rain Gauge", (uint8_t)addr.address); SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address); + SCAN_SIMPLE_CASE(CST226SE_ADDR, CST226SE, "CST226SE", (uint8_t)addr.address); #ifdef HAS_TPS65233 SCAN_SIMPLE_CASE(TPS65233_ADDR, TPS65233, "TPS65233", (uint8_t)addr.address); #endif From 7f5e98881744f527c60b04fb35965c72698a9046 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Mon, 14 Apr 2025 21:07:35 +0000 Subject: [PATCH 06/25] lowered speeds to 1/4 --- variants/tbeam_TFT/variant.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h index 65d242e7c..a58a8f296 100644 --- a/variants/tbeam_TFT/variant.h +++ b/variants/tbeam_TFT/variant.h @@ -15,8 +15,8 @@ #define VTFT_LEDA 4 #define TFT_BACKLIGHT_ON HIGH #define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 40000000 -#define SPI_READ_FREQUENCY 16000000 +#define SPI_FREQUENCY 10000000 +#define SPI_READ_FREQUENCY 4000000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes From 8c2e72703a01cbd23f0200e7b36d4e6c2cb9a947 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Tue, 15 Apr 2025 16:45:44 +0000 Subject: [PATCH 07/25] added SPI Speed to constructor+ cleaned up variant.h --- src/graphics/Screen.cpp | 6 +++--- variants/tbeam_TFT/platformio.ini | 2 +- variants/tbeam_TFT/variant.h | 5 +---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 01ff06218..44c7a97bd 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1546,7 +1546,7 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O #elif defined(USE_ST7796) #ifdef ESP_PLATFORM dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT, ST7796_SDA, - ST7796_MISO, ST7796_SCK); + ST7796_MISO, ST7796_SCK, TFT_SPI_FREQUENCY); #else dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); #endif @@ -1687,13 +1687,13 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) #ifdef USE_ST7796 SPI3.end(); #if defined(ARCH_ESP32) - pinMode(VTFT_LEDA, ANALOG); + pinMode(VTFT_LEDA, OUTPUT); + digitalWrite(VTFT_LEDA, LOW); pinMode(ST7796_RESET, ANALOG); pinMode(ST7796_RS, ANALOG); pinMode(ST7796_NSS, ANALOG); #else nrf_gpio_cfg_default(VTFT_LEDA); - nrf_gpio_cfg_default(VTFT_CTRL); nrf_gpio_cfg_default(ST7796_RESET); nrf_gpio_cfg_default(ST7796_RS); nrf_gpio_cfg_default(ST7796_NSS); diff --git a/variants/tbeam_TFT/platformio.ini b/variants/tbeam_TFT/platformio.ini index 0c25c1706..47f44ea26 100644 --- a/variants/tbeam_TFT/platformio.ini +++ b/variants/tbeam_TFT/platformio.ini @@ -4,7 +4,7 @@ extends = esp32_base board = ttgo-t-beam board_check = true lib_deps = ${esp32_base.lib_deps} - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon build_flags = ${esp32_base.build_flags} -DTBEAM_V10 -Ivariants/tbeam_TFT diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h index a58a8f296..2fd659754 100644 --- a/variants/tbeam_TFT/variant.h +++ b/variants/tbeam_TFT/variant.h @@ -13,10 +13,7 @@ #define ST7796_MISO -1 #define ST7796_BUSY -1 #define VTFT_LEDA 4 -#define TFT_BACKLIGHT_ON HIGH -#define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 10000000 -#define SPI_READ_FREQUENCY 4000000 +#define TFT_SPI_FREQUENCY 1000000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes From e145e104235e866290f023606e076211cbba96fc Mon Sep 17 00:00:00 2001 From: nasimovy Date: Tue, 15 Apr 2025 19:49:51 +0000 Subject: [PATCH 08/25] even slower speeds.... --- variants/tbeam_TFT/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h index 2fd659754..dd1616a1f 100644 --- a/variants/tbeam_TFT/variant.h +++ b/variants/tbeam_TFT/variant.h @@ -13,7 +13,7 @@ #define ST7796_MISO -1 #define ST7796_BUSY -1 #define VTFT_LEDA 4 -#define TFT_SPI_FREQUENCY 1000000 +#define TFT_SPI_FREQUENCY 500000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes From 9efdf8bb57f628bf367ac961a109a8797b772b93 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 12 Apr 2025 12:59:09 +0000 Subject: [PATCH 09/25] add ST7796 --- src/configuration.h | 2 ++ src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 8 ++++-- src/graphics/Screen.cpp | 50 ++++++++++++++++++++++++++++++++--- src/graphics/Screen.h | 2 ++ src/graphics/ScreenFonts.h | 2 +- src/graphics/images.h | 2 +- src/main.cpp | 2 +- src/mesh/NodeDB.cpp | 2 +- variants/tbeam/platformio.ini | 10 ++++--- variants/tbeam/variant.h | 33 ++++++++++++++++++++--- 11 files changed, 96 insertions(+), 18 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index d319ddb0a..4138d6950 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -187,6 +187,8 @@ along with this program. If not, see . // Touchscreen // ----------------------------------------------------------------------------- #define FT6336U_ADDR 0x48 +#define CST226SE_ADDR 0x1A +#define CST226SE_ADDR_ALT 0x5A // ----------------------------------------------------------------------------- // BIAS-T Generator diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index c363db1b5..e43bc7017 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -71,6 +71,7 @@ class ScanI2C DPS310, LTR390UV, TCA8418KB, + CST226SE, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 9781cbf56..b9db60029 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -439,8 +439,12 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) #endif case MLX90614_ADDR_DEF: - registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0e), 1); - if (registerValue == 0x5a) { + // Do we have the MLX90614 or the MPR121KB or the CST226SE + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x06), 1); + if (registerValue == 0xAB) { + type = CST226SE; + logFoundDevice("CST226SE", (uint8_t)addr.address); + } else if (getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0e), 1) == 0x5a) { type = MLX90614; logFoundDevice("MLX90614", (uint8_t)addr.address); } else { diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 8075dd468..a153d9519 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1104,7 +1104,7 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const NodeStat char usersString[20]; snprintf(usersString, sizeof(usersString), "%d/%d", nodeStatus->getNumOnline(), nodeStatus->getNumTotal()); #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x, y + 3, 8, 8, imgUser); #else @@ -1525,6 +1525,8 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ #if defined(ESP_PLATFORM) && defined(USE_ST7789) SPIClass SPI1(HSPI); +#elif defined(ESP_PLATFORM) && defined(USE_ST7796) +SPIClass SPI3(VSPI); #endif Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_OledType screenType, OLEDDISPLAY_GEOMETRY geometry) @@ -1541,6 +1543,13 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O #else dispdev = new ST7789Spi(&SPI1, ST7789_RESET, ST7789_RS, ST7789_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); #endif +#elif defined(USE_ST7796) +#ifdef ESP_PLATFORM + dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT, ST7796_SDA, + ST7796_MISO, ST7796_SCK); +#else + dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); +#endif #elif defined(USE_SSD1306) dispdev = new SSD1306Wire(address.address, -1, -1, geometry, (address.port == ScanI2C::I2CPort::WIRE1) ? HW_I2C::I2C_TWO : HW_I2C::I2C_ONE); @@ -1632,6 +1641,17 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) pinMode(VTFT_LEDA, OUTPUT); digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON); #endif +#endif +#ifdef USE_ST7796 + pinMode(VTFT_CTRL, OUTPUT); + digitalWrite(VTFT_CTRL, LOW); + ui->init(); +#ifdef ESP_PLATFORM + analogWrite(VTFT_LEDA, BRIGHTNESS_DEFAULT); +#else + pinMode(VTFT_LEDA, OUTPUT); + digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON); +#endif #endif enabled = true; setInterval(0); // Draw ASAP @@ -1666,6 +1686,22 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) nrf_gpio_cfg_default(ST7789_NSS); #endif #endif +#ifdef USE_ST7796 + SPI3.end(); +#if defined(ARCH_ESP32) + pinMode(VTFT_LEDA, ANALOG); + pinMode(VTFT_CTRL, ANALOG); + pinMode(ST7796_RESET, ANALOG); + pinMode(ST7796_RS, ANALOG); + pinMode(ST7796_NSS, ANALOG); +#else + nrf_gpio_cfg_default(VTFT_LEDA); + nrf_gpio_cfg_default(VTFT_CTRL); + nrf_gpio_cfg_default(ST7796_RESET); + nrf_gpio_cfg_default(ST7796_RS); + nrf_gpio_cfg_default(ST7796_NSS); +#endif +#endif #ifdef T_WATCH_S3 PMU->disablePowerOutput(XPOWERS_ALDO2); @@ -1695,6 +1731,10 @@ void Screen::setup() // Heltec T114 and T190: honor a custom text color, if defined in variant.h static_cast(dispdev)->setRGB(TFT_MESH); #endif +#if defined(USE_ST7796) && defined(TFT_MESH) + // Custom text color, if defined in variant.h + static_cast(dispdev)->setRGB(TFT_MESH); +#endif // Initialising the UI will init the display too. ui->init(); @@ -1755,6 +1795,8 @@ void Screen::setup() static_cast(dispdev)->flipScreenVertically(); #elif defined(USE_ST7789) static_cast(dispdev)->flipScreenVertically(); +#elif defined(USE_ST7796) + static_cast(dispdev)->flipScreenVertically(); #else dispdev->flipScreenVertically(); #endif @@ -2490,7 +2532,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 if (!Throttle::isWithinTimespanMs(storeForwardModule->lastHeartbeat, (storeForwardModule->heartbeatInterval * 1200))) { // no heartbeat, overlap a bit #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgQuestionL1); @@ -2502,7 +2544,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 #endif } else { #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8, imgSFL1); @@ -2517,7 +2559,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } else { // TODO: Raspberry Pi supports more than just the one screen size #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL1); diff --git a/src/graphics/Screen.h b/src/graphics/Screen.h index ce416156f..1f63d1fe6 100644 --- a/src/graphics/Screen.h +++ b/src/graphics/Screen.h @@ -47,6 +47,8 @@ class Screen #include #elif defined(USE_ST7789) #include +#elif defined(USE_ST7796) +#include #else // the SH1106/SSD1306 variant is auto-detected #include diff --git a/src/graphics/ScreenFonts.h b/src/graphics/ScreenFonts.h index 079a3e282..0c76f756a 100644 --- a/src/graphics/ScreenFonts.h +++ b/src/graphics/ScreenFonts.h @@ -65,7 +65,7 @@ #endif #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) // The screen is bigger so use bigger fonts #define FONT_SMALL FONT_MEDIUM_LOCAL // Height: 19 diff --git a/src/graphics/images.h b/src/graphics/images.h index b757dcf30..db5fd710e 100644 --- a/src/graphics/images.h +++ b/src/graphics/images.h @@ -21,7 +21,7 @@ const uint8_t bluetoothConnectedIcon[36] PROGMEM = {0xfe, 0x01, 0xff, 0x03, 0x03 #endif #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff}; const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f}; diff --git a/src/main.cpp b/src/main.cpp index 535a7afa1..f372a26ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -934,7 +934,7 @@ void setup() // Don't call screen setup until after nodedb is setup (because we need // the current region name) #if defined(ST7701_CS) || defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || \ - defined(ST7789_CS) || defined(HX8357_CS) || defined(USE_ST7789) + defined(ST7789_CS) || defined(HX8357_CS) || defined(USE_ST7789) || defined(USE_ST7796) screen->setup(); #elif defined(ARCH_PORTDUINO) if (screen_found.port != ScanI2C::I2CPort::NO_I2C || settingsMap[displayPanel]) { diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index c89abbe74..7ebe6b8bd 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -595,7 +595,7 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) config.bluetooth.fixed_pin = defaultBLEPin; #if defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7789_CS) || \ - defined(HX8357_CS) || defined(USE_ST7789) + defined(HX8357_CS) || defined(USE_ST7789) || defined(USE_ST7796) bool hasScreen = true; #ifdef HELTEC_MESH_NODE_T114 uint32_t st7789_id = get_st7789_id(ST7789_NSS, ST7789_SCK, ST7789_SDA, ST7789_RS, ST7789_RESET); diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index 9049836a3..a8b95d91b 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -3,10 +3,12 @@ extends = esp32_base board = ttgo-t-beam board_check = true -lib_deps = - ${esp32_base.lib_deps} -build_flags = - ${esp32_base.build_flags} -D TBEAM_V10 -I variants/tbeam +lib_deps = ${esp32_base.lib_deps} + lewisxhe/SensorLib@0.2.0 ; touchscreen addon + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.1.zip ; display addon +build_flags = ${esp32_base.build_flags} + -DTBEAM_V10 + -Ivariants/tbeam -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 8771c20d2..07056f5cf 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -6,10 +6,10 @@ #define BUTTON_PIN 38 // The middle button GPIO on the T-Beam // #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented // anywhere. -#define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. +// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. -#define LED_STATE_ON 0 // State when LED is lit -#define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 +// #define LED_STATE_ON 0 // State when LED is lit +// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 // TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if // not found then probe for SX1262 @@ -42,4 +42,29 @@ #define GPS_UBLOX #define GPS_RX_PIN 34 #define GPS_TX_PIN 12 -// #define GPS_DEBUG \ No newline at end of file +// #define GPS_DEBUG + +// Display addon +#define HAS_CST226SE +#define USE_ST7796 +#define ST7796_NSS 25 +#define ST7796_RS 13 // DC +#define ST7796_SDA 14 // MOSI +#define ST7796_SCK 15 +#define ST7796_RESET 2 +#define ST7796_MISO -1 +#define ST7796_BUSY -1 +#define VTFT_CTRL 7 +#define VTFT_LEDA 4 +#define TFT_BACKLIGHT_ON HIGH +#define ST7796_SPI_HOST VSPI_HOST +#define SPI_FREQUENCY 10000000 +#define SPI_READ_FREQUENCY 10000000 +#define TFT_HEIGHT 222 +#define TFT_WIDTH 480 +#define TFT_OFFSET_X 0 +#define TFT_OFFSET_Y 0 +// #define TFT_OFFSET_ROTATION 0 +// #define SCREEN_ROTATE +// #define SCREEN_TRANSITION_FRAMERATE 5 +#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes \ No newline at end of file From 04185686537912a9128568fe358b5df393bca472 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 12 Apr 2025 16:31:22 +0000 Subject: [PATCH 10/25] changes to get display centered+lib update --- src/graphics/Screen.cpp | 5 +---- variants/tbeam/platformio.ini | 2 +- variants/tbeam/variant.h | 13 +++++-------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index a153d9519..01ff06218 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1643,8 +1643,6 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) #endif #endif #ifdef USE_ST7796 - pinMode(VTFT_CTRL, OUTPUT); - digitalWrite(VTFT_CTRL, LOW); ui->init(); #ifdef ESP_PLATFORM analogWrite(VTFT_LEDA, BRIGHTNESS_DEFAULT); @@ -1690,7 +1688,6 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) SPI3.end(); #if defined(ARCH_ESP32) pinMode(VTFT_LEDA, ANALOG); - pinMode(VTFT_CTRL, ANALOG); pinMode(ST7796_RESET, ANALOG); pinMode(ST7796_RS, ANALOG); pinMode(ST7796_NSS, ANALOG); @@ -1796,7 +1793,7 @@ void Screen::setup() #elif defined(USE_ST7789) static_cast(dispdev)->flipScreenVertically(); #elif defined(USE_ST7796) - static_cast(dispdev)->flipScreenVertically(); + static_cast(dispdev)->mirrorScreen(); #else dispdev->flipScreenVertically(); #endif diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index a8b95d91b..294eea61f 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -5,7 +5,7 @@ board = ttgo-t-beam board_check = true lib_deps = ${esp32_base.lib_deps} lewisxhe/SensorLib@0.2.0 ; touchscreen addon - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.1.zip ; display addon + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon build_flags = ${esp32_base.build_flags} -DTBEAM_V10 -Ivariants/tbeam diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 07056f5cf..78a1d8115 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -45,7 +45,10 @@ // #define GPS_DEBUG // Display addon +#define HAS_TOUCHSCREEN 1 +#define USE_VIRTUAL_KEYBOARD 1 #define HAS_CST226SE +#define SCREEN_TOUCH_INT 35 #define USE_ST7796 #define ST7796_NSS 25 #define ST7796_RS 13 // DC @@ -54,17 +57,11 @@ #define ST7796_RESET 2 #define ST7796_MISO -1 #define ST7796_BUSY -1 -#define VTFT_CTRL 7 #define VTFT_LEDA 4 #define TFT_BACKLIGHT_ON HIGH #define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 10000000 -#define SPI_READ_FREQUENCY 10000000 +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 -#define TFT_OFFSET_X 0 -#define TFT_OFFSET_Y 0 -// #define TFT_OFFSET_ROTATION 0 -// #define SCREEN_ROTATE -// #define SCREEN_TRANSITION_FRAMERATE 5 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes \ No newline at end of file From f7f5466dffd6c06c2e13a2a82d729be18965a352 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sun, 13 Apr 2025 08:20:59 +0000 Subject: [PATCH 11/25] seperated from tbeam --- variants/tbeam/platformio.ini | 2 - variants/tbeam/variant.h | 30 ++------------- variants/tbeam_TFT/platformio.ini | 14 +++++++ variants/tbeam_TFT/variant.h | 63 +++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 28 deletions(-) create mode 100644 variants/tbeam_TFT/platformio.ini create mode 100644 variants/tbeam_TFT/variant.h diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index 294eea61f..4db99d1cb 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -4,8 +4,6 @@ extends = esp32_base board = ttgo-t-beam board_check = true lib_deps = ${esp32_base.lib_deps} - lewisxhe/SensorLib@0.2.0 ; touchscreen addon - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon build_flags = ${esp32_base.build_flags} -DTBEAM_V10 -Ivariants/tbeam diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 78a1d8115..8771c20d2 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -6,10 +6,10 @@ #define BUTTON_PIN 38 // The middle button GPIO on the T-Beam // #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented // anywhere. -// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. +#define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. -// #define LED_STATE_ON 0 // State when LED is lit -// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 +#define LED_STATE_ON 0 // State when LED is lit +#define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 // TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if // not found then probe for SX1262 @@ -42,26 +42,4 @@ #define GPS_UBLOX #define GPS_RX_PIN 34 #define GPS_TX_PIN 12 -// #define GPS_DEBUG - -// Display addon -#define HAS_TOUCHSCREEN 1 -#define USE_VIRTUAL_KEYBOARD 1 -#define HAS_CST226SE -#define SCREEN_TOUCH_INT 35 -#define USE_ST7796 -#define ST7796_NSS 25 -#define ST7796_RS 13 // DC -#define ST7796_SDA 14 // MOSI -#define ST7796_SCK 15 -#define ST7796_RESET 2 -#define ST7796_MISO -1 -#define ST7796_BUSY -1 -#define VTFT_LEDA 4 -#define TFT_BACKLIGHT_ON HIGH -#define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 40000000 -#define SPI_READ_FREQUENCY 16000000 -#define TFT_HEIGHT 222 -#define TFT_WIDTH 480 -#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes \ No newline at end of file +// #define GPS_DEBUG \ No newline at end of file diff --git a/variants/tbeam_TFT/platformio.ini b/variants/tbeam_TFT/platformio.ini new file mode 100644 index 000000000..0c25c1706 --- /dev/null +++ b/variants/tbeam_TFT/platformio.ini @@ -0,0 +1,14 @@ +; The 1.0 release of the TBEAM board +[env:tbeam_TFT] +extends = esp32_base +board = ttgo-t-beam +board_check = true +lib_deps = ${esp32_base.lib_deps} + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon +build_flags = ${esp32_base.build_flags} + -DTBEAM_V10 + -Ivariants/tbeam_TFT + -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. + -DBOARD_HAS_PSRAM + -mfix-esp32-psram-cache-issue +upload_speed = 921600 \ No newline at end of file diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h new file mode 100644 index 000000000..65d242e7c --- /dev/null +++ b/variants/tbeam_TFT/variant.h @@ -0,0 +1,63 @@ +// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep + +#define I2C_SDA 21 +#define I2C_SCL 22 + +// Display addon +#define USE_ST7796 +#define ST7796_NSS 25 +#define ST7796_RS 13 // DC +#define ST7796_SDA 14 // MOSI +#define ST7796_SCK 15 +#define ST7796_RESET 2 +#define ST7796_MISO -1 +#define ST7796_BUSY -1 +#define VTFT_LEDA 4 +#define TFT_BACKLIGHT_ON HIGH +#define ST7796_SPI_HOST VSPI_HOST +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 16000000 +#define TFT_HEIGHT 222 +#define TFT_WIDTH 480 +#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes + +#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam +// #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented +// anywhere. +// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. + +// #define LED_STATE_ON 0 // State when LED is lit +// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 + +// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if +// not found then probe for SX1262 +#define USE_RF95 // RFM95/SX127x +#define USE_SX1262 +#define USE_SX1268 + +#define LORA_DIO0 26 // a No connect on the SX1262 module +#define LORA_RESET 23 +#define LORA_DIO1 33 // SX1262 IRQ +#define LORA_DIO2 32 // SX1262 BUSY +#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled + +#ifdef USE_SX1262 +#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +// Not really an E22 but TTGO seems to be trying to clone that +#define SX126X_DIO2_AS_RF_SWITCH +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface +// code) +#endif + +// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts +// and waking from light sleep +// #define PMU_IRQ 35 +#define HAS_AXP192 +#define GPS_UBLOX +#define GPS_RX_PIN 34 +#define GPS_TX_PIN 12 +// #define GPS_DEBUG \ No newline at end of file From ee95455e22c6bed6976ece70124cf92d8e472e59 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sun, 13 Apr 2025 08:52:59 +0000 Subject: [PATCH 12/25] forgot the simple scan case --- src/detect/ScanI2CTwoWire.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index b9db60029..740649a1b 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -434,6 +434,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) SCAN_SIMPLE_CASE(MAX1704X_ADDR, MAX17048, "MAX17048", (uint8_t)addr.address); SCAN_SIMPLE_CASE(DFROBOT_RAIN_ADDR, DFROBOT_RAIN, "DFRobot Rain Gauge", (uint8_t)addr.address); SCAN_SIMPLE_CASE(LTR390UV_ADDR, LTR390UV, "LTR390UV", (uint8_t)addr.address); + SCAN_SIMPLE_CASE(CST226SE_ADDR, CST226SE, "CST226SE", (uint8_t)addr.address); #ifdef HAS_TPS65233 SCAN_SIMPLE_CASE(TPS65233_ADDR, TPS65233, "TPS65233", (uint8_t)addr.address); #endif From f5e3acb8c264bb3d5448fc898e682f7f4277d779 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Mon, 14 Apr 2025 21:07:35 +0000 Subject: [PATCH 13/25] lowered speeds to 1/4 --- variants/tbeam_TFT/variant.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h index 65d242e7c..a58a8f296 100644 --- a/variants/tbeam_TFT/variant.h +++ b/variants/tbeam_TFT/variant.h @@ -15,8 +15,8 @@ #define VTFT_LEDA 4 #define TFT_BACKLIGHT_ON HIGH #define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 40000000 -#define SPI_READ_FREQUENCY 16000000 +#define SPI_FREQUENCY 10000000 +#define SPI_READ_FREQUENCY 4000000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes From acc0cfe77316c56b83b0d1e3961f2c96655f5fd8 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Tue, 15 Apr 2025 16:45:44 +0000 Subject: [PATCH 14/25] added SPI Speed to constructor+ cleaned up variant.h --- src/graphics/Screen.cpp | 6 +++--- variants/tbeam_TFT/platformio.ini | 2 +- variants/tbeam_TFT/variant.h | 5 +---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 01ff06218..44c7a97bd 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1546,7 +1546,7 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O #elif defined(USE_ST7796) #ifdef ESP_PLATFORM dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT, ST7796_SDA, - ST7796_MISO, ST7796_SCK); + ST7796_MISO, ST7796_SCK, TFT_SPI_FREQUENCY); #else dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); #endif @@ -1687,13 +1687,13 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) #ifdef USE_ST7796 SPI3.end(); #if defined(ARCH_ESP32) - pinMode(VTFT_LEDA, ANALOG); + pinMode(VTFT_LEDA, OUTPUT); + digitalWrite(VTFT_LEDA, LOW); pinMode(ST7796_RESET, ANALOG); pinMode(ST7796_RS, ANALOG); pinMode(ST7796_NSS, ANALOG); #else nrf_gpio_cfg_default(VTFT_LEDA); - nrf_gpio_cfg_default(VTFT_CTRL); nrf_gpio_cfg_default(ST7796_RESET); nrf_gpio_cfg_default(ST7796_RS); nrf_gpio_cfg_default(ST7796_NSS); diff --git a/variants/tbeam_TFT/platformio.ini b/variants/tbeam_TFT/platformio.ini index 0c25c1706..47f44ea26 100644 --- a/variants/tbeam_TFT/platformio.ini +++ b/variants/tbeam_TFT/platformio.ini @@ -4,7 +4,7 @@ extends = esp32_base board = ttgo-t-beam board_check = true lib_deps = ${esp32_base.lib_deps} - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.4.zip ; display addon + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon build_flags = ${esp32_base.build_flags} -DTBEAM_V10 -Ivariants/tbeam_TFT diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h index a58a8f296..2fd659754 100644 --- a/variants/tbeam_TFT/variant.h +++ b/variants/tbeam_TFT/variant.h @@ -13,10 +13,7 @@ #define ST7796_MISO -1 #define ST7796_BUSY -1 #define VTFT_LEDA 4 -#define TFT_BACKLIGHT_ON HIGH -#define ST7796_SPI_HOST VSPI_HOST -#define SPI_FREQUENCY 10000000 -#define SPI_READ_FREQUENCY 4000000 +#define TFT_SPI_FREQUENCY 1000000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes From e0bb76261b52eaac9cf0af4947c1d65f0047d7f4 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Tue, 15 Apr 2025 19:49:51 +0000 Subject: [PATCH 15/25] even slower speeds.... --- variants/tbeam_TFT/variant.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h index 2fd659754..dd1616a1f 100644 --- a/variants/tbeam_TFT/variant.h +++ b/variants/tbeam_TFT/variant.h @@ -13,7 +13,7 @@ #define ST7796_MISO -1 #define ST7796_BUSY -1 #define VTFT_LEDA 4 -#define TFT_SPI_FREQUENCY 1000000 +#define TFT_SPI_FREQUENCY 500000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes From 020e44d8562875c8ff2ac9d851e049b98f0a6f81 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Wed, 16 Apr 2025 10:01:56 +0000 Subject: [PATCH 16/25] changed variant name to tbeam-displayshield --- variants/{tbeam_TFT => tbeam-displayshield}/platformio.ini | 4 ++-- variants/{tbeam_TFT => tbeam-displayshield}/variant.h | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename variants/{tbeam_TFT => tbeam-displayshield}/platformio.ini (88%) rename variants/{tbeam_TFT => tbeam-displayshield}/variant.h (100%) diff --git a/variants/tbeam_TFT/platformio.ini b/variants/tbeam-displayshield/platformio.ini similarity index 88% rename from variants/tbeam_TFT/platformio.ini rename to variants/tbeam-displayshield/platformio.ini index 47f44ea26..f6d999e30 100644 --- a/variants/tbeam_TFT/platformio.ini +++ b/variants/tbeam-displayshield/platformio.ini @@ -1,5 +1,5 @@ ; The 1.0 release of the TBEAM board -[env:tbeam_TFT] +[env:tbeam-displayshield] extends = esp32_base board = ttgo-t-beam board_check = true @@ -7,7 +7,7 @@ lib_deps = ${esp32_base.lib_deps} https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon build_flags = ${esp32_base.build_flags} -DTBEAM_V10 - -Ivariants/tbeam_TFT + -Ivariants/tbeam-displayshield -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam-displayshield/variant.h similarity index 100% rename from variants/tbeam_TFT/variant.h rename to variants/tbeam-displayshield/variant.h From b10af5b6596c36193708437b39b29c324caa3869 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Wed, 16 Apr 2025 11:50:45 +0000 Subject: [PATCH 17/25] modified variant.h and merged ini file+testing on lower spi frequency for the lora module, display shield pumps out EMI? --- src/main.cpp | 4 ++ variants/tbeam-displayshield/platformio.ini | 14 ----- variants/tbeam-displayshield/variant.h | 60 --------------------- variants/tbeam/platformio.ini | 22 ++++++-- variants/tbeam/variant.h | 24 ++++++++- variants/tbeam_TFT/platformio.ini | 14 ----- variants/tbeam_TFT/variant.h | 60 --------------------- 7 files changed, 44 insertions(+), 154 deletions(-) delete mode 100644 variants/tbeam-displayshield/platformio.ini delete mode 100644 variants/tbeam-displayshield/variant.h delete mode 100644 variants/tbeam_TFT/platformio.ini delete mode 100644 variants/tbeam_TFT/variant.h diff --git a/src/main.cpp b/src/main.cpp index f372a26ad..4881e27a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -840,7 +840,11 @@ void setup() // ESP32 SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); LOG_DEBUG("SPI.begin(SCK=%d, MISO=%d, MOSI=%d, NSS=%d)", LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); +#if defined(TBEAM_V10) && defined(USE_ST7796) + SPI.setFrequency(LORA_SPI_FREQUENCY); +#else SPI.setFrequency(4000000); +#endif #endif // Initialize the screen first so we can show the logo while we start up everything else. diff --git a/variants/tbeam-displayshield/platformio.ini b/variants/tbeam-displayshield/platformio.ini deleted file mode 100644 index f6d999e30..000000000 --- a/variants/tbeam-displayshield/platformio.ini +++ /dev/null @@ -1,14 +0,0 @@ -; The 1.0 release of the TBEAM board -[env:tbeam-displayshield] -extends = esp32_base -board = ttgo-t-beam -board_check = true -lib_deps = ${esp32_base.lib_deps} - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon -build_flags = ${esp32_base.build_flags} - -DTBEAM_V10 - -Ivariants/tbeam-displayshield - -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. - -DBOARD_HAS_PSRAM - -mfix-esp32-psram-cache-issue -upload_speed = 921600 \ No newline at end of file diff --git a/variants/tbeam-displayshield/variant.h b/variants/tbeam-displayshield/variant.h deleted file mode 100644 index dd1616a1f..000000000 --- a/variants/tbeam-displayshield/variant.h +++ /dev/null @@ -1,60 +0,0 @@ -// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep - -#define I2C_SDA 21 -#define I2C_SCL 22 - -// Display addon -#define USE_ST7796 -#define ST7796_NSS 25 -#define ST7796_RS 13 // DC -#define ST7796_SDA 14 // MOSI -#define ST7796_SCK 15 -#define ST7796_RESET 2 -#define ST7796_MISO -1 -#define ST7796_BUSY -1 -#define VTFT_LEDA 4 -#define TFT_SPI_FREQUENCY 500000 -#define TFT_HEIGHT 222 -#define TFT_WIDTH 480 -#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes - -#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam -// #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented -// anywhere. -// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. - -// #define LED_STATE_ON 0 // State when LED is lit -// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 - -// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if -// not found then probe for SX1262 -#define USE_RF95 // RFM95/SX127x -#define USE_SX1262 -#define USE_SX1268 - -#define LORA_DIO0 26 // a No connect on the SX1262 module -#define LORA_RESET 23 -#define LORA_DIO1 33 // SX1262 IRQ -#define LORA_DIO2 32 // SX1262 BUSY -#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled - -#ifdef USE_SX1262 -#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead -#define SX126X_DIO1 LORA_DIO1 -#define SX126X_BUSY LORA_DIO2 -#define SX126X_RESET LORA_RESET -// Not really an E22 but TTGO seems to be trying to clone that -#define SX126X_DIO2_AS_RF_SWITCH -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 -// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface -// code) -#endif - -// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts -// and waking from light sleep -// #define PMU_IRQ 35 -#define HAS_AXP192 -#define GPS_UBLOX -#define GPS_RX_PIN 34 -#define GPS_TX_PIN 12 -// #define GPS_DEBUG \ No newline at end of file diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index 4db99d1cb..d345b164b 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -5,9 +5,21 @@ board = ttgo-t-beam board_check = true lib_deps = ${esp32_base.lib_deps} build_flags = ${esp32_base.build_flags} - -DTBEAM_V10 - -Ivariants/tbeam - -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. - -DBOARD_HAS_PSRAM + -D TBEAM_V10 + -I variants/tbeam + -D GPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. + -D BOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -upload_speed = 921600 \ No newline at end of file +upload_speed = 921600 + +[env:tbeam-displayshield] +extends = env:tbeam + +build_flags = + ${env:tbeam.build_flags} + -D USE_ST7796 + +lib_deps = + ${env:tbeam.lib_deps} + https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon + lewisxhe/SensorLib@0.2.0 ; touchscreen addon diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 8771c20d2..4e16e5c70 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -42,4 +42,26 @@ #define GPS_UBLOX #define GPS_RX_PIN 34 #define GPS_TX_PIN 12 -// #define GPS_DEBUG \ No newline at end of file +// #define GPS_DEBUG + +// Used when the diplay shield is chosen +#ifdef USE_ST7796 +#define LORA_SPI_FREQUENCY 1000000 + +#undef EXT_NOTIFY_OUT +#undef LED_STATE_ON +#undef LED_PIN + +#define ST7796_NSS 25 +#define ST7796_RS 13 // DC +#define ST7796_SDA 14 // MOSI +#define ST7796_SCK 15 +#define ST7796_RESET 2 +#define ST7796_MISO -1 +#define ST7796_BUSY -1 +#define VTFT_LEDA 4 +#define TFT_SPI_FREQUENCY 500000 +#define TFT_HEIGHT 222 +#define TFT_WIDTH 480 +#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes +#endif \ No newline at end of file diff --git a/variants/tbeam_TFT/platformio.ini b/variants/tbeam_TFT/platformio.ini deleted file mode 100644 index 47f44ea26..000000000 --- a/variants/tbeam_TFT/platformio.ini +++ /dev/null @@ -1,14 +0,0 @@ -; The 1.0 release of the TBEAM board -[env:tbeam_TFT] -extends = esp32_base -board = ttgo-t-beam -board_check = true -lib_deps = ${esp32_base.lib_deps} - https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon -build_flags = ${esp32_base.build_flags} - -DTBEAM_V10 - -Ivariants/tbeam_TFT - -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. - -DBOARD_HAS_PSRAM - -mfix-esp32-psram-cache-issue -upload_speed = 921600 \ No newline at end of file diff --git a/variants/tbeam_TFT/variant.h b/variants/tbeam_TFT/variant.h deleted file mode 100644 index dd1616a1f..000000000 --- a/variants/tbeam_TFT/variant.h +++ /dev/null @@ -1,60 +0,0 @@ -// #define BUTTON_NEED_PULLUP // if set we need to turn on the internal CPU pullup during sleep - -#define I2C_SDA 21 -#define I2C_SCL 22 - -// Display addon -#define USE_ST7796 -#define ST7796_NSS 25 -#define ST7796_RS 13 // DC -#define ST7796_SDA 14 // MOSI -#define ST7796_SCK 15 -#define ST7796_RESET 2 -#define ST7796_MISO -1 -#define ST7796_BUSY -1 -#define VTFT_LEDA 4 -#define TFT_SPI_FREQUENCY 500000 -#define TFT_HEIGHT 222 -#define TFT_WIDTH 480 -#define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes - -#define BUTTON_PIN 38 // The middle button GPIO on the T-Beam -// #define BUTTON_PIN_ALT 13 // Alternate GPIO for an external button if needed. Does anyone use this? It is not documented -// anywhere. -// #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. - -// #define LED_STATE_ON 0 // State when LED is lit -// #define LED_PIN 4 // Newer tbeams (1.1) have an extra led on GPIO4 - -// TTGO uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if -// not found then probe for SX1262 -#define USE_RF95 // RFM95/SX127x -#define USE_SX1262 -#define USE_SX1268 - -#define LORA_DIO0 26 // a No connect on the SX1262 module -#define LORA_RESET 23 -#define LORA_DIO1 33 // SX1262 IRQ -#define LORA_DIO2 32 // SX1262 BUSY -#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled - -#ifdef USE_SX1262 -#define SX126X_CS LORA_CS // FIXME - we really should define LORA_CS instead -#define SX126X_DIO1 LORA_DIO1 -#define SX126X_BUSY LORA_DIO2 -#define SX126X_RESET LORA_RESET -// Not really an E22 but TTGO seems to be trying to clone that -#define SX126X_DIO2_AS_RF_SWITCH -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 -// Internally the TTGO module hooks the SX1262-DIO2 in to control the TX/RX switch (which is the default for the sx1262interface -// code) -#endif - -// Leave undefined to disable our PMU IRQ handler. DO NOT ENABLE THIS because the pmuirq can cause sperious interrupts -// and waking from light sleep -// #define PMU_IRQ 35 -#define HAS_AXP192 -#define GPS_UBLOX -#define GPS_RX_PIN 34 -#define GPS_TX_PIN 12 -// #define GPS_DEBUG \ No newline at end of file From 7867cf559033447d47514cd305a114fa08e05230 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Wed, 16 Apr 2025 17:36:58 +0000 Subject: [PATCH 18/25] try higher speeds + HSPI --- src/graphics/Screen.cpp | 2 +- src/main.cpp | 4 ---- variants/tbeam/variant.h | 3 +-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 44c7a97bd..a7c43dce0 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1526,7 +1526,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ #if defined(ESP_PLATFORM) && defined(USE_ST7789) SPIClass SPI1(HSPI); #elif defined(ESP_PLATFORM) && defined(USE_ST7796) -SPIClass SPI3(VSPI); +SPIClass SPI3(HSPI); #endif Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_OledType screenType, OLEDDISPLAY_GEOMETRY geometry) diff --git a/src/main.cpp b/src/main.cpp index 4881e27a6..f372a26ad 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -840,11 +840,7 @@ void setup() // ESP32 SPI.begin(LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); LOG_DEBUG("SPI.begin(SCK=%d, MISO=%d, MOSI=%d, NSS=%d)", LORA_SCK, LORA_MISO, LORA_MOSI, LORA_CS); -#if defined(TBEAM_V10) && defined(USE_ST7796) - SPI.setFrequency(LORA_SPI_FREQUENCY); -#else SPI.setFrequency(4000000); -#endif #endif // Initialize the screen first so we can show the logo while we start up everything else. diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 4e16e5c70..6a775e97b 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -46,7 +46,6 @@ // Used when the diplay shield is chosen #ifdef USE_ST7796 -#define LORA_SPI_FREQUENCY 1000000 #undef EXT_NOTIFY_OUT #undef LED_STATE_ON @@ -60,7 +59,7 @@ #define ST7796_MISO -1 #define ST7796_BUSY -1 #define VTFT_LEDA 4 -#define TFT_SPI_FREQUENCY 500000 +#define TFT_SPI_FREQUENCY 4000000 #define TFT_HEIGHT 222 #define TFT_WIDTH 480 #define BRIGHTNESS_DEFAULT 100 // Medium Low Brightnes From a69c489acf851424c301b2a18da158ccae317fd6 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Wed, 16 Apr 2025 18:49:53 +0000 Subject: [PATCH 19/25] cleanup of redundant code --- src/graphics/Screen.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index a7c43dce0..fbae74e21 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1523,10 +1523,8 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_ screen->drawColumns(display, x, y, fields); } -#if defined(ESP_PLATFORM) && defined(USE_ST7789) +#if defined(ESP_PLATFORM) && (defined(USE_ST7789) || defined(USE_ST7796)) SPIClass SPI1(HSPI); -#elif defined(ESP_PLATFORM) && defined(USE_ST7796) -SPIClass SPI3(HSPI); #endif Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_OledType screenType, OLEDDISPLAY_GEOMETRY geometry) @@ -1545,10 +1543,10 @@ Screen::Screen(ScanI2C::DeviceAddress address, meshtastic_Config_DisplayConfig_O #endif #elif defined(USE_ST7796) #ifdef ESP_PLATFORM - dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT, ST7796_SDA, + dispdev = new ST7796Spi(&SPI1, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT, ST7796_SDA, ST7796_MISO, ST7796_SCK, TFT_SPI_FREQUENCY); #else - dispdev = new ST7796Spi(&SPI3, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); + dispdev = new ST7796Spi(&SPI1, ST7796_RESET, ST7796_RS, ST7796_NSS, GEOMETRY_RAWMODE, TFT_WIDTH, TFT_HEIGHT); #endif #elif defined(USE_SSD1306) dispdev = new SSD1306Wire(address.address, -1, -1, geometry, @@ -1685,7 +1683,7 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) #endif #endif #ifdef USE_ST7796 - SPI3.end(); + SPI1.end(); #if defined(ARCH_ESP32) pinMode(VTFT_LEDA, OUTPUT); digitalWrite(VTFT_LEDA, LOW); From 3d8d6ef31f820473a8663115b59c8d8407053092 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Thu, 17 Apr 2025 18:49:46 +0000 Subject: [PATCH 20/25] refelct changes? --- src/graphics/Screen.cpp | 10 ++++++---- src/graphics/ScreenFonts.h | 2 +- src/graphics/images.h | 3 ++- src/main.cpp | 2 +- src/mesh/NodeDB.cpp | 2 +- variants/tbeam/variant.h | 3 +++ 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index fbae74e21..24db7942c 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1104,7 +1104,7 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const NodeStat char usersString[20]; snprintf(usersString, sizeof(usersString), "%d/%d", nodeStatus->getNumOnline(), nodeStatus->getNumTotal()); #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(ILI9488_CS) || defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x, y + 3, 8, 8, imgUser); #else @@ -2527,7 +2527,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 if (!Throttle::isWithinTimespanMs(storeForwardModule->lastHeartbeat, (storeForwardModule->heartbeatInterval * 1200))) { // no heartbeat, overlap a bit #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || defined(ILI9488_CS) || \ + ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgQuestionL1); @@ -2539,7 +2540,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 #endif } else { #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || defined(ILI9488_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8, imgSFL1); @@ -2554,7 +2555,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 } else { // TODO: Raspberry Pi supports more than just the one screen size #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || defined(ILI9488_CS) || \ + ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL1); diff --git a/src/graphics/ScreenFonts.h b/src/graphics/ScreenFonts.h index 0c76f756a..a91efdba1 100644 --- a/src/graphics/ScreenFonts.h +++ b/src/graphics/ScreenFonts.h @@ -65,7 +65,7 @@ #endif #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS)) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || defined(ILI9488_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) // The screen is bigger so use bigger fonts #define FONT_SMALL FONT_MEDIUM_LOCAL // Height: 19 diff --git a/src/graphics/images.h b/src/graphics/images.h index db5fd710e..f34b51c9b 100644 --- a/src/graphics/images.h +++ b/src/graphics/images.h @@ -21,7 +21,8 @@ const uint8_t bluetoothConnectedIcon[36] PROGMEM = {0xfe, 0x01, 0xff, 0x03, 0x03 #endif #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ - defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || ARCH_PORTDUINO) && \ + defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || defined(ILI9488_CS) || \ + ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff}; const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f}; diff --git a/src/main.cpp b/src/main.cpp index f372a26ad..ebab1da9a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -934,7 +934,7 @@ void setup() // Don't call screen setup until after nodedb is setup (because we need // the current region name) #if defined(ST7701_CS) || defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || \ - defined(ST7789_CS) || defined(HX8357_CS) || defined(USE_ST7789) || defined(USE_ST7796) + defined(ST7789_CS) || defined(HX8357_CS) || defined(USE_ST7789) || defined(ILI9488_CS) || defined(USE_ST7796) screen->setup(); #elif defined(ARCH_PORTDUINO) if (screen_found.port != ScanI2C::I2CPort::NO_I2C || settingsMap[displayPanel]) { diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 7ebe6b8bd..d8f958098 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -595,7 +595,7 @@ void NodeDB::installDefaultConfig(bool preserveKey = false) config.bluetooth.fixed_pin = defaultBLEPin; #if defined(ST7735_CS) || defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7789_CS) || \ - defined(HX8357_CS) || defined(USE_ST7789) || defined(USE_ST7796) + defined(HX8357_CS) || defined(USE_ST7789) || defined(ILI9488_CS) || defined(USE_ST7796) bool hasScreen = true; #ifdef HELTEC_MESH_NODE_T114 uint32_t st7789_id = get_st7789_id(ST7789_NSS, ST7789_SCK, ST7789_SDA, ST7789_RS, ST7789_RESET); diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 6a775e97b..4c89bd2be 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -51,6 +51,9 @@ #undef LED_STATE_ON #undef LED_PIN +#define HAS_TOUCHSCREEN 1 +#define SCREEN_TOUCH_INT 35 + #define ST7796_NSS 25 #define ST7796_RS 13 // DC #define ST7796_SDA 14 // MOSI From 43978af62b42458f9581dd2b617664a7290d4603 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Fri, 18 Apr 2025 09:21:46 +0000 Subject: [PATCH 21/25] trunk fmt --- src/graphics/images.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/graphics/images.h b/src/graphics/images.h index 9409b795e..f34b51c9b 100644 --- a/src/graphics/images.h +++ b/src/graphics/images.h @@ -22,7 +22,8 @@ const uint8_t bluetoothConnectedIcon[36] PROGMEM = {0xfe, 0x01, 0xff, 0x03, 0x03 #if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ILI9342_DRIVER) || defined(ST7701_CS) || defined(ST7735_CS) || \ defined(ST7789_CS) || defined(USE_ST7789) || defined(USE_ST7796) || defined(HX8357_CS) || defined(ILI9488_CS) || \ - ARCH_PORTDUINO) && !defined(DISPLAY_FORCE_SMALL_FONTS) + ARCH_PORTDUINO) && \ + !defined(DISPLAY_FORCE_SMALL_FONTS) const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff}; const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f}; const uint8_t imgInfoL1[] PROGMEM = {0xff, 0x01, 0x01, 0x01, 0x1e, 0x7f, 0x1e, 0x01, 0x01, 0x01, 0x01, 0xff}; From cb14fc3b9d310dfeb2b2b521b9174307f92c249d Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 19 Apr 2025 13:22:15 +0000 Subject: [PATCH 22/25] testing touchscreen code --- src/input/TouchScreenCST226SE.cpp | 103 ++++++++++++++++++++++++++++++ src/input/TouchScreenCST226SE.h | 32 ++++++++++ variants/tbeam/variant.h | 3 +- 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 src/input/TouchScreenCST226SE.cpp create mode 100644 src/input/TouchScreenCST226SE.h diff --git a/src/input/TouchScreenCST226SE.cpp b/src/input/TouchScreenCST226SE.cpp new file mode 100644 index 000000000..3151797c2 --- /dev/null +++ b/src/input/TouchScreenCST226SE.cpp @@ -0,0 +1,103 @@ +#include "TouchScreenCST226SE.h" +#include "variant.h" + +#ifdef HAS_CST226SE + +#include "PowerFSM.h" +#include "Wire.h" +#include "configuration.h" +#include "modules/ExternalNotificationModule.h" + +volatile bool CST_IRQ = false; + +TouchScreenCST226SE *touchScreenCST226SE; + +TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)) + : TouchScreenBase("touchscreen1", width, height), _getTouch(getTouch) +{ +} + +void TouchScreenCST226SE::init() +{ + for (uint8_t addr : PossibleAddresses) { + if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) { + i2cAddress = addr; + +#ifdef TOUCHSCREEN_INT + pinMode(TOUCHSCREEN_INT, INPUT); + attachInterrupt( + TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING); +#endif + + LOG_DEBUG("CST226SE init OK at address 0x%02X", addr); + return; + } + } + + LOG_ERROR("CST226SE init failed at all known addresses"); +} + +bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y) +{ + if (!touch.isPressed()) + return false; + + int16_t x_array[1], y_array[1]; + uint8_t count = touch.getPoint(x_array, y_array, 1); + if (count > 0) { + x = x_array[0]; + y = y_array[0]; + return true; + } + + return false; +} + +void TouchScreenCST226SE::onEvent(const TouchEvent &event) +{ + InputEvent e; + e.source = event.source; + + e.touchX = event.x; + e.touchY = event.y; + + switch (event.touchEvent) { + case TOUCH_ACTION_LEFT: { + e.inputEvent = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT); + break; + } + case TOUCH_ACTION_RIGHT: { + e.inputEvent = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT); + break; + } + case TOUCH_ACTION_UP: { + e.inputEvent = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP); + break; + } + case TOUCH_ACTION_DOWN: { + e.inputEvent = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN); + break; + } + case TOUCH_ACTION_DOUBLE_TAP: { + e.inputEvent = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT); + break; + } + case TOUCH_ACTION_LONG_PRESS: { + e.inputEvent = static_cast(meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL); + break; + } + case TOUCH_ACTION_TAP: { + if (moduleConfig.external_notification.enabled && (externalNotificationModule->nagCycleCutoff != UINT32_MAX)) { + externalNotificationModule->stopNow(); + } else { + powerFSM.trigger(EVENT_INPUT); + } + break; + } + default: + return; + } + this->notifyObservers(&e); +} + +#endif \ No newline at end of file diff --git a/src/input/TouchScreenCST226SE.h b/src/input/TouchScreenCST226SE.h new file mode 100644 index 000000000..71d037724 --- /dev/null +++ b/src/input/TouchScreenCST226SE.h @@ -0,0 +1,32 @@ +#pragma once + +#include "variant.h" + +#ifdef HAS_CST226SE + +#include "TouchScreenBase.h" +#include "touch/TouchClassCST226.h" + +class TouchScreenCST226SE : public TouchScreenBase +{ + public: + TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)); + void init(void); + + protected: + virtual bool getTouch(int16_t &x, int16_t &y); + virtual void onEvent(const TouchEvent &event); + + bool (*_getTouch)(int16_t *, int16_t *); + + private: + TouchClassCST226 touch; + uint8_t i2cAddress = 0; + + static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT}; +}; + +// For global reference in other code +extern TouchScreenCST226SE *touchScreenCST226SE; + +#endif \ No newline at end of file diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 4c89bd2be..04801e678 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -51,8 +51,9 @@ #undef LED_STATE_ON #undef LED_PIN +#define HAS_CST226SE 1 #define HAS_TOUCHSCREEN 1 -#define SCREEN_TOUCH_INT 35 +#define TOUCHSCREEN_INT 35 #define ST7796_NSS 25 #define ST7796_RS 13 // DC From 0f1e528b20aaa8a9ee12620fbb891e96eaf4a57e Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 19 Apr 2025 15:43:55 +0000 Subject: [PATCH 23/25] further testing --- src/graphics/Screen.cpp | 6 +++++- src/input/TouchScreenCST226SE.cpp | 22 +++++++++++++++++----- src/input/TouchScreenCST226SE.h | 8 ++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 9e4555e53..95b21c93f 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -39,6 +39,7 @@ along with this program. If not, see . #include "graphics/ScreenFonts.h" #include "graphics/images.h" #include "input/ScanAndSelect.h" +#include "input/TouchScreenCST226SE.h" #include "input/TouchScreenImpl1.h" #include "main.h" #include "mesh-pb-constants.h" @@ -1823,10 +1824,13 @@ void Screen::setup() new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast(dispdev)->getTouch); touchScreenImpl1->init(); } -#elif HAS_TOUCHSCREEN +#elif HAS_TOUCHSCREEN && !HAS_CST226SE touchScreenImpl1 = new TouchScreenImpl1(dispdev->getWidth(), dispdev->getHeight(), static_cast(dispdev)->getTouch); touchScreenImpl1->init(); +#elif HAS_TOUCHSCREEN && HAS_CST226SE + touchScreenCST226SE = new TouchScreenCST226SE(TFT_HEIGHT, TFT_WIDTH, TouchScreenCST226SE::forwardGetTouch); + touchScreenCST226SE->init(); #endif // Subscribe to status updates diff --git a/src/input/TouchScreenCST226SE.cpp b/src/input/TouchScreenCST226SE.cpp index 3151797c2..ff0b39a7a 100644 --- a/src/input/TouchScreenCST226SE.cpp +++ b/src/input/TouchScreenCST226SE.cpp @@ -10,11 +10,13 @@ volatile bool CST_IRQ = false; +TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr; TouchScreenCST226SE *touchScreenCST226SE; TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)) : TouchScreenBase("touchscreen1", width, height), _getTouch(getTouch) { + instance = this; } void TouchScreenCST226SE::init() @@ -23,11 +25,11 @@ void TouchScreenCST226SE::init() if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) { i2cAddress = addr; -#ifdef TOUCHSCREEN_INT - pinMode(TOUCHSCREEN_INT, INPUT); - attachInterrupt( - TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING); -#endif + // #ifdef TOUCHSCREEN_INT + // pinMode(TOUCHSCREEN_INT, INPUT); + // attachInterrupt( + // TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING); + // #endif LOG_DEBUG("CST226SE init OK at address 0x%02X", addr); return; @@ -53,6 +55,16 @@ bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y) return false; } +bool TouchScreenCST226SE::forwardGetTouch(int16_t *x, int16_t *y) +{ + if (instance) { + return instance->getTouch(*x, *y); + LOG_DEBUG("TouchScreen touched %dx %dy", x, y); + } + + return false; +} + void TouchScreenCST226SE::onEvent(const TouchEvent &event) { InputEvent e; diff --git a/src/input/TouchScreenCST226SE.h b/src/input/TouchScreenCST226SE.h index 71d037724..fe5b81229 100644 --- a/src/input/TouchScreenCST226SE.h +++ b/src/input/TouchScreenCST226SE.h @@ -4,6 +4,8 @@ #ifdef HAS_CST226SE +#include "modules/CannedMessageModule.h" + #include "TouchScreenBase.h" #include "touch/TouchClassCST226.h" @@ -13,13 +15,15 @@ class TouchScreenCST226SE : public TouchScreenBase TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)); void init(void); + static bool forwardGetTouch(int16_t *x, int16_t *y); + bool (*_getTouch)(int16_t *, int16_t *); + protected: virtual bool getTouch(int16_t &x, int16_t &y); virtual void onEvent(const TouchEvent &event); - bool (*_getTouch)(int16_t *, int16_t *); - private: + static TouchScreenCST226SE *instance; TouchClassCST226 touch; uint8_t i2cAddress = 0; From f5c3e77a6089c8fb6ef0c7307fbee087675fe506 Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 19 Apr 2025 20:48:06 +0000 Subject: [PATCH 24/25] changed to sensorlib 0.3.1 --- src/input/TouchScreenCST226SE.cpp | 44 +++++++++++++++++-------------- src/input/TouchScreenCST226SE.h | 6 ++--- variants/tbeam/platformio.ini | 2 +- variants/tbeam/variant.h | 2 +- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/input/TouchScreenCST226SE.cpp b/src/input/TouchScreenCST226SE.cpp index ff0b39a7a..b99ff067b 100644 --- a/src/input/TouchScreenCST226SE.cpp +++ b/src/input/TouchScreenCST226SE.cpp @@ -3,35 +3,38 @@ #ifdef HAS_CST226SE +#ifndef TOUCH_IRQ +#define TOUCH_IRQ -1 +#endif + #include "PowerFSM.h" #include "Wire.h" #include "configuration.h" #include "modules/ExternalNotificationModule.h" -volatile bool CST_IRQ = false; +volatile bool isPressed = false; TouchScreenCST226SE *TouchScreenCST226SE::instance = nullptr; TouchScreenCST226SE *touchScreenCST226SE; TouchScreenCST226SE::TouchScreenCST226SE(uint16_t width, uint16_t height, bool (*getTouch)(int16_t *, int16_t *)) - : TouchScreenBase("touchscreen1", width, height), _getTouch(getTouch) + : TouchScreenBase("CST226", width, height), _getTouch(getTouch) { instance = this; } void TouchScreenCST226SE::init() { + touch.setPins(-1, TOUCH_IRQ); + touch.setTouchDrvModel(TouchDrv_CST226); for (uint8_t addr : PossibleAddresses) { if (touch.begin(Wire, addr, I2C_SDA, I2C_SCL)) { i2cAddress = addr; - - // #ifdef TOUCHSCREEN_INT - // pinMode(TOUCHSCREEN_INT, INPUT); - // attachInterrupt( - // TOUCHSCREEN_INT, [] { CST_IRQ = true; }, RISING); - // #endif - + attachInterrupt( + TOUCH_IRQ, []() { isPressed = true; }, FALLING); LOG_DEBUG("CST226SE init OK at address 0x%02X", addr); + touch.setMaxCoordinates(TFT_WIDTH + 5, TFT_HEIGHT + 5); + touch.setMirrorXY(true, true); return; } } @@ -41,17 +44,18 @@ void TouchScreenCST226SE::init() bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y) { - if (!touch.isPressed()) + if (!touch.isPressed()) { return false; - int16_t x_array[1], y_array[1]; - uint8_t count = touch.getPoint(x_array, y_array, 1); - if (count > 0) { - x = x_array[0]; - y = y_array[0]; - return true; + int16_t x_array[1], y_array[1]; + uint8_t touched = touch.getPoint(x_array, y_array, 1); + if (touched > 0) { + x = x_array[0]; + y = y_array[0]; + LOG_DEBUG("TouchScreen touched %dx %dy", x, y); + return true; + } } - return false; } @@ -59,10 +63,10 @@ bool TouchScreenCST226SE::forwardGetTouch(int16_t *x, int16_t *y) { if (instance) { return instance->getTouch(*x, *y); - LOG_DEBUG("TouchScreen touched %dx %dy", x, y); + LOG_DEBUG("TouchScreen parsed %dx %dy", x, y); + } else { + return false; } - - return false; } void TouchScreenCST226SE::onEvent(const TouchEvent &event) diff --git a/src/input/TouchScreenCST226SE.h b/src/input/TouchScreenCST226SE.h index fe5b81229..26bc7a449 100644 --- a/src/input/TouchScreenCST226SE.h +++ b/src/input/TouchScreenCST226SE.h @@ -6,8 +6,8 @@ #include "modules/CannedMessageModule.h" +#include "TouchDrvCSTXXX.hpp" #include "TouchScreenBase.h" -#include "touch/TouchClassCST226.h" class TouchScreenCST226SE : public TouchScreenBase { @@ -17,14 +17,12 @@ class TouchScreenCST226SE : public TouchScreenBase static bool forwardGetTouch(int16_t *x, int16_t *y); bool (*_getTouch)(int16_t *, int16_t *); - - protected: virtual bool getTouch(int16_t &x, int16_t &y); virtual void onEvent(const TouchEvent &event); private: static TouchScreenCST226SE *instance; - TouchClassCST226 touch; + TouchDrvCSTXXX touch; uint8_t i2cAddress = 0; static constexpr uint8_t PossibleAddresses[2] = {CST226SE_ADDR, CST226SE_ADDR_ALT}; diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index d345b164b..41a805849 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -22,4 +22,4 @@ build_flags = lib_deps = ${env:tbeam.lib_deps} https://github.com/Nasimovy/st7796/archive/refs/tags/1.0.5.zip ; display addon - lewisxhe/SensorLib@0.2.0 ; touchscreen addon + lewisxhe/SensorLib@0.3.1 ; touchscreen addon diff --git a/variants/tbeam/variant.h b/variants/tbeam/variant.h index 04801e678..4cf409165 100644 --- a/variants/tbeam/variant.h +++ b/variants/tbeam/variant.h @@ -53,7 +53,7 @@ #define HAS_CST226SE 1 #define HAS_TOUCHSCREEN 1 -#define TOUCHSCREEN_INT 35 +#define TOUCH_IRQ 35 #define ST7796_NSS 25 #define ST7796_RS 13 // DC From f30f5281c1f496e80e9f78616578aa160a0d906c Mon Sep 17 00:00:00 2001 From: nasimovy Date: Sat, 19 Apr 2025 21:28:34 +0000 Subject: [PATCH 25/25] i broke it , dont know how to fix at the moment will investigate --- src/input/TouchScreenCST226SE.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/input/TouchScreenCST226SE.cpp b/src/input/TouchScreenCST226SE.cpp index b99ff067b..3afd20db3 100644 --- a/src/input/TouchScreenCST226SE.cpp +++ b/src/input/TouchScreenCST226SE.cpp @@ -33,8 +33,6 @@ void TouchScreenCST226SE::init() attachInterrupt( TOUCH_IRQ, []() { isPressed = true; }, FALLING); LOG_DEBUG("CST226SE init OK at address 0x%02X", addr); - touch.setMaxCoordinates(TFT_WIDTH + 5, TFT_HEIGHT + 5); - touch.setMirrorXY(true, true); return; } } @@ -46,15 +44,19 @@ bool TouchScreenCST226SE::getTouch(int16_t &x, int16_t &y) { if (!touch.isPressed()) { return false; - - int16_t x_array[1], y_array[1]; - uint8_t touched = touch.getPoint(x_array, y_array, 1); - if (touched > 0) { - x = x_array[0]; - y = y_array[0]; - LOG_DEBUG("TouchScreen touched %dx %dy", x, y); - return true; + } + int16_t x_array[1], y_array[1]; + uint8_t touched = touch.getPoint(x_array, y_array, 1); + if (touched > 0) { + int16_t tx = x_array[0]; + int16_t ty = y_array[0]; + if (tx > (TFT_WIDTH + 10) && tx < (10) && ty > (TFT_HEIGHT + 10) && ty < (10)) { + return false; } + x = tx; + y = ty; + LOG_DEBUG("TouchScreen touched %dx %dy", x, y); + return true; } return false; }