From 58485dec2a423161b34b628366c2921b1803db8d Mon Sep 17 00:00:00 2001 From: gemu Date: Mon, 22 Jul 2024 13:58:50 +0200 Subject: [PATCH] fix resistive Touch xpt for 2 spi busses (#21814) * fix xpt touch for 2 spi busses * support for 2 utouch spi busses * Update support.ino --- lib/lib_display/UDisplay/uDisplay.cpp | 22 ++++++++++++++-------- tasmota/tasmota_support/support.ino | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/lib_display/UDisplay/uDisplay.cpp b/lib/lib_display/UDisplay/uDisplay.cpp index eb6888447..d20f6037c 100755 --- a/lib/lib_display/UDisplay/uDisplay.cpp +++ b/lib/lib_display/UDisplay/uDisplay.cpp @@ -30,6 +30,7 @@ #include "tasmota_options.h" + extern int Cache_WriteBack_Addr(uint32_t addr, uint32_t size); @@ -2020,11 +2021,15 @@ bool uDisplay::utouch_Init(char **name) { attachInterrupt(ut_irq, ut_touch_irq, FALLING); } +extern SPIClass *Init_SPI_Bus(uint32 bus); + if (ut_spi_nr == spi_nr) { + // same as display ut_spi = uspi; } else { - // not yet - ut_spi = nullptr; +#ifdef ESP32 + ut_spi = Init_SPI_Bus(ut_spi_nr); +#endif } return ut_execute(ut_init_code); } @@ -2245,7 +2250,6 @@ void uDisplay::pushColors(uint16_t *data, uint16_t len, boolean not_swapped) { } else { uint16_t *fb_y = rgb_fb + (int32_t)seta_yp1 * _width; for (uint32_t y = seta_yp1; y < seta_yp2; y++) { - seta_yp1++; uint16_t * fb_xy = fb_y + seta_xp1; // we get the 'not_swapped' test outside of the inner loop if (not_swapped) { @@ -2254,7 +2258,7 @@ void uDisplay::pushColors(uint16_t *data, uint16_t len, boolean not_swapped) { *fb_xy = color; fb_xy++; lenc--; - if (!lenc) goto update_cache; // failsafe - exist if len (pixel number) is exhausted + if (!lenc) break; // failsafe - exist if len (pixel number) is exhausted } } else { for (uint32_t x = seta_xp1; x < seta_xp2; x++) { @@ -2263,16 +2267,18 @@ void uDisplay::pushColors(uint16_t *data, uint16_t len, boolean not_swapped) { *fb_xy = color; fb_xy++; lenc--; - if (!lenc) goto update_cache; // failsafe - exist if len (pixel number) is exhausted + if (!lenc) break; // failsafe - exist if len (pixel number) is exhausted } } + uint16_t * flush_ptr = rgb_fb + (int32_t)seta_yp1 * _width + seta_xp1; + esp_cache_msync(flush_ptr, (seta_xp2 - seta_xp1) * 2, 0); fb_y += _width; + seta_yp1++; + if (!lenc) break; } // using esp_cache_msync() to flush the PSRAM cache and ensure that all data is actually written to PSRAM // from https://github.com/espressif/esp-idf/blob/636ff35b52f10e1a804a3760a5bd94e68f4b1b71/components/esp_lcd/rgb/esp_lcd_panel_rgb.c#L159 -update_cache: - uint16_t * flush_ptr = rgb_fb + (int32_t)seta_yp1 * _width; - esp_cache_msync(flush_ptr, len * 2, 0); + } #endif return; diff --git a/tasmota/tasmota_support/support.ino b/tasmota/tasmota_support/support.ino index e6b85cd5c..4159efb79 100755 --- a/tasmota/tasmota_support/support.ino +++ b/tasmota/tasmota_support/support.ino @@ -1784,6 +1784,7 @@ bool ValidGPIO(uint32_t pin, uint32_t gpio) { return (GPIO_USER == ValidPin(pin, BGPIO(gpio))); // Only allow GPIO_USER pins } + bool ValidSpiPinUsed(uint32_t gpio) { // ESP8266: If SPI pin selected chk if it's not one of the three Hardware SPI pins (12..14) bool result = false; @@ -1794,6 +1795,29 @@ bool ValidSpiPinUsed(uint32_t gpio) { return result; } +#ifdef ESP32 +#ifndef FIRMWARE_SAFEBOOT +SPIClass *Init_SPI_Bus(uint32 bus) { + SPIClass *spi; + if (1 == bus) { + if (TasmotaGlobal.spi_enabled) { + spi = &SPI; + spi->begin(Pin(GPIO_SPI_CLK, 0), Pin(GPIO_SPI_MISO, 0), Pin(GPIO_SPI_MOSI, 0), -1); + return spi; + } + } + if (2 == bus) { + if (TasmotaGlobal.spi_enabled2) { + spi = new SPIClass(HSPI); + spi->begin(Pin(GPIO_SPI_CLK, 1), Pin(GPIO_SPI_MISO, 1), Pin(GPIO_SPI_MOSI, 1), -1); + return spi; + } + } + return nullptr; +} +#endif // FIRMWARE_SAFEBOOT +#endif // ESP32 + bool JsonTemplate(char* dataBuf) { // Old: {"NAME":"Shelly 2.5","GPIO":[56,0,17,0,21,83,0,0,6,82,5,22,156],"FLAG":2,"BASE":18}