feat(examples): Update BSP examples which have a display to use a gui class for clearer / more useful example code to start from#663
Merged
Conversation
… class for clearer / more useful example code to start from
|
✅Static analysis result - no issues found! ✅ |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors multiple ESPP BSP display examples to move LVGL UI creation, event dispatch, and LVGL task ownership into per-example Gui classes (example/main/gui.hpp + gui.cpp), leaving app_main focused on board/peripheral initialization and high-level UI interactions.
Changes:
- Introduces per-example
Guiclasses that encapsulate LVGL objects, a guardedlv_task_handler()pump task, and centralized LVGL event trampolines. - Updates example
app_mainimplementations to call into theGuiAPI instead of managing ad-hoc statics/lambdas and LVGL locking. - Fixes a BSP build warning/error for
m5stack-tab5by adding the missing designated initializer field.
Reviewed changes
Copilot reviewed 40 out of 40 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| components/ws-s3-touch/example/main/gui.hpp | New Gui API for ws-s3-touch (labels, buttons, gravity lines, circle layer). |
| components/ws-s3-touch/example/main/gui.cpp | Implements ws-s3-touch GUI setup, LVGL task loop, event dispatch, circle drawing. |
| components/ws-s3-lcd-1-47/example/main/ws_s3_lcd_1_47_example.cpp | Refactors example main to use Gui instead of static LVGL helpers. |
| components/ws-s3-lcd-1-47/example/main/gui.hpp | New Gui API for ws-s3-lcd-1-47 (label + circle layer + rotation). |
| components/ws-s3-lcd-1-47/example/main/gui.cpp | Implements ws-s3-lcd-1-47 GUI and LVGL update task. |
| components/ws-s3-geek/example/main/ws_s3_geek_example.cpp | Refactors ws-s3-geek example main to use Gui. |
| components/ws-s3-geek/example/main/gui.hpp | New Gui API for ws-s3-geek. |
| components/ws-s3-geek/example/main/gui.cpp | Implements ws-s3-geek GUI and LVGL update task. |
| components/wrover-kit/example/main/wrover_kit_example.cpp | Refactors wrover-kit example main to use Gui. |
| components/wrover-kit/example/main/gui.hpp | New Gui API for wrover-kit. |
| components/wrover-kit/example/main/gui.cpp | Implements wrover-kit GUI and LVGL update task. |
| components/t-dongle-s3/example/main/t_dongle_s3_example.cpp | Refactors t-dongle-s3 example main to use Gui. |
| components/t-dongle-s3/example/main/gui.hpp | New Gui API for t-dongle-s3. |
| components/t-dongle-s3/example/main/gui.cpp | Implements t-dongle-s3 GUI and LVGL update task. |
| components/t-deck/example/main/gui.hpp | New Gui API for t-deck (buttons + circle layer). |
| components/t-deck/example/main/gui.cpp | Implements t-deck GUI, event dispatch, and circle drawing. |
| components/smartpanlee-sc01-plus/example/main/smartpanlee_sc01_plus_example.cpp | Refactors SmartPanlee example main to use Gui and thread-safe UI calls from touch callback. |
| components/smartpanlee-sc01-plus/example/main/gui.hpp | New Gui API for SmartPanlee (label + buttons + circle layer). |
| components/smartpanlee-sc01-plus/example/main/gui.cpp | Implements SmartPanlee GUI layout + event dispatch + circle drawing. |
| components/seeed-studio-round-display/example/main/seeed_studio_round_display_example.cpp | Refactors round-display example main to use Gui. |
| components/seeed-studio-round-display/example/main/gui.hpp | New Gui API for round-display. |
| components/seeed-studio-round-display/example/main/gui.cpp | Implements round-display GUI, layout updates, and event dispatch. |
| components/matouch-rotary-display/example/main/matouch_rotary_display_example.cpp | Refactors matouch rotary display example main to use Gui. |
| components/matouch-rotary-display/example/main/gui.hpp | New Gui API for matouch rotary display. |
| components/matouch-rotary-display/example/main/gui.cpp | Implements matouch rotary display GUI, event dispatch, and circle drawing. |
| components/m5stack-tab5/src/touchpad.cpp | Adds missing designated initializer field (.write_then_read) to satisfy -Wmissing-field-initializers. |
| components/m5stack-tab5/example/main/gui.hpp | New Gui API for tab5 (gravity lines + brightness cycling + buttons). |
| components/m5stack-tab5/example/main/gui.cpp | Implements tab5 GUI, gravity line updates, and brightness cycling. |
| components/esp32-p4-function-ev-board/example/main/gui.hpp | New Gui API for P4 EV board (title + status + buttons + circles). |
| components/esp32-p4-function-ev-board/example/main/gui.cpp | Implements P4 EV board GUI, event dispatch, and circle drawing. |
| components/esp32-p4-function-ev-board/example/main/esp32_p4_function_ev_board_example.cpp | Refactors P4 EV board example main to use Gui for status and touch-to-draw. |
| components/esp-box/example/main/gui.hpp | New Gui API for esp-box (gravity lines + buttons + circles). |
| components/esp-box/example/main/gui.cpp | Implements esp-box GUI and gravity line vector remapping. |
| components/byte90/example/main/gui.hpp | New Gui API for byte90 (label + circles + rotation). |
| components/byte90/example/main/gui.cpp | Implements byte90 GUI and circle drawing. |
| components/byte90/example/main/byte90_example.cpp | Refactors byte90 example main to use Gui. |
…tability - Add <cmath> (and <numbers>) where math functions were used via transitive includes; replace non-standard M_PI with std::numbers::pi_v<float> and bare cos/sin with std::cos/std::sin in the circle-drawing examples - Add <utility> where std::swap was used via transitive includes Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Refactors all 13 BSP display examples (
esp-box,t-deck,wrover-kit,matouch-rotary-display,seeed-studio-round-display,byte90,ws-s3-lcd-1-47,ws-s3-touch,ws-s3-geek,smartpanlee-sc01-plus,t-dongle-s3,m5stack-tab5,esp32-p4-function-ev-board) so that all LVGLUI code lives in a per-example
Guiclass (example/main/gui.hpp+gui.cpp) instead of ad-hoc statics and lambdas inapp_main.Each
Guiclass follows the same canonical pattern (modeled on theGui/Menucomponents in esp-box-emu,without the squareline-generated code):
std::recursive_mutexguarding every LVGL call and anespp::Taskwhich pumps
lv_task_handler()every 16 ms.init_ui()is broken into small member functions, one per logical piece ofthe UI (
init_background(),init_label(),init_buttons(),init_circle_layer(), ...).thisas user-data and dispatchedthrough a single static trampoline (
event_callback) into member handlers.thread-safe, doxygen-documented methods (
set_label_text(),draw_circle(),clear_circles(),next_rotation(), plus board-specificones such as
set_kalman_down()/set_madgwick_down(),set_clock_text(),set_status_text(),cycle_brightness()).The
app_mains now contain only board/peripheral init and calls into theGui(−2,999 / +410 lines across the 14 modified example mains). The doxygen//! [<name> example]snippet markers are unchanged, so the rendered docs nowshow the much cleaner
app_mainusage.Behavior is preserved everywhere (touch-to-draw circles, rotation, keyboard /
encoder / hardware-button handling, IMU gravity lines, RTC clock, LED
animation tasks, audio clicks, networking/RTPS status on the P4 board), with
a few improvements:
LV_SYMBOL_TRASHclear buttonnext to the existing rotate button, exercising multi-button event dispatch
through the trampoline.
percent-based (0–100)
brightness()API — which effectively blanked thescreen — and added an on-screen brightness button; both now cycle
25/50/75/100% through a shared
Gui::cycle_brightness().-Werror=missing-field-initializers(missing.write_then_readdesignatedinitializer in
src/touchpad.cpp).Motivation and Context
The display examples had grown into large
app_mainfunctions full of staticglobals, free functions, and lambdas sharing a hand-rolled LVGL mutex — nearly
identical boilerplate duplicated 13 times, and not a good template for users
to build real UIs from. Encapsulating the UI in a
Guiclass gives users acopyable, idiomatic starting point for structuring C++ LVGL applications on
top of the espp BSPs (thread-safety, event dispatch, and update-task ownership
all handled in one place), and makes the examples themselves shorter and
easier to follow.
How has this been tested?
rm -rf build && idf.py build) withESP-IDF v6.0.1 across their respective targets (esp32, esp32s3, esp32p4);
13/13 pass.
lv_*calls remain in any exampleapp_main.initialize_*call from the original examples ispreserved in the refactored ones.
documentation still renders the example code.
.clang-format.re-verified on hardware.
Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):
N/A — no visual changes beyond the added clear/brightness buttons.
Types of changes
Checklist:
Software
.github/workflows/build.ymlfile to add my new test to the automated cloud build github action.