Under the hoods, Python and Micropython have several significant differences.
The mechanism for adding a native C modules is very different.
The memory management is different. Python relies on reference counting while Micropython uses Garbage Collection.
So, while the front end (python syntax) is very similar, the backend is very different.
My point is - I don’t think you can “convert” the Micropython binding to Python binding without re-designing and re-writing significant parts of it.
My focus is Micropython and it aligns well with LittlevGL, both were designed to work well on resource constrained devices such as microcontrollers.
As far as I know, @rreilink’s work is the most advanced attempt to create Python binding for LittlevGL. His bakcend is different but there was a time when he and I tried to collaborate and create a unified front-end. Unfortunately, it looks like @rreilink is busy with other things and didn’t make much progress with the Python binding for many months.
There are several open questions regarding the python binding, for example, how to manage memory and how to handle access to structs and fields. While on Micropython these are implemented and are working well, I’m not sure what is the best way to implement those for Python.
Did you consider using Micropython?
The Omega2 is a powerful device, but still constrained by RAM and Flash.
You could try the unix (Linux) port of Micropython on the Omega2, it could probably be an interesting project with a lot of potential!
Oh, and one last thing I forgot to mention, if you are worried about Micropython API to other modules with C API (other than LittlevGL) - you can also use the micropython bindings to interact with any other C library! (under certain assumptions).
Thanks for the detailed response! I’ve tried out the linux micropython port on the Omega2, it looks like it’s stable and very usable. Especially with the micropython-lib package that adds a whole suite of standard libraries.
Based on the work you’ve done, how much additional work would be involved in creating a standalone micropython littlev module? Would you be interested in working on this with the Onion team?
Btw, we have hardware prototypes ready for testing. We can send you a beta unit if you’re interested.
Yes… but take into account that many of these libraries have limited functionality and some of them are even just placeholders to prevent an error when you try to import them (but not when you try to use them).
It doesn’t get close to the “real” Python standard library.
Don’t expect a random python script which has some standard Python imports to “just run” on Micropython.
If I understand correctly, you already successfully ran both lvgl and micropython on Omega2. Is that correct?
If that’s the case, it should be pretty simple to create a micropython littlevgl module.
Did you try building lv_micropython? (try branch dev-6.1, that’s the closest to micropython’s upstream)
Did you have any problem building/running lv_micropython?
How “open” are your hardware and software? What license do you use?
When I contribute on my own free time, I limit myself to open projects such as lvgl (which has “MIT” license)
If your long term policy is all-embracing open hardware and software - I’ll be happy to help and collaborate!
That’s right, we’ve been able to run C lvgl and micropython on the Omega2.
From my understanding it looks like lv_micropython builds a full micropython runtime that has an lvgl module built-in.
Our preference would be to stick with the already available micropython package for OpenWRT and load lvgl as an external module. That’s where we could use your help since we’re new to micropython.
The intention of this project is to provide a reference design for display applications with the Omega2. So the schematics and layout of the hardware will be open source, as will any work done with drivers and application software.
Generally, we use GPLv3 but are open to other licenses.
I don’t think you could load lvgl binding as an external module without rebuilding micropython.
I had to do some small but important changes in micropython itself.
For example, lvgl uses micropython’s Garbage Collector for memory management, so I had to add lvgl gc-root pointers to micropython (see MICROPY_PORT_ROOT_POINTERS).
External modules don’t support Micropython gc.
Another example is a change I tried to push to micropython but unfortunately didn’t succeed yet, so I had to do it on my micropython fork.
btw, in micropython External C Modules feature don’t mean you can load the module on runtime like you load a shared library. What it means is that you can add your C files at some location and build micropython without manually writing the Makefile. So you would have to build your OpenWRT micropython project anyway if you want to add anything.
Remember that micropython was primarily designed for embedded platforms where you usually don’t load code dynamically, like you do in Linux.
What you can do, is build a fork of your OpenWRT micropython package with lvgl binding included.
What about other projects? What about the entire Onion policy?
I took a look at your website and couldn’t find any information about hardware/software licensing, or about what is supposed to be open and what is not.
I found, however, a few troubling posts on the forum.
I think that what’s missing is clarity.
What is the company’s policy and intentions regarding licensing? What parts are GPL? What parts are MIT? What parts are proprietary?
Thanks for the advice, I forked lv_micropython and lv_binding_micropython, made some adjustments, and compiled it for the Omega2.
Displaying lvgl objects works great, but I haven’t been able to get touch input detection to work at all. I press on a button and the style doesn’t change nor does the registered callback fire.
A few points worth mentioning:
Confirmed that the correct x and y coordinates were being read using a print statement
Confirmed that the mp_lv_task_handler function runs on an interval
We know the touch hardware and software work
We had previously tested lvgl in C and wrote a driver for the XPT7603 touch input device used on the Omega2 Dash (see file demo/littlev-demo/lv_drivers/indev/XPT2046.c in that repo)
It just seems like there’s some disconnect between the input and the displayed components.
Do you have any advice for where to look or what to investigate? It would be much appreciated.
Agreed, we need to be more clear about our licensing. This is something we’re slowly working towards.
Which touch driver do you use? How did you register it?
I have an example of a pure micropython XPT2046 touch driver that works well for me, you can use it as a reference if you want.
Try to put some printing in the your read callback in your driver implementation. It’s supposed to be called periodically by lvgl. Is it called? What values does it set for data.point and data.state?
I added a C driver for the xpt7603 device to our fork of lv_binding_micropython. See the driver file here, it’s based it on the existing driver/esp32/modxpt2046.c in the same repo, just modified to work with the I2C based XPT7603.
I had tested the xpt7603 code with a C lvgl program and it worked as expected.
For registering, I followed the available examples and register the touch driver in the micropython program:
That is strange.
You are saying that your driver’s read callback is called by lvgl, updates data with valid coordinates and state - but still, nothing happens on the GUI.
Whatever problem it is, I don’t think it’s related directly to Micropython. Perhaps @kisvegabor or @embeddedt would have an idea what that could be.
Maybe it’s not the touch, but the display driver? Or the combination of both?
Did you connect both the display and the touch driver to the same SPI bus? This is possible, (for example, my pure micropython ILI9341 driver can work with pure micropython XPT2046 on the same SPI bus), but if I remember correctly, the original C code of the XPT and ILI drivers was not designed to work on the same bus on the ESP32.
Maybe lvgl changes the display after the touch, but the display driver is stuck or malfunctions and cannot show the change?
It’s very easy to check - just put some animation and see if it keeps moving while you are touching the screen.
Any idea why this could be happening even though I’ve confirmed the lv_task_handler function is being run periodically?
Is there something that could be making the xpt7603_read callback blocking?
Should the xpt7603_read callback always return false, like @embeddedt suggested?
Yes it can be related to @embeddedt comment.
When read returns “true” it means that there is more data to be sent, false means no more data, so in general you almost always want to return false from read.
I’m 99% sure you should always return false from that function. Otherwise, LittlevGL will freeze (as you can see from the first and last lines of this code snippet).
Good news: it resolved the blocking issue I was seeing before. I can touch the screen and animations will still do their thing:
Bad news: touch input still isn’t properly propagating to the rest of lvgl.
My test script has a button with a callback attached and the callback never gets called no matter what I do.