Compare commits

...

10 Commits

Author SHA1 Message Date
Ken Van Hoeylandt
1dea7fc87d Update device 2025-08-15 22:20:36 +02:00
Ken Van Hoeylandt
773e87dcc9 Update for nullability 2025-08-15 22:20:33 +02:00
Ken Van Hoeylandt
a30de954ae Update RgbDisplay driver 2025-08-15 22:20:27 +02:00
Ken Van Hoeylandt
08b6e709d5 Updated boards & drivers 2025-08-15 21:35:27 +02:00
Ken Van Hoeylandt
0279568c68 Fix for native touch 2025-08-15 18:54:20 +02:00
Ken Van Hoeylandt
4509e693da Native touch driver 2025-08-15 18:33:06 +02:00
Ken Van Hoeylandt
7de3b871c6 Simplify NativeDisplay interface 2025-08-15 17:10:23 +02:00
Ken Van Hoeylandt
e1bd49cbc0 Fix for icon registration leak 2025-08-15 17:10:13 +02:00
Ken Van Hoeylandt
e28be828da LVGL init improved, add start/stop mechanism. Improved system events for LVGL. 2025-08-15 16:45:39 +02:00
Ken Van Hoeylandt
0807b09890 Various graphics and touch driver improvements 2025-08-15 15:25:27 +02:00
57 changed files with 880 additions and 601 deletions

View File

@ -9,7 +9,7 @@ dependencies:
espressif/esp_io_expander: "1.0.1"
espressif/esp_io_expander_tca95xx_16bit: "1.0.1"
espressif/esp_lcd_st7701:
version: "1.1.1"
version: "1.1.3"
rules:
- if: "target in [esp32s3, esp32p4]"
espressif/esp_lcd_st7796:

View File

@ -32,5 +32,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->mirrorX = true;
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
return std::make_shared<Ili934xDisplay>(std::move(configuration));
auto display = std::make_shared<Ili934xDisplay>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -14,7 +14,7 @@ bool initBoot() {
// This display has a weird glitch with gamma during boot, which results in uneven dark gray colours.
// Setting gamma curve index to 0 doesn't work at boot for an unknown reason, so we set the curve index to 1:
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootInitLvglEnd, [](auto event) {
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](auto) {
auto display = tt::hal::findFirstDevice<tt::hal::display::DisplayDevice>(tt::hal::Device::Type::Display);
assert(display != nullptr);
tt::lvgl::lock(portMAX_DELAY);

View File

@ -35,5 +35,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
return std::make_shared<Ili934xDisplay>(std::move(configuration));
auto display = std::make_shared<Ili934xDisplay>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -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 esp_lcd_st7701 esp_lcd_panel_io_additions GT911 PwmBacklight driver vfs fatfs
REQUIRES Tactility EspLcdCompat esp_lcd_st7701 esp_lcd_panel_io_additions GT911 PwmBacklight driver vfs fatfs
)

View File

@ -1,19 +1,17 @@
#include "CydDisplay.h"
#include "PwmBacklight.h"
#include <Gt911Touch.h>
#include <PwmBacklight.h>
#include <Tactility/Log.h>
#include <driver/gpio.h>
#include <esp_err.h>
#include <esp_lcd_panel_rgb.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lcd_panel_io.h>
#include <esp_lcd_panel_io_additions.h>
#include <esp_lcd_st7701.h>
#include <esp_lvgl_port.h>
#define TAG "cyd_display"
constexpr auto TAG = "ST7701";
static const st7701_lcd_init_cmd_t st7701_lcd_init_cmds[] = {
// {cmd, { data }, data_size, delay_ms}
@ -58,9 +56,7 @@ static const st7701_lcd_init_cmd_t st7701_lcd_init_cmds[] = {
{0x29, (uint8_t[]) {0x00}, 0, 0}, //Display On
};
bool CydDisplay::start() {
TT_LOG_I(TAG, "Starting");
bool CydDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
spi_line_config_t line_config = {
.cs_io_type = IO_TYPE_GPIO,
.cs_gpio_num = GPIO_NUM_39,
@ -68,11 +64,13 @@ bool CydDisplay::start() {
.scl_gpio_num = GPIO_NUM_48,
.sda_io_type = IO_TYPE_GPIO,
.sda_gpio_num = GPIO_NUM_47,
.io_expander = NULL,
.io_expander = nullptr,
};
esp_lcd_panel_io_3wire_spi_config_t panel_io_config = ST7701_PANEL_IO_3WIRE_SPI_CONFIG(line_config, 0);
ESP_ERROR_CHECK(esp_lcd_new_panel_io_3wire_spi(&panel_io_config, &ioHandle));
return esp_lcd_new_panel_io_3wire_spi(&panel_io_config, &outHandle) == ESP_OK;
}
bool CydDisplay::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) {
const esp_lcd_rgb_panel_config_t rgb_config = {
.clk_src = LCD_CLK_SRC_DEFAULT,
.timings = {
@ -179,7 +177,11 @@ bool CydDisplay::start() {
TT_LOG_E(TAG, "Failed to turn display on");
}
const lvgl_port_display_cfg_t disp_cfg = {
return true;
}
lvgl_port_display_cfg_t CydDisplay::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) {
return {
.io_handle = ioHandle,
.panel_handle = panelHandle,
.control_handle = nullptr,
@ -204,44 +206,29 @@ bool CydDisplay::start() {
.direct_mode = false
}
};
}
const lvgl_port_display_rgb_cfg_t rgb_cfg = {
lvgl_port_display_rgb_cfg_t CydDisplay::getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) {
return {
.flags = {
.bb_mode = true,
.avoid_tearing = false
}
};
displayHandle = lvgl_port_add_disp_rgb(&disp_cfg, &rgb_cfg);
TT_LOG_I(TAG, "Finished");
return displayHandle != nullptr;
}
bool CydDisplay::stop() {
assert(displayHandle != nullptr);
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable CydDisplay::getTouchDevice() {
if (touchDevice == nullptr) {
auto configuration = std::make_unique<Gt911Touch::Configuration>(
I2C_NUM_0,
480,
480
);
lvgl_port_remove_disp(displayHandle);
if (esp_lcd_panel_del(panelHandle) != ESP_OK) {
return false;
touchDevice = std::make_shared<Gt911Touch>(std::move(configuration));
}
if (esp_lcd_panel_io_del(ioHandle) != ESP_OK) {
return false;
}
displayHandle = nullptr;
return true;
}
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable CydDisplay::createTouch() {
auto configuration = std::make_unique<Gt911Touch::Configuration>(
I2C_NUM_0,
480,
480
);
return std::make_shared<Gt911Touch>(std::move(configuration));
return touchDevice;
}
void CydDisplay::setBacklightDuty(uint8_t backlightDuty) {
@ -249,5 +236,6 @@ void CydDisplay::setBacklightDuty(uint8_t backlightDuty) {
}
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
return std::make_shared<CydDisplay>();
auto display = std::make_shared<CydDisplay>();
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -1,32 +1,33 @@
#pragma once
#include "Tactility/hal/display/DisplayDevice.h"
#include <esp_lcd_types.h>
#include <EspLcdDisplay.h>
#include <lvgl.h>
class CydDisplay : public tt::hal::display::DisplayDevice {
class CydDisplay final : public EspLcdDisplay {
private:
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable touchDevice;
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& outHandle) 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;
bool isRgbPanel() const override { return true; }
lvgl_port_display_rgb_cfg_t getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) override;
public:
std::string getName() const final { return "ST7701S"; }
std::string getDescription() const final { return "RGB Display"; }
std::string getName() const override { return "ST7701S"; }
bool start() override;
std::string getDescription() const override { return "ST7701S RGB display"; }
bool stop() override;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable createTouch() override;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override;
void setBacklightDuty(uint8_t backlightDuty) override;
bool supportsBacklightDuty() const override { return true; }
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
bool supportsBacklightDuty() const override { return true; }
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -34,5 +34,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
return std::make_shared<St7789Display>(std::move(configuration));
auto display = std::make_shared<St7789Display>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -161,7 +161,7 @@ void TpagerKeyboard::processKeyboard() {
}
}
bool TpagerKeyboard::start(lv_display_t* display) {
bool TpagerKeyboard::startLvgl(lv_display_t* display) {
backlightOkay = initBacklight(BACKLIGHT, 30000, LEDC_TIMER_0, LEDC_CHANNEL_1);
initEncoder();
keypad->init(KB_ROWS, KB_COLS);
@ -195,7 +195,7 @@ bool TpagerKeyboard::start(lv_display_t* display) {
return true;
}
bool TpagerKeyboard::stop() {
bool TpagerKeyboard::stopLvgl() {
assert(inputTimer);
inputTimer->stop();
inputTimer = nullptr;

View File

@ -41,8 +41,8 @@ public:
std::string getName() const final { return "T-Lora Pager Keyboard"; }
std::string getDescription() const final { return "I2C keyboard with encoder"; }
bool start(lv_display_t* display) override;
bool stop() override;
bool startLvgl(lv_display_t* display) override;
bool stopLvgl() override;
bool isAttached() const override;
lv_indev_t* _Nullable getLvglIndev() override { return kbHandle; }

View File

@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility EspLcdNativeDisplay esp_lvgl_port esp_lcd ST7789 GT911 PwmBacklight driver esp_adc
REQUIRES Tactility EspLcdCompat ST7789 GT911 PwmBacklight driver esp_adc
)

View File

@ -41,5 +41,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
return std::make_shared<St7789Display>(std::move(configuration));
auto display = std::make_shared<St7789Display>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -1,40 +1,5 @@
#pragma once
#include "Tactility/hal/display/DisplayDevice.h"
#include <esp_lcd_types.h>
#include <lvgl.h>
class TdeckDisplay : 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<tt::hal::touch::TouchDevice> _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; }
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -7,7 +7,7 @@
#define TDECK_KEYBOARD_I2C_BUS_HANDLE I2C_NUM_0
#define TDECK_KEYBOARD_SLAVE_ADDRESS 0x55
static inline bool keyboard_i2c_read(uint8_t* output) {
static bool keyboard_i2c_read(uint8_t* output) {
return tt::hal::i2c::masterRead(TDECK_KEYBOARD_I2C_BUS_HANDLE, TDECK_KEYBOARD_SLAVE_ADDRESS, output, 1, 100 / portTICK_PERIOD_MS);
}
@ -43,7 +43,7 @@ static void keyboard_read_callback(TT_UNUSED lv_indev_t* indev, lv_indev_data_t*
last_buffer = read_buffer;
}
bool TdeckKeyboard::start(lv_display_t* display) {
bool TdeckKeyboard::startLvgl(lv_display_t* display) {
deviceHandle = lv_indev_create();
lv_indev_set_type(deviceHandle, LV_INDEV_TYPE_KEYPAD);
lv_indev_set_read_cb(deviceHandle, &keyboard_read_callback);
@ -52,7 +52,7 @@ bool TdeckKeyboard::start(lv_display_t* display) {
return true;
}
bool TdeckKeyboard::stop() {
bool TdeckKeyboard::stopLvgl() {
lv_indev_delete(deviceHandle);
deviceHandle = nullptr;
return true;

View File

@ -5,19 +5,17 @@
#include <esp_lcd_panel_io_interface.h>
#include <esp_lcd_touch.h>
class TdeckKeyboard : public tt::hal::keyboard::KeyboardDevice {
private:
class TdeckKeyboard final : public tt::hal::keyboard::KeyboardDevice {
lv_indev_t* _Nullable deviceHandle = nullptr;
public:
std::string getName() const final { return "T-Deck Keyboard"; }
std::string getDescription() const final { return "I2C keyboard"; }
std::string getName() const override { return "T-Deck Keyboard"; }
std::string getDescription() const override { return "I2C keyboard"; }
bool start(lv_display_t* display) override;
bool stop() override;
bool startLvgl(lv_display_t* display) override;
bool stopLvgl() override;
bool isAttached() const override;
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
};

View File

@ -4,6 +4,9 @@
#include "Tactility/hal/display/DisplayDevice.h"
#include <memory>
#include
#include
/** Hack: variable comes from LvglTask.cpp */
extern lv_disp_t* displayHandle;

View File

@ -4,20 +4,20 @@
#include <Tactility/TactilityCore.h>
class SdlKeyboard final : public tt::hal::keyboard::KeyboardDevice {
private:
lv_indev_t* _Nullable handle = nullptr;
public:
std::string getName() const final { return "SDL Keyboard"; }
std::string getDescription() const final { return "SDL keyboard device"; }
std::string getName() const override { return "SDL Keyboard"; }
std::string getDescription() const override { return "SDL keyboard device"; }
bool start(lv_display_t* display) override {
bool startLvgl(lv_display_t* display) override {
handle = lv_sdl_keyboard_create();
return handle != nullptr;
}
bool stop() override { tt_crash("Not supported"); }
bool stopLvgl() override { tt_crash("Not supported"); }
bool isAttached() const override { return true; }

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd_touch esp_lcd_touch_cst816s driver
REQUIRES Tactility EspLcdCompat esp_lcd_touch_cst816s driver
)

View File

@ -1,9 +1,8 @@
#pragma once
#include <Tactility/hal/touch/TouchDevice.h>
#include <esp_lcd_touch.h>
#include <EspLcdTouch.h>
class Cst816sTouch final : public tt::hal::touch::TouchDevice {
class Cst816sTouch final : public EspLcdTouch {
public:
@ -54,16 +53,18 @@ private:
void cleanup();
bool createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) override;
bool createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& configuration, esp_lcd_touch_handle_t& touchHandle) override;
esp_lcd_touch_config_t createEspLcdTouchConfig() override;
public:
explicit Cst816sTouch(std::unique_ptr<Configuration> inConfiguration) : configuration(std::move(inConfiguration)) {
assert(configuration != nullptr);
}
std::string getName() const final { return "CST816S"; }
std::string getDescription() const final { return "I2C touch driver"; }
bool start(lv_display_t* display) override;
bool stop() override;
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
std::string getName() const override { return "CST816S"; }
std::string getDescription() const override { return "CST816S I2C touch driver"; }
};

View File

@ -1,25 +1,18 @@
#include "Cst816Touch.h"
#include <Tactility/Log.h>
#include <driver/i2c.h>
#include <esp_err.h>
#include <esp_lcd_touch.h>
#include <esp_lcd_touch_cst816s.h>
#include <esp_lvgl_port.h>
#define TAG "cst816s"
bool Cst816sTouch::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) {
constexpr esp_lcd_panel_io_i2c_config_t touch_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();
return esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)configuration->port, &touch_io_config, &ioHandle) == ESP_OK;
}
bool Cst816sTouch::start(lv_display_t* display) {
TT_LOG_I(TAG, "Starting");
const esp_lcd_panel_io_i2c_config_t touch_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();
bool Cst816sTouch::createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& touchConfiguration, esp_lcd_touch_handle_t& touchHandle) {
return esp_lcd_touch_new_i2c_cst816s(ioHandle, &touchConfiguration, &touchHandle) == ESP_OK;
}
if (esp_lcd_new_panel_io_i2c((esp_lcd_i2c_bus_handle_t)configuration->port, &touch_io_config, &ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Touch I2C IO init failed");
return false;
}
esp_lcd_touch_config_t config = {
esp_lcd_touch_config_t Cst816sTouch::createEspLcdTouchConfig() {
return {
.x_max = configuration->xMax,
.y_max = configuration->yMax,
.rst_gpio_num = configuration->pinReset,
@ -38,47 +31,4 @@ bool Cst816sTouch::start(lv_display_t* display) {
.user_data = nullptr,
.driver_data = nullptr
};
if (esp_lcd_touch_new_i2c_cst816s(ioHandle, &config, &touchHandle) != ESP_OK) {
TT_LOG_E(TAG, "Driver init failed");
cleanup();
return false;
}
const lvgl_port_touch_cfg_t touch_cfg = {
.disp = display,
.handle = touchHandle,
};
deviceHandle = lvgl_port_add_touch(&touch_cfg);
if (deviceHandle == nullptr) {
TT_LOG_E(TAG, "Adding touch failed");
cleanup();
return false;
}
TT_LOG_I(TAG, "Finished");
return true;
}
bool Cst816sTouch::stop() {
cleanup();
return true;
}
void Cst816sTouch::cleanup() {
if (deviceHandle != nullptr) {
lv_indev_delete(deviceHandle);
deviceHandle = nullptr;
}
if (touchHandle != nullptr) {
esp_lcd_touch_del(touchHandle);
touchHandle = nullptr;
}
if (ioHandle != nullptr) {
esp_lcd_panel_io_del(ioHandle);
ioHandle = nullptr;
}
}

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lcd
REQUIRES Tactility esp_lcd esp_lcd_touch esp_lvgl_port
)

View File

@ -0,0 +1,3 @@
# EspLcdCompat
A set of helper classes to implement `esp_lcd` drivers in Tactility.

View File

@ -0,0 +1,102 @@
#include "EspLcdDisplay.h"
#include "EspLcdNativeDisplay.h"
#include <assert.h>
#include <esp_lvgl_port_disp.h>
#include <Tactility/Check.h>
#include <Tactility/LogEsp.h>
#include <Tactility/hal/touch/TouchDevice.h>
constexpr const char* TAG = "EspLcdDisplay";
EspLcdDisplay::~EspLcdDisplay() {
if (nativeDisplay != nullptr && nativeDisplay.use_count() > 1) {
tt_crash("NativeDisplay is still in use. This will cause memory access violations.");
}
}
bool EspLcdDisplay::start() {
if (!createIoHandle(ioHandle)) {
TT_LOG_E(TAG, "Failed to create IO handle");
return false;
}
if (!createPanelHandle(ioHandle, panelHandle)) {
TT_LOG_E(TAG, "Failed to create panel handle");
esp_lcd_panel_io_del(ioHandle);
return false;
}
return true;
}
bool EspLcdDisplay::stop() {
if (lvglDisplay != nullptr) {
stopLvgl();
lvglDisplay = nullptr;
}
if (panelHandle != nullptr && esp_lcd_panel_del(panelHandle) != ESP_OK) {
return false;
}
if (ioHandle != nullptr && esp_lcd_panel_io_del(ioHandle) != ESP_OK) {
return false;
}
if (nativeDisplay != nullptr && nativeDisplay.use_count() > 1) {
TT_LOG_W(TAG, "NativeDisplay is still in use.");
}
return true;
}
bool EspLcdDisplay::startLvgl() {
assert(lvglDisplay == nullptr);
if (nativeDisplay != nullptr && nativeDisplay.use_count() > 1) {
TT_LOG_W(TAG, "NativeDisplay is still in use.");
}
lvglPortDisplayConfig = getLvglPortDisplayConfig(ioHandle, panelHandle);
if (isRgbPanel()) {
auto rgb_config = getLvglPortDisplayRgbConfig(ioHandle, panelHandle);
lvglDisplay = lvgl_port_add_disp_rgb(&lvglPortDisplayConfig, &rgb_config);
} else {
lvglDisplay = lvgl_port_add_disp(&lvglPortDisplayConfig);
}
auto touch_device = getTouchDevice();
if (touch_device != nullptr) {
touch_device->startLvgl(lvglDisplay);
}
return lvglDisplay != nullptr;
}
bool EspLcdDisplay::stopLvgl() {
if (lvglDisplay == nullptr) {
return false;
}
auto touch_device = getTouchDevice();
if (touch_device != nullptr) {
touch_device->stopLvgl();
}
lvgl_port_remove_disp(lvglDisplay);
lvglDisplay = nullptr;
return true;
}
std::shared_ptr<display::NativeDisplay> EspLcdDisplay::getNativeDisplay() {
assert(lvglDisplay == nullptr); // Still attached to LVGL context. Call stopLvgl() first.
if (nativeDisplay == nullptr) {
nativeDisplay = std::make_shared<EspLcdNativeDisplay>(
panelHandle,
lvglPortDisplayConfig
);
}
return nativeDisplay;
}

View File

@ -0,0 +1,59 @@
#pragma once
#include <Tactility/hal/display/DisplayDevice.h>
#include <esp_lcd_types.h>
#include <esp_lvgl_port_disp.h>
#include <Tactility/Check.h>
#include <Tactility/hal/display/NativeDisplay.h>
class EspLcdDisplay : tt::hal::display::DisplayDevice {
esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
esp_lcd_panel_handle_t _Nullable panelHandle = nullptr;
lv_display_t* _Nullable lvglDisplay = nullptr;
lvgl_port_display_cfg_t _Nullable lvglPortDisplayConfig;
std::shared_ptr<tt::hal::display::NativeDisplay> _Nullable nativeDisplay;
protected:
// Used for sending commands such as setting curves
esp_lcd_panel_io_handle_t getIoHandle() const { return ioHandle; }
virtual bool createIoHandle(esp_lcd_panel_io_handle_t& outHandle) = 0;
virtual bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) = 0;
virtual lvgl_port_display_cfg_t getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) = 0;
virtual bool isRgbPanel() const { return false; }
virtual lvgl_port_display_rgb_cfg_t getLvglPortDisplayRgbConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) { tt_crash("Not supported"); }
public:
~EspLcdDisplay() override;
bool start() final;
bool stop() final;
// region LVGL
bool supportsLvgl() const final { return true; }
bool startLvgl() final;
bool stopLvgl() final;
lv_display_t* _Nullable getLvglDisplay() const final { return lvglDisplay; }
// endregion
// region NativedDisplay
/** @return a NativeDisplay instance if this device supports it */
std::shared_ptr<tt::hal::display::NativeDisplay> _Nullable getNativeDisplay() final;
// endregion
};

View File

@ -0,0 +1,42 @@
#pragma once
#include <Tactility/hal/display/NativeDisplay.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lvgl_port_disp.h>
using namespace tt::hal;
class EspLcdNativeDisplay final : public display::NativeDisplay {
esp_lcd_panel_handle_t panelHandle;
const lvgl_port_display_cfg_t& lvglPortDisplayConfig;
public:
EspLcdNativeDisplay(
esp_lcd_panel_handle_t panelHandle,
const lvgl_port_display_cfg_t& lvglPortDisplayConfig
) : panelHandle(panelHandle), lvglPortDisplayConfig(lvglPortDisplayConfig) {}
display::ColorFormat getColorFormat() const override {
using display::ColorFormat;
switch (lvglPortDisplayConfig.color_format) {
case LV_COLOR_FORMAT_I1:
return ColorFormat::Monochrome;
case LV_COLOR_FORMAT_RGB565:
// swap_bytes is only used for the 565 color format
// see lvgl_port_flush_callback() in esp_lvgl_port_disp.c
return lvglPortDisplayConfig.flags.swap_bytes ? ColorFormat::BGR565 : ColorFormat::RGB565;
case LV_COLOR_FORMAT_RGB888:
return ColorFormat::RGB888;
default:
return ColorFormat::RGB565;
}
}
bool drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) override {
return esp_lcd_panel_draw_bitmap(panelHandle, xStart, yStart, xEnd, yEnd, pixelData) == ESP_OK;
}
uint16_t getPixelWidth() const override { return lvglPortDisplayConfig.hres; }
uint16_t getPixelHeight() const override { return lvglPortDisplayConfig.vres; }
};

View File

@ -0,0 +1,13 @@
#include "EspLcdNativeTouch.h"
#include <Tactility/LogEsp.h>
constexpr const char* TAG = "EspLcdNativeTouch";
bool EspLcdNativeTouch::getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* _Nullable strength, uint8_t* pointCount, uint8_t maxPointCount) {
if (esp_lcd_touch_read_data(handle) != ESP_OK) {
TT_LOG_E(TAG, "Read data failed");
return false;
}
return esp_lcd_touch_get_coordinates(handle, x, y, strength, pointCount, maxPointCount) == ESP_OK;
}

View File

@ -0,0 +1,15 @@
#pragma once
#include <esp_lcd_touch.h>
#include <Tactility/hal/touch/NativeTouch.h>
class EspLcdNativeTouch final : public tt::hal::touch::NativeTouch {
esp_lcd_touch_handle_t handle;
public:
EspLcdNativeTouch(esp_lcd_touch_handle_t handle) : handle(handle) {}
bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* strength, uint8_t* pointCount, uint8_t maxPointCount) override;
};

View File

@ -0,0 +1,86 @@
#include "EspLcdTouch.h"
#include <EspLcdNativeTouch.h>
#include <esp_lvgl_port_touch.h>
#include <Tactility/LogEsp.h>
constexpr const char* TAG = "EspLcdTouch";
bool EspLcdTouch::start() {
if (!createIoHandle(ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Touch IO failed");
return false;
}
config = createEspLcdTouchConfig();
if (!createTouchHandle(ioHandle, config, touchHandle)) {
TT_LOG_E(TAG, "Driver init failed");
esp_lcd_panel_io_del(ioHandle);
ioHandle = nullptr;
return false;
}
return true;
}
bool EspLcdTouch::stop() {
if (lvglDevice != nullptr) {
stopLvgl();
}
if (ioHandle != nullptr) {
esp_lcd_panel_io_del(ioHandle);
ioHandle = nullptr;
}
if (touchHandle != nullptr) {
esp_lcd_touch_del(touchHandle);
touchHandle = nullptr;
}
return true;
}
bool EspLcdTouch::startLvgl(lv_disp_t* display) {
if (lvglDevice != nullptr) {
return false;
}
if (nativeTouch != nullptr && nativeTouch.use_count() > 1) {
TT_LOG_W(TAG, "NativeTouch is still in use.");
}
const lvgl_port_touch_cfg_t touch_cfg = {
.disp = display,
.handle = touchHandle,
};
TT_LOG_I(TAG, "Adding touch to LVGL");
lvglDevice = lvgl_port_add_touch(&touch_cfg);
if (lvglDevice == nullptr) {
TT_LOG_E(TAG, "Adding touch failed");
return false;
}
return true;
}
bool EspLcdTouch::stopLvgl() {
if (lvglDevice == nullptr) {
return false;
}
lvgl_port_remove_touch(lvglDevice);
lvglDevice = nullptr;
return true;
}
std::shared_ptr<tt::hal::touch::NativeTouch> _Nullable EspLcdTouch::getNativeTouch() {
assert(lvglDevice == nullptr); // Still attached to LVGL context. Call stopLvgl() first.
if (nativeTouch == nullptr) {
nativeTouch = std::make_shared<EspLcdNativeTouch>(touchHandle);
}
return nativeTouch;
}

View File

@ -0,0 +1,39 @@
#pragma once
#include <esp_lcd_touch.h>
#include <esp_lcd_types.h>
#include <lvgl.h>
#include <Tactility/hal/touch/TouchDevice.h>
class EspLcdTouch : public tt::hal::touch::TouchDevice {
esp_lcd_touch_config_t config;
esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
esp_lcd_touch_handle_t _Nullable touchHandle = nullptr;
lv_indev_t* _Nullable lvglDevice = nullptr;
std::shared_ptr<tt::hal::touch::NativeTouch> nativeTouch;
protected:
virtual bool createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) = 0;
virtual bool createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& configuration, esp_lcd_touch_handle_t& touchHandle) = 0;
virtual esp_lcd_touch_config_t createEspLcdTouchConfig() = 0;
public:
bool start() final;
bool stop() final;
bool supportsLvgl() const final { return true; }
bool startLvgl(lv_display_t* display) final;
bool stopLvgl() final;
lv_indev_t* _Nullable getLvglIndev() final { return lvglDevice; }
std::shared_ptr<tt::hal::touch::NativeTouch> _Nullable getNativeTouch() final;
};

View File

@ -1,3 +0,0 @@
# EspLcdNativeDisplay
An implementation of `tt::hal::display::NativeDisplay` for display drivers that are built around the `esp_lcd` library.

View File

@ -1,33 +0,0 @@
#pragma once
#include <Tactility/hal/display/NativeDisplay.h>
#include <esp_lcd_panel_ops.h>
namespace tt::hal::display {
class EspLcdNativeDisplay final : public NativeDisplay {
esp_lcd_panel_handle_t panelHandle;
ColorFormat colorFormat;
uint16_t pixelWidth;
uint16_t pixelHeight;
public:
EspLcdNativeDisplay(
esp_lcd_panel_handle_t panelHandle,
ColorFormat colorFormat,
uint16_t pixelWidth,
uint16_t pixelHeight
) : panelHandle(panelHandle), colorFormat(colorFormat), pixelWidth(pixelWidth), pixelHeight(pixelHeight) {}
ColorFormat getColorFormat() const override { return colorFormat; }
bool drawBitmap(int xStart, int yStart, int xEnd, int yEnd, const void* pixelData) override {
return esp_lcd_panel_draw_bitmap(panelHandle, xStart, yStart, xEnd, yEnd, pixelData) == ESP_OK;
}
uint16_t getPixelWidth() const override { return pixelWidth; }
uint16_t getPixelHeight() const override { return pixelHeight; }
};
}

View File

@ -5,11 +5,10 @@
#include <esp_lcd_touch_gt911.h>
#include <esp_err.h>
#include <esp_lvgl_port.h>
#define TAG "GT911"
bool Gt911Touch::start(lv_display_t* display) {
bool Gt911Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG();
/**
@ -26,12 +25,15 @@ bool Gt911Touch::start(lv_display_t* display) {
return false;
}
if (esp_lcd_new_panel_io_i2c(configuration->port, &io_config, &ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Touch IO I2C creation failed");
return false;
}
return esp_lcd_new_panel_io_i2c(configuration->port, &io_config, &outHandle) == ESP_OK;
}
esp_lcd_touch_config_t config = {
bool Gt911Touch::createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& configuration, esp_lcd_touch_handle_t& panelHandle) {
return esp_lcd_touch_new_i2c_gt911(ioHandle, &configuration, &panelHandle) == ESP_OK;
}
esp_lcd_touch_config_t Gt911Touch::createEspLcdTouchConfig() {
return {
.x_max = configuration->xMax,
.y_max = configuration->yMax,
.rst_gpio_num = configuration->pinReset,
@ -50,43 +52,4 @@ bool Gt911Touch::start(lv_display_t* display) {
.user_data = nullptr,
.driver_data = nullptr
};
if (esp_lcd_touch_new_i2c_gt911(ioHandle, &config, &touchHandle) != ESP_OK) {
TT_LOG_E(TAG, "Driver init failed");
cleanup();
return false;
}
const lvgl_port_touch_cfg_t touch_cfg = {
.disp = display,
.handle = touchHandle,
};
TT_LOG_I(TAG, "Adding touch to LVGL");
deviceHandle = lvgl_port_add_touch(&touch_cfg);
if (deviceHandle == nullptr) {
TT_LOG_E(TAG, "Adding touch failed");
cleanup();
return false;
}
return true;
}
bool Gt911Touch::stop() {
cleanup();
return true;
}
void Gt911Touch::cleanup() {
if (deviceHandle != nullptr) {
lv_indev_delete(deviceHandle);
deviceHandle = nullptr;
touchHandle = nullptr;
}
if (ioHandle != nullptr) {
esp_lcd_panel_io_del(ioHandle);
ioHandle = nullptr;
}
}

View File

@ -4,10 +4,11 @@
#include <Tactility/TactilityCore.h>
#include <driver/i2c.h>
#include <esp_lcd_panel_io_interface.h>
#include <esp_lcd_touch.h>
class Gt911Touch final : public tt::hal::touch::TouchDevice {
#include "../../EspLcdCompat/Source/EspLcdTouch.h"
class Gt911Touch final : public EspLcdTouch {
public:
@ -52,11 +53,12 @@ public:
private:
std::unique_ptr<Configuration> configuration;
esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
esp_lcd_touch_handle_t _Nullable touchHandle = nullptr;
lv_indev_t* _Nullable deviceHandle = nullptr;
void cleanup();
bool createIoHandle(esp_lcd_panel_io_handle_t& outHandle) override;
bool createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& configuration, esp_lcd_touch_handle_t& panelHandle) override;
esp_lcd_touch_config_t createEspLcdTouchConfig();
public:
@ -64,10 +66,7 @@ public:
assert(configuration != nullptr);
}
bool start(lv_display_t* display) override;
bool stop() override;
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
std::string getName() const override { return "GT911"; }
std::string getName() const final { return "GT911"; }
std::string getDescription() const final { return "I2C Touch Driver"; }
std::string getDescription() const override { return "GT911 I2C touch driver"; }
};

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9341 driver
REQUIRES Tactility EspLcdCompat esp_lcd_ili9341 driver
)

View File

@ -6,11 +6,9 @@
#include <esp_lcd_panel_commands.h>
#include <esp_lvgl_port.h>
#define TAG "ili934x"
bool Ili934xDisplay::start() {
TT_LOG_I(TAG, "Starting");
constexpr const char* TAG = "ILI934x";
bool Ili934xDisplay::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
const esp_lcd_panel_io_spi_config_t panel_io_config = {
.cs_gpio_num = configuration->csPin,
.dc_gpio_num = configuration->dcPin,
@ -35,11 +33,10 @@ bool Ili934xDisplay::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, &outHandle) == ESP_OK;
}
bool Ili934xDisplay::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) {
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = configuration->resetPin,
.rgb_ele_order = configuration->rgbElementOrder,
@ -86,18 +83,15 @@ bool Ili934xDisplay::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 Ili934xDisplay::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,
@ -118,28 +112,6 @@ bool Ili934xDisplay::start() {
.direct_mode = false
}
};
displayHandle = lvgl_port_add_disp(&disp_cfg);
TT_LOG_I(TAG, "Finished");
return displayHandle != nullptr;
}
bool Ili934xDisplay::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;
}
/**
@ -174,7 +146,7 @@ void Ili934xDisplay::setGammaCurve(uint8_t index) {
gamma_curve
};
if (esp_lcd_panel_io_tx_param(ioHandle , LCD_CMD_GAMSET, param, 1) != ESP_OK) {
if (esp_lcd_panel_io_tx_param(getIoHandle() , LCD_CMD_GAMSET, param, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set gamma");
}
}

View File

@ -9,7 +9,9 @@
#include <functional>
#include <lvgl.h>
class Ili934xDisplay final : public tt::hal::display::DisplayDevice {
#include <EspLcdDisplay.h>
class Ili934xDisplay final : public EspLcdDisplay {
public:
@ -41,8 +43,12 @@ public:
invertColor(invertColor),
bufferSize(bufferSize),
rgbElementOrder(rgbElementOrder),
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;
@ -65,9 +71,12 @@ public:
private:
std::unique_ptr<Configuration> 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& outHandle);
bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle);
lvgl_port_display_cfg_t getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle);
public:
@ -75,25 +84,21 @@ public:
assert(configuration != nullptr);
}
std::string getName() const final { return "ILI934x"; }
std::string getDescription() const final { return "ILI934x display"; }
std::string getName() const override { return "ILI934x"; }
bool start() final;
std::string getDescription() const override { return "ILI934x display"; }
bool stop() final;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return configuration->touch; }
std::shared_ptr<tt::hal::touch::TouchDevice> _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);
}
}
bool supportsBacklightDuty() const final { return configuration->backlightDutyFunction != nullptr; }
bool supportsBacklightDuty() const override { return configuration->backlightDutyFunction != nullptr; }
void setGammaCurve(uint8_t index) final;
uint8_t getGammaCurveCount() const final { return 4; };
void setGammaCurve(uint8_t index) override;
lv_display_t* _Nullable getLvglDisplay() const final { return displayHandle; }
uint8_t getGammaCurveCount() const override { return 4; };
};

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd
REQUIRES Tactility EspLcdCompat
)

View File

@ -6,8 +6,16 @@
#include <esp_lcd_panel_rgb.h>
#include <esp_lcd_panel_ops.h>
#include <esp_lvgl_port.h>
#include <Tactility/Check.h>
#include <Tactility/hal/touch/TouchDevice.h>
#define TAG "RgbDisplay"
constexpr auto TAG = "RgbDisplay";
RgbDisplay::~RgbDisplay() {
if (nativeDisplay != nullptr && nativeDisplay.use_count() > 1) {
tt_crash("NativeDisplay is still in use. This will cause memory access violations.");
}
}
bool RgbDisplay::start() {
TT_LOG_I(TAG, "Starting");
@ -42,25 +50,47 @@ bool RgbDisplay::start() {
return false;
}
auto horizontal_resolution = configuration->panelConfig.timings.h_res;
auto vertical_resolution = configuration->panelConfig.timings.v_res;
return true;
}
uint32_t buffer_size;
if (configuration->bufferConfiguration.size == 0) {
buffer_size = horizontal_resolution * vertical_resolution / 15;
} else {
buffer_size = configuration->bufferConfiguration.size;
bool RgbDisplay::stop() {
if (lvglDisplay != nullptr) {
stopLvgl();
lvglDisplay = nullptr;
}
if (panelHandle != nullptr && esp_lcd_panel_del(panelHandle) != ESP_OK) {
return false;
}
if (ioHandle != nullptr && esp_lcd_panel_io_del(ioHandle) != ESP_OK) {
return false;
}
if (nativeDisplay != nullptr && nativeDisplay.use_count() > 1) {
TT_LOG_W(TAG, "NativeDisplay is still in use.");
}
return true;
}
bool RgbDisplay::startLvgl() {
assert(lvglDisplay == nullptr);
if (nativeDisplay != nullptr && nativeDisplay.use_count() > 1) {
TT_LOG_W(TAG, "NativeDisplay is still in use.");
}
const lvgl_port_display_cfg_t display_config = {
.io_handle = ioHandle,
.panel_handle = panelHandle,
.control_handle = nullptr,
.buffer_size = buffer_size,
.buffer_size = configuration->bufferConfiguration.size,
.double_buffer = configuration->bufferConfiguration.doubleBuffer,
.trans_size = 0,
.hres = horizontal_resolution,
.vres = vertical_resolution,
.hres = configuration->panelConfig.timings.h_res,
.vres = configuration->panelConfig.timings.v_res,
.monochrome = false,
.rotation = {
.swap_xy = configuration->swapXY,
@ -85,25 +115,28 @@ bool RgbDisplay::start() {
}
};
displayHandle = lvgl_port_add_disp_rgb(&display_config, &rgb_config);
lvglDisplay = lvgl_port_add_disp_rgb(&display_config, &rgb_config);
TT_LOG_I(TAG, "Finished");
return displayHandle != nullptr;
auto touch_device = getTouchDevice();
if (touch_device != nullptr) {
touch_device->startLvgl(lvglDisplay);
}
return lvglDisplay != nullptr;
}
bool RgbDisplay::stop() {
assert(displayHandle != nullptr);
lvgl_port_remove_disp(displayHandle);
if (esp_lcd_panel_del(panelHandle) != ESP_OK) {
bool RgbDisplay::stopLvgl() {
if (lvglDisplay == nullptr) {
return false;
}
if (esp_lcd_panel_io_del(ioHandle) != ESP_OK) {
return false;
auto touch_device = getTouchDevice();
if (touch_device != nullptr) {
touch_device->stopLvgl();
}
displayHandle = nullptr;
lvgl_port_remove_disp(lvglDisplay);
lvglDisplay = nullptr;
return true;
}

View File

@ -51,16 +51,22 @@ public:
mirrorX(mirrorX),
mirrorY(mirrorY),
invertColor(invertColor),
backlightDutyFunction(std::move(backlightDutyFunction))
{}
backlightDutyFunction(std::move(backlightDutyFunction)) {
if (this->bufferConfiguration.size == 0) {
auto horizontal_resolution = panelConfig.timings.h_res;
auto vertical_resolution = panelConfig.timings.v_res;
this->bufferConfiguration.size = horizontal_resolution * vertical_resolution / 15;
}
}
};
private:
std::unique_ptr<Configuration> configuration = nullptr;
esp_lcd_panel_io_handle_t ioHandle = nullptr;
esp_lcd_panel_handle_t panelHandle = nullptr;
lv_display_t* displayHandle = nullptr;
std::unique_ptr<Configuration> _Nullable configuration = nullptr;
esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
esp_lcd_panel_handle_t _Nullable panelHandle = nullptr;
lv_display_t* _Nullable lvglDisplay = nullptr;
std::shared_ptr<tt::hal::display::NativeDisplay> _Nullable nativeDisplay;
public:
@ -68,6 +74,8 @@ public:
assert(configuration != nullptr);
}
~RgbDisplay();
std::string getName() const final { return "RGB Display"; }
std::string getDescription() const final { return "RGB Display"; }
@ -75,7 +83,13 @@ public:
bool stop() override;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable createTouch() final { return configuration->touch; }
bool supportsLvgl() const override { return true; }
bool startLvgl() override;
bool stopLvgl() override;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() final { return configuration->touch; }
void setBacklightDuty(uint8_t backlightDuty) final {
if (configuration->backlightDutyFunction != nullptr) {
@ -85,7 +99,7 @@ public:
bool supportsBacklightDuty() const final { return configuration->backlightDutyFunction != nullptr; }
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
lv_display_t* _Nullable getLvglDisplay() const override { return lvglDisplay; }
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd driver EspLcdNativeDisplay
REQUIRES Tactility driver EspLcdCompat
)

View File

@ -9,7 +9,7 @@
#define TAG "ST7789"
bool St7789Display::start() {
bool St7789Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
TT_LOG_I(TAG, "Starting");
const esp_lcd_panel_io_spi_config_t panel_io_config = {
@ -36,11 +36,16 @@ bool St7789Display::start() {
}
};
if (esp_lcd_new_panel_io_spi(configuration->spiBusHandle, &panel_io_config, &ioHandle) != ESP_OK) {
if (esp_lcd_new_panel_io_spi(configuration->spiBusHandle, &panel_io_config, &outHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
return false;
}
return true;
}
bool St7789Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) {
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = configuration->resetPin,
.rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB,
@ -87,30 +92,10 @@ bool St7789Display::start() {
return false;
}
TT_LOG_I(TAG, "Finished");
return panelHandle != nullptr;
}
bool St7789Display::stop() {
if (getLvglDisplay() != nullptr) {
stopLvgl();
}
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;
}
bool St7789Display::startLvgl() {
assert(displayHandle == nullptr);
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;
@ -118,7 +103,7 @@ bool St7789Display::startLvgl() {
buffer_size = configuration->bufferSize;
}
const lvgl_port_display_cfg_t disp_cfg = {
return lvgl_port_display_cfg_t {
.io_handle = ioHandle,
.panel_handle = panelHandle,
.control_handle = nullptr,
@ -143,21 +128,7 @@ bool St7789Display::startLvgl() {
.direct_mode = false
}
};
displayHandle = lvgl_port_add_disp(&disp_cfg);
return displayHandle != nullptr;
}
bool St7789Display::stopLvgl() {
if (displayHandle == nullptr) {
return false;
} else {
lvgl_port_remove_disp(displayHandle);
displayHandle = nullptr;
return true;
}
}
/**
* Note:
* The datasheet implies this should work, but it doesn't:
@ -190,7 +161,9 @@ void St7789Display::setGammaCurve(uint8_t index) {
gamma_curve
};
if (esp_lcd_panel_io_tx_param(ioHandle , LCD_CMD_GAMSET, param, 1) != ESP_OK) {
auto io_handle = getIoHandle();
assert(io_handle != nullptr);
if (esp_lcd_panel_io_tx_param(io_handle, LCD_CMD_GAMSET, param, 1) != ESP_OK) {
TT_LOG_E(TAG, "Failed to set gamma");
}
}

View File

@ -1,16 +1,15 @@
#pragma once
#include <EspLcdDisplay.h>
#include <Tactility/hal/display/DisplayDevice.h>
#include <EspLcdNativeDisplay.h>
#include <driver/gpio.h>
#include <esp_lcd_panel_io.h>
#include <esp_lcd_types.h>
#include <functional>
#include <lvgl.h>
class St7789Display final : public tt::hal::display::DisplayDevice {
class St7789Display final : public EspLcdDisplay {
public:
@ -63,9 +62,6 @@ public:
private:
std::unique_ptr<Configuration> configuration;
esp_lcd_panel_io_handle_t ioHandle = nullptr;
esp_lcd_panel_handle_t panelHandle = nullptr;
lv_display_t* displayHandle = nullptr;
public:
@ -76,11 +72,13 @@ public:
std::string getName() const override { return "ST7789"; }
std::string getDescription() const override { return "ST7789 display"; }
bool start() override;
bool createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) override;
bool stop() override;
bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) override;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable createTouch() override { return configuration->touch; }
lvgl_port_display_cfg_t getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) override;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return configuration->touch; }
void setBacklightDuty(uint8_t backlightDuty) override {
if (configuration->backlightDutyFunction != nullptr) {
@ -92,35 +90,6 @@ public:
void setGammaCurve(uint8_t index) override;
uint8_t getGammaCurveCount() const override { return 4; };
// region LVGL
bool supportsLvgl() const override { return true; }
bool startLvgl() override;
bool stopLvgl() override;
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
// endregion
// region NativedDisplay
bool supportsNativeDisplay() const override { return true; }
std::shared_ptr<tt::hal::display::NativeDisplay> getNativeDisplay() override {
assert(displayHandle == nullptr); // Still attached to LVGL context. Call stopLvgl() first.
return std::make_shared<tt::hal::display::EspLcdNativeDisplay>(
panelHandle,
tt::hal::display::ColorFormat::RGB565,
configuration->horizontalResolution,
configuration->verticalResolution
);
}
// endregion
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -26,7 +26,7 @@ public:
virtual bool isPoweredOn() const { return true; }
virtual bool supportsPowerControl() const { return false; }
virtual std::shared_ptr<touch::TouchDevice> _Nullable createTouch() = 0;
virtual std::shared_ptr<touch::TouchDevice> _Nullable getTouchDevice() = 0;
/** Set a value in the range [0, 255] */
virtual void setBacklightDuty(uint8_t backlightDuty) { /* NO-OP */ }
@ -43,8 +43,7 @@ public:
virtual bool startLvgl() { return false; }
virtual bool stopLvgl() { return false; }
virtual bool supportsNativeDisplay() const { return false; }
virtual std::shared_ptr<NativeDisplay> getNativeDisplay() { return nullptr; }
virtual std::shared_ptr<NativeDisplay> _Nullable getNativeDisplay() { return nullptr; }
};
} // namespace tt::hal::display

View File

@ -14,8 +14,8 @@ public:
Type getType() const override { return Type::Keyboard; }
virtual bool start(lv_display_t* display) = 0;
virtual bool stop() = 0;
virtual bool startLvgl(lv_display_t* display) = 0;
virtual bool stopLvgl() = 0;
virtual bool isAttached() const = 0;
virtual lv_indev_t* _Nullable getLvglIndev() = 0;

View File

@ -0,0 +1,23 @@
#pragma once
namespace tt::hal::touch {
class NativeTouch {
public:
/**
* Get the coordinates for the currently touched points on the screen.
*
* @param[in] x array of X coordinates
* @param[in] y array of Y coordinates
* @param[in] strength optional array of strengths
* @param[in] pointCount the number of points currently touched on the screen
* @param[in] maxPointCount the maximum number of points that can be touched at once
*
* @return true when touched and coordinates are available
*/
virtual bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* _Nullable strength, uint8_t* pointCount, uint8_t maxPointCount) = 0;
};
}

View File

@ -1,6 +1,7 @@
#pragma once
#include "../Device.h"
#include "NativeTouch.h"
#include <lvgl.h>
@ -14,10 +15,16 @@ public:
Type getType() const override { return Type::Touch; }
virtual bool start(lv_display_t* display) = 0;
virtual bool start() = 0;
virtual bool stop() = 0;
virtual bool supportsLvgl() const { return false; }
virtual bool startLvgl(lv_display_t* display) = 0;
virtual bool stopLvgl() = 0;
virtual lv_indev_t* _Nullable getLvglIndev() = 0;
virtual std::shared_ptr<NativeTouch> _Nullable getNativeTouch() = 0;
};
}

View File

@ -14,12 +14,14 @@ enum class SystemEvent {
BootInitSpiEnd,
BootInitUartBegin,
BootInitUartEnd,
BootInitLvglBegin,
BootInitLvglEnd,
BootSplash,
/** Gained IP address */
NetworkConnected,
NetworkDisconnected,
/** LVGL devices are initialized and usable */
LvglStarted,
/** LVGL devices were removed and not usable anymore */
LvglStopped,
/** An important system time-related event, such as NTP update or time-zone change */
Time,
};

View File

@ -1,5 +1,11 @@
#pragma once
#include <lvgl.h>
namespace tt::lvgl {
#include "./Colors.h"
bool isStarted();
void start();
void stop();
}

View File

@ -30,11 +30,11 @@ bool startService(const std::string& id);
bool stopService(const std::string& id);
/** Get the state of a service.
* @warning If the service is not found, the returned result will be "Stopped" - even if the service id does not exist
* @param[in] the service id as defined in its manifest
* @param[out] the variable to store the resulting state in
* @return true if the service was found and "state" was set
* @return the service state
*/
bool getState(const std::string& id, State& state);
State getState(const std::string& id);
/** Find a service manifest by its id.
* @param[in] id the id as defined in the manifest

View File

@ -1,7 +1,7 @@
#include "Tactility/Tactility.h"
#include "Tactility/app/ManifestRegistry.h"
#include "Tactility/lvgl/Init_i.h"
#include "Tactility/lvgl/LvglPrivate.h"
#include "Tactility/service/ServiceManifest.h"
#include <Tactility/TactilityHeadless.h>

View File

@ -38,16 +38,16 @@ static const char* getEventName(SystemEvent event) {
return TT_STRINGIFY(BootInitUartBegin);
case BootInitUartEnd:
return TT_STRINGIFY(BootInitUartEnd);
case BootInitLvglBegin:
return TT_STRINGIFY(BootInitLvglBegin);
case BootInitLvglEnd:
return TT_STRINGIFY(BootInitLvglEnd);
case BootSplash:
return TT_STRINGIFY(BootSplash);
case NetworkConnected:
return TT_STRINGIFY(NetworkConnected);
case NetworkDisconnected:
return TT_STRINGIFY(NetworkDisconnected);
case LvglStarted:
return TT_STRINGIFY(LvglStarted);
case LvglStopped:
return TT_STRINGIFY(LvglStopped);
case Time:
return TT_STRINGIFY(Time);
}

View File

@ -1,115 +0,0 @@
#include "Tactility/app/display/DisplaySettings.h"
#include "Tactility/lvgl/Keyboard.h"
#include "Tactility/hal/display/DisplayDevice.h"
#include "Tactility/hal/touch/TouchDevice.h"
#include <Tactility/hal/Configuration.h>
#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tactility/kernel/SystemEvents.h>
#ifdef ESP_PLATFORM
#include "Tactility/lvgl/EspLvglPort.h"
#endif
#include <lvgl.h>
namespace tt::lvgl {
#define TAG "lvgl_init"
static std::shared_ptr<hal::display::DisplayDevice> initDisplay(const hal::Configuration& config) {
assert(config.createDisplay);
auto display = config.createDisplay();
assert(display != nullptr);
if (!display->start()) {
TT_LOG_E(TAG, "Display start failed");
return nullptr;
}
if (display->supportsBacklightDuty()) {
display->setBacklightDuty(0);
}
if (display->supportsLvgl() && display->startLvgl()) {
auto lvgl_display = display->getLvglDisplay();
assert(lvgl_display != nullptr);
lv_display_rotation_t rotation = app::display::getRotation();
if (rotation != lv_display_get_rotation(lvgl_display)) {
lv_display_set_rotation(lvgl_display, rotation);
}
}
return display;
}
static bool initTouch(const std::shared_ptr<hal::display::DisplayDevice>& display, const std::shared_ptr<hal::touch::TouchDevice>& touch) {
TT_LOG_I(TAG, "Touch init");
assert(display);
assert(touch);
if (touch->start(display->getLvglDisplay())) {
return true;
} else {
TT_LOG_E(TAG, "Touch init failed");
return false;
}
}
static bool initKeyboard(const std::shared_ptr<hal::display::DisplayDevice>& display, const std::shared_ptr<hal::keyboard::KeyboardDevice>& keyboard) {
TT_LOG_I(TAG, "Keyboard init");
assert(display);
assert(keyboard);
if (keyboard->isAttached()) {
if (keyboard->start(display->getLvglDisplay())) {
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
lv_indev_set_user_data(keyboard_indev, keyboard.get());
hardware_keyboard_set_indev(keyboard_indev);
TT_LOG_I(TAG, "Keyboard started");
return true;
} else {
TT_LOG_E(TAG, "Keyboard start failed");
return false;
}
} else {
TT_LOG_E(TAG, "Keyboard attach failed");
return false;
}
}
void init(const hal::Configuration& config) {
TT_LOG_I(TAG, "Starting");
kernel::publishSystemEvent(kernel::SystemEvent::BootInitLvglBegin);
#ifdef ESP_PLATFORM
if (config.lvglInit == hal::LvglInit::Default && !initEspLvglPort()) {
return;
}
#endif
auto display = initDisplay(config);
if (display == nullptr) {
return;
}
hal::registerDevice(display);
auto touch = display->createTouch();
if (touch != nullptr) {
hal::registerDevice(touch);
initTouch(display, touch);
}
if (config.createKeyboard) {
auto keyboard = config.createKeyboard();
if (keyboard != nullptr) {
hal::registerDevice(keyboard);
initKeyboard(display, keyboard);
}
}
TT_LOG_I(TAG, "Finished");
kernel::publishSystemEvent(kernel::SystemEvent::BootInitLvglEnd);
}
} // namespace

View File

@ -0,0 +1,197 @@
#include "Tactility/app/display/DisplaySettings.h"
#include "Tactility/lvgl/Keyboard.h"
#include "Tactility/lvgl/Lvgl.h"
#include "Tactility/hal/display/DisplayDevice.h"
#include "Tactility/hal/touch/TouchDevice.h"
#include <Tactility/hal/Configuration.h>
#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tactility/kernel/SystemEvents.h>
#ifdef ESP_PLATFORM
#include "Tactility/lvgl/EspLvglPort.h"
#endif
#include <lvgl.h>
#include <Tactility/Tactility.h>
#include <Tactility/TactilityHeadless.h>
#include <Tactility/service/ServiceRegistry.h>
namespace tt::lvgl {
#define TAG "Lvgl"
static bool started = false;
static std::shared_ptr<hal::display::DisplayDevice> createDisplay(const hal::Configuration& config) {
assert(config.createDisplay);
auto display = config.createDisplay();
assert(display != nullptr);
if (!display->start()) {
TT_LOG_E(TAG, "Display start failed");
return nullptr;
}
if (display->supportsBacklightDuty()) {
display->setBacklightDuty(0);
}
return display;
}
void init(const hal::Configuration& config) {
TT_LOG_I(TAG, "Init started");
#ifdef ESP_PLATFORM
if (config.lvglInit == hal::LvglInit::Default && !initEspLvglPort()) {
return;
}
#endif
auto display = createDisplay(config);
if (display == nullptr) {
return;
}
hal::registerDevice(display);
auto touch = display->getTouchDevice();
if (touch != nullptr) {
touch->start();
hal::registerDevice(touch);
}
auto configuration = hal::getConfiguration();
if (configuration->createKeyboard) {
auto keyboard = configuration->createKeyboard();
if (keyboard != nullptr) {
hal::registerDevice(keyboard);
}
}
start();
TT_LOG_I(TAG, "Init finished");
}
bool isStarted() {
return started;
}
void start() {
TT_LOG_I(TAG, "Start LVGL");
if (started) {
TT_LOG_W(TAG, "Can't start LVGL twice");
return;
}
// Start displays (their related touch devices start automatically within)
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
for (auto display : displays) {
if (display->supportsLvgl() && display->startLvgl()) {
auto lvgl_display = display->getLvglDisplay();
assert(lvgl_display != nullptr);
lv_display_rotation_t rotation = app::display::getRotation();
if (rotation != lv_display_get_rotation(lvgl_display)) {
lv_display_set_rotation(lvgl_display, rotation);
}
}
}
// Start touch
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
for (auto touch_device : touch_devices) {
if (displays.size() > 0) {
// TODO: Consider implementing support for multiple displays
auto display = displays[0];
if (touch_device->supportsLvgl()) {
touch_device->startLvgl(display->getLvglDisplay());
}
}
}
// Start keyboards
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
for (auto keyboard : keyboards) {
if (displays.size() > 0) {
// TODO: Consider implementing support for multiple displays
auto display = displays[0];
if (keyboard->isAttached()) {
if (keyboard->startLvgl(display->getLvglDisplay())) {
lv_indev_t* keyboard_indev = keyboard->getLvglIndev();
hardware_keyboard_set_indev(keyboard_indev);
TT_LOG_I(TAG, "Keyboard started");
} else {
TT_LOG_E(TAG, "Keyboard start failed");
}
}
}
}
// Restart services
if (service::getState("Gui") == service::State::Stopped) {
service::startService("Gui");
} else {
TT_LOG_E(TAG, "Gui service is not in Stopped state");
}
if (service::getState("Statusbar") == service::State::Stopped) {
service::startService("Statusbar");
} else {
TT_LOG_E(TAG, "Statusbar service is not in Stopped state");
}
// Finalize
kernel::publishSystemEvent(kernel::SystemEvent::LvglStarted);
started = true;
}
void stop() {
TT_LOG_I(TAG, "Stop LVGL");
if (!started) {
TT_LOG_W(TAG, "Can't stop LVGL: not started");
return;
}
// Stop services that highly depend on LVGL
service::stopService("Statusbar");
service::stopService("Gui");
// Stop keyboards
auto keyboards = hal::findDevices<hal::keyboard::KeyboardDevice>(hal::Device::Type::Keyboard);
for (auto keyboard : keyboards) {
keyboard->stopLvgl();
}
// Stop touch
auto touch_devices = hal::findDevices<hal::touch::TouchDevice>(hal::Device::Type::Touch);
for (auto touch_device : touch_devices) {
touch_device->stopLvgl();
}
// Stop displays (and their touch devices)
auto displays = hal::findDevices<hal::display::DisplayDevice>(hal::Device::Type::Display);
for (auto display : displays) {
if (display->supportsLvgl() && display->getLvglDisplay() != nullptr && !display->stopLvgl()) {
TT_LOG_E("HelloWorld", "Failed to detach display from LVGL");
}
}
started = false;
kernel::publishSystemEvent(kernel::SystemEvent::LvglStopped);
}
} // namespace

View File

@ -7,6 +7,7 @@
#include <string>
#include <unordered_map>
#include <Tactility/app/AppInstance.h>
namespace tt::service {
@ -98,7 +99,7 @@ bool stopService(const std::string& id) {
TT_LOG_I(TAG, "Stopping %s", id.c_str());
auto service_instance = findServiceInstanceById(id);
if (service_instance == nullptr) {
TT_LOG_W(TAG, "service not running: %s", id.c_str());
TT_LOG_W(TAG, "Service not running: %s", id.c_str());
return false;
}
@ -119,15 +120,12 @@ bool stopService(const std::string& id) {
return true;
}
bool getState(const std::string& id, State& state) {
State getState(const std::string& id) {
auto service_instance = findServiceInstanceById(id);
if (service_instance == nullptr) {
TT_LOG_W(TAG, "service not running: %s", id.c_str());
return false;
} else {
state = service_instance->getState();
return true;
return State::Stopped;
}
return service_instance->getState();
}
} // namespace

View File

@ -32,16 +32,11 @@ void GuiService::onLoaderMessage(const void* message, TT_UNUSED void* context) {
}
int32_t GuiService::guiMain() {
State service_state;
while (true) {
uint32_t flags = Thread::awaitFlags(GUI_THREAD_FLAG_ALL, EventFlag::WaitAny, (uint32_t)portMAX_DELAY);
// When service (state) not found -> exit
if (!getState(manifest.id, service_state)) {
break;
}
// When service not started or starting -> exit
State service_state = getState(manifest.id);
if (service_state != State::Started && service_state != State::Starting) {
break;
}

View File

@ -130,20 +130,18 @@ static _Nullable const char* getPowerStatusIcon() {
class StatusbarService final : public Service {
private:
Mutex mutex;
std::unique_ptr<Timer> updateTimer;
int8_t gps_icon_id = lvgl::statusbar_icon_add();
int8_t gps_icon_id;
bool gps_last_state = false;
int8_t wifi_icon_id = lvgl::statusbar_icon_add();
int8_t wifi_icon_id;
const char* wifi_last_icon = nullptr;
int8_t sdcard_icon_id = lvgl::statusbar_icon_add();
int8_t sdcard_icon_id;
const char* sdcard_last_icon = nullptr;
int8_t power_icon_id = lvgl::statusbar_icon_add();
int8_t power_icon_id;
const char* power_last_icon = nullptr;
std::unique_ptr<service::Paths> paths;
std::unique_ptr<Paths> paths;
void lock() const {
mutex.lock();
@ -154,7 +152,7 @@ private:
}
void updateGpsIcon() {
auto gps_state = service::gps::findGpsService()->getState();
auto gps_state = gps::findGpsService()->getState();
bool show_icon = (gps_state == gps::State::OnPending) || (gps_state == gps::State::On);
if (gps_last_state != show_icon) {
if (show_icon) {
@ -199,7 +197,7 @@ private:
}
void updateSdCardIcon() {
auto sdcard = tt::hal::getConfiguration()->sdcard;
auto sdcard = hal::getConfiguration()->sdcard;
if (sdcard != nullptr) {
auto state = sdcard->getState();
if (state != hal::sdcard::SdCardDevice::State::Unknown) {
@ -229,10 +227,18 @@ private:
public:
~StatusbarService() final {
StatusbarService() {
gps_icon_id = lvgl::statusbar_icon_add();
sdcard_icon_id = lvgl::statusbar_icon_add();
wifi_icon_id = lvgl::statusbar_icon_add();
power_icon_id = lvgl::statusbar_icon_add();
}
~StatusbarService() override {
lvgl::statusbar_icon_remove(wifi_icon_id);
lvgl::statusbar_icon_remove(sdcard_icon_id);
lvgl::statusbar_icon_remove(power_icon_id);
lvgl::statusbar_icon_remove(gps_icon_id);
}
void onStart(ServiceContext& serviceContext) override {
@ -245,7 +251,7 @@ public:
assert(service);
onUpdate(service);
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, [service]() {
updateTimer = std::make_unique<Timer>(Timer::Type::Periodic, [service] {
onUpdate(service);
});