Add capacitive touch-button test optimized from btntest.

TTP223-style debounce (majority, min touch, rearm), SoftSPI+LVGL shell, flashable firmware/cyd.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-23 13:15:39 +08:00
commit 7f0f391705
23 changed files with 2014 additions and 0 deletions

16
include/button.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include <stdint.h>
void button_init();
/** 轮询:检测有效触摸边沿,返回本周期是否有一次有效触摸 */
bool button_poll_press();
uint32_t button_count();
void button_reset_count();
bool button_is_down();
/** 当前持续触摸时长(ms);未触摸为 0 */
uint32_t button_hold_ms();
/** 原始电平:1=HIGH,0=LOW */
int button_raw_level();
/** 触摸有效电平:1=HIGH 有效,0=LOW 有效(开机按空闲电平自动判定) */
int button_active_level();

1127
include/lv_conf.h Normal file

File diff suppressed because it is too large Load Diff

20
include/pins.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
// CYD ESP32-2432S028R — 触控/屏脚与 tftest / btntest 一致
#define TFT_BL_PIN 21
#define CYD_TOUCH_IRQ 36
#define CYD_TOUCH_MOSI 32
#define CYD_TOUCH_MISO 39
#define CYD_TOUCH_CLK 25
#define CYD_TOUCH_CS 33
// 三脚触控感应模块 OUT/S/DO → GPIO22(VCC→3.3V,GND→GND)
// 典型:TTP223 电容触摸(非机械轻触)
#define BTN_PIN 22
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
#define UI_HOR_RES 320
#define UI_VER_RES 240

12
include/touch.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include <lvgl.h>
#include <stdint.h>
void touch_init();
void touch_read_cb(lv_indev_t *indev, lv_indev_data_t *data);
// 调试:最近一次触点(物理 / LVGL 旋转后逻辑)
extern int16_t g_dbg_phys_x, g_dbg_phys_y;
extern int16_t g_dbg_logic_x, g_dbg_logic_y;
extern bool g_dbg_touch_down;

4
include/ui.h Normal file
View File

@@ -0,0 +1,4 @@
#pragma once
void ui_create();
void ui_refresh_count();