📄 ov7660.c
字号:
{0x42,0x74,0x40},
{0x42,0x75,0x40},
{0x42,0x76,0x40},
{0x42,0x77,0x40},
{0x42,0x78,0x3e},
{0x42,0x79,0x3c},
{0x42,0x7a,0x3c},
{0x42,0x7b,0x28},
{0x42,0x7c,0x08},
{0x42,0x7d,0x12},
{0x42,0x7e,0x21},
{0x42,0x7f,0x35},
{0x42,0x80,0x3e},
{0x42,0x81,0x46},
{0x42,0x82,0x4f},
{0x42,0x83,0x57},
{0x42,0x84,0x5f},
{0x42,0x85,0x67},
{0x42,0x86,0x77},
{0x42,0x87,0x87},
{0x42,0x88,0xa6},
{0x42,0x89,0xc4},
{0x42,0x8a,0xe2},
{0xff,0xff,0xff},
};
const uint8 ovt7660_CONTRAST_1 [][3] =
{
{0x42,0x6c,0x70},
{0x42,0x6d,0x80},
{0x42,0x6e,0x40},
{0x42,0x6f,0x54},
{0x42,0x70,0x58},
{0x42,0x71,0x60},
{0x42,0x72,0x60},
{0x42,0x73,0x60},
{0x42,0x74,0x50},
{0x42,0x75,0x58},
{0x42,0x76,0x44},
{0x42,0x77,0x3c},
{0x42,0x78,0x30},
{0x42,0x79,0x28},
{0x42,0x7a,0x22},
{0x42,0x7b,0x44},
{0x42,0x7c,0x07},
{0x42,0x7d,0x0f},
{0x42,0x7e,0x17},
{0x42,0x7f,0x2c},
{0x42,0x80,0x37},
{0x42,0x81,0x43},
{0x42,0x82,0x4f},
{0x42,0x83,0x5b},
{0x42,0x84,0x65},
{0x42,0x85,0x70},
{0x42,0x86,0x81},
{0x42,0x87,0x90},
{0x42,0x88,0xa8},
{0x42,0x89,0xbc},
{0x42,0x8a,0xcd},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_CONTRAST_2 [][3] =
{
{0x42,0x6c,0x10},
{0x42,0x6d,0x10},
{0x42,0x6e,0x18},
{0x42,0x6f,0x5c},
{0x42,0x70,0x90},
{0x42,0x71,0x90},
{0x42,0x72,0x90},
{0x42,0x73,0x90},
{0x42,0x74,0x80},
{0x42,0x75,0x80},
{0x42,0x76,0x60},
{0x42,0x77,0x5c},
{0x42,0x78,0x44},
{0x42,0x79,0x24},
{0x42,0x7a,0x1a},
{0x42,0x7b,0x10},
{0x42,0x7c,0x01},
{0x42,0x7d,0x02},
{0x42,0x7e,0x05},
{0x42,0x7f,0x1c},
{0x42,0x80,0x2e},
{0x42,0x81,0x40},
{0x42,0x82,0x52},
{0x42,0x83,0x64},
{0x42,0x84,0x74},
{0x42,0x85,0x84},
{0x42,0x86,0x9c},
{0x42,0x87,0xb3},
{0x42,0x88,0xd5},
{0x42,0x89,0xe7},
{0x42,0x8a,0xf4},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_CONTRAST_3 [][3] =
{
{0x42,0x6c,0x20},
{0x42,0x6d,0x40},
{0x42,0x6e,0x10},
{0x42,0x6f,0x38},
{0x42,0x70,0x80},
{0x42,0x71,0xe0},
{0x42,0x72,0xd0},
{0x42,0x73,0xe8},
{0x42,0x74,0xa0},
{0x42,0x75,0x80},
{0x42,0x76,0x80},
{0x42,0x77,0x54},
{0x42,0x78,0x30},
{0x42,0x79,0x22},
{0x42,0x7a,0x08},
{0x42,0x7b,0x01},
{0x42,0x7c,0x02},
{0x42,0x7d,0x06},
{0x42,0x7e,0x08},
{0x42,0x7f,0x16},
{0x42,0x80,0x26},
{0x42,0x81,0x42},
{0x42,0x82,0x5c},
{0x42,0x83,0x79},
{0x42,0x84,0x8d},
{0x42,0x85,0x9d},
{0x42,0x86,0xbd},
{0x42,0x87,0xd2},
{0x42,0x88,0xea},
{0x42,0x89,0xfb},
{0x42,0x8a,0xff},
{0xff, 0xff,0xff},
};
const uint8 ovt7660_SENSOR_SEPIA_NORMAL [][3] =
{
{0x42, 0x3a, 0x01},//01
{0x42, 0x67, 0x80},
{0x42, 0x68, 0x80},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_SENSOR_SEPIA_BLACKWHITE [][3] =
{
{0x42, 0x3a, 0x11},
{0x42, 0x67, 0x80},
{0x42, 0x68, 0x80},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_SENSOR_SEPIA_BLUE [][3] =
{
{0x42, 0x3a, 0x11},
{0x42, 0x67, 0xc0},
{0x42, 0x68, 0x80},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_SENSOR_SEPIA_GREEN [][3] =
{
{0x42, 0x3a, 0x11},
{0x42, 0x67, 0x40},
{0x42, 0x68, 0x40},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_SENSOR_SEPIA_RED [][3] =
{
{0x42, 0x3a, 0x11},
{0x42, 0x67, 0x80},
{0x42, 0x68, 0xc0},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_SENSOR_SEPIA_CANVAS [][3] =
{
{0x42, 0x3a, 0x11},
{0x42, 0x67, 0x40},
{0x42, 0x68, 0xb0},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_SENSOR_SEPIA_NEGATIVE [][3] =
{
{0x42, 0x3a, 0x21},
{0x42, 0x67, 0x80},
{0x42, 0x68, 0x80},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_VFLIP_ENABLE[][3] =
{
{0x42, 0x1e, 0x11},
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_VFLIP_DISABLE[][3] =
{
{0x42, 0x1e, 0x01},
{0xff, 0xff, 0xff},
};
const SENSOR_SEQUENCE_T ovt_7660_effect_seq[] =
{//sequence for different mode/
{
SENSOR_EFFECT_BRIGHTNESS_0,
0,
ovt7660_BRIGHTNESS_0,
},
{
SENSOR_EFFECT_BRIGHTNESS_1,
0,
ovt7660_BRIGHTNESS_1,
},
{
SENSOR_EFFECT_BRIGHTNESS_2,
0,
ovt7660_BRIGHTNESS_2,
},
{
SENSOR_EFFECT_BRIGHTNESS_3,
0,
ovt7660_BRIGHTNESS_3,
},
//decrease brightness level
{
SENSOR_EFFECT_CONTRAST_0,
0,
ovt7660_CONTRAST_0,
},
{
SENSOR_EFFECT_CONTRAST_1,
0,
ovt7660_CONTRAST_1,
},
{
SENSOR_EFFECT_CONTRAST_2,
0,
ovt7660_CONTRAST_2,
},
{
SENSOR_EFFECT_CONTRAST_3,
0,
ovt7660_CONTRAST_3,
},
//decrease contrast level
{
SENSOR_EFFECT_SEPIA_NORMAL,
0,
ovt7660_SENSOR_SEPIA_NORMAL,
},
{
SENSOR_EFFECT_SEPIA_BLACKWHITE,
0,
ovt7660_SENSOR_SEPIA_BLACKWHITE,
},
{
SENSOR_EFFECT_SEPIA_BLUE,
0,
ovt7660_SENSOR_SEPIA_BLUE,
},
{
SENSOR_EFFECT_SEPIA_GREEN,
0,
ovt7660_SENSOR_SEPIA_GREEN,
},
{
SENSOR_EFFECT_SEPIA_RED,
0,
ovt7660_SENSOR_SEPIA_RED,
},
{
SENSOR_EFFECT_SEPIA_CANVAS,
0,
ovt7660_SENSOR_SEPIA_CANVAS,
},
{
SENSOR_EFFECT_SEPIA_NEGATIVE,
0,
ovt7660_SENSOR_SEPIA_NEGATIVE,
},
{
SENSOR_EFFECT_VFLIP_ENABLE,
0,
ovt7660_VFLIP_ENABLE,
},
{
SENSOR_EFFECT_VFLIP_DISABLE,
0,
ovt7660_VFLIP_DISABLE,
},
{0, 0, 0}
};
LOCAL SENSOR_SPEC_T s_ov7660_spec =
{
0, //Polarity of Hsync 0: Low 1: High
1, //Polarity of Vsync 0: Low 1: High
0, //Polarity of Pixel
//0: Positive edge to strobe data
//1: Negative edge to strobe datah
4, //Frame number to capture in single mode
1, //Sensor Y data translation
1, //Sensor UV data translation
0x42, //ov7660 write address
0x43, //ov7660 read address
0,
3, //sequence length, so must be arranged by {addr, reg, val}
0, // reserved_1
OV7660_Reset, //reset_func,
OV7660_PowerDown, //powerdown_func,
OV7660_Probe, //verify function(check if sensor is equipped correctly)
OV7660_CfgParam, //function to config ov7660 parameter
OV7660_ChangeAE, //function to change AE value of sensor
OV7660_ReadGainExposure, // read back sensor gain & exposure value
OV7660_SetGainExposure, // set back sensor gain & exposure value
ovt_7660_mode_seq,
ovt_7660_effect_seq
};
LOCAL DC_LCD_SPEC_T s_main_lcd_spec =
{
LCD_WIDTH,
LCD_HEIGHT,
0,
};
LOCAL DC_LCD_SPEC_T s_sub_lcd_spec =
{
SUBLCD_WIDTH,
SUBLCD_HEIGHT,
2,
};
/******************************************************************************/
// Description: reg sensor and lcd spec to DCAM module
// Author: bruce.chi
// Input: none
// Output:
// Note: this should be called after DCAM_init and DC_Open
/******************************************************************************/
void DCAM_InitSensorAndLCD(void)
{
DC_RegisterLcdSpec(0,&s_main_lcd_spec);
DC_RegisterLcdSpec(1,&s_sub_lcd_spec);
DC_RegisterSensorSpec(&s_ov7660_spec);
}
/******************************************************************************
** Description: sensor config parameter **
** Author: jing.li **
** Input: cfg_mode config sensormode or effect, **
** SCI_TRUE to config sensor mode, **
** other to config sensor effect **
** i_sequence sequence id **
** Output: none **
** Return: SCI_SUCCESS successful **
** SCI_ERROR failed **
** Note: none **
*******************************************************************************/
LOCAL int OV7660_CfgParam(
BOOLEAN cfg_mode,
DC_SENSOR_MODE_E i_sequence)
{
//uint8 tmp = 0;
uint32 ret = 0;
//uint32 i = 0;
uint8 count=0;
const uint8 (*tmp_sequence);
SENSOR_SEQUENCE_T *p_sequence_tmp;
if(SCI_TRUE == cfg_mode)
{
p_sequence_tmp = (SENSOR_SEQUENCE_T *)ovt_7660_mode_seq;
}
else
{
//return SCI_SUCCESS;
p_sequence_tmp = (SENSOR_SEQUENCE_T *)ovt_7660_effect_seq;
}
while(p_sequence_tmp->i_name != 0)
{
if(p_sequence_tmp->i_name == i_sequence)
{
tmp_sequence = (const uint8 *)p_sequence_tmp->pp_sequence;
while(*tmp_sequence!=0xff)
{
count = 0;
//retry 3 times when config sensor
do
{
ret = I2C_WriteCmdArr(
*tmp_sequence,
(uint8 *)(tmp_sequence+1),
s_ov7660_spec.i2c_cmd_array_len-1,
s_ov7660_spec.i2c_ack
);
if(count >= 2)
{
SCI_TRACE_LOW("DCAM: I2C error id = %d", ret);
return SCI_ERROR;
}
else
{
count++;
}
} while(ret != 0);
//The code below is important for debug.
//It will read back sensor register value.
//pls not to delete it.
#if 0
tmp = 0;
I2C_WriteCmd(*tmp_sequence,
*(tmp_sequence+1),
s_ov7660_spec.i2c_ack);
for(i = 0; i<(s_ov7660_spec.i2c_cmd_array_len-2); i++)
{
I2C_ReadCmd(*tmp_sequence,
&tmp,
s_ov7660_spec.i2c_ack);
SCI_TRACE_LOW("DCAM: sensor register value %x", tmp);
}
#endif
//jing.li: cr52793; stablize color when preview
if( (0x12 == *(tmp_sequence+1)) && (0x80 == *(tmp_sequence+2)))
{
OV7660_DELAY_MS(5);
}
if( (0x13 == *(tmp_sequence+1)) )//&& (0xf7 == *(tmp_sequence+2))
{
switch(*(tmp_sequence+2)){
case 0xf5:
OV7660_DELAY_MS(700);
case 0xf7:
OV7660_DELAY_MS(100);
default:
break;
}
}
tmp_sequence = tmp_sequence + (s_ov7660_spec.i2c_cmd_array_len );
OV7660_DELAY_MS(1);
}
return SCI_SUCCESS;
}
p_sequence_tmp++;
}
return SCI_ERROR;
}
/******************************************************************************
** Description: change sensor AE value **
** Author: jing.li **
** Input: none **
** Output: none **
** Return: SCI_SUCCESS successful **
** SCI_ERROR failed **
** Note: none **
*******************************************************************************/
LOCAL uint32 OV7660_ChangeAE(void)
{
uint8 tmp;
uint16 aec = 0;
uint32 ret = 0;
OV7660_WriteReg(0x11, 0x81);
//OV7660_DELAY_MS(300);
//bit[1:0] of 0x04 is AEC[1:0]
tmp = OV7660_ReadReg(0x04);
aec |= (tmp&0x3);
//bit[7:0] of 0x10 is AEC[9:2]
tmp = OV7660_ReadReg(0x10);
aec |= (tmp<<2);
//bit[5:0] of 0x10 is AEC[15:10]
tmp = OV7660_ReadReg(0xa1);
aec |= ((tmp & 0xef) << 10);
//shutdown AEC & AGC
tmp = OV7660_ReadReg(0x13);
ret = OV7660_WriteReg(0x13, (tmp&0xfa));
//half aec
aec >>= 1;
//set aec back to register
tmp = (uint8)(aec&0x3);
OV7660_WriteReg(0x04, tmp);
tmp = (uint8)((aec&0x3fc)>>2);
OV7660_WriteReg(0x10, tmp);
tmp = (uint8)((aec&0xfc)>>10);
OV7660_WriteReg(0xa1, tmp);
return SCI_SUCCESS;
}
/******************************************************************************
** Description: read sensor Gain & Exposure value in current sensor mode **
** Author: jing.li **
** Input: e_sensor_mode: current sensor mode **
** Output: none **
** Return: SCI_SUCCESS successful **
** SCI_ERROR failed **
** Note: none **
*******************************************************************************/
LOCAL uint32 OV7660_ReadGainExposure(DC_SENSOR_MODE_E e_sensor_mode)
{
return SCI_SUCCESS;
}
/******************************************************************************
** Description: set back sensor Gain & Exposure value **
** Author: jing.li **
** Input: e_sensor_mode: current sensor mode **
** Output: none **
** Return: SCI_SUCCESS successful **
** SCI_ERROR failed **
** Note: none **
*******************************************************************************/
LOCAL uint32 OV7660_SetGainExposure(DC_SENSOR_MODE_E e_sensor_mode)
{
return SCI_SUCCESS;
}
/******************************************************************************
** Description: calc Gain & Exposure according to OV algorithm **
** Author: jing.li **
** Input: e_sensor_mode: current sensor mode **
** u16_AEC_val: aec value array **
** u8_Gain: gain value **
** Output: none **
** Return: none **
** Note: none **
*******************************************************************************/
LOCAL void OV_CalcGainExposure(int e_sensor_mode, uint16 *u16_AEC_val, uint8 u8_Gain)
{
return;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -