📄 image_sensor.c
字号:
write_cmos_sensor(0x3a ,0x00);
write_cmos_sensor(0x3c ,0x6c);
write_cmos_sensor(0x3d ,0x10);
write_cmos_sensor(0x3f ,0x29);
write_cmos_sensor(0x40 ,0xc1);
write_cmos_sensor(0x41 ,0x20);
write_cmos_sensor(0x6b ,0x0a);
write_cmos_sensor(0xa1 ,0xc8);
//write_cmos_sensor(0x69 ,0x80);
write_cmos_sensor(0x69,0x40);
write_cmos_sensor(0x43 ,0xf0);
write_cmos_sensor(0x44 ,0x10);
write_cmos_sensor(0x45,0x58);
write_cmos_sensor(0x46,0xAC);
write_cmos_sensor(0x47,0x4E);
write_cmos_sensor(0x48,0x73);
write_cmos_sensor(0x59,0x9C);
write_cmos_sensor(0x5A,0xA0);
write_cmos_sensor(0x5B,0xDD);
write_cmos_sensor(0x5C,0xC6);
write_cmos_sensor(0x5D,0x8E);
write_cmos_sensor(0x5E,0x19);
write_cmos_sensor(0x5F,0xE0);
write_cmos_sensor(0x60,0x05);
// write_cmos_sensor(0x43 ,0xf0);
// write_cmos_sensor(0x44 ,0x10);
// write_cmos_sensor(0x45 ,0x78);
// write_cmos_sensor(0x46 ,0xa8);
// write_cmos_sensor(0x47 ,0x60);
// write_cmos_sensor(0x48 ,0x80);
// write_cmos_sensor(0x59 ,0xba);
// write_cmos_sensor(0x5a ,0x9a);
// write_cmos_sensor(0x5b ,0x22);
// write_cmos_sensor(0x5c ,0xb9);
// write_cmos_sensor(0x5d ,0x9b);
// write_cmos_sensor(0x5e ,0x10);
// write_cmos_sensor(0x5f ,0xe0);
// write_cmos_sensor(0x60 ,0x85); //05 for advanced AWB
write_cmos_sensor(0x61 ,0x60);
write_cmos_sensor(0x9f ,0x9d);
write_cmos_sensor(0xa0 ,0xa0);
write_cmos_sensor(0x4f ,0x66);
write_cmos_sensor(0x50 ,0x6b);
write_cmos_sensor(0x51 ,0x05);
write_cmos_sensor(0x52 ,0x19);
write_cmos_sensor(0x53 ,0x40);
write_cmos_sensor(0x54 ,0x59);
write_cmos_sensor(0x55 ,0x40);
write_cmos_sensor(0x56 ,0x40);
write_cmos_sensor(0x57 ,0x40);
write_cmos_sensor(0x58 ,0x0d);
write_cmos_sensor(0x8b ,0xcc);
write_cmos_sensor(0x8c ,0xcc);
write_cmos_sensor(0x8d ,0xcf);
write_cmos_sensor(0x6c ,0x40);
write_cmos_sensor(0x6d ,0x30);
write_cmos_sensor(0x6e ,0x4b);
write_cmos_sensor(0x6f ,0x60);
write_cmos_sensor(0x70 ,0x70);
write_cmos_sensor(0x71 ,0x70);
write_cmos_sensor(0x72 ,0x70);
write_cmos_sensor(0x73 ,0x70);
write_cmos_sensor(0x74 ,0x60);
write_cmos_sensor(0x75 ,0x60);
write_cmos_sensor(0x76 ,0x50);
write_cmos_sensor(0x77 ,0x48);
write_cmos_sensor(0x78 ,0x3a);
write_cmos_sensor(0x79 ,0x2e);
write_cmos_sensor(0x7a ,0x28);
write_cmos_sensor(0x7b ,0x22);
write_cmos_sensor(0x7c ,0x04);
write_cmos_sensor(0x7d ,0x07);
write_cmos_sensor(0x7e ,0x10);
write_cmos_sensor(0x7f ,0x28);
write_cmos_sensor(0x80 ,0x36);
write_cmos_sensor(0x81 ,0x44);
write_cmos_sensor(0x82 ,0x52);
write_cmos_sensor(0x83 ,0x60);
write_cmos_sensor(0x84 ,0x6c);
write_cmos_sensor(0x85 ,0x78);
write_cmos_sensor(0x86 ,0x8c);
write_cmos_sensor(0x87 ,0x9e);
write_cmos_sensor(0x88 ,0xbb);
write_cmos_sensor(0x89 ,0xd2);
write_cmos_sensor(0x8a ,0xe6);
write_cmos_sensor(0x14 ,0x28);
write_cmos_sensor(0x24 ,0x78);
write_cmos_sensor(0x25 ,0x68);
write_cmos_sensor(0x12, 0x00);
write_cmos_sensor(0x9D, 0x56);
write_cmos_sensor(0x9E, 0x47);
write_cmos_sensor(0x04, 0x40);
write_cmos_sensor(0x18, 0x01);
//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);
sensor_cap_state=KAL_FALSE;
write_cmos_sensor(0x11 ,0x80);
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(7);
//SET_CMOS_DATA_LATCH(3);
SET_TG_PIXEL_CLK_DIVIDER(3);
SET_CMOS_DATA_LATCH(2);
dummy_pixels=0;
dummy_lines=(MIN_LINES_PER_FRAME-VGA_PERIOD_LINE_NUMS);
dummy_lines&=(~0x1);
}
else
{
MPEG4_encode_mode=KAL_FALSE;
/* config TG of ISP to match the setting of image sensor*/
SET_TG_OUTPUT_CLK_DIVIDER(1);
SET_CMOS_RISING_EDGE(0);
SET_CMOS_FALLING_EDGE(1);
ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
SET_TG_PIXEL_CLK_DIVIDER(3);
SET_CMOS_DATA_LATCH(2);
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_YCbY1Cr);
while(temp_reg2 != (0x00|temp_reg1))
{
write_cmos_sensor(0x1E,(0x00|temp_reg1));
temp_reg2=read_cmos_sensor(0x1E);
};
break;
case IMAGE_H_MIRROR:
SET_CAMERA_INPUT_ORDER(INPUT_ORDER_YCbY1Cr);
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_YCbY1Cr);
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_YCbY1Cr);
while(temp_reg2 != (0x30|temp_reg1))
{
write_cmos_sensor(0x1E,(0x30|temp_reg1));
temp_reg2=read_cmos_sensor(0x1E);
};
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+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);
write_cmos_sensor(0x13 ,0xF7); // Turn ON AEC/AGC/AWB
} /* 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
shutter=read_OV76X0_shutter();
sensor_global_gain=read_OV76X0_gain();
write_cmos_sensor(0x13,0xE0); // Turn OFF AEC/AGC/AWB
temp_reg=read_cmos_sensor(0x3B);
write_cmos_sensor(0x3B,temp_reg&~0x80);
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(15);
SET_CMOS_DATA_LATCH(6);
capture_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;
dummy_pixels=0;
dummy_lines=0;
}
else
{
if(sensor_config_data->frame_rate==0xF0) // That means WEBCAM mode.
{
write_cmos_sensor(0x11,0x81);
SET_TG_PIXEL_CLK_DIVIDER(7);
SET_CMOS_DATA_LATCH(3);
capture_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;
}
else
{
if ((image_window->image_target_width==IMAGE_SENSOR_1M_WIDTH)&&
(image_window->image_target_height==IMAGE_SENSOR_1M_HEIGHT))
{
write_cmos_sensor(0x11,0x87);
capture_pclk_division=32;
}
else
{
write_cmos_sensor(0x11,0x81);
SET_TG_PIXEL_CLK_DIVIDER(7);
SET_CMOS_DATA_LATCH(3);
capture_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;
}
dummy_pixels=0;
dummy_lines=0;
}
}
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;
}
if(shutter<1)
shutter=1;
set_OV76X0_dummy(dummy_pixels,dummy_lines);
write_OV76X0_shutter(shutter);
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)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -