📄 image_sensor_ov7690.c
字号:
case Phoenix_F28:
//;;===Lens Correction==;
write_cmos_sensor(0x85,0x90);
write_cmos_sensor(0x86,0x18);
write_cmos_sensor(0x87,0xb0);
write_cmos_sensor(0x88,0xA0);
write_cmos_sensor(0x89,0x32);
write_cmos_sensor(0x8a,0x2c);
write_cmos_sensor(0x8b,0x30);
break;
case Phoenix_F24:
//;;===Lens Correction==;
write_cmos_sensor(0x85,0x90);
write_cmos_sensor(0x86,0x18);
write_cmos_sensor(0x87,0x90);
write_cmos_sensor(0x88,0x00);
write_cmos_sensor(0x89,0x32);
write_cmos_sensor(0x8a,0x2c);
write_cmos_sensor(0x8b,0x30);
break;
case Dongya_F24:
//;;===Lens Correction==;
write_cmos_sensor(0x85,0x90);
write_cmos_sensor(0x86,0x18);
write_cmos_sensor(0x87,0x10);
write_cmos_sensor(0x88,0x00);
write_cmos_sensor(0x89,0x32);
write_cmos_sensor(0x8a,0x2c);
write_cmos_sensor(0x8b,0x30);
break;
default:
return;
}
}
/*****************************************************************************
* FUNCTION
* init_OV7690
* DESCRIPTION
* This function initialize the registers of CMOS sensor and ISP control register.
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
kal_int8 init_OV7690(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
char buffer[40] = {0};
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
cis_module_power_on(KAL_TRUE); /* Power On CIS Power */
kal_sleep_task(2); /* To wait for Stable Power */
RESET_CMOS_SENSOR_MODE2; /* High - reset, Low - normal. */
SET_CMOS_CLOCK_POLARITY_LOW;
SET_VSYNC_POLARITY_LOW;
SET_HSYNC_POLARITY_LOW;
ENABLE_CAMERA_INDATA_FORMAT;
SET_CAMERA_INPUT_TYPE(INPUT_YUV422);
ENABLE_CAMERA_TG_CLK_48M;
UPLL_Enable(UPLL_OWNER_ISP);
set_isp_driving_current(camera_para.SENSOR.reg[CMMCLK_CURRENT_INDEX].para);
/* Reset Sensor */
kal_sleep_task(20);
write_cmos_sensor(0x12, 0x80);
kal_sleep_task(20);
sensor_id = (read_cmos_sensor(0x0A) << 8) | read_cmos_sensor(0x0B);
//kal_prompt_trace(MOD_ENG, "Sensor ID = %x", sensor_id);
if(sensor_id != OV7690_SENSOR_ID)
return -1;
/* Initail Sequence Write In. */
init_cmos_sensor();
kal_sleep_task(30);
return 1;
} /* init_cmos_sensor() */
/*****************************************************************************
* FUNCTION
* power_off_OV7690
* DESCRIPTION
* This function is to turn off sensor module power.
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
void power_off_OV7690(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
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 */
} /* power_off_OV7690 */
/*****************************************************************************
* FUNCTION
* get_OV7690_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_OV7690_id(kal_uint8 *sensor_write_id, kal_uint8 *sensor_read_id)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
*sensor_write_id = OV76X0_WRITE_ID;
*sensor_read_id = OV76X0_READ_ID;
} /* get_OV7690_id */
/*****************************************************************************
* FUNCTION
* get_OV7690_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_OV7690_size(kal_uint16 *sensor_width, kal_uint16 *sensor_height)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
*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_OV7690_size */
/*****************************************************************************
* FUNCTION
* get_OV7690_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_OV7690_period(kal_uint16 *pixel_number, kal_uint16 *line_number)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
*pixel_number = 656; /* pixel numbers in one period of HSYNC */
*line_number = 484; /* line numbers in one period of VSYNC */
} /* get_OV7690_period */
void write_OV7690_extra_line(kal_uint16 extra_line)
{
write_cmos_sensor(0x2d, extra_line & 0xFF);
write_cmos_sensor(0x2e, (extra_line >> 8) & 0xFF);
}
/*****************************************************************************
* FUNCTION
* OV7690_preview
* DESCRIPTION
*
* PARAMETERS
* image_window [?] [?]
* sensor_config_data [?] [?]
* RETURNS
* void
*****************************************************************************/
extern kal_uint16 xieyang1,xieyang2;
void OV7690_preview(image_sensor_exposure_window_struct *image_window, image_sensor_config_struct *sensor_config_data)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 iTemp;
char buffer[40] = {0};
volatile kal_uint32 shutter = exposure_lines;
kal_uint32 extra_line;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
sensor_cap_state = KAL_FALSE;
g_bMJPEG_mode = KAL_FALSE;
// 1. Sensor's clock control register setting may cause 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, 0x01); // 12M 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;
write_cmos_sensor(0x11, 0x01);
SET_TG_OUTPUT_CLK_DIVIDER(3);
SET_CMOS_RISING_EDGE(0);
SET_CMOS_FALLING_EDGE(2);
ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
write_cmos_sensor(0x15,read_cmos_sensor(0x15)&0x7f);//Disable Night mode.
dummy_pixels = 0;
dummy_lines = 0;
}
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;
dummy_pixels = 0;
dummy_lines = 0;
}
else
{
MPEG4_encode_mode = KAL_FALSE;
write_cmos_sensor(0x15,read_cmos_sensor(0x15)|0x80);//Enable auto frame
/* 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;
dummy_pixels = 0;
dummy_lines = 0;
}
SET_CAMERA_INPUT_ORDER(0);
iTemp = read_cmos_sensor(0x0C) & ~0xC0;
switch (sensor_config_data->image_mirror)
{
case IMAGE_NORMAL:
write_cmos_sensor(0x0C, iTemp);
break;
case IMAGE_HV_MIRROR:
write_cmos_sensor(0x0C, iTemp | 0xC0);
break;
}
image_window->grab_start_x = 0;// xieyang1; // 1;
image_window->grab_start_y = 0; // xieyang2; // 2;
image_window->exposure_window_width = IMAGE_SENSOR_VGA_WIDTH-16;
image_window->exposure_window_height = IMAGE_SENSOR_VGA_HEIGHT-1;
set_OV7690_dummy(dummy_pixels, dummy_lines);
if (sensor_config_data->isp_op_mode == ISP_MJPEG_ENCODE_MODE)
{
sensor_config_data->sensor_frame_rate = 100; // 10fps
}
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(80);
} /* OV7690_preview */
/*****************************************************************************
* FUNCTION
* OV7690_capture
* DESCRIPTION
*
* PARAMETERS
* image_window [?] [?]
* sensor_config_data [?] [?]
* RETURNS
* void
*****************************************************************************/
void OV7690_capture(image_sensor_exposure_window_struct *image_window, image_sensor_config_struct *sensor_config_data)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
volatile kal_uint32 shutter = exposure_lines;
kal_uint32 extra_line;
char buffer[40] = {0};
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
sensor_cap_state = KAL_TRUE;
if (MPEG4_encode_mode)
ASSERT(0);
write_cmos_sensor(0x13, 0xf0); //close AE/AG 0xe8
shutter = read_OV7690_shutter();
extra_line = (read_cmos_sensor(0x2e) << 8) | read_cmos_sensor(0x2d);
sensor_global_gain=read_OV7690_gain();
if (!(sensor_config_data->frame_rate == 0xF0)) /* If not WEBCAM mode. */
{
if (image_window->image_target_width >= 1280 && image_window->image_target_height >= 960)
{
write_cmos_sensor(0x11, 5);
shutter /= 3;
extra_line /= 3;
dummy_pixels = 0;
dummy_lines = 0;
}
else
{
shutter/=1;
extra_line/=1;
dummy_pixels = 0;
dummy_lines = 0;
}
}
else /* Webcam */
{
// write_cmos_sensor(0x11, 1);
SET_TG_OUTPUT_CLK_DIVIDER(1);// org:3
SET_CMOS_RISING_EDGE(0);
SET_CMOS_FALLING_EDGE(1);// org:1
ENABLE_CAMERA_PIXEL_CLKIN_ENABLE;
write_cmos_sensor(0x13, 0xf7);
}
image_window->grab_start_x =0; //org: 1;
image_window->grab_start_y =0; //org: 2;
image_window->exposure_window_width = IMAGE_SENSOR_VGA_WIDTH-16;
image_window->exposure_window_height = IMAGE_SENSOR_VGA_HEIGHT-1;
if (shutter < 1)
shutter = 2;
set_OV7690_dummy(dummy_pixels, dummy_lines);
write_OV7690_shutter(shutter);
write_OV7690_extra_line(extra_line);
write_OV7690_gain(sensor_global_gain);
} /* OV7690_capture() */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -