lvgl / lv_binding_micropython

LVGL binding for MicroPython
MIT License
237 stars 156 forks source link

Port new SDL driver into Micropython Bindings #215

Closed amirgon closed 2 years ago

amirgon commented 2 years ago

Port SDL driver from lv_drivers into Micropython bindings instead of the existing (old) SDL driver.
This also adds keyboard support and supersedes https://github.com/lvgl/lv_binding_micropython/pull/211 (which seems to be abandoned?)

To run this - need to fix the Makefile on lv_micropython (this will be done after merging this PR):

diff --git a/ports/unix/Makefile b/ports/unix/Makefile
index a2dbf5af3..b0968bf5f 100644
--- a/ports/unix/Makefile
+++ b/ports/unix/Makefile
@@ -256,8 +256,8 @@ SRC_C += \
        $(wildcard $(VARIANT_DIR)/*.c)

 LIB_SRC_C += $(addprefix lib/,\
-    lv_bindings/driver/SDL/SDL_monitor.c \
-    lv_bindings/driver/SDL/SDL_mouse.c \
+    lv_bindings/driver/SDL/sdl_common.c \
+    lv_bindings/driver/SDL/sdl.c \
        lv_bindings/driver/SDL/modSDL.c \
        $(LIB_SRC_C_EXTRA) \
        )

@embeddedt - I would appreciate your comments!

embeddedt commented 2 years ago

Since I'm basing this on latest SDL LVGL driver, does it by any chance fix https://github.com/lvgl/lv_binding_micropython/issues/97?

I've just tested, and unfortunately, it does not. It must be some issue very specific to the threading environment/GC behavior of Micropython? I don't believe Nvidia open-sourced the OpenGL part of their driver stack, which is where the crash happens, so that won't be much help either.

Would keyboard work on the web simulator? How much effort is required to support this?

This should work out of the box or require very minimal changes. Emscripten supports using the keyboard with SDL so it just needs to be initialized.

amirgon commented 2 years ago

@embeddedt After merging this and updating lv_micropython, do we expect the simulator to update automatically? so far, it seems that the new SDL is not available on the simulator:

>>> import SDL
>>> hasattr(SDL, 'keyboard_read')
False
embeddedt commented 2 years ago

@amirgon Thanks for letting me know, this is fixed now. https://github.com/lvgl/lv_micropython/commit/60e0d6953aa6c2002a32ccabaa0cdc71a52945cb

There was no build failure notification due to a GitHub limitation when merging branches.

amirgon commented 2 years ago

this is fixed now. lvgl/lv_micropython@60e0d69

Great! I really missed that js also has its own makefile.
But I still don't see this on the simulator... Which job is supposed to actually deploy it?

embeddedt commented 2 years ago

Can you try clearing your browser cache? I see it here: https://sim.lvgl.io/v8.3/micropython/ports/javascript/index.html

image

amirgon commented 2 years ago

I see it here: https://sim.lvgl.io/v8.3/micropython/ports/javascript/index.html

Aha!
https://sim.lvgl.io/ only lists versions up to 8.1...
Perhaps we can have only "latest" v8 version? I don't believe anyone would want to use v8.2 when v8.3 is available. (but might still want to use v7 or v6)

amirgon commented 2 years ago

Also.... I don't think keyboard work on the JS simulator.
It simply doesn't focus on the LVGL GUI, only on the editor/console.

embeddedt commented 2 years ago

@amirgon I'll look into this but it won't be for another week at least.

embeddedt commented 2 years ago

The core of the issue turned out to be very simple, unfortunately it took me about two hours to find these lines. :laughing: I've tested locally and I can type into an LVGL textarea now. The fix should be deployed within 20 minutes or so.

amirgon commented 2 years ago

@embeddedt it works great!! Could you also update the https://sim.lvgl.io/ page? It has links to v8.0 and v8.1 but not to latest version. I think it's enough to have links to latest version of each major version instead. What do you think?

embeddedt commented 2 years ago

Sorry, I forgot to address your previous message. Updated.

amirgon commented 2 years ago

Thanks @embeddedt, it's perfect!