Board update

This commit is contained in:
Ken Van Hoeylandt 2025-08-16 00:13:11 +02:00
parent b64bb79b0c
commit c3a20c16c5
18 changed files with 174 additions and 211 deletions

View File

@ -42,5 +42,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->mirrorX = true;
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
return std::make_shared<Ili9488Display>(std::move(configuration));
auto display = std::make_shared<Ili9488Display>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -1,40 +1,5 @@
#pragma once
#include "Tactility/hal/display/DisplayDevice.h"
#include <esp_lcd_types.h>
#include <lvgl.h>
class CrowPanelDisplay : 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; }
};
#include <Tactility/hal/display/DisplayDevice.h>
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -3,8 +3,6 @@
#include <Tactility/lvgl/LvglSync.h>
#include <Tactility/hal/sdcard/SpiSdCardDevice.h>
#include <esp_vfs_fat.h>
using tt::hal::sdcard::SpiSdCardDevice;
std::shared_ptr<SdCardDevice> createSdCard() {

View File

@ -101,5 +101,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
driver::pwmbacklight::setBacklightDuty
);
return std::make_shared<RgbDisplay>(std::move(configuration));
auto display = std::make_shared<RgbDisplay>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -1,5 +1,5 @@
#pragma once
#include "Tactility/hal/display/DisplayDevice.h"
#include <Tactility/hal/display/DisplayDevice.h>
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -3,5 +3,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
idf_component_register(
SRCS ${SOURCE_FILES}
INCLUDE_DIRS "Source"
REQUIRES Tactility esp_lvgl_port esp_lcd ST7796 BQ27220 TCA8418 PwmBacklight driver esp_adc
REQUIRES Tactility esp_lcd ST7796 BQ27220 TCA8418 PwmBacklight driver esp_adc
)

View File

@ -6,8 +6,6 @@
#include <driver/spi_master.h>
#define TAG "TPAGER_display"
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
auto configuration = std::make_unique<St7796Display::Configuration>(
TPAGER_LCD_SPI_HOST,
@ -26,5 +24,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
return std::make_shared<St7796Display>(std::move(configuration));
auto display = std::make_shared<St7796Display>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -1,40 +1,5 @@
#pragma once
#include "Tactility/hal/display/DisplayDevice.h"
#include <esp_lcd_types.h>
#include <lvgl.h>
class TpagerDisplay : 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 "ST7796"; }
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; }
};
#include <Tactility/hal/display/DisplayDevice.h>
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -1,6 +1,5 @@
#pragma once
#include <Tactility/TactilityCore.h>
#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tca8418.h>
@ -10,10 +9,7 @@
#include <Tactility/Timer.h>
class TpagerKeyboard : public tt::hal::keyboard::KeyboardDevice {
private:
class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice {
lv_indev_t* _Nullable kbHandle = nullptr;
lv_indev_t* _Nullable encHandle = nullptr;
@ -36,13 +32,13 @@ private:
public:
TpagerKeyboard(std::shared_ptr<Tca8418> tca) : keypad(std::move(tca)) {}
~TpagerKeyboard() {}
std::string getName() const final { return "T-Lora Pager Keyboard"; }
std::string getDescription() const final { return "I2C keyboard with encoder"; }
std::string getName() const override { return "T-Lora Pager Keyboard"; }
std::string getDescription() const override { return "T-Lora Pager I2C keyboard with encoder"; }
bool startLvgl(lv_display_t* display) override;
bool stopLvgl() override;
bool isAttached() const override;
lv_indev_t* _Nullable getLvglIndev() override { return kbHandle; }

View File

@ -6,10 +6,13 @@
std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
auto configuration = std::make_unique<Ft6x36Touch::Configuration>(
I2C_NUM_0,
GPIO_NUM_39
GPIO_NUM_39,
CORE2_LCD_HORIZONTAL_RESOLUTION,
CORE2_LCD_VERTICAL_RESOLUTION
);
return std::make_shared<Ft6x36Touch>(std::move(configuration));
auto touch = std::make_shared<Ft6x36Touch>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::touch::TouchDevice>(touch);
}
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
@ -28,5 +31,6 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
true
);
return std::make_shared<Ili934xDisplay>(std::move(configuration));
auto display = std::make_shared<Ili934xDisplay>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
}

View File

@ -2,7 +2,7 @@
#include <Tactility/TactilityCore.h>
#include "axp192/axp192.h"
#define TAG "core2_power"
constexpr auto TAG = "Core2Power";
extern axp192_t axpDevice;

View File

@ -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<Ft6NativeTouch>(*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;
}

View File

@ -15,41 +15,76 @@ 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::NativeTouch> 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 Ft6NativeTouch : public tt::hal::touch::NativeTouch {
public:
const Ft6x36Touch& parent;
Ft6NativeTouch(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;
}
}
};
std::shared_ptr<tt::hal::touch::NativeTouch> _Nullable getNativeTouch() override { return nativeTouch; }
};

View File

@ -7,7 +7,7 @@
#include <esp_lcd_panel_st7789.h>
#include <esp_lvgl_port.h>
#define TAG "ST7789"
constexpr auto TAG = "ST7789";
bool St7789Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
TT_LOG_I(TAG, "Starting");
@ -96,18 +96,11 @@ bool St7789Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
}
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;
} else {
buffer_size = configuration->bufferSize;
}
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,

View File

@ -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;
@ -63,6 +67,12 @@ private:
std::unique_ptr<Configuration> configuration;
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:
explicit St7789Display(std::unique_ptr<Configuration> inConfiguration) : configuration(std::move(inConfiguration)) {
@ -70,14 +80,9 @@ public:
}
std::string getName() const override { return "ST7789"; }
std::string getDescription() const override { return "ST7789 display"; }
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;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return configuration->touch; }
void setBacklightDuty(uint8_t backlightDuty) override {

View File

@ -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
)

View File

@ -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
};

View File

@ -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();