2626#include "../../dvp_share_ctrl.h"
2727
2828#ifdef CONFIG_CAM_CTLR_DVP_CAM_ISR_CACHE_SAFE
29- #define CAM_DVP_MEM_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
29+ #define DVP_CAM_CTLR_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT)
3030#else
31- #define CAM_DVP_MEM_ALLOC_CAPS (MALLOC_CAP_DEFAULT)
31+ #define DVP_CAM_CTLR_ALLOC_CAPS (MALLOC_CAP_DEFAULT)
3232#endif
3333
34- #define ALIGN_UP_BY (num , align ) (((num) + ((align) - 1)) & ~((align) - 1))
34+ #if CONFIG_SPIRAM
35+ #define DVP_CAM_BK_BUFFER_ALLOC_CAPS (MALLOC_CAP_SPIRAM | MALLOC_CAP_DMA)
36+ #else
37+ #define DVP_CAM_BK_BUFFER_ALLOC_CAPS (MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA)
38+ #endif
39+
40+ #if SOC_PERIPH_CLK_CTRL_SHARED
41+ #define DVP_CAM_CLK_ATOMIC () PERIPH_RCC_ATOMIC()
42+ #else
43+ #define DVP_CAM_CLK_ATOMIC ()
44+ #endif
45+
46+ #define ALIGN_UP_BY (num , align ) ((align) == 0 ? (num) : (((num) + ((align) - 1)) & ~((align) - 1)))
3547
3648#define DVP_CAM_CONFIG_INPUT_PIN (pin , sig , inv ) \
3749{ \
@@ -209,7 +221,6 @@ static uint32_t IRAM_ATTR esp_cam_ctlr_dvp_get_jpeg_size(const uint8_t *buffer,
209221 */
210222static uint32_t IRAM_ATTR esp_cam_ctlr_dvp_get_recved_size (esp_cam_ctlr_dvp_cam_t * ctlr , uint8_t * rx_buffer , uint32_t dma_recv_size )
211223{
212- esp_err_t ret ;
213224 uint32_t recv_buffer_size ;
214225
215226 if (ctlr -> pic_format_jpeg ) {
@@ -218,8 +229,10 @@ static uint32_t IRAM_ATTR esp_cam_ctlr_dvp_get_recved_size(esp_cam_ctlr_dvp_cam_
218229 recv_buffer_size = ctlr -> fb_size_in_bytes ;
219230 }
220231
221- ret = esp_cache_msync (rx_buffer , recv_buffer_size , ESP_CACHE_MSYNC_FLAG_DIR_M2C );
222- assert (ret == ESP_OK );
232+ if (esp_ptr_external_ram (rx_buffer )) {
233+ esp_err_t ret = esp_cache_msync (rx_buffer , recv_buffer_size , ESP_CACHE_MSYNC_FLAG_DIR_M2C );
234+ assert (ret == ESP_OK );
235+ }
223236
224237 if (ctlr -> pic_format_jpeg ) {
225238 recv_buffer_size = esp_cam_ctlr_dvp_get_jpeg_size (rx_buffer , dma_recv_size );
@@ -336,7 +349,7 @@ esp_err_t esp_cam_ctlr_dvp_init(int ctlr_id, cam_clock_source_t clk_src, const e
336349 }
337350
338351 ESP_ERROR_CHECK (esp_clk_tree_enable_src ((soc_module_clk_t )clk_src , true));
339- PERIPH_RCC_ATOMIC () {
352+ DVP_CAM_CLK_ATOMIC () {
340353 cam_ll_enable_clk (ctlr_id , true);
341354 cam_ll_select_clk_src (ctlr_id , clk_src );
342355 };
@@ -367,7 +380,7 @@ esp_err_t esp_cam_ctlr_dvp_output_clock(int ctlr_id, cam_clock_source_t clk_src,
367380 ESP_LOGD (TAG , "DVP clock source frequency %" PRIu32 "Hz" , src_clk_hz );
368381
369382 if ((src_clk_hz % xclk_freq ) == 0 ) {
370- PERIPH_RCC_ATOMIC () {
383+ DVP_CAM_CLK_ATOMIC () {
371384 cam_ll_set_group_clock_coeff (ctlr_id , src_clk_hz / xclk_freq , 0 , 0 );
372385 };
373386
@@ -390,7 +403,7 @@ esp_err_t esp_cam_ctlr_dvp_deinit(int ctlr_id)
390403{
391404 ESP_RETURN_ON_FALSE (ctlr_id < CAP_DVP_PERIPH_NUM , ESP_ERR_INVALID_ARG , TAG , "invalid argument: ctlr_id >= %d" , CAP_DVP_PERIPH_NUM );
392405
393- PERIPH_RCC_ATOMIC () {
406+ DVP_CAM_CLK_ATOMIC () {
394407 cam_ll_enable_clk (ctlr_id , false);
395408 };
396409
@@ -710,19 +723,19 @@ esp_err_t esp_cam_new_dvp_ctlr(const esp_cam_ctlr_dvp_config_t *config, esp_cam_
710723 ESP_RETURN_ON_FALSE (config -> external_xtal || config -> pin_dont_init || config -> pin -> xclk_io != GPIO_NUM_NC , ESP_ERR_INVALID_ARG , TAG , "invalid argument: xclk_io is not set" );
711724 ESP_RETURN_ON_FALSE (config -> external_xtal || config -> xclk_freq , ESP_ERR_INVALID_ARG , TAG , "invalid argument: xclk_freq is not set" );
712725
713- ESP_RETURN_ON_ERROR (esp_cache_get_alignment (MALLOC_CAP_SPIRAM | MALLOC_CAP_DMA , & alignment_size ), TAG , "failed to get cache alignment" );
726+ ESP_RETURN_ON_ERROR (esp_cache_get_alignment (DVP_CAM_BK_BUFFER_ALLOC_CAPS , & alignment_size ), TAG , "failed to get cache alignment" );
714727 ESP_RETURN_ON_ERROR (esp_cam_ctlr_dvp_cam_get_frame_size (config , & fb_size_in_bytes ), TAG , "invalid argument: input frame pixel format is not supported" );
715728 ESP_RETURN_ON_ERROR (dvp_shared_ctrl_claim_io_signals (), TAG , "failed to claim io signals" );
716729
717- esp_cam_ctlr_dvp_cam_t * ctlr = heap_caps_calloc (1 , sizeof (esp_cam_ctlr_dvp_cam_t ), CAM_DVP_MEM_ALLOC_CAPS );
730+ esp_cam_ctlr_dvp_cam_t * ctlr = heap_caps_calloc (1 , sizeof (esp_cam_ctlr_dvp_cam_t ), DVP_CAM_CTLR_ALLOC_CAPS );
718731 ESP_GOTO_ON_FALSE (ctlr , ESP_ERR_NO_MEM , fail0 , TAG , "no mem for CAM DVP controller context" );
719732
720733 ESP_GOTO_ON_ERROR (s_dvp_claim_ctlr (config -> ctlr_id , ctlr ), fail1 , TAG , "no available DVP controller" );
721734
722735 ESP_LOGD (TAG , "alignment: 0x%x\n" , alignment_size );
723736 fb_size_in_bytes = ALIGN_UP_BY (fb_size_in_bytes , alignment_size );
724737 if (!config -> bk_buffer_dis ) {
725- ctlr -> backup_buffer = heap_caps_aligned_alloc (alignment_size , fb_size_in_bytes , MALLOC_CAP_SPIRAM );
738+ ctlr -> backup_buffer = heap_caps_aligned_alloc (alignment_size , fb_size_in_bytes , DVP_CAM_BK_BUFFER_ALLOC_CAPS );
726739 ESP_GOTO_ON_FALSE (ctlr -> backup_buffer , ESP_ERR_NO_MEM , fail2 , TAG , "no mem for DVP backup buffer" );
727740 }
728741
0 commit comments