@@ -55,7 +55,7 @@ typedef struct
5555} CAMERA_Ctx_t ;
5656
5757CMW_CameraInit_t camera_conf ;
58- CMW_Sensor_Name_t detected_sensor ;
58+ CMW_Sensor_Name_t connected_sensor ;
5959CAMERA_Ctx_t Camera_Ctx ;
6060
6161DCMIPP_HandleTypeDef hcamera_dcmipp ;
@@ -111,11 +111,11 @@ int32_t CMW_CAMERA_SetPipeConfig(uint32_t pipe, CMW_DCMIPP_Conf_t *p_conf, uint3
111111int32_t CMW_CAMERA_GetSensorName (CMW_Sensor_Name_t * sensorName )
112112{
113113 int32_t ret = CMW_ERROR_NONE ;
114- CMW_Sensor_Init_t initValues ;
114+ CMW_Sensor_Init_t initValues = { 0 } ;
115115
116116 if (is_camera_init != 0 )
117117 {
118- * sensorName = detected_sensor ;
118+ * sensorName = connected_sensor ;
119119 return CMW_ERROR_NONE ;
120120 }
121121
@@ -124,6 +124,7 @@ int32_t CMW_CAMERA_GetSensorName(CMW_Sensor_Name_t *sensorName)
124124 initValues .fps = 30 ;
125125 initValues .pixel_format = DCMIPP_PIXEL_PACKER_FORMAT_RGB565_1 ;
126126 initValues .mirrorFlip = CMW_MIRRORFLIP_NONE ;
127+ initValues .sensor_config = NULL ;
127128
128129 /* Set DCMIPP instance */
129130 hcamera_dcmipp .Instance = DCMIPP ;
@@ -143,12 +144,12 @@ int32_t CMW_CAMERA_GetSensorName(CMW_Sensor_Name_t *sensorName)
143144
144145 CMW_CAMERA_EnableGPIOs ();
145146
146- ret = CMW_CAMERA_Probe_Sensor (& initValues , & detected_sensor );
147+ ret = CMW_CAMERA_Probe_Sensor (& initValues , & connected_sensor );
147148 if (ret != CMW_ERROR_NONE )
148149 {
149150 return CMW_ERROR_UNKNOWN_COMPONENT ;
150151 }
151- * sensorName = detected_sensor ;
152+ * sensorName = connected_sensor ;
152153 return CMW_ERROR_NONE ;
153154}
154155
@@ -210,7 +211,6 @@ static int CMW_CAMERA_Probe_Sensor(CMW_Sensor_Init_t *initValues, CMW_Sensor_Nam
210211 return ret ;
211212 }
212213#endif
213-
214214#if defined(USE_VD66GY_SENSOR )
215215 ret = CMW_CAMERA_VD66GY_Init (initValues );
216216 if (ret == CMW_ERROR_NONE )
@@ -237,13 +237,14 @@ static int CMW_CAMERA_Probe_Sensor(CMW_Sensor_Init_t *initValues, CMW_Sensor_Nam
237237
238238/**
239239 * @brief Initializes the camera.
240- * @param initConf Camera sensor requested config
240+ * @param initConf Mandatory: General camera config
241+ * @param sensor_config Optional: Sensor specific configuration
241242 * @retval CMW status
242243 */
243- int32_t CMW_CAMERA_Init (CMW_CameraInit_t * initConf )
244+ int32_t CMW_CAMERA_Init (CMW_CameraInit_t * initConf , CMW_Sensor_Config_t * sensor_config )
244245{
245246 int32_t ret = CMW_ERROR_NONE ;
246- CMW_Sensor_Init_t initValues ;
247+ CMW_Sensor_Init_t initValues = { 0 } ;
247248 ISP_SensorInfoTypeDef info = {0 };
248249
249250 initValues .width = initConf -> width ;
@@ -252,9 +253,15 @@ int32_t CMW_CAMERA_Init(CMW_CameraInit_t *initConf)
252253 initValues .pixel_format = initConf -> pixel_format ;
253254 initValues .mirrorFlip = initConf -> mirror_flip ;
254255
255- if (is_camera_init != 0 )
256+ if (( sensor_config != NULL ) && ( sensor_config -> selected_sensor != CMW_NOTKNOWN_Sensor ) )
256257 {
257- return CMW_ERROR_NONE ;
258+ connected_sensor = sensor_config -> selected_sensor ; // Assume The sensor is the one selected by the application. Check during probe
259+ initValues .sensor_config = (void * ) & sensor_config -> config ;
260+ }
261+ else
262+ {
263+ connected_sensor = CMW_NOTKNOWN_Sensor ;
264+ initValues .sensor_config = NULL ;
258265 }
259266
260267 /* Set DCMIPP instance */
@@ -275,7 +282,7 @@ int32_t CMW_CAMERA_Init(CMW_CameraInit_t *initConf)
275282
276283 CMW_CAMERA_EnableGPIOs ();
277284
278- ret = CMW_CAMERA_Probe_Sensor (& initValues , & detected_sensor );
285+ ret = CMW_CAMERA_Probe_Sensor (& initValues , & connected_sensor );
279286 if (ret != CMW_ERROR_NONE )
280287 {
281288 return CMW_ERROR_UNKNOWN_COMPONENT ;
@@ -943,7 +950,6 @@ static int32_t CMW_CAMERA_VD55G1_Init( CMW_Sensor_Init_t *initSensors_params)
943950
944951 memset (& camera_bsp , 0 , sizeof (camera_bsp ));
945952 camera_bsp .vd55g1_bsp .Address = CAMERA_VD55G1_ADDRESS ;
946- camera_bsp .vd55g1_bsp .ClockInHz = CAMERA_VD55G1_FREQ_IN_HZ ;
947953 camera_bsp .vd55g1_bsp .Init = CMW_I2C_INIT ;
948954 camera_bsp .vd55g1_bsp .DeInit = CMW_I2C_DEINIT ;
949955 camera_bsp .vd55g1_bsp .WriteReg = CMW_I2C_WRITEREG16 ;
@@ -958,6 +964,12 @@ static int32_t CMW_CAMERA_VD55G1_Init( CMW_Sensor_Init_t *initSensors_params)
958964 return CMW_ERROR_COMPONENT_FAILURE ;
959965 }
960966
967+ if ((connected_sensor != CMW_VD55G1_Sensor ) && (connected_sensor != CMW_NOTKNOWN_Sensor ))
968+ {
969+ /* If the selected sensor in the application side has selected a different sensors than VD55G1 */
970+ return CMW_ERROR_COMPONENT_FAILURE ;
971+ }
972+
961973 /* Special case: when resolution is not specified take the full sensor resolution */
962974 if ((initSensors_params -> width == 0 ) || (initSensors_params -> height == 0 ))
963975 {
@@ -1014,7 +1026,6 @@ static int32_t CMW_CAMERA_VD66GY_Init( CMW_Sensor_Init_t *initSensors_params)
10141026
10151027 memset (& camera_bsp , 0 , sizeof (camera_bsp ));
10161028 camera_bsp .vd66gy_bsp .Address = CAMERA_VD66GY_ADDRESS ;
1017- camera_bsp .vd66gy_bsp .ClockInHz = CAMERA_VD66GY_FREQ_IN_HZ ;
10181029 camera_bsp .vd66gy_bsp .Init = CMW_I2C_INIT ;
10191030 camera_bsp .vd66gy_bsp .DeInit = CMW_I2C_DEINIT ;
10201031 camera_bsp .vd66gy_bsp .ReadReg = CMW_I2C_READREG16 ;
@@ -1035,6 +1046,12 @@ static int32_t CMW_CAMERA_VD66GY_Init( CMW_Sensor_Init_t *initSensors_params)
10351046 return CMW_ERROR_COMPONENT_FAILURE ;
10361047 }
10371048
1049+ if ((connected_sensor != CMW_VD66GY_Sensor ) && (connected_sensor != CMW_NOTKNOWN_Sensor ))
1050+ {
1051+ /* If the selected sensor in the application side has selected a different sensors than VD66GY */
1052+ return CMW_ERROR_COMPONENT_FAILURE ;
1053+ }
1054+
10381055 /* Special case: when resolution is not specified take the full sensor resolution */
10391056 if ((initSensors_params -> width == 0 ) || (initSensors_params -> height == 0 ))
10401057 {
@@ -1112,6 +1129,12 @@ static int32_t CMW_CAMERA_IMX335_Init(CMW_Sensor_Init_t *initSensors_params)
11121129 return CMW_ERROR_COMPONENT_FAILURE ;
11131130 }
11141131
1132+ if ((connected_sensor != CMW_IMX335_Sensor ) && (connected_sensor != CMW_NOTKNOWN_Sensor ))
1133+ {
1134+ /* If the selected sensor in the application side has selected a different sensors than IMX335 */
1135+ return CMW_ERROR_COMPONENT_FAILURE ;
1136+ }
1137+
11151138 /* Special case: when resolution is not specified take the full sensor resolution */
11161139 if ((initSensors_params -> width == 0 ) || (initSensors_params -> height == 0 ))
11171140 {
@@ -1341,3 +1364,31 @@ static int32_t CMW_CAMERA_SetPipe(DCMIPP_HandleTypeDef *hdcmipp, uint32_t pipe,
13411364 return HAL_OK ;
13421365}
13431366
1367+ int32_t CMW_CAMERA_SetDefaultSensorValues ( CMW_Sensor_Config_t * sensor_config )
1368+ {
1369+ if (sensor_config == NULL )
1370+ {
1371+ return CMW_ERROR_WRONG_PARAM ;
1372+ }
1373+ switch (sensor_config -> selected_sensor )
1374+ {
1375+ #if defined(USE_VD66GY_SENSOR )
1376+ case CMW_VD66GY_Sensor :
1377+ CMW_VD66GY_SetDefaultSensorValues (& sensor_config -> config .vd66gy_config );
1378+ break ;
1379+ #endif
1380+ #if defined(USE_VD55G1_SENSOR )
1381+ case CMW_VD55G1_Sensor :
1382+ CMW_VD55G1_SetDefaultSensorValues (& sensor_config -> config .vd55g1_config );
1383+ break ;
1384+ #endif
1385+ #if defined(USE_IMX335_SENSOR )
1386+ case CMW_IMX335_Sensor :
1387+ #endif
1388+ default :
1389+ return CMW_ERROR_WRONG_PARAM ;
1390+ break ;
1391+ }
1392+
1393+ return CMW_ERROR_NONE ;
1394+ }
0 commit comments