Compare commits

..

No commits in common. "35d1ca6f3b916f7375a1cf3a725d852c35e7d4f4" and "1dea7fc87d3575564c5e1050ec26dd19082a1b53" have entirely different histories.

44 changed files with 563 additions and 324 deletions

View File

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

View File

@ -5,6 +5,8 @@
#include <PwmBacklight.h>
#include <St7789Display.h>
#define TAG "crowpanel_display"
static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
// Note for future changes: Reset pin is 48 and interrupt pin is 47
auto configuration = std::make_unique<Ft5x06Touch::Configuration>(
@ -37,6 +39,5 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
auto display = std::make_shared<St7789Display>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
return std::make_shared<St7789Display>(std::move(configuration));
}

View File

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

View File

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

View File

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

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

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

View File

@ -1,5 +1,40 @@
#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; }
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

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

View File

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

View File

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

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_lcd ST7796 BQ27220 TCA8418 PwmBacklight driver esp_adc
REQUIRES Tactility esp_lvgl_port esp_lcd ST7796 BQ27220 TCA8418 PwmBacklight driver esp_adc
)

View File

@ -6,6 +6,8 @@
#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,
@ -24,6 +26,5 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->backlightDutyFunction = driver::pwmbacklight::setBacklightDuty;
auto display = std::make_shared<St7796Display>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
return std::make_shared<St7796Display>(std::move(configuration));
}

View File

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

View File

@ -1,5 +1,6 @@
#pragma once
#include <Tactility/TactilityCore.h>
#include <Tactility/hal/keyboard/KeyboardDevice.h>
#include <Tca8418.h>
@ -9,7 +10,10 @@
#include <Tactility/Timer.h>
class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice {
class TpagerKeyboard : public tt::hal::keyboard::KeyboardDevice {
private:
lv_indev_t* _Nullable kbHandle = nullptr;
lv_indev_t* _Nullable encHandle = nullptr;
@ -32,13 +36,13 @@ class TpagerKeyboard final : public tt::hal::keyboard::KeyboardDevice {
public:
TpagerKeyboard(std::shared_ptr<Tca8418> tca) : keypad(std::move(tca)) {}
~TpagerKeyboard() {}
std::string getName() const override { return "T-Lora Pager Keyboard"; }
std::string getDescription() const override { return "T-Lora Pager I2C keyboard with encoder"; }
std::string getName() const final { return "T-Lora Pager Keyboard"; }
std::string getDescription() const final { return "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,13 +6,10 @@
std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
auto configuration = std::make_unique<Ft6x36Touch::Configuration>(
I2C_NUM_0,
GPIO_NUM_39,
CORE2_LCD_HORIZONTAL_RESOLUTION,
CORE2_LCD_VERTICAL_RESOLUTION
GPIO_NUM_39
);
auto touch = std::make_shared<Ft6x36Touch>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::touch::TouchDevice>(touch);
return std::make_shared<Ft6x36Touch>(std::move(configuration));
}
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
@ -31,6 +28,5 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
true
);
auto display = std::make_shared<Ili934xDisplay>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
return std::make_shared<Ili934xDisplay>(std::move(configuration));
}

View File

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

View File

@ -1,4 +1,5 @@
#include "CoreS3Display.h"
#include "CoreS3Constants.h"
#include <Ft5x06Touch.h>
@ -6,7 +7,7 @@
#include <Tactility/Log.h>
#include <Tactility/hal/i2c/I2c.h>
constexpr auto TAG = "CoreS3Display";
#define TAG "cores3"
static void setBacklightDuty(uint8_t backlightDuty) {
const uint8_t voltage = 20 + ((8 * backlightDuty) / 255); // [0b00000, 0b11100] - under 20 is too dark
@ -24,8 +25,7 @@ static std::shared_ptr<tt::hal::touch::TouchDevice> createTouch() {
240
);
auto touch = std::make_shared<Ft5x06Touch>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::touch::TouchDevice>(touch);
return std::make_shared<Ft5x06Touch>(std::move(configuration));
}
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
@ -46,6 +46,5 @@ std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay() {
configuration->backlightDutyFunction = ::setBacklightDuty;
auto display = std::make_shared<Ili934xDisplay>(std::move(configuration));
return std::reinterpret_pointer_cast<tt::hal::display::DisplayDevice>(display);
return std::make_shared<Ili934xDisplay>(std::move(configuration));
}

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

@ -1,6 +1,5 @@
# TODOs
- Revisit TinyUSB mouse idea: the bugs related to cleanup seem to be fixed in the library.
- Bug: When a Wi-Fi SSID is too long, then it fails to save the credentials
- Add a Keyboard setting app to override the behaviour of soft keyboard hiding (e.g. keyboard hardware is present, but the user wants to use a soft keyboard)
- HAL for display touch calibration

View File

@ -15,8 +15,6 @@ class EspLcdTouch : public tt::hal::touch::TouchDevice {
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;

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility EspLcdCompat esp_lcd_touch_ft5x06 driver
REQUIRES Tactility esp_lvgl_port esp_lcd_touch esp_lcd_touch_ft5x06 driver
)

View File

@ -8,17 +8,15 @@
#define TAG "ft5x06"
bool Ft5x06Touch::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
bool Ft5x06Touch::start(lv_display_t* display) {
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;
}
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;
}
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;
}
esp_lcd_touch_config_t Ft5x06Touch::createEspLcdTouchConfig() {
return {
esp_lcd_touch_config_t config = {
.x_max = configuration->xMax,
.y_max = configuration->yMax,
.rst_gpio_num = configuration->pinReset,
@ -37,4 +35,47 @@ esp_lcd_touch_config_t Ft5x06Touch::createEspLcdTouchConfig() {
.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;
}
}

View File

@ -4,9 +4,10 @@
#include <Tactility/TactilityCore.h>
#include <driver/i2c.h>
#include <EspLcdTouch.h>
#include <esp_lcd_panel_io_interface.h>
#include <esp_lcd_touch.h>
class Ft5x06Touch final : public EspLcdTouch {
class Ft5x06Touch final : public tt::hal::touch::TouchDevice {
public:
@ -51,12 +52,11 @@ 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;
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;
void cleanup();
public:
@ -64,7 +64,10 @@ public:
assert(configuration != nullptr);
}
std::string getName() const override { return "FT5x06"; }
bool start(lv_display_t* display) override;
bool stop() override;
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
std::string getDescription() const override { return "FT5x06 I2C touch driver"; }
std::string getName() const final { return "FT5x06"; }
std::string getDescription() const final { return "I2C Touch Driver"; }
};

View File

@ -1,6 +1,5 @@
#include "Ft6x36Touch.h"
#include <Ft6x36Touch.h>
#include <Tactility/Log.h>
#include <esp_err.h>
@ -8,23 +7,22 @@
#define TAG "ft6x36"
void Ft6x36Touch::touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) {
static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) {
auto* touch = (Ft6x36Touch*)lv_indev_get_driver_data(indev);
touch->mutex.lock();
data->point = touch->lastPoint;
data->state = touch->lastState;
touch->mutex.unlock();
touch->readLast(data);
}
Ft6x36Touch::Ft6x36Touch(std::unique_ptr<Configuration> inConfiguration) :
configuration(std::move(inConfiguration)) {
nativeTouch = std::make_shared<Ft6NativeTouch>(*this);
}
configuration(std::move(inConfiguration)),
driverThread(tt::Thread("ft6x36", 4096, [this]() {
driverThreadMain();
return 0;
}))
{}
Ft6x36Touch::~Ft6x36Touch() {
if (driverThread != nullptr && driverThread->getState() != tt::Thread::State::Stopped) {
interruptDriverThread = true;
driverThread->join();
if (driverThread.getState() != tt::Thread::State::Stopped) {
stop();
}
}
@ -61,7 +59,7 @@ void Ft6x36Touch::driverThreadMain() {
}
}
bool Ft6x36Touch::shouldInterruptDriverThread() const {
bool Ft6x36Touch::shouldInterruptDriverThread() {
bool interrupt = false;
if (mutex.lock(50 / portTICK_PERIOD_MS)) {
interrupt = interruptDriverThread;
@ -70,65 +68,35 @@ bool Ft6x36Touch::shouldInterruptDriverThread() const {
return interrupt;
}
bool Ft6x36Touch::start() {
TT_LOG_I(TAG, "Start");
bool Ft6x36Touch::start(lv_display_t* display) {
TT_LOG_I(TAG, "start");
if (!driver.begin(FT6X36_DEFAULT_THRESHOLD, configuration->width, configuration->height)) {
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)) {
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::stopLvgl() {
if (deviceHandle == nullptr) {
return false;
}
bool Ft6x36Touch::stop() {
lv_indev_delete(deviceHandle);
deviceHandle = nullptr;
interruptDriverThread = true;
driverThread.join();
return true;
}
void Ft6x36Touch::readLast(lv_indev_data_t* data) {
data->point = lastPoint;
data->state = lastState;
}

View File

@ -15,76 +15,41 @@ public:
Configuration(
i2c_port_t port,
gpio_num_t pinInterrupt,
uint16_t width,
uint16_t height
gpio_num_t pinInterrupt
) : port(port),
pinInterrupt(pinInterrupt),
width(width),
height(height)
pinInterrupt(pinInterrupt)
{}
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);
std::shared_ptr<tt::Thread> driverThread;
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() const;
void driverThreadMain();
static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data);
bool shouldInterruptDriverThread();
public:
explicit Ft6x36Touch(std::unique_ptr<Configuration> inConfiguration);
~Ft6x36Touch() override;
~Ft6x36Touch() final;
std::string getName() const override { return "FT6x36"; }
std::string getDescription() const override { return "FT6x36 I2C touch driver"; }
std::string getName() const final { return "FT6x36"; }
std::string getDescription() const final { return "I2C touch driver"; }
bool start() override;
bool start(lv_display_t* display) override;
bool stop() override;
bool supportsLvgl() const override { return true; }
bool startLvgl(lv_display_t* display) override;
bool stopLvgl() override;
void readLast(lv_indev_data_t* data);
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
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; }
void driverThreadMain();
};

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility EspLcdCompat esp_lcd_touch_gt911 driver
REQUIRES Tactility esp_lvgl_port esp_lcd_touch esp_lcd_touch_gt911 driver
)

View File

@ -4,7 +4,9 @@
#include <Tactility/TactilityCore.h>
#include <driver/i2c.h>
#include <EspLcdTouch.h>
#include <esp_lcd_touch.h>
#include "../../EspLcdCompat/Source/EspLcdTouch.h"
class Gt911Touch final : public EspLcdTouch {
@ -56,7 +58,7 @@ private:
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;
esp_lcd_touch_config_t createEspLcdTouchConfig();
public:

View File

@ -72,11 +72,11 @@ private:
std::unique_ptr<Configuration> configuration;
bool createIoHandle(esp_lcd_panel_io_handle_t& outHandle) override;
bool createIoHandle(esp_lcd_panel_io_handle_t& outHandle);
bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle) override;
bool createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t& panelHandle);
lvgl_port_display_cfg_t getLvglPortDisplayConfig(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);
public:

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility EspLcdCompat esp_lcd_ili9488 driver
REQUIRES Tactility esp_lvgl_port esp_lcd esp_lcd_ili9488 driver
)

View File

@ -6,9 +6,11 @@
#include <esp_lcd_panel_commands.h>
#include <esp_lvgl_port.h>
#define TAG "ILI9488"
#define TAG "ili9488"
bool Ili9488Display::start() {
TT_LOG_I(TAG, "Starting");
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,
@ -33,10 +35,10 @@ bool Ili9488Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
}
};
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) {
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;
}
const esp_lcd_panel_dev_config_t panel_config = {
.reset_gpio_num = configuration->resetPin,
@ -49,7 +51,14 @@ bool Ili9488Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l
.vendor_config = nullptr
};
if (esp_lcd_new_panel_ili9488(ioHandle, &panel_config, configuration->bufferSize, &panelHandle) != ESP_OK) {
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) {
TT_LOG_E(TAG, "Failed to create panel");
return false;
}
@ -84,16 +93,11 @@ bool Ili9488Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_l
return false;
}
return true;
}
lvgl_port_display_cfg_t Ili9488Display::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) {
return {
const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = ioHandle,
.panel_handle = panelHandle,
.control_handle = nullptr,
.buffer_size = configuration->bufferSize,
.buffer_size = buffer_size,
.double_buffer = false,
.trans_size = 0,
.hres = configuration->horizontalResolution,
@ -114,4 +118,26 @@ lvgl_port_display_cfg_t Ili9488Display::getLvglPortDisplayConfig(esp_lcd_panel_i
.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;
}

View File

@ -2,13 +2,14 @@
#include "Tactility/hal/display/DisplayDevice.h"
#include <EspLcdDisplay.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 Ili9488Display final : public EspLcdDisplay {
class Ili9488Display final : public tt::hal::display::DisplayDevice {
public:
@ -38,11 +39,8 @@ public:
mirrorY(mirrorY),
invertColor(invertColor),
bufferSize(bufferSize),
touch(std::move(touch)) {
if (this->bufferSize == 0) {
this->bufferSize = horizontalResolution * verticalResolution / 10;
}
}
touch(std::move(touch))
{}
esp_lcd_spi_bus_handle_t spiBusHandle;
gpio_num_t csPin;
@ -64,12 +62,9 @@ public:
private:
std::unique_ptr<Configuration> configuration;
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;
esp_lcd_panel_io_handle_t ioHandle = nullptr;
esp_lcd_panel_handle_t panelHandle = nullptr;
lv_display_t* displayHandle = nullptr;
public:
@ -77,19 +72,24 @@ public:
assert(configuration != nullptr);
}
std::string getName() const override { return "ILI9488"; }
std::string getName() const final { return "ILI9488"; }
std::string getDescription() const final { return "ILI9488 display"; }
std::string getDescription() const override { return "ILI9488 display"; }
bool start() final;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return configuration->touch; }
bool stop() final;
void setBacklightDuty(uint8_t backlightDuty) override {
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable createTouch() final { return configuration->touch; }
void setBacklightDuty(uint8_t backlightDuty) final {
if (configuration->backlightDutyFunction != nullptr) {
configuration->backlightDutyFunction(backlightDuty);
}
}
bool supportsBacklightDuty() const override { return configuration->backlightDutyFunction != nullptr; }
bool supportsBacklightDuty() const final { return configuration->backlightDutyFunction != nullptr; }
lv_display_t* _Nullable getLvglDisplay() const final { return displayHandle; }
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -7,7 +7,7 @@
#include <esp_lcd_panel_st7789.h>
#include <esp_lvgl_port.h>
constexpr auto TAG = "ST7789";
#define TAG "ST7789"
bool St7789Display::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
TT_LOG_I(TAG, "Starting");
@ -96,11 +96,18 @@ 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 = configuration->bufferSize,
.buffer_size = buffer_size,
.double_buffer = false,
.trans_size = 0,
.hres = configuration->horizontalResolution,

View File

@ -40,11 +40,7 @@ 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;
@ -67,12 +63,6 @@ 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)) {
@ -80,9 +70,14 @@ 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 EspLcdCompat esp_lcd_st7796 driver
REQUIRES Tactility esp_lvgl_port esp_lcd_st7796 driver
)

View File

@ -2,13 +2,16 @@
#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>
constexpr auto TAG = "ST7796";
#define TAG "st7796"
bool St7796Display::start() {
TT_LOG_I(TAG, "Starting");
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,
@ -33,10 +36,11 @@ bool St7796Display::createIoHandle(esp_lcd_panel_io_handle_t& ioHandle) {
}
};
return 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, &ioHandle) != ESP_OK) {
TT_LOG_E(TAG, "Failed to create panel");
return false;
}
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},
@ -65,6 +69,7 @@ bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
.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)
@ -87,7 +92,7 @@ bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
},
.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;
@ -128,15 +133,18 @@ bool St7796Display::createPanelHandle(esp_lcd_panel_io_handle_t ioHandle, esp_lc
return false;
}
return true;
}
uint32_t buffer_size;
if (configuration->bufferSize == 0) {
buffer_size = configuration->horizontalResolution * configuration->verticalResolution / 10;
} else {
buffer_size = configuration->bufferSize;
}
lvgl_port_display_cfg_t St7796Display::getLvglPortDisplayConfig(esp_lcd_panel_io_handle_t ioHandle, esp_lcd_panel_handle_t panelHandle) {
return {
const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = ioHandle,
.panel_handle = panelHandle,
.control_handle = nullptr,
.buffer_size = configuration->bufferSize,
.buffer_size = buffer_size,
.double_buffer = false,
.trans_size = 0,
.hres = configuration->horizontalResolution,
@ -150,6 +158,28 @@ lvgl_port_display_cfg_t St7796Display::getLvglPortDisplayConfig(esp_lcd_panel_io
.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) {
@ -170,7 +200,6 @@ void St7796Display::setGammaCurve(uint8_t index) {
default:
return;
}
const uint8_t param[] = {
gamma_curve
};

View File

@ -1,10 +1,15 @@
#pragma once
#include <EspLcdDisplay.h>
#include <driver/gpio.h>
#include <functional>
#include "Tactility/hal/display/DisplayDevice.h"
class St7796Display final : public EspLcdDisplay {
#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 {
public:
@ -38,11 +43,7 @@ public:
gapX(gapX),
gapY(gapY),
bufferSize(bufferSize),
touch(std::move(touch)) {
if (this->bufferSize == 0) {
this->bufferSize = horizontalResolution * verticalResolution / 10;
}
}
touch(std::move(touch)) {}
esp_lcd_spi_bus_handle_t spiBusHandle;
gpio_num_t csPin;
@ -66,12 +67,9 @@ public:
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;
esp_lcd_panel_io_handle_t ioHandle = nullptr;
esp_lcd_panel_handle_t panelHandle = nullptr;
lv_display_t* displayHandle = nullptr;
public:
@ -79,23 +77,27 @@ public:
assert(configuration != nullptr);
}
std::string getName() const override { return "ST7796"; }
std::string getName() const final { return "ST7796"; }
std::string getDescription() const final { return "ST7796 display"; }
std::string getDescription() const override { return "ST7796 display"; }
bool start() final;
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable getTouchDevice() override { return configuration->touch; }
bool stop() final;
void setBacklightDuty(uint8_t backlightDuty) override {
std::shared_ptr<tt::hal::touch::TouchDevice> _Nullable createTouch() final { return configuration->touch; }
void setBacklightDuty(uint8_t backlightDuty) final {
if (configuration->backlightDutyFunction != nullptr) {
configuration->backlightDutyFunction(backlightDuty);
}
}
void setGammaCurve(uint8_t index) override;
void setGammaCurve(uint8_t index) final;
uint8_t getGammaCurveCount() const final { return 4; };
uint8_t getGammaCurveCount() const override { return 4; };
bool supportsBacklightDuty() const final { return configuration->backlightDutyFunction != nullptr; }
bool supportsBacklightDuty() const override { return configuration->backlightDutyFunction != nullptr; }
lv_display_t* _Nullable getLvglDisplay() const final { return displayHandle; }
};
std::shared_ptr<tt::hal::display::DisplayDevice> createDisplay();

View File

@ -1,5 +1,5 @@
idf_component_register(
SRC_DIRS "Source"
INCLUDE_DIRS "Source"
REQUIRES Tactility EspLcdCompat esp_lcd_touch_xpt2046
REQUIRES Tactility esp_lcd_touch esp_lcd_touch_xpt2046
)

View File

@ -2,28 +2,11 @@
#include "Xpt2046Touch.h"
#include <Tactility/Log.h>
#include <Tactility/hal/Device.h>
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 TAG "xpt2046_power"
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);
}
#define BATTERY_VOLTAGE_MIN 3.2f
#define BATTERY_VOLTAGE_MAX 4.2f
static uint8_t estimateChargeLevelFromVoltage(uint32_t milliVolt) {
float volts = std::min((float)milliVolt / 1000.f, BATTERY_VOLTAGE_MAX);
@ -64,26 +47,25 @@ bool Xpt2046Power::getMetric(MetricType type, MetricData& data) {
}
}
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;
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;
}
}
float vbat;
if (!xptTouch->getVBat(vbat)) {
return false;
}
// Convert to mV
output = (uint32_t)(vbat * 1000.f);
return true;
return false;
}
bool Xpt2046Power::readBatteryVoltageSampled(uint32_t& output) {
#define MAX_VOLTAGE_SAMPLES 15
bool Xpt2046Power::readBatteryVoltageSampled(uint32_t& output) const {
size_t samples_read = 0;
uint32_t sample_accumulator = 0;
uint32_t sample_read_buffer;

View File

@ -1,8 +1,8 @@
#pragma once
#include <Tactility/hal/power/PowerDevice.h>
#include <memory>
class Xpt2046Touch;
using tt::hal::power::PowerDevice;
/**
@ -11,13 +11,9 @@ 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"; }
@ -26,6 +22,10 @@ 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();

View File

@ -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::createIoHandle(esp_lcd_panel_io_handle_t& outHandle) {
bool Xpt2046Touch::start(lv_display_t* display) {
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;
}
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;
}
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;
}
esp_lcd_touch_config_t Xpt2046Touch::createEspLcdTouchConfig() {
return {
esp_lcd_touch_config_t config = {
.x_max = configuration->xMax,
.y_max = configuration->yMax,
.rst_gpio_num = GPIO_NUM_NC,
@ -38,20 +38,61 @@ esp_lcd_touch_config_t Xpt2046Touch::createEspLcdTouchConfig() {
.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) {
auto touch_handle = getTouchHandle();
if (touch_handle == nullptr) {
return false;
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;
}
}
// 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;
return false;
}

View File

@ -1,11 +1,13 @@
#pragma once
#include <Tactility/hal/touch/TouchDevice.h>
#include "Tactility/hal/touch/TouchDevice.h"
#include <Tactility/TactilityCore.h>
#include <esp_lcd_panel_io_interface.h>
#include <EspLcdTouch.h>
#include <esp_lcd_touch.h>
class Xpt2046Touch : public EspLcdTouch {
class Xpt2046Touch : public tt::hal::touch::TouchDevice {
public:
@ -43,12 +45,11 @@ 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;
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;
void cleanup();
public:
@ -57,8 +58,14 @@ public:
}
std::string getName() const final { return "XPT2046"; }
std::string getDescription() const final { return "I2C touch driver"; }
std::string getDescription() const final { return "XPT2046 I2C touch driver"; }
bool start(lv_display_t* display) override;
bool stop() override;
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
bool getVBat(float& outputVbat);
/** Used for accessing getVBat() in Power driver */
static Xpt2046Touch* getInstance() { return instance; }
};