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,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; }
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user