mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-19 03:13:14 +00:00
Various graphics and touch driver improvements
This commit is contained in:
parent
a5eb8ef834
commit
0807b09890
@ -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
|
||||
)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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
|
||||
)
|
||||
3
Drivers/EspLcdCompat/README.md
Normal file
3
Drivers/EspLcdCompat/README.md
Normal file
@ -0,0 +1,3 @@
|
||||
# EspLcdCompat
|
||||
|
||||
A set of helper classes to implement `esp_lcd` drivers in Tactility.
|
||||
96
Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp
Normal file
96
Drivers/EspLcdCompat/Source/EspLcdDisplay.cpp
Normal file
@ -0,0 +1,96 @@
|
||||
#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 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);
|
||||
lvglDisplay = lvgl_port_add_disp(&lvglPortDisplayConfig);
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr) {
|
||||
touch_device->start(lvglDisplay);
|
||||
}
|
||||
|
||||
return lvglDisplay != nullptr;
|
||||
}
|
||||
|
||||
bool EspLcdDisplay::stopLvgl() {
|
||||
if (lvglDisplay == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto touch_device = getTouchDevice();
|
||||
if (touch_device != nullptr) {
|
||||
touch_device->stop();
|
||||
}
|
||||
|
||||
lvgl_port_remove_disp(lvglDisplay);
|
||||
lvglDisplay = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<tt::hal::display::NativeDisplay> EspLcdDisplay::getNativeDisplay() {
|
||||
assert(lvglDisplay == nullptr); // Still attached to LVGL context. Call stopLvgl() first.
|
||||
if (nativeDisplay == nullptr) {
|
||||
nativeDisplay = std::make_shared<tt::hal::display::EspLcdNativeDisplay>(
|
||||
panelHandle,
|
||||
lvglPortDisplayConfig
|
||||
);
|
||||
}
|
||||
return nativeDisplay;
|
||||
}
|
||||
55
Drivers/EspLcdCompat/Source/EspLcdDisplay.h
Normal file
55
Drivers/EspLcdCompat/Source/EspLcdDisplay.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
#include <esp_lcd_types.h>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
#include <Tactility/hal/display/NativeDisplay.h>
|
||||
|
||||
class EspLcdDisplay : tt::hal::display::DisplayDevice {
|
||||
|
||||
esp_lcd_panel_io_handle_t ioHandle = nullptr;
|
||||
esp_lcd_panel_handle_t panelHandle = nullptr;
|
||||
lv_display_t* lvglDisplay = nullptr;
|
||||
lvgl_port_display_cfg_t lvglPortDisplayConfig;
|
||||
std::shared_ptr<tt::hal::display::NativeDisplay> 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;
|
||||
|
||||
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
|
||||
|
||||
bool supportsNativeDisplay() const final { return true; }
|
||||
|
||||
std::shared_ptr<tt::hal::display::NativeDisplay> getNativeDisplay() final;
|
||||
|
||||
// endregion
|
||||
};
|
||||
43
Drivers/EspLcdCompat/Source/EspLcdNativeDisplay.h
Normal file
43
Drivers/EspLcdCompat/Source/EspLcdNativeDisplay.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/NativeDisplay.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
|
||||
namespace tt::hal::display {
|
||||
|
||||
class EspLcdNativeDisplay final : public 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) {}
|
||||
|
||||
ColorFormat getColorFormat() const override {
|
||||
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; }
|
||||
};
|
||||
|
||||
}
|
||||
55
Drivers/EspLcdCompat/Source/EspLcdTouch.cpp
Normal file
55
Drivers/EspLcdCompat/Source/EspLcdTouch.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include "EspLcdTouch.h"
|
||||
|
||||
#include <esp_lvgl_port_touch.h>
|
||||
#include <Tactility/LogEsp.h>
|
||||
|
||||
constexpr char* TAG = "EspLcdTouch";
|
||||
|
||||
bool EspLcdTouch::start(lv_display_t* display) {
|
||||
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");
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
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");
|
||||
cleanup();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EspLcdTouch::stop() {
|
||||
cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
void EspLcdTouch::cleanup() {
|
||||
if (lvglDevice != nullptr) {
|
||||
lv_indev_delete(lvglDevice);
|
||||
lvglDevice = nullptr;
|
||||
// TODO: is this correct? We don't have to delete it manually?
|
||||
touchHandle = nullptr;
|
||||
}
|
||||
|
||||
if (ioHandle != nullptr) {
|
||||
esp_lcd_panel_io_del(ioHandle);
|
||||
ioHandle = nullptr;
|
||||
}
|
||||
}
|
||||
34
Drivers/EspLcdCompat/Source/EspLcdTouch.h
Normal file
34
Drivers/EspLcdCompat/Source/EspLcdTouch.h
Normal file
@ -0,0 +1,34 @@
|
||||
#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;
|
||||
|
||||
void cleanup();
|
||||
|
||||
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(lv_display_t* display) override;
|
||||
|
||||
bool stop() override;
|
||||
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return lvglDevice; }
|
||||
};
|
||||
@ -1,3 +0,0 @@
|
||||
# EspLcdNativeDisplay
|
||||
|
||||
An implementation of `tt::hal::display::NativeDisplay` for display drivers that are built around the `esp_lcd` library.
|
||||
@ -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; }
|
||||
};
|
||||
|
||||
}
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
#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 +26,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 +53,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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,6 @@ 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 final { return "GT911"; }
|
||||
std::string getDescription() const final { return "I2C Touch Driver"; }
|
||||
std::string getName() const override { return "GT911"; }
|
||||
std::string getDescription() const override { return "I2C Touch Driver"; }
|
||||
};
|
||||
|
||||
@ -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
|
||||
)
|
||||
|
||||
@ -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,
|
||||
@ -88,29 +93,10 @@ bool St7789Display::start() {
|
||||
}
|
||||
|
||||
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 +104,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 +129,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 +162,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");
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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 */ }
|
||||
|
||||
@ -3,3 +3,7 @@
|
||||
#include <lvgl.h>
|
||||
|
||||
#include "./Colors.h"
|
||||
|
||||
void startLvgl();
|
||||
|
||||
void stopLvgl();
|
||||
@ -43,18 +43,6 @@ static std::shared_ptr<hal::display::DisplayDevice> initDisplay(const hal::Confi
|
||||
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);
|
||||
@ -93,10 +81,9 @@ void init(const hal::Configuration& config) {
|
||||
}
|
||||
hal::registerDevice(display);
|
||||
|
||||
auto touch = display->createTouch();
|
||||
auto touch = display->getTouchDevice();
|
||||
if (touch != nullptr) {
|
||||
hal::registerDevice(touch);
|
||||
initTouch(display, touch);
|
||||
}
|
||||
|
||||
if (config.createKeyboard) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user