|
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 |
@@ -418,11 +427,12 @@ esp_err_t cam_config(const camera_config_t *config, framesize_t frame_size, uint |
418 | 427 | CAM_CHECK_GOTO(ret == ESP_OK, "ll_cam_set_sample_mode failed", err); |
419 | 428 |
|
420 | 429 | cam_obj->jpeg_mode = config->pixel_format == PIXFORMAT_JPEG; |
421 | | -#if CONFIG_IDF_TARGET_ESP32 |
422 | | - cam_obj->psram_mode = false; |
| 430 | +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 |
| 431 | + cam_obj->psram_mode = g_psram_dma_mode; |
423 | 432 | #else |
424 | | - cam_obj->psram_mode = (config->xclk_freq_hz == 16000000); |
| 433 | + cam_obj->psram_mode = false; |
425 | 434 | #endif |
| 435 | + ESP_LOGI(TAG, "PSRAM DMA mode %s", cam_obj->psram_mode ? "enabled" : "disabled"); |
426 | 436 | cam_obj->frame_cnt = config->fb_count; |
427 | 437 | cam_obj->width = resolution[frame_size].width; |
428 | 438 | cam_obj->height = resolution[frame_size].height; |
@@ -619,3 +629,15 @@ bool cam_get_available_frames(void) |
619 | 629 | { |
620 | 630 | return 0 < uxQueueMessagesWaiting(cam_obj->frame_buffer_queue); |
621 | 631 | } |
| 632 | + |
| 633 | +void cam_set_psram_mode(bool enable) |
| 634 | +{ |
| 635 | + portENTER_CRITICAL(&g_psram_dma_lock); |
| 636 | + g_psram_dma_mode = enable; |
| 637 | + portEXIT_CRITICAL(&g_psram_dma_lock); |
| 638 | +} |
| 639 | + |
| 640 | +bool cam_get_psram_mode(void) |
| 641 | +{ |
| 642 | + return g_psram_dma_mode; |
| 643 | +} |
0 commit comments