Restore landscape display and use RNT SoftSPI touch map.

Revert 320x240 create that garbled the panel; map touch to 240x320 like Random Nerd Tutorials.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-10-17 18:18:28 +08:00
parent 1381c221d9
commit 01c52661e4
6 changed files with 41 additions and 31 deletions

View File

@@ -1,12 +1,14 @@
# Changelog # Changelog
## 2026-10-17 — Touch = draw coords (CYD LVGL9 official) ## 2026-10-17 — Restore landscape + RNT touch map
- Root cause: `LV_DISPLAY_ROTATION_270` double-transforms touch vs TFT_eSPI - Revert create(320x240) — caused 花屏; keep 240x320 + ROTATION_270 landscape.
(lvgl#7841 / CYD community). - Touch = Random Nerd Tutorials recipe: SoftSPI rot2, map to 240x320, feed LVGL
- Fix per witnessmenow LVGL9 example: create display 320x240, rotation 0; directly (no extra inverse). Red cursor shows estimated UI point.
SoftSPI `setRotation(3)` map straight into the same 320x240 space.
- Red touch cursor follows reported point for visual check. ## 2026-10-17 — Touch = draw coords (CYD LVGL9 official) [reverted]
- create(320x240) without LVGL rot caused 花屏 on this panel; superseded.
## 2026-10-17 — SoftSPI touch + LVGL inverse (fix mux) ## 2026-10-17 — SoftSPI touch + LVGL inverse (fix mux)

View File

@@ -1,5 +1,5 @@
name: CYD TF card + touch speaker (cyd) name: CYD TF card + touch speaker (cyd)
git: 3768e54 git: 1381c22
date: 2026-10-17 date: 2026-10-17
board: ESP32-2432S028R (ILI9341) board: ESP32-2432S028R (ILI9341)
features: TF/SD info, SoftSPI touch, GPIO26 speaker features: TF/SD info, SoftSPI touch, GPIO26 speaker
@@ -12,5 +12,5 @@ offsets:
sha256: sha256:
bootloader.bin 3D234A7471F67B013686DABD4DEE7C1FA915C9928463616A94BC9297ACF1ABF8 bootloader.bin 3D234A7471F67B013686DABD4DEE7C1FA915C9928463616A94BC9297ACF1ABF8
boot_app0.bin F94C5D786A7A8FAB06AC5D10E33BF37711A6697636DC037559EA19CC410A17F0 boot_app0.bin F94C5D786A7A8FAB06AC5D10E33BF37711A6697636DC037559EA19CC410A17F0
firmware.bin DC7BD1738756078B002918725F5CE6C6B349ADBF8E9ADC0A209668D07C0F00ED firmware.bin 7C632F8D033997F18F39056F321011B2DB7D0B0FA64F14FED269EB70EE86C814
partitions.bin 148B959CBFF1C38AA8E1D5C0BA9D612C54997B945E56A63F41223EEF650653A1 partitions.bin 148B959CBFF1C38AA8E1D5C0BA9D612C54997B945E56A63F41223EEF650653A1

Binary file not shown.

View File

@@ -21,8 +21,8 @@
#define CYD_TOUCH_CLK 25 #define CYD_TOUCH_CLK 25
#define CYD_TOUCH_CS 33 #define CYD_TOUCH_CS 33
// 横屏 UI(与 witnessmenow CYD LVGL9 官方例程一致:直接 320x240,不用 LVGL 二次旋转) // 与 Random Nerd Tutorials / temperature 一致:物理竖屏 + LVGL 270 得横屏
#define SCREEN_WIDTH 320 #define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 240 #define SCREEN_HEIGHT 320
#define UI_HOR_RES SCREEN_WIDTH #define UI_HOR_RES 320
#define UI_VER_RES SCREEN_HEIGHT #define UI_VER_RES 240

View File

@@ -45,10 +45,11 @@ void setup() {
lv_init(); lv_init();
// 官方 CYD LVGL9:直接 320x240,不用 LV_DISPLAY_ROTATION_*(避免触控二次变换错位) // RNT / temperature:240x320 + ROTATION_270 → 横屏(勿改成 create 320x240,会花屏)
// https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/tree/main/Examples/LVGL9 // https://randomnerdtutorials.com/lvgl-cheap-yellow-display-esp32-2432s028r/
lv_display_t *disp = lv_display_t *disp =
lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf)); lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
lv_indev_t *indev = lv_indev_create(); lv_indev_t *indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER); lv_indev_set_type(indev, LV_INDEV_TYPE_POINTER);

View File

@@ -4,12 +4,15 @@
#include <Arduino.h> #include <Arduino.h>
/** /**
* SoftSPI XPT2046 — 与 SD 分脚 * SoftSPI XPT2046(SD 占 VSPI,触摸必须 SoftSPI)
* *
* 对齐官方 CYD LVGL9 例程(witnessmenow): * 现成方案 — Random Nerd Tutorials CYD + LVGL:
* - 显示直接建为 320x240,LVGL rotation=0(触控不再被二次变换) * create(240,320) + LV_DISPLAY_ROTATION_270
* - touch setRotation(3) + map 到 SCREEN_WIDTH/HEIGHT * touchscreen.setRotation(2)
* 参考:https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display/blob/main/Examples/LVGL9/ * x = map(p.x, 200, 3700, 1, 240)
* y = map(p.y, 240, 3800, 1, 320)
* 直接喂给 LVGL(由 LVGL 做旋转,不要再反变换 / 不要建 320x240)
* https://randomnerdtutorials.com/lvgl-cheap-yellow-display-esp32-2432s028r/
*/ */
int16_t g_dbg_phys_x = -1; int16_t g_dbg_phys_x = -1;
@@ -60,7 +63,7 @@ void touch_init() {
pinMode(CYD_TOUCH_IRQ, INPUT); pinMode(CYD_TOUCH_IRQ, INPUT);
digitalWrite(CYD_TOUCH_CS, HIGH); digitalWrite(CYD_TOUCH_CS, HIGH);
digitalWrite(CYD_TOUCH_CLK, LOW); digitalWrite(CYD_TOUCH_CLK, LOW);
Serial.println("Touch: SoftSPI rot3 map 320x240 (no LVGL rot)"); Serial.println("Touch: RNT SoftSPI rot2 map 240x320");
} }
void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) { void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
@@ -79,11 +82,11 @@ void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
return; return;
} }
// XPT2046_Touchscreen setRotation(3): // XPT2046_Touchscreen setRotation(2)
// xraw = 4095 - Y_sample, yraw = 4095 - X_sample const int16_t p_x = (int16_t)adc_x;
const int16_t p_x = (int16_t)(4095 - adc_y); const int16_t p_y = (int16_t)(4095 - adc_y);
const int16_t p_y = (int16_t)(4095 - adc_x);
// RNT:映射到物理 240x320,交给 LVGL ROTATION_270
int16_t x = map(p_x, 200, 3700, 1, SCREEN_WIDTH); int16_t x = map(p_x, 200, 3700, 1, SCREEN_WIDTH);
int16_t y = map(p_y, 240, 3800, 1, SCREEN_HEIGHT); int16_t y = map(p_y, 240, 3800, 1, SCREEN_HEIGHT);
@@ -100,17 +103,21 @@ void touch_read_cb(lv_indev_t * /*indev*/, lv_indev_data_t *data) {
y = SCREEN_HEIGHT - 1; y = SCREEN_HEIGHT - 1;
} }
g_dbg_phys_x = p_x; // 预估 LVGL 270 后的 UI 坐标(光标用):(y, 239-x)
g_dbg_phys_y = p_y; const int16_t ui_x = y;
g_dbg_logic_x = x; const int16_t ui_y = (int16_t)((SCREEN_WIDTH - 1) - x);
g_dbg_logic_y = y;
g_dbg_phys_x = x;
g_dbg_phys_y = y;
g_dbg_logic_x = ui_x;
g_dbg_logic_y = ui_y;
g_dbg_touch_down = true; g_dbg_touch_down = true;
static uint32_t last_log = 0; static uint32_t last_log = 0;
if (millis() - last_log > 120) { if (millis() - last_log > 120) {
last_log = millis(); last_log = millis();
Serial.printf("Touch adc(%u,%u) p(%d,%d) -> (%d,%d)\n", adc_x, adc_y, p_x, Serial.printf("Touch p(%d,%d) feed(%d,%d) UI~(%d,%d)\n", p_x, p_y, x, y,
p_y, x, y); ui_x, ui_y);
} }
data->point.x = x; data->point.x = x;