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(
|
idf_component_register(
|
||||||
SRC_DIRS "Source"
|
SRC_DIRS "Source"
|
||||||
INCLUDE_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_rgb.h>
|
||||||
#include <esp_lcd_panel_ops.h>
|
#include <esp_lcd_panel_ops.h>
|
||||||
#include <esp_lvgl_port.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() {
|
bool RgbDisplay::start() {
|
||||||
TT_LOG_I(TAG, "Starting");
|
TT_LOG_I(TAG, "Starting");
|
||||||
@ -42,25 +50,47 @@ bool RgbDisplay::start() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto horizontal_resolution = configuration->panelConfig.timings.h_res;
|
return true;
|
||||||
auto vertical_resolution = configuration->panelConfig.timings.v_res;
|
}
|
||||||
|
|
||||||
uint32_t buffer_size;
|
bool RgbDisplay::stop() {
|
||||||
if (configuration->bufferConfiguration.size == 0) {
|
if (lvglDisplay != nullptr) {
|
||||||
buffer_size = horizontal_resolution * vertical_resolution / 15;
|
stopLvgl();
|
||||||
} else {
|
lvglDisplay = nullptr;
|
||||||
buffer_size = configuration->bufferConfiguration.size;
|
}
|
||||||
|
|
||||||
|
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 = {
|
const lvgl_port_display_cfg_t display_config = {
|
||||||
.io_handle = ioHandle,
|
.io_handle = ioHandle,
|
||||||
.panel_handle = panelHandle,
|
.panel_handle = panelHandle,
|
||||||
.control_handle = nullptr,
|
.control_handle = nullptr,
|
||||||
.buffer_size = buffer_size,
|
.buffer_size = configuration->bufferConfiguration.size,
|
||||||
.double_buffer = configuration->bufferConfiguration.doubleBuffer,
|
.double_buffer = configuration->bufferConfiguration.doubleBuffer,
|
||||||
.trans_size = 0,
|
.trans_size = 0,
|
||||||
.hres = horizontal_resolution,
|
.hres = configuration->panelConfig.timings.h_res,
|
||||||
.vres = vertical_resolution,
|
.vres = configuration->panelConfig.timings.v_res,
|
||||||
.monochrome = false,
|
.monochrome = false,
|
||||||
.rotation = {
|
.rotation = {
|
||||||
.swap_xy = configuration->swapXY,
|
.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");
|
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() {
|
bool RgbDisplay::stopLvgl() {
|
||||||
assert(displayHandle != nullptr);
|
if (lvglDisplay == nullptr) {
|
||||||
|
|
||||||
lvgl_port_remove_disp(displayHandle);
|
|
||||||
|
|
||||||
if (esp_lcd_panel_del(panelHandle) != ESP_OK) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (esp_lcd_panel_io_del(ioHandle) != ESP_OK) {
|
auto touch_device = getTouchDevice();
|
||||||
return false;
|
if (touch_device != nullptr) {
|
||||||
|
touch_device->stopLvgl();
|
||||||
}
|
}
|
||||||
|
|
||||||
displayHandle = nullptr;
|
lvgl_port_remove_disp(lvglDisplay);
|
||||||
|
lvglDisplay = nullptr;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,16 +51,22 @@ public:
|
|||||||
mirrorX(mirrorX),
|
mirrorX(mirrorX),
|
||||||
mirrorY(mirrorY),
|
mirrorY(mirrorY),
|
||||||
invertColor(invertColor),
|
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:
|
private:
|
||||||
|
|
||||||
std::unique_ptr<Configuration> configuration = nullptr;
|
std::unique_ptr<Configuration> _Nullable configuration = nullptr;
|
||||||
esp_lcd_panel_io_handle_t ioHandle = nullptr;
|
esp_lcd_panel_io_handle_t _Nullable ioHandle = nullptr;
|
||||||
esp_lcd_panel_handle_t panelHandle = nullptr;
|
esp_lcd_panel_handle_t _Nullable panelHandle = nullptr;
|
||||||
lv_display_t* displayHandle = nullptr;
|
lv_display_t* _Nullable lvglDisplay = nullptr;
|
||||||
|
std::shared_ptr<tt::hal::display::NativeDisplay> _Nullable nativeDisplay;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -68,6 +74,8 @@ public:
|
|||||||
assert(configuration != nullptr);
|
assert(configuration != nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~RgbDisplay();
|
||||||
|
|
||||||
std::string getName() const final { return "RGB Display"; }
|
std::string getName() const final { return "RGB Display"; }
|
||||||
std::string getDescription() const final { return "RGB Display"; }
|
std::string getDescription() const final { return "RGB Display"; }
|
||||||
|
|
||||||
@ -75,7 +83,13 @@ public:
|
|||||||
|
|
||||||
bool stop() override;
|
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 {
|
void setBacklightDuty(uint8_t backlightDuty) final {
|
||||||
if (configuration->backlightDutyFunction != nullptr) {
|
if (configuration->backlightDutyFunction != nullptr) {
|
||||||
@ -85,7 +99,7 @@ public:
|
|||||||
|
|
||||||
bool supportsBacklightDuty() const final { return configuration->backlightDutyFunction != nullptr; }
|
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();
|
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user