diff --git a/firmware/cyd/VERSION.txt b/firmware/cyd/VERSION.txt index 3684e55..fa31bdc 100644 --- a/firmware/cyd/VERSION.txt +++ b/firmware/cyd/VERSION.txt @@ -1,5 +1,5 @@ name: CYD TF card + touch speaker (cyd) -git: f2b14eb +git: 4f41621 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 6A14D85F7466922C021B3288B7246987FD57DEC850741991C6E7671EA1BF7785 + firmware.bin 2D2D76255F85D2EB2ABBF0E7B98F32AC39E0692E1BAC99FF79DFF3F0B211CB47 partitions.bin 148B959CBFF1C38AA8E1D5C0BA9D612C54997B945E56A63F41223EEF650653A1 diff --git a/firmware/cyd/firmware.bin b/firmware/cyd/firmware.bin index 73d21b7..7b4d47b 100644 Binary files a/firmware/cyd/firmware.bin and b/firmware/cyd/firmware.bin differ diff --git a/src/touch.cpp b/src/touch.cpp index 87002f6..d43b68a 100644 --- a/src/touch.cpp +++ b/src/touch.cpp @@ -4,8 +4,9 @@ #include /** - * SoftSPI XPT2046 → 物理 240x320 → 交给 LVGL ROTATION_270 - * RNT 标定区间 + rot2;红点用变换后 UI 坐标 + * SoftSPI XPT2046 + * BL↔TR 是矩形主对角线镜像(XY 对调),不是 180°(180° 会搞成 TL↔BR)。 + * 先按 rot2 得到旧 UI,再做对角修正,反变换喂给 LVGL 270。 */ int16_t g_dbg_phys_x = -1; @@ -48,6 +49,16 @@ static uint16_t xpt_read(uint8_t cmd) { return v; } +static int16_t clampi(int32_t v, int32_t lo, int32_t hi) { + if (v < lo) { + return (int16_t)lo; + } + if (v > hi) { + return (int16_t)hi; + } + return (int16_t)v; +} + void touch_init() { pinMode(CYD_TOUCH_CS, OUTPUT); pinMode(CYD_TOUCH_CLK, OUTPUT); @@ -56,7 +67,7 @@ void touch_init() { pinMode(CYD_TOUCH_IRQ, INPUT); digitalWrite(CYD_TOUCH_CS, HIGH); digitalWrite(CYD_TOUCH_CLK, LOW); - Serial.println("Touch: SoftSPI rot2 map 240x320"); + Serial.println("Touch: SoftSPI + diagonal fix (BL/TR)"); } void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) { @@ -75,45 +86,40 @@ void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) { return; } - // setRotation(2) const int16_t p_x = (int16_t)adc_x; const int16_t p_y = (int16_t)(4095 - adc_y); int16_t x = map(p_x, 200, 3700, 1, SCREEN_WIDTH); int16_t y = map(p_y, 240, 3800, 1, SCREEN_HEIGHT); + x = clampi(x, 0, SCREEN_WIDTH - 1); + y = clampi(y, 0, SCREEN_HEIGHT - 1); - if (x < 0) { - x = 0; - } - if (y < 0) { - y = 0; - } - if (x >= SCREEN_WIDTH) { - x = SCREEN_WIDTH - 1; - } - if (y >= SCREEN_HEIGHT) { - y = SCREEN_HEIGHT - 1; - } + // 旧 UI(LVGL270):(y, 239-x) — 该空间里 BL↔TR,做主对角线镜像 + // (ux,uy) -> (uy*(319/239), ux*(239/319)) + const int32_t old_ux = y; + const int32_t old_uy = (SCREEN_WIDTH - 1) - x; + int16_t ui_x = clampi((old_uy * (UI_HOR_RES - 1)) / (UI_VER_RES - 1), 0, + UI_HOR_RES - 1); + int16_t ui_y = clampi((old_ux * (UI_VER_RES - 1)) / (UI_HOR_RES - 1), 0, + UI_VER_RES - 1); - // BL↔TR 对角反了:物理坐标整体旋转 180° - x = (int16_t)((SCREEN_WIDTH - 1) - x); - y = (int16_t)((SCREEN_HEIGHT - 1) - y); + // 反变换喂 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 g_dbg_phys_x = x; g_dbg_phys_y = y; - g_dbg_logic_x = y; - g_dbg_logic_y = (int16_t)((SCREEN_WIDTH - 1) - x); + g_dbg_logic_x = ui_x; + g_dbg_logic_y = ui_y; g_dbg_touch_down = true; static uint32_t last_log = 0; if (millis() - last_log > 80) { last_log = millis(); - Serial.printf("Touch phys(%d,%d) UI(%d,%d)\n", x, y, g_dbg_logic_x, - g_dbg_logic_y); + Serial.printf("Touch UI(%d,%d)\n", ui_x, ui_y); } - data->point.x = x; - data->point.y = y; + data->point.x = feed_x; + data->point.y = feed_y; data->state = LV_INDEV_STATE_PRESSED; }