|
16 | 16 | #include <string.h> |
17 | 17 | #include <stdalign.h> |
18 | 18 | #include "esp_heap_caps.h" |
| 19 | +#include "freertos/FreeRTOS.h" |
19 | 20 | #include "ll_cam.h" |
20 | 21 | #include "cam_hal.h" |
21 | 22 |
|
|
41 | 42 |
|
42 | 43 | static const char *TAG = "cam_hal"; |
43 | 44 | static cam_obj_t *cam_obj = NULL; |
| 45 | +#if defined(CONFIG_CAMERA_PSRAM_DMA) |
| 46 | +#define CAMERA_PSRAM_DMA_ENABLED CONFIG_CAMERA_PSRAM_DMA |
| 47 | +#else |
| 48 | +#define CAMERA_PSRAM_DMA_ENABLED 0 |
| 49 | +#endif |
| 50 | + |
| 51 | +static volatile bool g_psram_dma_mode = CAMERA_PSRAM_DMA_ENABLED; |
| 52 | +static portMUX_TYPE g_psram_dma_lock = portMUX_INITIALIZER_UNLOCKED; |
44 | 53 |
|
45 | 54 | /* At top of cam_hal.c – one switch for noisy ISR prints */ |
46 | 55 | #ifndef CAM_LOG_SPAM_EVERY_FRAME |
@@ -411,11 +420,12 @@ esp_err_t cam_config(const camera_config_t *config, framesize_t frame_size, uint |
411 | 420 | CAM_CHECK_GOTO(ret == ESP_OK, "ll_cam_set_sample_mode failed", err); |
412 | 421 |
|
413 | 422 | cam_obj->jpeg_mode = config->pixel_format == PIXFORMAT_JPEG; |
414 | | -#if CONFIG_IDF_TARGET_ESP32 |
415 | | - cam_obj->psram_mode = false; |
| 423 | +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 |
| 424 | + cam_obj->psram_mode = g_psram_dma_mode; |
416 | 425 | #else |
417 | | - cam_obj->psram_mode = (config->xclk_freq_hz == 16000000); |
| 426 | + cam_obj->psram_mode = false; |
418 | 427 | #endif |
| 428 | + ESP_LOGI(TAG, "PSRAM DMA mode %s", cam_obj->psram_mode ? "enabled" : "disabled"); |
419 | 429 | cam_obj->frame_cnt = config->fb_count; |
420 | 430 | cam_obj->width = resolution[frame_size].width; |
421 | 431 | cam_obj->height = resolution[frame_size].height; |
@@ -612,3 +622,15 @@ bool cam_get_available_frames(void) |
612 | 622 | { |
613 | 623 | return 0 < uxQueueMessagesWaiting(cam_obj->frame_buffer_queue); |
614 | 624 | } |
| 625 | + |
| 626 | +void cam_set_psram_mode(bool enable) |
| 627 | +{ |
| 628 | + portENTER_CRITICAL(&g_psram_dma_lock); |
| 629 | + g_psram_dma_mode = enable; |
| 630 | + portEXIT_CRITICAL(&g_psram_dma_lock); |
| 631 | +} |
| 632 | + |
| 633 | +bool cam_get_psram_mode(void) |
| 634 | +{ |
| 635 | + return g_psram_dma_mode; |
| 636 | +} |
0 commit comments