Add files via upload

CST816 touch driver add
This commit is contained in:
Szetya 2025-03-10 18:29:51 +01:00 committed by GitHub
parent cc50dbf59f
commit 5cc1fda908
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 210 additions and 110 deletions

View File

@ -1,110 +1,113 @@
/* MIT License - Copyright (c) 2019-2024 Francis Van Roie /* MIT License - Copyright (c) 2019-2024 Francis Van Roie
For full license information read the LICENSE file in the project folder */ For full license information read the LICENSE file in the project folder */
#ifndef HASP_BASE_TOUCH_DRIVER_H #ifndef HASP_BASE_TOUCH_DRIVER_H
#define HASP_BASE_TOUCH_DRIVER_H #define HASP_BASE_TOUCH_DRIVER_H
#ifdef ARDUINO #ifdef ARDUINO
#include <Arduino.h> #include <Arduino.h>
#endif #endif
#include "hasplib.h" #include "hasplib.h"
#include "lvgl.h" #include "lvgl.h"
namespace dev { namespace dev {
class BaseTouch { class BaseTouch {
public: public:
void init(int w, int h) void init(int w, int h)
{} {}
// void loop() // void loop()
// {} // {}
void show_info() void show_info()
{} {}
void set_rotation(uint8_t rotation) void set_rotation(uint8_t rotation)
{} {}
void set_invert(bool invert_display) void set_invert(bool invert_display)
{} {}
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
{ {
data->state = LV_INDEV_STATE_REL; data->state = LV_INDEV_STATE_REL;
return false; return false;
} }
void calibrate(uint16_t* calData) void calibrate(uint16_t* calData)
{} {}
void set_calibration(uint16_t* calData) void set_calibration(uint16_t* calData)
{} {}
bool is_driver_pin(uint8_t) bool is_driver_pin(uint8_t)
{ {
return false; return false;
} }
const char* get_touch_model() const char* get_touch_model()
{ {
return ""; return "";
} }
}; };
} // namespace dev } // namespace dev
#ifndef TOUCH_DRIVER #ifndef TOUCH_DRIVER
#define TOUCH_DRIVER -1 // No Touch #define TOUCH_DRIVER -1 // No Touch
#endif #endif
#if TOUCH_DRIVER == 0x2046 && defined(USER_SETUP_LOADED) #if TOUCH_DRIVER == 0x2046 && defined(USER_SETUP_LOADED)
#warning Building for TFT_eSPI XPT2046 #warning Building for TFT_eSPI XPT2046
//#include "touch_driver_xpt2046.h" //#include "touch_driver_xpt2046.h"
#include "touch_driver_tftespi.h" #include "touch_driver_tftespi.h"
#elif TOUCH_DRIVER == 0x2046 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) #elif TOUCH_DRIVER == 0x2046 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH)
#warning Building for LovyanGFX XPT2046 #warning Building for LovyanGFX XPT2046
#include "touch_driver_lovyangfx.h" #include "touch_driver_lovyangfx.h"
#elif TOUCH_DRIVER == 0x0911 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) #elif TOUCH_DRIVER == 0x0911 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH)
#warning Building for LovyanGFX GT911 #warning Building for LovyanGFX GT911
#include "touch_driver_lovyangfx.h" #include "touch_driver_lovyangfx.h"
#elif TOUCH_DRIVER == 0x6336 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) #elif TOUCH_DRIVER == 0x6336 && defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH)
#warning Building for LovyanGFX FT6336 #warning Building for LovyanGFX FT6336
#include "touch_driver_lovyangfx.h" #include "touch_driver_lovyangfx.h"
#elif defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH) #elif defined(LGFX_USE_V1) && defined(HASP_USE_LGFX_TOUCH)
#warning Building for LovyanGFX #warning Building for LovyanGFX
#include "touch_driver_lovyangfx.h" #include "touch_driver_lovyangfx.h"
#elif TOUCH_DRIVER == 0x5206 #elif TOUCH_DRIVER == 0x5206
#warning Building for FT5206 #warning Building for FT5206
#include "touch_driver_ft5206.h" #include "touch_driver_ft5206.h"
#elif TOUCH_DRIVER == 0x6336 #elif TOUCH_DRIVER == 0x6336
#warning Building for FT6336 #warning Building for FT6336
#include "touch_driver_ft6336u.h" #include "touch_driver_ft6336u.h"
#elif TOUCH_DRIVER == 0x0610 #elif TOUCH_DRIVER == 0x0610
#warning Building for STMPE610 #warning Building for STMPE610
#include "touch_driver_stmpe610.h" #include "touch_driver_stmpe610.h"
#elif TOUCH_DRIVER == 0x0911 #elif TOUCH_DRIVER == 0x0911
#warning Building for GT911 #warning Building for GT911
#include "touch_driver_gt911.h" #include "touch_driver_gt911.h"
#elif TOUCH_DRIVER == 0x0ADC #elif TOUCH_DRIVER == 0x0ADC
#warning Building for analog touch #warning Building for analog touch
#include "touch_driver_analog.h" #include "touch_driver_analog.h"
#elif TOUCH_DRIVER == 0x1680 #elif TOUCH_DRIVER == 0x1680
#warning Building for GSL1680 #warning Building for GSL1680
#include "touch_driver_gslx680.h" #include "touch_driver_gslx680.h"
#elif TOUCH_DRIVER == 0x2007 #elif TOUCH_DRIVER == 0x2007
#warning Building for TSC2007 #warning Building for TSC2007
#include "touch_driver_tsc2007.h" #include "touch_driver_tsc2007.h"
#elif defined(LGFX_USE_V1) #elif defined(LGFX_USE_V1)
#warning Building for LovyanGfx Touch #warning Building for LovyanGfx Touch
#include "touch_driver_lovyangfx.h" #include "touch_driver_lovyangfx.h"
#elif TOUCH_DRIVER == 0x3240 #elif TOUCH_DRIVER == 0x3240
#warning Building for CST3240 #warning Building for CST3240
#include "touch_driver_cst3240.h" #include "touch_driver_cst3240.h"
#else #elif TOUCH_DRIVER == 0x816
#warning Building for Generic Touch #warning Building for CST816S
using dev::BaseTouch; #include "touch_driver_cst816.h"
extern dev::BaseTouch haspTouch; #else
// IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data) #warning Building for Generic Touch
// { using dev::BaseTouch;
// data->state = LV_INDEV_STATE_REL; extern dev::BaseTouch haspTouch;
// return false; // IRAM_ATTR bool touch_read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
// } // {
#endif // data->state = LV_INDEV_STATE_REL;
// return false;
#endif // }
#endif
// #elif TOUCH_DRIVER == 0x2046B
// touched = XPT2046_getXY(&normal_x, &normal_y, true); #endif
// #elif TOUCH_DRIVER == 0x2046B
// touched = XPT2046_getXY(&normal_x, &normal_y, true);

View File

@ -0,0 +1,70 @@
/* MIT License - Copyright (c) 2019-2024 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#if defined(ARDUINO) && (TOUCH_DRIVER == 0x816)
#include <Arduino.h>
#include "ArduinoLog.h"
#include "hasp_conf.h"
#include "touch_driver_cst816.h"
#include <Wire.h>
#include "cst816t.h"
#include "touch_driver.h" // base class
#include "touch_helper.h" // i2c scanner
#include "../../hasp/hasp.h" // for hasp_sleep_state
extern uint8_t hasp_sleep_state;
cst816t touchpad(Wire, TOUCH_RST, TOUCH_IRQ);
namespace dev {
IRAM_ATTR bool TouchCst816::read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data)
{
if(touchpad.available()) {
if(hasp_sleep_state != HASP_SLEEP_OFF) hasp_update_sleep_state(); // update Idle
//LOG_INFO(TAG_DRVR, "CST816 touched x:%d, y:%d", touchpad.x, touchpad.y);
#ifdef TOUCH_WIDTH
data->point.x = map(x, 0, TOUCH_WIDTH - 1, 0, TFT_WIDTH - 1);
#else
data->point.x = touchpad.x;
#endif
#ifdef TOUCH_HEIGHT
data->point.y = map(y, 0, TOUCH_HEIGHT - 1, 0, TFT_HEIGHT - 1);
#else
data->point.y = touchpad.y;
#endif
data->state = LV_INDEV_STATE_PR;
hasp_set_sleep_offset(0); // Reset the offset
} else {
data->state = LV_INDEV_STATE_REL;
}
/*Return `false` because we are not buffering and no more data to read*/
return false;
}
void TouchCst816::init(int w, int h)
{
Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY);
if(touchpad.begin(mode_touch) == true) {
LOG_INFO(TAG_DRVR, "CST816 %s (170X320)", D_SERVICE_STARTED);
} else {
LOG_WARNING(TAG_DRVR, "CST816 %s", D_SERVICE_START_FAILED);
}
Wire.begin(TOUCH_SDA, TOUCH_SCL, (uint32_t)I2C_TOUCH_FREQUENCY);
touch_scan(Wire); // The address could change during begin, so scan afterwards
}
} // namespace dev
dev::TouchCst816 haspTouch;
#endif // ARDUINO

View File

@ -0,0 +1,27 @@
/* MIT License - Copyright (c) 2019-2024 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_CST816_TOUCH_DRIVER_H
#define HASP_CST816_TOUCH_DRIVER_H
#ifdef ARDUINO
#include "lvgl.h"
#include "touch_driver.h"
namespace dev {
class TouchCst816 : public BaseTouch {
public:
IRAM_ATTR bool read(lv_indev_drv_t* indev_driver, lv_indev_data_t* data);
void init(int w, int h);
};
} // namespace dev
using dev::TouchCst816;
extern dev::TouchCst816 haspTouch;
#endif // ARDUINO
#endif // HASP_CST816_TOUCH_DRIVER_H