Skip to content

Commit

Permalink
Refactor for NuttX
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Jun 5, 2023
1 parent c2acea9 commit 521b7c7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
43 changes: 41 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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
10 changes: 6 additions & 4 deletions feature-phone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
Binary file modified feature-phone.wasm
Binary file not shown.
21 changes: 12 additions & 9 deletions feature-phone.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 521b7c7

Please sign in to comment.