feat: 更新触摸屏支持与配置

- 移除不再使用的 CST816 触摸屏组件,替换为 CST816S 版本
- 更新依赖项以包含 espressif/esp_lcd_touch_cst816s
- 调整触摸屏初始化逻辑,支持新的 CST816S 驱动
- 修改显示配置以适应新的 LCD 分辨率和间隙设置
- 启用触摸功能并更新相关的 I2C 配置
- 更新 sdkconfig.defaults 以禁用 CST816S 的读取 ID 功能
This commit is contained in:
2026-07-01 21:04:27 +08:00
parent 7dc20b37a8
commit 55bbe951fe
6 changed files with 80 additions and 95 deletions
+16 -68
View File
@@ -13,72 +13,6 @@ dependencies:
registry_url: https://components.espressif.com/ registry_url: https://components.espressif.com/
type: service type: service
version: 1.0.6 version: 1.0.6
espp/base_component:
component_hash: 044472522a07bb4f03f50885ad0f3684d26254ef7cb0ea73f21d11241cfe4fdd
dependencies:
- name: espp/logger
registry_url: https://components.espressif.com
require: private
version: '>=1.0'
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.1.3
espp/base_peripheral:
component_hash: f1b5be84a6f1e3150d1b3d4a6ca5c81be0da06d3be391cc869b795ac4d5b7b92
dependencies:
- name: espp/base_component
registry_url: https://components.espressif.com
require: private
version: '>=1.0'
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.1.3
espp/cst816:
component_hash: a7c153be65c384213e80c83fec5a5466b172dd821021eb32d99b6752ad8f5f62
dependencies:
- name: espp/base_peripheral
registry_url: https://components.espressif.com
require: private
version: '>=0.22.0'
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com/
type: service
version: 0.22.1
espp/format:
component_hash: 997bc557fbb73549999699407f27856ad3c3cd9207e2e5f4af523e8dfc9ae659
dependencies:
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.1.3
espp/logger:
component_hash: 2a636c84d987a20b98cabbdcc65b92d9b6725d1c12cf2b3487d6ba60e452ef13
dependencies:
- name: espp/format
registry_url: https://components.espressif.com
require: private
version: '>=1.0'
- name: idf
require: private
version: '>=5.0'
source:
registry_url: https://components.espressif.com
type: service
version: 1.1.3
espressif/esp_lcd_touch: espressif/esp_lcd_touch:
component_hash: 3f85a7d95af876f1a6ecca8eb90a81614890d0f03a038390804e5a77e2caf862 component_hash: 3f85a7d95af876f1a6ecca8eb90a81614890d0f03a038390804e5a77e2caf862
dependencies: dependencies:
@@ -89,6 +23,20 @@ dependencies:
registry_url: https://components.espressif.com registry_url: https://components.espressif.com
type: service type: service
version: 1.2.1 version: 1.2.1
espressif/esp_lcd_touch_cst816s:
component_hash: a562ca3238756cca575908ed2cc4da4bab95f3815180b4f01f4c949b658bdd6d
dependencies:
- name: espressif/esp_lcd_touch
registry_url: https://components.espressif.com
require: public
version: ^1.2.0
- name: idf
require: private
version: '>=5.2'
source:
registry_url: https://components.espressif.com/
type: service
version: 1.1.1~1
espressif/esp_lcd_touch_stmpe610: espressif/esp_lcd_touch_stmpe610:
component_hash: d8adce47eabe3f8caa23c5acf03cfefe78012628abd974673ccb9a577c3d738b component_hash: d8adce47eabe3f8caa23c5acf03cfefe78012628abd974673ccb9a577c3d738b
dependencies: dependencies:
@@ -116,9 +64,9 @@ dependencies:
version: 9.3.0 version: 9.3.0
direct_dependencies: direct_dependencies:
- atanisoft/esp_lcd_touch_xpt2046 - atanisoft/esp_lcd_touch_xpt2046
- espp/cst816 - espressif/esp_lcd_touch_cst816s
- espressif/esp_lcd_touch_stmpe610 - espressif/esp_lcd_touch_stmpe610
- lvgl/lvgl - lvgl/lvgl
manifest_hash: 10c0c694b19d739cb3a8b361aa783292ec04b0f26fdbd54a5e06e72dd9b7b37c manifest_hash: 2b6db917e70b8d2f517a68c9019f4be93d8a03d820ef9c487259330151bd4a4f
target: esp32s3 target: esp32s3
version: 3.0.0 version: 3.0.0
+6 -3
View File
@@ -1,14 +1,17 @@
#pragma once #pragma once
#include "driver/i2c.h" #include "driver/i2c_types.h"
#include "driver/ledc.h" #include "driver/ledc.h"
#include "driver/spi_master.h" #include "driver/spi_master.h"
/* LCD SPI (ST7789) */ /* LCD SPI (ST7789) */
#define BOARD_LCD_HOST SPI2_HOST #define BOARD_LCD_HOST SPI2_HOST
#define BOARD_LCD_PIXEL_CLOCK_HZ (20 * 1000 * 1000) #define BOARD_LCD_PIXEL_CLOCK_HZ (20 * 1000 * 1000)
#define BOARD_LCD_H_RES 240 #define BOARD_LCD_H_RES 170
#define BOARD_LCD_V_RES 320 #define BOARD_LCD_V_RES 320
#define BOARD_LCD_PANEL_H_RES 240
#define BOARD_LCD_GAP_X ((BOARD_LCD_PANEL_H_RES - BOARD_LCD_H_RES) / 2)
#define BOARD_LCD_GAP_Y 0
#define BOARD_LCD_CMD_BITS 8 #define BOARD_LCD_CMD_BITS 8
#define BOARD_LCD_PARAM_BITS 8 #define BOARD_LCD_PARAM_BITS 8
@@ -35,7 +38,7 @@
#define BOARD_TOUCH_I2C_NUM I2C_NUM_0 #define BOARD_TOUCH_I2C_NUM I2C_NUM_0
#define BOARD_TOUCH_I2C_FREQ_HZ 400000 #define BOARD_TOUCH_I2C_FREQ_HZ 400000
#define BOARD_TOUCH_ENABLED 0 #define BOARD_TOUCH_ENABLED 1
/* User IO */ /* User IO */
#define BOARD_PIN_KEY 4 #define BOARD_PIN_KEY 4
+1
View File
@@ -87,6 +87,7 @@ esp_err_t display_init(esp_lcd_panel_io_handle_t *io_handle_out,
ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle)); ESP_ERROR_CHECK(esp_lcd_panel_reset(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle)); ESP_ERROR_CHECK(esp_lcd_panel_init(panel_handle));
ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, false, false)); ESP_ERROR_CHECK(esp_lcd_panel_mirror(panel_handle, false, false));
ESP_ERROR_CHECK(esp_lcd_panel_set_gap(panel_handle, BOARD_LCD_GAP_X, BOARD_LCD_GAP_Y));
ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true)); ESP_ERROR_CHECK(esp_lcd_panel_disp_on_off(panel_handle, true));
ESP_LOGI(TAG, "Turn on LCD backlight"); ESP_LOGI(TAG, "Turn on LCD backlight");
+55 -23
View File
@@ -3,30 +3,47 @@
#include "board_config.h" #include "board_config.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "driver/i2c.h" #include "driver/i2c_master.h"
#include "esp_lcd_io_i2c.h"
#include "esp_lcd_panel_io.h"
#include "esp_lcd_touch.h" #include "esp_lcd_touch.h"
#include "esp_lcd_touch_cst816s.h"
#include "esp_log.h" #include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"
static const char *TAG = "touch"; static const char *TAG = "touch";
#if BOARD_TOUCH_ENABLED #if BOARD_TOUCH_ENABLED
#include "esp_lcd_touch_cst816.h" static i2c_master_bus_handle_t s_touch_i2c_bus;
static esp_lcd_touch_handle_t s_touch_handle;
static SemaphoreHandle_t s_touch_mux;
static void touch_isr_cb(esp_lcd_touch_handle_t tp)
{
BaseType_t task_woken = pdFALSE;
(void)tp;
xSemaphoreGiveFromISR(s_touch_mux, &task_woken);
if (task_woken) {
portYIELD_FROM_ISR();
}
}
static void lvgl_touch_read_cb(lv_indev_t *indev, lv_indev_data_t *data) static void lvgl_touch_read_cb(lv_indev_t *indev, lv_indev_data_t *data)
{ {
uint16_t touchpad_x[1] = {0}; esp_lcd_touch_handle_t tp = lv_indev_get_user_data(indev);
uint16_t touchpad_y[1] = {0};
uint8_t touchpad_cnt = 0;
esp_lcd_touch_handle_t touch_pad = lv_indev_get_user_data(indev); if (xSemaphoreTake(s_touch_mux, 0) == pdTRUE) {
esp_lcd_touch_read_data(touch_pad); esp_lcd_touch_read_data(tp);
bool touchpad_pressed = esp_lcd_touch_get_coordinates( }
touch_pad, touchpad_x, touchpad_y, NULL, &touchpad_cnt, 1);
if (touchpad_pressed && touchpad_cnt > 0) { esp_lcd_touch_point_data_t points[1];
data->point.x = touchpad_x[0]; uint8_t point_cnt = 0;
data->point.y = touchpad_y[0]; if (esp_lcd_touch_get_data(tp, points, &point_cnt, 1) == ESP_OK && point_cnt > 0) {
data->point.x = points[0].x;
data->point.y = points[0].y;
data->state = LV_INDEV_STATE_PRESSED; data->state = LV_INDEV_STATE_PRESSED;
} else { } else {
data->state = LV_INDEV_STATE_RELEASED; data->state = LV_INDEV_STATE_RELEASED;
@@ -36,36 +53,51 @@ static void lvgl_touch_read_cb(lv_indev_t *indev, lv_indev_data_t *data)
esp_err_t touch_init(lv_display_t *display) esp_err_t touch_init(lv_display_t *display)
{ {
ESP_LOGI(TAG, "Initialize I2C for touch"); ESP_LOGI(TAG, "Initialize I2C for touch");
i2c_config_t i2c_conf = { i2c_master_bus_config_t bus_config = {
.mode = I2C_MODE_MASTER, .clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = BOARD_TOUCH_I2C_NUM,
.sda_io_num = BOARD_PIN_TOUCH_SDA, .sda_io_num = BOARD_PIN_TOUCH_SDA,
.scl_io_num = BOARD_PIN_TOUCH_SCL, .scl_io_num = BOARD_PIN_TOUCH_SCL,
.sda_pullup_en = GPIO_PULLUP_ENABLE, .glitch_ignore_cnt = 7,
.scl_pullup_en = GPIO_PULLUP_ENABLE, .flags.enable_internal_pullup = true,
.master.clk_speed = BOARD_TOUCH_I2C_FREQ_HZ,
}; };
ESP_ERROR_CHECK(i2c_param_config(BOARD_TOUCH_I2C_NUM, &i2c_conf)); ESP_ERROR_CHECK(i2c_new_master_bus(&bus_config, &s_touch_i2c_bus));
ESP_ERROR_CHECK(i2c_driver_install(BOARD_TOUCH_I2C_NUM, I2C_MODE_MASTER, 0, 0, 0));
ESP_LOGI(TAG, "Initialize touch controller CST816"); s_touch_mux = xSemaphoreCreateBinary();
esp_lcd_touch_handle_t tp = NULL; if (s_touch_mux == NULL) {
ESP_LOGE(TAG, "Failed to create touch semaphore");
return ESP_ERR_NO_MEM;
}
ESP_LOGI(TAG, "Initialize touch panel IO (CST816S)");
esp_lcd_panel_io_handle_t tp_io_handle = NULL;
esp_lcd_panel_io_i2c_config_t tp_io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();
tp_io_config.scl_speed_hz = BOARD_TOUCH_I2C_FREQ_HZ;
ESP_ERROR_CHECK(esp_lcd_new_panel_io_i2c(s_touch_i2c_bus, &tp_io_config, &tp_io_handle));
ESP_LOGI(TAG, "Initialize touch controller CST816S");
esp_lcd_touch_config_t tp_cfg = { esp_lcd_touch_config_t tp_cfg = {
.x_max = BOARD_LCD_H_RES, .x_max = BOARD_LCD_H_RES,
.y_max = BOARD_LCD_V_RES, .y_max = BOARD_LCD_V_RES,
.rst_gpio_num = BOARD_PIN_TOUCH_RST, .rst_gpio_num = BOARD_PIN_TOUCH_RST,
.int_gpio_num = BOARD_PIN_TOUCH_INT, .int_gpio_num = BOARD_PIN_TOUCH_INT,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = { .flags = {
.swap_xy = 0, .swap_xy = 0,
.mirror_x = 0, .mirror_x = 0,
.mirror_y = 0, .mirror_y = 0,
}, },
.interrupt_callback = touch_isr_cb,
}; };
ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_cst816(BOARD_TOUCH_I2C_NUM, &tp_cfg, &tp)); ESP_ERROR_CHECK(esp_lcd_touch_new_i2c_cst816s(tp_io_handle, &tp_cfg, &s_touch_handle));
lv_indev_t *indev = lv_indev_create(); lv_indev_t *indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);
lv_indev_set_display(indev, display); lv_indev_set_display(indev, display);
lv_indev_set_user_data(indev, tp); lv_indev_set_user_data(indev, s_touch_handle);
lv_indev_set_read_cb(indev, lvgl_touch_read_cb); lv_indev_set_read_cb(indev, lvgl_touch_read_cb);
return ESP_OK; return ESP_OK;
+1 -1
View File
@@ -1,5 +1,6 @@
dependencies: dependencies:
lvgl/lvgl: 9.3.0 lvgl/lvgl: 9.3.0
espressif/esp_lcd_touch_cst816s: ^1.1.1
esp_lcd_touch_stmpe610: ^1.0.0 esp_lcd_touch_stmpe610: ^1.0.0
atanisoft/esp_lcd_touch_xpt2046: 1.0.6 atanisoft/esp_lcd_touch_xpt2046: 1.0.6
espressif/esp_wifi_remote: espressif/esp_wifi_remote:
@@ -10,4 +11,3 @@ dependencies:
version: ~2 version: ~2
rules: rules:
- if: target in [esp32p4, esp32h2] - if: target in [esp32p4, esp32h2]
espp/cst816: ^0.22.0
+1
View File
@@ -1 +1,2 @@
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
CONFIG_ESP_LCD_TOUCH_CST816S_DISABLE_READ_ID=y