Page 1 of 1

ESP32-P4 MIPI double-buffering - can't work out how to swap buffers

Posted: Fri Jun 26, 2026 6:35 pm
by mikeselectricstuff
I'm working on a simple project which is basically loading and displaying images from an SD card to a MIPI LCD.
Not using LVGL, just throwing raw image data around.
Using IDF V5.5.4 ( as that was the example I started with used), Waveshare 3.4" round LCD board, with their BSP, configuration set for 2 buffers
I have pretty much everything working, loading the image data into memory and then using memcpy to copy to the active display buffer, which works, but not cleanly due to the time taken to do the copy.

But I'm now stuck figuring out how to do this properly with double-buffering, specifically

1) How to find which buffer is currently feeding the active display
2) How to make the display swap to the second buffer after I've loaded a new image .
i.e. the steps marked ** below

Use esp_lcd_dpi_panel_get_frame_buffer to get the buffer addresses
** determine which buffer is currently being displayed
Load image from SD card into the non-display buffer
Use esp_cache_msync to ensure it's all flushed from the cache
Set a flag to my "on_vsync" callback to do the swap on the next sync
** within my vsync callback, make the display to start displaying the other buffer

I'm sure there must be a simple answer, I just can't seem to find it!

Re: ESP32-P4 MIPI double-buffering - can't work out how to swap buffers

Posted: Sat Jun 27, 2026 12:00 am
by Sprite
First of all, I don't think there's a way to figure out which framebuffer is displayed; the way I solve it is to maintain that info myself. Secondly, the way you switch to one of the framebuffers is a bit odd: you use esp_lcd_panel_draw_bitmap with the framebuffer address; that routine will notice it's a framebuffer rather than a normal buffer and switch rather than draw. See e.g. here for an example.

Re: ESP32-P4 MIPI double-buffering - can't work out how to swap buffers

Posted: Sat Jun 27, 2026 9:05 am
by mikeselectricstuff
Thanks - I saw a reference to Draw_Bitmap, but thought this was in the context of flushing a screen buffer to a SPI type display with its own memory.
Would be helpful if the DSI display documentation had mentioned this, as it's far from obvious!