Custom functions in micropython #1791
-
I have followed the ''CONTRIBUTING.md" from pybricks-micropython and was able to build the firmware with new vars include in the 'pb_type_primehub.c'. I added vars like 'test' with the value of "Hello World" and it could be access through "PrimeHub().test". But now I want to take it to a practical level (the whole reason I am trying to build "my own" firmware is, because I need a algorithem to run way faster than "python" can, so I wanted to code it in C). So right now I have a problem with adding a custom function to the Prime Hub File. If anyone could help me with it, I would be very grateful since I have been working on this for 1.5 days : ) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Can you share the function you need to optimize? Maybe there is a way to still do it in Python and meet the timing requirements. Also, there are some other options to use native code without compiling your own firmware. For example https://docs.micropython.org/en/latest/develop/natmod.html is supported on SPIKE Prime. But if you still want to learn how to modify the firmware, I would suggest starting with adding a function to the tools module (e.g. see https://github.com/pybricks/pybricks-micropython/blob/master/pybricks/tools/pb_module_tools.c |
Beta Was this translation helpful? Give feedback.
Since it is a search algorithem (A*) on f...ing huge graph there isn't any other way but to code it in C, but the approach with the "pb_module_tools.c" really help, and I have a simple function that just adds to numbers. This is the code I have added to the "pb_module_tools.c" if anyone would need it in the future:
This code at line 347
And this code into the "tools_globals_table[]" Array (the array is now at 360):
{ MP_ROM_QSTR