MTK之camera框架



/*自己分析camera驱动程序*/

image_sensor驱动程序

 


/ *

 *      case KDIMGSENSORIOC_X_SET_DRIVER:

 * i4RetValue = kdSetDriver((unsigned int*)pBuff);

 * /

关键函数 int kdSetDriver(unsigned int* pDrvIndex);

{

....

kdGetSensorInitFuncList(&pSensorList);//即 *pSensorList = &kdSensorList[0].

...

drvIdx[i] = (pDrvIndex[i] & KDIMGSENSOR_DUAL_MASK_LSB);//获得是哪一个驱动

...

pSensorList[drvIdx[i]].SensorInit;//判断sensorinit是否为空

pSensorList[drvIdx[i]].SensorInit(&g_pInvokeSensorFunc[i]);//*g_pInvokeSensorFunc[i]

                       = &SensorFuncOV5647;

相应的ic驱动

/*ps:其中g_pInvokeSensorFunc为静态的全局变量*/

}





typedef struct
{
MUINT32 SensorId;
MUINT8  drvname[32];
MUINT32 (* SensorInit)(PSENSOR_FUNCTION_STRUCT *pfFunc);
} ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT, *PACDK_KD_SENSOR_INIT_FUNCTION_STRUCT;


ACDK_KD_SENSOR_INIT_FUNCTION_STRUCT kdSensorList[MAX_NUM_OF_SUPPORT_SENSOR+1] =
{
#if defined(OV8830_RAW)
    {OV8830_SENSOR_ID, SENSOR_DRVNAME_OV8830_RAW, OV8830SensorInit}, 
#endif
#if defined(OV9740_MIPI_YUV)
    {OV9740MIPI_SENSOR_ID, SENSOR_DRVNAME_OV9740_MIPI_YUV, 	 OV9740_MIPI_YUV_SensorInit}, 
#endif
#if defined(IMX073_MIPI_RAW)
    {IMX073_SENSOR_ID, SENSOR_DRVNAME_IMX073_MIPI_RAW, 	 IMX073_MIPI_RAW_SensorInit},
#endif
.....
}


SensorFuncOV5647系列的imagesensor为例:

typedef struct
{
   MUINT32 (* SensorOpen)(void);
  
   MUINT32 (* SensorGetInfo) (MUINT32 *pScenarioId[2], MSDK_SENSOR_INFO_STRUCT   *pSensorInfo[2],MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData[2]);
  
   MUINT32 (* SensorGetResolution) (MSDK_SENSOR_RESOLUTION_INFO_STRUCT *pSensorResolution[2]);

   MUINT32 (* SensorFeatureControl) (CAMERA_DUAL_CAMERA_SENSOR_ENUM InvokeCamera,MSDK_SENSOR_FEATURE_ENUM FeatureId, MUINT8 *pFeaturePara,MUINT32 *pFeatureParaLen);

   MUINT32 (* SensorControl) (MSDK_SCENARIO_ID_ENUM ScenarioId,MSDK_SENSOR_EXPOSURE_WINDOW_STRUCT *pImageWindow, MSDK_SENSOR_CONFIG_STRUCT *pSensorConfigData);

   MUINT32 (* SensorClose)(void);
} MULTI_SENSOR_FUNCTION_STRUCT, *PMULTI_SENSOR_FUNCTION_STRUCT;

SENSOR_FUNCTION_STRUCT	SensorFuncOV5647=
{
	OV5647Open,
	OV5647GetInfo,
	OV5647GetResolution,
	OV5647FeatureControl,
	OV5647Control,
	OV5647Close
};

UINT32 OV5647SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc)
{
	/* To Do : Check Sensor status here */
	if (pfFunc!=NULL)
		*pfFunc=&SensorFuncOV5647;

	return ERROR_NONE;
}


 



    UINT32 err = 0;

        KD_IMGSENSOR_PROFILE_INIT();
        //power on sensor
    if (atomic_read(&g_CamHWOpend) == 0  ) { //只有一个程序打开该设备
        if (g_pSensorFunc) { //?? *g_pSensorFunc = &kd_MultiSensorFunc
应该定义一个 *g_pSensorFunc =&g_pInvokeSensorFunc       
err = g_pSensorFunc->SensorOpen();//调用IC驱动定义的SensorOpen函数
            if(ERROR_NONE != err) {
                PK_DBG(" ERROR:SensorOpen(), turn off power \n");
                kdModulePowerOn((CAMERA_DUAL_CAMERA_SENSOR_ENUM*) g_invokeSocketIdx, g_invokeSensorNameStr, false, CAMERA_HW_DRVNAME1);
            }
        }
        else {
            PK_DBG(" ERROR:NULL g_pSensorFunc\n");
        }
        KD_IMGSENSOR_PROFILE("SensorOpen");
    }
	else {
		PK_ERR("adopt_CAMERA_HW_Open Fail, g_CamHWOpend = %d\n ",atomic_read(&g_CamHWOpend) );
	}

    if (err == 0 ) {
        atomic_set(&g_CamHWOpend, 1);

    }

    return err?-EIO:err;
}


当调用open函数时,最终调用IC驱动的open函数

UINT32 OV5647Open(void)
{
	kal_uint16 sensor_id=0; 

	// check if sensor ID correct
	sensor_id=((OV5647_read_cmos_sensor(0x300A)<<8)| OV5647_read_cmos_sensor(0x300B));   
#ifdef OV5647_DRIVER_TRACE
	SENSORDB("OV5647Open, sensor_id:%x \n",sensor_id);
#endif		
	if (sensor_id != OV5647_SENSOR_ID)
		return ERROR_SENSOR_CONNECT_FAIL;
	
	/* initail sequence write in  */
	OV5647_Sensor_Init();
	spin_lock(&ov5647_drv_lock);
	OV5647AutoFlicKerMode = KAL_FALSE;
	OV5647_sensor.Prv_line_length = OV5647_PV_PERIOD_PIXEL_NUMS;//For ZSD
	spin_unlock(&ov5647_drv_lock);
	return ERROR_NONE;
}


 

你可能感兴趣的:(MTK之camera框架)