Skip to content

Migrate display from TFT_eSPI to LovyanGFX#37

Draft
theNailz wants to merge 3 commits intoKeralots:mainfrom
theNailz:feature/lovyan-gfx
Draft

Migrate display from TFT_eSPI to LovyanGFX#37
theNailz wants to merge 3 commits intoKeralots:mainfrom
theNailz:feature/lovyan-gfx

Conversation

@theNailz
Copy link
Copy Markdown
Contributor

Summary

  • Replaces TFT_eSPI with LovyanGFX across the entire display stack (S3, CYD, C3)
  • Board-specific SPI/panel configurations moved from platformio.ini build flags into typed C++ classes in display_ui.cpp, eliminating the User_Setup.h pattern entirely
  • platformio.ini simplified significantly — no more per-env driver/pin defines
  • C3 no longer needs the SPI patch pre-script (LovyanGFX handles it natively)
  • Arc gauges use fillArc (filled rings) with a +90° angle offset to match the original gap-at-bottom orientation
  • alphaBlend565() helper replaces tft.alphaBlend() (not a member in LGFX)
  • drawArc (outline) replaces drawSmoothArc in animation code
  • S3 requires invertDisplay(true) at runtime for correct ST7789 colors
  • OTA update screen no longer gated behind #ifdef ENABLE_OTA_AUTO

Flash usage (after migration)

Board Flash used
S3 69.1%
CYD 66.7%
C3 65.3%

Test plan

  • All three environments build clean
  • Flashed and verified on S3 — display, gauges, arcs, animations all correct
  • Verify CYD
  • Verify C3

@theNailz
Copy link
Copy Markdown
Contributor Author

Trying to test with C3 and CYD and C3 is booting with color reversed but after reboot, display is not working at all (and another flash using new firmware does not change it, it's still dead). CYD is not compatible, I see similar issues when I was trying to use ILI9341 driver (but it worked with ILI9341_2), This library has the same problem with screen rotation and bottom 80px not working.

The ESP32 is too busy writing flash to respond to /ota/status poll
requests, so _autoOtaProgress often stays at a low value (e.g. 25%)
even when the download completes successfully. The previous >= 90%
threshold guard then blocked waitForReboot(), leaving the UI frozen.

Replace the progress threshold with an _otaInstallStarted flag set
after the server confirms the OTA task has begun. Any 404/network
error after install is confirmed now correctly triggers waitForReboot(),
regardless of the last polled progress value.
platformio.ini (esp32c3 env):
- Switch to partitions_4mb_c3.csv (1.875 MB OTA partitions)
- build_unflags: strip LOAD_GFXFF and SMOOTH_FONT — GFX free fonts and
  smooth VLW font renderer are compiled in by default but never used
- Explicit lib_deps without TFT_eWidget (dead code for C3)

partitions_4mb_c3.csv (new):
- app0/app1: 0x1E0000 (1.875 MB) each, up from 1.75 MB
- SPIFFS: 0x30000 (192 KB), reduced from 448 KB — SPIFFS unused in BambuHelper
- Result: 65 KB → 733 KB headroom
- Note: partition table change requires USB re-flash; OTA updates thereafter

src/main.cpp, src/display_ui.cpp:
- USB CDC startup delay and Serial.flush() removal (previously unstaged)
Replace TFT_eSPI with LovyanGFX across the entire display stack.
Board-specific configs (S3, CYD, C3) are C++ classes in display_ui.cpp.
SPI pins and driver settings move from build_flags into the class configs,
simplifying platformio.ini significantly. The C3 no longer needs the SPI
patch script.

Key changes:
- Three LGFX board classes: LGFX_S3 (ST7789), LGFX_CYD (ILI9342), LGFX_C3 (ST7789)
- fillArc replaces drawSmoothArc in gauge rendering; +90deg angle offset
  matches original gap-at-bottom orientation
- alphaBlend565() helper replaces tft.alphaBlend() (not a member in LGFX)
- drawArc (outline) replaces drawSmoothArc in animation code
- S3 requires invertDisplay(true) at runtime for correct colors
- Backlight handled via BACKLIGHT_PIN + analogWrite (unchanged)
- config.h: BACKLIGHT_PIN guard added (was hardcoded to TFT_BL)
@theNailz theNailz force-pushed the feature/lovyan-gfx branch from f2f0bd9 to ab274a7 Compare March 31, 2026 18:10
@theNailz theNailz marked this pull request as draft March 31, 2026 18:12
@theNailz
Copy link
Copy Markdown
Contributor Author

theNailz commented Apr 1, 2026

I'm waiting for my C3 and CYD to finalize this; might take a few days

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