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:
@@ -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