From 3f53ced44ea112a39eec70216c8c72fa6867726e Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Mon, 15 Jun 2026 07:50:23 -0500 Subject: firmware: double-buffer the panel + zero-copy decode → ~22 fps ceiling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Per-frame paint cost drops from ~24 ms to ~45 µs (≈500× faster) by enabling num_fbs=2 on the DPI panel and decoding straight into the back framebuffer. Measured on the bench: before: lock=7us ttfb=370us body=40ms dec=6ms paint=24ms post=35us = ~70ms / ~14fps after : lock=7us ttfb=330us body=38ms dec=6ms paint=42us post=25us = ~45ms / ~22fps How the win actually lands: - num_fbs=2 in the esp_lcd_dpi_panel_config_t makes the IDF driver allocate two framebuffers and stream from one while we fill the other. - display_back_buffer() returns the inactive fb pointer + its size. - jpeg_decoder_decode() now accepts a caller-provided destination buffer instead of owning its own scratch. http_api passes the panel back-fb so the hardware JPEG decoder writes BGR888 pixels straight into where the DSI will eventually scan from. Zero memcpy in the hot path. - display_flip_back_buffer() calls esp_lcd_panel_draw_bitmap with the fb pointer. Because the buffer is inside the panel's own fb range, the IDF driver skips its memcpy and just does a cache writeback + swaps cur_fb_index. The actual flip happens on the next vsync, asynchronously — the call returns in microseconds. The remaining ceiling is network body time (~38 ms for ~210 KB JPEGs) and the hardware decoder (~6 ms). Per-viewport JPEG quality (smaller files = shorter body) is the next lever; everything firmware-side is already at or near floor. Also drop the old static jpeg output scratch + JPEG_DECODER_MAX_OUTPUT_BYTES constant — nothing references them anymore. --- main/http_api.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'main/http_api.c') diff --git a/main/http_api.c b/main/http_api.c index c87b8dc..447cb52 100644 --- a/main/http_api.c +++ b/main/http_api.c @@ -365,9 +365,13 @@ static esp_err_t frame_post_handler(httpd_req_t *req) int64_t t_recv = esp_timer_get_time(); - void *rgb = NULL; + // Decode straight into the panel's back framebuffer — no scratch + // buffer, no later memcpy. The flip below is a cache writeback + + // index swap inside the IDF DPI driver. + size_t back_size = 0; + void *back = display_back_buffer(&back_size); uint16_t w = 0, h = 0; - esp_err_t dec_err = jpeg_decoder_decode(got, &rgb, &w, &h); + esp_err_t dec_err = jpeg_decoder_decode(got, back, back_size, &w, &h); int64_t t_decode = esp_timer_get_time(); if (dec_err != ESP_OK) { viewport_state_lock(); @@ -392,7 +396,7 @@ static esp_err_t frame_post_handler(httpd_req_t *req) return respond_status(req, "400 Bad Request", msg); } - esp_err_t paint_err = display_present_bgr888(rgb); + esp_err_t paint_err = display_flip_back_buffer(); int64_t t_paint = esp_timer_get_time(); int64_t t_post = 0; if (paint_err != ESP_OK) { -- cgit v1.2.3