From dec28a4630b3e5e2332d74154df987cdecbe22fb Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Thu, 7 Aug 2025 23:34:09 +0200 Subject: [PATCH] fix: Indicator display (#173) * disable some logs which potentially lead to crash * indicator: hw rotation + increase frequency * PSRAM display buffer allocation * define fast mem * revert frequency to 6M (to avoid drift) * trunk fmt --- include/graphics/LGFX/LGFX_INDICATOR.h | 31 +++++++++++++++++++---- include/graphics/driver/LGFXDriver.h | 14 +++++----- include/lv_conf.h | 2 +- source/graphics/TFT/TFTView_320x240.cpp | 6 ++--- source/graphics/common/ViewController.cpp | 2 +- source/util/LogRotate.cpp | 4 +-- 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/include/graphics/LGFX/LGFX_INDICATOR.h b/include/graphics/LGFX/LGFX_INDICATOR.h index 420fcb6..9f8d53d 100644 --- a/include/graphics/LGFX/LGFX_INDICATOR.h +++ b/include/graphics/LGFX/LGFX_INDICATOR.h @@ -54,13 +54,35 @@ class LGFX_Touch : public lgfx::LGFX_Device private: BBCapTouch bbct; }; +#endif +class Panel_Indicator : public lgfx::Panel_ST7701 +{ + public: + const uint8_t *getInitCommands(uint8_t listno) const override + { + static constexpr const uint8_t list1[] = { + 0x36, 1, 0x10, // MADCTL for vertical flip + 0xFF, 5, 0x77, 0x01, 0x00, 0x00, 0x10, // Command2 BK0 SEL + 0xC7, 1, 0x04, // SDIR: X-direction Control (Horizontal Flip) + 0xFF, 5, 0x77, 0x01, 0x00, 0x00, 0x00 // Command2 BK0 DIS + }; + switch (listno) { + case 1: + return list1; + default: + return lgfx::Panel_ST7701::getInitCommands(listno); + } + } +}; + +#ifdef CUSTOM_TOUCH_DRIVER class LGFX_INDICATOR : public LGFX_Touch #else class LGFX_INDICATOR : public lgfx::LGFX_Device #endif { - lgfx::Panel_ST7701 _panel_instance; + Panel_Indicator _panel_instance; lgfx::Bus_RGB _bus_instance; lgfx::Light_PWM _light_instance; lgfx::Touch_FT5x06 _touch_instance; @@ -81,7 +103,7 @@ class LGFX_INDICATOR : public lgfx::LGFX_Device cfg.panel_height = screenHeight; cfg.offset_x = 0; cfg.offset_y = 0; - cfg.offset_rotation = 2; + cfg.offset_rotation = 0; _panel_instance.config(cfg); } @@ -156,8 +178,8 @@ class LGFX_INDICATOR : public lgfx::LGFX_Device cfg.x_max = 479; cfg.y_min = 0; cfg.y_max = 479; - cfg.pin_int = GPIO_NUM_NC; // don't use IO_EXPANDER!; - cfg.pin_rst = GPIO_NUM_NC; // not needed as well; + cfg.pin_int = GPIO_NUM_NC; // don't use IO_EXPANDER! + cfg.pin_rst = GPIO_NUM_NC; // not needed as well cfg.bus_shared = false; cfg.offset_rotation = 0; @@ -170,7 +192,6 @@ class LGFX_INDICATOR : public lgfx::LGFX_Device _panel_instance.setTouch(&_touch_instance); } #endif - setPanel(&_panel_instance); } }; diff --git a/include/graphics/driver/LGFXDriver.h b/include/graphics/driver/LGFXDriver.h index a848e84..a31d18d 100644 --- a/include/graphics/driver/LGFXDriver.h +++ b/include/graphics/driver/LGFXDriver.h @@ -250,18 +250,18 @@ template void LGFXDriver::init(DeviceGUI *gui) #endif assert(buf1 != 0 /* && buf2 != 0 */); lv_display_set_buffers(disp, buf1, buf2, bufsize, LV_DISPLAY_RENDER_MODE_DIRECT); -#elif 0 // defined BOARD_HAS_PSRAM +#elif defined(BOARD_HAS_PSRAM) assert(ESP.getFreePsram()); - bufsize = screenWidth * height / 8 * sizeof(lv_color_t); - ILOG_DEBUG("LVGL: allocating %u bytes PSRAM for draw buffer"), bufsize; - buf1 = (lv_color_t *)heap_caps_malloc(bufsize, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT); // heap_alloc_psram + bufsize = lgfx->screenWidth * lgfx->screenHeight * sizeof(lv_color_t) / 4; + ILOG_DEBUG("LVGL: allocating %u bytes PSRAM for draw buffer", bufsize); + buf1 = (lv_color_t *)LV_MEM_POOL_ALLOC(bufsize); assert(buf1 != 0); - lv_display_set_buffers(display, buf1, buf2, bufsize, LV_DISPLAY_RENDER_MODE_PARTIAL); + lv_display_set_buffers(this->display, buf1, buf2, bufsize, LV_DISPLAY_RENDER_MODE_PARTIAL); #else - bufsize = lgfx->screenWidth * lgfx->screenHeight; + bufsize = lgfx->screenWidth * lgfx->screenHeight / 8; + ILOG_DEBUG("LVGL: allocating %u bytes heap memory for draw buffer", sizeof(lv_color_t) * bufsize); buf1 = new lv_color_t[bufsize]; assert(buf1 != 0); - ILOG_DEBUG("LVGL: allocating %u bytes heap memory for draw buffer", sizeof(lv_color_t) * bufsize); lv_display_set_buffers(this->display, buf1, buf2, sizeof(lv_color_t) * bufsize, LV_DISPLAY_RENDER_MODE_PARTIAL); #endif diff --git a/include/lv_conf.h b/include/lv_conf.h index 36fb5f1..1a219fc 100644 --- a/include/lv_conf.h +++ b/include/lv_conf.h @@ -464,7 +464,7 @@ #define LV_ATTRIBUTE_LARGE_RAM_ARRAY /*Place performance critical functions into a faster memory (e.g RAM)*/ -#define LV_ATTRIBUTE_FAST_MEM +#define LV_ATTRIBUTE_FAST_MEM IRAM_ATTR /*Export integer constant to binding. This macro is used with constants in the form of LV_ that *should also appear on LVGL binding API such as MicroPython.*/ diff --git a/source/graphics/TFT/TFTView_320x240.cpp b/source/graphics/TFT/TFTView_320x240.cpp index 8bab2ca..6b24b6f 100644 --- a/source/graphics/TFT/TFTView_320x240.cpp +++ b/source/graphics/TFT/TFTView_320x240.cpp @@ -6293,9 +6293,9 @@ void TFTView_320x240::newMessage(uint32_t nodeNum, lv_obj_t *container, uint8_t */ void TFTView_320x240::restoreMessage(const LogMessage &msg) { - ((uint8_t *)msg.bytes)[msg._size] = 0; - ILOG_DEBUG("restoring msg from:0x%08x, to:0x%08x, ch:%d, time:%d, status:%d, trash:%d, size:%d, '%s'", msg.from, msg.to, - msg.ch, msg.time, (int)msg.status, msg.trashFlag, msg._size, msg.bytes); + //((uint8_t *)msg.bytes)[msg._size] = 0; + // ILOG_DEBUG("restoring msg from:0x%08x, to:0x%08x, ch:%d, time:%d, status:%d, trash:%d, size:%d, '%s'", msg.from, msg.to, + // msg.ch, msg.time, (int)msg.status, msg.trashFlag, msg._size, msg.bytes); if (msg.from == ownNode) { lv_obj_t *container = nullptr; diff --git a/source/graphics/common/ViewController.cpp b/source/graphics/common/ViewController.cpp index 3857f7b..690d196 100644 --- a/source/graphics/common/ViewController.cpp +++ b/source/graphics/common/ViewController.cpp @@ -477,7 +477,7 @@ void ViewController::sendTextMessage(uint32_t to, uint8_t ch, uint8_t hopLimit, assert(msgLen <= (size_t)DATA_PAYLOAD_LEN); if (send(to, ch, hopLimit, requestId, meshtastic_PortNum_TEXT_MESSAGE_APP, false, usePkc, (const uint8_t *)textmsg, msgLen)) { - ILOG_DEBUG("storing msg to:0x%08x, ch:%d, time:%d, size:%d, '%s'", to, ch, msgTime, msgLen, textmsg); + // ILOG_DEBUG("storing msg to:0x%08x, ch:%d, time:%d, size:%d, '%s'", to, ch, msgTime, msgLen, textmsg); log.write(LogMessageEnv(myNodeNum, to, ch, msgTime, LogMessage::eDefault, false, msgLen, (const uint8_t *)textmsg)); } } diff --git a/source/util/LogRotate.cpp b/source/util/LogRotate.cpp index 965efca..4276574 100644 --- a/source/util/LogRotate.cpp +++ b/source/util/LogRotate.cpp @@ -104,8 +104,8 @@ bool LogRotate::write(const ILogEntry &entry) currentSize += entry.size(); totalSize += entry.size(); - ILOG_DEBUG("LogRotate: %d bytes written in %d ms to %s (%d/%d bytes, total: %d)", entry.size(), millis() - start, - currentLogName.c_str(), currentSize, c_maxFileSize, totalSize); + // ILOG_DEBUG("LogRotate: %d bytes written in %d ms to %s (%d/%d bytes, total: %d)", entry.size(), millis() - start, + // currentLogName.c_str(), currentSize, c_maxFileSize, totalSize); return true; }