summaryrefslogtreecommitdiff
path: root/docs/develop/cmodules.rst
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-05-31 22:56:11 +1000
committerDamien George <damien@micropython.org>2022-06-02 16:31:37 +1000
commitefe23aca7154d21a9e8f283313c7a1ac29e05d86 (patch)
tree385afed48501b70d94ac3869901ad6fd809201f8 /docs/develop/cmodules.rst
parent47f634300c5572571816817f16836113c98814ae (diff)
all: Remove third argument to MP_REGISTER_MODULE.
It's no longer needed because this macro is now processed after preprocessing the source code via cpp (in the qstr extraction stage), which means unused MP_REGISTER_MODULE's are filtered out by the preprocessor. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'docs/develop/cmodules.rst')
-rw-r--r--docs/develop/cmodules.rst12
1 files changed, 7 insertions, 5 deletions
diff --git a/docs/develop/cmodules.rst b/docs/develop/cmodules.rst
index 38225e868..143057f7f 100644
--- a/docs/develop/cmodules.rst
+++ b/docs/develop/cmodules.rst
@@ -221,23 +221,25 @@ as described above.
If a module is not enabled by default then the corresponding C preprocessor macro
must be enabled. This macro name can be found by searching for the ``MP_REGISTER_MODULE``
line in the module's source code (it usually appears at the end of the main source file).
-The third argument to ``MP_REGISTER_MODULE`` is the macro name, and this must be set
-to 1 using ``CFLAGS_EXTRA`` to make the module available. If the third argument is just
-the number 1 then the module is enabled by default.
+This macro should be surrounded by a ``#if X`` / ``#endif`` pair, and the configuration
+option ``X`` must be set to 1 using ``CFLAGS_EXTRA`` to make the module available. If
+there is no ``#if X`` / ``#endif`` pair then the module is enabled by default.
For example, the ``examples/usercmodule/cexample`` module is enabled by default so
has the following line in its source code:
.. code-block:: c
- MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, 1);
+ MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule);
Alternatively, to make this module disabled by default but selectable through
a preprocessor configuration option, it would be:
.. code-block:: c
- MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, MODULE_CEXAMPLE_ENABLED);
+ #if MODULE_CEXAMPLE_ENABLED
+ MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule);
+ #endif
In this case the module is enabled by adding ``CFLAGS_EXTRA=-DMODULE_CEXAMPLE_ENABLED=1``
to the ``make`` command, or editing ``mpconfigport.h`` or ``mpconfigboard.h`` to add