feat(cam): add cam sensor handle and deinit api

This commit is contained in:
gaoxu
2025-04-29 15:58:43 +08:00
parent f387f14509
commit 031ee36604
5 changed files with 46 additions and 16 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -19,7 +19,7 @@
static const char *TAG = "sensor_init";
void example_sensor_init(example_sensor_config_t *sensor_config, i2c_master_bus_handle_t *out_i2c_bus_handle)
void example_sensor_init(example_sensor_config_t *sensor_config, example_sensor_handle_t *out_sensor_handle)
{
esp_err_t ret = ESP_FAIL;
@@ -99,6 +99,12 @@ void example_sensor_init(example_sensor_config_t *sensor_config, i2c_master_bus_
ESP_LOGE(TAG, "Start stream fail");
}
ESP_ERROR_CHECK(ret);
*out_i2c_bus_handle = i2c_bus_handle;
out_sensor_handle->i2c_bus_handle = i2c_bus_handle;
out_sensor_handle->sccb_handle = cam_config.sccb_handle;
}
void example_sensor_deinit(example_sensor_handle_t sensor_handle)
{
ESP_ERROR_CHECK(esp_sccb_del_i2c_io(sensor_handle.sccb_handle));
ESP_ERROR_CHECK(i2c_del_master_bus(sensor_handle.i2c_bus_handle));
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -13,6 +13,14 @@
extern "C" {
#endif
/**
* @brief Handle of SCCB interface and sensor
*/
typedef struct {
esp_sccb_io_handle_t sccb_handle; /*!< SCCB io handle that created by `sccb_new_i2c_io` */
i2c_master_bus_handle_t i2c_bus_handle; /*!< I2C bus handle that created by `i2c_new_master_bus` */
} example_sensor_handle_t;
/**
* @brief Configuration of SCCB interface and sensor
*/
@@ -28,9 +36,16 @@ typedef struct {
* @brief SCCB Interface and Sensor Init
*
* @param[in] sensor_config Camera sensor configuration
* @param[out] out_i2c_bus_handle I2C bus handle
* @param[out] out_sensor_handle Camera sensor handle
*/
void example_sensor_init(example_sensor_config_t *sensor_config, i2c_master_bus_handle_t *out_i2c_bus_handle);
void example_sensor_init(example_sensor_config_t *sensor_config, example_sensor_handle_t *out_sensor_handle);
/**
* @brief SCCB Interface and Sensor Deinit
*
* @param[in] out_sensor_handle Camera sensor handle
*/
void example_sensor_deinit(example_sensor_handle_t sensor_handle);
#ifdef __cplusplus
}

View File

@@ -119,8 +119,11 @@ void app_main(void)
.port = ESP_CAM_SENSOR_DVP,
.format_name = EXAMPLE_CAM_FORMAT,
};
i2c_master_bus_handle_t i2c_bus_handle = NULL;
example_sensor_init(&cam_sensor_config, &i2c_bus_handle);
example_sensor_handle_t sensor_handle = {
.sccb_handle = NULL,
.i2c_bus_handle = NULL,
};
example_sensor_init(&cam_sensor_config, &sensor_handle);
//---------------ISP Init------------------//
isp_proc_handle_t isp_proc = NULL;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -66,7 +66,10 @@ void app_main(void)
};
//--------Camera Sensor and SCCB Init-----------//
i2c_master_bus_handle_t i2c_bus_handle = NULL;
example_sensor_handle_t sensor_handle = {
.sccb_handle = NULL,
.i2c_bus_handle = NULL,
};
example_sensor_config_t cam_sensor_config = {
.i2c_port_num = I2C_NUM_0,
.i2c_sda_io_num = EXAMPLE_MIPI_CSI_CAM_SCCB_SDA_IO,
@@ -74,7 +77,7 @@ void app_main(void)
.port = ESP_CAM_SENSOR_MIPI_CSI,
.format_name = EXAMPLE_CAM_FORMAT,
};
example_sensor_init(&cam_sensor_config, &i2c_bus_handle);
example_sensor_init(&cam_sensor_config, &sensor_handle);
//---------------CSI Init------------------//
esp_cam_ctlr_csi_config_t csi_config = {

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -223,7 +223,10 @@ void app_main(void)
};
//--------Camera Sensor and SCCB Init-----------//
i2c_master_bus_handle_t i2c_bus_handle = NULL;
example_sensor_handle_t sensor_handle = {
.sccb_handle = NULL,
.i2c_bus_handle = NULL,
};
example_sensor_config_t cam_sensor_config = {
.i2c_port_num = I2C_NUM_0,
.i2c_sda_io_num = EXAMPLE_MIPI_CSI_CAM_SCCB_SDA_IO,
@@ -231,7 +234,7 @@ void app_main(void)
.port = ESP_CAM_SENSOR_MIPI_CSI,
.format_name = EXAMPLE_CAM_FORMAT,
};
example_sensor_init(&cam_sensor_config, &i2c_bus_handle);
example_sensor_init(&cam_sensor_config, &sensor_handle);
//---------------VCM SCCB Init------------------//
esp_sccb_io_handle_t dw9714_io_handle = NULL;
@@ -240,7 +243,7 @@ void app_main(void)
.device_address = EXAMPLE_DW9714_DEV_ADDR,
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
};
ESP_ERROR_CHECK(sccb_new_i2c_io(i2c_bus_handle, &i2c_config, &dw9714_io_handle));
ESP_ERROR_CHECK(sccb_new_i2c_io(sensor_handle.i2c_bus_handle, &i2c_config, &dw9714_io_handle));
//---------------CSI Init------------------//
esp_cam_ctlr_csi_config_t csi_config = {