Skip to content

Board detection: host tests against the production sources, StampP4 fixed_board, and a soft I2C bus fix that identifies StampS3Bat - #363

Merged
lovyan03 merged 4 commits into
m5stack:developfrom
ainyan03:board_detect_host_tests
Oct 17, 2026
Merged

lovyan03 merged 4 commits into
m5stack:developfrom
ainyan03:board_detect_host_tests

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Commits

  1. Run the board detection tests that board specification CI left out — node --test test/ resolved the test directory through test/package.json's main and only ran board_spec.test.js. The ten detection test files (48 tests) never ran in CI. The workflow now runs npm test.
  2. Test board detection on the host against the production sources — the detection tests sliced function bodies out of the C++ sources by string search and compiled them against reduced stand-in types. test/board_detect/ (C++11, no Node) now includes the production headers and .inl files unchanged and replaces only the hardware (GPIO, I2C, SPI, delays, eFuse, the dedicated GPIO probe, the Atom touch peripheral). A new BoardDetect workflow runs it.
    To make the sources includeable, the detection integration moves out of M5GFX.cpp and board_detect.inl is split into units. These are moves only: with logging disabled, the allocated sections of the objects are identical (ESP32 / ESP32-S3 / ESP32-P4 with Arduino, ESP32-S3 with ESP-IDF 5.5). Log lines from the moved code show the new file names.
    Four checks that need the public M5GFX class, the display construction settings and the M5Unified checks stay in the catalog tests for now (test/board_detect/README.md).
  3. Allow fixed_board to select StampP4 — StampP4 was missing from the ESP32-P4 board table, so fixed_board = board_M5StampP4 failed with "not supported by this chip". Automatic detection is unchanged.
  4. soft_i2c: issue nine STOP conditions when a port is initialized — the detector reads the PM1 on G47/G48 in both orientations (StickS3: SDA 47 / SCL 48, StampS3Bat: SDA 48 / SCL 47). The swapped read left the StampS3Bat PM1 NACKing with SDA released, so StampS3Bat was never identified and fell back to StampS3Mini after five 200 ms attempts. init now issues nine STOP conditions on fixed 5 us steps, without waiting for the lines. The same change goes to LovyanGFX (the file is shared).

Testing

  • sh test/board_detect/run.sh (22 programs), npm test / npm run check in extras/board_spec
  • Builds for the ESP32 family on the Arduino and ESP-IDF versions used in CI, and native (SDL)
  • 41 boards, detection result and display configuration compared with the previous develop build: only StampS3Bat changes (StampS3Mini → StampS3Bat, M5.begin 2173 ms → 135 ms); the others are unchanged and M5.begin time moves by −4 to +3 ms
  • Fork CI passed

The workflow ran `node --test test/`, which resolved the test directory
through test/package.json's main entry and only ran board_spec.test.js.
The ten detection test files (48 tests) never ran in CI. Run `npm test`,
which expands test/*.test.js, and drop the misleading package.json.
Changes to src/M5GFX.cpp and src/M5GFX.h now also trigger the workflow,
since the remaining tests read them.
The detection tests in extras/board_spec/test sliced function bodies out
of the C++ sources by string search and compiled them against reduced
stand-in types, so any refactor broke them and a stand-in could hide a
real difference (the P4 test assumed a signature that the production
detector does not have).

test/board_detect/ (run.sh, C++11, no Node) now includes the production
headers and .inl files unchanged: descriptors, detectors, transactions,
startup, prepare and the detection integration. Only the hardware is
replaced (GPIO, I2C, SPI, delays, eFuse, the dedicated GPIO probe and the
Atom touch peripheral). Descriptor and registry contents are kept as
fixtures, and a new BoardDetect workflow runs the suite.

To make the sources includeable, the detection integration moves from
M5GFX.cpp into board_detect/detection_integration.inl and
detection_package.inl, and board_detect.inl is split into units. These
are moves only: with logging disabled, the allocated sections of the
objects are identical for ESP32, ESP32-S3 and ESP32-P4 (Arduino) and
ESP32-S3 (ESP-IDF 5.5). Log lines from the moved code now show the new
file names. The hardware include and the Atom touch include can be
replaced only when M5GFX_BOARD_DETECT_HOST_HAL /
M5GFX_BOARD_DETECT_HOST_TOUCH are defined; otherwise they resolve as
before.

Four checks that need the public M5GFX class, the display construction
settings and the M5Unified checks stay in the catalog tests for now (see
test/board_detect/README.md).
StampP4 has no detector, so it was missing from the ESP32-P4 board table
and fixed_board = board_M5StampP4 failed with "not supported by this
chip". Register it as a displayless board, as the other Stamp modules
are. Automatic detection is unchanged.
A device can be left mid transfer by traffic not addressed to it. On
ESP32-S3 boards the detector reads the PM1 PMIC on G47/G48 in both
orientations, because StickS3 (SDA 47, SCL 48) and StampS3Bat (SDA 48,
SCL 47) wire it the other way round. The swapped read leaves the
StampS3Bat PM1 NACKing with SDA released: it was never identified and
fell back to StampS3Mini after five 200 ms attempts. Release alone does
not show this state, and the existing recovery only runs while SDA is
held low.

init now issues nine STOP conditions as a best effort; each also gives
a clock, the count of the standard bus clear. The steps are a fixed 5 us
each (the standard-mode tLOW, tSU;STO and tBUF minimums) and do not wait
for the lines, so a pin that is not an I2C bus cannot stretch the init;
a device stretching the clock is not followed there, and beginTransaction
still checks the bus. The sequence is skipped for a pin number the
platform cannot drive (on ESP32 an out of range number would select
another pin's output latch). A version that waited for the lines added
7.7 ms per init on the DinMeter button pin probed as a Paper bus.

Measured on 41 boards against the previous build: only StampS3Bat
changes (StampS3Mini -> StampS3Bat, begin 2173 ms -> 135 ms), board and
display configuration of the others are unchanged and begin time moves
by -4 to +3 ms.
@lovyan03
lovyan03 merged commit 9c32c64 into m5stack:develop Oct 17, 2026
27 checks passed
@ainyan03
ainyan03 deleted the board_detect_host_tests branch October 17, 2026 03:39
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.

2 participants