ToughC5 fixes: SPI DMA on AHB_DMA, internal I2C on the low power port, touch retries - #238
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Bring-up fixes for the M5Stack ToughC5 (ESP32-C5), addressing touch stability during motion, ESP32-C5/C61 SPI DMA descriptor programming, internal I2C routing to the low-power controller, and increasing the ToughC5 SPI write clock.
Changes:
- Switch ToughC5 internal I2C (G2/G3) to the LP_I2C port when supported (ESP-IDF ≥ 5.4 + i2c_master driver), keeping HP I2C0 free for the external bus.
- Improve CHSC6540 touch behavior by dropping frames with incomplete coordinate payload reads and by returning the most recent reading when retries are exhausted (instead of reporting “no touch”).
- Update ESP32-C5/C61 SPI DMA setup to write the DMA descriptor address to the dedicated OUT_LINK_ADDR register (matching AHB_DMA behavior), and increase ToughC5 SPI write frequency to 40 MHz.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/M5GFX.cpp | Routes ToughC5 internal I2C to LP_I2C when available; bumps ToughC5 SPI write clock; uses selected I2C port for touch config. |
| src/lgfx/v1/touch/Touch_CHSC6540.cpp | Makes touch reads resilient to motion by avoiding “no touch” on retry exhaustion and dropping incomplete frames. |
| src/lgfx/v1/platforms/esp32/Bus_SPI.hpp | Extends DMA “second register” support to ESP32-C5/C61 for descriptor address programming. |
| src/lgfx/v1/platforms/esp32/Bus_SPI.cpp | Implements ESP32-C5/C61 AHB_DMA OUT_LINK_ADDR register writes for DMA descriptor address. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The consecutive reads exist to reject a frame whose bytes changed mid-read, but while a finger is moving no two reads agree: the retries run out and the function reported no touch at all, so drags and flicks kept breaking up mid-gesture. Adopt the most recent reading instead, the way Touch_FT5x06 already does. A frame whose coordinate payload could not be read is dropped rather than adopted, so a torn read does not turn into a touch at (0,0).
On the GDMA chips (C3 / S3 / C6) the OUT_LINK register carries the descriptor address bits [19:0] together with the START bit, and Bus_SPI ORs the address into its START writes. The AHB_DMA generation dropped the address bits from OUT_LINK and reads them from a separate OUT_LINK_ADDR_CHn register: the OR is silently ignored, the DMA starts with no descriptor, and the first DMA transfer hangs waiting for an OUT FIFO that never fills. The P4 (AXI_DMA) already needed a split address register; reuse that two-register path on the C5 and C61, whose OUT_LINK_ADDR_CHn registers sit 4 bytes apart. The H4 carries an AHB_DMA too but lays these registers out inside each channel block, so it keeps the old path. Verified on an ESP32-C5.
The internal bus (SDA=G2 / SCL=G3) sits exactly on the C5's fixed LP_I2C pads. Move the backlight, the touch panel and the post-detection bus onto the low power port; Port A is a level-shifted branch of the same bus, so this leaves the C5's single high power I2C controller entirely free. On Arduino builds this also takes the internal devices off TwoWire, since the low power port is driven by the ESP-IDF driver directly. The port choice follows the exact condition the common I2C code compiles its low power support under (ESP-IDF 5.4 with the new driver); anything older stays on the high power port. Pairs with the M5Unified change that moves In_I2C to the same port.
The same ILI9342 panel already runs at this rate on the Core2 and Tough; verified on the actual board.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bring-up fixes and tuning for the M5Stack ToughC5 (ESP32-C5). Four commits:
Verified on the actual board (display, backlight, touch, DMA transfers). The low power port commit pairs with m5stack/M5Unified#296 (In_I2C on the same port); the two should land together.