mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
Update RgbDisplay driver
This commit is contained in:
parent
08b6e709d5
commit
a30de954ae
@ -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 (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;
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user