xtensa/esp32s3: refactor cam driver to use cam_ll HAL layer#18703
xtensa/esp32s3: refactor cam driver to use cam_ll HAL layer#18703xiaoxiang781216 merged 1 commit intoapache:masterfrom
Conversation
Replace direct putreg32/getreg32 register accesses in esp32s3_cam.c with cam_ll_* inline functions from Espressif's esp_hal_cam component. This reduces maintenance burden by using the vendor-provided HAL abstraction instead of raw register manipulation. Changes: - Add lcd_cam_dev_t *hw pointer to driver struct - Use cam_ll_start/stop/reset/fifo_reset for CAM control - Use cam_ll_get_interrupt_status/clear_interrupt_status for ISR - Use cam_ll_set_recv_data_bytelen for DMA buffer length - Use cam_ll_select_clk_src/set_group_clock_coeff for clock config - Use cam_ll_enable_vsync_filter/set_vsync_filter_thres - Use cam_ll_enable_vsync_generate_eof/enable_rgb_yuv_convert - Use struct access for interrupt enable (cam_ll_enable_interrupt requires __DECLARE_RCC_ATOMIC_ENV not available in NuttX) - Add esp_hal_cam include paths to hal.mk Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
|
Looks clearer a lot, nice work. |
|
@eren-terzioglu Thanks again for the suggestion — I've been refactoring the ESP32-S3 CAM driver to use the During testing I found a bug in The current code writes dev->cam_ctrl.cam_update = 1;
dev->cam_ctrl1.cam_start = 1;
The fix is to swap the order — set dev->cam_ctrl1.cam_start = 1;
dev->cam_ctrl.cam_update = 1;Does $ git show
commit 44ec73727cb0bfefb587246d48095c662e372fd4 (HEAD)
Author: wangjianyu3 <wangjianyu3@xiaomi.com>
Date: Fri Apr 10 18:14:30 2026 +0800
hal/cam_ll: fix cam_ll_start register write order
cam_update is a self-clearing latch that captures the current value of
cam_start. Writing cam_update before cam_start means the latch fires
while cam_start is still 0, so the CAM never actually starts on the
first call — it only works if a previous start left cam_start high.
Swap the order: set cam_start=1 first, then trigger cam_update to latch
it. This matches the hardware intent documented in the TRM.
Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
diff --git a/components/esp_hal_cam/esp32s3/include/hal/cam_ll.h b/components/esp_hal_cam/esp32s3/include/hal/cam_ll.h
index 2b58c45f76f..9f6619cf3dd 100644
--- a/components/esp_hal_cam/esp32s3/include/hal/cam_ll.h
+++ b/components/esp_hal_cam/esp32s3/include/hal/cam_ll.h
@@ -443,8 +443,8 @@ static inline void cam_ll_set_data_wire_width(lcd_cam_dev_t *dev, uint32_t width
__attribute__((always_inline))
static inline void cam_ll_start(lcd_cam_dev_t *dev)
{
- dev->cam_ctrl.cam_update = 1;
dev->cam_ctrl1.cam_start = 1;
+ dev->cam_ctrl.cam_update = 1; // self clear, latches cam_start=1
}
/** |
It is fine to open there but we have to ask it into |
Summary
As suggested by @eren-terzioglu in #18692 (comment),
refactor the ESP32-S3 CAM driver to use Espressif's
cam_ll_*HAL abstractionlayer instead of direct
putreg32/getreg32register manipulation.Replace all raw register accesses in
esp32s3_cam.cwithcam_ll_*inlinefunctions from the
esp_hal_camcomponent inesp-hal-3rdparty. This reducesmaintenance burden and aligns with Espressif's recommended driver architecture.
Changes:
lcd_cam_dev_t *hwpointer to the driver private structcam_ll_start/stop/reset/fifo_resetfor CAM controlcam_ll_get_interrupt_status/clear_interrupt_statusfor ISR handlingcam_ll_set_recv_data_bytelenfor DMA buffer length configurationcam_ll_select_clk_src/set_group_clock_coefffor clock setupcam_ll_enable_vsync_filter/set_vsync_filter_thresfor VSYNC filteringcam_ll_enable_vsync_generate_eof/enable_rgb_yuv_convertfor capture configcam_ll_enable_interruptrequires
__DECLARE_RCC_ATOMIC_ENVwhich is not available in NuttX)esp_hal_caminclude paths tohal.mkNet result: 68 insertions, 155 deletions — eliminates all
putreg32/getreg32calls from the CAM driver.
Impact
access method changes from raw addresses to the vendor HAL layer.
arch/xtensa/src/esp32s3/esp32s3_cam.candhal.mk.Testing
Host: Ubuntu 22.04 x86_64, xtensa-esp32s3-elf-gcc
Target: ESP32-S3 (lckfb-szpi-esp32s3, ESP32-S3-WROOM-1-N16R8, PSRAM 8MB OCT)
with GC0308 DVP camera and ST7789 LCD
Build and flash:
Runtime test — continuous preview:
Runtime test — mirrored preview:
Verified:
-m) works correctly