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_touch esp_lcd_touch_cst816s driver
|
||||
REQUIRES Tactility EspLcdCompat esp_lcd_touch_cst816s driver
|
||||
)
|
||||
|
||||
@@ -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"; }
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lcd esp_lcd_touch esp_lvgl_port
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
# EspLcdCompat
|
||||
|
||||
A set of helper classes to implement `esp_lcd` drivers in Tactility.
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "EspLcdDisplay.h"
|
||||
#include "EspLcdDisplayDriver.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 = "EspLcdDispDrv";
|
||||
|
||||
EspLcdDisplay::~EspLcdDisplay() {
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
tt_crash("DisplayDriver 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 (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver is still in use.");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EspLcdDisplay::startLvgl() {
|
||||
assert(lvglDisplay == nullptr);
|
||||
|
||||
if (displayDriver != nullptr && displayDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "DisplayDriver 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::DisplayDriver> EspLcdDisplay::getDisplayDriver() {
|
||||
assert(lvglDisplay == nullptr); // Still attached to LVGL context. Call stopLvgl() first.
|
||||
if (displayDriver == nullptr) {
|
||||
displayDriver = std::make_shared<EspLcdDisplayDriver>(
|
||||
panelHandle,
|
||||
lvglPortDisplayConfig
|
||||
);
|
||||
}
|
||||
return displayDriver;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
#include <esp_lcd_types.h>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
#include <Tactility/Check.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::DisplayDriver> _Nullable displayDriver;
|
||||
|
||||
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 NativeDisplay
|
||||
|
||||
bool supportsDisplayDriver() const override { return true; }
|
||||
|
||||
/** @return a NativeDisplay instance if this device supports it */
|
||||
std::shared_ptr<tt::hal::display::DisplayDriver> _Nullable getDisplayDriver() final;
|
||||
|
||||
// endregion
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/display/DisplayDriver.h>
|
||||
#include <esp_lcd_panel_ops.h>
|
||||
#include <esp_lvgl_port_disp.h>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
class EspLcdDisplayDriver : public display::DisplayDriver {
|
||||
|
||||
esp_lcd_panel_handle_t panelHandle;
|
||||
const lvgl_port_display_cfg_t& lvglPortDisplayConfig;
|
||||
|
||||
public:
|
||||
|
||||
EspLcdDisplayDriver(
|
||||
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; }
|
||||
};
|
||||
@@ -0,0 +1,92 @@
|
||||
#include "EspLcdTouch.h"
|
||||
|
||||
#include <EspLcdTouchDriver.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 (touchDriver != nullptr && touchDriver.use_count() > 1) {
|
||||
TT_LOG_W(TAG, "TouchDriver 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::TouchDriver> _Nullable EspLcdTouch::getTouchDriver() {
|
||||
assert(lvglDevice == nullptr); // Still attached to LVGL context. Call stopLvgl() first.
|
||||
|
||||
if (touchHandle == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (touchDriver == nullptr) {
|
||||
touchDriver = std::make_shared<EspLcdTouchDriver>(touchHandle);
|
||||
}
|
||||
|
||||
return touchDriver;
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <esp_lcd_touch.h>
|
||||
#include <esp_lcd_types.h>
|
||||
#include <lvgl.h>
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <Tactility/hal/touch/TouchDriver.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::TouchDriver> touchDriver;
|
||||
|
||||
protected:
|
||||
|
||||
esp_lcd_touch_handle_t _Nullable getTouchHandle() const { return touchHandle; }
|
||||
|
||||
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; }
|
||||
|
||||
bool supportsTouchDriver() override { return true; }
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDriver> _Nullable getTouchDriver() final;
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
#include "EspLcdTouchDriver.h"
|
||||
|
||||
#include <Tactility/LogEsp.h>
|
||||
|
||||
constexpr const char* TAG = "EspLcdTouchDriver";
|
||||
|
||||
bool EspLcdTouchDriver::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;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <esp_lcd_touch.h>
|
||||
#include <Tactility/hal/touch/TouchDriver.h>
|
||||
|
||||
class EspLcdTouchDriver final : public tt::hal::touch::TouchDriver {
|
||||
|
||||
esp_lcd_touch_handle_t handle;
|
||||
|
||||
public:
|
||||
|
||||
EspLcdTouchDriver(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;
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd_touch esp_lcd_touch_ft5x06 driver
|
||||
REQUIRES Tactility EspLcdCompat esp_lcd_touch_ft5x06 driver
|
||||
)
|
||||
|
||||
@@ -8,15 +8,17 @@
|
||||
|
||||
#define TAG "ft5x06"
|
||||
|
||||
bool Ft5x06Touch::start(lv_display_t* display) {
|
||||
bool Ft5x06Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
|
||||
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
|
||||
return esp_lcd_new_panel_io_i2c(configuration->port, &io_config, &outHandle) == ESP_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
bool Ft5x06Touch::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_ft5x06(ioHandle, &configuration, &panelHandle) == ESP_OK;
|
||||
}
|
||||
|
||||
esp_lcd_touch_config_t config = {
|
||||
esp_lcd_touch_config_t Ft5x06Touch::createEspLcdTouchConfig() {
|
||||
return {
|
||||
.x_max = configuration->xMax,
|
||||
.y_max = configuration->yMax,
|
||||
.rst_gpio_num = configuration->pinReset,
|
||||
@@ -35,47 +37,4 @@ bool Ft5x06Touch::start(lv_display_t* display) {
|
||||
.user_data = nullptr,
|
||||
.driver_data = nullptr
|
||||
};
|
||||
|
||||
if (esp_lcd_touch_new_i2c_ft5x06(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 Ft5x06Touch::stop() {
|
||||
cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Ft5x06Touch::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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#include <esp_lcd_panel_io_interface.h>
|
||||
#include <esp_lcd_touch.h>
|
||||
#include <EspLcdTouch.h>
|
||||
|
||||
class Ft5x06Touch final : public tt::hal::touch::TouchDevice {
|
||||
class Ft5x06Touch final : public EspLcdTouch {
|
||||
|
||||
public:
|
||||
|
||||
@@ -52,11 +51,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() override;
|
||||
|
||||
public:
|
||||
|
||||
@@ -64,10 +64,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 "FT5x06"; }
|
||||
|
||||
std::string getName() const final { return "FT5x06"; }
|
||||
std::string getDescription() const final { return "I2C Touch Driver"; }
|
||||
std::string getDescription() const override { return "FT5x06 I2C touch driver"; }
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "Ft6x36Touch.h"
|
||||
|
||||
#include <Ft6x36Touch.h>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <esp_err.h>
|
||||
@@ -7,22 +8,23 @@
|
||||
|
||||
#define TAG "ft6x36"
|
||||
|
||||
static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
void Ft6x36Touch::touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
auto* touch = (Ft6x36Touch*)lv_indev_get_driver_data(indev);
|
||||
touch->readLast(data);
|
||||
touch->mutex.lock();
|
||||
data->point = touch->lastPoint;
|
||||
data->state = touch->lastState;
|
||||
touch->mutex.unlock();
|
||||
}
|
||||
|
||||
Ft6x36Touch::Ft6x36Touch(std::unique_ptr<Configuration> inConfiguration) :
|
||||
configuration(std::move(inConfiguration)),
|
||||
driverThread(tt::Thread("ft6x36", 4096, [this]() {
|
||||
driverThreadMain();
|
||||
return 0;
|
||||
}))
|
||||
{}
|
||||
configuration(std::move(inConfiguration)) {
|
||||
nativeTouch = std::make_shared<Ft6TouchDriver>(*this);
|
||||
}
|
||||
|
||||
Ft6x36Touch::~Ft6x36Touch() {
|
||||
if (driverThread.getState() != tt::Thread::State::Stopped) {
|
||||
stop();
|
||||
if (driverThread != nullptr && driverThread->getState() != tt::Thread::State::Stopped) {
|
||||
interruptDriverThread = true;
|
||||
driverThread->join();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +61,7 @@ void Ft6x36Touch::driverThreadMain() {
|
||||
}
|
||||
}
|
||||
|
||||
bool Ft6x36Touch::shouldInterruptDriverThread() {
|
||||
bool Ft6x36Touch::shouldInterruptDriverThread() const {
|
||||
bool interrupt = false;
|
||||
if (mutex.lock(50 / portTICK_PERIOD_MS)) {
|
||||
interrupt = interruptDriverThread;
|
||||
@@ -68,35 +70,65 @@ bool Ft6x36Touch::shouldInterruptDriverThread() {
|
||||
return interrupt;
|
||||
}
|
||||
|
||||
bool Ft6x36Touch::start(lv_display_t* display) {
|
||||
TT_LOG_I(TAG, "start");
|
||||
bool Ft6x36Touch::start() {
|
||||
TT_LOG_I(TAG, "Start");
|
||||
|
||||
driverThread.start();
|
||||
|
||||
uint16_t width = lv_display_get_horizontal_resolution(display);
|
||||
uint16_t height = lv_display_get_vertical_resolution(display);
|
||||
if (!driver.begin(FT6X36_DEFAULT_THRESHOLD, width, height)) {
|
||||
if (!driver.begin(FT6X36_DEFAULT_THRESHOLD, configuration->width, configuration->height)) {
|
||||
TT_LOG_E(TAG, "driver.begin() failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
mutex.lock();
|
||||
|
||||
interruptDriverThread = false;
|
||||
|
||||
driverThread = std::make_shared<tt::Thread>("ft6x36", 4096, [this] {
|
||||
driverThreadMain();
|
||||
return 0;
|
||||
});
|
||||
|
||||
driverThread->start();
|
||||
|
||||
mutex.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ft6x36Touch::stop() {
|
||||
TT_LOG_I(TAG, "Stop");
|
||||
|
||||
mutex.lock();
|
||||
interruptDriverThread = true;
|
||||
mutex.unlock();
|
||||
|
||||
driverThread->join();
|
||||
|
||||
mutex.lock();
|
||||
driverThread = nullptr;
|
||||
mutex.unlock();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Ft6x36Touch::startLvgl(lv_display_t* display) {
|
||||
if (deviceHandle != nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
deviceHandle = lv_indev_create();
|
||||
lv_indev_set_type(deviceHandle, LV_INDEV_TYPE_POINTER);
|
||||
lv_indev_set_driver_data(deviceHandle, this);
|
||||
lv_indev_set_read_cb(deviceHandle, touchReadCallback);
|
||||
|
||||
TT_LOG_I(TAG, "start success");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Ft6x36Touch::stop() {
|
||||
bool Ft6x36Touch::stopLvgl() {
|
||||
if (deviceHandle == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
lv_indev_delete(deviceHandle);
|
||||
interruptDriverThread = true;
|
||||
driverThread.join();
|
||||
deviceHandle = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Ft6x36Touch::readLast(lv_indev_data_t* data) {
|
||||
data->point = lastPoint;
|
||||
data->state = lastState;
|
||||
}
|
||||
|
||||
@@ -15,41 +15,78 @@ public:
|
||||
|
||||
Configuration(
|
||||
i2c_port_t port,
|
||||
gpio_num_t pinInterrupt
|
||||
gpio_num_t pinInterrupt,
|
||||
uint16_t width,
|
||||
uint16_t height
|
||||
) : port(port),
|
||||
pinInterrupt(pinInterrupt)
|
||||
pinInterrupt(pinInterrupt),
|
||||
width(width),
|
||||
height(height)
|
||||
{}
|
||||
|
||||
i2c_port_t port;
|
||||
gpio_num_t pinInterrupt;
|
||||
};
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<Configuration> configuration;
|
||||
lv_indev_t* _Nullable deviceHandle = nullptr;
|
||||
FT6X36 driver = FT6X36(configuration->port, configuration->pinInterrupt);
|
||||
tt::Thread driverThread;
|
||||
std::shared_ptr<tt::Thread> driverThread;
|
||||
bool interruptDriverThread = false;
|
||||
tt::Mutex mutex;
|
||||
std::shared_ptr<tt::hal::touch::TouchDriver> nativeTouch;
|
||||
|
||||
lv_point_t lastPoint = { .x = 0, .y = 0 };
|
||||
lv_indev_state_t lastState = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
bool shouldInterruptDriverThread();
|
||||
bool shouldInterruptDriverThread() const;
|
||||
|
||||
void driverThreadMain();
|
||||
|
||||
static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data);
|
||||
|
||||
public:
|
||||
|
||||
explicit Ft6x36Touch(std::unique_ptr<Configuration> inConfiguration);
|
||||
~Ft6x36Touch() final;
|
||||
~Ft6x36Touch() override;
|
||||
|
||||
std::string getName() const final { return "FT6x36"; }
|
||||
std::string getDescription() const final { return "I2C touch driver"; }
|
||||
std::string getName() const override { return "FT6x36"; }
|
||||
std::string getDescription() const override { return "FT6x36 I2C touch driver"; }
|
||||
|
||||
bool start(lv_display_t* display) override;
|
||||
bool start() override;
|
||||
bool stop() override;
|
||||
|
||||
void readLast(lv_indev_data_t* data);
|
||||
bool supportsLvgl() const override { return true; }
|
||||
bool startLvgl(lv_display_t* display) override;
|
||||
bool stopLvgl() override;
|
||||
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
|
||||
void driverThreadMain();
|
||||
|
||||
class Ft6TouchDriver : public tt::hal::touch::TouchDriver {
|
||||
public:
|
||||
const Ft6x36Touch& parent;
|
||||
Ft6TouchDriver(const Ft6x36Touch& parent) : parent(parent) {}
|
||||
|
||||
bool getTouchedPoints(uint16_t* x, uint16_t* y, uint16_t* _Nullable strength, uint8_t* pointCount, uint8_t maxPointCount) {
|
||||
auto lock = parent.mutex.asScopedLock();
|
||||
lock.lock();
|
||||
if (parent.lastState == LV_INDEV_STATE_PRESSED) {
|
||||
*x = parent.lastPoint.x;
|
||||
*y = parent.lastPoint.y;
|
||||
*pointCount = 1;
|
||||
return true;
|
||||
} else {
|
||||
*pointCount = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
bool supportsTouchDriver() override { return true; }
|
||||
|
||||
std::shared_ptr<tt::hal::touch::TouchDriver> _Nullable getTouchDriver() override { return nativeTouch; }
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd_touch esp_lcd_touch_gt911 driver
|
||||
REQUIRES Tactility EspLcdCompat esp_lcd_touch_gt911 driver
|
||||
)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#include <esp_lcd_panel_io_interface.h>
|
||||
#include <esp_lcd_touch.h>
|
||||
#include <EspLcdTouch.h>
|
||||
|
||||
class Gt911Touch final : public tt::hal::touch::TouchDevice {
|
||||
class Gt911Touch final : public EspLcdTouch {
|
||||
|
||||
public:
|
||||
|
||||
@@ -52,11 +51,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() override;
|
||||
|
||||
public:
|
||||
|
||||
@@ -64,10 +64,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"; }
|
||||
};
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) 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;
|
||||
|
||||
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; };
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9488 driver
|
||||
REQUIRES Tactility EspLcdCompat esp_lcd_ili9488 driver
|
||||
)
|
||||
|
||||
@@ -6,11 +6,9 @@
|
||||
#include <esp_lcd_panel_commands.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "ili9488"
|
||||
|
||||
bool Ili9488Display::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
#define TAG "ILI9488"
|
||||
|
||||
bool Ili9488Display::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,10 +33,10 @@ bool Ili9488Display::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 Ili9488Display::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,
|
||||
@@ -51,14 +49,7 @@ bool Ili9488Display::start() {
|
||||
.vendor_config = nullptr
|
||||
};
|
||||
|
||||
uint32_t buffer_size;
|
||||
if (configuration->bufferSize == 0) {
|
||||
buffer_size = configuration->horizontalResolution * configuration->verticalResolution / 20;
|
||||
} else {
|
||||
buffer_size = configuration->bufferSize;
|
||||
}
|
||||
|
||||
if (esp_lcd_new_panel_ili9488(ioHandle, &panel_config, buffer_size, &panelHandle) != ESP_OK) {
|
||||
if (esp_lcd_new_panel_ili9488(ioHandle, &panel_config, configuration->bufferSize, &panelHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to create panel");
|
||||
return false;
|
||||
}
|
||||
@@ -93,11 +84,16 @@ bool Ili9488Display::start() {
|
||||
return false;
|
||||
}
|
||||
|
||||
const lvgl_port_display_cfg_t disp_cfg = {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
lvgl_port_display_cfg_t Ili9488Display::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,26 +114,4 @@ bool Ili9488Display::start() {
|
||||
.direct_mode = false
|
||||
}
|
||||
};
|
||||
|
||||
displayHandle = lvgl_port_add_disp(&disp_cfg);
|
||||
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool Ili9488Display::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;
|
||||
}
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
|
||||
#include <driver/spi_common.h>
|
||||
#include <EspLcdDisplay.h>
|
||||
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_types.h>
|
||||
#include <functional>
|
||||
#include <lvgl.h>
|
||||
|
||||
class Ili9488Display final : public tt::hal::display::DisplayDevice {
|
||||
class Ili9488Display final : public EspLcdDisplay {
|
||||
|
||||
public:
|
||||
|
||||
@@ -39,8 +38,11 @@ public:
|
||||
mirrorY(mirrorY),
|
||||
invertColor(invertColor),
|
||||
bufferSize(bufferSize),
|
||||
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;
|
||||
@@ -62,9 +64,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) 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;
|
||||
|
||||
public:
|
||||
|
||||
@@ -72,24 +77,19 @@ public:
|
||||
assert(configuration != nullptr);
|
||||
}
|
||||
|
||||
std::string getName() const final { return "ILI9488"; }
|
||||
std::string getDescription() const final { return "ILI9488 display"; }
|
||||
std::string getName() const override { return "ILI9488"; }
|
||||
|
||||
bool start() final;
|
||||
std::string getDescription() const override { return "ILI9488 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; }
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const final { return displayHandle; }
|
||||
bool supportsBacklightDuty() const override { return configuration->backlightDutyFunction != nullptr; }
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd driver
|
||||
REQUIRES Tactility driver EspLcdCompat
|
||||
)
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
#include <esp_lcd_panel_st7789.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "st7789"
|
||||
constexpr auto 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,
|
||||
@@ -86,18 +91,16 @@ bool St7789Display::start() {
|
||||
TT_LOG_E(TAG, "Failed to turn display on");
|
||||
return false;
|
||||
}
|
||||
uint32_t buffer_size;
|
||||
if (configuration->bufferSize == 0) {
|
||||
buffer_size = configuration->horizontalResolution * configuration->verticalResolution / 10;
|
||||
} else {
|
||||
buffer_size = configuration->bufferSize;
|
||||
}
|
||||
|
||||
const lvgl_port_display_cfg_t disp_cfg = {
|
||||
return true;
|
||||
}
|
||||
|
||||
lvgl_port_display_cfg_t St7789Display::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) {
|
||||
return lvgl_port_display_cfg_t {
|
||||
.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,30 +121,7 @@ bool St7789Display::start() {
|
||||
.direct_mode = false
|
||||
}
|
||||
};
|
||||
|
||||
displayHandle = lvgl_port_add_disp(&disp_cfg);
|
||||
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool St7789Display::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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note:
|
||||
* The datasheet implies this should work, but it doesn't:
|
||||
@@ -174,7 +154,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,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
#include <EspLcdDisplay.h>
|
||||
#include <Tactility/hal/display/DisplayDevice.h>
|
||||
|
||||
#include <driver/spi_common.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:
|
||||
|
||||
@@ -40,7 +40,11 @@ public:
|
||||
invertColor(invertColor),
|
||||
bufferSize(bufferSize),
|
||||
touch(std::move(touch))
|
||||
{}
|
||||
{
|
||||
if (this->bufferSize == 0) {
|
||||
this->bufferSize = horizontalResolution * verticalResolution / 10;
|
||||
}
|
||||
}
|
||||
|
||||
esp_lcd_spi_bus_handle_t spiBusHandle;
|
||||
gpio_num_t csPin;
|
||||
@@ -62,9 +66,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& ioHandle) 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;
|
||||
|
||||
public:
|
||||
|
||||
@@ -72,27 +79,22 @@ public:
|
||||
assert(configuration != nullptr);
|
||||
}
|
||||
|
||||
std::string getName() const final { return "ST7789"; }
|
||||
std::string getDescription() const final { return "ST7789 display"; }
|
||||
std::string getName() const override { return "ST7789"; }
|
||||
|
||||
bool start() final;
|
||||
std::string getDescription() const override { return "ST7789 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; };
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const final { return displayHandle; }
|
||||
void setGammaCurve(uint8_t index) override;
|
||||
uint8_t getGammaCurveCount() const override { return 4; };
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd_st7796 driver
|
||||
REQUIRES Tactility EspLcdCompat esp_lcd_st7796 driver
|
||||
)
|
||||
|
||||
@@ -2,16 +2,13 @@
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <esp_lcd_panel_commands.h>
|
||||
#include <esp_lcd_panel_dev.h>
|
||||
#include <esp_lcd_st7796.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "st7796"
|
||||
|
||||
bool St7796Display::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
constexpr auto TAG = "ST7796";
|
||||
|
||||
bool St7796Display::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) {
|
||||
const esp_lcd_panel_io_spi_config_t panel_io_config = {
|
||||
.cs_gpio_num = configuration->csPin,
|
||||
.dc_gpio_num = configuration->dcPin,
|
||||
@@ -36,11 +33,10 @@ bool St7796Display::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, &ioHandle) == ESP_OK;
|
||||
}
|
||||
|
||||
bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) {
|
||||
static const st7796_lcd_init_cmd_t lcd_init_cmds[] = {
|
||||
{0x01, (uint8_t[]) {0x00}, 0, 120},
|
||||
{0x11, (uint8_t[]) {0x00}, 0, 120},
|
||||
@@ -69,7 +65,6 @@ bool St7796Display::start() {
|
||||
.init_cmds_size = sizeof(lcd_init_cmds) / sizeof(st7796_lcd_init_cmd_t),
|
||||
};
|
||||
|
||||
|
||||
const esp_lcd_panel_dev_config_t panel_config = {
|
||||
.reset_gpio_num = configuration->resetPin, // Set to -1 if not use
|
||||
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
@@ -92,7 +87,7 @@ bool St7796Display::start() {
|
||||
},
|
||||
.vendor_config = nullptr
|
||||
};
|
||||
*/
|
||||
*/
|
||||
if (esp_lcd_new_panel_st7796(ioHandle, &panel_config, &panelHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to create panel");
|
||||
return false;
|
||||
@@ -133,18 +128,15 @@ bool St7796Display::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 St7796Display::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,
|
||||
@@ -158,28 +150,6 @@ bool St7796Display::start() {
|
||||
.color_format = LV_COLOR_FORMAT_NATIVE,
|
||||
.flags = {.buff_dma = true, .buff_spiram = false, .sw_rotate = false, .swap_bytes = true, .full_refresh = false, .direct_mode = false}
|
||||
};
|
||||
|
||||
displayHandle = lvgl_port_add_disp(&disp_cfg);
|
||||
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
bool St7796Display::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;
|
||||
}
|
||||
|
||||
void St7796Display::setGammaCurve(uint8_t index) {
|
||||
@@ -200,6 +170,7 @@ void St7796Display::setGammaCurve(uint8_t index) {
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
const uint8_t param[] = {
|
||||
gamma_curve
|
||||
};
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/display/DisplayDevice.h"
|
||||
|
||||
#include <EspLcdDisplay.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <driver/spi_common.h>
|
||||
#include <esp_lcd_panel_io.h>
|
||||
#include <esp_lcd_types.h>
|
||||
#include <functional>
|
||||
#include <lvgl.h>
|
||||
|
||||
class St7796Display final : public tt::hal::display::DisplayDevice {
|
||||
class St7796Display final : public EspLcdDisplay {
|
||||
|
||||
public:
|
||||
|
||||
@@ -43,7 +38,11 @@ public:
|
||||
gapX(gapX),
|
||||
gapY(gapY),
|
||||
bufferSize(bufferSize),
|
||||
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;
|
||||
@@ -67,9 +66,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& ioHandle) 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;
|
||||
|
||||
public:
|
||||
|
||||
@@ -77,27 +79,23 @@ public:
|
||||
assert(configuration != nullptr);
|
||||
}
|
||||
|
||||
std::string getName() const final { return "ST7796"; }
|
||||
std::string getDescription() const final { return "ST7796 display"; }
|
||||
std::string getName() const override { return "ST7796"; }
|
||||
|
||||
bool start() final;
|
||||
std::string getDescription() const override { return "ST7796 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);
|
||||
}
|
||||
}
|
||||
|
||||
void setGammaCurve(uint8_t index) final;
|
||||
uint8_t getGammaCurveCount() const final { return 4; };
|
||||
void setGammaCurve(uint8_t index) override;
|
||||
|
||||
bool supportsBacklightDuty() const final { return configuration->backlightDutyFunction != nullptr; }
|
||||
uint8_t getGammaCurveCount() const override { return 4; };
|
||||
|
||||
lv_display_t* _Nullable getLvglDisplay() const final { return displayHandle; }
|
||||
bool supportsBacklightDuty() const override { return configuration->backlightDutyFunction != nullptr; }
|
||||
};
|
||||
|
||||
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lcd_touch esp_lcd_touch_xpt2046
|
||||
REQUIRES Tactility EspLcdCompat esp_lcd_touch_xpt2046
|
||||
)
|
||||
|
||||
@@ -2,11 +2,28 @@
|
||||
#include "Xpt2046Touch.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <Tactility/hal/Device.h>
|
||||
|
||||
#define TAG "xpt2046_power"
|
||||
constexpr auto TAG = "Xpt2046Power";
|
||||
constexpr auto BATTERY_VOLTAGE_MIN = 3.2f;
|
||||
constexpr auto BATTERY_VOLTAGE_MAX = 4.2f;
|
||||
constexpr auto MAX_VOLTAGE_SAMPLES = 15;
|
||||
|
||||
#define BATTERY_VOLTAGE_MIN 3.2f
|
||||
#define BATTERY_VOLTAGE_MAX 4.2f
|
||||
static std::shared_ptr<Xpt2046Touch> findXp2046TouchDevice() {
|
||||
// Make a safe copy
|
||||
auto touch = tt::hal::findFirstDevice<tt::hal::touch::TouchDevice>(tt::hal::Device::Type::Touch);
|
||||
if (touch == nullptr) {
|
||||
TT_LOG_E(TAG, "Touch device not found");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (touch->getName() != "XPT2046") {
|
||||
TT_LOG_E(TAG, "Touch device name mismatch");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return std::reinterpret_pointer_cast<Xpt2046Touch>(touch);
|
||||
}
|
||||
|
||||
static uint8_t estimateChargeLevelFromVoltage(uint32_t milliVolt) {
|
||||
float volts = std::min((float)milliVolt / 1000.f, BATTERY_VOLTAGE_MAX);
|
||||
@@ -47,25 +64,26 @@ bool Xpt2046Power::getMetric(MetricType type, MetricData& data) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Xpt2046Power::readBatteryVoltageOnce(uint32_t& output) const {
|
||||
// Make a safe copy
|
||||
auto touch = Xpt2046Touch::getInstance();
|
||||
if (touch != nullptr) {
|
||||
float vbat;
|
||||
if (touch->getVBat(vbat)) {
|
||||
// Convert to mV
|
||||
output = (uint32_t)(vbat * 1000.f);
|
||||
return true;
|
||||
bool Xpt2046Power::readBatteryVoltageOnce(uint32_t& output) {
|
||||
if (xptTouch == nullptr) {
|
||||
xptTouch = findXp2046TouchDevice();
|
||||
if (xptTouch == nullptr) {
|
||||
TT_LOG_E(TAG, "XPT2046 touch device not found");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
float vbat;
|
||||
if (!xptTouch->getVBat(vbat)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert to mV
|
||||
output = (uint32_t)(vbat * 1000.f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#define MAX_VOLTAGE_SAMPLES 15
|
||||
|
||||
bool Xpt2046Power::readBatteryVoltageSampled(uint32_t& output) const {
|
||||
bool Xpt2046Power::readBatteryVoltageSampled(uint32_t& output) {
|
||||
size_t samples_read = 0;
|
||||
uint32_t sample_accumulator = 0;
|
||||
uint32_t sample_read_buffer;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/power/PowerDevice.h>
|
||||
#include <memory>
|
||||
|
||||
class Xpt2046Touch;
|
||||
using tt::hal::power::PowerDevice;
|
||||
|
||||
/**
|
||||
@@ -11,9 +11,13 @@ using tt::hal::power::PowerDevice;
|
||||
*/
|
||||
class Xpt2046Power : public PowerDevice {
|
||||
|
||||
std::shared_ptr<Xpt2046Touch> xptTouch;
|
||||
|
||||
bool readBatteryVoltageOnce(uint32_t& output);
|
||||
bool readBatteryVoltageSampled(uint32_t& output);
|
||||
|
||||
public:
|
||||
|
||||
Xpt2046Power() = default;
|
||||
~Xpt2046Power() = default;
|
||||
|
||||
std::string getName() const final { return "XPT2046 Power Measurement"; }
|
||||
@@ -22,10 +26,6 @@ public:
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(MetricType type, MetricData& data) override;
|
||||
|
||||
private:
|
||||
|
||||
bool readBatteryVoltageOnce(uint32_t& output) const;
|
||||
bool readBatteryVoltageSampled(uint32_t& output) const;
|
||||
};
|
||||
|
||||
std::shared_ptr<PowerDevice> getOrCreatePower();
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
#include <esp_lcd_touch_xpt2046.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "xpt2046_touch"
|
||||
|
||||
Xpt2046Touch* Xpt2046Touch::instance = nullptr;
|
||||
|
||||
bool Xpt2046Touch::start(lv_display_t* display) {
|
||||
bool Xpt2046Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
|
||||
const esp_lcd_panel_io_spi_config_t io_config = ESP_LCD_TOUCH_IO_SPI_XPT2046_CONFIG(configuration->spiPinCs);
|
||||
return esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &outHandle) == ESP_OK;
|
||||
}
|
||||
|
||||
if (esp_lcd_new_panel_io_spi(SPI2_HOST, &io_config, &ioHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Touch IO SPI creation failed");
|
||||
return false;
|
||||
}
|
||||
bool Xpt2046Touch::createTouchHandle(esp_lcd_panel_io_handle_t ioHandle, const esp_lcd_touch_config_t& config, esp_lcd_touch_handle_t& panelHandle) {
|
||||
return esp_lcd_touch_new_spi_xpt2046(ioHandle, &config, &panelHandle) == ESP_OK;
|
||||
}
|
||||
|
||||
esp_lcd_touch_config_t config = {
|
||||
esp_lcd_touch_config_t Xpt2046Touch::createEspLcdTouchConfig() {
|
||||
return {
|
||||
.x_max = configuration->xMax,
|
||||
.y_max = configuration->yMax,
|
||||
.rst_gpio_num = GPIO_NUM_NC,
|
||||
@@ -38,61 +38,20 @@ bool Xpt2046Touch::start(lv_display_t* display) {
|
||||
.user_data = nullptr,
|
||||
.driver_data = nullptr
|
||||
};
|
||||
|
||||
if (esp_lcd_touch_new_spi_xpt2046(ioHandle, &config, &touchHandle) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "XPT2046 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;
|
||||
}
|
||||
|
||||
instance = this;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Xpt2046Touch::stop() {
|
||||
instance = nullptr;
|
||||
cleanup();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Xpt2046Touch::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;
|
||||
}
|
||||
}
|
||||
|
||||
bool Xpt2046Touch::getVBat(float& outputVbat) {
|
||||
if (touchHandle != nullptr) {
|
||||
// Shares the SPI bus with the display, so we have to sync/lock as this method might be called from anywhere
|
||||
if (tt::lvgl::lock(50 / portTICK_PERIOD_MS)) {
|
||||
esp_lcd_touch_xpt2046_read_battery_level(touchHandle, &outputVbat);
|
||||
tt::lvgl::unlock();
|
||||
return true;
|
||||
}
|
||||
auto touch_handle = getTouchHandle();
|
||||
if (touch_handle == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
// Shares the SPI bus with the display, so we have to sync/lock as this method might be called from anywhere
|
||||
if (!tt::lvgl::lock(50 / portTICK_PERIOD_MS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
esp_lcd_touch_xpt2046_read_battery_level(touch_handle, &outputVbat);
|
||||
tt::lvgl::unlock();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "Tactility/hal/touch/TouchDevice.h"
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <EspLcdTouch.h>
|
||||
|
||||
#include <esp_lcd_panel_io_interface.h>
|
||||
#include <esp_lcd_touch.h>
|
||||
|
||||
class Xpt2046Touch : public tt::hal::touch::TouchDevice {
|
||||
class Xpt2046Touch : public EspLcdTouch {
|
||||
|
||||
public:
|
||||
|
||||
@@ -45,11 +42,12 @@ private:
|
||||
static Xpt2046Touch* instance;
|
||||
|
||||
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() override;
|
||||
|
||||
public:
|
||||
|
||||
@@ -58,14 +56,8 @@ public:
|
||||
}
|
||||
|
||||
std::string getName() const final { return "XPT2046"; }
|
||||
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 getDescription() const final { return "XPT2046 I2C touch driver"; }
|
||||
|
||||
bool getVBat(float& outputVbat);
|
||||
|
||||
/** Used for accessing getVBat() in Power driver */
|
||||
static Xpt2046Touch* getInstance() { return instance; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user