Skip to content

Commit 20098df

Browse files
committed
cam: Improve memory allocation
* realloc the dma descriptors and buffers, so we can change the image size * NULL out the camera pointer after deinit, so deinit is idempotent
1 parent 4350949 commit 20098df

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

ports/esp32s2/cam.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,8 @@ void cam_dma_config(const cam_config_t *config) {
430430

431431
ESP_LOGI(TAG, "cam_buffer_size: %d, cam_dma_size: %d, cam_dma_node_cnt: %d, cam_total_cnt: %d\n", cam_obj->buffer_size, cam_obj->dma_size, cam_obj->node_cnt, cam_obj->total_cnt);
432432

433-
cam_obj->dma = (lldesc_t *)heap_caps_malloc(cam_obj->node_cnt * sizeof(lldesc_t), MALLOC_CAP_DMA);
434-
cam_obj->buffer = (uint8_t *)heap_caps_malloc(cam_obj->buffer_size * sizeof(uint8_t), MALLOC_CAP_DMA);
433+
cam_obj->dma = (lldesc_t *)heap_caps_realloc(cam_obj->dma, cam_obj->node_cnt * sizeof(lldesc_t), MALLOC_CAP_DMA);
434+
cam_obj->buffer = (uint8_t *)heap_caps_realloc(cam_obj->buffer, cam_obj->buffer_size * sizeof(uint8_t), MALLOC_CAP_DMA);
435435

436436
for (uint32_t x = 0; x < cam_obj->node_cnt; x++) {
437437
cam_obj->dma[x].size = cam_obj->dma_size;
@@ -460,6 +460,8 @@ esp_err_t cam_deinit() {
460460
free(cam_obj->buffer);
461461
free(cam_obj);
462462

463+
cam_obj = NULL;
464+
463465
return ESP_OK;
464466
}
465467

0 commit comments

Comments
 (0)