Replies: 21 comments
-
Hi, there is a similar request for the LVGL in the stubber repo , so lets try to do this. Im currently working on generating much richer MicroPython stubs from the documentation, and that seems to be nearly done. if you can point me to firmware or instructions to build a MPY + LVGL for a M5Stack Basic or M5 Fire then I'll have a look on what can be done . |
Beta Was this translation helpful? Give feedback.
-
Great. I'm not familiar with that hardware, but looks like it's ESP32-based and has a (likely?) supported display. If you want to build your own, the build directions are pretty straightforward., especially if you've built MP yourself before. It's just slow. I built my own to add more fonts in (by default only 2 are included). If you just want to give it a quick try, the 16MB firmware from this link should get your started. I do wonder if gen_mpy (linked above) could be modified to easily produce only stubs instead of the full modules (which call into the LVGL C code functions). Happy to try out your richer stubs if it helps. |
Beta Was this translation helpful? Give feedback.
-
I have uploaded my basic lv_micropython build to this repo: |
Beta Was this translation helpful? Give feedback.
-
I echo the benefits of SPIRAM, but one of the cool things about LVGL is it lets you allocate a single buffer of say 1/10th the screen area, and it uses that buffer behind the scenes to batch graphics updates to the display. E.g. an entire image never needs to be in RAM. So even with 90k free you're able to do interesting things. Still, extra RAM is always nice, especially for canvas drawing. |
Beta Was this translation helpful? Give feedback.
-
I managed to get the firmware flashed , but am not able to get anything on the display yet ( probably not having the correct initialization in place just resets the MCU) I was able to :
|
Beta Was this translation helpful? Give feedback.
-
@Josverl I have been able to run the stubber against my firmware and, just like you say, it's extremely big. One thing I noticed is that not all of the information is stubbed, for example, this is part of the btn class:
As you can see, the class' properties and functions are there, but not the functions' parameters: In the end, the list of modules that lvgl adds to the micropython project is: Now, so far I have a hodgepodge of paths for Intellisense to read since it seems that having the unfrozen module is better than a stub and therefore the following modules are available in either the lv_micropython or the bindings repos: That leaves: ['lodepng','lvgl', 'rtch'] As the only modules really stubbed from the firmware. I haven't had the time to check if it's possible to compile the bindings and obtain those modules in an unfrozen/more complete state or if the lack of additional information is a function of being cross-compiled. Currently, I have this order of priorities for the modules: |
Beta Was this translation helpful? Give feedback.
-
It should come up to the MP prompt without any resetting. I had resetting on boot when my custom build overflowed the default "app" partition size, and I had to edit Once stable, you can import your driver (ili9XXX?) and import LVGL and try out some of the examples. Here's my display startup: from ili9XXX import st7789
import lvgl as lv
import fs_driver
disp = None
def start():
global disp
if not disp:
disp = st7789(width=135, height=240, double_buffer = False,
factor=8, rot=st7789.LANDSCAPE)
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')
lv.init() (I'm using a pre-release st7789 build). Note the "factor" which is the factor by which to reduce the size of the display buffer. The fs_driver stuff is so you can specify images or fonts by file path (with a leading |
Beta Was this translation helpful? Give feedback.
-
According to this:
I've tried lvgl's advanced demo application (https://github.com/lvgl/lv_binding_micropython/blob/master/examples/advanced_demo.py) on my non-M5 ESP32 and it works (still working on fully calibrating the TS though) |
Beta Was this translation helpful? Give feedback.
-
Roberto
|
Beta Was this translation helpful? Give feedback.
-
WRT to getting the display to work , but that is does not display anything either :-( |
Beta Was this translation helpful? Give feedback.
-
Gents, I needed to fix more than a few things to deal with the lvgl native modules
Note that this (unfortunately) does not include the parameter info for the functions / methods , as that information is not included in the firmware. |
Beta Was this translation helpful? Give feedback.
-
Finally had a chance to test these... brilliant! Seem to be working well. I'll let you know if I run into any issues. |
Beta Was this translation helpful? Give feedback.
-
thanks for letting me know. |
Beta Was this translation helpful? Give feedback.
-
OK I discovered something quite interesting: lv_micropython includes a json file with all the calling information, structure members, etc. In my build I found it in Seems like an easy target to translate and give type information to parameters, with some type translation (e.g. enum_type -> int, etc.). This could be done either by fully parsing this file, or by adding in parameter information from this file to your generated .pyi's. Here's an example from the json:
vs:
Merging these would end up with something like:
Here are the types mentioned (and their frequency), leaving out those ending
|
Beta Was this translation helpful? Give feedback.
-
Comparing the json with your stubs also reveals a small problem: everything listed under "functions" in the json incorrectly gets a "self" parameter in your stubs. E.g. |
Beta Was this translation helpful? Give feedback.
-
Interesting , something to look into
wrt to 2, im close to releasing similar functionality for micropython by generating stubs directly from the documentation. I also have PoC code to 'merge/enrich' function / method parameters between different files using libCST |
Beta Was this translation helpful? Give feedback.
-
It's quite easy to fix the non-methods using the json file, since they are nested in the structure under a top level category "functions" (vs. "objects" for all the class/method info, and "enums" for the static constants like ALIGN.TOP_LEFT, etc.). Also they have no "type": "lv_obj_t*" argument, so no self parameter.
That sounds great. Are you basing on the PyBoardTypeshedGenerator? I believe it also scans the docs. In my brief testing the stubs it produces are truly excellent (but with some typing hard-coding to make various corrections per module). But PyBoard-specific thus far.
Yes this sounds good. I doubt you could pull enough info from lvgl docs... this file is structured perfectly to look up a method/class/etc. and enrich parameters. Take a look! Thanks for your work on this. |
Beta Was this translation helpful? Give feedback.
-
Is def black If so , that appears to be a regression in the updates I made so that needs to get fixed. |
Beta Was this translation helpful? Give feedback.
-
The top-level functions in |
Beta Was this translation helpful? Give feedback.
-
The other advantage of the json is it has all the typing info as well. |
Beta Was this translation helpful? Give feedback.
-
that json file cannot be used in it's current form. to create a correct stub file with type hints and documentation. I have tried and it is not correct/missing a lot of things like what classes are a subclass of lv_obj_t. How the naming is done remains a complete mystery to me because you have functions like There is no standard to the behavior when the micropython code is generated and I have looked at the gen_mpy script for hours on end and have not been able to sort out what in the heck it is doing. I can tell the script was written by a C developer that is unfamiliar with Python and object orientated languages. I have thought about tearing the script down and making it more "Pythonic". Lots of time needs to be invested to do that. |
Beta Was this translation helpful? Give feedback.
-
LVGL (a mini graphics library) has really usable bindings for micropython, and compiles pretty easily. They seem to be focussing more and more on MP. I'm using it with MP on a tiny TTGO-TDISPLAY and it works amazingly well for drawing and building interfaces. Really simple and clean and powerful. But man do you spend time flipping back and forth to the docs.
The auto-generated LVGL bindings in MicroPython have an incredibly broad set of attributes (e.g.
lv.textarea.*
has ~400 entries!). Their gen_mpy script does all the heavy lifting to create the module. I wonder how easy it would be to perform your stub-making on the LVGL bindings generated bygen_mpy
, to add them to your collection? That would make building LVGL apps in MP almost trivial! Thanks for micropython-stubs!Beta Was this translation helpful? Give feedback.
All reactions