06-17-2023, 02:10 AM
(This post was last modified: 06-17-2023, 02:48 AM by WhiteHexagon.
Edit Reason: nightmare formatting
)
That is what I got working, feature-phone app via wasm and device
Sure, I understand, the RISC-V stuff is the future Maybe I manage to get a PineTabV in the next batch, although no blog news in over two months, so I wasnt sure they had even shipped it yet (and store still shows 'late May').
Anyway I have plenty to explore now you got the pinephone working. Amazing that you got it booting into a interactive UI in under a second! again, good work
[edit]
here are a few of the tweeks I needed to get it to build:
1) there was an unused variable: static x x++
2) build: I needed to link in libc via -lc \
3) custom panic handlers required a third parameter adding: , ret_addr: ?usize
4) in memset I had to change d.* = c2; to: d[0] = c2; (maybe in two places)
5) changed lines like this:
to:
6) feature-phone needed these:
Possibly I have a slightly different Zig version? mine reports 0.10.1
Sorry my notes are not clear, I didnt use git and vscode seems to ignore some subfolders still when I look for changes.
Updated build.sh
Sure, I understand, the RISC-V stuff is the future Maybe I manage to get a PineTabV in the next batch, although no blog news in over two months, so I wasnt sure they had even shipped it yet (and store still shows 'late May').
Anyway I have plenty to explore now you got the pinephone working. Amazing that you got it booting into a interactive UI in under a second! again, good work
[edit]
here are a few of the tweeks I needed to get it to build:
1) there was an unused variable: static x x++
2) build: I needed to link in libc via -lc \
3) custom panic handlers required a third parameter adding: , ret_addr: ?usize
4) in memset I had to change d.* = c2; to: d[0] = c2; (maybe in two places)
5) changed lines like this:
Code:
@cInclude("../../../../../../nuttx/include/limits.h");
@cInclude("../../../../../../nuttx/config.h");
to:
Code:
@cInclude("nuttx/include/limits.h");
@cInclude("nuttx/config.h");
6) feature-phone needed these:
Code:
pub export fn __stack_chk_fail() void {}
pub export fn __stack_chk_guard() void {}
Possibly I have a slightly different Zig version? mine reports 0.10.1
Sorry my notes are not clear, I didnt use git and vscode seems to ignore some subfolders still when I look for changes.
Updated build.sh
Code:
#!/usr/bin/env bash
# Build LVGL App (in Zig) and LVGL Library (in C) for PinePhone and WebAssembly
set -e # Exit when any command fails
set -x # Echo commands
export PRJ_HOME=/home/peter/prj/zig/examples/lvgl/pinephone-lvgl-zig
export OBJ_HOME=/home/peter/software/nuttx/apps/graphics/lvgl/lvgl/demos/widgets
export NUTTX_HOME=/home/peter/software/nuttx
export APPS_HOME=$NUTTX_HOME/apps
export LVGL_HOME=$NUTTX_HOME/apps/graphics/lvgl
export LVGL_SRC=$LVGL_HOME/lvgl/src
## Build the LVGL App (in Zig) and LVGL Library (in C) for PinePhone and WebAssembly
function build_zig {
## Check that NuttX Build has completed and `lv_demo_widgets.*.o` exists
if [ ! -f $OBJ_HOME/lv_demo_widgets.*.o ]
then
echo "*** Error: Build NuttX first before building Zig app"
exit 1
fi
## Compile our LVGL Display Driver from C to WebAssembly with Zig Compiler
compile_lvgl $PRJ_HOME/display.c $PRJ_HOME/display.o
## Compile LVGL Library from C to WebAssembly with Zig Compiler
compile_lvgl $LVGL_SRC/font/lv_font_montserrat_14.c $PRJ_HOME/lv_font_montserrat_14.o
compile_lvgl $LVGL_SRC/font/lv_font_montserrat_20.c $PRJ_HOME/lv_font_montserrat_20.o
compile_lvgl $LVGL_SRC/widgets/lv_label.c $PRJ_HOME/lv_label.o
compile_lvgl $LVGL_SRC/core/lv_obj.c $PRJ_HOME/lv_obj.o
compile_lvgl $LVGL_SRC/misc/lv_mem.c $PRJ_HOME/lv_mem.o
compile_lvgl $LVGL_SRC/core/lv_event.c $PRJ_HOME/lv_event.o
compile_lvgl $LVGL_SRC/core/lv_obj_style.c $PRJ_HOME/lv_obj_style.o
compile_lvgl $LVGL_SRC/core/lv_obj_pos.c $PRJ_HOME/lv_obj_pos.o
compile_lvgl $LVGL_SRC/misc/lv_txt.c $PRJ_HOME/lv_txt.o
compile_lvgl $LVGL_SRC/draw/lv_draw_label.c $PRJ_HOME/lv_draw_label.o
compile_lvgl $LVGL_SRC/core/lv_obj_draw.c $PRJ_HOME/lv_obj_draw.o
compile_lvgl $LVGL_SRC/misc/lv_area.c $PRJ_HOME/lv_area.o
compile_lvgl $LVGL_SRC/core/lv_obj_scroll.c $PRJ_HOME/lv_obj_scroll.o
compile_lvgl $LVGL_SRC/font/lv_font.c $PRJ_HOME/lv_font.o
compile_lvgl $LVGL_SRC/core/lv_obj_class.c $PRJ_HOME/lv_obj_class.o
compile_lvgl $LVGL_SRC/core/lv_obj_tree.c $PRJ_HOME/lv_obj_tree.o
compile_lvgl $LVGL_SRC/hal/lv_hal_disp.c $PRJ_HOME/lv_hal_disp.o
compile_lvgl $LVGL_SRC/misc/lv_anim.c $PRJ_HOME/lv_anim.o
compile_lvgl $LVGL_SRC/misc/lv_tlsf.c $PRJ_HOME/lv_tlsf.o
compile_lvgl $LVGL_SRC/core/lv_group.c $PRJ_HOME/lv_group.o
compile_lvgl $LVGL_SRC/core/lv_indev.c $PRJ_HOME/lv_indev.o
compile_lvgl $LVGL_SRC/draw/lv_draw_rect.c $PRJ_HOME/lv_draw_rect.o
compile_lvgl $LVGL_SRC/draw/lv_draw_mask.c $PRJ_HOME/lv_draw_mask.o
compile_lvgl $LVGL_SRC/misc/lv_style.c $PRJ_HOME/lv_style.o
compile_lvgl $LVGL_SRC/misc/lv_ll.c $PRJ_HOME/lv_ll.o
compile_lvgl $LVGL_SRC/core/lv_obj_style_gen.c $PRJ_HOME/lv_obj_style_gen.o
compile_lvgl $LVGL_SRC/misc/lv_timer.c $PRJ_HOME/lv_timer.o
compile_lvgl $LVGL_SRC/core/lv_disp.c $PRJ_HOME/lv_disp.o
compile_lvgl $LVGL_SRC/core/lv_refr.c $PRJ_HOME/lv_refr.o
compile_lvgl $LVGL_SRC/misc/lv_color.c $PRJ_HOME/lv_color.o
compile_lvgl $LVGL_SRC/draw/lv_draw_line.c $PRJ_HOME/lv_draw_line.o
compile_lvgl $LVGL_SRC/draw/lv_draw_img.c $PRJ_HOME/lv_draw_img.o
compile_lvgl $LVGL_SRC/misc/lv_math.c $PRJ_HOME/lv_math.o
compile_lvgl $LVGL_SRC/hal/lv_hal_indev.c $PRJ_HOME/lv_hal_indev.o
compile_lvgl $LVGL_SRC/core/lv_theme.c $PRJ_HOME/lv_theme.o
compile_lvgl $LVGL_SRC/hal/lv_hal_tick.c $PRJ_HOME/lv_hal_tick.o
compile_lvgl $LVGL_SRC/misc/lv_log.c $PRJ_HOME/lv_log.o
compile_lvgl $LVGL_SRC/misc/lv_printf.c $PRJ_HOME/lv_printf.o
compile_lvgl $LVGL_SRC/misc/lv_fs.c $PRJ_HOME/lv_fs.o
compile_lvgl $LVGL_SRC/draw/lv_draw.c $PRJ_HOME/lv_draw.o
compile_lvgl $LVGL_SRC/draw/lv_img_decoder.c $PRJ_HOME/lv_img_decoder.o
compile_lvgl $LVGL_SRC/extra/lv_extra.c $PRJ_HOME/lv_extra.o
compile_lvgl $LVGL_SRC/extra/layouts/flex/lv_flex.c $PRJ_HOME/lv_flex.o
compile_lvgl $LVGL_SRC/extra/layouts/grid/lv_grid.c $PRJ_HOME/lv_grid.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw.c $PRJ_HOME/lv_draw_sw.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_rect.c $PRJ_HOME/lv_draw_sw_rect.o
compile_lvgl $LVGL_SRC/draw/lv_img_cache.c $PRJ_HOME/lv_img_cache.o
compile_lvgl $LVGL_SRC/draw/lv_img_buf.c $PRJ_HOME/lv_img_buf.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_arc.c $PRJ_HOME/lv_draw_sw_arc.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_letter.c $PRJ_HOME/lv_draw_sw_letter.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_blend.c $PRJ_HOME/lv_draw_sw_blend.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_layer.c $PRJ_HOME/lv_draw_sw_layer.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_transform.c $PRJ_HOME/lv_draw_sw_transform.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_polygon.c $PRJ_HOME/lv_draw_sw_polygon.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_line.c $PRJ_HOME/lv_draw_sw_line.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_img.c $PRJ_HOME/lv_draw_sw_img.o
compile_lvgl $LVGL_SRC/draw/sw/lv_draw_sw_gradient.c $PRJ_HOME/lv_draw_sw_gradient.o
compile_lvgl $LVGL_SRC/draw/lv_draw_transform.c $PRJ_HOME/lv_draw_transform.o
compile_lvgl $LVGL_SRC/extra/themes/default/lv_theme_default.c $PRJ_HOME/lv_theme_default.o
compile_lvgl $LVGL_SRC/font/lv_font_fmt_txt.c $PRJ_HOME/lv_font_fmt_txt.o
compile_lvgl $LVGL_SRC/draw/lv_draw_layer.c $PRJ_HOME/lv_draw_layer.o
compile_lvgl $LVGL_SRC/misc/lv_style_gen.c $PRJ_HOME/lv_style_gen.o
compile_lvgl $LVGL_SRC/misc/lv_gc.c $PRJ_HOME/lv_gc.o
compile_lvgl $LVGL_SRC/misc/lv_utils.c $PRJ_HOME/lv_utils.o
compile_lvgl $LVGL_SRC/widgets/lv_btn.c $PRJ_HOME/lv_btn.o
compile_lvgl $LVGL_SRC/core/lv_indev_scroll.c $PRJ_HOME/lv_indev_scroll.o
## Compile the Zig LVGL App for WebAssembly
zig build-lib \
--verbose-cimport \
-target wasm32-freestanding \
-dynamic \
-rdynamic \
-lc \
-DFAR= \
-DLV_MEM_CUSTOM=1 \
-DLV_FONT_MONTSERRAT_14=1 \
-DLV_FONT_MONTSERRAT_20=1 \
-DLV_FONT_DEFAULT_MONTSERRAT_20=1 \
-DLV_USE_FONT_PLACEHOLDER=1 \
-DLV_USE_LOG=1 \
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
-DLV_LOG_TRACE_OBJ_CREATE=1 \
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
-I . \
\
-isystem "$NUTTX_HOME/nuttx/include" \
-I "$NUTTX_HOME" \
-I "$APPS_HOME/include" \
-I "$LVGL_HOME" \
-I "$LVGL_SRC/core" \
-I "$LVGL_SRC/draw" \
-I "$LVGL_SRC/draw/arm2d" \
-I "$LVGL_SRC/draw/nxp" \
-I "$LVGL_SRC/draw/nxp/pxp" \
-I "$LVGL_SRC/draw/nxp/vglite" \
-I "$LVGL_SRC/draw/sdl" \
-I "$LVGL_SRC/draw/stm32_dma2d" \
-I "$LVGL_SRC/draw/sw" \
-I "$LVGL_SRC/draw/swm341_dma2d" \
-I "$LVGL_SRC/font" \
-I "$LVGL_SRC/hal" \
-I "$LVGL_SRC/misc" \
-I "$LVGL_SRC/widgets" \
\
lvglwasm.zig \
display.o \
lv_font_montserrat_14.o \
lv_font_montserrat_20.o \
lv_label.o \
lv_mem.o \
lv_obj.o \
lv_event.o \
lv_obj_style.o \
lv_obj_pos.o \
lv_txt.o \
lv_draw_label.o \
lv_obj_draw.o \
lv_area.o \
lv_obj_scroll.o \
lv_font.o \
lv_obj_class.o \
lv_obj_tree.o \
lv_hal_disp.o \
lv_anim.o \
lv_tlsf.o \
lv_group.o \
lv_indev.o \
lv_draw_rect.o \
lv_draw_mask.o \
lv_style.o \
lv_ll.o \
lv_obj_style_gen.o \
lv_timer.o \
lv_disp.o \
lv_refr.o \
lv_color.o \
lv_draw_line.o \
lv_draw_img.o \
lv_math.o \
lv_hal_indev.o \
lv_theme.o \
lv_hal_tick.o \
lv_log.o \
lv_printf.o \
lv_fs.o \
lv_draw.o \
lv_img_decoder.o \
lv_extra.o \
lv_flex.o \
lv_grid.o \
lv_draw_sw.o \
lv_draw_sw_rect.o \
lv_img_cache.o \
lv_img_buf.o \
lv_draw_sw_arc.o \
lv_draw_sw_letter.o \
lv_draw_sw_blend.o \
lv_draw_sw_layer.o \
lv_draw_sw_transform.o \
lv_draw_sw_polygon.o \
lv_draw_sw_line.o \
lv_draw_sw_img.o \
lv_draw_sw_gradient.o \
lv_draw_transform.o \
lv_theme_default.o \
lv_font_fmt_txt.o \
lv_draw_layer.o \
lv_style_gen.o \
lv_gc.o \
lv_utils.o \
lv_btn.o \
lv_indev_scroll.o \
## Compile the Zig LVGL App for PinePhone
## (armv8-a with cortex-a53)
zig build-obj \
-lc \
--verbose-cimport \
-target aarch64-freestanding-none \
-mcpu cortex_a53 \
\
-isystem "$NUTTX_HOME/nuttx/include" \
-I . \
-I "$NUTTX_HOME" \
-I "$APPS_HOME/include" \
-I "$LVGL_HOME" \
-I "$LVGL_SRC/core" \
-I "$LVGL_SRC/draw" \
-I "$LVGL_SRC/draw/arm2d" \
-I "$LVGL_SRC/draw/nxp" \
-I "$LVGL_SRC/draw/nxp/pxp" \
-I "$LVGL_SRC/draw/nxp/vglite" \
-I "$LVGL_SRC/draw/sdl" \
-I "$LVGL_SRC/draw/stm32_dma2d" \
-I "$LVGL_SRC/draw/sw" \
-I "$LVGL_SRC/draw/swm341_dma2d" \
-I "$LVGL_SRC/font" \
-I "$LVGL_SRC/hal" \
-I "$LVGL_SRC/misc" \
-I "$LVGL_SRC/widgets" \
lvgltest.zig
## Copy the compiled Zig LVGL App to NuttX and overwrite `lv_demo_widgets.*.o`
cp lvgltest.o $OBJ_HOME/lv_demo_widgets.*.o
}
## Compile LVGL Library from C to WebAssembly with Zig Compiler
function compile_lvgl {
local source_file=$1 ## Input Source File (LVGL in C)
local object_file=$2 ## Output Object File (WebAssembly)
zig cc \
-target wasm32-freestanding \
-dynamic \
-rdynamic \
-lc \
-DFAR= \
-DLV_MEM_CUSTOM=1 \
-DLV_FONT_MONTSERRAT_14=1 \
-DLV_FONT_MONTSERRAT_20=1 \
-DLV_FONT_DEFAULT_MONTSERRAT_20=1 \
-DLV_USE_FONT_PLACEHOLDER=1 \
-DLV_USE_LOG=1 \
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
-DLV_LOG_TRACE_OBJ_CREATE=1 \
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
\
-c \
-fno-common \
-Wall \
-Wstrict-prototypes \
-Wshadow \
-Wundef \
-Werror \
-Os \
-fno-strict-aliasing \
-fomit-frame-pointer \
-ffunction-sections \
-fdata-sections \
-g \
-isystem $NUTTX_HOME/nuttx/include \
-D__NuttX__ \
-pipe \
-I $LVGL_HOME \
-I "$APPS_HOME/include" \
-Wno-format \
-Wno-format-security \
-Wno-unused-variable \
"-I./lvgl/src/core" \
"-I./lvgl/src/draw" \
"-I./lvgl/src/draw/arm2d" \
"-I./lvgl/src/draw/nxp" \
"-I./lvgl/src/draw/nxp/pxp" \
"-I./lvgl/src/draw/nxp/vglite" \
"-I./lvgl/src/draw/sdl" \
"-I./lvgl/src/draw/stm32_dma2d" \
"-I./lvgl/src/draw/sw" \
"-I./lvgl/src/draw/swm341_dma2d" \
"-I./lvgl/src/font" \
"-I./lvgl/src/hal" \
"-I./lvgl/src/misc" \
"-I./lvgl/src/widgets" \
$source_file \
-o $object_file
}
## Build the Feature Phone Zig LVGL App for WebAssembly
function build_feature_phone_wasm {
zig build-lib \
-lc \
--verbose-cimport \
-target wasm32-freestanding \
-dynamic \
-rdynamic \
-DFAR= \
-DLV_MEM_CUSTOM=1 \
-DLV_FONT_MONTSERRAT_14=1 \
-DLV_FONT_MONTSERRAT_20=1 \
-DLV_FONT_DEFAULT_MONTSERRAT_20=1 \
-DLV_USE_FONT_PLACEHOLDER=1 \
-DLV_USE_LOG=1 \
-DLV_LOG_LEVEL=LV_LOG_LEVEL_TRACE \
-DLV_LOG_TRACE_OBJ_CREATE=1 \
"-DLV_ASSERT_HANDLER={void lv_assert_handler(void); lv_assert_handler();}" \
-I . \
\
-isystem "$NUTTX_HOME/nuttx/include" \
-I "$NUTTX_HOME" \
-I "$APPS_HOME/include" \
-I "$LVGL_HOME" \
-I "$LVGL_SRC/core" \
-I "$LVGL_SRC/draw" \
-I "$LVGL_SRC/draw/arm2d" \
-I "$LVGL_SRC/draw/nxp" \
-I "$LVGL_SRC/draw/nxp/pxp" \
-I "$LVGL_SRC/draw/nxp/vglite" \
-I "$LVGL_SRC/draw/sdl" \
-I "$LVGL_SRC/draw/stm32_dma2d" \
-I "$LVGL_SRC/draw/sw" \
-I "$LVGL_SRC/draw/swm341_dma2d" \
-I "$LVGL_SRC/font" \
-I "$LVGL_SRC/hal" \
-I "$LVGL_SRC/misc" \
-I "$LVGL_SRC/widgets" \
\
feature-phone.zig \
display.o \
lv_font_montserrat_14.o \
lv_font_montserrat_20.o \
lv_label.o \
lv_mem.o \
lv_obj.o \
lv_event.o \
lv_obj_style.o \
lv_obj_pos.o \
lv_txt.o \
lv_draw_label.o \
lv_obj_draw.o \
lv_area.o \
lv_obj_scroll.o \
lv_font.o \
lv_obj_class.o \
lv_obj_tree.o \
lv_hal_disp.o \
lv_anim.o \
lv_tlsf.o \
lv_group.o \
lv_indev.o \
lv_draw_rect.o \
lv_draw_mask.o \
lv_style.o \
lv_ll.o \
lv_obj_style_gen.o \
lv_timer.o \
lv_disp.o \
lv_refr.o \
lv_color.o \
lv_draw_line.o \
lv_draw_img.o \
lv_math.o \
lv_hal_indev.o \
lv_theme.o \
lv_hal_tick.o \
lv_log.o \
lv_printf.o \
lv_fs.o \
lv_draw.o \
lv_img_decoder.o \
lv_extra.o \
lv_flex.o \
lv_grid.o \
lv_draw_sw.o \
lv_draw_sw_rect.o \
lv_img_cache.o \
lv_img_buf.o \
lv_draw_sw_arc.o \
lv_draw_sw_letter.o \
lv_draw_sw_blend.o \
lv_draw_sw_layer.o \
lv_draw_sw_transform.o \
lv_draw_sw_polygon.o \
lv_draw_sw_line.o \
lv_draw_sw_img.o \
lv_draw_sw_gradient.o \
lv_draw_transform.o \
lv_theme_default.o \
lv_font_fmt_txt.o \
lv_draw_layer.o \
lv_style_gen.o \
lv_gc.o \
lv_utils.o \
lv_btn.o \
lv_indev_scroll.o \
}
## 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)
zig build-obj \
-lc \
--verbose-cimport \
-target aarch64-freestanding-none \
-mcpu cortex_a53 \
\
-isystem "$NUTTX_HOME/nuttx/include" \
-I . \
-I "$NUTTX_HOME" \
-I "$APPS_HOME/include" \
-I "$LVGL_HOME" \
-I "$LVGL_SRC/core" \
-I "$LVGL_SRC/draw" \
-I "$LVGL_SRC/draw/arm2d" \
-I "$LVGL_SRC/draw/nxp" \
-I "$LVGL_SRC/draw/nxp/pxp" \
-I "$LVGL_SRC/draw/nxp/vglite" \
-I "$LVGL_SRC/draw/sdl" \
-I "$LVGL_SRC/draw/stm32_dma2d" \
-I "$LVGL_SRC/draw/sw" \
-I "$LVGL_SRC/draw/swm341_dma2d" \
-I "$LVGL_SRC/font" \
-I "$LVGL_SRC/hal" \
-I "$LVGL_SRC/misc" \
-I "$LVGL_SRC/widgets" \
feature-phone.zig
## Copy the compiled Zig LVGL App to NuttX and overwrite `lv_demo_widgets.*.o`
cp feature-phone.o $OBJ_HOME/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_wasm
## Compile the Feature Phone Zig LVGL App for Apache NuttX RTOS
build_feature_phone_nuttx