From 9d3a8505c0a79ec9cd07275151f7d2eca08e0028 Mon Sep 17 00:00:00 2001 From: ainyan03 Date: Sun, 16 Aug 2026 11:41:00 +0000 Subject: [PATCH] Wait for the touch controller response when identifying the M5Tab5 panel The ST71xx touch controller needs several tens of milliseconds to respond again when it is reset during scan operation. The previous 3-attempt probe gave up too early, so a warm reset from a running state (esp_restart or the reset caused by connecting a serial monitor) left the panel type undetected and the screen blank. Poll until a recognized ST71xx firmware version is read or the GT911 (ILI9881C variant) ACKs, up to roughly 600 ms. The ST variants still require the touch FW version to distinguish their DSI timings; a unit whose touch never responds falls back to the previous behavior (the ILI9881C variant is still identified by its DSI ID). --- src/M5GFX.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/M5GFX.cpp b/src/M5GFX.cpp index b704c71..5a9a074 100644 --- a/src/M5GFX.cpp +++ b/src/M5GFX.cpp @@ -2940,12 +2940,26 @@ The usage of each pin is as follows. bool hit_st7121 = false; bool hit_st7123 = false; bool read_st_touch_fw = false; - for (int i = 0; i < 3; ++i) { + bool found_gt911 = false; + // ST71xx のタッチコントローラは、スキャン動作中にリセットされた場合、 + // 応答可能になるまで数十 ms を要する (実測: 稼働中からのソフトリセット後 + // およそ 50ms)。待ちを打ち切ると ST パネルの判別に失敗して表示が出ない + // (ST7121/ST7123 は lane 速度が異なり DSI ID では安全に区別できない) ため、 + // ST touch の既知 FW 版数 (1/3) を認識するか GT911 (ILI9881C 個体) が + // ACK するまで待つ。 + int last_logged_fw = -1; + for (int i = 0; i < 60; ++i) { uint8_t fw_version = 0; uint8_t fw_reg[2] = { 0, 0 }; if (lgfx::i2c::transactionWriteRead(probe_i2c_port, Touch_ST7123::default_addr, fw_reg, sizeof(fw_reg), &fw_version, 1, 100000).has_value()) { read_st_touch_fw = true; - ESP_LOGI(LIBRARY_NAME, "M5Tab5 ST touch FW version %02x", fw_version); + if (fw_version != last_logged_fw) { // 未知値のリトライ継続で同じログを繰り返さない + last_logged_fw = fw_version; + ESP_LOGI(LIBRARY_NAME, "M5Tab5 ST touch FW version %02x", fw_version); + if (fw_version != 1 && fw_version != 3) { + ESP_LOGW(LIBRARY_NAME, "M5Tab5 unknown ST touch FW version %02x", fw_version); + } + } if (fw_version == 1) { hit_st7121 = true; break; @@ -2954,11 +2968,18 @@ The usage of each pin is as follows. hit_st7123 = true; break; } - ESP_LOGW(LIBRARY_NAME, "M5Tab5 unknown ST touch FW version %02x", fw_version); + } else { + // GT911 はアドレス ACK の確認のみ (実読すると内部ポインタを進めてしまう) + if (lgfx::i2c::beginTransaction(probe_i2c_port, Touch_GT911::default_addr_1, 100000, false).has_value() + && lgfx::i2c::endTransaction(probe_i2c_port).has_value()) { + found_gt911 = true; + ESP_LOGI(LIBRARY_NAME, "M5Tab5 GT911 touch detected"); + break; + } } lgfx::delay(10); } - if (!read_st_touch_fw) { + if (!read_st_touch_fw && !found_gt911) { ESP_LOGW(LIBRARY_NAME, "M5Tab5 ST touch FW version read failed"); }