Skip to content

zephyr-cp: enable keypad, keypad_demux, touchio, atexit, codeop, locale - #11649

Open
dhalbert wants to merge 1 commit into
adafruit:mainfrom
dhalbert:zephyr-cp-default-modules
Open

dhalbert wants to merge 1 commit into
adafruit:mainfrom
dhalbert:zephyr-cp-default-modules

Conversation

@dhalbert

@dhalbert dhalbert commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Code, tests and hardware testing by Claude, with review by @dhalbert. This note by @dhalbert.

  • Turn on these shared-module modules on zephyr-cp:
    • atexit
    • codeop
    • keypad
    • keypad_demux
    • locale
    • touchio
  • Added the six modules to DEFAULT_MODULES in ports/zephyr-cp/cptools/build_circuitpython.py.
  • Sorted that list alphabetically.
  • I needed to set these flags in EXTRA_FLAGS to turn on all the keypad features:
    • CIRCUITPY_KEYPAD_KEYS=1
    • CIRCUITPY_KEYPAD_KEYMATRIX=1
    • CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS=1
  • I set CIRCUITPY_TOUCHIO_USE_NATIVE=0, so touchio will use the generic shared-module implementation, which needs an external 1 MΩ pull-down (as on CPB).
  • Added native_sim tests:
    • test_keypad.py drives keypad.Keys with GPIO input traces, for both active-low and active-high keys.
    • test_touchio.py checks the untouched threshold, a touch simulated by holding the pin high, and the ValueErrors raised when the pull resistor is missing.

I didn't test KeyMatrix on native_sim, because gpio_emul can't make an input pin follow an output pin. Fixing this requires changes to our fork of Zephyr, and will be done later.

Testing

On hardware, with zephyr-cp builds of this branch:

  • Adafruit MacroPad RP2040, using a temporary local zephyr-cp board definition (not part of this PR): keypad.Keys on all 12 keys and the encoder switch, plus rotaryio. Results matched the rp2 port, including the encoder direction.
  • Adafruit Feather nRF52840: touchio with a 1 MΩ pull-down on A5; a rotary encoder with rotaryio; and its switch read both as a 1×1 keypad.KeyMatrix and as keypad.Keys.

Not in this PR

The touchio test on the Feather also turned up what appears to be a serious off-by-one bug in gc_realloc() in py/gc.c, which can crash any port. The Feather keypad and rotaryio tests ran on a build that included the fix. I'll have a separate PR for the bug after further testing.

Turn on the remaining port-neutral shared modules that other ports
enable by default. Set the keypad and touchio sub-flags in EXTRA_FLAGS,
since zephyr-cp does not use py/circuitpy_mpconfig.mk defaults.
Alphabetize DEFAULT_MODULES.

Add native_sim tests for keypad.Keys and touchio.TouchIn using GPIO
input traces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant