📄 ov2640.c
字号:
{0xda, 0x10},
{0xd9, 0x10},
{0x33, 0x80},
{0x3c, 0x10},
{0xd3, 0x04},
{0xdd, 0xef},
{0xe0, 0x00},
{0xff, 0x01},
{0x13, 0xe0},
{0xff, 0x00},
{0xd3, 0x04},
{0x44, 0x04}
};
kal_int8 init_OV2640(void)
{
int i;
if(Camera_name != SENSOR_OV2640)
return -1;
return 1;
}
/*****************************************************************************
* FUNCTION
* power_off_OV2640
* DESCRIPTION
* This function is to turn off sensor module power.
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void power_off_OV2640(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 /* HW_SCCB */
}
/*****************************************************************************
* FUNCTION
* get_OV2640_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
* void
*****************************************************************************/
void get_OV2640_id(kal_uint8 *sensor_write_id, kal_uint8 *sensor_read_id)
{
*sensor_write_id = Sensor_Write_ID;
*sensor_read_id = Sensor_Read_ID;
}
/*****************************************************************************
* FUNCTION
* get_OV2640_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
* void
*****************************************************************************/
void get_OV2640_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 */
}
/*****************************************************************************
* FUNCTION
* get_OV2640_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
* void
*****************************************************************************/
void get_OV2640_period(kal_uint16 *pixel_number, kal_uint16 *line_number)
{
*pixel_number=VGA_PERIOD_PIXEL_NUMS_OV2640; /* pixel numbers in one period of HSYNC */
*line_number=VGA_PERIOD_LINE_NUMS_OV2640; /* line numbers in one period of VSYNC */
}
void write_OV2640_extra_line(kal_uint16 extra_line)
{
write_cmos_sensor(0x2d, extra_line & 0xFF);
write_cmos_sensor(0x2e, (extra_line >> 8) & 0xFF);
}
/*****************************************************************************
* FUNCTION
* OV2640_preview
* DESCRIPTION
*
* PARAMETERS
* image_window [?] [?]
* sensor_config_data [?] [?]
* RETURNS
* void
*****************************************************************************/
void OV2640_preview(image_sensor_exposure_window_struct *image_window, image_sensor_config_struct *sensor_config_data)
{
volatile kal_uint32 temp_reg2, temp_reg1;
kal_uint16 current_shutter;
kal_uint16 i;
jpeg_capture_flag = 0;
for(i=0; i<sizeof(OV2640_Preview)/sizeof(OV2640_Preview[0]); i++)
{
write_cmos_sensor(OV2640_Preview[i][0], OV2640_Preview[i][1]);
}
sensor_cap_state=KAL_FALSE;
g_bMJPEG_mode = KAL_FALSE;
if( (sensor_config_data->isp_op_mode == ISP_MJPEG_PREVIEW_MODE) )
{
}
{
MPEG4_encode_mode=KAL_FALSE;
SET_TG_OUTPUT_CLK_DIVIDER(1); //7.5fps
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 = 20;
dummy_lines = 20;
}
preview_pclk_division=((DRV_Reg32(ISP_TG_PHASE_COUNTER_REG)&0xF0)>>4)+1;
write_cmos_sensor(0xff,0x01);
temp_reg1=read_cmos_sensor(0x04);
temp_reg1 = (temp_reg1 & 0x2f);
switch (sensor_config_data->image_mirror)
{
case IMAGE_NORMAL:
write_cmos_sensor(0x04, temp_reg1);
break;
case IMAGE_H_MIRROR:
write_cmos_sensor(0x04, (temp_reg1|0x80));
break;
case IMAGE_V_MIRROR:
write_cmos_sensor(0x04, (temp_reg1|0x50));
break;
case IMAGE_HV_MIRROR:
write_cmos_sensor(0x04, (temp_reg1|0xd0));
break;
}
if (sensor_config_data->isp_op_mode == ISP_MJPEG_PREVIEW_MODE)
{
image_window->grab_start_x = 32; //32
image_window->grab_start_y = 24; //24
image_window->exposure_window_width= 400; //400 //560
image_window->exposure_window_height= 300; //300 //420;
}
else
{
image_window->grab_start_x = 4;
image_window->grab_start_y = 4 ;
image_window->exposure_window_width=IMAGE_SENSOR_VGA_WIDTH -1;
image_window->exposure_window_height=IMAGE_SENSOR_VGA_HEIGHT -1;
}
set_OV2640_dummy(dummy_pixels,dummy_lines);
if (sensor_config_data->isp_op_mode == ISP_MJPEG_ENCODE_MODE)
{
sensor_config_data->sensor_frame_rate = 15 ; //1fps=10
}
kal_sleep_task(60);
}
/*****************************************************************************
* FUNCTION
* OV2640_capture
* DESCRIPTION
*
* PARAMETERS
* image_window [?] [?]
* sensor_config_data [?] [?]
* RETURNS
* void
*****************************************************************************/
void OV2640_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;
kal_uint32 i;
kal_uint16 m;
kal_uint8 temp_reg1;
kal_uint16 PrvExp;
kal_uint16 TgtExp;
kal_uint16 TgtExpGain;
kal_uint8 temp_reg0;
kal_uint8 temp_reg4;
kal_uint8 temp_reg10;
kal_uint8 temp_reg45;
kal_uint8 temp_reg13;
kal_uint8 PrvGain;
kal_uint8 TgtGain;
kal_uint8 retVal;
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;
write_cmos_sensor(0xff, 0x01);
write_cmos_sensor(0x13, 0xe0);
temp_reg0=read_cmos_sensor(0x00);
temp_reg4=read_cmos_sensor(0x04);
temp_reg10=read_cmos_sensor(0x10);
temp_reg45=read_cmos_sensor(0x45);
if(jpeg_capture_flag == 0)
{
SET_TG_PIXEL_CLK_DIVIDER(3);
SET_CMOS_DATA_LATCH(2);
start_grab_x_offset=0;
start_grab_y_offset=0;
dummy_pixels = 20;
dummy_lines = 20;
image_window->grab_start_x= 4;
image_window->grab_start_y= 4;
image_window->exposure_window_width= 640 -1;
image_window->exposure_window_height= 480 -1;
set_OV2640_dummy(dummy_pixels,dummy_lines);
}
else if(jpeg_capture_flag == 1)
{
// 1m_1m 1280*960
for(i=0; i<sizeof(OV2640_Capture_1M)/sizeof(OV2640_Capture_1M[0]); i++)
{
write_cmos_sensor(OV2640_Capture_1M[i][0], OV2640_Capture_1M[i][1]);
}
SET_TG_PIXEL_CLK_DIVIDER(7);
SET_CMOS_DATA_LATCH(4);
start_grab_x_offset=0;
start_grab_y_offset=0;
dummy_pixels = 20;
dummy_lines = 20;
image_window->grab_start_x=0/*2*/;
image_window->grab_start_y=6/*2*/;
image_window->exposure_window_width= 1280/*1200 -2*/; //640 -2; // 1280;
image_window->exposure_window_height= 960-6/*960 -2*/; // 480 -2; // 1024;
}
else
{
// 2m_2m 1600*1200
for(i=0; i<sizeof(OV2640_Capture_2M)/sizeof(OV2640_Capture_2M[0]); i++)
{
write_cmos_sensor(OV2640_Capture_2M[i][0], OV2640_Capture_2M[i][1]);
}
SET_TG_PIXEL_CLK_DIVIDER(7);
SET_CMOS_DATA_LATCH(4);
start_grab_x_offset=0;
start_grab_y_offset=0;
dummy_pixels = 20;
dummy_lines = 20;
image_window->grab_start_x = 0;
image_window->grab_start_y = 0;
image_window->exposure_window_width= 1600;
image_window->exposure_window_height= 1200;
}
if(jpeg_capture_flag != 0)
{
write_cmos_sensor(0xff, 0x01);
PrvGain = temp_reg0;
PrvExp = (kal_uint16)(temp_reg45 & 0x3F);
PrvExp = PrvExp << 8;
PrvExp = PrvExp |(kal_uint16)(temp_reg10);
PrvExp = PrvExp << 2;
PrvExp = PrvExp | (kal_uint16)( temp_reg4 & 0x03);
TgtExp = PrvExp/2;
if (PrvGain & 0x10)
{
PrvGain = PrvGain & 0x0f;
TgtExp = TgtExp * 2;
}
write_cmos_sensor(0x00, PrvGain);
temp_reg4 = (temp_reg4 & 0xFC ) |(kal_uint8)(TgtExp & 0x0003);
write_cmos_sensor(0x04, temp_reg4);
temp_reg10 = (TgtExp >> 2 ) & 0xFF;
write_cmos_sensor(0x10, temp_reg10);
temp_reg45 = (TgtExp >> 10 );
write_cmos_sensor(0x45, temp_reg45);
kal_sleep_task(kal_milli_secs_to_ticks(350));
}
}
/*****************************************************************************
* FUNCTION
* write_OV2640_reg
* DESCRIPTION
* This function set the register of OV2640.
* PARAMETERS
* addr [IN] The register index of OV2640
* para [IN] Setting parameter of the specified register of OV2640
* RETURNS
* void
*****************************************************************************/
void write_OV2640_reg(kal_uint32 addr, kal_uint32 para)
{
write_cmos_sensor(addr, para);
}
/*****************************************************************************
* FUNCTION
* read_OV2640_reg
* DESCRIPTION
* This function read parameter of specified register from OV2640.
* PARAMETERS
* addr [IN] The register index of OV2640
* RETURNS
* the data that read from OV2640
*****************************************************************************/
kal_uint32 read_OV2640_reg(kal_uint32 addr)
{
return (read_cmos_sensor(addr));
}
/*****************************************************************************
* FUNCTION
* set_OV2640_shutter
* DESCRIPTION
* This function set e-shutter of OV2640 to change exposure time.
* PARAMETERS
* shutter [IN] Exposured lines
* RETURNS
* void
*****************************************************************************/
void set_OV2640_shutter(kal_uint16 shutter)
{
exposure_lines = shutter;
write_OV2640_shutter(shutter);
}
/*****************************************************************************
* FUNCTION
* set_OV2640_gain
* DESCRIPTION
* This function is to set global gain to sensor.
* PARAMETERS
* gain [IN] Sensor global gain(base: 0x40)
* RETURNS
* the actually gain set to sensor.
*****************************************************************************/
kal_uint16 set_OV2640_gain(kal_uint16 gain)
{
}
/*****************************************************************************
* FUNCTION
* OV2640_night_mode
* DESCRIPTION
* This function night mode of OV2640.
* PARAMETERS
* enable [IN]
* RETURNS
* void
*****************************************************************************/
void OV2640_night_mode(kal_bool enable)
{
kal_uint8 temp;
temp = read_cmos_sensor(0x15);
if (!enable)
{
write_cmos_sensor(0xff, 0x01);
write_cmos_sensor(0x11, 0x00); //(0x11, 0x00)
}
else
{
write_cmos_sensor(0xff, 0x01);
write_cmos_sensor(0x11, 0x02); //(0x11, 0x00)
}
}
/*****************************************************************************
* FUNCTION
* set_OV2640_flashlight
* DESCRIPTION
* turn on/off OV2640 flashlight .
* PARAMETERS
* enable [IN]
* RETURNS
* void
*****************************************************************************/
void set_OV2640_flashlight(kal_bool enable)
{
}
/*****************************************************************************
* FUNCTION
* set_OV2640_param_zoom
* DESCRIPTION
* OV2640 zoom setting.
* PARAMETERS
* para [IN]
* RETURNS
* void
*****************************************************************************/
kal_uint32 set_OV2640_param_zoom(kal_uint32 para)
{
return KAL_FALSE;
}
/*****************************************************************************
* FUNCTION
* set_OV2640_param_contrast
* DESCRIPTION
* OV2640 contrast setting.
* PARAMETERS
* para [IN]
* RETURNS
* void
*****************************************************************************/
kal_uint32 set_OV2640_param_contrast(kal_uint32 para)
{
return KAL_FALSE;
}
/*****************************************************************************
* FUNCTION
* set_OV2640_param_brightness
* DESCRIPTION
* OV2640 brightness setting.
* PARAMETERS
* para [IN]
* RETURNS
* void
*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -