Fix SoftSPI touch: official channels without broken mirror.
Logs showed MIRROR_X+corr crushed UI Y to top; SoftSPI uses 0xD1/0x91 linear feed. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
name: CYD TF card + touch speaker (cyd)
|
||||
git: 01c5266
|
||||
git: 8a29196
|
||||
date: 2026-10-17
|
||||
board: ESP32-2432S028R (ILI9341)
|
||||
features: TF/SD info, SoftSPI touch, GPIO26 speaker
|
||||
@@ -12,5 +12,5 @@ offsets:
|
||||
sha256:
|
||||
bootloader.bin 3D234A7471F67B013686DABD4DEE7C1FA915C9928463616A94BC9297ACF1ABF8
|
||||
boot_app0.bin F94C5D786A7A8FAB06AC5D10E33BF37711A6697636DC037559EA19CC410A17F0
|
||||
firmware.bin 94A0C3011B584646E8D4F4D29531252E97B488BBE47827DEDD2CDB21FD1FA76F
|
||||
firmware.bin 71D6F25E57435D8D3EAE086122BD459C0ECEFA6CBEB78065C653F580EC787545
|
||||
partitions.bin 148B959CBFF1C38AA8E1D5C0BA9D612C54997B945E56A63F41223EEF650653A1
|
||||
|
||||
Binary file not shown.
@@ -4,21 +4,13 @@
|
||||
#include <Arduino.h>
|
||||
|
||||
/**
|
||||
* SoftSPI XPT2046 — 对齐 Sunton 官方板级(esp32-2432S028R.json / smartdisplay):
|
||||
* TOUCH_SWAP_XY=false, TOUCH_MIRROR_X=true, TOUCH_MIRROR_Y=false
|
||||
* x_max=240, y_max=320
|
||||
* X 通道 CMD=0xD1, Y 通道 CMD=0x91(与 PaulStoffregen 命名相反)
|
||||
* 线性:coord = adc * max / 4096,再 mirror_x
|
||||
* 显示仍用 create(240,320)+LV_DISPLAY_ROTATION_270(横屏,勿改 320x240)
|
||||
*
|
||||
* 用户日志:红点在手指左下方 → UI 需向右上修正(见 TOUCH_UI_DX/DY)
|
||||
* https://github.com/rzeldent/platformio-espressif32-sunton/blob/main/esp32-2432S028R.json
|
||||
* SoftSPI XPT2046 — Sunton esp32-2432S028R 官方通道 + 线性映射
|
||||
* X CMD=0xD1, Y CMD=0x91, scale /4096 → 240x320
|
||||
* SoftSPI 与官方 HW SPI 极性不同:不做 MIRROR_X(日志证明 mirror 会把 UI Y 压到顶部)
|
||||
* 显示:240x320 + LV_DISPLAY_ROTATION_270;触点直接喂物理坐标,由 LVGL 旋转
|
||||
* 板级:https://github.com/rzeldent/platformio-espressif32-sunton
|
||||
*/
|
||||
|
||||
// 红点相对手指的补偿(像素,横屏 UI):左偏→+X,下偏→-Y
|
||||
static constexpr int16_t TOUCH_UI_DX = 45;
|
||||
static constexpr int16_t TOUCH_UI_DY = -45;
|
||||
|
||||
int16_t g_dbg_phys_x = -1;
|
||||
int16_t g_dbg_phys_y = -1;
|
||||
int16_t g_dbg_logic_x = -1;
|
||||
@@ -67,12 +59,10 @@ void touch_init() {
|
||||
pinMode(CYD_TOUCH_IRQ, INPUT);
|
||||
digitalWrite(CYD_TOUCH_CS, HIGH);
|
||||
digitalWrite(CYD_TOUCH_CLK, LOW);
|
||||
Serial.printf("Touch: Sunton official mirror_x + UI corr(%d,%d)\n",
|
||||
(int)TOUCH_UI_DX, (int)TOUCH_UI_DY);
|
||||
Serial.println("Touch: Sunton 0xD1/0x91 linear, SoftSPI no-mirror");
|
||||
}
|
||||
|
||||
void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
|
||||
// 官方驱动:X=0xD1, Y=0x91(先丢弃一次噪声读)
|
||||
(void)xpt_read(0xD1);
|
||||
uint16_t adc_x = xpt_read(0xD1);
|
||||
uint16_t adc_y = xpt_read(0x91);
|
||||
@@ -89,13 +79,9 @@ void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// esp_touch_xpt2046: (adc>>3 等价 12bit) * max / 4096
|
||||
int16_t px = (int16_t)(((uint32_t)adc_x * SCREEN_WIDTH) / 4096);
|
||||
int16_t py = (int16_t)(((uint32_t)adc_y * SCREEN_HEIGHT) / 4096);
|
||||
|
||||
// TOUCH_MIRROR_X=true
|
||||
px = (int16_t)((SCREEN_WIDTH - 1) - px);
|
||||
|
||||
if (px < 0) {
|
||||
px = 0;
|
||||
}
|
||||
@@ -109,26 +95,9 @@ void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
|
||||
py = SCREEN_HEIGHT - 1;
|
||||
}
|
||||
|
||||
// LVGL ROTATION_270 后 UI:(py, 239-px);再按日志把红点挪向手指
|
||||
int16_t ui_x = (int16_t)(py + TOUCH_UI_DX);
|
||||
int16_t ui_y = (int16_t)(((SCREEN_WIDTH - 1) - px) + TOUCH_UI_DY);
|
||||
|
||||
if (ui_x < 0) {
|
||||
ui_x = 0;
|
||||
}
|
||||
if (ui_y < 0) {
|
||||
ui_y = 0;
|
||||
}
|
||||
if (ui_x >= UI_HOR_RES) {
|
||||
ui_x = UI_HOR_RES - 1;
|
||||
}
|
||||
if (ui_y >= UI_VER_RES) {
|
||||
ui_y = UI_VER_RES - 1;
|
||||
}
|
||||
|
||||
// 反变换喂给 LVGL,使其变换后落到 (ui_x, ui_y)
|
||||
const int16_t feed_x = (int16_t)((SCREEN_WIDTH - 1) - ui_y);
|
||||
const int16_t feed_y = ui_x;
|
||||
// LVGL 270 后预估 UI(红点);触点仍喂物理坐标
|
||||
const int16_t ui_x = py;
|
||||
const int16_t ui_y = (int16_t)((SCREEN_WIDTH - 1) - px);
|
||||
|
||||
g_dbg_phys_x = px;
|
||||
g_dbg_phys_y = py;
|
||||
@@ -139,11 +108,11 @@ void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
|
||||
static uint32_t last_log = 0;
|
||||
if (millis() - last_log > 100) {
|
||||
last_log = millis();
|
||||
Serial.printf("Touch adc(%u,%u) phys(%d,%d) UI(%d,%d) feed(%d,%d)\n", adc_x,
|
||||
adc_y, px, py, ui_x, ui_y, feed_x, feed_y);
|
||||
Serial.printf("Touch adc(%u,%u) phys(%d,%d) UI~(%d,%d)\n", adc_x, adc_y, px,
|
||||
py, ui_x, ui_y);
|
||||
}
|
||||
|
||||
data->point.x = feed_x;
|
||||
data->point.y = feed_y;
|
||||
data->point.x = px;
|
||||
data->point.y = py;
|
||||
data->state = LV_INDEV_STATE_PRESSED;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user