Skip to content

Use m5gfx::delay for internal hardware waits - #327

Merged
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:delay_unify
Aug 18, 2026
Merged

Use m5gfx::delay for internal hardware waits#327
lovyan03 merged 1 commit into
m5stack:developfrom
ainyan03:delay_unify

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Problem

M5.delay() is a plain vTaskDelay(msec / portTICK_PERIOD_MS), so it
truncates to the tick period and can only undershoot. With the ESP-IDF
default tick rate of 100 Hz (10 ms tick), M5.delay(1) through
M5.delay(9) perform no delay at all — just a yield. The Arduino core's
1000 Hz tick hides this, but ESP-IDF builds use the shorter waits as
written:

  • the I2C init retry backoff (M5Unified.cpp) becomes a busy retry loop,
  • the ES8388 soft-ramp transition wait (M5Unified.cpp) waits for nothing,
  • the BQ27220 sub-command wait of 10 ms can shrink to zero.

m5gfx::delay() waits coarsely with vTaskDelay and completes short
remainders 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 what Power_Class.cpp already does everywhere.
M5.delay() itself is unchanged and remains the sketch-facing convenience
API.

BQ27220_Class.cpp referenced the global M5 object only for these
delays, so its include narrows from M5Unified.h to M5GFX.h.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 with m5gfx::delay(…) in M5Unified.cpp.
  • Switched BQ27220_Class.cpp from M5Unified.h to M5GFX.h after removing its last dependency on the global M5 object.

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.

@lovyan03
lovyan03 merged commit b92c642 into m5stack:develop Aug 18, 2026
27 checks passed
@ainyan03
ainyan03 deleted the delay_unify branch August 18, 2026 04:38
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.

3 participants