This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the UIFlow MicroPython firmware repository for M5Stack devices. It's a custom MicroPython port built on ESP-IDF v5.4.2, providing hardware abstraction and device drivers for the M5Stack ecosystem of ESP32-based controllers, modules, units, and accessories.
mkdir uiflow_workspace && cd uiflow_workspace
git clone --depth 1 --branch v5.4.2 https://github.com/espressif/esp-idf.git
git -C esp-idf submodule update --init --recursive
./esp-idf/install.sh
. ./esp-idf/export.shAll build commands are run from the m5stack/ directory:
cd m5stack
make submodules # Initialize git submodules
make patch # Apply patches to dependencies
make littlefs # Build littlefs filesystem tools
make mpy-cross # Build MicroPython cross-compiler
make flash_all # Build and flash firmware (default: M5STACK_AtomS3)Specify a board with BOARD=<board_name>:
make BOARD=M5STACK_CoreS3 pack_all
make BOARD=M5STACK_Cardputer flash_allBoard definitions are in m5stack/boards/. Each board has:
board.json- Hardware configurationmpconfigboard.h- MicroPython configmpconfigboard.cmake- CMake configsdkconfig.board- ESP-IDF configmanifest.py- Python module manifestfiles/system/- Board-specific assets
make clean- Clean build artifactsmake erase- Erase flashmake monitor- Open serial monitormake pack_all- Build firmware packagemake unpatch- Remove patches from dependencies
-
m5stack/ - Main firmware port
- boards/ - Board-specific configurations (40+ M5Stack devices)
- components/ - ESP-IDF components
- M5Unified/ - Core hardware abstraction (C++ bindings to MicroPython)
- cmodules/ - C/C++ MicroPython modules
- m5unified/ - M5Unified integration
- m5camera/ - Camera support
- m5audio2/ - Audio processing
- omv/ - OpenMV machine vision
- lv_binding_micropython/ - LVGL GUI bindings
- libs/ - Python libraries
- base/ - Base modules (displays, motors, etc.)
- unit/ - Unit accessories
- hat/ - HAT accessories
- chain/ - Chain accessories
- hardware/ - Hardware APIs (IMU, touch, etc.)
- driver/ - Device drivers
- modules/ - Core Python modules (boot, startup)
- patches/ - Patches for dependencies
-
docs/ - Sphinx documentation (reStructuredText)
-
examples/ - Example code organized by category
-
tools/ - Build and development tools
-
micropython/ - Upstream MicroPython (submodule)
-
esp-adf/ - ESP Audio Development Framework (submodule)
-
third-party/ - External dependencies
The firmware uses a manifest-based module system. Each board's manifest.py includes:
- Startup scripts from
m5stack/modules/startup/ - Libraries from
m5stack/libs/(base, unit, hat, chain, etc.) - Board-specific Python packages
Python modules in m5stack/libs/ are frozen into firmware at build time.
The M5Unified component (m5stack/components/M5Unified/) provides the core hardware abstraction:
mpy_m5unified.cpp- Main M5 modulempy_m5gfx.cpp- Display/graphicsmpy_m5btn.cpp- Buttonsmpy_m5imu.cpp- IMU/accelerometermpy_m5spk.cpp- Speakermpy_m5mic.cpp- Microphonempy_m5power.cpp- Power managementmpy_m5touch.cpp- Touch screenmpy_m5led.cpp- RGB LEDmpy_m5als.cpp- Ambient light sensor
Format code before committing:
tools/codeformat.py -v -c -fThis runs:
uncrustifyfor C/C++ codeblackfor Python coderufffor Python linting
Run tests from the tests/ directory (test infrastructure is minimal).
Documentation is built with Sphinx from docs/source/:
cd docs
make htmlDocumentation follows a strict structure (see .github/prompts/docs.prompt.md):
- Title and description
- UiFlow2 examples (visual block programming)
- MicroPython examples
- API reference (using Sphinx autodoc)
Use the git-commit agent (.github/agents/git-commit.agent.md) for standardized commits:
- Format:
<prefix>: <Capitalized description>. - Prefix based on changed directory (boards, libs/unit, docs, etc.)
- Max 72 characters
- Always include
-sflag (Signed-off-by)
For changes in m5stack/, omit the "m5stack/" prefix:
- ✓
boards: Add Core2 config. - ✗
m5stack/boards: Add Core2 config.
- The working directory for builds is
m5stack/, not the repository root - ESP-IDF v5.4.2 is required (specified in workflows and README)
- Patches in
m5stack/patches/are critical - apply withmake patchbefore building - The default board is M5STACK_AtomS3 if BOARD is not specified
- Documentation uses reStructuredText with specific formatting requirements
- All Python code in
m5stack/libs/is frozen into firmware (not loaded from filesystem)
- uiflow2-coder - UIFlow2 MicroPython coding with official API lookup
- uiflow2-reviewer - Review code against M5Stack source for API correctness
- m5stack-assistant - M5Stack product queries, specs, and technical support