Skip to content

Add standalone XPT2046 touch driver for RGB/ArduinoGFX boards (Sunton 4827S043R)#1028

Open
lucvan wants to merge 1 commit into
HASwitchPlate:masterfrom
lucvan:feat/xpt2046-standalone-touch
Open

Add standalone XPT2046 touch driver for RGB/ArduinoGFX boards (Sunton 4827S043R)#1028
lucvan wants to merge 1 commit into
HASwitchPlate:masterfrom
lucvan:feat/xpt2046-standalone-touch

Conversation

@lucvan

@lucvan lucvan commented Jul 7, 2026

Copy link
Copy Markdown

Problem

openHASP's XPT2046 support is only wired into the TFT_eSPI and LovyanGFX display drivers, which own the SPI touch read. RGB-parallel boards must use ArduinoGFX for the display, so on those boards TOUCH_DRIVER=0x2046 matches no branch in touch_driver.h and falls through to the no-op Generic Touch stub — resistive touch is silently dead. This is the blocker behind the unresolved reports of no touch on the Sunton ESP32-4827S043R (e.g. discussion #648).

Change

A self-contained XPT2046 touch driver that runs on its own SPI bus, independent of the display driver:

  • src/drv/touch/touch_driver_xpt2046.{h,cpp}TouchXpt2046 : BaseTouch using a dedicated SPIClass, PENIRQ press-detection, median-filtered 12-bit reads, and build-flag calibration (TOUCH_XPT2046_XMIN/XMAX/YMIN/YMAX, SWAP_XY, MIRROR_X/Y). Guarded to compile only when TOUCH_DRIVER==0x2046 and neither TFT_eSPI (USER_SETUP_LOADED) nor LovyanGFX (LGFX_USE_V1) is active — so it is a no-op on every existing board.
  • src/drv/touch/touch_driver.h — dispatch to the new driver in a branch placed after the existing TFT_eSPI/LovyanGFX 0x2046 branches, so those still win when their display driver is active.
  • user_setups/esp32s3/sunton-esp32-s3-tft.ini — turn the existing [sunton-4827s043r_16MB] template into a buildable [env:...], enable TOUCH_DRIVER=0x2046 with the board's touch pins, and add a measured calibration. The dead, uncalled src/drv/old/hasp_drv_touch.cpp is excluded for this env via build_src_filter (its 0x2046 branch assumes a TFT_eSPI display object and won't compile on ArduinoGFX).

Testing

Built and flashed to a Sunton ESP32-4827S043R. Display renders and resistive touch works, calibrated across the full 480×272 panel (corner taps map correctly). No other board's build is affected — both the new driver and the legacy-file exclusion are scoped (compile guards / per-env build_src_filter).

Notes

  • The touch pins for the 4827S043R (SCLK 12 / MISO 13 / MOSI 11 / CS 38 / IRQ 18) were already present in the board template; this makes them usable.
  • Calibration defaults are board-specific build flags and can be overridden per board.

openHASP's XPT2046 support was only wired into the TFT_eSPI and LovyanGFX
display drivers, which own the SPI touch read. RGB-parallel boards must use
ArduinoGFX for the display, so TOUCH_DRIVER=0x2046 there matched no dispatch
branch and fell through to the no-op "Generic Touch" stub -- resistive touch
was silently dead (discussion HASwitchPlate#648).

Add a self-contained driver that runs XPT2046 on its own SPI bus, independent
of the display driver:

- src/drv/touch/touch_driver_xpt2046.{h,cpp}: TouchXpt2046 : BaseTouch on a
  dedicated SPIClass, IRQ press-detect, median-filtered 12-bit reads, and
  build-flag calibration (raw min/max window, SWAP_XY, MIRROR_X/Y). Guarded to
  compile only when TOUCH_DRIVER==0x2046 and neither TFT_eSPI nor LovyanGFX is
  active, so it is a no-op on every other board.
- src/drv/touch/touch_driver.h: dispatch to the standalone driver after the
  existing TFT_eSPI/LovyanGFX 0x2046 branches (those still win when active).
- Enable it on the Sunton ESP32-4827S043R: make its env buildable, set
  TOUCH_DRIVER=0x2046 with the touch pins, and add a measured calibration.
  Exclude the dead, uncalled src/drv/old/hasp_drv_touch.cpp for this env, whose
  0x2046 branch assumes a TFT_eSPI display object.
- Register sunton-4827s043r_16MB in the CI build matrix and the
  platformio_override template, alongside the existing 4827s043c variant, so
  nightly builds publish the resistive firmware.

Verified on hardware: display and calibrated resistive touch working.

Signed-off-by: Luc Van <lucvan@gmail.com>
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.

1 participant