Skip to content

Commit 5c25cbe

Browse files
committed
Improve build script and LVGL emulator
build_and_run.sh: clear the build directory when the cached CMake generator or CMAKE_BUILD_TYPE no longer matches the desired values, and choose RelWithDebInfo for local runs (Debug for CI). Introduce BUILD_TYPE and pass it to CMake so generator/build-type mismatches are handled cleanly. emulator_display.cpp: align the LVGL draw buffer to 4 bytes to satisfy LV_DRAW_BUF_ALIGN (avoids LVGL v9 assert) and call lv_timer_handler() repeatedly before lv_refr_now to drain timers/deferred layout work so the first render doesn't block.
1 parent 36e5727 commit 5c25cbe

2 files changed

Lines changed: 25 additions & 13 deletions

File tree

test/test_screenshots/build_and_run.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,30 @@ fi
8585

8686
mkdir -p "$BUILD_DIR"
8787

88-
# Switching to --local with Ninja: clear a Unix Makefiles (or other) cache once.
89-
if [ "$LOCAL_BUILD" = 1 ] && [ "${#CMAKE_GEN_ARGS[@]}" -gt 0 ]; then
90-
if [ -f "$BUILD_DIR/CMakeCache.txt" ]; then
91-
if ! grep -q '^CMAKE_GENERATOR:INTERNAL=Ninja$' "$BUILD_DIR/CMakeCache.txt" 2>/dev/null; then
92-
echo "Local build: clearing $BUILD_DIR to switch CMake generator to Ninja..."
93-
rm -rf "$BUILD_DIR"
94-
mkdir -p "$BUILD_DIR"
95-
fi
88+
# If the cached generator or build type no longer matches, clear the build dir once.
89+
if [ -f "$BUILD_DIR/CMakeCache.txt" ]; then
90+
cached_gen=$(grep '^CMAKE_GENERATOR:INTERNAL=' "$BUILD_DIR/CMakeCache.txt" 2>/dev/null | cut -d= -f2)
91+
cached_type=$(grep '^CMAKE_BUILD_TYPE:STRING=' "$BUILD_DIR/CMakeCache.txt" 2>/dev/null | cut -d= -f2)
92+
want_gen="Unix Makefiles"
93+
[ "${#CMAKE_GEN_ARGS[@]}" -gt 0 ] && want_gen="Ninja"
94+
if [ "$cached_gen" != "$want_gen" ] || [ "$cached_type" != "$BUILD_TYPE" ]; then
95+
echo "Clearing $BUILD_DIR (generator/build type changed: ${cached_gen}/${cached_type} -> ${want_gen}/${BUILD_TYPE})..."
96+
rm -rf "$BUILD_DIR"
97+
mkdir -p "$BUILD_DIR"
9698
fi
9799
fi
98100

99101
cd "$BUILD_DIR"
100102

101103
echo ""
102104
echo "--- Configuring CMake ---"
105+
# --local uses RelWithDebInfo: optimized binary (5-10x faster renderer) with debug symbols.
106+
# CI keeps Debug for faithful failure diagnostics.
107+
BUILD_TYPE="Debug"
108+
[ "$LOCAL_BUILD" = 1 ] && BUILD_TYPE="RelWithDebInfo"
103109
# shellcheck disable=SC2086
104110
cmake "$SCRIPT_DIR" \
105-
-DCMAKE_BUILD_TYPE=Debug \
111+
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
106112
"${CMAKE_GEN_ARGS[@]}" \
107113
"${CMAKE_CCACHE_ARGS[@]}" \
108114
${LVGL_DIR:+-DLVGL_DIR="$LVGL_DIR"} \

test/test_screenshots/emulator_display.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
// Full-screen framebuffer: 160 x 128 pixels, RGB565
1313
static uint16_t framebuffer[SCREEN_WIDTH * SCREEN_HEIGHT];
1414

15-
// LVGL draw buffers (full-screen for complete frame capture)
16-
static uint8_t lvgl_buf1[SCREEN_WIDTH * SCREEN_HEIGHT * 2];
15+
// LVGL draw buffer - must be aligned to LV_DRAW_BUF_ALIGN (4 bytes).
16+
// LVGL v9 asserts on misaligned buffers and spins in while(1) on failure.
17+
static uint8_t lvgl_buf1[SCREEN_WIDTH * SCREEN_HEIGHT * 2] __attribute__((aligned(4)));
1718

1819
// Define globals declared in lvgl_core.h
1920
lv_display_t* main_display = nullptr;
@@ -81,9 +82,14 @@ lv_display_t* emulator_init_display(bool darkMode) {
8182
}
8283

8384
void emulator_render_frame() {
84-
// Tick LVGL forward to process any pending timers/animations
85+
// Tick LVGL forward so any time-dependent layout/animation work is scheduled.
8586
lv_tick_inc(100);
86-
// Force a full refresh
87+
// Drain LVGL's internal timer queue before forcing the refresh. Without
88+
// this the first render on a freshly-created screen can block waiting for
89+
// deferred layout passes that are only triggered by lv_timer_handler().
90+
for (int i = 0; i < 64; i++) {
91+
lv_timer_handler();
92+
}
8793
lv_refr_now(main_display);
8894
}
8995

0 commit comments

Comments
 (0)