Skip to content

feat: add SDL support - #227

Open
mverch67 wants to merge 20 commits into
masterfrom
sdl-support
Open

feat: add SDL support#227
mverch67 wants to merge 20 commits into
masterfrom
sdl-support

Conversation

@mverch67

@mverch67 mverch67 commented Oct 15, 2025

Copy link
Copy Markdown
Collaborator

requires lvgl 9.4.0

Summary by CodeRabbit

  • New Features
    • Added SDL-based display support for PC/Raspberry Pi simulation, including mouse, keyboard, and scroll-wheel input.
    • Added SDL as a selectable display device.
  • Enhancements
    • Upgraded LVGL to v9.5.0 with updated default rendering, widgets, media, and profiling configuration.
    • Improved display timing/cadence for SDL and X11, plus architecture-specific TFT tick adjustments.
    • Refined styling across the 320×240 interface.
  • Bug Fixes
    • Made RGB565 byte-swapping optional on supported LGFX builds to prevent incorrect colors.

@mverch67

mverch67 commented Dec 1, 2025

Copy link
Copy Markdown
Collaborator Author

facing this issue as well: lvgl/lvgl#9237

@arthurlutz

Copy link
Copy Markdown

does this enable iterating on the UI without flashing a device ?

@mverch67

Copy link
Copy Markdown
Collaborator Author

does this enable iterating on the UI without flashing a device ?

yes, but that can be done with native/X11, too

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

LVGL is upgraded to 9.5 with expanded configuration, SDL display support is added, platform-specific timing is revised, and TFT UI styling is updated across maps, nodes, messages, connectivity indicators, and chat controls.

Changes

LVGL display updates

Layer / File(s) Summary
LVGL configuration and rendering update
include/lv_conf.h, include/graphics/driver/LGFXDriver.h, library.json
LVGL rendering, backend, widget, filesystem, profiling, input, demo, and build options are revised, the dependency changes to v9.5.0, and RGB565 swapping becomes configurable.
SDL display-driver integration
include/graphics/driver/SDLDriver.h, source/graphics/driver/SDLDriver.cpp, source/graphics/driver/DisplayDriverFactory.cpp
Adds an SDLDriver singleton-style factory, initializes SDL-backed LVGL display and input devices, schedules LVGL ticks, and adds SDL device selection to the display-driver factory.
Platform LVGL timing ownership
include/graphics/driver/TFTDriver.h, include/graphics/driver/X11Driver.h, source/graphics/DeviceGUI.cpp, source/graphics/driver/X11Driver.cpp
Configures ESP32 and Portduinuo tick sources, delegates timing from DeviceGUI to drivers, and adds X11 task scheduling with LVGL tick updates.
TFT LVGL style updates
source/graphics/TFT/TFTView_320x240.cpp
Revises LVGL main-part styling, spacing, text measurement, icons, node and map presentation, message bubbles, connection indicators, trace-route controls, filters, and chat widgets.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DisplayDriverFactory
  participant SDLDriver
  participant DisplayDriver
  participant LVGL
  DisplayDriverFactory->>SDLDriver: create(width, height)
  SDLDriver->>DisplayDriver: initialize base driver
  SDLDriver->>LVGL: create SDL display and input devices
  SDLDriver->>DisplayDriver: run display task handler
  SDLDriver->>LVGL: advance LVGL ticks
Loading

Poem

I’m a rabbit hopping through the screen,
Where SDL windows sparkle green.
Ticks now march and styles align,
Nodes and chats look extra fine.
LVGL blooms from burrow to beam!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.63% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding SDL support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mverch67
mverch67 marked this pull request as ready for review July 16, 2026 20:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (1)
library.json (1)

24-24: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update the LVGL version banner in include/lv_conf.h
library.json pins LVGL v9.5.0, but the header still says v9.2.2. Keep the comment aligned with the dependency.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@library.json` at line 24, Update the LVGL version banner comment in lv_conf.h
to state v9.5.0, matching the version pinned by the lvgl/lvgl dependency in
library.json.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@include/graphics/driver/SDLDriver.h`:
- Around line 4-9: Update the documentation comment above the SDL driver class
to reference SDL2 linking, replacing the misleading -lSDL flag with -lSDL2 or
the project’s established SDL2 build configuration. Keep the existing usage and
platform guidance unchanged.

In `@include/lv_conf.h`:
- Around line 288-292: Update the SDL and X11 driver preprocessor guards to use
value-based checks, replacing `#ifdef/`#if defined(...) checks with `#if` USE_SDL or
`#if` USE_X11 as appropriate. Ensure USE_SDL=0 and USE_X11=0 disable their
respective paths while nonzero values enable them, including the related guards
in include/lv_conf.h.

In `@source/graphics/driver/X11Driver.cpp`:
- Around line 32-49: Update X11Driver::task_handler to remove both lv_tick_inc()
calls while preserving the existing duration-based sleep behavior in both
branches.

In `@source/graphics/TFT/TFTView_320x240.cpp`:
- Around line 7144-7146: Replace the unsafe strcpy call in the no-new-messages
branch with a bounded copy using snprintf or strlcpy, ensuring the translated
string is truncated safely and buf remains null-terminated within its 64-byte
capacity.
- Around line 5185-5187: Replace the sprintf call formatting the MAC address in
the Bluetooth label update with snprintf, passing the size of buf so writes are
bounded while preserving the existing output format and lv_label_set_text call.
- Line 244: Rename the LVGL style setter calls throughout the TFT view
implementation from the deprecated `bg_img` spelling to the LVGL 9 `bg_image`
spelling, including `lv_obj_set_style_bg_img_recolor` and all other `_img_`
style setters in this file. Preserve each call’s existing arguments and
behavior.

---

Nitpick comments:
In `@library.json`:
- Line 24: Update the LVGL version banner comment in lv_conf.h to state v9.5.0,
matching the version pinned by the lvgl/lvgl dependency in library.json.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c1b4c862-46f2-4655-a716-8bdfe1bc0464

📥 Commits

Reviewing files that changed from the base of the PR and between 33917d5 and d6e1a19.

📒 Files selected for processing (10)
  • include/graphics/driver/SDLDriver.h
  • include/graphics/driver/TFTDriver.h
  • include/graphics/driver/X11Driver.h
  • include/lv_conf.h
  • library.json
  • source/graphics/DeviceGUI.cpp
  • source/graphics/TFT/TFTView_320x240.cpp
  • source/graphics/driver/DisplayDriverFactory.cpp
  • source/graphics/driver/SDLDriver.cpp
  • source/graphics/driver/X11Driver.cpp
💤 Files with no reviewable changes (1)
  • source/graphics/DeviceGUI.cpp

Comment on lines +4 to +9
/**
* @brief For simulation on pc/raspberry
* This class provides an SDL GUI on the local desktop; dimensions are defined
* in lv_drv_conf.h Usage: define USE_SDL=1 for the rasbian/portduino target and
* link with -lSDL
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
rg -n -- '-lSDL(2)?\b|sdl2-config|pkg-config.*sdl2|SDL2::SDL2' .

Repository: meshtastic/device-ui

Length of output: 217


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== SDLDriver.h =="
cat -n include/graphics/driver/SDLDriver.h

echo
echo "== SDL-related files =="
git ls-files | rg '(^|/)(CMakeLists\.txt|.*\.cmake|.*\.(h|hpp|c|cc|cpp))$' | rg 'SDL|sdl|graphics/driver'

echo
echo "== SDL includes/usages =="
rg -n --glob '!**/build/**' --glob '!**/dist/**' --glob '!**/node_modules/**' 'SDL2?|sdl2-config|pkg-config.*sdl2|SDL_' include src .github CMakeLists.txt *.cmake

echo
echo "== Build/link config mentions =="
rg -n --glob '!**/build/**' --glob '!**/dist/**' --glob '!**/node_modules/**' '-lSDL(2)?\b|SDL2::SDL2|PkgConfig::.*SDL2|find_package\(SDL2|find_package\(SDL' .

Repository: meshtastic/device-ui

Length of output: 3592


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== SDL driver implementation =="
cat -n source/graphics/driver/SDLDriver.cpp

echo
echo "== SDL2 and linker config mentions =="
rg -n --glob '!**/build/**' --glob '!**/dist/**' --glob '!**/node_modules/**' \
  'SDL2|sdl2-config|pkg-config.*sdl2|find_package\(SDL|find_package\(SDL2|SDL2::SDL2|PkgConfig::.*SDL2|SDL_INCLUDE|SDL_LIB|USE_SDL|LV_USE_SDL' \
  include source .

echo
echo "== Build files =="
git ls-files | rg '(^|/)(CMakeLists\.txt|.*\.cmake|Makefile|GNUmakefile|Kconfig|platformio\.ini)$'

Repository: meshtastic/device-ui

Length of output: 4303


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== CMakeLists.txt =="
cat -n CMakeLists.txt

echo
echo "== cmake/Portduino.cmake =="
cat -n cmake/Portduino.cmake

echo
echo "== cmake/LVGL.cmake =="
cat -n cmake/LVGL.cmake

echo
echo "== SDL build references =="
rg -n --glob '!**/build/**' --glob '!**/dist/**' --glob '!**/node_modules/**' \
  'SDL2|SDL|sdl2-config|pkg-config|target_link_libraries|find_package' CMakeLists.txt cmake include source

Repository: meshtastic/device-ui

Length of output: 10711


Document the SDL2 linker flag

This code uses SDL2 (<SDL2/SDL.h> and LV_SDL_INCLUDE_PATH), so -lSDL is misleading. Update the note to point to SDL2 linking (-lSDL2 or the project’s SDL2 build config).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@include/graphics/driver/SDLDriver.h` around lines 4 - 9, Update the
documentation comment above the SDL driver class to reference SDL2 linking,
replacing the misleading -lSDL flag with -lSDL2 or the project’s established
SDL2 build configuration. Keep the existing usage and platform guidance
unchanged.

Comment thread include/lv_conf.h Outdated
Comment on lines +32 to +49
/**
* Measure how long it takes to call DisplayDriver::task_handler().
* Then tell the lvgl library how long it took via lv_tick_inc().
*/
void X11Driver::task_handler(void)
{
const int ms = 10;
auto start = std::chrono::high_resolution_clock::now();
DisplayDriver::task_handler();
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
if (duration.count() < ms) {
std::this_thread::sleep_for(std::chrono::milliseconds(ms - duration.count()));
lv_tick_inc(ms);
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
lv_tick_inc(duration.count() + 1);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
curl -fsSL \
  https://raw.githubusercontent.com/lvgl/lvgl/v9.5.0/src/drivers/x11/lv_x11_display.c |
  rg -n -C3 'x11_tick_thread|lv_tick_inc'

Repository: meshtastic/device-ui

Length of output: 605


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the driver and its LVGL/X11 integration points
git ls-files 'source/graphics/driver/*' 'source/graphics/*' 'src/*' 'include/*' | sed -n '1,200p'

echo '--- X11Driver.cpp ---'
cat -n source/graphics/driver/X11Driver.cpp | sed -n '1,220p'

echo '--- search for X11 backend / lv_tick_inc / lv_timer_handler usage ---'
rg -n 'lv_tick_inc|lv_timer_handler|x11|LV_USE_X11|lv_x11' source include src

Repository: meshtastic/device-ui

Length of output: 9173


Remove the extra X11 tick updates

LVGL’s X11 backend already advances time on its own 5 ms thread, so these lv_tick_inc() calls double-count time and make timers/animations run too fast. Keep the sleep, but remove both increments.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@source/graphics/driver/X11Driver.cpp` around lines 32 - 49, Update
X11Driver::task_handler to remove both lv_tick_inc() calls while preserving the
existing duration-based sleep behavior in both branches.

Comment thread source/graphics/TFT/TFTView_320x240.cpp
Comment thread source/graphics/TFT/TFTView_320x240.cpp
Comment thread source/graphics/TFT/TFTView_320x240.cpp
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mverch67

mverch67 commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator Author

lvgl 9.5.0 crashes in lv_draw_sdl.c (see lvgl/lvgl@master...mverch67:lvgl:fixes-9.5.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants