Usage I2C or SPI in a native module? #16411
Replies: 1 comment
-
The MicroPython build exposes a set of symbols that native modules can use. I think it is defined in py/nativeglue.h/.c. There might be some generic ways to call into Python code exposed in that table, which could potentially be used in sneaky ways. Like mp_load_global, mp_import_name etc. You could also include from the native platform modules everything that is needed for I2C/SPI communication. This will be a complete separate usage from what MicroPython does, so one can easily create conflicts that way, but also possible. A fourth way would be to pass an MicroPython object representing the I2C/SPI (or a custom class which wraps such I/O communication) one into C. Then you should be able to call methods on that object from the native C module. I feel this is conceptually the cleanest approach. I am not sure if anyone else has done this before however, so be aware that this is likely quite uncharted territory. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to use the communication methods I2C or SPI from inside a native module? In an external C module it is possible to include i2c or spi and use it, but will this also work for native modules? (I am just looking for a way to avoid rebuilding the full micropython build when experimenting with c modules)
Beta Was this translation helpful? Give feedback.
All reactions