mirror of
https://github.com/Xinyuan-LilyGO/T-Display-S3.git
synced 2024-09-21 09:57:26 +00:00
Update lv_demos.ino to work with the same logic as examples/CapacitiveTouch.ino
This commit is contained in:
parent
612f8dd853
commit
0f2eafcbd2
@ -5,12 +5,13 @@
|
||||
#endif
|
||||
|
||||
/* Please make sure your touch IC model. */
|
||||
#define TOUCH_USE_CAPACITIVE_TOUCH // uses same logic as examples/CapacitiveTouch.ino
|
||||
// #define TOUCH_MODULES_CST_MUTUAL
|
||||
// #define TOUCH_MODULES_CST_SELF
|
||||
|
||||
#if defined(TOUCH_MODULES_CST_SELF) || defined(TOUCH_MODULES_CST_SELF)
|
||||
#include "TouchLib.h"
|
||||
// #define TOUCH_READ_FROM_INTERRNUPT
|
||||
// #include "TouchLib.h"
|
||||
#define TOUCH_READ_FROM_INTERRNUPT
|
||||
#endif
|
||||
|
||||
/* The product now has two screens, and the initialization code needs a small change in the new version. The LCD_MODULE_CMD_1 is used to define the
|
||||
@ -27,13 +28,44 @@
|
||||
#include "pin_config.h"
|
||||
#include "lv_demo_widgets.h"
|
||||
|
||||
#ifdef TOUCH_USE_CAPACITIVE_TOUCH
|
||||
#include <TouchDrvCSTXXX.hpp>
|
||||
#define PIN_LCD_BL 38
|
||||
#define PIN_LCD_D0 39
|
||||
#define PIN_LCD_D1 40
|
||||
#define PIN_LCD_D2 41
|
||||
#define PIN_LCD_D3 42
|
||||
#define PIN_LCD_D4 45
|
||||
#define PIN_LCD_D5 46
|
||||
#define PIN_LCD_D6 47
|
||||
#define PIN_LCD_D7 48
|
||||
#define PIN_POWER_ON 15
|
||||
#define PIN_LCD_RES 5
|
||||
#define PIN_LCD_CS 6
|
||||
#define PIN_LCD_DC 7
|
||||
#define PIN_LCD_WR 8
|
||||
#define PIN_LCD_RD 9
|
||||
#define PIN_BUTTON_1 0
|
||||
#define PIN_BUTTON_2 14
|
||||
#define PIN_BAT_VOLT 4
|
||||
#define BOARD_I2C_SCL 17
|
||||
#define BOARD_I2C_SDA 18
|
||||
#define BOARD_TOUCH_IRQ 16
|
||||
#define BOARD_TOUCH_RST 21
|
||||
|
||||
TouchDrvCSTXXX touch;
|
||||
int16_t x[5], y[5];
|
||||
|
||||
#endif
|
||||
|
||||
esp_lcd_panel_io_handle_t io_handle = NULL;
|
||||
static lv_disp_draw_buf_t disp_buf; // contains internal graphic buffer(s) called draw buffer(s)
|
||||
static lv_disp_drv_t disp_drv; // contains callback functions
|
||||
static lv_color_t *lv_disp_buf;
|
||||
static bool is_initialized_lvgl = false;
|
||||
#if defined(LCD_MODULE_CMD_1)
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t data[14];
|
||||
uint8_t len;
|
||||
@ -66,10 +98,10 @@ bool get_int_signal = false;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
static bool example_notify_lvgl_flush_ready(esp_lcd_panel_io_handle_t panel_io, esp_lcd_panel_io_event_data_t *edata, void *user_ctx)
|
||||
{
|
||||
if (is_initialized_lvgl) {
|
||||
if (is_initialized_lvgl)
|
||||
{
|
||||
lv_disp_drv_t *disp_driver = (lv_disp_drv_t *)user_ctx;
|
||||
lv_disp_flush_ready(disp_driver);
|
||||
}
|
||||
@ -87,22 +119,29 @@ static void example_lvgl_flush_cb(lv_disp_drv_t *drv, const lv_area_t *area, lv_
|
||||
esp_lcd_panel_draw_bitmap(panel_handle, offsetx1, offsety1, offsetx2 + 1, offsety2 + 1, color_map);
|
||||
}
|
||||
|
||||
#if defined(TOUCH_MODULES_CST_SELF) || defined(TOUCH_MODULES_CST_SELF)
|
||||
#if defined(TOUCH_MODULES_CST_SELF) || defined(TOUCH_MODULES_CST_SELF) || defined(TOUCH_USE_CAPACITIVE_TOUCH)
|
||||
static void lv_touchpad_read(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
|
||||
{
|
||||
#if defined(TOUCH_READ_FROM_INTERRNUPT)
|
||||
if (get_int_signal) {
|
||||
#ifdef TOUCH_READ_FROM_INTERRNUPT
|
||||
if (get_int_signal)
|
||||
{
|
||||
get_int_signal = false;
|
||||
touch.read();
|
||||
#else
|
||||
if (touch.read()) {
|
||||
#endif
|
||||
TP_Point t = touch.getPoint(0);
|
||||
data->point.x = t.x;
|
||||
data->point.y = t.y;
|
||||
#ifdef TOUCH_USE_CAPACITIVE_TOUCH
|
||||
if (touch.getPoint(x, y, touch.getSupportTouchPoint()))
|
||||
{
|
||||
data->point.x = *x;
|
||||
data->point.y = *y;
|
||||
data->state = LV_INDEV_STATE_PR;
|
||||
} else
|
||||
data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
#else
|
||||
if (touch.read())
|
||||
{
|
||||
#endif
|
||||
#endif
|
||||
|
||||
else data->state = LV_INDEV_STATE_REL;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -110,13 +149,10 @@ void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
|
||||
// Turn on display power
|
||||
pinMode(PIN_POWER_ON, OUTPUT);
|
||||
digitalWrite(PIN_POWER_ON, HIGH);
|
||||
|
||||
|
||||
|
||||
pinMode(PIN_LCD_RD, OUTPUT);
|
||||
digitalWrite(PIN_LCD_RD, HIGH);
|
||||
esp_lcd_i80_bus_handle_t i80_bus = NULL;
|
||||
@ -174,7 +210,8 @@ void setup()
|
||||
// have different gap value
|
||||
esp_lcd_panel_set_gap(panel_handle, 0, 35);
|
||||
#if defined(LCD_MODULE_CMD_1)
|
||||
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++) {
|
||||
for (uint8_t i = 0; i < (sizeof(lcd_st7789v) / sizeof(lcd_cmd_t)); i++)
|
||||
{
|
||||
esp_lcd_panel_io_tx_param(io_handle, lcd_st7789v[i].cmd, lcd_st7789v[i].data, lcd_st7789v[i].len & 0x7f);
|
||||
if (lcd_st7789v[i].len & 0x80)
|
||||
delay(120);
|
||||
@ -183,7 +220,8 @@ void setup()
|
||||
/* Lighten the screen with gradient */
|
||||
ledcSetup(0, 10000, 8);
|
||||
ledcAttachPin(PIN_LCD_BL, 0);
|
||||
for (uint8_t i = 0; i < 0xFF; i++) {
|
||||
for (uint8_t i = 0; i < 0xFF; i++)
|
||||
{
|
||||
ledcWrite(0, i);
|
||||
delay(2);
|
||||
}
|
||||
@ -206,7 +244,8 @@ void setup()
|
||||
/* Register touch brush with LVGL */
|
||||
Wire.begin(PIN_IIC_SDA, PIN_IIC_SCL, 800000);
|
||||
inited_touch = touch.init();
|
||||
if (inited_touch) {
|
||||
if (inited_touch)
|
||||
{
|
||||
touch.setRotation(1);
|
||||
static lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
@ -217,10 +256,43 @@ void setup()
|
||||
is_initialized_lvgl = true;
|
||||
#if defined(TOUCH_READ_FROM_INTERRNUPT)
|
||||
attachInterrupt(
|
||||
PIN_TOUCH_INT, [] { get_int_signal = true; }, FALLING);
|
||||
PIN_TOUCH_INT, []
|
||||
{ get_int_signal = true; }, FALLING);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef TOUCH_USE_CAPACITIVE_TOUCH
|
||||
// Initialize capacitive touch
|
||||
touch.setPins(BOARD_TOUCH_RST, BOARD_TOUCH_IRQ);
|
||||
|
||||
if (!touch.begin(Wire, CST328_SLAVE_ADDRESS, BOARD_I2C_SDA, BOARD_I2C_SCL))
|
||||
{
|
||||
Serial.println("Failed init CST328 Device!");
|
||||
if (!touch.begin(Wire, CST816_SLAVE_ADDRESS, BOARD_I2C_SDA, BOARD_I2C_SCL))
|
||||
{
|
||||
Serial.println("Failed init CST816 Device!");
|
||||
while (1)
|
||||
{
|
||||
Serial.println("Not find touch device!");
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fix orientation
|
||||
touch.setMaxCoordinates(320, 170);
|
||||
touch.setMirrorXY(true, false);
|
||||
touch.setSwapXY(true);
|
||||
#endif
|
||||
|
||||
// link
|
||||
static lv_indev_drv_t indev_drv;
|
||||
lv_indev_drv_init(&indev_drv);
|
||||
indev_drv.type = LV_INDEV_TYPE_POINTER;
|
||||
indev_drv.read_cb = lv_touchpad_read;
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
is_initialized_lvgl = true;
|
||||
|
||||
lv_demo_widgets();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user