Skip to content
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

使新mpy支持携带lv_binding编译,升级lvgl9 #11

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions m5stack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(SDKCONFIG_DEFAULTS ${CMAKE_BINARY_DIR}/sdkconfig.combined)
if(BUILD_WITH_LVGL)
# Include LVGL component, ignore KCONFIG
idf_build_set_property(LV_MICROPYTHON 1)
include_directories(${CMAKE_SOURCE_DIR}/components/lv_bindings)
idf_build_component(${CMAKE_SOURCE_DIR}/components/lv_bindings/lvgl)
idf_build_set_property(COMPILE_DEFINITIONS "-DLV_KCONFIG_IGNORE" APPEND)
separate_arguments(LV_CFLAGS_ENV UNIX_COMMAND $ENV{LV_CFLAGS})
Expand Down
10 changes: 8 additions & 2 deletions m5stack/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,22 @@ define pack_fw
$(BUILD)/uiflow-Sx-$(GIT_VERSION).uf2
endef

.PHONY: all build deploy flash flash_all clean erase nvs fs pack pack_all littlefs mpy-cross submodules FORCE
.PHONY: all fix_lv_bindings build deploy flash flash_all clean erase nvs fs pack pack_all littlefs mpy-cross submodules FORCE

all: nvs fs pack
@echo ""
@echo "Done, default packed firmware don't include vfs filesystem, if need vfs filesystem, please use 'make pack_all' command."

$(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE

# Change lv_bindings
# fix lv_bindings path bug as lv_micropython sub project
fix_lv_bindings:
sed -i 's|lib/lv_bindings/include/|include/|g' components/lv_bindings/lv_conf.h
sed -i 's|MP_OBJ_TO_PTR(self_in);|(mp_ptr_t*)(MP_OBJ_TO_PTR(self_in));|g' components/lv_bindings/driver/include/common.h

# Build the MicroPython firmware.
build: nvs
build: nvs fix_lv_bindings
idf.py $(IDFPY_FLAGS) build

# Deploy the MicroPython.
Expand Down
2 changes: 1 addition & 1 deletion m5stack/cmodules/m5unified/m5unified.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#if MICROPY_PY_LVGL
#include "lvgl/lvgl.h"
#include "lvgl/src/hal/lv_hal_disp.h"
#include "lvgl/src/hal/lv_hal.h"
#include "./../../components/lv_bindings/driver/include/common.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion m5stack/cmodules/m5unified/m5unified_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern mp_obj_t user_panel_make_new(const mp_obj_type_t *type, size_t n_args, si
#if MICROPY_PY_LVGL
extern void gfx_lvgl_flush(void *_disp_drv, const lv_area_t *area, lv_color_t *color_p);
extern void user_lvgl_flush(void *_disp_drv, const lv_area_t *area, lv_color_t *color_p);
extern bool gfx_lvgl_touch_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data);
extern bool gfx_lvgl_touch_read(lv_indev_t *indev_drv, lv_indev_data_t *data);
DEFINE_PTR_OBJ(gfx_lvgl_flush);
DEFINE_PTR_OBJ(user_lvgl_flush);
DEFINE_PTR_OBJ(gfx_lvgl_touch_read);
Expand Down
14 changes: 7 additions & 7 deletions m5stack/components/M5Unified/mpy_lvgl.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if MICROPY_PY_LVGL
#include "lvgl/lvgl.h"
#include "lvgl/src/hal/lv_hal_disp.h"
#include "lvgl/src/hal/lv_hal.h"

void gfx_lvgl_flush(void *_disp_drv, const lv_area_t *area, lv_color_t *color_p) {
lv_disp_drv_t *disp_drv = (lv_disp_drv_t*)_disp_drv;
lv_disp_t *disp_drv = (lv_disp_t *)_disp_drv;

int idx = mp_obj_get_int(mp_obj_dict_get(disp_drv->user_data, MP_OBJ_NEW_QSTR(MP_QSTR_display_index)));
LovyanGFX *lvgl_gfx = (LovyanGFX *)&(M5.getDisplay(idx));
Expand All @@ -16,12 +16,12 @@ void gfx_lvgl_flush(void *_disp_drv, const lv_area_t *area, lv_color_t *color_p)

lvgl_gfx->startWrite();
lvgl_gfx->setAddrWindow(area->x1, area->y1, w, h);
lvgl_gfx->writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
lvgl_gfx->writePixels((lgfx::rgb565_t *)color_p, w * h);
lvgl_gfx->endWrite();
lv_disp_flush_ready(disp_drv);
}

bool gfx_lvgl_touch_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) {
bool gfx_lvgl_touch_read(lv_disp_t *indev_drv, lv_indev_data_t *data) {
M5.update();

if (!M5.Touch.getCount()) {
Expand All @@ -38,15 +38,15 @@ bool gfx_lvgl_touch_read(lv_indev_drv_t *indev_drv, lv_indev_data_t *data) {


void user_lvgl_flush(void *_disp_drv, const lv_area_t *area, lv_color_t *color_p) {
lv_disp_drv_t *disp_drv = (lv_disp_drv_t*)_disp_drv;
lv_disp_t *disp_drv = (lv_disp_t*)_disp_drv;

int w = (area->x2 - area->x1 + 1);
int h = (area->y2 - area->y1 + 1);

user_panel.startWrite();
user_panel.setAddrWindow(area->x1, area->y1, w, h);
user_panel.writePixels((lgfx::rgb565_t *)&color_p->full, w * h);
user_panel.writePixels((lgfx::rgb565_t *)color_p, w * h);
user_panel.endWrite();
lv_disp_flush_ready((lv_disp_drv_t *)disp_drv);
lv_disp_flush_ready((lv_disp_t *)disp_drv);
}
#endif
2 changes: 1 addition & 1 deletion m5stack/components/M5Unified/mpy_m5gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern "C"

#if MICROPY_PY_LVGL
#include "lvgl/lvgl.h"
#include "lvgl/src/hal/lv_hal_disp.h"
#include "lvgl/src/hal/lv_hal.h"
#include "./../../components/lv_bindings/driver/include/common.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion m5stack/components/lv_bindings
Submodule lv_bindings updated 51 files
+3 −3 .github/workflows/unix_port.yml
+44 −65 README.md
+0 −173 driver/SDL/modSDL.c
+0 −373 driver/SDL/sdl.c
+0 −84 driver/SDL/sdl.h
+0 −268 driver/SDL/sdl_common.c
+0 −106 driver/SDL/sdl_common.h
+12 −10 driver/esp32/espidf.c
+2 −2 driver/esp32/espidf.h
+60 −30 driver/esp32/ili9XXX.py
+0 −353 driver/esp32/modILI9341.c
+12 −12 driver/esp32/modrtch.c
+3 −5 driver/esp32/modxpt2046.c
+1 −1 driver/esp32/sh2lib.h
+4 −6 driver/esp32/xpt2046.py
+6 −8 driver/generic/ft6x36.py
+1 −1 driver/generic/ili9xxx-test.py
+0 −33 driver/generic/indev_example.py
+1 −1 driver/generic/st77xx-test.py
+6 −13 driver/generic/st77xx.py
+5 −8 driver/generic/xpt2046.py
+6 −5 driver/include/common.h
+12 −9 driver/js/lv_timer.py
+4 −6 driver/linux/evdev.py
+2 −2 driver/linux/lv_timer.py
+0 −304 driver/linux/modfb.c
+1 −1 driver/stm32/STM32F7DISC/ft5336.c
+1 −1 driver/stm32/STM32F7DISC/ft5336.h
+5 −6 driver/stm32/STM32F7DISC/modrk043fn48h.c
+6 −6 driver/zephyr/lvgl.c
+0 −1 examples/Dynamic_loading_font_example.py
+25 −76 examples/advanced_demo.py
+5 −5 examples/custom_widget_example.py
+19 −63 examples/example1.py
+13 −21 examples/example3.py
+10 −24 examples/fb_test.py
+1 −1 examples/generic-st77xx-with-xpt2046.py
+3 −2 examples/png_example.py
+15 −37 examples/uasyncio_example1.py
+276 −193 gen/gen_mpy.py
+11,626 −10,382 gen/lv_mpy_example.c
+269,202 −0 gen/lv_mpy_example.json
+11 −0 include/lv_mp_root_pointers.h
+9 −40 lib/display_driver_utils.py
+13 −11 lib/lv_utils.py
+2 −2 lib/tpcal.py
+130 −25 lv_conf.h
+1 −1 lvgl
+1 −1 pycparser
+1 −1 tests/run.sh
+1 −1 tests/run_test.py
57 changes: 24 additions & 33 deletions tests/lvgl/multiple_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,24 @@
# lvgl init
M5.Lcd.lvgl_init()

# create a display 0 buffer
disp_buf0 = lv.disp_draw_buf_t()
buf1_0 = bytearray(M5.getDisplay(0).width() * 10)
disp_buf0.init(buf1_0, None, len(buf1_0) // lv.color_t.__SIZE__)
# init function update in lvgl9. ref: https://github.com/lvgl/lvgl/issues/4011
# lv_disp_t * disp = lv_disp_create(hor_res, ver_res)
# lv_disp_set_flush_cb(disp, flush_cb);
# lv_disp_set_draw_buffers(disp, buf1, buf2, buf_size_in_bytes, mode);

# register display 0 driver
disp_drv_0 = lv.disp_drv_t()
disp_drv_0.init()
disp_drv_0.draw_buf = disp_buf0
disp_drv_0.flush_cb = M5.Lcd.lvgl_flush
disp_drv_0.hor_res = M5.getDisplay(0).width()
disp_drv_0.ver_res = M5.getDisplay(0).height()
disp_drv_0.user_data = {"display_index": 0}
disp0 = disp_drv_0.register()
# create display 0
disp0 = lv.disp_create(M5.getDisplay(0).width(), M5.getDisplay(0).height())
disp0.set_flush_cb(M5.Lcd.lvgl_flush)
buf1_0 = bytearray(M5.getDisplay(0).width() * 10 * lv.color_t.__SIZE__)
disp0.set_draw_buffers(buf1_0, None, len(buf1_0), lv.DISP_RENDER_MODE.PARTIAL)
disp0.set_user_data({"display_index": 0})

# create a display 1 buffer
disp_buf1 = lv.disp_draw_buf_t()
buf1_1 = bytearray(M5.getDisplay(1).width() * 10)
disp_buf1.init(buf1_1, None, len(buf1_1) // lv.color_t.__SIZE__)

# register display 1 driver
disp_drv_1 = lv.disp_drv_t()
disp_drv_1.init()
disp_drv_1.draw_buf = disp_buf1
disp_drv_1.flush_cb = M5.Lcd.lvgl_flush
disp_drv_1.hor_res = M5.getDisplay(1).width()
disp_drv_1.ver_res = M5.getDisplay(1).height()
disp_drv_1.user_data = {"display_index": 1}
disp1 = disp_drv_1.register()
# create display 1
disp1 = lv.disp_create(M5.getDisplay(1).width(), M5.getDisplay(1).height())
disp1.set_flush_cb(M5.Lcd.lvgl_flush)
buf1_1 = bytearray(M5.getDisplay(1).width() * 10 * lv.color_t.__SIZE__)
disp1.set_draw_buffers(buf1_1, None, len(buf1_1), lv.DISP_RENDER_MODE.PARTIAL)
disp1.set_user_data({"display_index": 1})

# set default display to screen 0
lv.disp_t.set_default(disp0)
Expand All @@ -59,12 +48,14 @@
lv.scr_load(scr1)

# touch driver init
indev_drv = lv.indev_drv_t()
indev_drv.init()
indev_drv.disp = disp0 # input device assigned to display 0
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb = M5.Lcd.lvgl_read
indev = indev_drv.register()
# init function update in lvgl9. ref: https://github.com/lvgl/lvgl/issues/4011
# lv_indev_t * indev = lv_indev_create();
# lv_indev_set_type(indev, LV_INDEV_TYPE_...);
# lv_indev_set_read_cb(indev, read_cb);
indev_drv = lv.indev_create()
indev_drv.set_disp(disp0) # input device assigned to display 0
indev_drv.set_type(lv.INDEV_TYPE.POINTER)
indev_drv.set_read_cb(M5.Lcd.lvgl_read)

# Create an image from the jpg file
try:
Expand Down