diff --git a/build.sh b/build.sh index 6310c58..6280cb5 100755 --- a/build.sh +++ b/build.sh @@ -292,7 +292,7 @@ function compile_lvgl { ## Build the Feature Phone Zig LVGL App for WebAssembly ## TODO: Change ".." to your NuttX Project Directory -function build_feature_phone { +function build_feature_phone_wasm { zig build-lib \ --verbose-cimport \ -target wasm32-freestanding \ @@ -400,8 +400,47 @@ function build_feature_phone { } +## Compile the Feature Phone Zig LVGL App for Apache NuttX RTOS +function build_feature_phone_nuttx { + ## Compile the Zig LVGL App for PinePhone + ## (armv8-a with cortex-a53) + ## TODO: Change ".." to your NuttX Project Directory + zig build-obj \ + --verbose-cimport \ + -target aarch64-freestanding-none \ + -mcpu cortex_a53 \ + \ + -isystem "../nuttx/include" \ + -I . \ + -I "../apps/include" \ + -I "../apps/graphics/lvgl" \ + -I "../apps/graphics/lvgl/lvgl/src/core" \ + -I "../apps/graphics/lvgl/lvgl/src/draw" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/arm2d" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/nxp" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/nxp/pxp" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/nxp/vglite" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/sdl" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/stm32_dma2d" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/sw" \ + -I "../apps/graphics/lvgl/lvgl/src/draw/swm341_dma2d" \ + -I "../apps/graphics/lvgl/lvgl/src/font" \ + -I "../apps/graphics/lvgl/lvgl/src/hal" \ + -I "../apps/graphics/lvgl/lvgl/src/misc" \ + -I "../apps/graphics/lvgl/lvgl/src/widgets" \ + feature-phone.zig + + ## Copy the compiled Zig LVGL App to NuttX and overwrite `lv_demo_widgets.*.o` + ## TODO: Change ".." to your NuttX Project Directory + cp lvgltest.o \ + ../apps/graphics/lvgl/lvgl/demos/widgets/lv_demo_widgets.*.o +} + ## Build the LVGL App (in Zig) and LVGL Library (in C) for PinePhone and WebAssembly build_zig ## Compile the Feature Phone Zig LVGL App for WebAssembly -build_feature_phone +build_feature_phone_wasm + +## Compile the Feature Phone Zig LVGL App for Apache NuttX RTOS +build_feature_phone_nuttx diff --git a/feature-phone.js b/feature-phone.js index 70a399d..6ed232e 100644 --- a/feature-phone.js +++ b/feature-phone.js @@ -125,10 +125,13 @@ canvas.addEventListener("touchend", (e) => { function main() { console.log("main: start"); const start_ms = Date.now(); + const zig = wasm.instance.exports; + + // Init the LVGL Display and Input + zig.initDisplay(); // Render the LVGL Widgets in Zig - wasm.instance.exports - .lv_demo_widgets(); + zig.lv_demo_widgets(); // Render Loop const loop = function() { @@ -137,8 +140,7 @@ function main() { const elapsed_ms = Date.now() - start_ms; // Handle LVGL Tasks to update the display - wasm.instance.exports - .handleTimer(elapsed_ms); + zig.handleTimer(elapsed_ms); // Loop to next frame window.requestAnimationFrame(loop); diff --git a/feature-phone.wasm b/feature-phone.wasm index 7b4226d..d8d4a99 100755 Binary files a/feature-phone.wasm and b/feature-phone.wasm differ diff --git a/feature-phone.zig b/feature-phone.zig index a0dff3a..2ac7db5 100644 --- a/feature-phone.zig +++ b/feature-phone.zig @@ -21,6 +21,18 @@ pub export fn lv_demo_widgets() void { debug("lv_demo_widgets: start", .{}); defer debug("lv_demo_widgets: end", .{}); + // Create the widgets for display + createWidgets() catch |e| { + // In case of error, quit + std.log.err("createWidgets failed: {}", .{e}); + return; + }; + + // JavaScript should call handleTimer periodically to handle LVGL Tasks +} + +/// Init the LVGL Display and Input +pub export fn initDisplay() void { // Create the Memory Allocator for malloc memory_allocator = std.heap.FixedBufferAllocator.init(&memory_buffer); @@ -54,15 +66,6 @@ pub export fn lv_demo_widgets() void { indev_drv.type = c.LV_INDEV_TYPE_POINTER; indev_drv.read_cb = readInput; _ = c.register_input(&indev_drv); - - // Create the widgets for display - createWidgets() catch |e| { - // In case of error, quit - std.log.err("createWidgets failed: {}", .{e}); - return; - }; - - // JavaScript should call handleTimer periodically to handle LVGL Tasks } /// LVGL Callback Function to Flush Display