doubao_chat/apps/common/camera/gc2145_dvp/gc2145.c

1042 lines
23 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "asm/iic.h"
#include "asm/isc.h"
#include "asm/isp_dev.h"
#include "gc2145.h"
#include "gpio.h"
#include "generic/jiffies.h"
#include "device/iic.h"
#include "device/device.h"
#include "app_config.h"
#ifdef CONFIG_VIDEO_ENABLE
#define GC2145_DVP_WRCMD 0x78
#define GC2145_DVP_RDCMD 0x79
//摄像头分辨率选择,GC2145_30W:640*480 , GC2145_100W:1280*720 , GC2145_200W:1600*1200
#define GC2145_DEVP_INPUT_MAX_W 1600
#define GC2145_DEVP_INPUT_MAX_H 1200
#if (CONFIG_VIDEO_IMAGE_W > GC2145_DEVP_INPUT_MAX_W)
#define GC2145_DEVP_INPUT_W GC2145_DEVP_INPUT_MAX_W
#define GC2145_DEVP_INPUT_H GC2145_DEVP_INPUT_MAX_H
#else
#define GC2145_DEVP_INPUT_W CONFIG_VIDEO_IMAGE_W
#define GC2145_DEVP_INPUT_H CONFIG_VIDEO_IMAGE_H
#endif
/*#define FPGA_TEST*/
#ifdef CONFIG_VIDEO_720P
#define CONFIG_INPUT_FPS 40//该帧率针对720P,VGA为2倍,1600*1200为0.5倍
#else
#define CONFIG_INPUT_FPS 20//该帧率针对720P,VGA为2倍,1600*1200为0.5倍
#endif
#define DELAY_TIME 10
static void *iic = NULL;
static u8 gc2145_reset_io[2] = {-1, -1};
static u8 gc2145_power_io[2] = {-1, -1};
typedef struct {
u8 addr;
u8 value;
} Sensor_reg_ini;
const Sensor_reg_ini GC2145_INI_REG[] = {
{0xfe, 0xf0},
{0xfe, 0xf0},
{0xfe, 0xf0},
{0xfc, 0x06},
{0xf6, 0x00},
{0xf7, 0x1d},
#ifdef FPGA_TEST
{0xf8, 0x80}, //pclk=mclk * (v[0:3] + 1) //24M
#else
{0xf8, 0x83}, //pclk=mclk * (v[0:3] + 1) //96M
#endif
{0xfa, 0x00},
{0xf9, 0xfe},
{0xf2, 0x00},
/////////////////////////////////////////////////
//////////////////ISP reg//////////////////////
////////////////////////////////////////////////////
{0xfe, 0x00},
{0x03, 0x04},
{0x04, 0xe2},
//选择中间区域挖图, max: 1616 * 1232
{0x09, ((((GC2145_DEVP_INPUT_MAX_H + 32) - CONFIG_VIDEO_IMAGE_H) / 2) >> 8) & 0xff},
{0x0a, ((((GC2145_DEVP_INPUT_MAX_H + 32) - CONFIG_VIDEO_IMAGE_H) / 2)) & 0xff},
{0x0b, ((((GC2145_DEVP_INPUT_MAX_W + 16) - CONFIG_VIDEO_IMAGE_W) / 2) >> 8) & 0xff},
{0x0c, ((((GC2145_DEVP_INPUT_MAX_W + 16) - CONFIG_VIDEO_IMAGE_W) / 2)) & 0xff},
//选择输出分辨率
{0x0f, ((CONFIG_VIDEO_IMAGE_W + 32) >> 8) & 0xff},
{0x10, ((CONFIG_VIDEO_IMAGE_W + 32)) & 0xff},
{0x0d, ((CONFIG_VIDEO_IMAGE_H + 8) >> 8) & 0xff},
{0x0e, ((CONFIG_VIDEO_IMAGE_H + 8)) & 0xff},
{0x0b, 0x00},
{0x0c, 0x00},
{0x13, 0x10},
{0x14, 0x04},
{0x12, 0x2e},
{0x17, 0x14}, //mirror
{0x18, 0x22},
{0x19, 0x0e},
{0x1a, 0x01},
{0x1b, 0x4b},
{0x1c, 0x07},
{0x1d, 0x10},
{0x1e, 0x88},
{0x1f, 0x78},
{0x20, 0x03},
{0x21, 0x40},
{0x22, 0xa0},
/*{0x24 , 0x16},*/
{0x24, 0xab}, //强驱
{0x25, 0x01},
{0x26, 0x10},
{0x2d, 0x60},
{0x30, 0x01},
{0x31, 0x90},
{0x33, 0x06},
{0x34, 0x01},
/////////////////////////////////////////////////
//////////////////ISP reg////////////////////
/////////////////////////////////////////////////
{0xfe, 0x00},
{0x80, 0x7f},
{0x81, 0x26},
{0x82, 0xfa},
{0x83, 0x00},
{0x84, 0x02},//yuyv
{0x86, 0x03},//HSNC VYNC极性选择
{0x88, 0x03},
{0x89, 0x03},
{0x85, 0x08},
{0x8a, 0x00},
{0x8b, 0x00},
{0xb0, 0x55},
{0xc3, 0x00},
{0xc4, 0x80},
{0xc5, 0x90},
{0xc6, 0x3b},
{0xc7, 0x46},
{0xec, 0x06},
{0xed, 0x04},
{0xee, 0x60},
{0xef, 0x90},
{0xb6, 0x01},
{0x90, 0x01},
{0x91, 0x00},
{0x92, 0x00},
{0x93, 0x00},
{0x94, 0x00},
{0x95, 0x04},
{0x96, 0xb0},
{0x97, 0x06},
{0x98, 0x40},
/////////////////////////////////////////
/////////// BLK ////////////////////////
/////////////////////////////////////////
{0xfe, 0x00},
{0x40, 0x42},
{0x41, 0x00},
{0x43, 0x5b},
{0x5e, 0x00},
{0x5f, 0x00},
{0x60, 0x00},
{0x61, 0x00},
{0x62, 0x00},
{0x63, 0x00},
{0x64, 0x00},
{0x65, 0x00},
{0x66, 0x20},
{0x67, 0x20},
{0x68, 0x20},
{0x69, 0x20},
{0x76, 0x00},
{0x6a, 0x08},
{0x6b, 0x08},
{0x6c, 0x08},
{0x6d, 0x08},
{0x6e, 0x08},
{0x6f, 0x08},
{0x70, 0x08},
{0x71, 0x08},
{0x76, 0x00},
{0x72, 0xf0},
{0x7e, 0x3c},
{0x7f, 0x00},
{0xfe, 0x02},
{0x48, 0x15},
{0x49, 0x00},
{0x4b, 0x0b},
{0xfe, 0x00},
////////////////////////////////////////
/////////// AEC ////////////////////////
////////////////////////////////////////
{0xfe, 0x01},
{0x01, 0x04},
{0x02, 0xc0},
{0x03, 0x04},
{0x04, 0x90},
{0x05, 0x30},
{0x06, 0x90},
{0x07, 0x30},
{0x08, 0x80},
{0x09, 0x00},
{0x0a, 0x82},
{0x0b, 0x11},
{0x0c, 0x10},
{0x11, 0x10},
{0x13, 0x7b},
{0x17, 0x00},
{0x1c, 0x11},
{0x1e, 0x61},
{0x1f, 0x35},
{0x20, 0x40},
{0x22, 0x40},
{0x23, 0x20},
{0xfe, 0x02},
{0x0f, 0x04},
{0xfe, 0x01},
{0x12, 0x35},
{0x15, 0xb0},
{0x10, 0x31},
{0x3e, 0x28},
{0x3f, 0xb0},
{0x40, 0x90},
{0x41, 0x0f},
/////////////////////////////
//////// INTPEE /////////////
/////////////////////////////
{0xfe, 0x02},
{0x90, 0x6c},
{0x91, 0x03},
{0x92, 0xcb},
{0x94, 0x33},
{0x95, 0x84},
{0x97, 0x65},
{0xa2, 0x11},
{0xfe, 0x00},
/////////////////////////////
//////// DNDD///////////////
/////////////////////////////
{0xfe, 0x02},
{0x80, 0xc1},
{0x81, 0x08},
{0x82, 0x05},
{0x83, 0x08},
{0x84, 0x0a},
{0x86, 0xf0},
{0x87, 0x50},
{0x88, 0x15},
{0x89, 0xb0},
{0x8a, 0x30},
{0x8b, 0x10},
/////////////////////////////////////////
/////////// ASDE ////////////////////////
/////////////////////////////////////////
{0xfe, 0x01},
{0x21, 0x04},
{0xfe, 0x02},
{0xa3, 0x50},
{0xa4, 0x20},
{0xa5, 0x40},
{0xa6, 0x80},
{0xab, 0x40},
{0xae, 0x0c},
{0xb3, 0x46},
{0xb4, 0x64},
{0xb6, 0x38},
{0xb7, 0x01},
{0xb9, 0x2b},
{0x3c, 0x04},
{0x3d, 0x15},
{0x4b, 0x06},
{0x4c, 0x20},
{0xfe, 0x00},
/////////////////////////////////////////
/////////// GAMMA ////////////////////////
/////////////////////////////////////////
///////////////////gamma1////////////////////
{0xfe, 0x02},
{0x10, 0x09},
{0x11, 0x0d},
{0x12, 0x13},
{0x13, 0x19},
{0x14, 0x27},
{0x15, 0x37},
{0x16, 0x45},
{0x17, 0x53},
{0x18, 0x69},
{0x19, 0x7d},
{0x1a, 0x8f},
{0x1b, 0x9d},
{0x1c, 0xa9},
{0x1d, 0xbd},
{0x1e, 0xcd},
{0x1f, 0xd9},
{0x20, 0xe3},
{0x21, 0xea},
{0x22, 0xef},
{0x23, 0xf5},
{0x24, 0xf9},
{0x25, 0xff},
{0xfe, 0x00},
{0xc6, 0x20},
{0xc7, 0x2b},
///////////////////gamma2////////////////////
{0xfe, 0x02},
{0x26, 0x0f},
{0x27, 0x14},
{0x28, 0x19},
{0x29, 0x1e},
{0x2a, 0x27},
{0x2b, 0x33},
{0x2c, 0x3b},
{0x2d, 0x45},
{0x2e, 0x59},
{0x2f, 0x69},
{0x30, 0x7c},
{0x31, 0x89},
{0x32, 0x98},
{0x33, 0xae},
{0x34, 0xc0},
{0x35, 0xcf},
{0x36, 0xda},
{0x37, 0xe2},
{0x38, 0xe9},
{0x39, 0xf3},
{0x3a, 0xf9},
{0x3b, 0xff},
///////////////////////////////////////////////
///////////YCP ///////////////////////
///////////////////////////////////////////////
{0xfe, 0x02},
{0xd1, 0x32},
{0xd2, 0x32},
{0xd3, 0x40},
{0xd6, 0xf0},
{0xd7, 0x10},
{0xd8, 0xda},
{0xdd, 0x14},
{0xde, 0x86},
{0xed, 0x80},
{0xee, 0x00},
{0xef, 0x3f},
{0xd8, 0xd8},
///////////////////abs/////////////////
{0xfe, 0x01},
{0x9f, 0x40},
/////////////////////////////////////////////
//////////////////////// LSC ///////////////
//////////////////////////////////////////
{0xfe, 0x01},
{0xc2, 0x14},
{0xc3, 0x0d},
{0xc4, 0x0c},
{0xc8, 0x15},
{0xc9, 0x0d},
{0xca, 0x0a},
{0xbc, 0x24},
{0xbd, 0x10},
{0xbe, 0x0b},
{0xb6, 0x25},
{0xb7, 0x16},
{0xb8, 0x15},
{0xc5, 0x00},
{0xc6, 0x00},
{0xc7, 0x00},
{0xcb, 0x00},
{0xcc, 0x00},
{0xcd, 0x00},
{0xbf, 0x07},
{0xc0, 0x00},
{0xc1, 0x00},
{0xb9, 0x00},
{0xba, 0x00},
{0xbb, 0x00},
{0xaa, 0x01},
{0xab, 0x01},
{0xac, 0x00},
{0xad, 0x05},
{0xae, 0x06},
{0xaf, 0x0e},
{0xb0, 0x0b},
{0xb1, 0x07},
{0xb2, 0x06},
{0xb3, 0x17},
{0xb4, 0x0e},
{0xb5, 0x0e},
{0xd0, 0x09},
{0xd1, 0x00},
{0xd2, 0x00},
{0xd6, 0x08},
{0xd7, 0x00},
{0xd8, 0x00},
{0xd9, 0x00},
{0xda, 0x00},
{0xdb, 0x00},
{0xd3, 0x0a},
{0xd4, 0x00},
{0xd5, 0x00},
{0xa4, 0x00},
{0xa5, 0x00},
{0xa6, 0x77},
{0xa7, 0x77},
{0xa8, 0x77},
{0xa9, 0x77},
{0xa1, 0x80},
{0xa2, 0x80},
{0xfe, 0x01},
{0xdf, 0x0d},
{0xdc, 0x25},
{0xdd, 0x30},
{0xe0, 0x77},
{0xe1, 0x80},
{0xe2, 0x77},
{0xe3, 0x90},
{0xe6, 0x90},
{0xe7, 0xa0},
{0xe8, 0x90},
{0xe9, 0xa0},
{0xfe, 0x00},
///////////////////////////////////////////////
/////////// AWB////////////////////////
///////////////////////////////////////////////
{0xfe, 0x01},
{0x4f, 0x00},
{0x4f, 0x00},
{0x4b, 0x01},
{0x4f, 0x00},
{0x4c, 0x01}, // D75
{0x4d, 0x71},
{0x4e, 0x01},
{0x4c, 0x01},
{0x4d, 0x91},
{0x4e, 0x01},
{0x4c, 0x01},
{0x4d, 0x70},
{0x4e, 0x01},
{0x4c, 0x01}, // D65
{0x4d, 0x90},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0xb0},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0x8f},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0x6f},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0xaf},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0xd0},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0xf0},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0xcf},
{0x4e, 0x02},
{0x4c, 0x01},
{0x4d, 0xef},
{0x4e, 0x02},
{0x4c, 0x01}, //D50
{0x4d, 0x6e},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x8e},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xae},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xce},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x4d},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x6d},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x8d},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xad},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xcd},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x4c},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x6c},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x8c},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xac},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xcc},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xcb},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x4b},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x6b},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x8b},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0xab},
{0x4e, 0x03},
{0x4c, 0x01},
{0x4d, 0x8a},
{0x4e, 0x04},
{0x4c, 0x01},
{0x4d, 0xaa},
{0x4e, 0x04},
{0x4c, 0x01},
{0x4d, 0xca},
{0x4e, 0x04},
{0x4c, 0x01},
{0x4d, 0xca},
{0x4e, 0x04},
{0x4c, 0x01},
{0x4d, 0xc9},
{0x4e, 0x04},
{0x4c, 0x01},
{0x4d, 0x8a},
{0x4e, 0x04},
{0x4c, 0x01},
{0x4d, 0x89},
{0x4e, 0x04},
{0x4c, 0x01},
{0x4d, 0xa9},
{0x4e, 0x04},
{0x4c, 0x02},
{0x4d, 0x0b},
{0x4e, 0x05},
{0x4c, 0x02},
{0x4d, 0x0a},
{0x4e, 0x05},
{0x4c, 0x01},
{0x4d, 0xeb},
{0x4e, 0x05},
{0x4c, 0x01},
{0x4d, 0xea},
{0x4e, 0x05},
{0x4c, 0x02},
{0x4d, 0x09},
{0x4e, 0x05},
{0x4c, 0x02},
{0x4d, 0x29},
{0x4e, 0x05},
{0x4c, 0x02},
{0x4d, 0x2a},
{0x4e, 0x05},
{0x4c, 0x02},
{0x4d, 0x4a},
{0x4e, 0x05},
//{0x4c , 0x02},//A
//{0x4d , 0x6a},
//{0x4e , 0x06},
{0x4c, 0x02},
{0x4d, 0x8a},
{0x4e, 0x06},
{0x4c, 0x02},
{0x4d, 0x49},
{0x4e, 0x06},
{0x4c, 0x02},
{0x4d, 0x69},
{0x4e, 0x06},
{0x4c, 0x02},
{0x4d, 0x89},
{0x4e, 0x06},
{0x4c, 0x02},
{0x4d, 0xa9},
{0x4e, 0x06},
{0x4c, 0x02},
{0x4d, 0x48},
{0x4e, 0x06},
{0x4c, 0x02},
{0x4d, 0x68},
{0x4e, 0x06},
{0x4c, 0x02},
{0x4d, 0x69},
{0x4e, 0x06},
{0x4c, 0x02}, //H
{0x4d, 0xca},
{0x4e, 0x07},
{0x4c, 0x02},
{0x4d, 0xc9},
{0x4e, 0x07},
{0x4c, 0x02},
{0x4d, 0xe9},
{0x4e, 0x07},
{0x4c, 0x03},
{0x4d, 0x09},
{0x4e, 0x07},
{0x4c, 0x02},
{0x4d, 0xc8},
{0x4e, 0x07},
{0x4c, 0x02},
{0x4d, 0xe8},
{0x4e, 0x07},
{0x4c, 0x02},
{0x4d, 0xa7},
{0x4e, 0x07},
{0x4c, 0x02},
{0x4d, 0xc7},
{0x4e, 0x07},
{0x4c, 0x02},
{0x4d, 0xe7},
{0x4e, 0x07},
{0x4c, 0x03},
{0x4d, 0x07},
{0x4e, 0x07},
{0x4f, 0x01},
{0x50, 0x80},
{0x51, 0xa8},
{0x52, 0x47},
{0x53, 0x38},
{0x54, 0xc7},
{0x56, 0x0e},
{0x58, 0x08},
{0x5b, 0x00},
{0x5c, 0x74},
{0x5d, 0x8b},
{0x61, 0xdb},
{0x62, 0xb8},
{0x63, 0x86},
{0x64, 0xc0},
{0x65, 0x04},
{0x67, 0xa8},
{0x68, 0xb0},
{0x69, 0x00},
{0x6a, 0xa8},
{0x6b, 0xb0},
{0x6c, 0xaf},
{0x6d, 0x8b},
{0x6e, 0x50},
{0x6f, 0x18},
{0x73, 0xf0},
{0x70, 0x0d},
{0x71, 0x60},
{0x72, 0x80},
{0x74, 0x01},
{0x75, 0x01},
{0x7f, 0x0c},
{0x76, 0x70},
{0x77, 0x58},
{0x78, 0xa0},
{0x79, 0x5e},
{0x7a, 0x54},
{0x7b, 0x58},
{0xfe, 0x00},
//////////////////////////////////////////
///////////CC////////////////////////
//////////////////////////////////////////
{0xfe, 0x02},
{0xc0, 0x01},
{0xc1, 0x44},
{0xc2, 0xfd},
{0xc3, 0x04},
{0xc4, 0xF0},
{0xc5, 0x48},
{0xc6, 0xfd},
{0xc7, 0x46},
{0xc8, 0xfd},
{0xc9, 0x02},
{0xca, 0xe0},
{0xcb, 0x45},
{0xcc, 0xec},
{0xcd, 0x48},
{0xce, 0xf0},
{0xcf, 0xf0},
{0xe3, 0x0c},
{0xe4, 0x4b},
{0xe5, 0xe0},
//////////////////////////////////////////
///////////ABS ////////////////////
//////////////////////////////////////////
{0xfe, 0x01},
{0x9f, 0x40},
{0xfe, 0x00},
//////////////////////////////////////
/////////// OUTPUT ////////////////
//////////////////////////////////////
{0xfe, 0x00},
{0xf2, 0x0f},
///////////////dark sun////////////////////
{0xfe, 0x02},
{0x40, 0xbf},
{0x46, 0xcf},
{0xfe, 0x00},
{0xfe, 0x00},
{0xfd, 0x00},
{0xfa, 0x00},
//////////////////////////////////////
///////// crop window /////////////
//////////////////////////////////////
{0xfe, 0x00},
{0x90, 0x01},
{0x91, 0x00},
{0x92, 0x00},
{0x93, 0x00},
{0x94, 0x00},
#if (CONFIG_VIDEO_IMAGE_W > 1280)
//最大输出1600*1200
{0x95, 0x04},
{0x96, 0xb0},
{0x97, 0x06},
{0x98, 0x40},
#else
//100W以下,最大输出1280*720
{0x95, 0x02},
{0x96, 0xd0},
{0x97, 0x05},
{0x98, 0x00},
{0x99, 0x11},
{0x9a, 0x06},
#endif
//// AWB
{0xfe, 0x00},
{0xec, 0x06},
{0xed, 0x04},
{0xee, 0x60},
{0xef, 0x90},
{0xfe, 0x01},
{0x74, 0x01},
//// AEC
{0xfe, 0x01},
{0x01, 0x04},
{0x02, 0xc0},
{0x03, 0x04},
{0x04, 0x90},
{0x05, 0x30},
{0x06, 0x90},
{0x07, 0x30},
{0x08, 0x80},
{0x0a, 0x82},
{0xfe, 0x01},
{0x21, 0x15},
{0xfe, 0x00},
{0x20, 0x15},
{0xfe, 0x00},
//////////////frame rate 50Hz/////////
{0xfe, 0x00},
#if (CONFIG_INPUT_FPS == 15)
{0x05, 0x03},//PCLK:96M , 15FPS
{0x06, 0xff},
{0x07, 0x01},
{0x08, 0xff},
#elif (CONFIG_INPUT_FPS == 20)
{0x05, 0x01},//PCLK:96M , 20FPS
{0x06, 0x50},
{0x07, 0x04},
{0x08, 0x6f},
#elif (CONFIG_INPUT_FPS == 25)
{0x05, 0x02},//PCLK:96M , 25FPS
{0x06, 0xc0},
{0x07, 0x01},
{0x08, 0x80},
#elif (CONFIG_INPUT_FPS == 26)
{0x05, 0x02},//PCLK:96M , 25FPS
{0x06, 0xc0},
{0x07, 0x01},
{0x08, 0x80},
#elif (CONFIG_INPUT_FPS == 27)
{0x05, 0x01},//PCLK:96M , 27FPS
{0x06, 0xc0},
{0x07, 0x01},
{0x08, 0x20},
#elif (CONFIG_INPUT_FPS == 40)
{0x05, 0x01},//行间隔高位pclk 96M 720p 20fps 行间隔调到最小了
{0x06, 0x20},//行间隔低位
{0x07, 0x02},//帧间隔高位
{0x08, 0x10},//帧间隔低位
#elif (CONFIG_INPUT_FPS == 51)
{0x05, 0x01},//PCLK:96M , 50FPS
{0x06, 0x20},
{0x07, 0x00},
{0x08, 0x40},
#endif
{0xfe, 0x01},
{0x25, 0x00},
{0x26, 0xee},
{0x27, 0x02},
{0x28, 0xb8},
{0x29, 0x02},
{0x2a, 0xb8},
{0x2b, 0x02},
{0x2c, 0xb8},
{0x2d, 0x02},
{0x2e, 0xb8},
{0xfe, 0x00},
};
unsigned char wrGC2145Reg(unsigned char regID, unsigned char regDat)
{
u8 ret = 1;
dev_ioctl(iic, IIC_IOCTL_START, 0);
if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_START_BIT, GC2145_DVP_WRCMD)) {
ret = 0;
printf("iic write err!!! line : %d \n", __LINE__);
goto exit;
}
delay(DELAY_TIME);
if (dev_ioctl(iic, IIC_IOCTL_TX, regID)) {
ret = 0;
printf("iic write err!!! line : %d \n", __LINE__);
goto exit;
}
delay(DELAY_TIME);
if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_STOP_BIT, regDat)) {
ret = 0;
printf("iic write err!!! line : %d \n", __LINE__);
goto exit;
}
delay(DELAY_TIME);
exit:
dev_ioctl(iic, IIC_IOCTL_STOP, 0);
return ret;
}
unsigned char rdGC2145Reg(unsigned char regID, unsigned char *regDat)
{
u8 ret = 1;
dev_ioctl(iic, IIC_IOCTL_START, 0);
if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_START_BIT, GC2145_DVP_WRCMD)) {
ret = 0;
printf("iic write err!!! line : %d \n", __LINE__);
goto exit;
}
delay(DELAY_TIME);
if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_STOP_BIT, regID)) {
ret = 0;
printf("iic write err!!! line : %d \n", __LINE__);
goto exit;
}
delay(DELAY_TIME);
if (dev_ioctl(iic, IIC_IOCTL_TX_WITH_START_BIT, GC2145_DVP_RDCMD)) {
ret = 0;
printf("iic write err!!! line : %d \n", __LINE__);
goto exit;
}
delay(DELAY_TIME);
dev_ioctl(iic, IIC_IOCTL_RX_WITH_STOP_BIT, (u32)regDat);
exit:
dev_ioctl(iic, IIC_IOCTL_STOP, 0);
return ret;
}
void GC2145_config_SENSOR(u16 *width, u16 *height, u8 *format, u8 *frame_freq)
{
int i;
for (i = 0; i < sizeof(GC2145_INI_REG) / sizeof(Sensor_reg_ini); i++) {
wrGC2145Reg(GC2145_INI_REG[i].addr, GC2145_INI_REG[i].value);
}
*format = SEN_IN_FORMAT_YUYV;
puts("\nGC2145 YUYV\n");
}
s32 GC2145_set_output_size(u16 *width, u16 *height, u8 *freq)
{
u16 w = *width + 32;//宽多加32像素点
u16 h = *height + 8;//高多加8像素点
u16 max_w = GC2145_DEVP_INPUT_MAX_W + 16;//max 1616
u16 max_h = GC2145_DEVP_INPUT_MAX_H + 32;//max 1232
u16 raw_start = (max_h - CONFIG_VIDEO_IMAGE_H) / 2;
u16 col_start = (max_w - CONFIG_VIDEO_IMAGE_W) / 2;
wrGC2145Reg(0xfe, 0x00);
//选择中间区域挖图, max: 1616 * 1232
wrGC2145Reg(0x09, (raw_start >> 8) & 0xff);
wrGC2145Reg(0x0a, raw_start & 0xff);
wrGC2145Reg(0x0b, (col_start >> 8) & 0xff);
wrGC2145Reg(0x0c, col_start & 0xff);
//选择输出分辨率
wrGC2145Reg(0x0f, (w >> 8) & 0xff);
wrGC2145Reg(0x10, w & 0xff);
wrGC2145Reg(0x0d, (h >> 8) & 0xff);
wrGC2145Reg(0x0e, h & 0xff);
return 0;
}
s32 GC2145_ID_check(void)
{
u8 pid = 0x00;
u8 ver = 0x00;
u8 i ;
for (i = 0; i < 3; i++) { //
rdGC2145Reg(0xf0, &pid);
rdGC2145Reg(0xf1, &ver);
}
puts("Sensor PID \n");
puts("\n");
if (pid != 0x21 || ver != 0x45) {
puts("\n----not GC2145_DVP-----\n");
return -1;
}
puts("\n----hello GC2145_DVP-----\n");
return 0;
}
static s32 GC2145_powerio_ctl(u8 _power_gpio, u8 on_off)
{
gpio_direction_output(_power_gpio, on_off);
return 0;
}
void GC2145_reset(u8 isp_dev)
{
u8 res_io;
u8 powd_io;
u8 id = 0;
puts("GC2145 reset\n");
if (isp_dev == ISP_DEV_0) {
res_io = gc2145_reset_io[0];
powd_io = gc2145_power_io[0];
} else {
res_io = gc2145_reset_io[1];
powd_io = gc2145_power_io[1];
}
if (powd_io != (u8) - 1) {
GC2145_powerio_ctl(powd_io, 0);
}
if (res_io != (u8) - 1) {
gpio_direction_output(res_io, 1);
gpio_direction_output(res_io, 0);
os_time_dly(1);
gpio_direction_output(res_io, 1);
}
}
s32 GC2145_check(u8 isp_dev, u32 _reset_gpio, u32 _power_gpio)
{
if (!iic) {
if (isp_dev == ISP_DEV_0) {
iic = dev_open("iic0", 0);
} else {
iic = dev_open("iic1", 0);
}
gc2145_reset_io[isp_dev] = (u8)_reset_gpio;
gc2145_power_io[isp_dev] = (u8)_power_gpio;
}
if (iic == NULL) {
printf("GC2145 iic open err!!!\n\n");
return -1;
}
GC2145_reset(isp_dev);
if (0 != GC2145_ID_check()) {
dev_close(iic);
iic = NULL;
return -1;
}
return 0;
}
u16 GC2145_dvp_rd_reg(u16 addr)
{
u8 val;
rdGC2145Reg((u8)addr, &val);
return val;
}
void free_gc2145_gpio(void)
{
wrGC2145Reg(0xfe, 0x0);
wrGC2145Reg(0x19, 0x0);
}
void GC2145_dvp_wr_reg(u16 addr, u16 val)
{
wrGC2145Reg((u8)addr, (u8)val);
}
void set_rev_sensor_GC2145(u16 rev_flag)
{
if (!rev_flag) {
wrGC2145Reg(0x17, 0x12);
} else {
wrGC2145Reg(0x17, 0x11);
}
}
static s32 GC2145_init(u8 isp_dev, u16 *width, u16 *height, u8 *format, u8 *frame_freq)
{
puts("\n\n GC2145_init \n\n");
if (0 != GC2145_check(isp_dev, 0, 0)) {
return -1;
}
GC2145_config_SENSOR(width, height, format, frame_freq);
return 0;
}
// *INDENT-OFF*
REGISTER_CAMERA(GC2145) = {
.logo = "GC2145",
.isp_dev = ISP_DEV_NONE,
.in_format = SEN_IN_FORMAT_YUYV,
.mbus_type = SEN_MBUS_PARALLEL,
.mbus_config = SEN_MBUS_DATA_WIDTH_8B | SEN_MBUS_HSYNC_ACTIVE_HIGH | \
SEN_MBUS_PCLK_SAMPLE_FALLING | SEN_MBUS_VSYNC_ACTIVE_HIGH,
#if CONFIG_CAMERA_H_V_EXCHANGE
.sync_config = SEN_MBUS_SYNC0_VSYNC_SYNC1_HSYNC,//WL82/AC791才可以H-V SYNC互换,请留意
#endif
.fps = CONFIG_INPUT_FPS,
.sen_size = {GC2145_DEVP_INPUT_W, GC2145_DEVP_INPUT_H},
.cap_fps = CONFIG_INPUT_FPS,
.sen_cap_size = {GC2145_DEVP_INPUT_W, GC2145_DEVP_INPUT_H},
.ops = {
.avin_fps = NULL,
.avin_valid_signal = NULL,
.avin_mode_det = NULL,
.sensor_check = GC2145_check,
.init = GC2145_init,
.set_size_fps = GC2145_set_output_size,
.power_ctrl = GC2145_powerio_ctl,
.sleep = NULL,
.wakeup = NULL,
.write_reg = GC2145_dvp_wr_reg,
.read_reg = GC2145_dvp_rd_reg,
.set_sensor_reverse = set_rev_sensor_GC2145,
}
};
#endif