#include "ov7725.h"
#include "spi_lcd.h"
#include "sccb.h"
#include "delay.h"
OV7725_IDTypeDef OV7725ID;
u8 ov_sta,ov_frame;
extern uint32_t count;
#define CAMERA_H 120
#define CAMERA_W 160
/* 寄存器参数配置 */
typedef struct Reg
{
uint8_t Address; /*寄存器地址*/
uint8_t Value; /*寄存器值*/
}Reg_Info;
Reg_Info Sensor_Config1[] =
{
{OV7725_CLKRC, 0x00}, /*clock config*/
{OV7725_COM7, 0x46}, /*QVGA RGB565 */
{OV7725_HSTART, 0x3f},
{OV7725_HSIZE, 0x50},
{OV7725_VSTRT, 0x03},
{OV7725_VSIZE, 0x78},
{OV7725_HREF, 0x00},
{OV7725_HOutSize, 0x2c},
{OV7725_VOutSize, 0x78},
{OV7725_EXHCH, 0x00},
/*DSP control*/
{OV7725_TGT_B, 0x7f},
{OV7725_FixGain, 0x09},
{OV7725_AWB_Ctrl0, 0xe0},
{OV7725_DSP_Ctrl1, 0xff},
{OV7725_DSP_Ctrl2, 0x20},
{OV7725_DSP_Ctrl3, 0x00},
{OV7725_DSP_Ctrl4, 0x00},
/*AGC AEC AWB*/
{OV7725_COM8, 0xf0},
{OV7725_COM4, 0x81}, /*Pll AEC CONFIG*/
{OV7725_COM6, 0xc5},
{OV7725_COM9, 0x21},
{OV7725_BDBase, 0xFF},
{OV7725_BDMStep, 0x01},
{OV7725_AEW, 0x34},
{OV7725_AEB, 0x3c},
{OV7725_VPT, 0xa1},
{OV7725_EXHCL, 0x00},
{OV7725_AWBCtrl3, 0xaa},
{OV7725_COM8, 0xff},
{OV7725_AWBCtrl1, 0x5d},
{OV7725_EDGE1, 0x0a},
{OV7725_DNSOff, 0x01},
{OV7725_EDGE2, 0x01},
{OV7725_EDGE3, 0x01},
{OV7725_MTX1, 0x5f},
{OV7725_MTX2, 0x53},
{OV7725_MTX3, 0x11},
{OV7725_MTX4, 0x1a},
{OV7725_MTX5, 0x3d},
{OV7725_MTX6, 0x5a},
{OV7725_MTX_Ctrl, 0x1e},
{OV7725_BRIGHT, 0x00},
{OV7725_CNST, 0x25},
{OV7725_USAT, 0x65},
{OV7725_VSAT, 0x65},
{OV7725_UVADJ0, 0x81},
{OV7725_SDE, 0x06},
/*GAMMA config*/
{OV7725_GAM1, 0x0c},
{OV7725_GAM2, 0x16},
{OV7725_GAM3, 0x2a},
{OV7725_GAM4, 0x4e},
{OV7725_GAM5, 0x61},
{OV7725_GAM6, 0x6f},
{OV7725_GAM7, 0x7b},
{OV7725_GAM8, 0x86},
{OV7725_GAM9, 0x8e},
{OV7725_GAM10, 0x97},
{OV7725_GAM11, 0xa4},
{OV7725_GAM12, 0xaf},
{OV7725_GAM13, 0xc5},
{OV7725_GAM14, 0xd7},
{OV7725_GAM15, 0xe8},
{OV7725_SLOP, 0x20},
{OV7725_HUECOS, 0x80},
{OV7725_HUESIN, 0x80},
{OV7725_DSPAuto, 0xff},
{OV7725_DM_LNL, 0x00},
{OV7725_BDBase, 0x99},
{OV7725_BDMStep, 0x03},
{OV7725_LC_RADI, 0x00},
{OV7725_LC_COEF, 0x13},
{OV7725_LC_XC, 0x08},
{OV7725_LC_COEFB, 0x14},
{OV7725_LC_COEFR, 0x17},
{OV7725_LC_CTR, 0x05},
{OV7725_COM3, 0xd0},/*Horizontal mirror image*/
/*night mode auto frame rate control*/
{OV7725_COM5, 0xf5}, /*?úò1êó?·?3??£?×??ˉ?μμí???ê£?±£?¤μí???è?-???êá?*/
//{COM5, 0x31}, /*ò1êó?·?3???ê2?±?*/
};
/*OV7725初始化配置表*/
Reg_Info Sensor_Config[] =
{
//寄存器,寄存器值次
{OV7725_COM4 , 0xC1},
{OV7725_CLKRC , 0x00},
{OV7725_COM2 , 0x03},
{OV7725_COM3 , 0xD0},
{OV7725_COM7 , 0x40},
{OV7725_HSTART , 0x3F},
{OV7725_HSIZE , 0x50},
{OV7725_VSTRT , 0x03},
{OV7725_VSIZE , 0x78},
{OV7725_HREF , 0x00},
{OV7725_SCAL0 , 0x0A},
{OV7725_AWB_Ctrl0 , 0xE0},
{OV7725_DSPAuto , 0xff},
{OV7725_DSP_Ctrl2 , 0x0C},
{OV7725_DSP_Ctrl3 , 0x00},
{OV7725_DSP_Ctrl4 , 0x00},
#if (CAMERA_W == 80)
{OV7725_HOutSize , 0x14},
#elif (CAMERA_W == 160)
{OV7725_HOutSize , 0x28},
#elif (CAMERA_W == 240)
{OV7725_HOutSize , 0x3c},
#elif (CAMERA_W == 320)
{OV7725_HOutSize , 0x50},
#else
#endif
#if (CAMERA_H == 60 )
{OV7725_VOutSize , 0x1E},
#elif (CAMERA_H == 120 )
{OV7725_VOutSize , 0x3c},
#elif (CAMERA_H == 180 )
{OV7725_VOutSize , 0x5a},
#elif (CAMERA_H == 240 )
{OV7725_VOutSize , 0x78},
#else
#endif
{OV7725_EXHCH , 0x00},
{OV7725_GAM1 , 0x0c},
{OV7725_GAM2 , 0x16},
{OV7725_GAM3 , 0x2a},
{OV7725_GAM4 , 0x4e},
{OV7725_GAM5 , 0x61},
{OV7725_GAM6 , 0x6f},
{OV7725_GAM7 , 0x7b},
{OV7725_GAM8 , 0x86},
{OV7725_GAM9 , 0x8e},
{OV7725_GAM10 , 0x97},
{OV7725_GAM11 , 0xa4},
{OV7725_GAM12 , 0xaf},
{OV7725_GAM13 , 0xc5},
{OV7725_GAM14 , 0xd7},
{OV7725_GAM15 , 0xe8},
{OV7725_SLOP , 0x20},
{OV7725_LC_RADI , 0x00},
{OV7725_LC_COEF , 0x13},
{OV7725_LC_XC , 0x08},
{OV7725_LC_COEFB , 0x14},
{OV7725_LC_COEFR , 0x17},
{OV7725_LC_CTR , 0x05},
{OV7725_BDBase , 0x99},
{OV7725_BDMStep , 0x03},
{OV7725_SDE , 0x04},
{OV7725_BRIGHT , 0x00},
{OV7725_CNST , 0xFF},
{OV7725_SIGN , 0x06},
{OV7725_UVADJ0 , 0x11},
{OV7725_UVADJ1 , 0x02},
};
u8 OV7725_REG_NUM = sizeof(Sensor_Config)/sizeof(Sensor_Config[0]); /*结构体数组成员数目*/
u8 OV7725_REG_NUM1= sizeof(Sensor_Config1)/sizeof(Sensor_Config1[0]);
uint8_t Ov7725_vsync = 0; /* 帧同步信号标志,在中断函数和main函数里面使用 */
void OV7725_GPIO_Init(void)
{
uint8_t i=0;
const gpio_output_pin_user_config_t sccb_gpio_config[]=
{
{.pinName = GPIO_MAKE_PIN(GPIOC_IDX, 16U),
.config.outputLogic = 1,
.config.slewRate = kPortFastSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortHighDriveStrength,
}, //PTC16 WE
{.pinName = GPIO_MAKE_PIN(GPIOC_IDX, 17U),
.config.outputLogic = 1,
.config.slewRate = kPortFastSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortHighDriveStrength,
}, //PTC17 WRST
{.pinName = GPIO_MAKE_PIN(GPIOA_IDX, 1U),
.config.outputLogic = 1,
.config.slewRate = kPortFastSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortHighDriveStrength,
}, //PTA1 RCLK
{.pinName = GPIO_MAKE_PIN(GPIOB_IDX, 23U),
.config.outputLogic = 1,
.config.slewRate = kPortFastSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortHighDriveStrength,
}, //PTB23 PRST
{.pinName = GPIO_MAKE_PIN(GPIOA_IDX, 2U),
.config.outputLogic = 1,
.config.slewRate = kPortFastSlewRate,
.config.isOpenDrainEnabled = false,
.config.driveStrength = kPortHighDriveStrength,
}, //PTA2 OE
};