There is a lot of pyboard module which can be use by micropython. Currently I just know that these module's real implementation is done in C. My question is:
How is the relationship mapped between the Python module and C implementation?
Such as we can use import pyb
, where is the pyb Python file?
Such as we can use from pyb import LED
and call the intensity function, where is the Python LED class definition? Where is the definition of its intensity function?
Asked
Active
Viewed 210 times
0
1 Answers
1
Easiest way to find this out is clone the source code and then start looking around using whatever text/file search tool you prefer. Search for files/text 'pyb' and/or 'LED'. Then you'll find for instance modpyb.c which defines the pyb module (in C, not in Python). There you can see the module's global dictionary has an entry
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pyb_led_type) }
which is MicroPython lingo to say 'there's a thing with the name LED and it is of type pyb_led_type. The latter being the the C code for the LED class and found in led.c, including the led_obj_intensity
function.

stijn
- 34,664
- 13
- 111
- 163
-
1Hi,stijin,So thanks for your infomation. I also found a article for hacking MicroPython. https://github.com/PyConPL/Book/blob/master/2016/workshops/hacking_micropython/text.md – hustzhuch Feb 07 '18 at 06:06