From c3a20c16c5e3c155aceb844456c6484cc9c66db7 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 16 Aug 2025 00:13:11 +0200 Subject: [PATCH] Board update --- .../Source/hal/CrowPanelDisplay.cpp | 3 +- .../Source/hal/CrowPanelDisplay.h | 37 +------- .../Source/hal/CrowPanelSdCard.cpp | 2 - .../Source/hal/CrowPanelDisplay.cpp | 3 +- .../Source/hal/CrowPanelDisplay.h | 2 +- Boards/LilygoTLoraPager/CMakeLists.txt | 2 +- .../Source/hal/TpagerDisplay.cpp | 5 +- .../Source/hal/TpagerDisplay.h | 37 +------- .../Source/hal/TpagerKeyboard.h | 12 +-- .../M5stackCore2/Source/hal/Core2Display.cpp | 10 ++- Boards/M5stackCore2/Source/hal/Core2Power.cpp | 2 +- Drivers/FT6x36/Source/Ft6x36Touch.cpp | 86 +++++++++++++------ Drivers/FT6x36/Source/Ft6x36Touch.h | 57 +++++++++--- Drivers/ST7789/Source/St7789Display.cpp | 11 +-- Drivers/ST7789/Source/St7789Display.h | 19 ++-- Drivers/ST7796/CMakeLists.txt | 2 +- Drivers/ST7796/Source/St7796Display.cpp | 53 +++--------- Drivers/ST7796/Source/St7796Display.h | 42 +++++---- 18 files changed, 174 insertions(+), 211 deletions(-) diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.cpp index cc6cfc1b..4f50d62c 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.cpp @@ -42,5 +42,6 @@ std::shared_ptr createDisplay() { configuration->mirrorX = true; configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty; - return std::make_shared(std::move(configuration)); + auto display = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(display); } diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.h b/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.h index 6c0fde39..7a9b967d 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.h +++ b/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelDisplay.h @@ -1,40 +1,5 @@ #pragma once -#include "Tactility/hal/display/DisplayDevice.h" -#include -#include - -class CrowPanelDisplay : public tt::hal::display::DisplayDevice { - -private: - - esp_lcd_panel_io_handle_t ioHandle = nullptr; - esp_lcd_panel_handle_t panelHandle = nullptr; - lv_display_t* displayHandle = nullptr; - bool poweredOn = false; - -public: - - std::string getName() const final { return "ST7789"; } - std::string getDescription() const final { return "SPI display"; } - - bool start() override; - - bool stop() override; - - void setPowerOn(bool turnOn) override; - bool isPoweredOn() const override { return poweredOn; }; - bool supportsPowerControl() const override { return true; } - - std::shared_ptr _Nullable createTouch() override; - - void setBacklightDuty(uint8_t backlightDuty) override; - bool supportsBacklightDuty() const override { return true; } - - void setGammaCurve(uint8_t index) override; - uint8_t getGammaCurveCount() const override { return 4; }; - - lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; } -}; +#include std::shared_ptr createDisplay(); diff --git a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp b/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp index 0959c55c..0274fd3e 100644 --- a/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp +++ b/Boards/ElecrowCrowpanelBasic35/Source/hal/CrowPanelSdCard.cpp @@ -3,8 +3,6 @@ #include #include -#include - using tt::hal::sdcard::SpiSdCardDevice; std::shared_ptr createSdCard() { diff --git a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.cpp b/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.cpp index d81bc5c5..6533da9a 100644 --- a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.cpp +++ b/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.cpp @@ -101,5 +101,6 @@ std::shared_ptr createDisplay() { driver::pwmbacklight::setBacklightDuty ); - return std::make_shared(std::move(configuration)); + auto display = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(display); } diff --git a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h b/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h index 5a0d81b3..7a9b967d 100644 --- a/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h +++ b/Boards/ElecrowCrowpanelBasic50/Source/hal/CrowPanelDisplay.h @@ -1,5 +1,5 @@ #pragma once -#include "Tactility/hal/display/DisplayDevice.h" +#include std::shared_ptr createDisplay(); diff --git a/Boards/LilygoTLoraPager/CMakeLists.txt b/Boards/LilygoTLoraPager/CMakeLists.txt index 3e3a7c3c..5746b57d 100644 --- a/Boards/LilygoTLoraPager/CMakeLists.txt +++ b/Boards/LilygoTLoraPager/CMakeLists.txt @@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*) idf_component_register( SRCS ${SOURCE_FILES} INCLUDE_DIRS "Source" - REQUIRES Tactility esp_lvgl_port esp_lcd ST7796 BQ27220 TCA8418 PwmBacklight driver esp_adc + REQUIRES Tactility esp_lcd ST7796 BQ27220 TCA8418 PwmBacklight driver esp_adc ) diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.cpp b/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.cpp index 30dceb9a..5f4c6755 100644 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.cpp +++ b/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.cpp @@ -6,8 +6,6 @@ #include -#define TAG "TPAGER_display" - std::shared_ptr createDisplay() { auto configuration = std::make_unique( TPAGER_LCD_SPI_HOST, @@ -26,5 +24,6 @@ std::shared_ptr createDisplay() { configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty; - return std::make_shared(std::move(configuration)); + auto display = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(display); } diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h b/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h index df09ebc9..7a9b967d 100644 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h +++ b/Boards/LilygoTLoraPager/Source/hal/TpagerDisplay.h @@ -1,40 +1,5 @@ #pragma once -#include "Tactility/hal/display/DisplayDevice.h" -#include -#include - -class TpagerDisplay : public tt::hal::display::DisplayDevice { - -private: - - esp_lcd_panel_io_handle_t ioHandle = nullptr; - esp_lcd_panel_handle_t panelHandle = nullptr; - lv_display_t* displayHandle = nullptr; - bool poweredOn = false; - -public: - - std::string getName() const final { return "ST7796"; } - std::string getDescription() const final { return "SPI display"; } - - bool start() override; - - bool stop() override; - - void setPowerOn(bool turnOn) override; - bool isPoweredOn() const override { return poweredOn; }; - bool supportsPowerControl() const override { return true; } - - std::shared_ptr _Nullable createTouch() override; - - void setBacklightDuty(uint8_t backlightDuty) override; - bool supportsBacklightDuty() const override { return true; } - - void setGammaCurve(uint8_t index) override; - uint8_t getGammaCurveCount() const override { return 4; }; - - lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; } -}; +#include std::shared_ptr createDisplay(); diff --git a/Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.h b/Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.h index 6922ba61..5f09dcd7 100644 --- a/Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.h +++ b/Boards/LilygoTLoraPager/Source/hal/TpagerKeyboard.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include @@ -10,10 +9,7 @@ #include - -class TpagerKeyboard : public tt::hal::keyboard::KeyboardDevice { - -private: +class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice { lv_indev_t* _Nullable kbHandle = nullptr; lv_indev_t* _Nullable encHandle = nullptr; @@ -36,13 +32,13 @@ private: public: TpagerKeyboard(std::shared_ptr tca) : keypad(std::move(tca)) {} - ~TpagerKeyboard() {} - std::string getName() const final { return "T-Lora Pager Keyboard"; } - std::string getDescription() const final { return "I2C keyboard with encoder"; } + std::string getName() const override { return "T-Lora Pager Keyboard"; } + std::string getDescription() const override { return "T-Lora Pager I2C keyboard with encoder"; } bool startLvgl(lv_display_t* display) override; bool stopLvgl() override; + bool isAttached() const override; lv_indev_t* _Nullable getLvglIndev() override { return kbHandle; } diff --git a/Boards/M5stackCore2/Source/hal/Core2Display.cpp b/Boards/M5stackCore2/Source/hal/Core2Display.cpp index 585d2d28..25f7f7e5 100644 --- a/Boards/M5stackCore2/Source/hal/Core2Display.cpp +++ b/Boards/M5stackCore2/Source/hal/Core2Display.cpp @@ -6,10 +6,13 @@ std::shared_ptr createTouch() { auto configuration = std::make_unique( I2C_NUM_0, - GPIO_NUM_39 + GPIO_NUM_39, + CORE2_LCD_HORIZONTAL_RESOLUTION, + CORE2_LCD_VERTICAL_RESOLUTION ); - return std::make_shared(std::move(configuration)); + auto touch = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(touch); } std::shared_ptr createDisplay() { @@ -28,5 +31,6 @@ std::shared_ptr createDisplay() { true ); - return std::make_shared(std::move(configuration)); + auto display = std::make_shared(std::move(configuration)); + return std::reinterpret_pointer_cast(display); } diff --git a/Boards/M5stackCore2/Source/hal/Core2Power.cpp b/Boards/M5stackCore2/Source/hal/Core2Power.cpp index 504ff594..6256186d 100644 --- a/Boards/M5stackCore2/Source/hal/Core2Power.cpp +++ b/Boards/M5stackCore2/Source/hal/Core2Power.cpp @@ -2,7 +2,7 @@ #include #include "axp192/axp192.h" -#define TAG "core2_power" +constexpr auto TAG = "Core2Power"; extern axp192_t axpDevice; diff --git a/Drivers/FT6x36/Source/Ft6x36Touch.cpp b/Drivers/FT6x36/Source/Ft6x36Touch.cpp index e163c768..511cf137 100644 --- a/Drivers/FT6x36/Source/Ft6x36Touch.cpp +++ b/Drivers/FT6x36/Source/Ft6x36Touch.cpp @@ -1,5 +1,6 @@ #include "Ft6x36Touch.h" +#include #include #include @@ -7,22 +8,23 @@ #define TAG "ft6x36" -static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) { +void Ft6x36Touch::touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) { auto* touch = (Ft6x36Touch*)lv_indev_get_driver_data(indev); - touch->readLast(data); + touch->mutex.lock(); + data->point = touch->lastPoint; + data->state = touch->lastState; + touch->mutex.unlock(); } Ft6x36Touch::Ft6x36Touch(std::unique_ptr inConfiguration) : - configuration(std::move(inConfiguration)), - driverThread(tt::Thread("ft6x36", 4096, [this]() { - driverThreadMain(); - return 0; - })) -{} + configuration(std::move(inConfiguration)) { + nativeTouch = std::make_shared(*this); +} Ft6x36Touch::~Ft6x36Touch() { - if (driverThread.getState() != tt::Thread::State::Stopped) { - stop(); + if (driverThread != nullptr && driverThread->getState() != tt::Thread::State::Stopped) { + interruptDriverThread = true; + driverThread->join(); } } @@ -59,7 +61,7 @@ void Ft6x36Touch::driverThreadMain() { } } -bool Ft6x36Touch::shouldInterruptDriverThread() { +bool Ft6x36Touch::shouldInterruptDriverThread() const { bool interrupt = false; if (mutex.lock(50 / portTICK_PERIOD_MS)) { interrupt = interruptDriverThread; @@ -68,35 +70,65 @@ bool Ft6x36Touch::shouldInterruptDriverThread() { return interrupt; } -bool Ft6x36Touch::start(lv_display_t* display) { - TT_LOG_I(TAG, "start"); +bool Ft6x36Touch::start() { + TT_LOG_I(TAG, "Start"); - driverThread.start(); - - uint16_t width = lv_display_get_horizontal_resolution(display); - uint16_t height = lv_display_get_vertical_resolution(display); - if (!driver.begin(FT6X36_DEFAULT_THRESHOLD, width, height)) { + if (!driver.begin(FT6X36_DEFAULT_THRESHOLD, configuration->width, configuration->height)) { TT_LOG_E(TAG, "driver.begin() failed"); return false; } + mutex.lock(); + + interruptDriverThread = false; + + driverThread = std::make_shared("ft6x36", 4096, [this] { + driverThreadMain(); + return 0; + }); + + driverThread->start(); + + mutex.unlock(); + + return true; +} + +bool Ft6x36Touch::stop() { + TT_LOG_I(TAG, "Stop"); + + mutex.lock(); + interruptDriverThread = true; + mutex.unlock(); + + driverThread->join(); + + mutex.lock(); + driverThread = nullptr; + mutex.unlock(); + + return false; +} + +bool Ft6x36Touch::startLvgl(lv_display_t* display) { + if (deviceHandle != nullptr) { + return false; + } + deviceHandle = lv_indev_create(); lv_indev_set_type(deviceHandle, LV_INDEV_TYPE_POINTER); lv_indev_set_driver_data(deviceHandle, this); lv_indev_set_read_cb(deviceHandle, touchReadCallback); - TT_LOG_I(TAG, "start success"); return true; } -bool Ft6x36Touch::stop() { +bool Ft6x36Touch::stopLvgl() { + if (deviceHandle == nullptr) { + return false; + } + lv_indev_delete(deviceHandle); - interruptDriverThread = true; - driverThread.join(); + deviceHandle = nullptr; return true; } - -void Ft6x36Touch::readLast(lv_indev_data_t* data) { - data->point = lastPoint; - data->state = lastState; -} diff --git a/Drivers/FT6x36/Source/Ft6x36Touch.h b/Drivers/FT6x36/Source/Ft6x36Touch.h index 75ef8af1..bcdd9d88 100644 --- a/Drivers/FT6x36/Source/Ft6x36Touch.h +++ b/Drivers/FT6x36/Source/Ft6x36Touch.h @@ -15,41 +15,76 @@ public: Configuration( i2c_port_t port, - gpio_num_t pinInterrupt + gpio_num_t pinInterrupt, + uint16_t width, + uint16_t height ) : port(port), - pinInterrupt(pinInterrupt) + pinInterrupt(pinInterrupt), + width(width), + height(height) {} i2c_port_t port; gpio_num_t pinInterrupt; - }; + uint16_t width; + uint16_t height; +}; private: std::unique_ptr configuration; lv_indev_t* _Nullable deviceHandle = nullptr; FT6X36 driver = FT6X36(configuration->port, configuration->pinInterrupt); - tt::Thread driverThread; + std::shared_ptr driverThread; bool interruptDriverThread = false; tt::Mutex mutex; + std::shared_ptr nativeTouch; lv_point_t lastPoint = { .x = 0, .y = 0 }; lv_indev_state_t lastState = LV_INDEV_STATE_RELEASED; - bool shouldInterruptDriverThread(); + bool shouldInterruptDriverThread() const; + + void driverThreadMain(); + + static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data); public: explicit Ft6x36Touch(std::unique_ptr inConfiguration); - ~Ft6x36Touch() final; + ~Ft6x36Touch() override; - std::string getName() const final { return "FT6x36"; } - std::string getDescription() const final { return "I2C touch driver"; } + std::string getName() const override { return "FT6x36"; } + std::string getDescription() const override { return "FT6x36 I2C touch driver"; } - bool start(lv_display_t* display) override; + bool start() override; bool stop() override; - void readLast(lv_indev_data_t* data); + bool supportsLvgl() const override { return true; } + bool startLvgl(lv_display_t* display) override; + bool stopLvgl() override; + lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; } - void driverThreadMain(); + + class Ft6NativeTouch : public tt::hal::touch::NativeTouch { + public: + const Ft6x36Touch& parent; + Ft6NativeTouch(const Ft6x36Touch& parent) : parent(parent) {} + + bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* _Nullable strength, uint8_t* pointCount, uint8_t maxPointCount) { + auto lock = parent.mutex.asScopedLock(); + lock.lock(); + if (parent.lastState == LV_INDEV_STATE_PRESSED) { + *x = parent.lastPoint.x; + *y = parent.lastPoint.y; + *pointCount = 1; + return true; + } else { + *pointCount = 0; + return false; + } + } + }; + + std::shared_ptr _Nullable getNativeTouch() override { return nativeTouch; } }; diff --git a/Drivers/ST7789/Source/St7789Display.cpp b/Drivers/ST7789/Source/St7789Display.cpp index b3ac49f1..99a00ac2 100644 --- a/Drivers/ST7789/Source/St7789Display.cpp +++ b/Drivers/ST7789/Source/St7789Display.cpp @@ -7,7 +7,7 @@ #include #include -#define TAG "ST7789" +constexpr auto TAG = "ST7789"; bool St7789Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) { TT_LOG_I(TAG, "Starting"); @@ -96,18 +96,11 @@ bool St7789Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc } lvgl_port_display_cfg_t St7789Display::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { - uint32_t buffer_size; - if (configuration->bufferSize == 0) { - buffer_size = configuration->horizontalResolution * configuration->verticalResolution / 10; - } else { - buffer_size = configuration->bufferSize; - } - return lvgl_port_display_cfg_t { .io_handle = ioHandle, .panel_handle = panelHandle, .control_handle = nullptr, - .buffer_size = buffer_size, + .buffer_size = configuration->bufferSize, .double_buffer = false, .trans_size = 0, .hres = configuration->horizontalResolution, diff --git a/Drivers/ST7789/Source/St7789Display.h b/Drivers/ST7789/Source/St7789Display.h index 8a0668bb..b4bdd941 100644 --- a/Drivers/ST7789/Source/St7789Display.h +++ b/Drivers/ST7789/Source/St7789Display.h @@ -40,7 +40,11 @@ public: invertColor(invertColor), bufferSize(bufferSize), touch(std::move(touch)) - {} + { + if (this->bufferSize == 0) { + this->bufferSize = horizontalResolution * verticalResolution / 10; + } + } esp_lcd_spi_bus_handle_t spiBusHandle; gpio_num_t csPin; @@ -63,6 +67,12 @@ private: std::unique_ptr configuration; + bool createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) override; + + bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) override; + + lvgl_port_display_cfg_t getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) override; + public: explicit St7789Display(std::unique_ptr inConfiguration) : configuration(std::move(inConfiguration)) { @@ -70,14 +80,9 @@ public: } std::string getName() const override { return "ST7789"; } + std::string getDescription() const override { return "ST7789 display"; } - bool createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) override; - - bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) override; - - lvgl_port_display_cfg_t getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) override; - std::shared_ptr _Nullable getTouchDevice() override { return configuration->touch; } void setBacklightDuty(uint8_t backlightDuty) override { diff --git a/Drivers/ST7796/CMakeLists.txt b/Drivers/ST7796/CMakeLists.txt index 983cc248..f86c3121 100644 --- a/Drivers/ST7796/CMakeLists.txt +++ b/Drivers/ST7796/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register( SRC_DIRS "Source" INCLUDE_DIRS "Source" - REQUIRES Tactility esp_lvgl_port esp_lcd_st7796 driver + REQUIRES Tactility EspLcdCompat esp_lcd_st7796 driver ) diff --git a/Drivers/ST7796/Source/St7796Display.cpp b/Drivers/ST7796/Source/St7796Display.cpp index 22ae268f..0cf1c4ec 100644 --- a/Drivers/ST7796/Source/St7796Display.cpp +++ b/Drivers/ST7796/Source/St7796Display.cpp @@ -2,16 +2,13 @@ #include -#include #include #include #include -#define TAG "st7796" - -bool St7796Display::start() { - TT_LOG_I(TAG, "Starting"); +constexpr auto TAG = "ST7796"; +bool St7796Display::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) { const esp_lcd_panel_io_spi_config_t panel_io_config = { .cs_gpio_num = configuration->csPin, .dc_gpio_num = configuration->dcPin, @@ -36,11 +33,10 @@ bool St7796Display::start() { } }; - if (esp_lcd_new_panel_io_spi(configuration->spiBusHandle, &panel_io_config, &ioHandle) != ESP_OK) { - TT_LOG_E(TAG, "Failed to create panel"); - return false; - } + return esp_lcd_new_panel_io_spi(configuration->spiBusHandle, &panel_io_config, &ioHandle) == ESP_OK; +} +bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) { static const st7796_lcd_init_cmd_t lcd_init_cmds[] = { {0x01, (uint8_t[]) {0x00}, 0, 120}, {0x11, (uint8_t[]) {0x00}, 0, 120}, @@ -69,7 +65,6 @@ bool St7796Display::start() { .init_cmds_size = sizeof(lcd_init_cmds) / sizeof(st7796_lcd_init_cmd_t), }; - const esp_lcd_panel_dev_config_t panel_config = { .reset_gpio_num = configuration->resetPin, // Set to -1 if not use #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) @@ -92,7 +87,7 @@ bool St7796Display::start() { }, .vendor_config = nullptr }; -*/ + */ if (esp_lcd_new_panel_st7796(ioHandle, &panel_config, &panelHandle) != ESP_OK) { TT_LOG_E(TAG, "Failed to create panel"); return false; @@ -133,18 +128,15 @@ bool St7796Display::start() { return false; } - uint32_t buffer_size; - if (configuration->bufferSize == 0) { - buffer_size = configuration->horizontalResolution * configuration->verticalResolution / 10; - } else { - buffer_size = configuration->bufferSize; - } + return true; +} - const lvgl_port_display_cfg_t disp_cfg = { +lvgl_port_display_cfg_t St7796Display::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { + return { .io_handle = ioHandle, .panel_handle = panelHandle, .control_handle = nullptr, - .buffer_size = buffer_size, + .buffer_size = configuration->bufferSize, .double_buffer = false, .trans_size = 0, .hres = configuration->horizontalResolution, @@ -158,28 +150,6 @@ bool St7796Display::start() { .color_format = LV_COLOR_FORMAT_NATIVE, .flags = {.buff_dma = true, .buff_spiram = false, .sw_rotate = false, .swap_bytes = true, .full_refresh = false, .direct_mode = false} }; - - displayHandle = lvgl_port_add_disp(&disp_cfg); - - TT_LOG_I(TAG, "Finished"); - return displayHandle != nullptr; -} - -bool St7796Display::stop() { - assert(displayHandle != nullptr); - - lvgl_port_remove_disp(displayHandle); - - if (esp_lcd_panel_del(panelHandle) != ESP_OK) { - return false; - } - - if (esp_lcd_panel_io_del(ioHandle) != ESP_OK) { - return false; - } - - displayHandle = nullptr; - return true; } void St7796Display::setGammaCurve(uint8_t index) { @@ -200,6 +170,7 @@ void St7796Display::setGammaCurve(uint8_t index) { default: return; } + const uint8_t param[] = { gamma_curve }; diff --git a/Drivers/ST7796/Source/St7796Display.h b/Drivers/ST7796/Source/St7796Display.h index 3b7bf0a8..8ded6d59 100644 --- a/Drivers/ST7796/Source/St7796Display.h +++ b/Drivers/ST7796/Source/St7796Display.h @@ -1,15 +1,10 @@ #pragma once -#include "Tactility/hal/display/DisplayDevice.h" - +#include #include -#include -#include -#include #include -#include -class St7796Display final : public tt::hal::display::DisplayDevice { +class St7796Display final : public EspLcdDisplay { public: @@ -43,7 +38,11 @@ public: gapX(gapX), gapY(gapY), bufferSize(bufferSize), - touch(std::move(touch)) {} + touch(std::move(touch)) { + if (this->bufferSize == 0) { + this->bufferSize = horizontalResolution * verticalResolution / 10; + } + } esp_lcd_spi_bus_handle_t spiBusHandle; gpio_num_t csPin; @@ -67,9 +66,12 @@ public: private: std::unique_ptr configuration; - esp_lcd_panel_io_handle_t ioHandle = nullptr; - esp_lcd_panel_handle_t panelHandle = nullptr; - lv_display_t* displayHandle = nullptr; + + bool createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) override; + + bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) override; + + lvgl_port_display_cfg_t getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) override; public: @@ -77,27 +79,23 @@ public: assert(configuration != nullptr); } - std::string getName() const final { return "ST7796"; } - std::string getDescription() const final { return "ST7796 display"; } + std::string getName() const override { return "ST7796"; } - bool start() final; + std::string getDescription() const override { return "ST7796 display"; } - bool stop() final; + std::shared_ptr _Nullable getTouchDevice() override { return configuration->touch; } - std::shared_ptr _Nullable createTouch() final { return configuration->touch; } - - void setBacklightDuty(uint8_t backlightDuty) final { + void setBacklightDuty(uint8_t backlightDuty) override { if (configuration->backlightDutyFunction != nullptr) { configuration->backlightDutyFunction(backlightDuty); } } - void setGammaCurve(uint8_t index) final; - uint8_t getGammaCurveCount() const final { return 4; }; + void setGammaCurve(uint8_t index) override; - bool supportsBacklightDuty() const final { return configuration->backlightDutyFunction != nullptr; } + uint8_t getGammaCurveCount() const override { return 4; }; - lv_display_t* _Nullable getLvglDisplay() const final { return displayHandle; } + bool supportsBacklightDuty() const override { return configuration->backlightDutyFunction != nullptr; } }; std::shared_ptr createDisplay();