From 97824c6ba0b73968a1ffd6a11470c5655d438b65 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 20 Apr 2026 00:20:53 -0500 Subject: [PATCH] Get t-watch-ultra working better on BaseUI --- src/graphics/Screen.cpp | 2 +- src/graphics/TFTDisplay.cpp | 65 ++++++++++++++---------- variants/esp32s3/t-watch-ultra/variant.h | 5 +- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 5d5ed3686..fb9ae0c8b 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -438,7 +438,7 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver) #endif // some screens seem to need a kick in the pants to turn back on -#if defined(MUZI_BASE) || defined(M5STACK_CARDPUTER_ADV) +#if defined(MUZI_BASE) || defined(M5STACK_CARDPUTER_ADV) || defined(TFT_RESET_AFTER_SLEEP) dispdev->init(); dispdev->setBrightness(brightness); dispdev->flipScreenVertically(); diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index f47e51720..bc680dd1b 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -82,42 +82,19 @@ class LGFX : public lgfx::LGFX_Device setPanel(&_panel_instance); } - bool enableFrameBuffer(bool auto_display = false) - { - if (_panel_instance.initPanelFb()) { - auto fbPanel = _panel_instance.getPanelFb(); - if (fbPanel) { - fbPanel->setBus(&_bus_instance); - fbPanel->setAutoDisplay(auto_display); - setPanel(fbPanel); - return true; - } - } - return false; - } - - void disableFrameBuffer() - { - auto fbPanel = _panel_instance.getPanelFb(); - if (fbPanel) { - _panel_instance.deinitPanelFb(); - setPanel(&_panel_instance); - } - } - bool init() { #ifdef CO5300_RESET LOG_DEBUG("LGFX_Panel_CO5300::init()"); lgfx::pinMode(CO5300_RESET, lgfx::pin_mode_t::output); lgfx::gpio_hi(CO5300_RESET); - delay(200); + delay(20); lgfx::gpio_lo(CO5300_RESET); - delay(300); + delay(30); lgfx::gpio_hi(CO5300_RESET); - delay(200); + delay(20); #endif - return lgfx::LGFX_Device::init() && enableFrameBuffer(false); + return lgfx::LGFX_Device::init(); } }; @@ -1385,13 +1362,41 @@ void TFTDisplay::display(bool fromBlank) if (x_LastPixelUpdate >= displayWidth) { x_LastPixelUpdate = displayWidth - 1; } + + int y_offset = 0; +#if defined(CO5300_CS) + uint8_t lines_updated = 2; + if (y % 2 == 0) { + y_byteIndex = ((y + 1) / 8) * displayWidth; + y_byteMask = (1 << ((y + 1) & 7)); + uint32_t bufferIndex = 1; + for (x = x_FirstPixelUpdate; x < x_LastPixelUpdate; x++) { + isset = buffer[x + y_byteIndex] & y_byteMask; + linePixelBuffer[bufferIndex++ + x_LastPixelUpdate] = isset ? colorTftMesh : colorTftBlack; + } + } else { + y_offset = -1; + memcpy(&linePixelBuffer[x_LastPixelUpdate + 1], &linePixelBuffer[x_FirstPixelUpdate], + 2 * (x_LastPixelUpdate - x_FirstPixelUpdate + 1)); + y_byteIndex = ((y - 1) / 8) * displayWidth; + y_byteMask = (1 << ((y - 1) & 7)); + uint32_t bufferIndex = 0; + for (x = x_FirstPixelUpdate; x < x_LastPixelUpdate; x++) { + isset = buffer[x + y_byteIndex] & y_byteMask; + linePixelBuffer[bufferIndex++ + x_FirstPixelUpdate] = isset ? colorTftMesh : colorTftBlack; + } + } +#else + uint8_t lines_updated = 1; +#endif + #if defined(HACKADAY_COMMUNICATOR) tft->draw16bitBeRGBBitmap(x_FirstPixelUpdate, y, &linePixelBuffer[x_FirstPixelUpdate], (x_LastPixelUpdate - x_FirstPixelUpdate + 1), 1); #else // Step 4: Send the changed pixels on this line to the screen as a single block transfer. // This function accepts pixel data MSB first so it can dump the memory straight out the SPI port. - tft->pushRect(x_FirstPixelUpdate, y, (x_LastPixelUpdate - x_FirstPixelUpdate + 1), 1, + tft->pushRect(x_FirstPixelUpdate, y + y_offset, (x_LastPixelUpdate - x_FirstPixelUpdate + 1), lines_updated, &linePixelBuffer[x_FirstPixelUpdate]); #endif somethingChanged = true; @@ -1617,7 +1622,11 @@ bool TFTDisplay::connect() tft->fillScreen(TFT_BLACK); if (this->linePixelBuffer == NULL) { +#if defined(CO5300_CS) + this->linePixelBuffer = (uint16_t *)malloc(sizeof(uint16_t) * displayWidth * 2); +#else this->linePixelBuffer = (uint16_t *)malloc(sizeof(uint16_t) * displayWidth); +#endif if (!this->linePixelBuffer) { LOG_ERROR("Not enough memory to create TFT line buffer\n"); diff --git a/variants/esp32s3/t-watch-ultra/variant.h b/variants/esp32s3/t-watch-ultra/variant.h index 02544b880..9f3c6d181 100644 --- a/variants/esp32s3/t-watch-ultra/variant.h +++ b/variants/esp32s3/t-watch-ultra/variant.h @@ -18,6 +18,8 @@ #define TFT_OFFSET_ROTATION 0 #define SCREEN_TRANSITION_FRAMERATE 5 // fps #define USE_TFTDISPLAY 1 +#define HAS_SCREEN 1 +#define TFT_RESET_AFTER_SLEEP #define HAS_TOUCHSCREEN 1 #define SCREEN_TOUCH_INT 12 @@ -42,7 +44,7 @@ #define DAC_I2S_BCK 9 #define DAC_I2S_WS 10 #define DAC_I2S_DOUT 11 -#define DAC_I2S_MCLK 0 // TODO +#define DAC_I2S_MCLK -1 // TODO #define HAS_AXP2101 // #define PMU_IRQ 7 @@ -67,6 +69,7 @@ #define USE_SX1262 // #define USE_SX1280 +#define HW_SPI1_DEVICE #define LORA_SCK 35 #define LORA_MISO 33