feat: 添加 CST816 触摸屏驱动支持及相关配置

This commit is contained in:
2026-06-29 22:50:34 +08:00
parent fc03cedf66
commit 60efac6dfc
4 changed files with 160 additions and 44 deletions
+10 -8
View File
@@ -1,7 +1,9 @@
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-S2 | ESP32-S3 | ESP32-P4 | ESP32-H2 | # Suppor
| ----------------- | ----- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- | -------- |
# 外围硬件 | Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-S2 | ESP32-S3 | ESP32-P4 | ESP32-H2 |
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- | -------- | -------- |
## 外围硬件
| 硬件类别 | 组件/型号 | 关键参数/功能 | 备注 | | 硬件类别 | 组件/型号 | 关键参数/功能 | 备注 |
| :----------------- | :--------------- | :--------------------------------- | :------------------------------- | | :----------------- | :--------------- | :--------------------------------- | :------------------------------- |
@@ -25,10 +27,10 @@
| | 启动按键 | BOOT | 用于下载模式和引导 | | | 启动按键 | BOOT | 用于下载模式和引导 |
| **扩展接口** | Pico兼容排针 | 引出丰富GPIO | 兼容树莓派Pico生态,可连接扩展板 | | **扩展接口** | Pico兼容排针 | 引出丰富GPIO | 兼容树莓派Pico生态,可连接扩展板 |
# 外围接口 ## 外围接口
| 接口名称 | 接口类型 | 引脚/GPIO | 功能说明 | | 接口名称 | 接口类型 | 引脚/GPIO | 功能说明 |
| :------------- | :--- | :------------- | :------------------- | | :---------------- | :------- | :------------- | :------------------------- |
| **LCD 显示屏** | SPI | IO9 | LCD\_RST(复位) | | **LCD 显示屏** | SPI | IO9 | LCD\_RST(复位) |
| | | IO10 | LCD\_CLK(时钟) | | | | IO10 | LCD\_CLK(时钟) |
| | | IO11 | LCD\_DC(数据/命令) | | | | IO11 | LCD\_DC(数据/命令) |
@@ -61,7 +63,7 @@
| **扩展排针 J3** | 混合 | IO0~IO14 | 20Pin 排针,引出主要 GPIO | | **扩展排针 J3** | 混合 | IO0~IO14 | 20Pin 排针,引出主要 GPIO |
| **扩展排针 J4** | 混合 | IO14~IO48等 | 20Pin 排针,含 USB/3V3/地 | | **扩展排针 J4** | 混合 | IO14~IO48等 | 20Pin 排针,含 USB/3V3/地 |
# Wi-Fi Station Example ## Wi-Fi Station Example
(See the README.md file in the upper level 'examples' directory for more information about examples.) (See the README.md file in the upper level 'examples' directory for more information about examples.)
@@ -111,7 +113,7 @@ Note that the output, in particular the order of the output, may vary depending
Console output if station connects to AP successfully: Console output if station connects to AP successfully:
``` ```bash
I (589) wifi station: ESP_WIFI_MODE_STA I (589) wifi station: ESP_WIFI_MODE_STA
I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0 I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0
I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
@@ -145,7 +147,7 @@ I (2089) wifi station: connected to ap SSID:myssid password:mypassword
Console output if the station failed to connect to AP: Console output if the station failed to connect to AP:
``` ```bash
I (589) wifi station: ESP_WIFI_MODE_STA I (589) wifi station: ESP_WIFI_MODE_STA
I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0 I (599) wifi: wifi driver task: 3ffc08b4, prio:23, stack:3584, core=0
I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE I (599) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
+68 -1
View File
@@ -13,6 +13,72 @@ 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:
@@ -50,8 +116,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_stmpe610 - espressif/esp_lcd_touch_stmpe610
- lvgl/lvgl - lvgl/lvgl
manifest_hash: 783844712ff012ac0ccef68126d4d5ff8016553ec5d5055c68eab3b7cae073cf manifest_hash: 10c0c694b19d739cb3a8b361aa783292ec04b0f26fdbd54a5e06e72dd9b7b37c
target: esp32s3 target: esp32s3
version: 3.0.0 version: 3.0.0
+4 -3
View File
@@ -5,8 +5,9 @@ dependencies:
espressif/esp_wifi_remote: espressif/esp_wifi_remote:
version: ">=0.10,<2.0" version: ">=0.10,<2.0"
rules: rules:
- if: "target in [esp32p4, esp32h2]" - if: target in [esp32p4, esp32h2]
espressif/esp_hosted: espressif/esp_hosted:
version: "~2" version: ~2
rules: rules:
- if: "target in [esp32p4, esp32h2]" - if: target in [esp32p4, esp32h2]
espp/cst816: ^0.22.0
+46
View File
@@ -132,6 +132,52 @@
#define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024) #define EXAMPLE_LVGL_TASK_STACK_SIZE (4 * 1024)
#define EXAMPLE_LVGL_TASK_PRIORITY 2 #define EXAMPLE_LVGL_TASK_PRIORITY 2
// 开启触摸屏支持
#define CONFIG_EXAMPLE_LCD_TOUCH_ENABLED 0
// 添加 CST816 驱动代码
#define CST816_I2C_ADDR 0x15
typedef struct {
uint16_t x;
uint16_t y;
uint8_t touched;
} cst816_data_t;
static bool cst816_read_touch(cst816_data_t *data) {
uint8_t reg = 0x02; // 触摸点数寄存器
uint8_t buffer[5];
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (CST816_I2C_ADDR << 1) | I2C_MASTER_WRITE, true);
i2c_master_write_byte(cmd, reg, true);
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (CST816_I2C_ADDR << 1) | I2C_MASTER_READ, true);
i2c_master_read_byte(cmd, buffer, I2C_MASTER_ACK);
i2c_master_read_byte(cmd, buffer + 1, I2C_MASTER_ACK);
i2c_master_read_byte(cmd, buffer + 2, I2C_MASTER_ACK);
i2c_master_read_byte(cmd, buffer + 3, I2C_MASTER_ACK);
i2c_master_read_byte(cmd, buffer + 4, I2C_MASTER_NACK);
i2c_master_stop(cmd);
esp_err_t ret =
i2c_master_cmd_begin(TOUCH_I2C_MASTER_NUM, cmd, pdMS_TO_TICKS(100));
i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) {
return false;
}
data->touched = buffer[0] > 0;
if (data->touched) {
data->x = ((buffer[1] & 0x0F) << 8) | buffer[2];
data->y = ((buffer[3] & 0x0F) << 8) | buffer[4];
return true;
}
return false;
}
// LVGL library is not thread-safe, this example will call LVGL APIs from // LVGL library is not thread-safe, this example will call LVGL APIs from
// different tasks, so use a mutex to protect it // different tasks, so use a mutex to protect it
static _lock_t lvgl_api_lock; static _lock_t lvgl_api_lock;