Skip to content
This repository was archived by the owner on Jun 15, 2020. It is now read-only.

Commit 90f05fd

Browse files
committed
camera: add function to de-initialize the driver
1 parent e4f922f commit 90f05fd

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
lines changed

components/camera/camera.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,39 @@ esp_err_t camera_init(const camera_config_t* config)
345345
return ESP_OK;
346346

347347
fail:
348-
free(s_state->fb);
348+
camera_deinit();
349+
return err;
350+
}
351+
352+
esp_err_t camera_deinit()
353+
{
354+
if (s_state == NULL) {
355+
return ESP_ERR_INVALID_STATE;
356+
}
357+
if (s_state->dma_filter_task) {
358+
vTaskDelete(s_state->dma_filter_task);
359+
}
349360
if (s_state->data_ready) {
350361
vQueueDelete(s_state->data_ready);
351362
}
352363
if (s_state->frame_ready) {
353364
vSemaphoreDelete(s_state->frame_ready);
354365
}
355-
if (s_state->dma_filter_task) {
356-
vTaskDelete(s_state->dma_filter_task);
366+
if (s_state->vsync_intr_handle) {
367+
esp_intr_disable(s_state->vsync_intr_handle);
368+
esp_intr_free(s_state->vsync_intr_handle);
369+
}
370+
if (s_state->i2s_intr_handle) {
371+
esp_intr_disable(s_state->i2s_intr_handle);
372+
esp_intr_free(s_state->i2s_intr_handle);
357373
}
358374
dma_desc_deinit();
359-
return err;
375+
free(s_state->fb);
376+
free(s_state);
377+
s_state = NULL;
378+
camera_disable_out_clock();
379+
periph_module_disable(PERIPH_I2S0_MODULE);
380+
return ESP_OK;
360381
}
361382

362383
uint8_t* camera_get_fb()

components/camera/include/camera.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ typedef struct {
8787
esp_err_t camera_probe(const camera_config_t* config, camera_model_t* out_camera_model);
8888

8989
/**
90-
* @brief Initialize the camera
90+
* @brief Initialize the camera driver
9191
*
9292
* @note call camera_probe before calling this function
9393
*
@@ -103,6 +103,15 @@ esp_err_t camera_probe(const camera_config_t* config, camera_model_t* out_camera
103103
*/
104104
esp_err_t camera_init(const camera_config_t* config);
105105

106+
/**
107+
* Deinitialize the camera driver
108+
*
109+
* @return
110+
* - ESP_OK on success
111+
* - ESP_ERR_INVALID_STATE if the driver hasn't been initialized yet
112+
*/
113+
esp_err_t camera_deinit();
114+
106115
/**
107116
* @brief Obtain the pointer to framebuffer allocated by camera_init function.
108117
*

components/camera/xclk.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ esp_err_t camera_enable_out_clock(camera_config_t* config)
3636
return ESP_OK;
3737
}
3838

39+
void camera_disable_out_clock()
40+
{
41+
periph_module_disable(PERIPH_LEDC_MODULE);
42+
}

components/camera/xclk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
#include "camera_common.h"
44

55
esp_err_t camera_enable_out_clock();
6+
7+
void camera_disable_out_clock();

0 commit comments

Comments
 (0)