Skip to content

input: release touch handles before deleting the i2c bus#307

Open
CaTeIM wants to merge 1 commit into
Blockstream:masterfrom
CaTeIM:fix-touchscreen-i2c-deinit
Open

input: release touch handles before deleting the i2c bus#307
CaTeIM wants to merge 1 commit into
Blockstream:masterfrom
CaTeIM:fix-touchscreen-i2c-deinit

Conversation

@CaTeIM

@CaTeIM CaTeIM commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes the boot hang and camera freezes on the Waveshare S3 Touch LCD 2 reported in #306, caused by an undocumented breaking change in ESP-IDF 5.5. Fixes #306.

Root Cause

  • The regression bisects to a single commit: d931d543 (esp-idf: update to v5.5.4).
  • Since IDF v5.5.0 (espressif/esp-idf@e73d78ba), i2c_del_master_bus() refuses to delete a bus that still has devices attached and returns ESP_ERR_INVALID_STATE. Under v5.4 it destroyed the bus unconditionally.
  • The touchscreen task registers a panel IO device on its i2c bus (esp_lcd_new_panel_io_i2c(), touchscreen.inc:57) but never releases it, so the first touchscreen_deinit() fails at ESP_ERROR_CHECK(_i2c_deinit(...)) (touchscreen.inc:94) and aborts.
  • This board panics with CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y, so it halts frozen on whatever is on screen.
  • The only callers of touchscreen_deinit()/init() are jade_camera_init()/jade_camera_stop() (camera.c:323-337), which explains all three symptoms: boot entropy (splash), scanner stuck at "Initializing...", and the freeze when leaving the camera.

Changes

main/input/touchscreen.inc

  • Fix: Release the touch handle (esp_lcd_touch_del) and the panel IO device (esp_lcd_panel_io_del, which removes it from the bus) before deleting the i2c bus.
  • Result: The deinit/init cycle works again under IDF 5.5.4 for all touchscreen boards, including M5CoreS3, where the restart around the camera is load-bearing (camera and touch share i2c pins).
  • Bonus: Also fixes a heap leak present under IDF 5.4, where both handles leaked on every camera start/stop cycle.

Testing

  • Tested on real hardware (Waveshare S3 Touch LCD 2): boot passes the splash, the QR scanner opens and scans, exiting and re-opening the camera works, and touch keeps working afterwards.

Motivation

Restores basic usability for touchscreen DIY boards after the IDF 5.5.4 update with the smallest possible diff (3 lines) at the root cause, instead of board-specific workarounds.

Since ESP-IDF v5.5 (espressif/esp-idf@e73d78ba) i2c_del_master_bus()
refuses to delete a bus that still has devices attached and returns
ESP_ERR_INVALID_STATE. The touchscreen task registers a panel IO
device on the bus but never releases it, so under IDF 5.5.4 the first
touchscreen_deinit() fails and aborts via ESP_ERROR_CHECK.

On boards that panic with PRINT_HALT, such as the Waveshare S3 Touch
LCD 2, this freezes the device on the boot splash screen while
gathering camera entropy, and also hangs the QR scanner and the
camera exit path, since the touchscreen is restarted around every
camera start/stop (see Blockstream#306).

Releasing the touch handle and the panel IO device (which removes it
from the bus) before deleting the bus restores the deinit/init cycle,
and also fixes a heap leak present under IDF 5.4 where both handles
leaked on every cycle.

Co-authored-by: oroderico <oroderico@users.noreply.github.com>
@CaTeIM CaTeIM force-pushed the fix-touchscreen-i2c-deinit branch from b7d0b66 to d7c5d51 Compare July 10, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Waveshare ESP32-S3 Touch LCD 2 camera hangs after IDF 5.5 update

1 participant