Skip to content

Commit 521b7c7

Browse files
committed
Refactor for NuttX
1 parent c2acea9 commit 521b7c7

File tree

4 files changed

+59
-15
lines changed

4 files changed

+59
-15
lines changed

build.sh

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ function compile_lvgl {
292292

293293
## Build the Feature Phone Zig LVGL App for WebAssembly
294294
## TODO: Change ".." to your NuttX Project Directory
295-
function build_feature_phone {
295+
function build_feature_phone_wasm {
296296
zig build-lib \
297297
--verbose-cimport \
298298
-target wasm32-freestanding \
@@ -400,8 +400,47 @@ function build_feature_phone {
400400

401401
}
402402

403+
## Compile the Feature Phone Zig LVGL App for Apache NuttX RTOS
404+
function build_feature_phone_nuttx {
405+
## Compile the Zig LVGL App for PinePhone
406+
## (armv8-a with cortex-a53)
407+
## TODO: Change ".." to your NuttX Project Directory
408+
zig build-obj \
409+
--verbose-cimport \
410+
-target aarch64-freestanding-none \
411+
-mcpu cortex_a53 \
412+
\
413+
-isystem "../nuttx/include" \
414+
-I . \
415+
-I "../apps/include" \
416+
-I "../apps/graphics/lvgl" \
417+
-I "../apps/graphics/lvgl/lvgl/src/core" \
418+
-I "../apps/graphics/lvgl/lvgl/src/draw" \
419+
-I "../apps/graphics/lvgl/lvgl/src/draw/arm2d" \
420+
-I "../apps/graphics/lvgl/lvgl/src/draw/nxp" \
421+
-I "../apps/graphics/lvgl/lvgl/src/draw/nxp/pxp" \
422+
-I "../apps/graphics/lvgl/lvgl/src/draw/nxp/vglite" \
423+
-I "../apps/graphics/lvgl/lvgl/src/draw/sdl" \
424+
-I "../apps/graphics/lvgl/lvgl/src/draw/stm32_dma2d" \
425+
-I "../apps/graphics/lvgl/lvgl/src/draw/sw" \
426+
-I "../apps/graphics/lvgl/lvgl/src/draw/swm341_dma2d" \
427+
-I "../apps/graphics/lvgl/lvgl/src/font" \
428+
-I "../apps/graphics/lvgl/lvgl/src/hal" \
429+
-I "../apps/graphics/lvgl/lvgl/src/misc" \
430+
-I "../apps/graphics/lvgl/lvgl/src/widgets" \
431+
feature-phone.zig
432+
433+
## Copy the compiled Zig LVGL App to NuttX and overwrite `lv_demo_widgets.*.o`
434+
## TODO: Change ".." to your NuttX Project Directory
435+
cp lvgltest.o \
436+
../apps/graphics/lvgl/lvgl/demos/widgets/lv_demo_widgets.*.o
437+
}
438+
403439
## Build the LVGL App (in Zig) and LVGL Library (in C) for PinePhone and WebAssembly
404440
build_zig
405441

406442
## Compile the Feature Phone Zig LVGL App for WebAssembly
407-
build_feature_phone
443+
build_feature_phone_wasm
444+
445+
## Compile the Feature Phone Zig LVGL App for Apache NuttX RTOS
446+
build_feature_phone_nuttx

feature-phone.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,13 @@ canvas.addEventListener("touchend", (e) => {
125125
function main() {
126126
console.log("main: start");
127127
const start_ms = Date.now();
128+
const zig = wasm.instance.exports;
129+
130+
// Init the LVGL Display and Input
131+
zig.initDisplay();
128132

129133
// Render the LVGL Widgets in Zig
130-
wasm.instance.exports
131-
.lv_demo_widgets();
134+
zig.lv_demo_widgets();
132135

133136
// Render Loop
134137
const loop = function() {
@@ -137,8 +140,7 @@ function main() {
137140
const elapsed_ms = Date.now() - start_ms;
138141

139142
// Handle LVGL Tasks to update the display
140-
wasm.instance.exports
141-
.handleTimer(elapsed_ms);
143+
zig.handleTimer(elapsed_ms);
142144

143145
// Loop to next frame
144146
window.requestAnimationFrame(loop);

feature-phone.wasm

171 Bytes
Binary file not shown.

feature-phone.zig

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ pub export fn lv_demo_widgets() void {
2121
debug("lv_demo_widgets: start", .{});
2222
defer debug("lv_demo_widgets: end", .{});
2323

24+
// Create the widgets for display
25+
createWidgets() catch |e| {
26+
// In case of error, quit
27+
std.log.err("createWidgets failed: {}", .{e});
28+
return;
29+
};
30+
31+
// JavaScript should call handleTimer periodically to handle LVGL Tasks
32+
}
33+
34+
/// Init the LVGL Display and Input
35+
pub export fn initDisplay() void {
2436
// Create the Memory Allocator for malloc
2537
memory_allocator = std.heap.FixedBufferAllocator.init(&memory_buffer);
2638

@@ -54,15 +66,6 @@ pub export fn lv_demo_widgets() void {
5466
indev_drv.type = c.LV_INDEV_TYPE_POINTER;
5567
indev_drv.read_cb = readInput;
5668
_ = c.register_input(&indev_drv);
57-
58-
// Create the widgets for display
59-
createWidgets() catch |e| {
60-
// In case of error, quit
61-
std.log.err("createWidgets failed: {}", .{e});
62-
return;
63-
};
64-
65-
// JavaScript should call handleTimer periodically to handle LVGL Tasks
6669
}
6770

6871
/// LVGL Callback Function to Flush Display

0 commit comments

Comments
 (0)