📄 ov7660.c
字号:
/******************************************************************************
** File Name: DigitalCamera_M.c *
** Author: bruce.chi *
** Date: 09/21/2005 *
** Copyright: 2004 Spreadtrum, Incoporated. All Rights Reserved. *
** Description: implementation of digital camera register interface *
******************************************************************************
******************************************************************************
** Edit History *
** ------------------------------------------------------------------------- *
** DATE NAME DESCRIPTION *
** 09/21/2005 bruce.chi Create. *
******************************************************************************/
#ifndef _DIGITAL_CAMERA_M_C_
#define _DIGITAL_CAMERA_M_C_
/**--------------------------------------------------------------------------*
** Include Files *
**--------------------------------------------------------------------------*/
#include "DigitalCamera.h"
//#include "dc_context.h"
#include "i2c_drv.h"
#include "sci_types.h"
#include "os_api.h"
#include "tb_comm.h"
#include "sc6600M_reg_global.h"
#include "sc6600m_reg.h"
#include "arm_reg.h"
#include "prod_dc.h"
#include "lcd_cfg.h"
/**---------------------------------------------------------------------------*
** Const variables *
**---------------------------------------------------------------------------*/
#define OV7660_I2C_ADDR_W 0x42
#define OV7660_I2C_ADDR_R 0x43
#define OV7660_I2C_ACK 0x0
/**---------------------------------------------------------------------------*
** Macro define *
**---------------------------------------------------------------------------*/
#define OV7660_DELAY_MS(ms) {\
uint32 end = SCI_GetTickCount() + ms;\
while (SCI_GetTickCount() < end)\
;\
}
#define SENSOR_MODE_NUM 3 // QCIF, QVGA, VGA
#define GET_MAX_EXPOSURE_LINES(sensor_mode) \
s_u16_Max_Exposure_lines[(sensor_mode-1)/2]
#define GET_LINES_10MS(sensor_mode) \
s_uint16_Lines_10ms[(sensor_mode-1)/2]
#define GET_FRAME_RATE(sensor_mode) \
s_u8_frame_rate[(sensor_mode-1)/2]
#define FIXED_PREVIEW_MODE SENSOR_MODE_640X480_NORMAL
/**---------------------------------------------------------------------------*
** Const variables *
**---------------------------------------------------------------------------*/
LOCAL uint16 s_u16_Capture_Gain = 0;
LOCAL uint16 s_u16_Capture_Exposure = 0;
LOCAL uint8 s_u8_AGC = 0; // AGC value
LOCAL uint16 s_u16_AEC_val[3] = {0, 0, 0}; // AEC value
LOCAL uint8 s_u8_AWB_val[3] = {0, 0, 0}; // AWB value
// OV give the parameters
LOCAL uint16 s_u16_Max_Exposure_lines[SENSOR_MODE_NUM] =
{
0, // QCIF: not care
250, // QVGA
500, // VGA
}; // sort according to DC_SENSOR_MODE_E
LOCAL uint16 s_uint16_Lines_10ms[SENSOR_MODE_NUM] =
{
0, // QCIF: not care
37, // QVGA
75, // VGA
};
LOCAL uint8 s_u8_frame_rate[SENSOR_MODE_NUM] =
{
0, // QCIF: not care
30, // QVGA
30, // VGA
};
/**---------------------------------------------------------------------------*
** Extern Item *
**---------------------------------------------------------------------------*/
extern void GPIO_SetSensorPwdn(BOOLEAN b_on);
extern void GPIO_ResetSensor(BOOLEAN b_on);
extern void DC_RegisterGpioControl(uint8 gpio0, uint8 gpio1, uint8 gpio2, uint8 gpio3);
/**---------------------------------------------------------------------------*
** Local Function Prototypes *
**---------------------------------------------------------------------------*/
/******************************************************************************
** 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);
/******************************************************************************
** 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);
/******************************************************************************
** Description: read sensor Gain & Exposure value in current sensor mode **
** Author: jing.li **
** Input: pe_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);
/******************************************************************************
** 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);
/******************************************************************************
** 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);
/**---------------------------------------------------------------------------*
** Function Definitions *
**---------------------------------------------------------------------------*/
LOCAL uint32 OV7660_WriteReg(uint8 reg, uint8 value)
{
uint8 i2c_cmd[2];
uint32 ret;
uint32 count = 0;
i2c_cmd[0] = reg;
i2c_cmd[1] = value;
SCI_TRACE_LOW("OV7660_WriteReg: reg: 0x%02x, write_val: 0x%02x",i2c_cmd[0],i2c_cmd[1]);
do
{
ret = I2C_WriteCmdArr(OV7660_I2C_ADDR_W,
i2c_cmd,
2,
OV7660_I2C_ACK
);
if(count >= 2)
{
SCI_TRACE_LOW("DCAM: I2C error id = %d", ret);
return SCI_ERROR;
}
else
{
count++;
}
}while(ret != 0);
return SCI_SUCCESS;
}
LOCAL uint8 OV7660_ReadReg(uint8 reg)
{
uint8 ret;
I2C_WriteCmd(OV7660_I2C_ADDR_W, reg, OV7660_I2C_ACK);
I2C_ReadCmdArr(OV7660_I2C_ADDR_R, &ret, 1, OV7660_I2C_ACK);
SCI_TRACE_LOW("reg:%02x, read_val:%02x", reg, ret);
return ret;
}
/*****************************************************************************/
// Description: get sensor max mode size
// Author: Bruce.Chi
// Note:
/*****************************************************************************/
PUBLIC PROD_SENSOR_MAX_MODE_E PRODDC_GetSensorMaxMode(void)
{
//ov7600
return SENSOR_MODEMAX_640_480;
}
/******************************************************************************/
// Description: sensor power down function
// Author: bruce.chi
// Input: none
// Output: result
// Return: 0 successful
// others failed
// Note:
/******************************************************************************/
LOCAL int OV7660_PowerDown(void)
{
GPIO_SetSensorPwdn(SCI_TRUE);
GPIO_ResetSensor(SCI_FALSE);
return SCI_SUCCESS;
}
/******************************************************************************/
// Description: sensor power on function
// Author: bruce.chi
// Input: none
// Output: result
// Return: 0 successful
// others failed
// Note:
/******************************************************************************/
LOCAL int OV7660_Reset(void)
{
GPIO_SetSensorPwdn(SCI_FALSE);
GPIO_ResetSensor(SCI_TRUE);
return SCI_SUCCESS;
}
/******************************************************************************/
// Description: sensor probe function
// Author: benny.zou
// Input: none
// Output: result
// Return: 0 successful
// others failed
// Note: this function only to check whether sensor is work, not identify
// whitch it is!!
/******************************************************************************/
LOCAL int OV7660_Probe(void)
{
uint8 reg[4] = {0x0A, 0x0B, 0x1C, 0x1D};
uint8 value[4] = {0x76, 0x60, 0x7f, 0xA2};
uint8 ret = 0;
uint32 i;
uint8 err_cnt = 0;
for(i = 0; i<4; )
{
ret = OV7660_ReadReg(reg[i]);
if( ret != value[i])
{
err_cnt++;
if(err_cnt>3)
{
return SCI_ERROR;
}
else
{
SCI_Sleep(10);
continue;
}
}
err_cnt = 0;
i++;
}
return SCI_SUCCESS;
}
const uint8 ovt7660_640X480_NORMAL[][3] =
{
{0x42, 0x12, 0x80},
{0x42, 0x11, 0x80},//0x81
{0x42, 0x92, 0x00},
{0x42, 0x93, 0x00},
{0x42, 0x9d, 0x4c},
{0x42, 0x9e, 0x3f},
{0x42, 0x3b, 0x02},//0x02 for 60hz
{0x42, 0x13, 0xf0},
{0x42, 0x10, 0x00},
{0x42, 0x00, 0x00},
{0x42, 0x01, 0x80},
{0x42, 0x02, 0x80},
//{0x42, 0x13, 0xf7},
{0x42, 0x13, 0xf5},// jing.li:stablize color
{0x42, 0x12, 0x00},
{0x42, 0x04, 0x00},
{0x42, 0x18, 0x01},
{0x42, 0x17, 0x13},
{0x42, 0x32, 0x92},
{0x42, 0x19, 0x02},
{0x42, 0x1a, 0x7a},
{0x42, 0x03, 0x00},
{0x42, 0x0e, 0x84},
{0x42, 0x0f, 0x62},
{0x42, 0x15, 0x02},
{0x42, 0x16, 0x02},
{0x42, 0x1b, 0x01},
{0x42, 0x1e, 0x01},
{0x42, 0x29, 0x3c}, //20 for internal regulator
{0x42, 0x33, 0x00},
{0x42, 0x34, 0x07},
{0x42, 0x35, 0x84},
{0x42, 0x36, 0x00},
{0x42, 0x38, 0x13},
{0x42, 0x39, 0x43},
{0x42, 0x3a, 0x00},//00
{0x42, 0x3c, 0x6c},
{0x42, 0x3d, 0x90},
{0x42, 0x3f, 0x29},
{0x42, 0x40, 0xc1},
{0x42, 0x41, 0x20},
{0x42, 0x6b, 0x0a},
{0x42, 0xa1, 0xc8},
{0x42, 0x69, 0x80},
{0x42, 0x43, 0xf0},
{0x42, 0x44, 0x10},
{0x42, 0x45, 0x78},
{0x42, 0x46, 0xa8},
{0x42, 0x47, 0x60},
{0x42, 0x48, 0x80},
{0x42, 0x59, 0xba},
{0x42, 0x5a, 0x9a},
{0x42, 0x5b, 0x22},
{0x42, 0x5c, 0xb9},
{0x42, 0x5d, 0x9b},
{0x42, 0x5e, 0x10},
{0x42, 0x5f, 0xe0},
{0x42, 0x60, 0x85}, //85//05 for advanced AWB
{0x42, 0x61, 0x60},
{0x42, 0x9f, 0x9d},
{0x42, 0xa0, 0xa0},
{0x42, 0x4f, 0x66},
{0x42, 0x50, 0x6b},
{0x42, 0x51, 0x05},
{0x42, 0x52, 0x19},
{0x42, 0x53, 0x40},
{0x42, 0x54, 0x59},
{0x42, 0x55, 0x40},
{0x42, 0x56, 0x40},
{0x42, 0x57, 0x40},
{0x42, 0x58, 0x0d},
{0x42, 0x8b, 0xcc},
{0x42, 0x8c, 0xcc},
{0x42, 0x8d, 0xcf},
{0x42, 0x6c, 0x40},
{0x42, 0x6d, 0x30},
{0x42, 0x6e, 0x4b},
{0x42, 0x6f, 0x60},
{0x42, 0x70, 0x70},
{0x42, 0x71, 0x70},
{0x42, 0x72, 0x70},
{0x42, 0x73, 0x70},
{0x42, 0x74, 0x60},
{0x42, 0x75, 0x60},
{0x42, 0x76, 0x50},
{0x42, 0x77, 0x48},
{0x42, 0x78, 0x3a},
{0x42, 0x79, 0x2e},
{0x42, 0x7a, 0x28},
{0x42, 0x7b, 0x22},
{0x42, 0x7c, 0x04},
{0x42, 0x7d, 0x07},
{0x42, 0x7e, 0x10},
{0x42, 0x7f, 0x28},
{0x42, 0x80, 0x36},
{0x42, 0x81, 0x44},
{0x42, 0x82, 0x52},
{0x42, 0x83, 0x60},
{0x42, 0x84, 0x6c},
{0x42, 0x85, 0x78},
{0x42, 0x86, 0x8c},
{0x42, 0x87, 0x9e},
{0x42, 0x88, 0xbb},
{0x42, 0x89, 0xd2},
{0x42, 0x8a, 0xe6},
{0x42, 0x14, 0x2e},
{0x42, 0x24, 0x68},
{0x42, 0x25, 0x5C},
{0x42, 0x13, 0xf7},// jing.li:stablize color
{0xff, 0xff, 0xff}, //terminated symbol,end of the sequece!!!!
};
const uint8 ovt7660_640X480_NIGHT[][3] =
{
{0x42, 0x12, 0x80},
{0x42, 0x11, 0x80},//0x81
{0x42, 0x92, 0x00},
{0x42, 0x93, 0x00},
{0x42, 0x9d, 0x4c},
{0x42, 0x9e, 0x3f},
{0x42, 0x3b, 0x0a},//0x0a for 50hz
{0x42, 0x13, 0xf0},
{0x42, 0x10, 0x00},
{0x42, 0x00, 0x00},
{0x42, 0x01, 0x80},
{0x42, 0x02, 0x80},
//{0x42, 0x13, 0xf7},
{0x42, 0x13, 0xf5},// jing.li:stablize color
{0x42, 0x12, 0x00},
{0x42, 0x04, 0x00},
{0x42, 0x18, 0x01},
{0x42, 0x17, 0x13},
{0x42, 0x32, 0x92},
{0x42, 0x19, 0x02},
{0x42, 0x1a, 0x7a},
{0x42, 0x03, 0x00},
{0x42, 0x0e, 0x84},
{0x42, 0x0f, 0x62},
{0x42, 0x15, 0x02},
{0x42, 0x16, 0x02},
{0x42, 0x1b, 0x01},
{0x42, 0x1e, 0x01},
{0x42, 0x29, 0x3c}, //20 for internal regulator
{0x42, 0x33, 0x00},
{0x42, 0x34, 0x07},
{0x42, 0x35, 0x84},
{0x42, 0x36, 0x00},
{0x42, 0x38, 0x13},
{0x42, 0x39, 0x43},
{0x42, 0x3a, 0x00}, //00
{0x42, 0x3c, 0x6c},
{0x42, 0x3d, 0x90},
{0x42, 0x3f, 0x29},
{0x42, 0x40, 0xc1},
{0x42, 0x41, 0x20},
{0x42, 0x6b, 0x0a},
{0x42, 0xa1, 0xc8},
{0x42, 0x69, 0x80},
{0x42, 0x43, 0xf0},
{0x42, 0x44, 0x10},
{0x42, 0x45, 0x78},
{0x42, 0x46, 0xa8},
{0x42, 0x47, 0x60},
{0x42, 0x48, 0x80},
{0x42, 0x59, 0xba},
{0x42, 0x5a, 0x9a},
{0x42, 0x5b, 0x22},
{0x42, 0x5c, 0xb9},
{0x42, 0x5d, 0x9b},
{0x42, 0x5e, 0x10},
{0x42, 0x5f, 0xe0},
{0x42, 0x60, 0x85},//85 //05 for advanced AWB
{0x42, 0x61, 0x60},
{0x42, 0x9f, 0x9d},
{0x42, 0xa0, 0xa0},
{0x42, 0x4f, 0x66},
{0x42, 0x50, 0x6b},
{0x42, 0x51, 0x05},
{0x42, 0x52, 0x19},
{0x42, 0x53, 0x40},
{0x42, 0x54, 0x59},
{0x42, 0x55, 0x40},
{0x42, 0x56, 0x40},
{0x42, 0x57, 0x40},
{0x42, 0x58, 0x0d},
{0x42, 0x8b, 0xcc},
{0x42, 0x8c, 0xcc},
{0x42, 0x8d, 0xcf},
{0x42, 0x6c, 0x40},
{0x42, 0x6d, 0x30},
{0x42, 0x6e, 0x4b},
{0x42, 0x6f, 0x60},
{0x42, 0x70, 0x70},
{0x42, 0x71, 0x70},
{0x42, 0x72, 0x70},
{0x42, 0x73, 0x70},
{0x42, 0x74, 0x60},
{0x42, 0x75, 0x60},
{0x42, 0x76, 0x50},
{0x42, 0x77, 0x48},
{0x42, 0x78, 0x3a},
{0x42, 0x79, 0x2e},
{0x42, 0x7a, 0x28},
{0x42, 0x7b, 0x22},
{0x42, 0x7c, 0x04},
{0x42, 0x7d, 0x07},
{0x42, 0x7e, 0x10},
{0x42, 0x7f, 0x28},
{0x42, 0x80, 0x36},
{0x42, 0x81, 0x44},
{0x42, 0x82, 0x52},
{0x42, 0x83, 0x60},
{0x42, 0x84, 0x6c},
{0x42, 0x85, 0x78},
{0x42, 0x86, 0x8c},
{0x42, 0x87, 0x9e},
{0x42, 0x88, 0xbb},
{0x42, 0x89, 0xd2},
{0x42, 0x8a, 0xe6},
{0x42, 0x14, 0x2e},
{0x42, 0x24, 0x68},
{0x42, 0x25, 0x5C},
{0x42, 0x13, 0xf7},// jing.li:stablize color
{0xff, 0xff, 0xff},
};
const uint8 ovt7660_320X240_NORMAL[][3] =
{
{0x42, 0x12, 0x80},
//delay 5ms --dgq
{0x42, 0x11, 0x81},//83
{0x42, 0x92, 0x00},
{0x42, 0x93, 0x00},
{0x42, 0x9d, 0x52}, //0x31 --dgq
{0x42, 0x9e, 0x29},
{0x42, 0x3b, 0x0a},//0x02 for 60hz
{0x42, 0x12, 0x10},
{0x42, 0x04, 0x00},
{0x42, 0x18, 0x4b},// 0x04
{0x42, 0x17, 0x23},// 0x16
{0x42, 0x32, 0xbf},
{0x42, 0x19, 0x02},
{0x42, 0x1a, 0x7a},
{0x42, 0x03, 0x00},
{0x42, 0x13, 0xf0},
{0x42, 0x10, 0x00},
{0x42, 0x00, 0x00},
{0x42, 0x01, 0x80},
{0x42, 0x02, 0x80},
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -