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
+42 -40
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,43 +27,43 @@
| | 启动按键 | BOOT | 用于下载模式和引导 |
| **扩展接口** | Pico兼容排针 | 引出丰富GPIO | 兼容树莓派Pico生态,可连接扩展板 |
# 外围接口
## 外围接口
| 接口名称 | 接口类型 | 引脚/GPIO | 功能说明 |
| :------------- | :--- | :------------- | :------------------- |
| **LCD 显示屏** | SPI | IO9 | LCD\_RST(复位) |
| | | IO10 | LCD\_CLK(时钟) |
| | | IO11 | LCD\_DC(数据/命令) |
| | | IO12 | LCD\_CS(片选) |
| | | IO13 | LCD\_DIN(数据输入) |
| | | IO14 | LCD\_BL(背光控制,PWM |
| **触摸屏** | I2C | IO47 | TP\_SDA(数据线) |
| | | IO48 | TP\_SCL(时钟线) |
| | GPIO | IO17 | TP\_RESET(复位) |
| | | IO21 | TP\_INT(中断) |
| **SD 卡** | SPI | IO5 | SD\_CS(片选) |
| | | IO39 | SD\_CLK(时钟) |
| | | IO40 | SD\_MISO(主入从出) |
| | | IO41 | SD\_MOSI(主出从入) |
| **IMU 传感器** | I2C | IO8 | IMU\_SDA(数据线) |
| (QMI8658A) | | IO7 | IMU\_SCL(时钟线) |
| | GPIO | IO6 | IMU\_INT1(中断1 |
| | | IO15 | IMU\_INT2(中断2 |
| **UART0 串口** | UART | IO43 | U0\_TX(发送) |
| | | IO44 | U0\_RX(接收) |
| **用户按键** | GPIO | IO0 | BOOT0(启动/下载模式) |
| | | IO4 | KEY\_IO(用户按键) |
| **用户 LED** | GPIO | IO16 | LED\_A(指示灯) |
| **电池检测** | ADC | IO3 | BAT\_ADC(电池电压采集) |
| **USB Type-C** | USB | VBUS/D+/D- | 供电 + 程序下载 + 串口通信 |
| **锂电池接口** | 电源 | J1 | 电池充电与供电(ETA6098) |
| **WiFi/蓝牙天线** | 射频 | J5 (U.FL-IPEX) | 外接天线座 |
| **TF 卡座** | SPI | TF1 | MicroSD 卡扩展存储 |
| **外部 Flash** | SPI | U5 (W25Q32) | 4MB 板载 Flash |
| **扩展排针 J3** | 混合 | IO0~IO14 | 20Pin 排针,引出主要 GPIO |
| **扩展排针 J4** | 混合 | IO14~IO48等 | 20Pin 排针,含 USB/3V3/地 |
| 接口名称 | 接口类型 | 引脚/GPIO | 功能说明 |
| :---------------- | :------- | :------------- | :------------------------- |
| **LCD 显示屏** | SPI | IO9 | LCD\_RST(复位) |
| | | IO10 | LCD\_CLK(时钟) |
| | | IO11 | LCD\_DC(数据/命令) |
| | | IO12 | LCD\_CS(片选) |
| | | IO13 | LCD\_DIN(数据输入) |
| | | IO14 | LCD\_BL(背光控制,PWM |
| **触摸屏** | I2C | IO47 | TP\_SDA(数据线) |
| | | IO48 | TP\_SCL(时钟线) |
| | GPIO | IO17 | TP\_RESET(复位) |
| | | IO21 | TP\_INT(中断) |
| **SD 卡** | SPI | IO5 | SD\_CS(片选) |
| | | IO39 | SD\_CLK(时钟) |
| | | IO40 | SD\_MISO(主入从出) |
| | | IO41 | SD\_MOSI(主出从入) |
| **IMU 传感器** | I2C | IO8 | IMU\_SDA(数据线) |
| (QMI8658A) | | IO7 | IMU\_SCL(时钟线) |
| | GPIO | IO6 | IMU\_INT1(中断1 |
| | | IO15 | IMU\_INT2(中断2 |
| **UART0 串口** | UART | IO43 | U0\_TX(发送) |
| | | IO44 | U0\_RX(接收) |
| **用户按键** | GPIO | IO0 | BOOT0(启动/下载模式) |
| | | IO4 | KEY\_IO(用户按键) |
| **用户 LED** | GPIO | IO16 | LED\_A(指示灯) |
| **电池检测** | ADC | IO3 | BAT\_ADC(电池电压采集) |
| **USB Type-C** | USB | VBUS/D+/D- | 供电 + 程序下载 + 串口通信 |
| **锂电池接口** | 电源 | J1 | 电池充电与供电(ETA6098 |
| **WiFi/蓝牙天线** | 射频 | J5 (U.FL-IPEX) | 外接天线座 |
| **TF 卡座** | SPI | TF1 | MicroSD 卡扩展存储 |
| **外部 Flash** | SPI | U5 (W25Q32) | 4MB 板载 Flash |
| **扩展排针 J3** | 混合 | IO0~IO14 | 20Pin 排针,引出主要 GPIO |
| **扩展排针 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.)
@@ -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:
```
```bash
I (589) wifi station: ESP_WIFI_MODE_STA
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
@@ -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:
```
```bash
I (589) wifi station: ESP_WIFI_MODE_STA
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
+68 -1
View File
@@ -13,6 +13,72 @@ dependencies:
registry_url: https://components.espressif.com/
type: service
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:
component_hash: 3f85a7d95af876f1a6ecca8eb90a81614890d0f03a038390804e5a77e2caf862
dependencies:
@@ -50,8 +116,9 @@ dependencies:
version: 9.3.0
direct_dependencies:
- atanisoft/esp_lcd_touch_xpt2046
- espp/cst816
- espressif/esp_lcd_touch_stmpe610
- lvgl/lvgl
manifest_hash: 783844712ff012ac0ccef68126d4d5ff8016553ec5d5055c68eab3b7cae073cf
manifest_hash: 10c0c694b19d739cb3a8b361aa783292ec04b0f26fdbd54a5e06e72dd9b7b37c
target: esp32s3
version: 3.0.0
+4 -3
View File
@@ -5,8 +5,9 @@ dependencies:
espressif/esp_wifi_remote:
version: ">=0.10,<2.0"
rules:
- if: "target in [esp32p4, esp32h2]"
- if: target in [esp32p4, esp32h2]
espressif/esp_hosted:
version: "~2"
version: ~2
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_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
// different tasks, so use a mutex to protect it
static _lock_t lvgl_api_lock;