Repository navigation
Build as a user C module in CircuitPython too - #41
Merged
Merged
Conversation
CircuitPython's make-based ports read USER_C_MODULES exactly as MicroPython 1.29 does, so micropython.mk now builds pygraphics into CircuitPython-compatible firmware with no apply script: - micropython.mk passes -DPYGRAPHICS_USER_C_MODULE=1, so a build with CIRCUITPY=1 still registers the module (the shared-bindings path through apply_cp_patches.sh is unchanged). - The warnings the drawing code trips on purpose are repeated per object, where they land after the -Werror=sign-compare/float-equal CircuitPython's MCU ports append late. - Polygon coordinates are read with memcpy instead of a cast: a memoryview can start at any byte, and a Cortex-M0+ faults on an unaligned load (atmel-samd builds with -Werror=cast-align). - The MONO_HLSB copy a PNG save makes comes from the GC heap in a user C module build: atmel-samd has no C heap, so malloc() didn't link.
This was referenced Oct 8, 2026
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.
CircuitPython's make-based ports read
USER_C_MODULESthe way MicroPython 1.29 does, so with these changesmicropython.mkbuilds pygraphics into CircuitPython-compatible firmware withoutapply_cp_patches.sh. Proven on CircuitPython 11.0.0-alpha.1: the unixcoveragebuild (import, draw, read back,capabilities()says native), and board builds foradafruit_feather_rp2040andsparkfun_samd51_thing_plusthat link with the module in their module table.What changed:
micropython.mkpasses-DPYGRAPHICS_USER_C_MODULE=1. CircuitPython's unix port setsCIRCUITPY=1, and without the define the module skippedMP_REGISTER_MODULEand couldn't be imported. The shared-bindings path throughapply_cp_patches.shis unchanged.-Wno-*flags the drawing code needs are repeated per object. CircuitPython's MCU ports append-Werror=sign-compareand-Werror=float-equalafter the user module flags, and a target-specific flag lands last. The object path is the onepy/py.mkuses since MicroPython 1.29,$(BUILD)/<module dir name>/src/<file>.o.memcpyrather than a pointer cast. A memoryview can start at any byte, and a Cortex-M0+ (RP2040) faults on an unaligned halfword or word load; atmel-samd builds with-Werror=cast-align, which caught it.MONO_HLSBframebuffer comes from the GC heap (m_malloc). atmel-samd has no C heap, somalloc()didn't link. CPython and MicroPython's CMake ports keepmalloc/free, through the newgfx_png_release().MicroPython is unaffected: the unix build with this branch passes the same import/draw/read-back check, and the CPython extension builds without warnings and passes its native suite (93 tests, 6 skipped).