From 19e62b8686c8fcb1203d6ba9c727a8d6081288bd Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Sat, 4 Oct 2025 12:36:31 +0200 Subject: [PATCH] add framebuffer --- src/graphics/TFTDisplay.cpp | 51 ++++++++++++++++++------ variants/esp32s3/t-watch-ultra/variant.h | 2 +- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 43b9ca8ff..4bc86683a 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -57,13 +57,13 @@ class LGFX : public lgfx::LGFX_Device { // Set the display panel control. auto cfg = _panel_instance.config(); // Gets a structure for display panel settings. - cfg.pin_cs = CO5300_CS; // Pin number where CS is connected (-1 = disable) - cfg.pin_rst = CO5300_RESET; // Pin number where RST is connected (-1 = disable) - cfg.panel_width = TFT_WIDTH; // actual displayable width - cfg.panel_height = TFT_HEIGHT; // actual displayable height - cfg.offset_rotation = 0; // Rotation direction value offset 0~7 (4~7 is upside down) - cfg.offset_x = 22; - cfg.offset_y = 0; + cfg.pin_cs = CO5300_CS; // Pin number where CS is connected (-1 = disable) + cfg.pin_rst = CO5300_RESET; // Pin number where RST is connected (-1 = disable) + cfg.panel_width = TFT_WIDTH; // actual displayable width + cfg.panel_height = TFT_HEIGHT; // actual displayable height + cfg.offset_rotation = TFT_OFFSET_ROTATION; // Rotation direction value offset 0~7 (4~7 is upside down) + cfg.offset_x = TFT_OFFSET_X; + cfg.offset_y = TFT_OFFSET_Y; cfg.dummy_read_pixel = 8; // Number of bits for dummy read before pixel readout cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read cfg.readable = true; // Set to true if data can be read @@ -81,6 +81,29 @@ 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 @@ -93,7 +116,7 @@ class LGFX : public lgfx::LGFX_Device lgfx::gpio_hi(CO5300_RESET); delay(200); #endif - return lgfx::LGFX_Device::init(); + return lgfx::LGFX_Device::init() && enableFrameBuffer(false); } }; @@ -1303,8 +1326,8 @@ void TFTDisplay::display(bool fromBlank) // 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, - &linePixelBuffer[x_FirstPixelUpdate]); + tft->pushImage(x_FirstPixelUpdate, y, (x_LastPixelUpdate - x_FirstPixelUpdate + 1), 1, + &linePixelBuffer[x_FirstPixelUpdate]); somethingChanged = true; } @@ -1364,7 +1387,7 @@ void TFTDisplay::sendCommand(uint8_t com) // handle display on/off directly switch (com) { case DISPLAYON: { - // LOG_DEBUG("Display on"); + LOG_DEBUG("Display on"); backlightEnable->set(true); #if ARCH_PORTDUINO display(true); @@ -1383,12 +1406,13 @@ void TFTDisplay::sendCommand(uint8_t com) #endif #ifdef RAK14014 #elif !defined(M5STACK) && !defined(ST7789_CS) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function + LOG_DEBUG("tft->setBrightness(172)"); tft->setBrightness(172); #endif break; } case DISPLAYOFF: { - // LOG_DEBUG("Display off"); + LOG_DEBUG("Display off"); backlightEnable->set(false); #if ARCH_PORTDUINO tft->clear(); @@ -1407,6 +1431,7 @@ void TFTDisplay::sendCommand(uint8_t com) #endif #ifdef RAK14014 #elif !defined(M5STACK) + LOG_DEBUG("tft->setBrightness(0)"); tft->setBrightness(0); #endif break; @@ -1482,8 +1507,8 @@ bool TFTDisplay::connect() tft = new LGFX; #endif - backlightEnable->set(true); LOG_INFO("Power to TFT Backlight"); + backlightEnable->set(true); #ifdef UNPHONE unphone.backlight(true); // using unPhone library diff --git a/variants/esp32s3/t-watch-ultra/variant.h b/variants/esp32s3/t-watch-ultra/variant.h index 23404ea60..b79b8507b 100644 --- a/variants/esp32s3/t-watch-ultra/variant.h +++ b/variants/esp32s3/t-watch-ultra/variant.h @@ -13,7 +13,7 @@ #define SPI_READ_FREQUENCY 16000000 // irrelevant #define TFT_HEIGHT 502 #define TFT_WIDTH 410 -#define TFT_OFFSET_X 0 +#define TFT_OFFSET_X 22 #define TFT_OFFSET_Y 0 #define TFT_OFFSET_ROTATION 0 #define SCREEN_TRANSITION_FRAMERATE 5 // fps