diff options
| author | Luke Hoersten <[email protected]> | 2026-06-13 22:48:48 -0500 |
|---|---|---|
| committer | Luke Hoersten <[email protected]> | 2026-06-13 22:48:48 -0500 |
| commit | 6cbdd4ed7466da28e524c9e0804722428a4b9698 (patch) | |
| tree | 90df296bf9df9ec4be0ad22267fcea51df92fc93 /main/display.c | |
| parent | e7feac61e5ea275f303574fedd942ebed8fc8e73 (diff) | |
M5: POST /frame — hardware JPEG decode + orientation-aware paint
jpeg_decoder.{h,c} wraps esp_driver_jpeg (ESP32-P4 hardware decoder).
- One-time engine + DMA-aligned PSRAM scratch buffer setup (1 MB input,
768 KB output @ panel native 800x480 RGB565).
- try_lock + unlock so concurrent /frame POSTs get 503 instead of
queueing, per spec.
- jpeg_decoder_get_info() reports the dimensions; the http handler
validates them against the effective resolution before painting.
display.h adds display_present_rgb565(src, w, h):
- Landscape: src is 800x480, memcpy 1:1 into the panel framebuffer.
- Portrait: src is 480x800, software rotate 90° CW into the 800x480
panel framebuffer. (PPA / 2D-DMA hardware rotation is a later
optimization if portrait latency matters.)
http_api.c adds POST /frame:
- Content-Type must be image/jpeg → else 400.
- Empty body → 400. > 1 MB → 413. Display not initialized → 500.
- jpeg_decoder_try_lock(0) for concurrency: second post returns 503.
- Body streamed into the decoder's input buffer in chunks.
- Decode failure or dimension mismatch → 400 + decode_errors++.
- Paint failure → 500.
- Success → frames_received++, last_frame_us = esp_timer_get_time(),
204 No Content.
app_main initializes the JPEG decoder after display_init(). Both are
best-effort: failures log a warning and leave the rest of the firmware
running.
CMakeLists.txt: add esp_driver_jpeg to REQUIRES.
Known gap (M6 closes it): /frame currently paints regardless of
wake/sleep state. The 409-when-asleep rule lands with POST /state
in M6.
Build clean against ESP-IDF 5.4 (binary ~640 KB).
TESTING.md M5 expanded with portrait/landscape test commands,
ImageMagick test-image recipes, the full negative matrix (wrong
Content-Type, oversize, wrong dims, concurrent, garbage), and the
M6 dependency note.
Diffstat (limited to 'main/display.c')
| -rw-r--r-- | main/display.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/main/display.c b/main/display.c index a1a64fd..21e8e5e 100644 --- a/main/display.c +++ b/main/display.c @@ -249,6 +249,44 @@ esp_err_t display_fill(uint16_t rgb565) PANEL_H_ACTIVE, PANEL_V_ACTIVE, fb); } +esp_err_t display_present_rgb565(const uint16_t *src, + uint16_t src_w, + uint16_t src_h) +{ + if (!s_up) return ESP_ERR_INVALID_STATE; + + viewport_state_lock(); + viewport_orientation_t orient = viewport_state_get()->orientation; + viewport_state_unlock(); + + void *fb = NULL; + esp_err_t err = esp_lcd_dpi_panel_get_frame_buffer(s_panel, 1, &fb); + if (err != ESP_OK) return err; + uint16_t *dst = (uint16_t *)fb; + + if (orient == VIEWPORT_ORIENTATION_LANDSCAPE) { + if (src_w != PANEL_H_ACTIVE || src_h != PANEL_V_ACTIVE) + return ESP_ERR_INVALID_SIZE; + memcpy(dst, src, (size_t)src_w * src_h * sizeof(uint16_t)); + } else { + // Portrait: src is 480x800, rotate 90° CW into the 800x480 panel. + // dst dims = src_h x src_w. dst_stride = src_h. + // src(x,y) -> dst(x, src_h - 1 - y) + if (src_w != PANEL_V_ACTIVE || src_h != PANEL_H_ACTIVE) + return ESP_ERR_INVALID_SIZE; + const uint16_t dst_stride = src_h; + for (uint16_t y = 0; y < src_h; ++y) { + const uint16_t *srow = src + (size_t)y * src_w; + const uint16_t dst_col = (uint16_t)(src_h - 1 - y); + for (uint16_t x = 0; x < src_w; ++x) { + dst[(size_t)x * dst_stride + dst_col] = srow[x]; + } + } + } + return esp_lcd_panel_draw_bitmap(s_panel, 0, 0, + PANEL_H_ACTIVE, PANEL_V_ACTIVE, fb); +} + esp_err_t display_test_pattern(void) { if (!s_up) return ESP_ERR_INVALID_STATE; |
