android—camera从应用到驱动——驱动代码

    下面是展讯平台一个camera_gc5004的驱动代码:
    所做的工作主要有:
    	1、camera上电_gc5004_mipi_PowerOn
    	2、识别camera型号_gc5004_mipi_Identify
    	3、硬件寄存器相关的设置
    	4、为kernel系统提供函数接口g_gc5004_mipi_raw_info


#include 
#include "sensor.h"
#include "jpeg_exif_header.h"
#include "sensor_drv_u.h"
#include "sensor_raw.h"
#include "sensor_gc5004_mipi_raw_param.c"


#define SENSOR_PRINT CMR_LOGE


#define DW9714_VCM_SLAVE_ADDR (0x18>>1)


#define gc5004_mipi_I2C_ADDR_W        0x36
#define gc5004_mipi_I2C_ADDR_R         0x36


#define gc5004_mipi_RAW_PARAM_COM  0x0000




static int s_gc5004_mipi_gain = 0;
static int s_capture_shutter = 0;
static int s_capture_VTS = 0;
static int s_video_min_framerate = 0;
static int s_video_max_framerate = 0;


LOCAL uint32_t _gc5004_mipi_GetResolutionTrimTab(uint32_t param);
LOCAL uint32_t _gc5004_mipi_PowerOn(uint32_t power_on);				/*上电函数*/
LOCAL uint32_t _gc5004_mipi_Identify(uint32_t param);               /*读取ID函数*/
LOCAL uint32_t _gc5004_mipi_BeforeSnapshot(uint32_t param);
LOCAL uint32_t _gc5004_mipi_after_snapshot(uint32_t param);
LOCAL uint32_t _gc5004_mipi_StreamOn(uint32_t param);
LOCAL uint32_t _gc5004_mipi_StreamOff(uint32_t param);
LOCAL uint32_t _gc5004_mipi_write_exposure(uint32_t param);
LOCAL uint32_t _gc5004_mipi_write_gain(uint32_t param);
LOCAL uint32_t _gc5004_mipi_write_af(uint32_t param);
LOCAL uint32_t _gc5004_mipi_flash(uint32_t param);
LOCAL uint32_t _gc5004_mipi_ExtFunc(uint32_t ctl_param);
LOCAL uint32_t _gc5004_mipi_get_VTS(void);
LOCAL uint32_t _gc5004_mipi_set_VTS(int VTS);
LOCAL uint32_t _gc5004_mipi_ReadGain(uint32_t param);
LOCAL uint32_t _gc5004_mipi_set_video_mode(uint32_t param);
LOCAL uint32_t _gc5004_mipi_get_shutter(void);
LOCAL uint32_t _dw9174_SRCInit(uint32_t mode);
LOCAL uint32_t _gc5004_mipi_com_Identify_otp(void* param_ptr);


LOCAL const struct raw_param_info_tab s_gc5004_mipi_raw_param_tab[]={
	{gc5004_mipi_RAW_PARAM_COM, &s_gc5004_mipi_raw_info, _gc5004_mipi_com_Identify_otp, PNULL},
	{RAW_INFO_END_ID, PNULL, PNULL, PNULL}
};


struct sensor_raw_info* s_gc5004_mipi_raw_info_ptr=NULL;


static uint32_t g_module_id = 0;


static uint32_t g_flash_mode_en = 0;
static uint32_t g_af_slewrate = 1;


LOCAL const SENSOR_REG_T gc5004_mipi_common_init[] = {
	//......
	{0x04, 0x40},
	{0x05, 0x01},
	//......
};


LOCAL const SENSOR_REG_T gc5004_mipi_2592X1944_mipi_raw[] = {
	//......
    {0x18, 0x02},//skip on
    //......
};




LOCAL SENSOR_REG_TAB_INFO_T s_gc5004_mipi_resolution_Tab_RAW[] = {
	{ADDR_AND_LEN_OF_ARRAY(gc5004_mipi_common_init), 0, 0, 24, SENSOR_IMAGE_FORMAT_RAW},
	{ADDR_AND_LEN_OF_ARRAY(gc5004_mipi_1296X972_mipi_raw), 1296, 972, 24, SENSOR_IMAGE_FORMAT_RAW},
	{ADDR_AND_LEN_OF_ARRAY(gc5004_mipi_2592X1944_mipi_raw), 2592, 1944, 24, SENSOR_IMAGE_FORMAT_RAW},


};


LOCAL SENSOR_TRIM_T s_gc5004_mipi_Resolution_Trim_Tab[] = {
	{0, 0, 0, 0, 0, 0, {0, 0, 0, 0}},
	{0, 0, 1296, 972, 200, 480, 1000, {0, 0, 1296, 972}},//sysclk*10
	{0, 0, 2592, 1944, 500, 480, 1972, {0, 0, 2592, 1944}},//sysclk*10


};


LOCAL const SENSOR_REG_T s_gc5004_mipi_1296X972_video_tab[SENSOR_VIDEO_MODE_MAX][1] = {
	/*video mode 0: ?fps*/
	{
		{0xff, 0xff}
	},


};
LOCAL const SENSOR_REG_T s_gc5004_mipi_2592X1944_video_tab[SENSOR_VIDEO_MODE_MAX][1] = {
	/*video mode 0: ?fps*/
	{
		{0xff, 0xff}
	},
};


LOCAL SENSOR_VIDEO_INFO_T s_gc5004_mipi_video_info[] = {
	{{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, PNULL},
	{{{30, 30, 200, 64}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},(SENSOR_REG_T**)s_gc5004_mipi_1296X972_video_tab},
	{{{15, 15, 500, 64}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}},(SENSOR_REG_T**)s_gc5004_mipi_2592X1944_video_tab},
	{{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}}, PNULL},
};


LOCAL uint32_t _gc5004_mipi_set_video_mode(uint32_t param)
{
	SENSOR_REG_T_PTR sensor_reg_ptr;
	uint16_t         i = 0x00;
	uint32_t         mode;


	if (param >= SENSOR_VIDEO_MODE_MAX)
		return 0;


	if (SENSOR_SUCCESS != Sensor_GetMode(&mode)) {
		SENSOR_PRINT("fail.");
		return SENSOR_FAIL;
	}


	if (PNULL == s_gc5004_mipi_video_info[mode].setting_ptr) {
		SENSOR_PRINT("fail.");
		return SENSOR_FAIL;
	}


	sensor_reg_ptr = (SENSOR_REG_T_PTR)&s_gc5004_mipi_video_info[mode].setting_ptr[param];
	if (PNULL == sensor_reg_ptr) {
		SENSOR_PRINT("fail.");
		return SENSOR_FAIL;
	}


	for (i=0x00; (0xff!=sensor_reg_ptr[i].reg_addr)||(0xff!=sensor_reg_ptr[i].reg_value); i++) {
		Sensor_WriteReg(sensor_reg_ptr[i].reg_addr, sensor_reg_ptr[i].reg_value);
	}


	SENSOR_PRINT("0x%02x", param);
	return 0;
}




LOCAL SENSOR_IOCTL_FUNC_TAB_T s_gc5004_mipi_ioctl_func_tab = {
	PNULL,
	_gc5004_mipi_PowerOn,     //上电
	PNULL,
	_gc5004_mipi_Identify,    //读取id
	_gc5004_mipi_GetResolutionTrimTab,


	_gc5004_mipi_BeforeSnapshot,
	_gc5004_mipi_after_snapshot,
	PNULL, //_gc5004_mipi_flash,
	PNULL,
	_gc5004_mipi_write_exposure,
	PNULL,
	_gc5004_mipi_write_gain,
	PNULL,
	PNULL,
	_gc5004_mipi_write_af,    //对焦函数
	PNULL,
	PNULL, //_gc5004_mipi_GetExifInfo,
	_gc5004_mipi_ExtFunc,
	PNULL, //_gc5004_mipi_set_anti_flicker,
	_gc5004_mipi_StreamOn,    //打开camera函数
	_gc5004_mipi_StreamOff,   //关闭camera函数
	PNULL,
};




SENSOR_INFO_T g_gc5004_mipi_raw_info = {   //外部调用接口
	gc5004_mipi_I2C_ADDR_W,	// salve i2c write address
	gc5004_mipi_I2C_ADDR_R,	// salve i2c read address


	SENSOR_I2C_REG_8BIT | SENSOR_I2C_REG_8BIT,	// bit0: 0: i2c register value is 8 bit, 1: i2c register value is 16 bit
	// bit1: 0: i2c register addr  is 8 bit, 1: i2c register addr  is 16 bit
	// other bit: reseved
	SENSOR_HW_SIGNAL_PCLK_N | SENSOR_HW_SIGNAL_VSYNC_N | SENSOR_HW_SIGNAL_HSYNC_P,	// bit0: 0:negative; 1:positive -> polarily of pixel clock
	// bit2: 0:negative; 1:positive -> polarily of horizontal synchronization signal
	// bit4: 0:negative; 1:positive -> polarily of vertical synchronization signal
	// other bit: reseved


	// preview mode
	SENSOR_ENVIROMENT_NORMAL | SENSOR_ENVIROMENT_NIGHT,


	// image effect
	SENSOR_IMAGE_EFFECT_NORMAL |
	    SENSOR_IMAGE_EFFECT_BLACKWHITE |
	    SENSOR_IMAGE_EFFECT_RED |
	    SENSOR_IMAGE_EFFECT_GREEN |
	    SENSOR_IMAGE_EFFECT_BLUE |
	    SENSOR_IMAGE_EFFECT_YELLOW |
	    SENSOR_IMAGE_EFFECT_NEGATIVE | SENSOR_IMAGE_EFFECT_CANVAS,


	// while balance mode
	0,


	7,			// bit[0:7]: count of step in brightness, contrast, sharpness, saturation
	// bit[8:31] reseved


	SENSOR_LOW_PULSE_RESET,	// reset pulse level
	50,			// reset pulse width(ms)


	SENSOR_HIGH_LEVEL_PWDN,	// 1: high level valid; 0: low level valid


	1,			// count of identify code
	{{0xf0, 0x50},		// supply two code to identify sensor.
	 {0xf1, 0x04}},		// for Example: index = 0-> Device id, index = 1 -> version id


	SENSOR_AVDD_2800MV,	// voltage of avdd


	2592,			// max width of source image
	1944,			// max height of source image
	"gc5004_mipi",		// name of sensor


	SENSOR_IMAGE_FORMAT_RAW,	// define in SENSOR_IMAGE_FORMAT_E enum,SENSOR_IMAGE_FORMAT_MAX
	// if set to SENSOR_IMAGE_FORMAT_MAX here, image format depent on SENSOR_REG_TAB_INFO_T


	SENSOR_IMAGE_PATTERN_RAWRGB_B,// pattern of input image form sensor;


	s_gc5004_mipi_resolution_Tab_RAW,	// point to resolution table information structure
	&s_gc5004_mipi_ioctl_func_tab,	// point to ioctl function table
	&s_gc5004_mipi_raw_info_ptr,		// information and table about Rawrgb sensor
	NULL,			//&g_gc5004_mipi_ext_info,                // extend information about sensor
	SENSOR_AVDD_1800MV,	// iovdd
	SENSOR_AVDD_1500MV,	// dvdd
	3,			// skip frame num before preview  打开camera到预览跳过得帧数
	1,			// skip frame num before capture  打开camera拍照览跳过得帧数
	0,			// deci frame num during preview
	0,			// deci frame num during video preview


	0,
	0,
	0,
	0,
	0,
	{SENSOR_INTERFACE_TYPE_CSI2, 2, 10, 0},
	s_gc5004_mipi_video_info,
	3,			// skip frame num while change setting
};


LOCAL struct sensor_raw_info* Sensor_GetContext(void)
{
	return s_gc5004_mipi_raw_info_ptr;
}


LOCAL uint32_t Sensor_gc5004_mipi_InitRawTuneInfo(void)
{
	uint32_t rtn=0x00;
	struct sensor_raw_info* raw_sensor_ptr=Sensor_GetContext();
	struct sensor_raw_tune_info* sensor_ptr=raw_sensor_ptr->tune_ptr;
	struct sensor_raw_cali_info* cali_ptr=raw_sensor_ptr->cali_ptr;


	raw_sensor_ptr->version_info->version_id=0x00010000;
	raw_sensor_ptr->version_info->srtuct_size=sizeof(struct sensor_raw_info);


	return rtn;
}




LOCAL uint32_t _gc5004_mipi_GetResolutionTrimTab(uint32_t param)
{
	SENSOR_PRINT("0x%x",  (uint32_t)s_gc5004_mipi_Resolution_Trim_Tab);
	return (uint32_t) s_gc5004_mipi_Resolution_Trim_Tab;
}


LOCAL uint32_t _gc5004_mipi_PowerOn(uint32_t power_on)  /*上电函数*/
{
	SENSOR_AVDD_VAL_E dvdd_val = g_gc5004_mipi_raw_info.dvdd_val;
	SENSOR_AVDD_VAL_E avdd_val = g_gc5004_mipi_raw_info.avdd_val;
	SENSOR_AVDD_VAL_E iovdd_val = g_gc5004_mipi_raw_info.iovdd_val;
	BOOLEAN power_down = g_gc5004_mipi_raw_info.power_down_level;
	BOOLEAN reset_level = g_gc5004_mipi_raw_info.reset_pulse_level;


	if (SENSOR_TRUE == power_on) {//上电时序
		Sensor_PowerDown(power_down);
		// Open power
		Sensor_SetMonitorVoltage(SENSOR_AVDD_2800MV);
		Sensor_SetVoltage(dvdd_val, avdd_val, iovdd_val);
              Sensor_SetMonitorVoltage(SENSOR_AVDD_2800MV);
		usleep(20*1000);
		_dw9174_SRCInit(2);
		Sensor_SetMCLK(SENSOR_DEFALUT_MCLK);
		usleep(10*1000);
		Sensor_PowerDown(!power_down);
		// Reset sensor
		Sensor_Reset(reset_level);
		usleep(10*1000);
	} else {
		Sensor_PowerDown(power_down);
		Sensor_SetMCLK(SENSOR_DISABLE_MCLK);
		Sensor_SetVoltage(SENSOR_AVDD_CLOSED, SENSOR_AVDD_CLOSED, SENSOR_AVDD_CLOSED);
		Sensor_SetMonitorVoltage(SENSOR_AVDD_CLOSED);
	}
	SENSOR_PRINT("SENSOR_gc5004_mipi: _gc5004_mipi_Power_On(1:on, 0:off): %d", power_on);
	return SENSOR_SUCCESS;
}




LOCAL uint32_t _gc5004_mipi_cfg_otp(uint32_t  param)
{
	uint32_t rtn=SENSOR_SUCCESS;
	struct raw_param_info_tab* tab_ptr = (struct raw_param_info_tab*)s_gc5004_mipi_raw_param_tab;
	uint32_t module_id=g_module_id;


	SENSOR_PRINT("SENSOR_gc5004_mipi: _gc5004_mipi_cfg_otp");


	if(PNULL!=tab_ptr[module_id].cfg_otp){
		tab_ptr[module_id].cfg_otp(0);
		}


	return rtn;
}




LOCAL uint32_t _gc5004_mipi_com_Identify_otp(void* param_ptr)
{
	uint32_t rtn=SENSOR_FAIL;
	uint32_t param_id;


	SENSOR_PRINT("SENSOR_gc5004_mipi: _gc5004_mipi_com_Identify_otp1111111111111111");


	/*read param id from sensor omap*/
	param_id=gc5004_mipi_RAW_PARAM_COM;


	if(gc5004_mipi_RAW_PARAM_COM==param_id){
		rtn=SENSOR_SUCCESS ;
	}
	rtn=SENSOR_SUCCESS ;
	return rtn;
}


LOCAL uint32_t _gc5004_mipi_GetRawInof(void)
{
	uint32_t rtn=SENSOR_SUCCESS;
	struct raw_param_info_tab* tab_ptr = (struct raw_param_info_tab*)s_gc5004_mipi_raw_param_tab;
	uint32_t param_id;
	uint32_t i=0x00;


	/*read param id from sensor omap*/
	param_id=gc5004_mipi_RAW_PARAM_COM;


	for(i=0x00; ; i++)
	{
		g_module_id = i;
		if(RAW_INFO_END_ID==tab_ptr[i].param_id){
			if(NULL==s_gc5004_mipi_raw_info_ptr){
				SENSOR_PRINT("SENSOR_gc5004_mipi: ov5647_GetRawInof no param error");
				rtn=SENSOR_FAIL;
			}
			SENSOR_PRINT("SENSOR_gc5004_mipi: gc5004_mipi_GetRawInof end");
			break;
		}
		else if(PNULL!=tab_ptr[i].identify_otp){
			if(SENSOR_SUCCESS==tab_ptr[i].identify_otp(0))
			{
				s_gc5004_mipi_raw_info_ptr = tab_ptr[i].info_ptr;
				SENSOR_PRINT("SENSOR_gc5004_mipi: gc5004_mipi_GetRawInof success");
				break;
			}
		}
	}


	return rtn;
}


LOCAL uint32_t _gc5004_mipi_GetMaxFrameLine(uint32_t index)
{
	uint32_t max_line=0x00;
	SENSOR_TRIM_T_PTR trim_ptr=s_gc5004_mipi_Resolution_Trim_Tab;


	max_line=trim_ptr[index].frame_line;


	return max_line;
}


LOCAL uint32_t _gc5004_mipi_Identify(uint32_t param)
{
#define gc5004_mipi_PID_VALUE    0x50
#define gc5004_mipi_PID_ADDR     0xf0
#define gc5004_mipi_VER_VALUE    0x04
#define gc5004_mipi_VER_ADDR     0xf1


	uint8_t pid_value = 0x00;
	uint8_t ver_value = 0x00;
	uint32_t ret_value = SENSOR_FAIL;


	SENSOR_PRINT("SENSOR_gc5004_mipi: mipi raw identify\n");


	pid_value = Sensor_ReadReg(gc5004_mipi_PID_ADDR);
	if (gc5004_mipi_PID_VALUE == pid_value) {
		ver_value = Sensor_ReadReg(gc5004_mipi_VER_ADDR);//读取ID
		SENSOR_PRINT("SENSOR_gc5004_mipi: Identify: PID = %x, VER = %x", pid_value, ver_value);
		if (gc5004_mipi_VER_VALUE == ver_value) {   //判断读取的id是否正确
			ret_value=_gc5004_mipi_GetRawInof();
			Sensor_gc5004_mipi_InitRawTuneInfo();
			ret_value = SENSOR_SUCCESS;
			SENSOR_PRINT("SENSOR_gc5004_mipi: this is gc5004_mipi sensor !");
		} else {
			SENSOR_PRINT
			    ("SENSOR_gc5004_mipi: Identify this is GC%x%x sensor !", pid_value, ver_value);
		}
	} else {
		SENSOR_PRINT("SENSOR_gc5004_mipi: identify fail,pid_value=%x", pid_value);
	}
	
	return ret_value;//返回ID是否读取正确
}


LOCAL uint32_t _gc5004_mipi_write_exposure(uint32_t param)
{
	uint32_t ret_value = SENSOR_SUCCESS;
	uint16_t expsure_line=0x00;
	uint16_t dummy_line=0x00;
	uint16_t shutter_temp=0x00;


	SENSOR_PRINT("gc5004_mipi_Write_line  param_exp  = %d \n",param);
	expsure_line=param&0xffff;
	dummy_line=(param>>0x10)&0xffff;


	SENSOR_PRINT("gc5004_mipi_Write_line  dummy_line  = %d \n",dummy_line );
	if (!expsure_line) expsure_line = 4; /* avoid 0 */
	


	if(expsure_line < 4) expsure_line = 4;
	if(expsure_line > 8191) expsure_line = 8191;//2    ^ 13
	//Update Shutter
	expsure_line = expsure_line/4;
	expsure_line = expsure_line*4;
	shutter_temp = expsure_line%4;


	if(shutter_temp >2)
	expsure_line+=4;


	SENSOR_PRINT("gc5004_mipi_Write_line  5004line  = %d \n",expsure_line);
	ret_value = Sensor_WriteReg(0x04, (expsure_line) & 0xFF);
	ret_value = Sensor_WriteReg(0x03, (expsure_line >> 8) & 0x1F);	


	return ret_value;
}


LOCAL uint32_t _gc5004_mipi_write_gain(uint32_t param)
{
	uint32_t ret_value = SENSOR_SUCCESS;


	uint16_t temp=0x00;
	uint32_t real_gain = 0;
	SENSOR_PRINT("_gc5004_mipi raw _write_gain param = %d  \n",param);




	real_gain = ((param&0xf)+16)*(((param>>4)&0x01)+1)*(((param>>5)&0x01)+1)*(((param>>6)&0x01)+1)*(((param>>7)&0x01)+1);
	real_gain = real_gain*(((param>>8)&0x01)+1)*(((param>>9)&0x01)+1)*(((param>>10)&0x01)+1)*(((param>>11)&0x01)+1);


	real_gain <<= 2;


	SENSOR_PRINT("_gc5004_mipi raw _write_gain real_gain = %d  \n",real_gain);
	Sensor_WriteReg(0xfe, 0x00);
	Sensor_WriteReg(0xb6, 0x00); 
	Sensor_WriteReg(0xb1, 0x01);
	Sensor_WriteReg(0xb2, 0x00);


	if(real_gain < 64)
	{
	real_gain = 64;
	Sensor_WriteReg(0xb6, 0x00); 
	Sensor_WriteReg(0xb1, 0x01);
	Sensor_WriteReg(0xb2, 0x00);


	}
	else if ((64 <= real_gain)&(real_gain < 90))
	{
	Sensor_WriteReg(0xb6, 0x00); 
	temp = real_gain;
	SENSOR_PRINT("_gc5004_mipi_write_gain_1 temp = %d  \n",temp);
	Sensor_WriteReg(0xb1, temp>>6);
	Sensor_WriteReg(0xb2, (temp<<2)&0xfc);
	}
	else if ((90 <= real_gain)&(real_gain < 128))
	{
	Sensor_WriteReg(0xb6, 0x01); 
	temp = 64*real_gain/90;
	SENSOR_PRINT("_gc5004_mipi_write_gain_2 temp = %d  \n",temp);
	Sensor_WriteReg(0xb1, temp>>6);
	Sensor_WriteReg(0xb2, (temp<<2)&0xfc);
	}	
	else if ((128 <= real_gain)&(real_gain < 178))
	{
	Sensor_WriteReg(0xb6, 0x02); 
	temp = 64*real_gain/128;
	SENSOR_PRINT("_gc5004_mipi_write_gain_3 temp = %d  \n",temp);
	Sensor_WriteReg(0xb1, temp>>6);
	Sensor_WriteReg(0xb2, (temp<<2)&0xfc);
	}
	else if ((178 <= real_gain)&(real_gain < 247))
	{
	Sensor_WriteReg(0xb6, 0x03); 
	temp = 64*real_gain/178;
	SENSOR_PRINT("_gc5004_mipi_write_gain_4 temp = %d  \n",temp);
	Sensor_WriteReg(0xb1, temp>>6);
	Sensor_WriteReg(0xb2, (temp<<2)&0xfc);
	}
	else if (247 <= real_gain)
	{
	Sensor_WriteReg(0xb6, 0x04); 
	temp = 64*real_gain/247;
	SENSOR_PRINT("_gc5004_mipi_write_gain_5 temp = %d  \n",temp);
	Sensor_WriteReg(0xb1, temp>>6);
	Sensor_WriteReg(0xb2, (temp<<2)&0xfc);
	}	
	
	return ret_value;
}


LOCAL uint32_t _gc5004_mipi_write_af(uint32_t param)
{
	uint32_t ret_value = SENSOR_SUCCESS;
	uint16_t  slave_addr = DW9714_VCM_SLAVE_ADDR;
	uint16_t cmd_len = 0;
	uint8_t cmd_val[2] = {0x00};


	cmd_val[0] = ((param&0xfff0)>>4) & 0x3f;
	cmd_val[1] = ((param&0x0f)<<4) & 0xf0;
	cmd_len = 2;
	ret_value = Sensor_WriteI2C(slave_addr,(uint8_t*)&cmd_val[0], cmd_len);


	SENSOR_PRINT("SENSOR_Gc5004: _write_af, ret =  %d, param = %d,  MSL:%x, LSL:%x\n", 
		ret_value, param, cmd_val[0], cmd_val[1]);
	return ret_value;
}


LOCAL uint32_t _gc5004_mipi_PreBeforeSnapshot(uint32_t param)
{
     uint32_t  cap_shutter,prv_shutter;
     uint32_t shutter_h,shutter_l,shutter;
  
     SENSOR_PRINT("_gc5004_mipi_PreBeforeSnapshot param :%d",param);


     if(SENSOR_MODE_PREVIEW_ONE>= param){
       SENSOR_PRINT("SENSOR_gc5004_mipi:preview equal to capture");   
	return SENSOR_SUCCESS;
       }


       shutter_l = (uint8_t)Sensor_ReadReg(0x04);
       shutter_h = (uint8_t)Sensor_ReadReg(0x03);
       shutter = ((shutter_h<<8)&0x1F00)|(shutter_l&0xFF);
	SENSOR_PRINT("SENSOR_gc5004_mipi_PreBeforeSnapshot prv_shutter = %d",shutter);   
       prv_shutter = shutter;


      Sensor_SetMode(param);
       cap_shutter = shutter*2/5; 
    
	SENSOR_PRINT("SENSOR_gc5004_mipi_PreBeforeSnapshot cap_shutter = %d",cap_shutter);   


      if(!cap_shutter)cap_shutter=1;
      if(cap_shutter<1)cap_shutter=1;
      if(cap_shutter>8191)cap_shutter=8191;


       Sensor_WriteReg(0x04,cap_shutter&0xFF);
       Sensor_WriteReg(0x03,(cap_shutter>>8)&0x1F);
    //   usleep(100*1000);
  	//Sensor_StreamOff();
      return SENSOR_SUCCESS;
}


LOCAL uint32_t _gc5004_mipi_BeforeSnapshot(uint32_t param)
{
        uint32_t cap_mode = (param >> CAP_MODE_BITS);
 	uint32_t rtn = SENSOR_SUCCESS;
	param = param & 0xffff;
        rtn = _gc5004_mipi_PreBeforeSnapshot(param);
	SENSOR_PRINT("_gc5004_mipi_BeforeSnapshot+++++++++++++++++ param = %d",param);
	return rtn;
}
LOCAL uint32_t _gc5004_mipi_after_snapshot(uint32_t param)
{
	SENSOR_PRINT("SENSOR_gc5004_mipi: after_snapshot mode:%d", param);
	Sensor_SetMode(param);
	return SENSOR_SUCCESS;
}
#if 0
LOCAL uint32_t _gc5004_mipi_flash(uint32_t param)
{
	SENSOR_PRINT("SENSOR_gc5004_mipi: param=%d", param);
	g_flash_mode_en = param;
	Sensor_SetFlash(param);
	SENSOR_PRINT_HIGH("end");
	return SENSOR_SUCCESS;
}
#endif


LOCAL uint32_t _gc5004_mipi_StreamOn(uint32_t param)
{
	SENSOR_PRINT("SENSOR_gc5004_mipi: StreamOn");
	usleep(50*1000);
	Sensor_WriteReg(0xfe, 0x03);
	Sensor_WriteReg(0x10, 0x91);
	Sensor_WriteReg(0xfe, 0x00);
	usleep(50*1000);
	return 0;
}


LOCAL uint32_t _gc5004_mipi_StreamOff(uint32_t param)
{
	SENSOR_PRINT("SENSOR_gc5004_mipi: StreamOff");
	usleep(50*1000);
	Sensor_WriteReg(0xfe, 0x03);
	Sensor_WriteReg(0x10, 0x81);
	Sensor_WriteReg(0xfe, 0x00);
	usleep(50*1000);
	return 0;
}






static uint32_t _gc5004_mipi_SetEV(uint32_t param)
{
	uint32_t rtn = SENSOR_SUCCESS;
	
	return rtn;
}
LOCAL uint32_t _gc5004_mipi_ExtFunc(uint32_t ctl_param)
{
	uint32_t rtn = SENSOR_SUCCESS;
	SENSOR_EXT_FUN_PARAM_T_PTR ext_ptr =
	    (SENSOR_EXT_FUN_PARAM_T_PTR) ctl_param;
	SENSOR_PRINT_HIGH("0x%x", ext_ptr->cmd);


	switch (ext_ptr->cmd) {
	case SENSOR_EXT_FUNC_INIT:
		break;
	case SENSOR_EXT_FOCUS_START:
		break;
	case SENSOR_EXT_EXPOSURE_START:
		break;
	case SENSOR_EXT_EV:
		rtn = _gc5004_mipi_SetEV(ctl_param);
		break;
	default:
		break;
	}
	return rtn;
}


LOCAL uint32_t _dw9174_SRCInit(uint32_t mode)
{
	uint8_t cmd_val[2] = {0x00};
	uint16_t  slave_addr = 0;
	uint16_t cmd_len = 0;
	uint32_t ret_value = SENSOR_SUCCESS;	
	int i = 0;
	
	slave_addr = DW9714_VCM_SLAVE_ADDR;
	SENSOR_PRINT("SENSOR_Gc5004: _DW9714A_SRCInit: mode = %d\n", mode);
	switch (mode) {
		case 1:
		break;
		
		case 2:
		{
			cmd_val[0] = 0xec;
			cmd_val[1] = 0xa3;
			cmd_len = 2;
			ret_value = Sensor_WriteI2C(slave_addr,(uint8_t*)&cmd_val[0], cmd_len);


			cmd_val[0] = 0xa1;
			cmd_val[1] = 0x0e;
			cmd_len = 2;
			ret_value = Sensor_WriteI2C(slave_addr,(uint8_t*)&cmd_val[0], cmd_len);


			cmd_val[0] = 0xf2;
			cmd_val[1] = 0x90;
			cmd_len = 2;
			ret_value = Sensor_WriteI2C(slave_addr,(uint8_t*)&cmd_val[0], cmd_len);


			cmd_val[0] = 0xdc;
			cmd_val[1] = 0x51;
			cmd_len = 2;
			ret_value = Sensor_WriteI2C(slave_addr,(uint8_t*)&cmd_val[0], cmd_len);
		}
		break;


		case 3:
		break;


	}


	return ret_value;
}


LOCAL uint32_t _gc5004_mipi_ReadGain(uint32_t param)
{
	uint32_t rtn = SENSOR_SUCCESS;
	return rtn;
}

你可能感兴趣的:(android学习)