-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Feature suggestion: Micropython binding #557
Comments
Hi, I also see a big potential in it. Both reaching a larger audience and the benefits of Micropython sounds very well. Earlier I made some experiments with Lua binding but Micropython is more mainstream right now. So this feature would be very welcome! |
@kisvegabor |
@turoksama There will definitely be overhead from using Python due to the need to convert objects back and forth. I guess the hope is that Python will be used on platforms which can afford the additional overhead. |
Here is what I had in mind. import lvgl
label1 = lvgl.label(lvgl.get_scr_act())
label1.set_text("Hello world!")
label1.align(None, lvgl.ALIGN_CENTER, 0, 0) Creating micropython extensions requires lots of boilerplate. I don't think we should write them manually. Writing them manually would be not only tedious to start with, but also hard to maintain when objects are changed and added. |
@amirgon Sound good to me! I also vote for the automated way. |
@kisvegabor Calling a Micropython function from C code is covered by Micropython. One thing we'll need to figure out is how to separate display/board specific code from generic lvgl code. |
@amirgon The only problem with your suggestion is that the performance overhead of handling the low-level display code through Python might be too high. What do you think? |
@embeddedt It's true that Micropython is slower than C, and costs more resources (RAM, Flash).
|
@amirgon I agree, calling |
@kisvegabor I agree, |
@amirgon |
@kisvegabor I've created a Micropython module and one object manually, and ran it on my HW setup. I didn't start working on the automatic generation of Micropython extensions yet, but I'm looking into doing this using pycparser. |
@amirgon |
Just found this. (btw, progress update, pycparser is great and I'm making some progress with it, creating some micropython lvgl extension functions automatically, but there's still a lot of work to be done) |
Looks amazing! My old dream to make an interactive online GUI demo tool but didn't find the right way to do this. I'm looking forward to try Micropython! |
@kisvegabor Have you considered Emscripten? It converts C to JavaScript and might be faster than using Unicorn and MicroPython for a demo. |
@embeddedt |
@kisvegabor I can experiment with Emscripten if you'd like but it may take a while to get stuff working. I probably won't get to it before next week. |
@embeddedt if you do have time to experiment with Emscripten, please try to build Micropython as part of lvgl sources. |
@embeddedt Some test would be welcome in this field. I never used Emscripten before the mentioned test so probably you will get better results than me :) |
Not ready for a PR yet, but I have a working script. Here is a working example I just run on my device:
A nice thing about Mpy REPL is the automatic completion (start typing and press For example:
Next things to implement:
If you want to see the code, have a look at:
I'll be happy to receive comments. |
@amirgon I didn't use Micropython so far but I'd like to try it with my STM32F429 Discovery. I fond this: https://github.com/micropython/micropython/wiki/Board-STM32F429 |
@kisvegabor I didn't check how much flash it requires, however,
I'm not familiar with STM32F429, my board is ESP32. But I don't see why it would matter, Micropython is the same.
You can find more information here, let me know how it goes! |
@amirgon Thank you! I hope I can ry it on the weekend |
@amirgon
I suppose I need to add the source files of |
@kisvegabor Yes you need to add lvgl sources to the Makefile.
You don't have to explicitly specify all files, you can use wildcards to include C files from specific lvgl directories. |
@kisvegabor Please make sure you take the latest version when you try it out.
but
|
@amirgon Thank you very much! I will try it on Sunday! |
@kisvegabor I have a problem with callbacks (
|
It is the first case in LittlevGL when we can't agree on something. Obviously, as the leader of this project, I have a big responsibility in solving questions when the parties don't agree on something. I should know when to say no and when to leave things to be added even if I don't agree. In addition, a friendly atmosphere should be created. However, similarly to most of us, I'm a developer with only a few experiences in leadership. I still need to learn a lot and surely will make wrong decisions too. And unfortunately, it means that sometimes something needs to be rewritten or reverted. I truly feel sorry if I make extra work for somebody who pays his free time to develop LittlevGL.
The new evidence was that we couldn't find a good way to add the colors and the related macros without source code parsing. In light of that, it seemed to me, the source code parsing need to introduced for colors. And once we have source code parsing it should be easy to add it for the symbols too which are quite similar. I really want to merge your updates (with numstr) to lvgl and release it in v5.3. As we proceed in v6.0 we will see what is working and what isn't. |
When this is integrated into 5.3, I'd be happy to merge my code for 6.0, and also implement the separation of front-end / back-end for both Python and Micropython, as discussed earlier! I think integrating my work before 5.3 would be too tight, I'd also like to put some effort into a more elaborate test case that we can run on both Python and Micropython |
@kisvegabor Ok. See this PR. I had to disable the following on
@rreilink Good. Are you going to add support for generic structs? This would be required in order to have the same syntax on Python and Micropython.
That would be great! Currently I have very few simple examples. A more complex example would be very helpful. |
Yes, it should be fixed on lvgl sources. I've checked
Perfect, thank you! |
@kisvegabor To get the list of missing function definitions all you need to do is enable the relevant |
I'll check it. But please send an example of how to run |
@kisvegabor Please have a look at /*
* Auto-Generated file, DO NOT EDIT!
*
* Command line:
* ../../lib/lvgl/micropython/gen_mpy.py -X anim -X group -X task -I../../lib/berkeley-db-1.xx/PORT/include -I../../lib/lvgl -I. -I../.. -Ibuild -I../../lib/mp-readline -I ../../lib/lvgl/micropython/pycparser/utils/fake_libc_include ../../lib/lvgl/lvgl.h
* You can also find this in the makefile in $(BUILD)/micropython/lv_mpy.c: $(ALL_LVGL_SRC)
$(ECHO) "LVGL-GEN $@"
$(Q)mkdir -p $(BUILD)/micropython
$(Q)$(PYTHON) $(TOP)/$(LVGL_DIR)/micropython/gen_mpy.py -X anim -X group -X task $(INC) -I $(TOP)/$(LVGL_DIR)/micropython/pycparser/utils/fake_libc_include $(TOP)/$(LVGL_DIR)/lvgl.h > $@ |
@amirgon
|
This has become a long thread! Thanks to everyone for putting in the effort, particularly @amirgon, @rreilink and @kisvegabor. The MicroPython community really needs a decent UI library. LittlevGL is certainly an excellent option and I'm going to watch the integration carefully and help out where I can. I help run the Melbourne MicroPython Meetup so I'll be sure to feature LittlevGL integration at the next meetup... I was more bullish about a library with the bulk of the code in (Micro)Python and a smaller core (primitives, font rendering, drivers) in C. I still think, longer-term, that this would be a more elegant solution. But the progress you guys have made is starting to convince me that wrapping up LittlevGL might be a more pragmatic approach... In any case, I just wanted to say keep up the good work, this will be of real interest to a lot of MicroPython developers and I'll start to get more across the implementation you've been working on. Thanks again! |
@mattytrentini It's very good to hear that you are interested in the integration of LittlevGL! Soon we will have a stable project to test Micropython and LittlevGL with the Unix port. We will keep you updated! |
Related: micropython/micropython#4195.
@andrewleech It's great to hear you are interested in LittlevGL and Micropython Bindings! If you would like to try it, you can fork lv_micropython. There is a Micropython script example to get you started, it displays some controls, uses styles, callbacks, etc. I would love to hear some feedback on lvgl Micropython bindings! I'm still going to make some changes in the way the lvgl is registered with Micropython (lvgl/lv_binding_micropython#5) and I'm also planning to add an ESP32 support, as an example of adding LittlevGL to a Micropython port (currently only the unix port is working). |
Progress update: |
That's quite exciting, I look forward to trying this out! I have an M5Stack which seems to be an ideal test device (ESP32+ILI9341). The main concern I have with this approach - bindings to a C library - is that the API is likely to reflect the C API too closely. ie not feel very pythonic. The advantage, of course, is to be able to build on top of the large existing codebase... I guess we'll have to see how it progresses! In any case thanks again for your efforts and I'll try it out as soon as I have some time. |
@mattytrentini That's great! I'd love to hear some user feedback.
Don't be fooled by the fact that it's written in C. class SymbolButton(lv.btn):
def __init__(self, parent, symbol, text):
super().__init__(parent)
self.symbol = lv.label(self)
self.symbol.set_text(symbol)
self.symbol.set_style(symbolstyle)
self.symbol.align(self, lv.ALIGN.CENTER,0,0)
self.label = lv.label(self)
self.label.set_text(text)
self.label.align(self, lv.ALIGN.CENTER,20,0) In this example (originally taken from here, thanks @rreilink!) we create a reusable composite component that inherits from a native LittlevGL For more examples please have a look at the Micropython demo script. So, I would like to hear more about your concern. I believe there are many advantages in starting from LittlevGL instead of building something totally new in pure MicroPython:
|
Micropython is now an official LittlevGL feature! I would like to thank @kisvegabor and @embeddedt for their support in this effort. It is a pleasure to work with you! I would also like to thank @rreilink for his comments, his work on the Python binding and his advanced_demo.py example script which I use with minor changes as my primary example script. Here is a blog post about Micropython + LittlevGL. Closing the issue. |
Thank you very much for adding this awesome feature and the ideas and suggestions to make LittlevGL better! Having Micropython support really makes a difference! I'm sure that there is a big potential in it! 👏 👏 👏 |
There's a blogpost on Hackaday. |
@manison |
@kisvegabor perfect marketing 👍 |
Actually, my friend suggested it so it's his merit. :) |
Micropython is becoming mainstream on IOT and embedded development in general. It is available for quite a few of embedded architectures (this and this, partial list), and can be ported to new ones.
Today there already exist several architecture-specific micropython display modules (for example this and this), but none of them as feature rich and general as littlevgl.
I think it could be useful to provide micropython API to littlevgl Objects and Styles.
Main benefits are:
If it turns out there is an agreement about this feature, I might try sending PR if I find the time for it.
The text was updated successfully, but these errors were encountered: