mirror of
https://github.com/Architeuthis-Flux/JumperlessV5.git
synced 2025-09-03 18:27:37 +00:00
4.7 KiB
4.7 KiB
Building the Jumperless Native MicroPython Module
This guide explains how to build the Jumperless firmware with the native MicroPython module integration.
Prerequisites
- PlatformIO installed and configured
- Git (for MicroPython repository cloning)
- Build tools (make, gcc, etc.)
Build Process
1. Build MicroPython with Jumperless Module
First, build MicroPython with the native Jumperless module integrated:
# From the project root directory
./scripts/build_micropython.sh
This script will:
- Clone or update the MicroPython repository
- Build MicroPython embed port with the Jumperless module included
- Generate QSTR definitions for the Jumperless functions
- Verify the module integration
2. Build Jumperless Firmware
After MicroPython is built, compile the main firmware:
# Using PlatformIO
pio run
# Or using PlatformIO with specific environment
pio run -e pico
3. Upload to Device
# Upload firmware
pio run -t upload
# Or with specific environment
pio run -e pico -t upload
Build Verification
The build script will verify:
- QSTR Generation: Confirms MicroPython QSTR definitions are generated
- Jumperless QSTRs: Checks that Jumperless-specific function names are included
- Module Files: Verifies all required source files are present
- Configuration: Ensures the module is enabled in the configuration
Expected Output
◆ MicroPython embed build successful!
Generated 1234 QSTR definitions
Jumperless module QSTRs found: 25
◆ Jumperless MicroPython module found
◆ Jumperless API wrapper found
◆ Jumperless module enabled in configuration
◆ MicroPython is ready for use with Jumperless native module enabled!
Troubleshooting
Common Issues
-
Module Not Found
◇ Jumperless MicroPython module missing
- Check that
lib/micropython/modjumperless.cpp
exists - Verify the USER_C_MODULES path is correct
- Check that
-
API Wrapper Missing
◇ Jumperless API wrapper missing
- Check that
src/JumperlessMicroPythonAPI.cpp
exists - Verify include paths in the source file
- Check that
-
No Jumperless QSTRs
Warning: No Jumperless module QSTRs detected
- The module may not be properly registered
- Check
MODULE_JUMPERLESS_ENABLED
is defined - Verify
MP_REGISTER_MODULE
call in the module source
-
Build Errors
- Check that all include paths are correct in
platformio.ini
- Verify that required headers are available
- Ensure
MODULE_JUMPERLESS_ENABLED=1
is set in build flags
- Check that all include paths are correct in
Debug Steps
-
Check Module Registration:
grep -r "MP_QSTR_jumperless" lib/micropython/micropython_embed/
-
Verify Build Flags:
grep -A5 "build_flags" platformio.ini
-
Check Include Paths:
find . -name "modjumperless.cpp" find . -name "JumperlessMicroPythonAPI.cpp"
Runtime Testing
After successful build and upload, test the module:
# In MicroPython REPL
import jumperless
# Test basic functions
jumperless.dac_set(0, 2.5)
voltage = jumperless.adc_get(0)
print(f"ADC reading: {voltage}V")
# Test node connections
jumperless.nodes_connect(1, 5)
jumperless.nodes_disconnect(1, 5)
Or call the built-in test function from C++:
testJumperlessNativeModule();
File Structure
After building, the key files are:
lib/micropython/
├── modjumperless.cpp # Native module implementation
├── micropython.mk # Module build configuration
├── mpconfigport.h # Module enabled flag
└── micropython_embed/ # Generated MicroPython files
├── genhdr/qstrdefs.generated.h # QSTR definitions
└── ...
src/
├── JumperlessMicroPythonAPI.cpp # C++ wrapper functions
├── Python_Proper.cpp # MicroPython integration
└── Python_Proper.h # Header file
platformio.ini # Build configuration with module flags
Performance Benefits
The native module provides significant improvements over the string-based approach:
- ~10x faster execution - No string parsing overhead
- Better memory efficiency - No intermediate string buffers
- Type safety - Native Python type handling
- Error handling - Proper Python exceptions
- IDE support - Full Python syntax support
Next Steps
After successful build:
- Test all hardware functions through the native module
- Update existing Python code to use direct function calls
- Remove old string-based command parsing code
- Add additional hardware functions as needed
For usage examples, see examples/python_proper_native_demo.py
.