Driver improvements (#226)
- Created driver subprojects: `FT5x06`, `FT6x36`, `CST816S`. - Refactored existing projects to use new drivers. - Improve `PwmBacklight` driver: expose frequency, channel id and timer id - Update `build-and-release-all.sh` for recent board addition
This commit is contained in:
committed by
GitHub
parent
6e8fbae62b
commit
933bc5fb97
@@ -0,0 +1,5 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "Source"
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port esp_lcd_touch esp_lcd_touch_cst816s driver
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
# CST816S
|
||||
|
||||
I2C touch driver for Tactility
|
||||
@@ -0,0 +1,69 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <esp_lcd_touch.h>
|
||||
|
||||
class Cst816sTouch final : public tt::hal::touch::TouchDevice {
|
||||
|
||||
public:
|
||||
|
||||
class Configuration {
|
||||
public:
|
||||
|
||||
Configuration(
|
||||
i2c_port_t port,
|
||||
uint16_t xMax,
|
||||
uint16_t yMax,
|
||||
bool swapXy = false,
|
||||
bool mirrorX = false,
|
||||
bool mirrorY = false,
|
||||
gpio_num_t pinReset = GPIO_NUM_NC,
|
||||
gpio_num_t pinInterrupt = GPIO_NUM_NC,
|
||||
unsigned int pinResetLevel = 0,
|
||||
unsigned int pinInterruptLevel = 0
|
||||
) : port(port),
|
||||
xMax(xMax),
|
||||
yMax(yMax),
|
||||
swapXY(swapXy),
|
||||
mirrorX(mirrorX),
|
||||
mirrorY(mirrorY),
|
||||
pinReset(pinReset),
|
||||
pinInterrupt(pinInterrupt),
|
||||
pinResetLevel(pinResetLevel),
|
||||
pinInterruptLevel(pinInterruptLevel)
|
||||
{}
|
||||
|
||||
i2c_port_t port;
|
||||
uint16_t xMax;
|
||||
uint16_t yMax;
|
||||
bool swapXY;
|
||||
bool mirrorX;
|
||||
bool mirrorY;
|
||||
gpio_num_t pinReset;
|
||||
gpio_num_t pinInterrupt;
|
||||
unsigned int pinResetLevel;
|
||||
unsigned int pinInterruptLevel;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<Configuration> configuration;
|
||||
esp_lcd_panel_io_handle_t ioHandle = nullptr;
|
||||
esp_lcd_touch_handle_t touchHandle = nullptr;
|
||||
lv_indev_t* _Nullable deviceHandle = nullptr;
|
||||
|
||||
void cleanup();
|
||||
|
||||
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; }
|
||||
};
|
||||
@@ -0,0 +1,84 @@
|
||||
#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::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();
|
||||
|
||||
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 = {
|
||||
.x_max = configuration->xMax,
|
||||
.y_max = configuration->yMax,
|
||||
.rst_gpio_num = configuration->pinReset,
|
||||
.int_gpio_num = configuration->pinInterrupt,
|
||||
.levels = {
|
||||
.reset = configuration->pinResetLevel,
|
||||
.interrupt = configuration->pinInterruptLevel,
|
||||
},
|
||||
.flags = {
|
||||
.swap_xy = configuration->swapXY,
|
||||
.mirror_x = configuration->mirrorX,
|
||||
.mirror_y = configuration->mirrorY,
|
||||
},
|
||||
.process_coordinates = nullptr,
|
||||
.interrupt_callback = nullptr,
|
||||
.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_lvgl_port esp_lcd_touch esp_lcd_touch_ft5x06 driver
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
# FT5x06
|
||||
|
||||
A Tactility driver for FT5x06 touch.
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "Ft5x06Touch.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <esp_lcd_touch_ft5x06.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "ft5x06"
|
||||
|
||||
bool Ft5x06Touch::start(lv_display_t* display) {
|
||||
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_FT5x06_CONFIG();
|
||||
|
||||
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 config = {
|
||||
.x_max = configuration->xMax,
|
||||
.y_max = configuration->yMax,
|
||||
.rst_gpio_num = configuration->pinReset,
|
||||
.int_gpio_num = configuration->pinInterrupt,
|
||||
.levels = {
|
||||
.reset = configuration->pinResetLevel,
|
||||
.interrupt = configuration->pinInterruptLevel,
|
||||
},
|
||||
.flags = {
|
||||
.swap_xy = configuration->swapXy,
|
||||
.mirror_x = configuration->mirrorX,
|
||||
.mirror_y = configuration->mirrorY,
|
||||
},
|
||||
.process_coordinates = nullptr,
|
||||
.interrupt_callback = nullptr,
|
||||
.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#include <esp_lcd_panel_io_interface.h>
|
||||
#include <esp_lcd_touch.h>
|
||||
|
||||
class Ft5x06Touch final : public tt::hal::touch::TouchDevice {
|
||||
|
||||
public:
|
||||
|
||||
class Configuration {
|
||||
public:
|
||||
|
||||
Configuration(
|
||||
i2c_port_t port,
|
||||
uint16_t xMax,
|
||||
uint16_t yMax,
|
||||
bool swapXy = false,
|
||||
bool mirrorX = false,
|
||||
bool mirrorY = false,
|
||||
gpio_num_t pinReset = GPIO_NUM_NC,
|
||||
gpio_num_t pinInterrupt = GPIO_NUM_NC,
|
||||
unsigned int pinResetLevel = 0,
|
||||
unsigned int pinInterruptLevel = 0
|
||||
) : port(port),
|
||||
xMax(xMax),
|
||||
yMax(yMax),
|
||||
swapXy(swapXy),
|
||||
mirrorX(mirrorX),
|
||||
mirrorY(mirrorY),
|
||||
pinReset(pinReset),
|
||||
pinInterrupt(pinInterrupt),
|
||||
pinResetLevel(pinResetLevel),
|
||||
pinInterruptLevel(pinInterruptLevel)
|
||||
{}
|
||||
|
||||
i2c_port_t port;
|
||||
uint16_t xMax;
|
||||
uint16_t yMax;
|
||||
bool swapXy;
|
||||
bool mirrorX;
|
||||
bool mirrorY;
|
||||
gpio_num_t pinReset;
|
||||
gpio_num_t pinInterrupt;
|
||||
unsigned int pinResetLevel;
|
||||
unsigned int pinInterruptLevel;
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
public:
|
||||
|
||||
explicit Ft5x06Touch(std::unique_ptr<Configuration> inConfiguration) : configuration(std::move(inConfiguration)) {
|
||||
assert(configuration != nullptr);
|
||||
}
|
||||
|
||||
bool start(lv_display_t* display) override;
|
||||
bool stop() override;
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
|
||||
|
||||
std::string getName() const final { return "FT5x06"; }
|
||||
std::string getDescription() const final { return "I2C Touch Driver"; }
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c*)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
INCLUDE_DIRS "Source"
|
||||
REQUIRES Tactility esp_lvgl_port driver
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
# FT6x36
|
||||
|
||||
A Tactility driver for FT6x36 touch.
|
||||
@@ -0,0 +1,105 @@
|
||||
#include "Ft6x36Touch.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
#include <esp_err.h>
|
||||
#include <esp_lvgl_port.h>
|
||||
|
||||
#define TAG "ft6x36"
|
||||
|
||||
static void touchReadCallback(lv_indev_t* indev, lv_indev_data_t* data) {
|
||||
auto* touch = (Ft6x36Touch*)lv_indev_get_driver_data(indev);
|
||||
touch->readLast(data);
|
||||
}
|
||||
|
||||
static int32_t threadCallback(void* context) {
|
||||
auto* touch = (Ft6x36Touch*)context;
|
||||
touch->driverThreadMain();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Ft6x36Touch::Ft6x36Touch(std::unique_ptr<Configuration> inConfiguration) :
|
||||
configuration(std::move(inConfiguration)),
|
||||
driverThread(tt::Thread("ft6x36", 4096, threadCallback, this))
|
||||
{}
|
||||
|
||||
Ft6x36Touch::~Ft6x36Touch() {
|
||||
if (driverThread.getState() != tt::Thread::State::Stopped) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
|
||||
void Ft6x36Touch::driverThreadMain() {
|
||||
TPoint point = { .x = 0, .y = 0 };
|
||||
TEvent event = TEvent::None;
|
||||
|
||||
while (!shouldInterruptDriverThread()) {
|
||||
driver.processTouch();
|
||||
driver.poll(&point, &event);
|
||||
|
||||
if (mutex.lock(100)) {
|
||||
switch (event) {
|
||||
case TEvent::TouchStart:
|
||||
case TEvent::TouchMove:
|
||||
case TEvent::DragStart:
|
||||
case TEvent::DragMove:
|
||||
case TEvent::DragEnd:
|
||||
lastState = LV_INDEV_STATE_PR;
|
||||
lastPoint.x = point.x;
|
||||
lastPoint.y = point.y;
|
||||
break;
|
||||
case TEvent::TouchEnd:
|
||||
lastState = LV_INDEV_STATE_REL;
|
||||
lastPoint.x = point.x;
|
||||
lastPoint.y = point.y;
|
||||
break;
|
||||
case TEvent::Tap:
|
||||
case TEvent::None:
|
||||
break;
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Ft6x36Touch::shouldInterruptDriverThread() {
|
||||
bool interrupt = false;
|
||||
if (mutex.lock(50 / portTICK_PERIOD_MS)) {
|
||||
interrupt = interruptDriverThread;
|
||||
mutex.unlock();
|
||||
}
|
||||
return interrupt;
|
||||
}
|
||||
|
||||
bool Ft6x36Touch::start(lv_display_t* display) {
|
||||
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)) {
|
||||
TT_LOG_E(TAG, "driver.begin() failed");
|
||||
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() {
|
||||
lv_indev_delete(deviceHandle);
|
||||
interruptDriverThread = true;
|
||||
driverThread.join();
|
||||
return true;
|
||||
}
|
||||
|
||||
void Ft6x36Touch::readLast(lv_indev_data_t* data) {
|
||||
data->point = lastPoint;
|
||||
data->state = lastState;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <Tactility/hal/touch/TouchDevice.h>
|
||||
#include <Tactility/TactilityCore.h>
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#include "ft6x36/FT6X36.h"
|
||||
|
||||
class Ft6x36Touch final : public tt::hal::touch::TouchDevice {
|
||||
|
||||
public:
|
||||
|
||||
class Configuration {
|
||||
public:
|
||||
|
||||
Configuration(
|
||||
i2c_port_t port,
|
||||
gpio_num_t pinInterrupt
|
||||
) : port(port),
|
||||
pinInterrupt(pinInterrupt)
|
||||
{}
|
||||
|
||||
i2c_port_t port;
|
||||
gpio_num_t pinInterrupt;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<Configuration> configuration;
|
||||
lv_indev_t* _Nullable deviceHandle = nullptr;
|
||||
FT6X36 driver = FT6X36(configuration->port, configuration->pinInterrupt);
|
||||
tt::Thread driverThread;
|
||||
bool interruptDriverThread = false;
|
||||
tt::Mutex mutex;
|
||||
|
||||
lv_point_t lastPoint = { .x = 0, .y = 0 };
|
||||
lv_indev_state_t lastState = LV_INDEV_STATE_RELEASED;
|
||||
|
||||
bool shouldInterruptDriverThread();
|
||||
|
||||
public:
|
||||
|
||||
explicit Ft6x36Touch(std::unique_ptr<Configuration> inConfiguration);
|
||||
~Ft6x36Touch() final;
|
||||
|
||||
std::string getName() const final { return "FT6x36"; }
|
||||
std::string getDescription() const final { return "I2C touch driver"; }
|
||||
|
||||
bool start(lv_display_t* display) override;
|
||||
bool stop() override;
|
||||
|
||||
void readLast(lv_indev_data_t* data);
|
||||
lv_indev_t* _Nullable getLvglIndev() override { return deviceHandle; }
|
||||
void driverThreadMain();
|
||||
};
|
||||
@@ -0,0 +1,378 @@
|
||||
#include "FT6X36.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
||||
#define CONFIG_FT6X36_DEBUG false
|
||||
|
||||
FT6X36 *FT6X36::_instance = nullptr;
|
||||
static const char *TAG = "i2c-touch";
|
||||
|
||||
//Handle indicating I2C is ready to read the touch
|
||||
SemaphoreHandle_t TouchSemaphore = xSemaphoreCreateBinary();
|
||||
|
||||
FT6X36::FT6X36(i2c_port_t port, gpio_num_t interruptPin)
|
||||
{
|
||||
_instance = this;
|
||||
_port = port;
|
||||
_intPin = interruptPin;
|
||||
}
|
||||
|
||||
// Destructor should detach interrupt to the pin
|
||||
FT6X36::~FT6X36()
|
||||
{
|
||||
if (_intPin >= 0)
|
||||
gpio_isr_handler_remove((gpio_num_t)_intPin);
|
||||
}
|
||||
|
||||
bool FT6X36::begin(uint8_t threshold, uint16_t width, uint16_t height)
|
||||
{
|
||||
_touch_width = width;
|
||||
_touch_height = height;
|
||||
if (width == 0 || height ==0) {
|
||||
ESP_LOGE(TAG,"begin(uint8_t threshold, uint16_t width, uint16_t height) did not receive the width / height so touch cannot be rotation aware");
|
||||
}
|
||||
|
||||
uint8_t data_panel_id;
|
||||
readRegister8(FT6X36_REG_PANEL_ID, &data_panel_id);
|
||||
|
||||
if (data_panel_id != FT6X36_VENDID) {
|
||||
ESP_LOGE(TAG,"FT6X36_VENDID does not match. Received:0x%x Expected:0x%x\n",data_panel_id,FT6X36_VENDID);
|
||||
return false;
|
||||
}
|
||||
ESP_LOGI(TAG, "\tDevice ID: 0x%02x", data_panel_id);
|
||||
|
||||
uint8_t chip_id;
|
||||
readRegister8(FT6X36_REG_CHIPID, &chip_id);
|
||||
if (chip_id != FT6206_CHIPID && chip_id != FT6236_CHIPID && chip_id != FT6336_CHIPID) {
|
||||
ESP_LOGE(TAG,"FT6206_CHIPID does not match. Received:0x%x\n",chip_id);
|
||||
return false;
|
||||
}
|
||||
ESP_LOGI(TAG, "\tFound touch controller with Chip ID: 0x%02x", chip_id);
|
||||
|
||||
if (_intPin >= 0)
|
||||
{
|
||||
// INT pin triggers the callback function on the Falling edge of the GPIO
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_NEGEDGE; // GPIO_INTR_NEGEDGE repeats always interrupt
|
||||
io_conf.pin_bit_mask = 1ULL<<_intPin;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pull_down_en = (gpio_pulldown_t) 0; // disable pull-down mode
|
||||
io_conf.pull_up_en = (gpio_pullup_t) 1; // pull-up mode
|
||||
gpio_config(&io_conf);
|
||||
|
||||
esp_err_t isr_service = gpio_install_isr_service(0);
|
||||
printf("ISR trigger install response: 0x%x %s\n", isr_service, (isr_service==0)?"ESP_OK":"");
|
||||
gpio_isr_handler_add((gpio_num_t)_intPin, isr, (void*) 1);
|
||||
}
|
||||
|
||||
writeRegister8(FT6X36_REG_DEVICE_MODE, 0x00);
|
||||
writeRegister8(FT6X36_REG_THRESHHOLD, threshold);
|
||||
writeRegister8(FT6X36_REG_TOUCHRATE_ACTIVE, 0x0E);
|
||||
return true;
|
||||
}
|
||||
|
||||
void FT6X36::registerTouchHandler(void (*fn)(TPoint point, TEvent e))
|
||||
{
|
||||
_touchHandler = fn;
|
||||
if (CONFIG_FT6X36_DEBUG) printf("Touch handler function registered\n");
|
||||
}
|
||||
|
||||
uint8_t FT6X36::touched()
|
||||
{
|
||||
uint8_t data_buf;
|
||||
esp_err_t ret = readRegister8(FT6X36_REG_NUM_TOUCHES, &data_buf);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Error reading from device: %s", esp_err_to_name(ret));
|
||||
}
|
||||
|
||||
if (data_buf > 2)
|
||||
{
|
||||
data_buf = 0;
|
||||
}
|
||||
|
||||
return data_buf;
|
||||
}
|
||||
|
||||
void FT6X36::loop()
|
||||
{
|
||||
processTouch();
|
||||
}
|
||||
|
||||
void IRAM_ATTR FT6X36::isr(void* arg)
|
||||
{
|
||||
/* Un-block the interrupt processing task now */
|
||||
xSemaphoreGive(TouchSemaphore);
|
||||
//xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
|
||||
}
|
||||
|
||||
void FT6X36::processTouch()
|
||||
{
|
||||
/* Task move to Block state to wait for interrupt event */
|
||||
if (_intPin >= 0)
|
||||
{
|
||||
if (xSemaphoreTake(TouchSemaphore, portMAX_DELAY) == false) return;
|
||||
}
|
||||
|
||||
readData();
|
||||
uint8_t n = 0;
|
||||
TRawEvent event = (TRawEvent)_touchEvent[n];
|
||||
TPoint point{_touchX[n], _touchY[n]};
|
||||
|
||||
switch (event) {
|
||||
|
||||
case TRawEvent::PressDown:
|
||||
_points[0] = point;
|
||||
_dragMode = false;
|
||||
// Note: Is in microseconds. Ref https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/esp_timer.html
|
||||
_touchStartTime = esp_timer_get_time()/1000;
|
||||
fireEvent(point, TEvent::TouchStart);
|
||||
break;
|
||||
|
||||
case TRawEvent::Contact:
|
||||
// Dragging makes no sense IMHO. Since the X & Y are not getting updated while dragging
|
||||
// Dragging && _points[0].aboutEqual(point) - Not used IDEA 2: && (lastEvent == 2)
|
||||
if (!_dragMode &&
|
||||
(abs(lastX-_touchX[n]) <= maxDeviation || abs(lastY-_touchY[n])<=maxDeviation) &&
|
||||
esp_timer_get_time()/1000 - _touchStartTime > 300) {
|
||||
_dragMode = true;
|
||||
fireEvent(point, TEvent::DragStart);
|
||||
#if defined(CONFIG_FT6X36_DEBUG_EVENTS) && CONFIG_FT6X36_DEBUG_EVENTS==1
|
||||
printf("EV: DragStart\n");
|
||||
#endif
|
||||
|
||||
} else if (_dragMode) {
|
||||
fireEvent(point, TEvent::DragMove);
|
||||
#if defined(CONFIG_FT6X36_DEBUG_EVENTS) && CONFIG_FT6X36_DEBUG_EVENTS==1
|
||||
printf("EV: DragMove\n");
|
||||
#endif
|
||||
}
|
||||
fireEvent(point, TEvent::TouchMove);
|
||||
|
||||
// For me the _touchStartTime shouold be set in both PressDown & Contact events, but after Drag detection
|
||||
_touchStartTime = esp_timer_get_time()/1000;
|
||||
break;
|
||||
|
||||
case TRawEvent::LiftUp:
|
||||
|
||||
_points[9] = point;
|
||||
_touchEndTime = esp_timer_get_time()/1000;
|
||||
|
||||
//printf("TIMEDIFF: %lu End: %lu\n", _touchEndTime - _touchStartTime, _touchEndTime);
|
||||
|
||||
fireEvent(point, TEvent::TouchEnd);
|
||||
if (_dragMode) {
|
||||
fireEvent(point, TEvent::DragEnd);
|
||||
#if defined(CONFIG_FT6X36_DEBUG_EVENTS) && CONFIG_FT6X36_DEBUG_EVENTS==1
|
||||
printf("EV: DragEnd\n");
|
||||
#endif
|
||||
_dragMode = false;
|
||||
}
|
||||
|
||||
if ( _touchEndTime - _touchStartTime <= 900) {
|
||||
// Do not get why this: _points[0].aboutEqual(point) (Original library)
|
||||
fireEvent(point, TEvent::Tap);
|
||||
_points[0] = {0, 0};
|
||||
_touchStartTime = 0;
|
||||
|
||||
#if defined(CONFIG_FT6X36_DEBUG_EVENTS) && CONFIG_FT6X36_DEBUG_EVENTS==1
|
||||
printf("EV: Tap\n");
|
||||
#endif
|
||||
_dragMode = false;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TRawEvent::NoEvent:
|
||||
#if defined(CONFIG_FT6X36_DEBUG_EVENTS) && CONFIG_FT6X36_DEBUG_EVENTS==1
|
||||
printf("EV: NoEvent\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
// Store lastEvent
|
||||
lastEvent = (int) event;
|
||||
lastX = _touchX[0];
|
||||
lastY = _touchY[0];
|
||||
}
|
||||
|
||||
void FT6X36::poll(TPoint * point, TEvent * e)
|
||||
{
|
||||
readData();
|
||||
// TPoint point{_touchX[0], _touchY[0]};
|
||||
TRawEvent event = (TRawEvent)_touchEvent[0];
|
||||
|
||||
if (point != NULL)
|
||||
{
|
||||
point->x = _touchX[0];
|
||||
point->y = _touchY[0];
|
||||
}
|
||||
if (e != NULL)
|
||||
{
|
||||
switch (event)
|
||||
{
|
||||
case TRawEvent::PressDown:
|
||||
*e = TEvent::TouchStart;
|
||||
break;
|
||||
case TRawEvent::Contact:
|
||||
*e = TEvent::TouchMove;
|
||||
break;
|
||||
case TRawEvent::LiftUp:
|
||||
default:
|
||||
*e = TEvent::TouchEnd;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t FT6X36::read8(uint8_t regName) {
|
||||
uint8_t buf;
|
||||
readRegister8(regName, &buf);
|
||||
return buf;
|
||||
}
|
||||
|
||||
#define data_size 16 // Discarding last 2: 0x0E & 0x0F as not relevant
|
||||
bool FT6X36::readData(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
uint8_t data[data_size];
|
||||
uint8_t touch_pnt_cnt; // Number of detected touch points
|
||||
readRegister8(FT6X36_REG_NUM_TOUCHES, &touch_pnt_cnt);
|
||||
|
||||
// Read data
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (FT6X36_ADDR<<1), ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, 0, ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(_port, cmd, 1000 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (FT6X36_ADDR<<1)|1, ACK_CHECK_EN);
|
||||
i2c_master_read(cmd, data, data_size, I2C_MASTER_LAST_NACK);
|
||||
i2c_master_stop(cmd);
|
||||
ret = i2c_master_cmd_begin(_port, cmd, 1000 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
if (CONFIG_FT6X36_DEBUG) {
|
||||
//printf("REGISTERS:\n");
|
||||
for (int16_t i = 0; i < data_size; i++)
|
||||
{
|
||||
printf("%x:%x ", i, data[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
const uint8_t addrShift = 6;
|
||||
|
||||
// READ X, Y and Touch events (X 2)
|
||||
for (uint8_t i = 0; i < 2; i++)
|
||||
{
|
||||
_touchX[i] = data[FT6X36_REG_P1_XH + i * addrShift] & 0x0F;
|
||||
_touchX[i] <<= 8;
|
||||
_touchX[i] |= data[FT6X36_REG_P1_XL + i * addrShift];
|
||||
_touchY[i] = data[FT6X36_REG_P1_YH + i * addrShift] & 0x0F;
|
||||
_touchY[i] <<= 8;
|
||||
_touchY[i] |= data[FT6X36_REG_P1_YL + i * addrShift];
|
||||
_touchEvent[i] = data[FT6X36_REG_P1_XH + i * addrShift] >> 6;
|
||||
}
|
||||
|
||||
// Make _touchX[idx] and _touchY[idx] rotation aware
|
||||
switch (_rotation)
|
||||
{
|
||||
case 1:
|
||||
swap(_touchX[0], _touchY[0]);
|
||||
swap(_touchX[1], _touchY[1]);
|
||||
_touchY[0] = _touch_width - _touchY[0] -1;
|
||||
_touchY[1] = _touch_width - _touchY[1] -1;
|
||||
break;
|
||||
case 2:
|
||||
_touchX[0] = _touch_width - _touchX[0] - 1;
|
||||
_touchX[1] = _touch_width - _touchX[1] - 1;
|
||||
_touchY[0] = _touch_height - _touchY[0] - 1;
|
||||
_touchY[1] = _touch_height - _touchY[1] - 1;
|
||||
break;
|
||||
case 3:
|
||||
swap(_touchX[0], _touchY[0]);
|
||||
swap(_touchX[1], _touchY[1]);
|
||||
_touchX[0] = _touch_height - _touchX[0] - 1;
|
||||
_touchX[1] = _touch_height - _touchX[1] - 1;
|
||||
break;
|
||||
}
|
||||
if (CONFIG_FT6X36_DEBUG) {
|
||||
printf("X0:%d Y0:%d EVENT:%d\n", _touchX[0], _touchY[0], _touchEvent[0]);
|
||||
//printf("X1:%d Y1:%d EVENT:%d\n", _touchX[1], _touchY[1], _touchEvent[1]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void FT6X36::writeRegister8(uint8_t reg, uint8_t value)
|
||||
{
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, FT6X36_ADDR << 1 | I2C_MASTER_WRITE, ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg , ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, value , ACK_CHECK_EN);
|
||||
i2c_master_stop(cmd);
|
||||
i2c_master_cmd_begin(_port, cmd, 1000 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
}
|
||||
|
||||
uint8_t FT6X36::readRegister8(uint8_t reg, uint8_t *data_buf)
|
||||
{
|
||||
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, FT6X36_ADDR << 1 | I2C_MASTER_WRITE, ACK_CHECK_EN);
|
||||
i2c_master_write_byte(cmd, reg, I2C_MASTER_ACK);
|
||||
// Research: Why it's started a 2nd time here
|
||||
i2c_master_start(cmd);
|
||||
i2c_master_write_byte(cmd, (FT6X36_ADDR << 1) | I2C_MASTER_READ, true);
|
||||
|
||||
i2c_master_read_byte(cmd, data_buf, I2C_MASTER_NACK);
|
||||
i2c_master_stop(cmd);
|
||||
esp_err_t ret = i2c_master_cmd_begin(_port, cmd, 1000 / portTICK_PERIOD_MS);
|
||||
i2c_cmd_link_delete(cmd);
|
||||
|
||||
|
||||
//FT6X36_REG_GESTURE_ID. Check if it can be read!
|
||||
#if defined(FT6X36_DEBUG) && FT6X36_DEBUG==1
|
||||
printf("REG 0x%x: 0x%x\n",reg,ret);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void FT6X36::fireEvent(TPoint point, TEvent e)
|
||||
{
|
||||
if (_touchHandler)
|
||||
_touchHandler(point, e);
|
||||
}
|
||||
|
||||
void FT6X36::debugInfo()
|
||||
{
|
||||
printf(" TH_DIFF: %d CTRL: %d\n", read8(FT6X36_REG_FILTER_COEF), read8(FT6X36_REG_CTRL));
|
||||
printf(" TIMEENTERMONITOR: %d PERIODACTIVE: %d\n", read8(FT6X36_REG_TIME_ENTER_MONITOR), read8(FT6X36_REG_TOUCHRATE_ACTIVE));
|
||||
printf(" PERIODMONITOR: %d RADIAN_VALUE: %d\n", read8(FT6X36_REG_TOUCHRATE_MONITOR), read8(FT6X36_REG_RADIAN_VALUE));
|
||||
printf(" OFFSET_LEFT_RIGHT: %d OFFSET_UP_DOWN: %d\n", read8(FT6X36_REG_OFFSET_LEFT_RIGHT), read8(FT6X36_REG_OFFSET_UP_DOWN));
|
||||
printf("DISTANCE_LEFT_RIGHT: %d DISTANCE_UP_DOWN: %d\n", read8(FT6X36_REG_DISTANCE_LEFT_RIGHT), read8(FT6X36_REG_DISTANCE_UP_DOWN));
|
||||
printf(" DISTANCE_ZOOM: %d CIPHER: %d\n", read8(FT6X36_REG_DISTANCE_ZOOM), read8(FT6X36_REG_CHIPID));
|
||||
printf(" G_MODE: %d PWR_MODE: %d\n", read8(FT6X36_REG_INTERRUPT_MODE), read8(FT6X36_REG_POWER_MODE));
|
||||
printf(" FIRMID: %d FOCALTECH_ID: %d STATE: %d\n", read8(FT6X36_REG_FIRMWARE_VERSION), read8(FT6X36_REG_PANEL_ID), read8(FT6X36_REG_STATE));
|
||||
}
|
||||
|
||||
void FT6X36::setRotation(uint8_t rotation) {
|
||||
_rotation = rotation;
|
||||
}
|
||||
|
||||
void FT6X36::setTouchWidth(uint16_t width) {
|
||||
printf("touch w:%d\n",width);
|
||||
_touch_width = width;
|
||||
}
|
||||
|
||||
void FT6X36::setTouchHeight(uint16_t height) {
|
||||
printf("touch h:%d\n",height);
|
||||
_touch_height = height;
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "esp_log.h"
|
||||
#include "driver/i2c.h"
|
||||
#include "sdkconfig.h"
|
||||
#include <esp_timer.h>
|
||||
|
||||
#ifndef ft6x36_h
|
||||
#define ft6x36_h
|
||||
// I2C Constants
|
||||
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
||||
|
||||
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
|
||||
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
|
||||
#define ACK_VAL 0x0 /*!< I2C ack value */
|
||||
#define NACK_VAL 0x1 /*!< I2C nack value */
|
||||
|
||||
//SemaphoreHandle_t print_mux = NULL;
|
||||
|
||||
#define FT6X36_ADDR 0x38
|
||||
|
||||
#define FT6X36_REG_DEVICE_MODE 0x00
|
||||
#define FT6X36_REG_GESTURE_ID 0x01
|
||||
#define FT6X36_REG_NUM_TOUCHES 0x02
|
||||
#define FT6X36_REG_P1_XH 0x03
|
||||
#define FT6X36_REG_P1_XL 0x04
|
||||
#define FT6X36_REG_P1_YH 0x05
|
||||
#define FT6X36_REG_P1_YL 0x06
|
||||
#define FT6X36_REG_P1_WEIGHT 0x07
|
||||
#define FT6X36_REG_P1_MISC 0x08
|
||||
#define FT6X36_REG_P2_XH 0x09
|
||||
#define FT6X36_REG_P2_XL 0x0A
|
||||
#define FT6X36_REG_P2_YH 0x0B
|
||||
#define FT6X36_REG_P2_YL 0x0C
|
||||
#define FT6X36_REG_P2_WEIGHT 0x0D
|
||||
#define FT6X36_REG_P2_MISC 0x0E
|
||||
#define FT6X36_REG_THRESHHOLD 0x80
|
||||
#define FT6X36_REG_FILTER_COEF 0x85
|
||||
#define FT6X36_REG_CTRL 0x86
|
||||
#define FT6X36_REG_TIME_ENTER_MONITOR 0x87
|
||||
#define FT6X36_REG_TOUCHRATE_ACTIVE 0x88
|
||||
#define FT6X36_REG_TOUCHRATE_MONITOR 0x89 // value in ms
|
||||
#define FT6X36_REG_RADIAN_VALUE 0x91
|
||||
#define FT6X36_REG_OFFSET_LEFT_RIGHT 0x92
|
||||
#define FT6X36_REG_OFFSET_UP_DOWN 0x93
|
||||
#define FT6X36_REG_DISTANCE_LEFT_RIGHT 0x94
|
||||
#define FT6X36_REG_DISTANCE_UP_DOWN 0x95
|
||||
#define FT6X36_REG_DISTANCE_ZOOM 0x96
|
||||
#define FT6X36_REG_LIB_VERSION_H 0xA1
|
||||
#define FT6X36_REG_LIB_VERSION_L 0xA2
|
||||
#define FT6X36_REG_CHIPID 0xA3
|
||||
#define FT6X36_REG_INTERRUPT_MODE 0xA4
|
||||
#define FT6X36_REG_POWER_MODE 0xA5
|
||||
#define FT6X36_REG_FIRMWARE_VERSION 0xA6
|
||||
#define FT6X36_REG_PANEL_ID 0xA8
|
||||
#define FT6X36_REG_STATE 0xBC
|
||||
|
||||
#define FT6X36_PMODE_ACTIVE 0x00
|
||||
#define FT6X36_PMODE_MONITOR 0x01
|
||||
#define FT6X36_PMODE_STANDBY 0x02
|
||||
#define FT6X36_PMODE_HIBERNATE 0x03
|
||||
|
||||
/* Possible values returned by FT6X36_GEST_ID_REG */
|
||||
#define FT6X36_GEST_ID_NO_GESTURE 0x00
|
||||
#define FT6X36_GEST_ID_MOVE_UP 0x10
|
||||
#define FT6X36_GEST_ID_MOVE_RIGHT 0x14
|
||||
#define FT6X36_GEST_ID_MOVE_DOWN 0x18
|
||||
#define FT6X36_GEST_ID_MOVE_LEFT 0x1C
|
||||
#define FT6X36_GEST_ID_ZOOM_IN 0x48
|
||||
#define FT6X36_GEST_ID_ZOOM_OUT 0x49
|
||||
|
||||
#define FT6X36_VENDID 0x11
|
||||
#define FT6206_CHIPID 0x06
|
||||
#define FT6236_CHIPID 0x36
|
||||
#define FT6336_CHIPID 0x64
|
||||
|
||||
#define FT6X36_DEFAULT_THRESHOLD 22
|
||||
|
||||
// From: https://github.com/lvgl/lv_port_esp32/blob/master/components/lvgl_esp32_drivers/lvgl_touch/ft6x36.h
|
||||
#define FT6X36_MSB_MASK 0x0F
|
||||
#define FT6X36_LSB_MASK 0xFF
|
||||
|
||||
enum class TRawEvent
|
||||
{
|
||||
PressDown,
|
||||
LiftUp,
|
||||
Contact,
|
||||
NoEvent
|
||||
};
|
||||
|
||||
enum class TEvent
|
||||
{
|
||||
None,
|
||||
TouchStart,
|
||||
TouchMove,
|
||||
TouchEnd,
|
||||
Tap,
|
||||
DragStart,
|
||||
DragMove,
|
||||
DragEnd
|
||||
};
|
||||
|
||||
struct TPoint
|
||||
{
|
||||
uint16_t x;
|
||||
uint16_t y;
|
||||
/**
|
||||
* This is being used in the original library but I'm not using it in this implementation
|
||||
*/
|
||||
bool aboutEqual(const TPoint point)
|
||||
{
|
||||
return abs(x - point.x) <= 5 && abs(y - point.y) <= 5;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FT6X36
|
||||
{
|
||||
static void IRAM_ATTR isr(void* arg);
|
||||
public:
|
||||
// TwoWire * wire will be replaced by ESP-IDF https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/i2c.html
|
||||
FT6X36(i2c_port_t = I2C_NUM_0, gpio_num_t interruptPin = GPIO_NUM_NC);
|
||||
~FT6X36();
|
||||
bool begin(uint8_t threshold = FT6X36_DEFAULT_THRESHOLD, uint16_t width = 0, uint16_t height = 0);
|
||||
void registerTouchHandler(void(*fn)(TPoint point, TEvent e));
|
||||
uint8_t touched();
|
||||
void loop();
|
||||
void processTouch();
|
||||
void debugInfo();
|
||||
void poll(TPoint * point, TEvent * event);
|
||||
// Helper functions to make the touch display aware
|
||||
void setRotation(uint8_t rotation);
|
||||
void setTouchWidth(uint16_t width);
|
||||
void setTouchHeight(uint16_t height);
|
||||
// Pending implementation. How much x->touch y↓touch is placed (In case is smaller than display)
|
||||
void setXoffset(uint16_t x_offset);
|
||||
void setYoffset(uint16_t y_offset);
|
||||
// Smart template from EPD to swap x,y:
|
||||
template <typename T> static inline void
|
||||
swap(T& a, T& b)
|
||||
{
|
||||
T t = a;
|
||||
a = b;
|
||||
b = t;
|
||||
}
|
||||
void(*_touchHandler)(TPoint point, TEvent e) = nullptr;
|
||||
|
||||
bool readData(void);
|
||||
private:
|
||||
void writeRegister8(uint8_t reg, uint8_t val);
|
||||
uint8_t readRegister8(uint8_t reg, uint8_t *data_buf);
|
||||
void fireEvent(TPoint point, TEvent e);
|
||||
uint8_t read8(uint8_t regName);
|
||||
static FT6X36 * _instance;
|
||||
|
||||
i2c_port_t _port;
|
||||
int8_t _intPin;
|
||||
|
||||
// Make touch rotation aware:
|
||||
uint8_t _rotation = 0;
|
||||
uint16_t _touch_width = 0;
|
||||
uint16_t _touch_height = 0;
|
||||
|
||||
uint8_t _touches;
|
||||
uint16_t _touchX[2], _touchY[2], _touchEvent[2];
|
||||
TPoint _points[10];
|
||||
uint8_t _pointIdx = 0;
|
||||
unsigned long _touchStartTime = 0;
|
||||
unsigned long _touchEndTime = 0;
|
||||
uint8_t lastEvent = 3; // No event
|
||||
uint16_t lastX = 0;
|
||||
uint16_t lastY = 0;
|
||||
bool _dragMode = false;
|
||||
const uint8_t maxDeviation = 5;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 strange_v
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,8 @@
|
||||
This project is an adaption of the code at https://github.com/martinberlin/FT6X36-IDF which is an adaptation of https://github.com/strange-v/FT6X36
|
||||
The original license is an MIT license and is included in this directory.
|
||||
|
||||
Changes:
|
||||
- Remove Kconfig-based configuratio
|
||||
- Removed I2C init code
|
||||
- Allow for passing a different I2C port
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#define TAG "ili934x"
|
||||
|
||||
|
||||
bool Ili934xDisplay::start() {
|
||||
TT_LOG_I(TAG, "Starting");
|
||||
|
||||
@@ -67,6 +66,11 @@ bool Ili934xDisplay::start() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_swap_xy(panelHandle, configuration->swapXY) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to swap XY ");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (esp_lcd_panel_mirror(panelHandle, configuration->mirrorX, configuration->mirrorY) != ESP_OK) {
|
||||
TT_LOG_E(TAG, "Failed to set panel to mirror");
|
||||
return false;
|
||||
@@ -81,6 +85,7 @@ bool Ili934xDisplay::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;
|
||||
@@ -99,7 +104,7 @@ bool Ili934xDisplay::start() {
|
||||
.vres = configuration->verticalResolution,
|
||||
.monochrome = false,
|
||||
.rotation = {
|
||||
.swap_xy = false,
|
||||
.swap_xy = configuration->swapXY,
|
||||
.mirror_x = configuration->mirrorX,
|
||||
.mirror_y = configuration->mirrorY,
|
||||
},
|
||||
@@ -115,6 +120,7 @@ bool Ili934xDisplay::start() {
|
||||
};
|
||||
|
||||
displayHandle = lvgl_port_add_disp(&disp_cfg);
|
||||
|
||||
TT_LOG_I(TAG, "Finished");
|
||||
return displayHandle != nullptr;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,22 @@ public:
|
||||
gpio_num_t dcPin,
|
||||
unsigned int horizontalResolution,
|
||||
unsigned int verticalResolution,
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> touch
|
||||
std::shared_ptr<tt::hal::touch::TouchDevice> touch,
|
||||
bool swapXY = false,
|
||||
bool mirrorX = false,
|
||||
bool mirrorY = false,
|
||||
bool invertColor = false,
|
||||
uint32_t bufferSize = 0 // Size in pixel count. 0 means default, which is 1/10 of the screen size
|
||||
) : spiBusHandle(spi_bus_handle),
|
||||
csPin(csPin),
|
||||
dcPin(dcPin),
|
||||
horizontalResolution(horizontalResolution),
|
||||
verticalResolution(verticalResolution),
|
||||
swapXY(swapXY),
|
||||
mirrorX(mirrorX),
|
||||
mirrorY(mirrorY),
|
||||
invertColor(invertColor),
|
||||
bufferSize(bufferSize),
|
||||
touch(std::move(touch))
|
||||
{}
|
||||
|
||||
@@ -40,6 +50,7 @@ public:
|
||||
size_t transactionQueueDepth = 10;
|
||||
unsigned int horizontalResolution;
|
||||
unsigned int verticalResolution;
|
||||
bool swapXY = false;
|
||||
bool mirrorX = false;
|
||||
bool mirrorY = false;
|
||||
bool invertColor = false;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "PwmBacklight.h"
|
||||
|
||||
#include <Tactility/Log.h>
|
||||
#include <driver/ledc.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
#define TAG "pwm_backlight"
|
||||
|
||||
@@ -8,16 +8,20 @@ namespace driver::pwmbacklight {
|
||||
|
||||
static bool isBacklightInitialized = false;
|
||||
static gpio_num_t backlightPin = GPIO_NUM_NC;
|
||||
static ledc_timer_t backlightTimer;
|
||||
static ledc_channel_t backlightChannel;
|
||||
|
||||
bool init(gpio_num_t pin) {
|
||||
bool init(gpio_num_t pin, uint32_t frequencyHz, ledc_timer_t timer, ledc_channel_t channel) {
|
||||
backlightPin = pin;
|
||||
backlightTimer = timer;
|
||||
backlightChannel = channel;
|
||||
|
||||
TT_LOG_I(TAG, "Init");
|
||||
ledc_timer_config_t ledc_timer = {
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.duty_resolution = LEDC_TIMER_8_BIT,
|
||||
.timer_num = LEDC_TIMER_0,
|
||||
.freq_hz = 4000,
|
||||
.timer_num = backlightTimer,
|
||||
.freq_hz = frequencyHz,
|
||||
.clk_cfg = LEDC_AUTO_CLK,
|
||||
.deconfigure = false
|
||||
};
|
||||
@@ -30,9 +34,9 @@ bool init(gpio_num_t pin) {
|
||||
ledc_channel_config_t ledc_channel = {
|
||||
.gpio_num = backlightPin,
|
||||
.speed_mode = LEDC_LOW_SPEED_MODE,
|
||||
.channel = LEDC_CHANNEL_0,
|
||||
.channel = backlightChannel,
|
||||
.intr_type = LEDC_INTR_DISABLE,
|
||||
.timer_sel = LEDC_TIMER_0,
|
||||
.timer_sel = backlightTimer,
|
||||
.duty = 0,
|
||||
.hpoint = 0,
|
||||
.sleep_mode = LEDC_SLEEP_MODE_NO_ALIVE_NO_PD,
|
||||
@@ -55,8 +59,8 @@ bool setBacklightDuty(uint8_t duty) {
|
||||
TT_LOG_E(TAG, "Not initialized");
|
||||
return false;
|
||||
}
|
||||
return ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, duty) == ESP_OK &&
|
||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0) == ESP_OK;
|
||||
return ledc_set_duty(LEDC_LOW_SPEED_MODE, backlightChannel, duty) == ESP_OK &&
|
||||
ledc_update_duty(LEDC_LOW_SPEED_MODE, backlightChannel) == ESP_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <driver/ledc.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
namespace driver::pwmbacklight {
|
||||
|
||||
bool init(gpio_num_t pin);
|
||||
bool init(gpio_num_t pin, uint32_t frequencyHz = 40000, ledc_timer_t timer = LEDC_TIMER_0, ledc_channel_t channel = LEDC_CHANNEL_0);
|
||||
|
||||
void setBacklightDuty(uint8_t duty);
|
||||
bool setBacklightDuty(uint8_t duty);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user