?? image_sensor.c.bak
字號:
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
normal_gain=read_cmos_sensor(0x00);
sensor_gain_base=read_OV76X0_gain();
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);
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;
dummy_lines=255;
// 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;
}
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);
dummy_pixels=0;
dummy_lines=0;
}
}
preview_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;
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();
// sensor_global_gain=read_OV76X0_gain();
}
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;
else
dummy_pixels=VGA_PERIOD_PIXEL_NUMS/4;
dummy_lines=0;
}
else
{
if(sensor_config_data->frame_rate==0xF0) // That means WEBCAM mode.
{
write_cmos_sensor(0x11,0x80);
SET_TG_PIXEL_CLK_DIVIDER(1);
SET_CMOS_DATA_LATCH(1);
start_grab_x_offset=0;
start_grab_y_offset=0;
dummy_pixels=200;
dummy_lines=0;
}
else
{
write_cmos_sensor(0x11,0x81);
SET_TG_PIXEL_CLK_DIVIDER(3);
SET_CMOS_DATA_LATCH(2);
if ((image_window->image_target_width==IMAGE_SENSOR_1M_WIDTH)&&
(image_window->image_target_height==IMAGE_SENSOR_1M_HEIGHT))
dummy_pixels=1000;
else
dummy_pixels=0;
dummy_lines=0;
}
}
capture_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;
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=IMAGE_SENSOR_VGA_INSERTED_PIXELS;
image_window->grab_start_y=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 - 1; // minus 1 to avoid the last black line
}
if(shutter<1)
shutter=1;
set_OV76X0_dummy(dummy_pixels,dummy_lines);
write_OV76X0_shutter(shutter);
//write_OV76X0_gain(sensor_global_gain+10);
//kal_sleep_task(10);
//write_OV76X0_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 OV76X0_capture");
rmmi_write_to_uart((kal_uint8*) temp_buffer, strlen(temp_buffer), KAL_TRUE);
#endif
} /* OV76X0_capture() */
/*************************************************************************
* FUNCTION
* write_OV76X0_reg
*
* DESCRIPTION
* This function set the register of OV76X0.
*
* PARAMETERS
* addr : the register index of OV76X0
* para : setting parameter of the specified register of OV76X0
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void write_OV76X0_reg(kal_uint32 addr, kal_uint32 para)
{
write_cmos_sensor(addr,para);
} /* write_OV76X0_reg() */
/*************************************************************************
* FUNCTION
* read_cmos_sensor
*
* DESCRIPTION
* This function read parameter of specified register from OV76X0.
*
* PARAMETERS
* addr : the register index of OV76X0
*
* RETURNS
* the data that read from OV76X0
*
* GLOBALS AFFECTED
*
*************************************************************************/
kal_uint32 read_OV76X0_reg(kal_uint32 addr)
{
return (read_cmos_sensor(addr));
} /* read_OV76X0_reg() */
/*************************************************************************
* FUNCTION
* set_OV76X0_shutter
*
* DESCRIPTION
* This function set e-shutter of OV76X0 to change exposure time.
*
* PARAMETERS
* shutter : exposured lines
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void set_OV76X0_shutter(kal_uint16 shutter)
{
exposure_lines=shutter;
write_OV76X0_shutter(shutter);
} /* set_OV76X0_shutter */
/*************************************************************************
* FUNCTION
* set_OV76X0_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_OV76X0_gain(kal_uint16 gain)
{
sensor_global_gain=(gain*sensor_gain_base)/BASEGAIN;
write_OV76X0_gain(sensor_global_gain);
sensor_global_gain=(sensor_global_gain*BASEGAIN)/sensor_gain_base;
return sensor_global_gain;
}
/*************************************************************************
* FUNCTION
* OV76X0_night_mode
*
* DESCRIPTION
* This function night mode of OV76X0.
*
* PARAMETERS
* none
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void OV76X0_night_mode(kal_bool enable)
{
kal_uint8 night = read_cmos_sensor(0x3B);
if (!sensor_cap_state) {
if (enable) {
if (g_bMJPEG_mode == KAL_TRUE) {
//
// this mode is used by MJPEG mode only
//
write_cmos_sensor(0x3B, night & 0x1F);
/* set Max gain to 16X */
write_cmos_sensor(0x14, 0x38);
}else {
//
// this mode is used by camera or MPEG4 Apps
//
write_cmos_sensor(0x3B, night | 0xC0);
/* set Max gain to 16X */
write_cmos_sensor(0x14, 0x38);
}
}else{
if (g_bMJPEG_mode == KAL_TRUE) {
//
// this mode is used by MJPEG mode only
//
write_cmos_sensor(0x3B, night & 0x1F);
/* set Max gain to 8X */
write_cmos_sensor(0x14, 0x28);
}else {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -