Skip to content

Commit cec9a69

Browse files
committed
samd51: Make errno, os, and time module aliases
Add alias for uerrno so the user doesn't have to know about the CircuitPython special names for the module. Make os and time weak modules (aliases) making it possible to add functionality to those modules written in python. Example: 'import os' will now look in the path for an os module and if not found it will import the builtin module. An os module written in python will import the builtin module through its name prefixed with an underscore (_os) following the C module naming practice in CPython. Also right align the macro values to increase readability making it easier to compare the values for samd21 and samd51. Even the longest macro from py/mpconfig.h will fit with this alignment.
1 parent db4a8f5 commit cec9a69

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

ports/atmel-samd/mpconfigport.h

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
#define MICROPY_VFS (1)
8585
#define MICROPY_VFS_FAT (1)
8686
#define MICROPY_PY_MACHINE (1)
87-
#define MICROPY_MODULE_WEAK_LINKS (0)
8887
#define MICROPY_REPL_AUTO_INDENT (1)
8988
#define MICROPY_HW_ENABLE_DAC (1)
9089
#define MICROPY_ENABLE_FINALISER (1)
@@ -140,15 +139,17 @@ typedef long mp_off_t;
140139
#include "include/sam.h"
141140

142141
#ifdef SAMD21
143-
#define CIRCUITPY_MCU_FAMILY samd21
142+
#define CIRCUITPY_MCU_FAMILY samd21
144143
#define MICROPY_PY_SYS_PLATFORM "Atmel SAMD21"
145-
#define PORT_HEAP_SIZE (16384 + 4096)
144+
#define PORT_HEAP_SIZE (16384 + 4096)
145+
#define MICROPY_MODULE_WEAK_LINKS (0)
146146
#endif
147147

148148
#ifdef SAMD51
149-
#define CIRCUITPY_MCU_FAMILY samd51
149+
#define CIRCUITPY_MCU_FAMILY samd51
150150
#define MICROPY_PY_SYS_PLATFORM "MicroChip SAMD51"
151-
#define PORT_HEAP_SIZE (0x20000) // 128KiB
151+
#define PORT_HEAP_SIZE (0x20000) // 128KiB
152+
#define MICROPY_MODULE_WEAK_LINKS (1)
152153
#endif
153154

154155
#ifdef LONGINT_IMPL_NONE
@@ -290,6 +291,33 @@ extern const struct _mp_obj_module_t usb_hid_module;
290291
{ MP_OBJ_NEW_QSTR(MP_QSTR_supervisor), (mp_obj_t)&supervisor_module }, \
291292
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
292293
{ MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module },
294+
#elif MICROPY_MODULE_WEAK_LINKS
295+
#define MICROPY_PORT_BUILTIN_MODULES \
296+
{ MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, \
297+
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
298+
{ MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \
299+
{ MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
300+
{ MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module }, \
301+
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module }, \
302+
{ MP_OBJ_NEW_QSTR(MP_QSTR__os), (mp_obj_t)&os_module }, \
303+
{ MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \
304+
{ MP_OBJ_NEW_QSTR(MP_QSTR_random), (mp_obj_t)&random_module }, \
305+
{ MP_OBJ_NEW_QSTR(MP_QSTR_rtc), (mp_obj_t)&rtc_module }, \
306+
{ MP_OBJ_NEW_QSTR(MP_QSTR_samd),(mp_obj_t)&samd_module }, \
307+
{ MP_OBJ_NEW_QSTR(MP_QSTR_storage), (mp_obj_t)&storage_module }, \
308+
{ MP_OBJ_NEW_QSTR(MP_QSTR_struct), (mp_obj_t)&struct_module }, \
309+
{ MP_OBJ_NEW_QSTR(MP_QSTR_supervisor), (mp_obj_t)&supervisor_module }, \
310+
{ MP_OBJ_NEW_QSTR(MP_QSTR_math), (mp_obj_t)&math_module }, \
311+
{ MP_OBJ_NEW_QSTR(MP_QSTR__time), (mp_obj_t)&time_module }, \
312+
{ MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid),(mp_obj_t)&usb_hid_module }, \
313+
TOUCHIO_MODULE \
314+
EXTRA_BUILTIN_MODULES
315+
316+
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
317+
{ MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_uerrno) }, \
318+
{ MP_ROM_QSTR(MP_QSTR_os), MP_ROM_PTR(&os_module) }, \
319+
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
320+
293321
#else
294322
#define MICROPY_PORT_BUILTIN_MODULES \
295323
{ MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, \

0 commit comments

Comments
 (0)