Skip to content
Snippets Groups Projects
Commit c98b1e2c authored by schneider's avatar schneider
Browse files

Update pycardium_modules.md

parent ae5b6864
No related branches found
No related tags found
No related merge requests found
Pipeline #1247 passed
...@@ -7,7 +7,7 @@ Pycardium is our micropython port. You can find it [here](https://git.card10.ba ...@@ -7,7 +7,7 @@ Pycardium is our micropython port. You can find it [here](https://git.card10.ba
This page gives an overview on adding new modules to pycardium. There are two kinds of modules: This page gives an overview on adding new modules to pycardium. There are two kinds of modules:
#### Modules written in Python #### Modules written in Python
Python modules are written in ... python. They live in [`pycardium/modules/py`](https://git.card10.badge.events.ccc.de/card10/firmware/tree/master/pycardium/modules/py) and are pre-compiled and packed into pycardium at build-time. Python modules are meant to be used for creating abstractions and helpers based on lower level functionality. The rationale is that it is easier to write pythonic modules in python instead of having to wrap all that in C code. Though care has to be taken as these modules get quite big. Python modules are written in ... Python. They live in [`pycardium/modules/py`](https://git.card10.badge.events.ccc.de/card10/firmware/tree/master/pycardium/modules/py) and are pre-compiled and packed into pycardium at build-time. Python modules are meant to be used for creating abstractions and helpers based on lower level functionality. The rationale is that it is easier to write pythonic modules in Python instead of having to wrap all that in C code. Though care has to be taken as these modules get quite big.
#### Modules written in C #### Modules written in C
...@@ -15,7 +15,7 @@ C modules allow MicroPython code to interface with the rest of the system or all ...@@ -15,7 +15,7 @@ C modules allow MicroPython code to interface with the rest of the system or all
## Table Of Contents ## Table Of Contents
- [Python Modules](#python-modules) - [Python Modules](#python-modules)
- [Adding a new python module](#adding-a-new-python-module) - [Adding a new Python module](#adding-a-new-python-module)
- [Size Considerations](#size-considerations) - [Size Considerations](#size-considerations)
- [C Modules](#c-modules) - [C Modules](#c-modules)
- [Basic Structure](#basic-structure) - [Basic Structure](#basic-structure)
...@@ -28,8 +28,8 @@ C modules allow MicroPython code to interface with the rest of the system or all ...@@ -28,8 +28,8 @@ C modules allow MicroPython code to interface with the rest of the system or all
## Python Modules ## Python Modules
### Adding a new python module ### Adding a new Python module
Add a file with the name of the module you want to [`pycardium/modules/py`](https://git.card10.badge.events.ccc.de/card10/firmware/tree/master/pycardium/modules/py). Make the build-system aware of the new python module by adding it in [`pycardium/modules/py/meson.build`](https://git.card10.badge.events.ccc.de/card10/firmware/blob/master/pycardium/modules/py/meson.build). Rebuild and you should have your module available in MicroPython! You can list the available modules in MicroPython using the following command: Add a file with the name of the module you want to [`pycardium/modules/py`](https://git.card10.badge.events.ccc.de/card10/firmware/tree/master/pycardium/modules/py). Make the build-system aware of the new Python module by adding it in [`pycardium/modules/py/meson.build`](https://git.card10.badge.events.ccc.de/card10/firmware/blob/master/pycardium/modules/py/meson.build). Rebuild and you should have your module available in MicroPython! You can list the available modules in MicroPython using the following command:
```python ```python
help("modules") help("modules")
...@@ -125,9 +125,9 @@ static mp_obj_t mp_example_hello(mp_obj_t number) ...@@ -125,9 +125,9 @@ static mp_obj_t mp_example_hello(mp_obj_t number)
``` ```
## QSTR ## QSTR
QSTRs are so called "interned strings". This means they are not allocated like normal python objects but instead live in flash and are indexed. This allow MicroPython to very efficiently use them as identifiers. According to them, comparing two QSTR is as fast as comparing integers. QSTRs are so called "interned strings". This means they are not allocated like normal Python objects but instead live in flash and are indexed. This allow MicroPython to very efficiently use them as identifiers. According to them, comparing two QSTR is as fast as comparing integers.
Unfortunately, the way these QSTRs are collected from the source files is quite weird. MicroPython comes with a few python scripts (namely [`makeqstrdefs.py`](https://github.com/micropython/micropython/blob/master/py/makeqstrdefs.py) and [`makeqstrdata.py`](https://github.com/micropython/micropython/blob/master/py/makeqstrdata.py)) that parse the C source files and search for uses of `MP_QSTR_*`. These are then sorted and indexed into a header file called `qstrdefs.collected.h`. This is closely tied in with their Makefiles. Unfortunately, the way these QSTRs are collected from the source files is quite weird. MicroPython comes with a few Python scripts (namely [`makeqstrdefs.py`](https://github.com/micropython/micropython/blob/master/py/makeqstrdefs.py) and [`makeqstrdata.py`](https://github.com/micropython/micropython/blob/master/py/makeqstrdata.py)) that parse the C source files and search for uses of `MP_QSTR_*`. These are then sorted and indexed into a header file called `qstrdefs.collected.h`. This is closely tied in with their Makefiles.
As we use our own build system, we had to somehow wrap this generation to work for us as well. This is done using a few scripts in [`lib/micropython`](https://git.card10.badge.events.ccc.de/card10/firmware/tree/master/lib/micropython). As we use our own build system, we had to somehow wrap this generation to work for us as well. This is done using a few scripts in [`lib/micropython`](https://git.card10.badge.events.ccc.de/card10/firmware/tree/master/lib/micropython).
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment