Skip to content

Commit 810ea38

Browse files
committed
Updates to build configuration for WASM port
1 parent 65fc3d6 commit 810ea38

6 files changed

Lines changed: 131 additions & 5 deletions

File tree

ports/wasm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ FROZEN_MANIFEST ?= variants/manifest.py
3535
QSTR_DEFS = qstrdefsport.h
3636
QSTR_GLOBAL_DEPENDENCIES += $(VARIANT_DIR)/mpconfigvariant.h
3737

38+
include $(TOP)/py/circuitpy_mpconfig.mk
3839
include $(TOP)/py/circuitpy_defns.mk
3940

4041
# include py core make definitions

ports/wasm/mpconfigport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111

112112
// CIRCUITPY-CHANGE: CircuitPython-specific settings
113113
#define CIRCUITPY_MICROPYTHON_ADVANCED (1)
114-
#define MICROPY_PY_ASYNC_AWAIT (1)
114+
// MICROPY_PY_ASYNC_AWAIT and CIRCUITPY_STATUS_BAR are set in mpconfigport.mk
115115
#define MICROPY_PY_UCTYPES (0)
116116
#define MICROPY_PY_MICROPYTHON_RINGIO (0) // Not supported in WASM
117117

ports/wasm/mpconfigport.mk

Lines changed: 115 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@
2222

2323
# CIRCUITPY-CHANGE: CircuitPython global marker
2424
CFLAGS += -DCIRCUITPY=1
25-
25+
CIRCUITPY_FULL_BUILD = 0
2626
# Enable VFS POSIX for Emscripten filesystem
2727
MICROPY_VFS = 1
28-
28+
LONGINT_IMPL = MPZ
2929
# This variable can take the following values:
3030
# 0 - no readline, just simple stdin input
3131
# 1 - use MicroPython version of readline
@@ -76,6 +76,13 @@ MICROPY_VFS_LFS2 = 0
7676

7777
CIRCUITPY_MESSAGE_COMPRESSION_LEVEL = 1
7878
MICROPY_EMIT_NATIVE = 0
79+
CIRCUITPY_USB_DEVICE = 0
80+
81+
# Enable async/await even though FULL_BUILD=0
82+
MICROPY_PY_ASYNC_AWAIT = 1
83+
84+
# WASM has no physical LEDs
85+
CIRCUITPY_STATUS_BAR = 0
7986

8087
# Enable modules that we have implemented or that work without hardware
8188
CIRCUITPY_BOARD = 1
@@ -89,7 +96,7 @@ CIRCUITPY_MICROCONTROLLER = 1
8996
CIRCUITPY_NEOPIXEL_WRITE = 1
9097
CIRCUITPY_PWMIO = 1
9198
CIRCUITPY_ROTARYIO = 1
92-
CIRCUITPY_ROTARYIO_SOFTENCODER = 1
99+
# CIRCUITPY_ROTARYIO_SOFTENCODER = 1
93100
CIRCUITPY_TIME = 1
94101

95102
# Enable ulab for scientific computing (pure software module)
@@ -106,3 +113,108 @@ CIRCUITPY_JSON = 1
106113
CIRCUITPY_OS_GETENV = 1
107114
CIRCUITPY_RE = 1
108115
CIRCUITPY_ZLIB = 0
116+
117+
# ==============================================================================
118+
# EXPLICITLY DISABLE MODULES
119+
# ==============================================================================
120+
# Since CIRCUITPY_FULL_BUILD=0, many modules are already disabled by default,
121+
# but we explicitly disable modules that might be enabled by dependencies or
122+
# that require external libraries/hardware we don't support.
123+
124+
# Note: MICROPY_PY_ASYNC_AWAIT is set by circuitpy_mpconfig.mk based on CIRCUITPY_FULL_BUILD
125+
# We enable it in mpconfigport.h instead to avoid redefinition
126+
127+
# Audio modules (require external libraries like mp3 decoder, or hardware)
128+
CIRCUITPY_AUDIOBUSIO = 0
129+
CIRCUITPY_AUDIOCORE = 0
130+
CIRCUITPY_AUDIOIO = 0
131+
CIRCUITPY_AUDIOMP3 = 0
132+
CIRCUITPY_AUDIOPWMIO = 0
133+
CIRCUITPY_AUDIOMIXER = 0
134+
CIRCUITPY_AUDIODELAYS = 0
135+
CIRCUITPY_AUDIOFILTERS = 0
136+
CIRCUITPY_AUDIOFREEVERB = 0
137+
138+
# Display modules (need hardware or complex implementations)
139+
CIRCUITPY_DISPLAYIO = 0
140+
CIRCUITPY_BITMAPTOOLS = 0
141+
CIRCUITPY_BITMAPFILTER = 0
142+
CIRCUITPY_FRAMEBUFFERIO = 0
143+
CIRCUITPY_PARALLELDISPLAYBUS = 0
144+
CIRCUITPY_EPAPERDISPLAY = 0
145+
CIRCUITPY_FOURWIRE = 0
146+
CIRCUITPY_I2CDISPLAYBUS = 0
147+
148+
# Bluetooth (needs hardware)
149+
CIRCUITPY_BLEIO = 0
150+
CIRCUITPY_BLEIO_HCI = 0
151+
CIRCUITPY_BLEIO_NATIVE = 0
152+
CIRCUITPY_BLE_FILE_SERVICE = 0
153+
154+
# Hardware-specific modules not implemented
155+
CIRCUITPY_ALARM = 0
156+
CIRCUITPY_ANALOGBUFIO = 0
157+
CIRCUITPY_BITBANGIO = 0
158+
CIRCUITPY_BITOPS = 0
159+
CIRCUITPY_CAMERA = 0
160+
CIRCUITPY_CANIO = 0
161+
CIRCUITPY_COUNTIO = 0
162+
CIRCUITPY_DUALBANK = 0
163+
CIRCUITPY_ESPIDF = 0
164+
CIRCUITPY_ESPULP = 0
165+
CIRCUITPY_FREQUENCYIO = 0
166+
CIRCUITPY_GNSS = 0
167+
CIRCUITPY_I2CTARGET = 0
168+
CIRCUITPY_IMAGECAPTURE = 0
169+
CIRCUITPY_KEYPAD = 0
170+
CIRCUITPY_MDNS = 0
171+
CIRCUITPY_MEMORYMAP = 0
172+
CIRCUITPY_NEOPIXEL = 0
173+
CIRCUITPY_NVM = 0
174+
CIRCUITPY_ONEWIREIO = 0
175+
CIRCUITPY_OS = 0
176+
CIRCUITPY_PS2IO = 0
177+
CIRCUITPY_PULSEIO = 0
178+
CIRCUITPY_RGBMATRIX = 0
179+
CIRCUITPY_RTC = 0
180+
CIRCUITPY_SDCARDIO = 0
181+
CIRCUITPY_SDIOIO = 0
182+
CIRCUITPY_SOCKETPOOL = 0
183+
CIRCUITPY_SSL = 0
184+
CIRCUITPY_STORAGE = 0
185+
CIRCUITPY_SUPERVISOR = 0
186+
CIRCUITPY_SYNTHIO = 0
187+
CIRCUITPY_TOUCHIO = 0
188+
CIRCUITPY_USB_CDC = 0
189+
CIRCUITPY_USB_HID = 0
190+
CIRCUITPY_USB_MIDI = 0
191+
CIRCUITPY_USB_MSC = 0
192+
CIRCUITPY_USB_VIDEO = 0
193+
CIRCUITPY_VIDEOCORE = 0
194+
CIRCUITPY_WATCHDOG = 0
195+
CIRCUITPY_WIFI = 0
196+
197+
# Software modules not yet needed/tested
198+
CIRCUITPY_AESIO = 0
199+
CIRCUITPY_ATEXIT = 0
200+
CIRCUITPY_CODEOP = 0
201+
CIRCUITPY_GETPASS = 0
202+
CIRCUITPY_GIFIO = 0
203+
CIRCUITPY_HASHLIB = 0
204+
CIRCUITPY_LOCALE = 0
205+
CIRCUITPY_MAX3421E = 0
206+
CIRCUITPY_MSGPACK = 0
207+
CIRCUITPY_PIXELBUF = 0
208+
CIRCUITPY_QRIO = 0
209+
CIRCUITPY_TRACEBACK = 0
210+
CIRCUITPY_USERCMODULE = 0
211+
212+
# Additional software modules to consider enabling later
213+
CIRCUITPY_ARRAY = 1
214+
CIRCUITPY_COLLECTIONS = 1
215+
CIRCUITPY_IO = 1
216+
CIRCUITPY_MATH = 1
217+
CIRCUITPY_RANDOM = 1
218+
CIRCUITPY_STRUCT = 0 # Has upstream pointer type bug (mp_uint_t* vs size_t*)
219+
CIRCUITPY_SYS = 1
220+
CIRCUITPY_WARNINGS = 1

ports/wasm/mphalport.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ extern int mp_interrupt_char;
8181
int mp_hal_get_interrupt_char(void) {
8282
return mp_interrupt_char;
8383
}
84+
85+
// CircuitPython os.urandom support (required by random module)
86+
bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) {
87+
// TODO: Implement using JavaScript's crypto.getRandomValues()
88+
// For now, return zeros to indicate no real randomness available
89+
for (uint32_t i = 0; i < length; i++) {
90+
buffer[i] = 0;
91+
}
92+
return false; // Return false to indicate we didn't get real random data
93+
}

ports/wasm/variants/standard/mpconfigvariant.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@
4444
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES)
4545

4646
// WASM has no physical status LEDs, disable status bar features
47-
#define CIRCUITPY_STATUS_BAR 0
47+
// NOTE: CIRCUITPY_STATUS_BAR is now set in mpconfigport.h to avoid redefinition
48+
// #define CIRCUITPY_STATUS_BAR 0
4849

shared-bindings/busio/I2C.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ static void check_for_deinit(busio_i2c_obj_t *self) {
106106
// Provided by context manager helper.
107107

108108
static void check_lock(busio_i2c_obj_t *self) {
109+
#ifndef __EMSCRIPTEN__
109110
asm ("");
111+
#endif
110112
if (!common_hal_busio_i2c_has_lock(self)) {
111113
mp_raise_RuntimeError(MP_ERROR_TEXT("Function requires lock"));
112114
}

0 commit comments

Comments
 (0)