Mapping between Micropython and C

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
graemef
Posts: 5
Joined: Fri Jun 23, 2017 3:12 pm

Mapping between Micropython and C

Post by graemef » Fri Jun 23, 2017 3:24 pm

Hi,

I would like to understand how the following maps to C drivers.

As an example: i2c.scan()

I understand the driver level code and found the I2C driver including the scan commands in the drivers. What I don't understand is how calling the python code maps to the C code. Followed this http://wiki.micropython.org/Creating-Pyb-Modules but not sure if it is outdated as the qstrdefsport.h file doesn't match up to what the autor was saying.

I guess what I am asking is how would I implement i2c.xyz() assuming that the low level drivers exist.

Thanks. Graeme

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Mapping between Micropython and C

Post by dhylands » Fri Jun 23, 2017 11:23 pm

You probably want to read this thread:
viewtopic.php?f=16&t=2861&p=19206

You can find the mapping here:
https://github.com/micropython/micropyt ... 2c.c#L1018

The scan is an entry in the locals dict, which is included in the pyb_i2c_type, which is in turn referenced from either the pyb module:
https://github.com/micropython/micropyt ... pyb.c#L188
(there is also machine.i2c and you didn't specify which one you were using).

To add an xyz function, you'd add an entry to the same table that has the scan function in it, and then implement the function.

Post Reply