Add frozen code to the machine module?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
MasterOfGizmo
Posts: 50
Joined: Sun Nov 29, 2020 8:17 pm

Add frozen code to the machine module?

Post by MasterOfGizmo » Fri Jan 28, 2022 10:31 am

There are discussions about machine.Encoder and machine.Counter classes in github. These are implemented in C. I would like to give a python variant a trial and would like to add it as a frozen class to the machine module so my versions are compatible with the ones from the existing PR's.

Is that possible at all? Can one mix python and C in the same module? If yes, how? Simply adding machine/Encoder.py to port/esp32/modules does not work.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: Add frozen code to the machine module?

Post by pidou46 » Tue Feb 01, 2022 7:12 am

Hello,

If I understand your need accordingly, I think Damien is cooking something up:

https://github.com/micropython/micropython/pull/8191
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

MasterOfGizmo
Posts: 50
Joined: Sun Nov 29, 2020 8:17 pm

Re: Add frozen code to the machine module?

Post by MasterOfGizmo » Tue Feb 01, 2022 11:57 am

pidou46 wrote:
Tue Feb 01, 2022 7:12 am
If I understand your need accordingly, I think Damien is cooking something up:
Thanks for the response. But ... no, I don't think this is what I am searching for. I don't have a problem including my code into the firmware. This already works.

I can add

Code: Select all

port/esp32/modules/mymachine/Encoder.py
This will be converted into MPY and included into the firmware. This can then be used like

Code: Select all

from mymachine import Encoder
But the documentation of the Counter and Encoder classes requires them to be part of the machine module. So I'd like to add

Code: Select all

port/esp32/modules/machine/Encoder.py
That also compiles successfully. But

Code: Select all

from machine import Encoder
won't work. Probably because I cannot simply add something to the internal machine module. The question is: How do I add python code to a built-in native module? Is this possible at all?

Post Reply