Skip to content

Follow the IOExpander_Base API of M5Unified 0.2.21 - #8

Merged
lovyan03 merged 1 commit into
m5stack:mainfrom
ainyan03:ioexpander_m5unified_0_2_21
Aug 28, 2026
Merged

Follow the IOExpander_Base API of M5Unified 0.2.21#8
lovyan03 merged 1 commit into
m5stack:mainfrom
ainyan03:ioexpander_m5unified_0_2_21

Conversation

@ainyan03

Copy link
Copy Markdown
Contributor

Problem

M5Unified 0.2.21 changed the IOExpander_Base interface that PY32IOExpander_Class derives from: the mutating methods now return the write status as bool, setPullMode() takes a gpio_pull_t (pull_none / pull_up / pull_down) instead of a bool, and enablePull() was removed from the base class. StackChan-BSP 1.1.0 still declares the old signatures with override, so it no longer compiles against 0.2.21 (m5stack/M5Unified#346):

PY32IOExpander.hpp:26:10: error: conflicting return type specified for 'virtual void m5::PY32IOExpander_Class::setDirection(uint8_t, bool)'
PY32IOExpander.hpp:28:10: error: 'void m5::PY32IOExpander_Class::enablePull(uint8_t, bool)' marked 'override', but does not override
...
error: invalid new-expression of abstract class type 'm5::PY32IOExpander_Class'

Change

  • Move the register access into version independent private helpers that return the I2C status and validate the pin (0–13, matching the register layout).
  • Select the set of override declarations from M5UNIFIED_VERSION_*, so the library builds against both M5Unified 0.2.20 (old interface) and 0.2.21 and later (new interface).
  • Keep the public API of PY32IOExpander_Class source compatible on both versions: setPullMode(pin, bool) and enablePull(pin, bool) remain callable (as plain members on 0.2.21+), and the gpio_pull_t enum is provided locally on the old interface so setPullMode(pin, PY32IOExpander_Class::pull_up) works everywhere. The internal call sites in M5StackChan.cpp use the enum.
  • Behaviour on valid pins is unchanged: setHighImpedance(true) still switches the pin to input with both pulls disabled, setPullMode(pin, true) still means pull-up.

Verification

Compiled a sketch that calls M5StackChan.begin() plus the old-style and enum-style pull/drive calls, with PlatformIO (pioarduino 55.03.34, m5stack-cores3, Arduino) against:

  • M5Unified 0.2.21 (develop) + M5GFX 0.2.28 — fails on the unmodified library with the errors above, builds with this change
  • M5Unified 0.2.20 + M5GFX 0.2.28 — builds before and after

Fixes the build error reported in m5stack/M5Unified#346.

M5Unified 0.2.21 changed the IOExpander_Base virtuals: the mutating methods
now return the write status as bool, setPullMode() takes gpio_pull_t and
enablePull() was removed. PY32IOExpander_Class still declared the old
signatures with override, so the library no longer compiled
(m5stack/M5Unified#346).

Move the register access into version independent private helpers that
return the I2C status and validate the pin, and select the override set from
M5UNIFIED_VERSION_* so the library builds against both 0.2.20 and 0.2.21.
The pull mode call sites use the gpio_pull_t enum, which is provided locally
for the old API.
@ainyan03
ainyan03 force-pushed the ioexpander_m5unified_0_2_21 branch from 96bc0bc to 342f0a1 Compare August 28, 2026 04:39
@ainyan03

Copy link
Copy Markdown
Contributor Author

CI status of this PR:

  • Formatting Check (src): one line of src/M5StackChan.cpp was not clang-formatted (comment alignment after my change). Fixed and force-pushed; the examples job was only cancelled by fail-fast, not failing on its own.
  • Lint Check: pre-existing, fails on every run of main since April (LP018: library not in the Library Manager index, LP052: includes= lists directories). Not related to this PR; fixed separately in Fix the Arduino Lint check #9.

The re-run needs a maintainer approval since the PR comes from a fork.

@lovyan03
lovyan03 merged commit 6216027 into m5stack:main Aug 28, 2026
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