Skip to content

feat(display): allocate the draw buffers aligned to LV_DRAW_BUF_ALIGN - #916

Merged
finger563 merged 1 commit into
mainfrom
feat/display-aligned-draw-buffers
Nov 20, 2026
Merged

finger563 merged 1 commit into
mainfrom
feat/display-aligned-draw-buffers

Conversation

@finger563

Copy link
Copy Markdown
Contributor

What

espp::Display allocates its draw buffers (DynamicMemoryConfig) aligned to LV_DRAW_BUF_ALIGN:

  • heap_caps_aligned_alloc() at the new vram_alignment() (LV_DRAW_BUF_ALIGN, at least a pointer's size).
  • Each buffer's size is rounded up to a multiple of that alignment, so no other allocation shares its last cache line (DMA engines and cache syncs work in whole lines).
  • The destructor frees them with heap_caps_free().

A StaticMemoryConfig buffer that is not aligned is now logged as an error, instead of the display silently drawing nothing. The README notes the requirement.

Why

LVGL's lv_display_set_buffers() refuses buffers that are not aligned to LV_DRAW_BUF_ALIGN (LV_CHECK_ARG in lv_display.c), and the display then draws nothing. LVGL's PPA draw unit on the ESP32-P4 (LV_USE_PPA) requires LV_DRAW_BUF_ALIGN to equal the data cache line size (128; its private header refuses to compile otherwise). heap_caps_malloc() gives no such alignment, so any BSP that lets Display allocate its buffers could not use the PPA draw unit.

With the default LV_DRAW_BUF_ALIGN (4) the allocation is the same as before, rounded to 4 bytes.

Test

On an M5Stack Tab5 (ESP32-P4, ESP-IDF 6.1, LVGL 9.6.0), in an application whose BSP (M5StackTab5::initialize_display()) lets Display allocate two 184 KB draw buffers in PSRAM, built with LV_DRAW_BUF_ALIGN=128:

  • With LV_USE_PPA on and with it off, the UI draws: six scripted 20 s scroll runs of a 1280 x 720 launcher, with screenshots checked.
  • LV_DRAW_BUF_ALIGN=4 (the default) was not run on hardware with this branch; it takes the same code path with a 4-byte alignment.
  • clang-format pre-commit hook passes.

The Tab5 BSP change that goes with the PPA draw unit (its flush rotation) is a separate PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY

LVGL's lv_display_set_buffers() refuses buffers that are not aligned to
LV_DRAW_BUF_ALIGN, and the display then draws nothing. Display allocated its
draw buffers with plain heap_caps_malloc(), so raising LV_DRAW_BUF_ALIGN (LVGL's
PPA draw unit on the ESP32-P4 requires the data cache line size, 128) broke
every board whose BSP lets Display allocate them.

- The DynamicMemoryConfig buffers come from heap_caps_aligned_alloc() at
  vram_alignment() (LV_DRAW_BUF_ALIGN, at least a pointer), their size
  rounded up to a multiple of it, so no other allocation shares their last
  cache line.
- A StaticMemoryConfig buffer that is not aligned is logged as an error
  instead of failing silently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY
@github-actions

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

@finger563
finger563 merged commit d9ce00d into main Nov 20, 2026
183 checks passed
@finger563
finger563 deleted the feat/display-aligned-draw-buffers branch November 20, 2026 18:51
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.

1 participant