Skip to content

Commit 031ee36

Browse files
committed
feat(cam): add cam sensor handle and deinit api
1 parent f387f14 commit 031ee36

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

examples/peripherals/camera/common_components/sensor_init/example_sensor_init.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -19,7 +19,7 @@
1919

2020
static const char *TAG = "sensor_init";
2121

22-
void example_sensor_init(example_sensor_config_t *sensor_config, i2c_master_bus_handle_t *out_i2c_bus_handle)
22+
void example_sensor_init(example_sensor_config_t *sensor_config, example_sensor_handle_t *out_sensor_handle)
2323
{
2424
esp_err_t ret = ESP_FAIL;
2525

@@ -99,6 +99,12 @@ void example_sensor_init(example_sensor_config_t *sensor_config, i2c_master_bus_
9999
ESP_LOGE(TAG, "Start stream fail");
100100
}
101101
ESP_ERROR_CHECK(ret);
102+
out_sensor_handle->i2c_bus_handle = i2c_bus_handle;
103+
out_sensor_handle->sccb_handle = cam_config.sccb_handle;
104+
}
102105

103-
*out_i2c_bus_handle = i2c_bus_handle;
106+
void example_sensor_deinit(example_sensor_handle_t sensor_handle)
107+
{
108+
ESP_ERROR_CHECK(esp_sccb_del_i2c_io(sensor_handle.sccb_handle));
109+
ESP_ERROR_CHECK(i2c_del_master_bus(sensor_handle.i2c_bus_handle));
104110
}

examples/peripherals/camera/common_components/sensor_init/include/example_sensor_init.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -13,6 +13,14 @@
1313
extern "C" {
1414
#endif
1515

16+
/**
17+
* @brief Handle of SCCB interface and sensor
18+
*/
19+
typedef struct {
20+
esp_sccb_io_handle_t sccb_handle; /*!< SCCB io handle that created by `sccb_new_i2c_io` */
21+
i2c_master_bus_handle_t i2c_bus_handle; /*!< I2C bus handle that created by `i2c_new_master_bus` */
22+
} example_sensor_handle_t;
23+
1624
/**
1725
* @brief Configuration of SCCB interface and sensor
1826
*/
@@ -28,9 +36,16 @@ typedef struct {
2836
* @brief SCCB Interface and Sensor Init
2937
*
3038
* @param[in] sensor_config Camera sensor configuration
31-
* @param[out] out_i2c_bus_handle I2C bus handle
39+
* @param[out] out_sensor_handle Camera sensor handle
40+
*/
41+
void example_sensor_init(example_sensor_config_t *sensor_config, example_sensor_handle_t *out_sensor_handle);
42+
43+
/**
44+
* @brief SCCB Interface and Sensor Deinit
45+
*
46+
* @param[in] out_sensor_handle Camera sensor handle
3247
*/
33-
void example_sensor_init(example_sensor_config_t *sensor_config, i2c_master_bus_handle_t *out_i2c_bus_handle);
48+
void example_sensor_deinit(example_sensor_handle_t sensor_handle);
3449

3550
#ifdef __cplusplus
3651
}

examples/peripherals/camera/dvp_isp_dsi/main/dvp_isp_dsi_main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ void app_main(void)
119119
.port = ESP_CAM_SENSOR_DVP,
120120
.format_name = EXAMPLE_CAM_FORMAT,
121121
};
122-
i2c_master_bus_handle_t i2c_bus_handle = NULL;
123-
example_sensor_init(&cam_sensor_config, &i2c_bus_handle);
122+
example_sensor_handle_t sensor_handle = {
123+
.sccb_handle = NULL,
124+
.i2c_bus_handle = NULL,
125+
};
126+
example_sensor_init(&cam_sensor_config, &sensor_handle);
124127

125128
//---------------ISP Init------------------//
126129
isp_proc_handle_t isp_proc = NULL;

examples/peripherals/camera/mipi_isp_dsi/main/mipi_isp_dsi_main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -66,15 +66,18 @@ void app_main(void)
6666
};
6767

6868
//--------Camera Sensor and SCCB Init-----------//
69-
i2c_master_bus_handle_t i2c_bus_handle = NULL;
69+
example_sensor_handle_t sensor_handle = {
70+
.sccb_handle = NULL,
71+
.i2c_bus_handle = NULL,
72+
};
7073
example_sensor_config_t cam_sensor_config = {
7174
.i2c_port_num = I2C_NUM_0,
7275
.i2c_sda_io_num = EXAMPLE_MIPI_CSI_CAM_SCCB_SDA_IO,
7376
.i2c_scl_io_num = EXAMPLE_MIPI_CSI_CAM_SCCB_SCL_IO,
7477
.port = ESP_CAM_SENSOR_MIPI_CSI,
7578
.format_name = EXAMPLE_CAM_FORMAT,
7679
};
77-
example_sensor_init(&cam_sensor_config, &i2c_bus_handle);
80+
example_sensor_init(&cam_sensor_config, &sensor_handle);
7881

7982
//---------------CSI Init------------------//
8083
esp_cam_ctlr_csi_config_t csi_config = {

examples/peripherals/isp/multi_pipelines/main/isp_dsi_main.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -223,15 +223,18 @@ void app_main(void)
223223
};
224224

225225
//--------Camera Sensor and SCCB Init-----------//
226-
i2c_master_bus_handle_t i2c_bus_handle = NULL;
226+
example_sensor_handle_t sensor_handle = {
227+
.sccb_handle = NULL,
228+
.i2c_bus_handle = NULL,
229+
};
227230
example_sensor_config_t cam_sensor_config = {
228231
.i2c_port_num = I2C_NUM_0,
229232
.i2c_sda_io_num = EXAMPLE_MIPI_CSI_CAM_SCCB_SDA_IO,
230233
.i2c_scl_io_num = EXAMPLE_MIPI_CSI_CAM_SCCB_SCL_IO,
231234
.port = ESP_CAM_SENSOR_MIPI_CSI,
232235
.format_name = EXAMPLE_CAM_FORMAT,
233236
};
234-
example_sensor_init(&cam_sensor_config, &i2c_bus_handle);
237+
example_sensor_init(&cam_sensor_config, &sensor_handle);
235238

236239
//---------------VCM SCCB Init------------------//
237240
esp_sccb_io_handle_t dw9714_io_handle = NULL;
@@ -240,7 +243,7 @@ void app_main(void)
240243
.device_address = EXAMPLE_DW9714_DEV_ADDR,
241244
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
242245
};
243-
ESP_ERROR_CHECK(sccb_new_i2c_io(i2c_bus_handle, &i2c_config, &dw9714_io_handle));
246+
ESP_ERROR_CHECK(sccb_new_i2c_io(sensor_handle.i2c_bus_handle, &i2c_config, &dw9714_io_handle));
244247

245248
//---------------CSI Init------------------//
246249
esp_cam_ctlr_csi_config_t csi_config = {

0 commit comments

Comments
 (0)