✨ 新增功能 - 按键驱动模块:GPIO中断+软件去抖,支持BOOT和KEY2按键事件回调 - 休眠管理器:10秒无操作自动休眠,触摸/按键唤醒,UI集成开关 - 电池电量监控:GPIO3 ADC实时检测,ScreenSet界面圆弧显示 🐛 Bug修复 - 修复FreeRTOS任务栈溢出导致内存损坏(battery任务栈2048→4096) - 修复图片文件名损坏问题(改用静态缓冲区替代动态分配) - 修复触摸中断引脚配置错误(GPIO4→GPIO5,匹配V1.0硬件) - 修复开机闪烁问题(调整背光初始化时序,UI渲染后再点亮) 🎨 界面优化 - ScreenSet恢复为标准Screen切换方式(移除浮动面板架构) - 亮度调节支持0%(完全关闭)和10-100%范围 - ScreenHome界面电量显示独立(不关联实时电量) - 手势导航优化:下拉显示设置,上滑返回主界面 ⚡ 性能优化 - 启动时间优化:从650ms缩短至170ms - 内存管理优化:图片列表使用静态数组(10×32字节) - 任务栈配置调优:battery 4096, button 3072, sleep_mgr 3072 📝 其他改进 - CMakeLists.txt添加新模块编译配置 - 添加硬件版本兼容性注释(GPIO引脚说明) - 完善函数注释和错误日志输出 - sdkconfig配置更新 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
ESP LCD Touch CST816S Controller
Implementation of the CST816S touch controller with esp_lcd_touch component.
| Touch controller | Communication interface | Component name | Link to datasheet |
|---|---|---|---|
| CST816S | I2C | esp_lcd_touch_cst816s | datasheet |
Note
- There are two things about the driver are noteworthy (from document):
- It only responds to I2C commands after an event, such as a touch detection. Do not expect it to respond on init. Instead after a touch event, it will assert the IRQ and respond to I2C reads for a short time.
- While it should be able to detect multiple finger events, this version of the chip always returns only a single finger event and a gesture. Reading the display data multiple times during a single event will return the last sampled finger position.
- For some chips, reading ID may cause initialization failure. Disable reading ID by setting
CONFIG_ESP_LCD_TOUCH_CST816S_DISABLE_READ_IDtoyinmenuconfig.
Add to project
Packages from this repository are uploaded to Espressif's component service.
You can add them to your project via idf.py add-dependancy, e.g.
idf.py add-dependency esp_lcd_touch_cst816s==1.0.0
Alternatively, you can create idf_component.yml. More is in Espressif's documentation.
Example use
Define a mutex for the touch and create it before initialize the touch:
static SemaphoreHandle_t touch_mux;
touch_mux = xSemaphoreCreateBinary();
Define a callback function used by ISR:
static void touch_callback(esp_lcd_touch_handle_t tp)
{
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
xSemaphoreGiveFromISR(touch_mux, &xHigherPriorityTaskWoken);
if (xHigherPriorityTaskWoken) {
portYIELD_FROM_ISR();
}
}
Initialization of the touch component.
esp_lcd_panel_io_i2c_config_t io_config = ESP_LCD_TOUCH_IO_I2C_CST816S_CONFIG();
esp_lcd_touch_config_t tp_cfg = {
.x_max = CONFIG_LCD_HRES,
.y_max = CONFIG_LCD_VRES,
.rst_gpio_num = CONFIG_LCD_TOUCH_RST,
.int_gpio_num = CONFIG_LCD_TOUCH_INT,
.levels = {
.reset = 0,
.interrupt = 0,
},
.flags = {
.swap_xy = 0,
.mirror_x = 0,
.mirror_y = 0,
},
.interrupt_callback = touch_callback,
};
esp_lcd_touch_handle_t tp;
esp_lcd_touch_new_i2c_cst816s(io_handle, &tp_cfg, &tp);
Read data from the touch controller and store it in RAM memory. It should be called regularly in poll.
if (xSemaphoreTake(touch_mux, 0) == pdTRUE) {
esp_lcd_touch_read_data(tp); // read only when ISR was triggled
}
Get one X and Y coordinates with strength of touch.
uint16_t touch_x[1];
uint16_t touch_y[1];
uint16_t touch_strength[1];
uint8_t touch_cnt = 0;
bool touchpad_pressed = esp_lcd_touch_get_coordinates(tp, touch_x, touch_y, touch_strength, &touch_cnt, 1);