Touch and display driver subsystems reworked (and more) (#302)
- Refactored `TouchDevice`: it can now start/stop LVGL separately, and it has an optional `TouchDriver` interface - Refactored `DisplayDevice`: it can now start/stop LVGL separately, and it has an optional `DisplayDriver` interface - Updated all boards and drivers for above changes - LVGL can now be stopped and (re)started on the fly - Fixed issues with restarting Gui and Statusbar services - Refactored `Gui` service to be class and renamed `Gui` to `GuiService` - Fixed `Statusbar` service: forgot to deregister one of the icons - Updated `esp_lcd_st7701` to v1.1.3 - `lv_textarea_create()` now automatically registers the hardware keyboard hooks (by wrapping the function) - Fixed and updated `tactility.py` - Cleanup of a lot of code - `BootInitLvglBegin` and `BootInitLvglEnd` are replaced by `LvglStarted` and `LvglStopped`. - Introduced `tt::service::State` which is accessible via `tt::service::getState()` (and internally via `ServiceInstance`) - Started replacing `#define TAG` with `constexpr auto TAG = "..";`
This commit is contained in:
committed by
GitHub
parent
15f4fbfdc6
commit
d875ade8cb
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd
|
||||
REQUIRES Tactility EspLcdCompat
|
||||
)
|
||||
|
||||
@@ -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 (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
tt_crash("DisplayDriver is still in use. This will cause memory access violations.");
|
||||
}
|
||||
}
|
||||
|
||||
bool RgbDisplay::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
@@ -42,25 +50,85 @@ 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;
|
||||
}
|
||||
|
||||
const lvgl_port_display_cfg_t display_config = {
|
||||
.io_handle = ioHandle,
|
||||
if (panelHandle != nullptr && esp_lcd_panel_del(panelHandle) != ESP_OK) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver is still in use.");
|
||||
}
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr) {
|
||||
touch_device->startLvgl(lvglDisplay);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RgbDisplay::startLvgl() {
|
||||
assert(lvglDisplay == nullptr);
|
||||
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver is still in use.");
|
||||
}
|
||||
|
||||
auto display_config = getLvglPortDisplayConfig();
|
||||
|
||||
const lvgl_port_display_rgb_cfg_t rgb_config = {
|
||||
.flags = {
|
||||
.bb_mode = configuration->bufferConfiguration.bounceBufferMode,
|
||||
.avoid_tearing = configuration->bufferConfiguration.avoidTearing
|
||||
}
|
||||
};
|
||||
|
||||
lvglDisplay = lvgl_port_add_disp_rgb(&display_config, &rgb_config);
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr) {
|
||||
touch_device->startLvgl(lvglDisplay);
|
||||
}
|
||||
|
||||
return lvglDisplay != nullptr;
|
||||
}
|
||||
|
||||
bool RgbDisplay::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;
|
||||
}
|
||||
|
||||
lvgl_port_display_cfg_t RgbDisplay::getLvglPortDisplayConfig() const {
|
||||
return {
|
||||
.io_handle = nullptr,
|
||||
.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,
|
||||
@@ -77,33 +145,5 @@ bool RgbDisplay::start() {
|
||||
.direct_mode = false
|
||||
}
|
||||
};
|
||||
|
||||
const lvgl_port_display_rgb_cfg_t rgb_config = {
|
||||
.flags = {
|
||||
.bb_mode = configuration->bufferConfiguration.bounceBufferMode,
|
||||
.avoid_tearing = configuration->bufferConfiguration.avoidTearing
|
||||
}
|
||||
};
|
||||
|
||||
displayHandle = lvgl_port_add_disp_rgb(&display_config, &rgb_config);
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool RgbDisplay::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;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
#include <EspLcdDisplayDriver.h>
|
||||
#include <esp_lcd_panel_rgb.h>
|
||||
#include <esp_lcd_types.h>
|
||||
#include <lvgl.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
class RgbDisplay : public tt::hal::display::DisplayDevice {
|
||||
class RgbDisplay final : public display::DisplayDevice {
|
||||
|
||||
public:
|
||||
|
||||
@@ -25,7 +21,7 @@ public:
|
||||
|
||||
esp_lcd_rgb_panel_config_t panelConfig;
|
||||
BufferConfiguration bufferConfiguration;
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> touch;
|
||||
std::shared_ptr<touch::TouchDevice> touch;
|
||||
lv_color_format_t colorFormat;
|
||||
bool swapXY;
|
||||
bool mirrorX;
|
||||
@@ -36,7 +32,7 @@ public:
|
||||
Configuration(
|
||||
esp_lcd_rgb_panel_config_t panelConfig,
|
||||
BufferConfiguration bufferConfiguration,
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> touch,
|
||||
std::shared_ptr<touch::TouchDevice> touch,
|
||||
lv_color_format_t colorFormat,
|
||||
bool swapXY = false,
|
||||
bool mirrorX = false,
|
||||
@@ -51,16 +47,23 @@ 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_handle_t _Nullable panelHandle = nullptr;
|
||||
lv_display_t* _Nullable lvglDisplay = nullptr;
|
||||
std::shared_ptr<display::DisplayDriver> _Nullable displayDriver;
|
||||
|
||||
lvgl_port_display_cfg_t getLvglPortDisplayConfig() const;
|
||||
|
||||
public:
|
||||
|
||||
@@ -68,24 +71,41 @@ public:
|
||||
assert(configuration != nullptr);
|
||||
}
|
||||
|
||||
std::string getName() const final { return "RGB Display"; }
|
||||
std::string getDescription() const final { return "RGB Display"; }
|
||||
~RgbDisplay();
|
||||
|
||||
std::string getName() const override { return "RGB Display"; }
|
||||
std::string getDescription() const override { return "RGB Display"; }
|
||||
|
||||
bool start() override;
|
||||
|
||||
bool stop() override;
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable createTouch() final { return configuration->touch; }
|
||||
bool supportsLvgl() const override { return true; }
|
||||
|
||||
void setBacklightDuty(uint8_t backlightDuty) final {
|
||||
bool startLvgl() override;
|
||||
|
||||
bool stopLvgl() override;
|
||||
|
||||
std::shared_ptr<touch::TouchDevice> _Nullable getTouchDevice() override { return configuration->touch; }
|
||||
|
||||
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; }
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return displayHandle; }
|
||||
lv_display_t* _Nullable getLvglDisplay() const override { return lvglDisplay; }
|
||||
|
||||
bool supportsDisplayDriver() const override { return true; }
|
||||
|
||||
std::shared_ptr<display::DisplayDriver> _Nullable getDisplayDriver() override {
|
||||
if (displayDriver == nullptr) {
|
||||
displayDriver = std::make_shared<EspLcdDisplayDriver>(panelHandle, getLvglPortDisplayConfig());
|
||||
}
|
||||
return displayDriver;
|
||||
}
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
|
||||
Reference in New Issue
Block a user