MTK 前后使用相同类型的Camera

Posted 冷冻的彩虹

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MTK 前后使用相同类型的Camera相关的知识,希望对你有一定的参考价值。

由于实际项目开发中,前后摄像头使用前后相同类型的Camera,前后Camera经FAE优化使得驱动参数不一致,此时需要使用两份不同的驱动文件;这就涉及到如何在同一款camera上同时使用两套不同的驱动;


硬件电路跟上一篇是一致的就不重复帖图了,请看:MTK Camera驱动移植

驱动兼容原则:“另外一份驱动使用自定义sensor ID 和sensor name中,在系统读取sensor ID的时候使用正确的ID进行匹配”;

这样就能够绕过两款摄像头都是相同的ID的问题了;


以SP5507+SP5507为例

(1)将kernel层代码整个目录sp5507_mipi_raw和 hal层代码整个目录sp5507_mipi_raw各拷贝一份为sp5507_mipi_sub_raw,建议后缀保持raw或yuv;
(2)将前后摄像头优化后的参数合并到代码中;
(3)修改sp5507_mipi_sub_raw中的文件名;


(4)sp5507_mipi_sub_raw拷贝到mediatek/custom/common/kernel/imgsensor/和mediatek/custom/common/hal/imgsensor/目录下;


(5)打开mediatek/custom/common/kernel/imgsensor/inc/kd_imgsensor.h文件, 定义sensor id和sensor name

#define SP5507MIPI_SENSOR_ID                    0x5670  
#define SENSOR_DRVNAME_SP5507MIPI_RAW           "sp5507_mipi_raw"

#define SP5507MIPI_SUB_SENSOR_ID                    0x5671  //在原来的基础上做加1
#define SENSOR_DRVNAME_SP5507MIPI_SUB_RAW           "sp2509_mipi_sub_raw"


(6)在mediatek/custom/common/kernel/imgsensor/src/kd_sensorlist.h文件中声明初始化函数;

UINT32 SP5507_MIPI_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc); 

UINT32 SP5507_MIPI_SUB_RAW_SensorInit(PSENSOR_FUNCTION_STRUCT *pfFunc);  //该函数为kernel中的初始化函数改为这个SP5507_MIPI_SUB_RAW_SensorInit

在kdSensorList数组中添加:

#if defined(SP5507_MIPI_RAW)   
    SP5507MIPI_SENSOR_ID, SENSOR_DRVNAME_SP5507MIPI_RAW, SP5507_MIPI_RAW_SensorInit,
#endif

#if defined(SP5507_MIPI_SUB_RAW) 
    SP5507MIPI_SUB_SENSOR_ID, SENSOR_DRVNAME_SP5507MIPI_SUB_RAW, SP5507_MIPI_SUB_RAW_SensorInit,
#endif


(7)在mediatek/custom/common/hal/imgsensor/src/sensorlist.cpp文件的SensorList数组中添加
#if defined(SP5507_MIPI_RAW)
    RAW_INFO(SP5507MIPI_SENSOR_ID, SENSOR_DRVNAME_SP5507MIPI_RAW, NULL),
#endif

#if defined(SP5507_MIPI_SUB_RAW)
    RAW_INFO(SP5507MIPI_SUB_SENSOR_ID,SENSOR_DRVNAME_SP5507MIPI_SUB_RAW, NULL),
#endif

代码位置要跟kdSensorList数组中的位置保持一致;


(8) 修改mediatek/config/pro/ProjectConfig.mk配置文件
CUSTOM_HAL_IMGSENSOR=sp5507_mipi_raw
CUSTOM_HAL_MAIN_IMGSENSOR=sp5507_mipi_raw  //后摄像头
CUSTOM_HAL_SUB_IMGSENSOR=sp5507_mipi_sub_raw//前摄像头
 
CUSTOM_KERNEL_IMGSENSOR=sp5507_mipi_raw
CUSTOM_KERNEL_MAIN_IMGSENSOR =sp5507_mipi_raw  //后摄像头
CUSTOM_KERNEL_SUB_IMGSENSOR=sp5507_mipi_sub_raw //前摄像头


(9)驱动文件的修改

修改kernel层中部分重要的函数名和变量名,否则kernel在链接阶段会出现重复定义的错误提示;修改kernel和hal中的include对象,否则出现找不到.h文件的提示;

修改kernel层中的XXXXmipiraw_sub_Sensor.h文件中的Sensor ID宏为kd_imgsensor.h中定义的Sensor ID宏:

#define OV5670_SENSOR_ID  SP5507MIPI_SUB_SENSOR_ID 

再修改hal层中的camera_info_XXXXmipiraw.h中的SENSOR_ID和SENSOR_DRVNAME为kd_imgsensor.h中定义的宏,修改config.ftbl.XXXX_mipi_raw.h中的FTABLE_DEFINITION(SENSOR_DRVNAME_XXXX_MIPI_RAW)的SENSOR_DRVNAME为kd_imgsensor.h中定义的sensor name宏;


(10)修改kernel层中id匹配

搜索使用到获取设备id的代码段,发现只有open函数和getSensorID函数有通过i2c获取设备id的操作;

UINT32 OV5670SUBOpen_sub(void)

	volatile signed int i;
	kal_uint16 sensor_id = 0;

	OV5670SUBDB("OV5670SUB Open enter :\\n ");
	OV5670SUB_write_cmos_sensor(0x0103,0x01);// Reset sensor
        mdelay(2);
	for(i=0;i<2;i++)
	
		/* 这里读取出来的ID为0x5670,但是我们自定义的ID为0x5671所以直接使用“+1”操作就可以了 */
		sensor_id = ((OV5670SUB_read_cmos_sensor(0x300B)<<8)|OV5670SUB_read_cmos_sensor(0x300C))+1;  //加1操作
		OV5670SUBDB("OV5670SUB READ ID :%x",sensor_id);
		if(sensor_id != OV5670SUB_SENSOR_ID)  //这样就能够匹配了
		
			return ERROR_SENSOR_CONNECT_FAIL;
		else
			break;
	
	......

    return ERROR_NONE;  //最后会返回无错误

UINT32 OV5670SUBGetSensorID(UINT32 *sensorID)

    int  retry = 2;
   
	OV5670SUBDB("OV5670SUBGetSensorID enter :\\n ");
    mdelay(5);
    /* 这里读取出来的ID为0x5670,但是我们自定义的ID为0x5671所以直接使用“+1”操作就可以了 */
    do 
        *sensorID = ((OV5670SUB_read_cmos_sensor(0x300B)<<8)|OV5670SUB_read_cmos_sensor(0x300C))+1;  //这里就能够返回0x5671
        if (*sensorID == OV5670SUB_SENSOR_ID)
        	
        		OV5670SUBDB("Sensor ID = 0x%04x\\n", *sensorID);
            	break;
        	
        OV5670SUBDB("Read Sensor ID Fail = 0x%04x\\n", *sensorID);
        retry--;
     while (retry > 0);
	
    if (*sensorID != OV5670SUB_SENSOR_ID) 
		OV5670SUBDB("Read Sensor ID Fail = 0x%04x\\n", *sensorID);
		
		/*
        *sensorID = OV5670SUB_SENSOR_ID;
        return ERROR_SENSOR_CONNECT_FAIL;
	*/
	 *sensorID = 0xFFFFFFFF;
     return ERROR_SENSOR_CONNECT_FAIL;
    
    return ERROR_NONE;  <span style="font-family: Arial;">//最后会返回无错误</span>


(11)上电时序

上电时序只需要在原来基础之上做下兼容就可以了;

打开mediatek\\custom\\pro\\kernel\\camera\\camera\\kd_camera_hw.c文件

修改kdCISModulePowerOn()函数;

在文件中两处使用到(0 == strcmp(SENSOR_DRVNAME_SP5507MIPI_RAW,currSensorName))的地方都加上加上“ || ( 0 == strcmp(SENSOR_DRVNAME_SP5507MIPI_SUB_RAW,currSensorName))” 就可以兼容前后摄像头了;


通过这一系列的操作,就实现了前后使用相同类型的camera设备并且前后对应各自的驱动代码;


以上是关于MTK 前后使用相同类型的Camera的主要内容,如果未能解决你的问题,请参考以下文章

MTK Camera驱动移植

Mtk Camera

MTK android 工程中如何修改照片详细信息中机型名

mtk camera faq

MTK Camera(OV13850) 驱动移植

MTK 平台上如何给 camera 添加一种 preview size