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
+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;