This is an automated email from the ASF dual-hosted git repository. simbit18 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 7c451141f5cd58615dd3b0a1edc06ffb964972ef Author: wangjianyu3 <[email protected]> AuthorDate: Tue Apr 7 10:19:50 2026 +0800 xtensa/esp32s3: cam driver support MMAP buffer allocation Implement imgdata_ops alloc/free callbacks so the V4L2 framework can use MMAP mode to allocate frame buffers with proper GDMA alignment. This lets applications avoid hardcoding platform- specific alignment values. - Add esp32s3_cam_alloc() using kmm_memalign with the alignment derived from the GDMA external memory block size setting. - Add esp32s3_cam_free() wrapper around kmm_free. - Introduce ESP32S3_CAM_EXT_MEMBLK / ESP32S3_CAM_DMA_ALIGN macros so the block size enum and byte alignment are defined in one place and stay in sync automatically. Signed-off-by: wangjianyu3 <[email protected]> --- arch/xtensa/src/esp32s3/esp32s3_cam.c | 49 +++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/arch/xtensa/src/esp32s3/esp32s3_cam.c b/arch/xtensa/src/esp32s3/esp32s3_cam.c index d76eb67e38e..b063da0b428 100644 --- a/arch/xtensa/src/esp32s3/esp32s3_cam.c +++ b/arch/xtensa/src/esp32s3/esp32s3_cam.c @@ -75,6 +75,21 @@ #define ESP32S3_CAM_VSYNC_FILTER 4 +/* GDMA external memory block size setting for PSRAM RX. + * Change this single macro to switch between 16B / 32B / 64B. + * ESP32S3_CAM_DMA_ALIGN is the byte alignment derived from it. + */ + +#define ESP32S3_CAM_EXT_MEMBLK ESP32S3_DMA_EXT_MEMBLK_64B + +#if ESP32S3_CAM_EXT_MEMBLK == ESP32S3_DMA_EXT_MEMBLK_64B +# define ESP32S3_CAM_DMA_ALIGN 64 +#elif ESP32S3_CAM_EXT_MEMBLK == ESP32S3_DMA_EXT_MEMBLK_32B +# define ESP32S3_CAM_DMA_ALIGN 32 +#else +# define ESP32S3_CAM_DMA_ALIGN 16 +#endif + /**************************************************************************** * Private Types ****************************************************************************/ @@ -128,6 +143,9 @@ static int esp32s3_cam_start_capture(struct imgdata_s *data, imgdata_capture_t callback, void *arg); static int esp32s3_cam_stop_capture(struct imgdata_s *data); +static void *esp32s3_cam_alloc(struct imgdata_s *data, + uint32_t align_size, uint32_t size); +static void esp32s3_cam_free(struct imgdata_s *data, void *addr); /**************************************************************************** * Private Data @@ -141,6 +159,8 @@ static const struct imgdata_ops_s g_cam_ops = .validate_frame_setting = esp32s3_cam_validate_frame_setting, .start_capture = esp32s3_cam_start_capture, .stop_capture = esp32s3_cam_stop_capture, + .alloc = esp32s3_cam_alloc, + .free = esp32s3_cam_free, }; static struct esp32s3_cam_s g_cam_priv = @@ -402,7 +422,7 @@ static int esp32s3_cam_dmasetup(struct esp32s3_cam_s *priv) esp32s3_dma_set_ext_memblk(priv->dma_channel, false, - ESP32S3_DMA_EXT_MEMBLK_64B); + ESP32S3_CAM_EXT_MEMBLK); return OK; } @@ -674,7 +694,7 @@ static int esp32s3_cam_set_buf(struct imgdata_s *data, */ priv->fb_size = priv->width * priv->height * 2; - priv->fb = kmm_memalign(64, priv->fb_size); + priv->fb = kmm_memalign(ESP32S3_CAM_DMA_ALIGN, priv->fb_size); if (!priv->fb) { snerr("ERROR: Failed to allocate frame buffer\n"); @@ -698,6 +718,31 @@ static int esp32s3_cam_set_buf(struct imgdata_s *data, return OK; } +/**************************************************************************** + * Name: esp32s3_cam_alloc + * + * Description: + * Allocate frame buffer memory with GDMA-required alignment. + * GDMA with EXT_MEMBLK_64B needs 64-byte aligned addresses + * for PSRAM access. + * + ****************************************************************************/ + +static void *esp32s3_cam_alloc(struct imgdata_s *data, + uint32_t align_size, uint32_t size) +{ + return kmm_memalign(ESP32S3_CAM_DMA_ALIGN, size); +} + +/**************************************************************************** + * Name: esp32s3_cam_free + ****************************************************************************/ + +static void esp32s3_cam_free(struct imgdata_s *data, void *addr) +{ + kmm_free(addr); +} + /**************************************************************************** * Name: esp32s3_cam_validate_frame_setting ****************************************************************************/
