Use m5gfx::delay for internal hardware waits - #327
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates internal hardware timing waits to use m5gfx::delay() so short delays don’t collapse to a zero-time yield under coarse FreeRTOS tick configurations (notably ESP-IDF defaults), while keeping M5.delay() unchanged as the sketch-facing API.
Changes:
- Replaced internal
M5.delay(…)calls used for hardware timing withm5gfx::delay(…)inM5Unified.cpp. - Switched
BQ27220_Class.cppfromM5Unified.htoM5GFX.hafter removing its last dependency on the globalM5object.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/utility/power/BQ27220_Class.cpp | Uses m5gfx::delay() for BQ27220 timing waits and narrows includes to M5GFX.h. |
| src/M5Unified.cpp | Uses m5gfx::delay() for I2C retry backoff and ES8388 soft-ramp transition wait to guarantee minimum delay time. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Problem
M5.delay()is a plainvTaskDelay(msec / portTICK_PERIOD_MS), so ittruncates to the tick period and can only undershoot. With the ESP-IDF
default tick rate of 100 Hz (10 ms tick),
M5.delay(1)throughM5.delay(9)perform no delay at all — just a yield. The Arduino core's1000 Hz tick hides this, but ESP-IDF builds use the shorter waits as
written:
M5Unified.cpp) becomes a busy retry loop,M5Unified.cpp) waits for nothing,m5gfx::delay()waits coarsely withvTaskDelayand completes shortremainders with a microsecond busy-wait, so it guarantees at least the
requested time regardless of the tick configuration.
Fix
Internal waits that exist for hardware timing reasons now use
m5gfx::delay(), matching whatPower_Class.cppalready does everywhere.M5.delay()itself is unchanged and remains the sketch-facing convenienceAPI.
BQ27220_Class.cppreferenced the globalM5object only for thesedelays, so its include narrows from
M5Unified.htoM5GFX.h.