-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Frozen python code as part of machine module? #8241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There is not a direct way to do this, to combine Python and C code in the same (built in) module. But the idea with u-module naming is that the C parts can be implemented in, eg, See also #5025 for an idea of a way to implement built-in functions in Python. |
Understood, thanks for the reply. So there is currently no way to implement Counter and Encoder as documented in #8072 in Python. I wonder if it then makes sense to put highlevel stuff like Encoder and Counter that into the machine module at all. On some plattforms without dedicated hardware counter this may actually be implemented on top of Pin.irq() which in turn can nicely be done in Python and would not require any C. But anyway, then I'll happily support the somewhat bloated solution in #6639 . As said in the PR: Better that version than nothing. |
So i can achieve this by just changing micropython/ports/esp32/mpconfigport.h Line 237 in 1f04a9a
and creating
This now copes with my little Encoder class quite nicely. But what are the chances, that such a patch would be accepted upstream? Also all other uXXXX modules use the u prefix interally for C functions and such as well. Would a proper patch renaming everything inside the esp32 port to umachine? |
I think it's a good change. Some ports already have See #8244 for a patch that makes this change. |
|
Fix RGB/BGR color order for Picopad
Uh oh!
There was an error while loading. Please reload this page.
I am implementing an alternative to #6639 which only does the very basic ESP32 PCNT API in C. The Counter and Encoder classes as decribed at #8072 are pure Python and subclassed from this PCNT API.
I personally think that such an approach is nicer and cleaner than the current approach. I thus would like to provide a full implementation of my approach.
But Encoder and Counter classes as described in the aforementioned documentation are part of the machine module. And I don't know how to add Python code to that. Is that possible at all? Can I add python code to the machine module to be frozen into the firmware?
I simply tried to add machine/Encoder.py to port/esp32/modules. But that does not work. It compiles but Encoder does not how up in the machine module.
The text was updated successfully, but these errors were encountered: