Skip to content

Commit f76e4c7

Browse files
authored
Merge pull request #8849 from jepler/document-register-module
document how to use MP_REGISTER_MODULE
2 parents b704452 + 1e7d368 commit f76e4c7

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

docs/common_hal.md

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,9 @@ SRC_QSTR += $(SRC_C) $(SRC_BINDINGS_EXPANDED) $(STM_SRC_C)
5252
The `Makefile` defines the modules to build and adds the sources to include the `shared-bindings` version and the `common-hal` version within the port specific directory. You may comment out certain subfolders to reduce the number of modules to add but don't comment out individual classes. It won't compile then.
5353

5454
### Hooking the modules in
55-
Built in modules are typically defined in `mpconfigport.h`. To add support you should have something like:
56-
57-
```
58-
extern const struct _mp_obj_module_t microcontroller_module;
59-
extern const struct _mp_obj_module_t analogio_module;
60-
extern const struct _mp_obj_module_t digitalio_module;
61-
extern const struct _mp_obj_module_t pulseio_module;
62-
extern const struct _mp_obj_module_t busio_module;
63-
extern const struct _mp_obj_module_t board_module;
64-
extern const struct _mp_obj_module_t time_module;
65-
extern const struct _mp_obj_module_t neopixel_write_module;
66-
67-
#define MICROPY_PORT_BUILTIN_MODULES \
68-
{ MP_OBJ_NEW_QSTR(MP_QSTR_microcontroller), (mp_obj_t)&microcontroller_module }, \
69-
{ MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module }, \
70-
{ MP_OBJ_NEW_QSTR(MP_QSTR_digitalio), (mp_obj_t)&digitalio_module }, \
71-
{ MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, \
72-
{ MP_OBJ_NEW_QSTR(MP_QSTR_busio), (mp_obj_t)&busio_module }, \
73-
{ MP_OBJ_NEW_QSTR(MP_QSTR_board), (mp_obj_t)&board_module }, \
74-
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
75-
{ MP_OBJ_NEW_QSTR(MP_QSTR_neopixel_write),(mp_obj_t)&neopixel_write_module } \
55+
Modules are registered by the macro `MP_REGISTER_MODULE` from `py/obj.h`. The macro takes two arguments: the module name as a QSTR and the module object itself. The `board` module is registered like so:
56+
```py
57+
MP_REGISTER_MODULE(MP_QSTR_board, board_module);
7658
```
7759

7860
### Implementing the Common HAL

0 commit comments

Comments
 (0)