⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 image_sensor.c

📁 mtk双摄像头驱动软件
💻 C
📖 第 1 页 / 共 5 页
字号:
		//write_cmos_sensor(0xd8	,0x4	);   //flicker_step, div2, 24M

		w_blank=0;
		h_blank=4;


		
            dummy_pixels=0;
            dummy_lines=0;  
	    }
     #endif
	 
	preview_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;

#if 0	// set updown mirror
	switch (sensor_config_data->image_mirror)
	{
		case IMAGE_NORMAL:
		 
			//SET_FIRST_GRAB_COLOR(BAYER_Gb);
		
			while(updown_mirror != 0x20)
			{
				write_cmos_sensor(0x0e,0x20|CISCTL_mode);
				updown_mirror=read_cmos_sensor(0x0e)&0x30;
			};
        break;

    case IMAGE_H_MIRROR:
		  
				//SET_FIRST_GRAB_COLOR(BAYER_Gb);
			
			while(updown_mirror != 0x10)
			{	volatile kal_uint32 CISCTL_mode_tmp = CISCTL_mode&~0x20;
				write_cmos_sensor(0x0e,0x10|CISCTL_mode_tmp);
				updown_mirror=read_cmos_sensor(0x0e)&0x30;
			};
        break;

    case IMAGE_V_MIRROR:
		
				//SET_FIRST_GRAB_COLOR(BAYER_Gr);
			
			while(updown_mirror != 0x20)
			{	volatile kal_uint32 CISCTL_mode_tmp = CISCTL_mode&~0x10;
				write_cmos_sensor(0x0e,0x20|CISCTL_mode);
				updown_mirror=read_cmos_sensor(0x0e)&0x30;
			};
        break;

    case IMAGE_HV_MIRROR:

				//SET_FIRST_GRAB_COLOR(BAYER_R);   
			
			while(updown_mirror != 0x00)
			{
				write_cmos_sensor(0x0e,~0x30&CISCTL_mode);
				updown_mirror=read_cmos_sensor(0x0e)&0x30;
			};
		break;
	}
#endif

	image_window->grab_start_x=4;////IMAGE_SENSOR_VGA_INSERTED_PIXELS;
	image_window->grab_start_y=4;//IMAGE_SENSOR_VGA_INSERTED_LINES+dummy_lines;
	
	#if 0
	image_window->exposure_window_width=IMAGE_SENSOR_VGA_WIDTH;
	image_window->exposure_window_height=IMAGE_SENSOR_VGA_HEIGHT-4;
	#else
	image_window->exposure_window_width=IMAGE_SENSOR_VGA_WIDTH-w_blank;
	image_window->exposure_window_height=IMAGE_SENSOR_VGA_HEIGHT-h_blank;
	#endif
	
	//set_GC0306_dummy(dummy_pixels,dummy_lines);
	//write_GC0306_shutter(kal_uint16 shutter)(exposure_lines);
	//kal_sleep_task(30);
	

	/*if (sensor_config_data->isp_op_mode == ISP_MJPEG_ENCODE_MODE) {
		current_shutter=read_GC0306_shutter();
		if (current_shutter < 510)
            current_shutter = 510;

		sensor_config_data->sensor_frame_rate = 10 * (48000000 / preview_pclk_division / 784 / current_shutter / 2); //1fps=10
	}else {
	    // ISP_MJPEG_ENCODE_MODE mode does not invok YUV setting API after preview function
	    // If turn on AEC/AGC/AWB in ISP_MJPEG_ENCODE_MODE mode, the AWB setting will be overwriten.
    	write_cmos_sensor(0x13, 0xF7);  // Turn ON AEC/AGC/AWB
	}*/

	kal_sleep_task(10);		
}	/* GC0306_preview */




void GC0306_capture(image_sensor_exposure_window_struct *image_window, image_sensor_config_struct *sensor_config_data)
{
    volatile kal_uint32 shutter=exposure_lines;
    kal_uint8 temp_reg;
    
    sensor_cap_state=KAL_TRUE;
	
	if(MPEG4_encode_mode)
	    ASSERT(0);
	
	//if(sensor_config_data->enable_shutter_tansfer==KAL_TRUE)
		//shutter=sensor_config_data->capture_shutter;
		
	#ifdef OUTPUT_DEBUG_INFO
	sprintf(temp_buffer, "Begin of GC0306_capture");
	rmmi_write_to_uart((kal_uint8*) temp_buffer, strlen(temp_buffer), KAL_TRUE);
	sprintf(temp_buffer, "cap_shutter:%d, pre_shut:%d", shutter, exposure_lines);
	rmmi_write_to_uart((kal_uint8*) temp_buffer, strlen(temp_buffer), KAL_TRUE);
	#endif

    if(!(sensor_config_data->frame_rate==0xF0))	// If not WEBCAM mode.
    {        
	// turn off night mode
                
    }
    	
	if ((image_window->image_target_width<=IMAGE_SENSOR_1M_WIDTH)&&
		(image_window->image_target_height<=IMAGE_SENSOR_1M_HEIGHT))
	{	/* Less than VGA Mode */
		if (image_window->digital_zoom_factor>=(ISP_DIGITAL_ZOOM_INTERVAL<<1))
		{
			//write_cmos_sensor(0x11,0x83);
			
			SET_TG_PIXEL_CLK_DIVIDER(7);
			SET_CMOS_DATA_LATCH(4);
			
			if ((image_window->image_target_width==IMAGE_SENSOR_1M_WIDTH)&&
				(image_window->image_target_height==IMAGE_SENSOR_1M_HEIGHT))
			//	dummy_pixels=2000;
				dummy_pixels=0;
			else
				dummy_pixels=VGA_PERIOD_PIXEL_NUMS/4;
			dummy_lines=0;
		}
		else
		{
			if(sensor_config_data->frame_rate==0xF0)	// That means WEBCAM mode.
			{
			    SET_TG_OUTPUT_CLK_DIVIDER(1);			//30fps
		              SET_CMOS_RISING_EDGE(0);
		              SET_CMOS_FALLING_EDGE(1);
		              ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
				SET_TG_PIXEL_CLK_DIVIDER(1);
				SET_CMOS_DATA_LATCH(1);

				//write_cmos_sensor(0xd8	,0x2	); 
				
				start_grab_x_offset=0;
				start_grab_y_offset=0;
				
			//	dummy_pixels=200;
				dummy_pixels=0;
				dummy_lines=0;
			}
			else
			{
                        PutUARTBytes(0, "aaa", 3);

				if ((image_window->image_target_width==IMAGE_SENSOR_1M_WIDTH)&&
				(image_window->image_target_height==IMAGE_SENSOR_1M_HEIGHT))
				{
					SET_TG_OUTPUT_CLK_DIVIDER(7);			//30fps
		              		SET_CMOS_RISING_EDGE(0);
		              		SET_CMOS_FALLING_EDGE(5);
					ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
					SET_TG_PIXEL_CLK_DIVIDER(7);
					SET_CMOS_DATA_LATCH(5);
					shutter=read_GC0306_shutter();  //william 20070613
				//	kal_prompt_trace(MOD_MMI,"second, shutter=%d " ,shutter);
				//	shutter=read_GC0306_shutter();  //william 20070613
				//	kal_prompt_trace(MOD_MMI,"###%d,%d###",
					shutter = shutter/4;
				//	kal_prompt_trace(MOD_MMI,"third, shutter=%d " ,shutter);
					write_GC0306_shutter(shutter);   //william 20070613

				}
			 
			else
				{
			     	       SET_TG_OUTPUT_CLK_DIVIDER(2);		//30fps, william change 0625
		              	       SET_CMOS_RISING_EDGE(0);
		              		SET_CMOS_FALLING_EDGE(1);
		              		ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
					SET_TG_PIXEL_CLK_DIVIDER(2);
					SET_CMOS_DATA_LATCH(1);
					shutter=read_GC0306_shutter();  //william 20070613
					//shutter = shutter/2;
					kal_prompt_trace(MOD_MMI,"third, shutter=%d " ,shutter);
					write_GC0306_shutter(shutter);   //william 20070613

					//write_cmos_sensor(0xd8	,0x0f	);
				}	
				dummy_lines=0;
			}
		}
		
		capture_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;

		//shutter=read_GC0306_shutter();  //william 20070613
		//shutter=(shutter*preview_pclk_division)/capture_pclk_division;
		//shutter=(shutter*VGA_PERIOD_PIXEL_NUMS)/(VGA_PERIOD_PIXEL_NUMS+dummy_pixels);

		image_window->grab_start_x=4;  //IMAGE_SENSOR_VGA_INSERTED_PIXELS;
		image_window->grab_start_y=4;  //IMAGE_SENSOR_VGA_INSERTED_LINES+dummy_lines;
		image_window->exposure_window_width=IMAGE_SENSOR_VGA_WIDTH;
		image_window->exposure_window_height=IMAGE_SENSOR_VGA_HEIGHT-4 ; // minus 1 to avoid the last black line
	}
	


	//set_GC0306_dummy(dummy_pixels,dummy_lines);
	//write_GC0306_shutter(shutter);   //william 20070613
	//write_GC0306_gain(sensor_global_gain+10);
	//kal_sleep_task(10);
	//write_GC0306_gain(sensor_global_gain);
	
	#ifdef OUTPUT_DEBUG_INFO
	sprintf(temp_buffer, "cap_shut:%d, pre_shut:%d, pre_pclk_div=%d, cap_pclk_div=%d, dummy_p=%d, dummy_l=%d", shutter, exposure_lines, preview_pclk_division, capture_pclk_division, dummy_pixels, dummy_lines);
	rmmi_write_to_uart((kal_uint8*) temp_buffer, strlen(temp_buffer), KAL_TRUE);
	sprintf(temp_buffer, "End of GC0306_capture");
	rmmi_write_to_uart((kal_uint8*) temp_buffer, strlen(temp_buffer), KAL_TRUE);
	#endif
	 PutUARTBytes(0, "bbb", 3);
}	/* GC0306_capture() */

/*************************************************************************
* FUNCTION
*	write_GC0306_reg
*
* DESCRIPTION
*	This function set the register of GC0306.
*
* PARAMETERS
*	addr : the register index of GC0306
*  para : setting parameter of the specified register of GC0306
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void write_GC0306_reg(kal_uint32 addr, kal_uint32 para)
{
	//write_cmos_sensor(addr,para);
}	/* write_GC0306_reg() */

/*************************************************************************
* FUNCTION
*	read_cmos_sensor
*
* DESCRIPTION
*	This function read parameter of specified register from GC0306.
*
* PARAMETERS
*	addr : the register index of GC0306
*
* RETURNS
*	the data that read from GC0306
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 read_GC0306_reg(kal_uint32 addr)
{
	return (read_cmos_sensor(addr));
}	/* read_GC0306_reg() */

/*************************************************************************
* FUNCTION
*	set_GC0306_shutter
*
* DESCRIPTION
*	This function set e-shutter of GC0306 to change exposure time.
*
* PARAMETERS
*	shutter : exposured lines
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void set_GC0306_shutter(kal_uint16 shutter)
{
	exposure_lines=shutter;
	//write_GC0306_shutter(shutter);
}	/* set_GC0306_shutter */

/*************************************************************************
* FUNCTION
*	set_GC0306_gain
*
* DESCRIPTION
*	This function is to set global gain to sensor.
*
* PARAMETERS
*	gain : sensor global gain(base: 0x40)
*
* RETURNS
*	the actually gain set to sensor.
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint16 set_GC0306_gain(kal_uint16 gain)
{


}

/*************************************************************************
* FUNCTION
*	GC0306_night_mode
*
* DESCRIPTION
*	This function night mode of GC0306.
*
* PARAMETERS
*	none
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void GC0306_night_mode(kal_bool enable)
{
    if(enable)
	{
		MAX_EXPOSURE_LINES=2*(PIXEL_CLK/MIN_FRAME_RATE)/VGA_PERIOD_PIXEL_NUMS;

		sensor_night_mode=KAL_TRUE;
	
		write_cmos_sensor(	0x59	,	0xef	);
		write_cmos_sensor(	0x5a	,	0xef );
		write_cmos_sensor(	0x5b	,	0xef	);
		write_cmos_sensor(	0x5c	,	0xef );

		write_cmos_sensor(	0x68	,	0x40	); //0x60

		write_cmos_sensor(	0x19	,	0x33	);
		write_cmos_sensor(	0x1a	,	0x33	);
		write_cmos_sensor(	0xd8	,	0x08	);  //william change 0625

		write_cmos_sensor(	0x82	,	0x11	);
		
		write_cmos_sensor(	0x87	,	0x91	);
		write_cmos_sensor(	0x88	,	0x10	);
		write_cmos_sensor(	0x89	,	0x08	);
	}
	else
      {
		MAX_EXPOSURE_LINES=(PIXEL_CLK/MIN_FRAME_RATE)/VGA_PERIOD_PIXEL_NUMS;

		sensor_night_mode=KAL_FALSE;

		write_cmos_sensor(	0x59	,	0xf0	);
		write_cmos_sensor(	0x5a	,	0xf0 );
		write_cmos_sensor(	0x5b	,	0xf0	);
		write_cmos_sensor(	0x5c	,	0xf0 );

		
		write_cmos_sensor(	0x68	,	0x30	); //0x60

		write_cmos_sensor(	0x19	,	0x00	);
		write_cmos_sensor(	0x1a	,	0x00	);
		write_cmos_sensor(	0xd8	,	0x03	);  //william change 0625

		write_cmos_sensor(	0x82	,	0x34	);		
		write_cmos_sensor(	0x87	,	0x93	);
		write_cmos_sensor(	0x88	,	0x0a	);
		write_cmos_sensor(	0x89	,	0x4	);
	}
	
	Delayms(100);
	if(camera_oper_data.pregain_mode==ISP_ONLY)
	    //sensor_gain_base=read_OV9650_gain();//;BASEGAIN
	    sensor_gain_base=BASEGAIN;
}

/*************************************************************************
* FUNCTION
*	set_GC0306_flashlight
*
* DESCRIPTION
*	turn on/off GC0306 flashlight .
*
* PARAMETERS
*	none
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void set_GC0306_flashlight(kal_bool enable)
{
	// Todo
}

/*************************************************************************
* FUNCTION
*	set_GC0306_param_zoom
*
* DESCRIPTION
*	GC0306 zoom setting.
*
* PARAMETERS
*	none
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 set_GC0306_param_zoom(kal_uint32 para)
{
	return KAL_FALSE;
}

/*************************************************************************
* FUNCTION
*	set_GC0306_param_contrast
*
* DESCRIPTION
*	GC0306 contrast setting.
*
* PARAMETERS
*	none
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 set_GC0306_param_contrast(kal_uint32 para)
{
	// Not Support
	return KAL_FALSE;	
}

/*************************************************************************
* FUNCTION
*	set_GC0306_param_brightness
*
* DESCRIPTION
*	GC0306 brightness setting.
*
* PARAMETERS
*	none
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 set_GC0306_param_brightness(kal_uint32 para)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -