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

📄 image_sensor.c

📁 MTK6225 摄像头驱动 OV7660
💻 C
📖 第 1 页 / 共 4 页
字号:
    write_cmos_sensor(0xa0,0x68);
    write_cmos_sensor(0xa1,0x03);
    write_cmos_sensor(0xa6,0xD8);
    write_cmos_sensor(0xa7,0xD8);
    write_cmos_sensor(0xa8,0xf0);
    write_cmos_sensor(0xa9,0x90);
    write_cmos_sensor(0xaa,0x14);
    write_cmos_sensor(0x13,0xe5);
    
    write_cmos_sensor(0x0e,0x61);
    write_cmos_sensor(0x0f,0x4b);
    write_cmos_sensor(0x16,0x02);
    write_cmos_sensor(0x1e,0x07);
    write_cmos_sensor(0x21,0x02);
    write_cmos_sensor(0x22,0x91);
    write_cmos_sensor(0x29,0x07);
    write_cmos_sensor(0x33,0x0b);
    write_cmos_sensor(0x35,0x0b);
    write_cmos_sensor(0x37,0x1d);
    write_cmos_sensor(0x38,0x71);
    write_cmos_sensor(0x39,0x2a);
    write_cmos_sensor(0x3c,0x78);
    write_cmos_sensor(0x4d,0x40);
    write_cmos_sensor(0x4e,0x20);
    write_cmos_sensor(0x69,0x00);
    write_cmos_sensor(0x6b,0x0a);
    write_cmos_sensor(0x74,0x10);	

    write_cmos_sensor(0x8d,0x4f);
    write_cmos_sensor(0x8e,0x00);
    write_cmos_sensor(0x8f,0x20);
//    write_cmos_sensor(0x8f,0x00);
    write_cmos_sensor(0x90,0x00);
    write_cmos_sensor(0x91,0x00);
    write_cmos_sensor(0x96,0x00);
    write_cmos_sensor(0x9a,0x80);
    write_cmos_sensor(0xb0,0x84);
    write_cmos_sensor(0xb1,0x0c);
    write_cmos_sensor(0xb2,0x0e);
    write_cmos_sensor(0xb3,0x82);
    write_cmos_sensor(0xb8,0x0a);

   write_cmos_sensor (0x43,0x0a);
    write_cmos_sensor(0x44,0xf2);
    write_cmos_sensor(0x45,0x39);
    write_cmos_sensor(0x46,0x62);
    write_cmos_sensor(0x47,0x3d);
    write_cmos_sensor(0x48,0x55);
    write_cmos_sensor(0x59,0x83);
    write_cmos_sensor(0x5a,0x0d);
    write_cmos_sensor(0x5b,0xcd);
    write_cmos_sensor(0x5c,0x8c);
    write_cmos_sensor(0x5d,0x77);
    write_cmos_sensor(0x5e,0x16);
    write_cmos_sensor(0x6c,0x0a);
    write_cmos_sensor(0x6d,0x65);
    write_cmos_sensor(0x6e,0x11);
    write_cmos_sensor(0x6f,0x9e);
//
    write_cmos_sensor(0x6a,0x40);
    write_cmos_sensor(0x01,0x56);
    write_cmos_sensor(0x02,0x44);
    write_cmos_sensor(0x13,0xe7);
    
    /* Color Matrix */

    write_cmos_sensor(0x4f,0x88);
    write_cmos_sensor(0x50,0x8B);
    write_cmos_sensor(0x51,0x04);
    write_cmos_sensor(0x52,0x11);
    write_cmos_sensor(0x53,0x8C);
    write_cmos_sensor(0x54,0x9D);
    write_cmos_sensor(0x55,0x00);
    write_cmos_sensor(0x56,0x40);
    write_cmos_sensor(0x57,0x80);
    write_cmos_sensor(0x58,0x9A);

    write_cmos_sensor(0x41,0x08);
    write_cmos_sensor(0x3f,0x00);
    write_cmos_sensor(0x75,0x04);
    write_cmos_sensor(0x76,0x60);
    write_cmos_sensor(0x4c,0x00);
    write_cmos_sensor(0x77,0x01);
    write_cmos_sensor(0x3D,0xC2);
    write_cmos_sensor(0x4b,0x09);
    write_cmos_sensor(0xc9,0x30);
    write_cmos_sensor(0x41,0x38);
    write_cmos_sensor(0x56,0x40);
    
    write_cmos_sensor(0x34,0x11);
    write_cmos_sensor(0x3b,0x12);
    write_cmos_sensor(0xa4,0x88);
    write_cmos_sensor(0x96,0x00);
    write_cmos_sensor(0x97,0x30);
    write_cmos_sensor(0x98,0x20);
    write_cmos_sensor(0x99,0x30);
    write_cmos_sensor(0x9a,0x84);
    write_cmos_sensor(0x9b,0x29);
    write_cmos_sensor(0x9c,0x03);
    write_cmos_sensor(0x9d,0x99);
    write_cmos_sensor(0x9e,0x7f);
    write_cmos_sensor(0x78,0x04);
    
    write_cmos_sensor(0x79,0x01);
    write_cmos_sensor(0xc8,0xf0);
    write_cmos_sensor(0x79,0x0f);
    write_cmos_sensor(0xc8,0x00);
    write_cmos_sensor(0x79,0x10);
    write_cmos_sensor(0xc8,0x7e);
    write_cmos_sensor(0x79,0x0a);
    write_cmos_sensor(0xc8,0x80);
    write_cmos_sensor(0x79,0x0b);
    write_cmos_sensor(0xc8,0x01);
    write_cmos_sensor(0x79,0x0c);
    write_cmos_sensor(0xc8,0x0f);
    write_cmos_sensor(0x79,0x0d);
    write_cmos_sensor(0xc8,0x20);
    write_cmos_sensor(0x79,0x09);
    write_cmos_sensor(0xc8,0x80);
    write_cmos_sensor(0x79,0x02);
    write_cmos_sensor(0xc8,0xc0);
    write_cmos_sensor(0x79,0x03);
    write_cmos_sensor(0xc8,0x40);
    write_cmos_sensor(0x79,0x05);
    write_cmos_sensor(0xc8,0x30);
    write_cmos_sensor(0x79,0x26);
    
    //L99 LENS
    write_cmos_sensor(0x62,0x00);
    write_cmos_sensor(0x63,0x00);
    write_cmos_sensor(0x64,0x06);
    write_cmos_sensor(0x65,0x00);
    write_cmos_sensor(0x66,0x05);
    write_cmos_sensor(0x94,0x05);
    //write_cmos_sensor(0x95,0x0D); //OVT joe 12/14/2006
    write_cmos_sensor(0x95,0x09);	//OVT joe 12/14/2006
    //write_cmos_sensor(0x95,0x0a);	//OVT joe 12/14/2006
    //camera_para_to_sensor();    // switch to preview mode key setting
    
	return 1;
}	/* init_cmos_sensor() */

/*************************************************************************
* FUNCTION
*	power_off_OV76X0
*
* DESCRIPTION
*	This function is to turn off sensor module power.
*
* PARAMETERS
*	None
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/

void power_off_OV76X0(void)
{
	cis_module_power_on(KAL_FALSE);      // Power Off CIS Power
	UPLL_Disable(UPLL_OWNER_ISP);
	#ifndef HW_SCCB
	   SET_SCCB_CLK_LOW;
	   SET_SCCB_DATA_LOW;
	#endif
}	/* power_off_OV76X0 */

/*************************************************************************
* FUNCTION
*	get_OV76X0_id
*
* DESCRIPTION
*	This function return the sensor read/write id of SCCB interface.
*
* PARAMETERS
*	*sensor_write_id : address pointer of sensor write id
*  *sensor_read_id  : address pointer of sensor read id
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void get_OV76X0_id(kal_uint8 *sensor_write_id, kal_uint8 *sensor_read_id)
{
	*sensor_write_id=OV76X0_WRITE_ID;
	*sensor_read_id=OV76X0_READ_ID;
}	/* get_OV76X0_id */

/*************************************************************************
* FUNCTION
*	get_OV76X0_size
*
* DESCRIPTION
*	This function return the image width and height of image sensor.
*
* PARAMETERS
*	*sensor_width : address pointer of horizontal effect pixels of image sensor
*  *sensor_height : address pointer of vertical effect pixels of image sensor
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void get_OV76X0_size(kal_uint16 *sensor_width, kal_uint16 *sensor_height)
{
	*sensor_width=IMAGE_SENSOR_VGA_WIDTH;			/* pixel numbers actually used in one frame */
	*sensor_height=IMAGE_SENSOR_VGA_HEIGHT;		/* line numbers actually used in one frame */
}	/* get_OV76X0_size */

/*************************************************************************
* FUNCTION
*	get_OV76X0_period
*
* DESCRIPTION
*	This function return the image width and height of image sensor.
*
* PARAMETERS
*	*pixel_number : address pointer of pixel numbers in one period of HSYNC
*  *line_number : address pointer of line numbers in one period of VSYNC
*
* RETURNS
*	None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void get_OV76X0_period(kal_uint16 *pixel_number, kal_uint16 *line_number)
{
	*pixel_number=VGA_PERIOD_PIXEL_NUMS;		/* pixel numbers in one period of HSYNC */
	*line_number=VGA_PERIOD_LINE_NUMS;			/* line numbers in one period of VSYNC */
}	/* get_OV76X0_period */

void OV76X0_preview(image_sensor_exposure_window_struct *image_window, image_sensor_config_struct *sensor_config_data)
{
	volatile kal_uint32 temp_reg2=read_cmos_sensor(0x1E), temp_reg1=(temp_reg2&0x0F);
    const kal_bool b50Hz = (isp_preview_config_data.banding_freq == 0);
	kal_uint8 iTemp;
	kal_uint16 current_shutter;
	
    iTemp = read_cmos_sensor(0x78) & 0xBF;  // clear 0x78[6] = 0

	sensor_cap_state=KAL_FALSE;

	g_bMJPEG_mode = KAL_FALSE;

    // 1. OV7670's clock control register causes sensor output some abnormal frame even if
    // it is written with the same value twice
    // 2. MJPEG preview/capture use the same clock divider, no need to update for
    // MJPEG encode mode
    if (sensor_config_data->isp_op_mode != ISP_MJPEG_ENCODE_MODE) {
        write_cmos_sensor(0x11,0x80);	//MCLK = PCLK
	}

	if((sensor_config_data->isp_op_mode==ISP_MJPEG_PREVIEW_MODE)||
		(sensor_config_data->isp_op_mode==ISP_MJPEG_ENCODE_MODE))
	{
			MPEG4_encode_mode=KAL_FALSE;
			g_bMJPEG_mode = KAL_TRUE;

			/* config TG of ISP to match the setting of image sensor*/
			SET_TG_OUTPUT_CLK_DIVIDER(3);			//10fps
			SET_CMOS_RISING_EDGE(0);
			SET_CMOS_FALLING_EDGE(2);
			ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
			SET_TG_PIXEL_CLK_DIVIDER(3);
			SET_CMOS_DATA_LATCH(2);
			dummy_pixels=0;
            if (b50Hz == KAL_TRUE) {
		        dummy_lines=0xFF;
		    }else {
		        dummy_lines=0xFF;
		    }

//			SET_TG_OUTPUT_CLK_DIVIDER(7);			//7.5fps
//			SET_CMOS_RISING_EDGE(0);
//			SET_CMOS_FALLING_EDGE(3);
//			ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
//			SET_TG_PIXEL_CLK_DIVIDER(7);
//			SET_CMOS_DATA_LATCH(3);
	}
	else
	{
	    if(sensor_config_data->frame_rate==0x0F)		// MPEG4 Encode Mode
	    {
		    MPEG4_encode_mode=KAL_TRUE;
		
		    /* config TG of ISP to match the setting of image sensor*/
		    SET_TG_OUTPUT_CLK_DIVIDER(3);
	    	SET_CMOS_RISING_EDGE(0);
    		SET_CMOS_FALLING_EDGE(2);
		    ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
	    	SET_TG_PIXEL_CLK_DIVIDER(3);
    		SET_CMOS_DATA_LATCH(2);

    		dummy_pixels=0;
//		    dummy_lines=20;
            if (b50Hz == KAL_TRUE) {
		        dummy_lines=0x66;
		    }else {
		        dummy_lines=0x7F;
		    }
	    }
	    else
	    {
		    MPEG4_encode_mode=KAL_FALSE;
		
		    /* config TG of ISP to match the setting of image sensor*/
		    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);

#ifdef __MMI_MAINLCD_240X320__
            dummy_pixels=450;
            if (b50Hz == KAL_TRUE) {
		        dummy_lines = 0x44;
		    }else {
		        dummy_lines=0x8A;
		    }
#else
            dummy_pixels=0;
            if (b50Hz == KAL_TRUE) {
		        dummy_lines = 0x66;
		    }else {
		        dummy_lines=0;
		    }
#endif
	    }
    }

	preview_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;
	g_iPV_LinePeriod = VGA_PERIOD_PIXEL_NUMS + dummy_pixels;

	switch (sensor_config_data->image_mirror)
	{
		case IMAGE_NORMAL:
		    SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1);
			while(temp_reg2 != (0x00|temp_reg1))
			{
				write_cmos_sensor(0x1E,(0x00|temp_reg1));
				temp_reg2=read_cmos_sensor(0x1E);
				write_cmos_sensor(0x78, iTemp | 0x00); // 0x78[6] must be equal to 0x1E[5]
			};
		break;
		case IMAGE_H_MIRROR:
		    SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1);		
			while(temp_reg2 != (0x20|temp_reg1))
			{
				write_cmos_sensor(0x1E,(0x20|temp_reg1));
				temp_reg2=read_cmos_sensor(0x1E);
			};
		break;
		case IMAGE_V_MIRROR:
		    SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1);		
			while(temp_reg2 != (0x10|temp_reg1))
			{
				write_cmos_sensor(0x1E,(0x10|temp_reg1));
				temp_reg2=read_cmos_sensor(0x1E);
			};
		break;
		case IMAGE_HV_MIRROR:
		    SET_CAMERA_INPUT_ORDER(INPUT_ORDER_CbYCrY1);		
			while(temp_reg2 != (0x30|temp_reg1))
			{
				write_cmos_sensor(0x1E,(0x30|temp_reg1));
				temp_reg2=read_cmos_sensor(0x1E);
				write_cmos_sensor(0x78, iTemp | 0x40);  // 0x78[6] must be equal to 0x1E[5]
			};
		break;
	}

	image_window->grab_start_x=IMAGE_SENSOR_VGA_INSERTED_PIXELS+start_grab_x_offset;
	image_window->grab_start_y=IMAGE_SENSOR_VGA_INSERTED_LINES+dummy_lines+start_grab_y_offset;
	image_window->exposure_window_width=IMAGE_SENSOR_VGA_WIDTH;
	image_window->exposure_window_height=IMAGE_SENSOR_VGA_HEIGHT;
	
	set_OV76X0_dummy(dummy_pixels,dummy_lines);
	write_OV76X0_shutter(exposure_lines);
	kal_sleep_task(30);
	

	if (sensor_config_data->isp_op_mode == ISP_MJPEG_ENCODE_MODE) {
		current_shutter=read_OV76X0_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(100);		
}	/* OV76X0_preview */

void OV76X0_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 OV76X0_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
        temp_reg=read_cmos_sensor(0x3B);
        write_cmos_sensor(0x3B,temp_reg&~0x80);

        write_cmos_sensor(0x13,0xE0);  // Turn OFF AEC/AGC/AWB
        
        shutter=read_OV76X0_shutter();
    }
    	
	if ((image_window->image_target_width<=IMAGE_SENSOR_1M_WIDTH)&&
		(image_window->image_target_height<=IMAGE_SENSOR_1M_HEIGHT))

⌨️ 快捷键说明

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