|
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 | +static volatile bool g_psram_dma_mode = CONFIG_CAMERA_PSRAM_DMA; |
| 46 | +static portMUX_TYPE g_psram_dma_lock = portMUX_INITIALIZER_UNLOCKED; |
44 | 47 |
|
45 | 48 | /* At top of cam_hal.c – one switch for noisy ISR prints */ |
46 | 49 | #ifndef CAM_LOG_SPAM_EVERY_FRAME |
@@ -411,11 +414,12 @@ esp_err_t cam_config(const camera_config_t *config, framesize_t frame_size, uint |
411 | 414 | CAM_CHECK_GOTO(ret == ESP_OK, "ll_cam_set_sample_mode failed", err); |
412 | 415 |
|
413 | 416 | cam_obj->jpeg_mode = config->pixel_format == PIXFORMAT_JPEG; |
414 | | -#if CONFIG_IDF_TARGET_ESP32 |
415 | | - cam_obj->psram_mode = false; |
| 417 | +#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 |
| 418 | + cam_obj->psram_mode = g_psram_dma_mode; |
416 | 419 | #else |
417 | | - cam_obj->psram_mode = (config->xclk_freq_hz == 16000000); |
| 420 | + cam_obj->psram_mode = false; |
418 | 421 | #endif |
| 422 | + ESP_LOGI(TAG, "PSRAM DMA mode %s", cam_obj->psram_mode ? "enabled" : "disabled"); |
419 | 423 | cam_obj->frame_cnt = config->fb_count; |
420 | 424 | cam_obj->width = resolution[frame_size].width; |
421 | 425 | cam_obj->height = resolution[frame_size].height; |
@@ -612,3 +616,15 @@ bool cam_get_available_frames(void) |
612 | 616 | { |
613 | 617 | return 0 < uxQueueMessagesWaiting(cam_obj->frame_buffer_queue); |
614 | 618 | } |
| 619 | + |
| 620 | +void cam_set_psram_mode(bool enable) |
| 621 | +{ |
| 622 | + portENTER_CRITICAL(&g_psram_dma_lock); |
| 623 | + g_psram_dma_mode = enable; |
| 624 | + portEXIT_CRITICAL(&g_psram_dma_lock); |
| 625 | +} |
| 626 | + |
| 627 | +bool cam_get_psram_mode(void) |
| 628 | +{ |
| 629 | + return g_psram_dma_mode; |
| 630 | +} |
0 commit comments