iic.cpp

来自「S3C24A0的完整BSP包,对开发此芯片的开发者很有用.」· C++ 代码 · 共 1,063 行 · 第 1/2 页

CPP
1,063
字号
#include <windows.h>
#include <Winbase.h>
#include <s3c24A0.h>
#include <nkintr.h>
#include <oal_intr.h>
#include <p2.h>

#include "camif.h"

#define U8	unsigned char
#define U16	unsigned short
#define U32	unsigned int

#define CAM_OV7620	(0) // OMNI Vision camera, 640x480 VGA
#define CAM_S5X433	(1) // Samsung S5X433 VGA camera
#define CAM_S5X532	(2) // Samsung S5X532 VGA camera
#define CAM_AU70H	(3) // 1152x864 MegaPixel Camera, max 19.3Mhz
#define CAM_S5X3A1	(4) // Mega pixel
#define CAM_OV9650  (5) // OV9650


//#define SlaveID	0x42  //OV7620 Slave ID 
//#define SlaveID	0x5a  //S5X532 Slave ID 
#define SlaveID	0x60  //ov9650 Slave ID 


#define WRDATA      (1)
#define RDDATA      (3)
#define SETRDADDR   (4)

#define CAMIICBUFSIZE 0x20
#define IICBUFSIZE 	0x20

#define RETAIL_ON 1

static U8 _iicData[IICBUFSIZE];
static volatile int _iicDataCount;
static volatile int _iicStatus;
static volatile int _iicMode;
static int _iicPt;

DWORD gIntrIIC = SYSINTR_NOP;

/*
const unsigned char Ov7620_YCbCr8bit_TV[][2] = {
// OMNI Vision	
	{0x12, 0x80},		// Camera Soft reset. Self cleared after reset.
	{0x00, 0x00},
	{0x01, 0x80},		// set blue gain
	{0x02, 0x80},		// set red gain
	{0x03, 0xb0},
	{0x06, 0x60},		// set brightness
	{0x0c, 0x24},		// set blue background
	{0x0d, 0x24},		// set red background
	{0x10, 0xff},		// set exposure time, brightness control
	{0x11, 0x80},		// set frame rate CLK_input = PCLK
	{0x12, 0x74},		// set 8 Bit YUV mode, enable AGC/AWB, mirror image enabled.
	{0x13, 0x21}, 		 // 8bit Data, CCIR601 Format
	{0x15, 0x01},		// Use PCLK falling edge to latch data, 8 Bit UYVY....
	{0x16, 0x03},		//
	{0x17, 0x2f},		//
	{0x18, 0xcf},	       // (207-47)*4 = 640
	{0x19, 0x06},		//
	{0x1a, 0xf5},	       // ((244-5)+1)*2=480
	{0x1b, 0x00},
	{0x20, 0x00},
	{0x21, 0x80},
	{0x22, 0x80},
	{0x23, 0x00},
	{0x26, 0xa2},
	{0x27, 0xea},
	{0x29, 0x00},
	{0x2a, 0x00},
	{0x2b, 0x00},
	{0x2c, 0x88},
	{0x2e, 0x80},
	{0x2f, 0x44},
	{0x60, 0x27},
	{0x61, 0x82},
	{0x62, 0x5f},
	{0x63, 0xd5},
	{0x64, 0x57},
	{0x65, 0x83},
	{0x66, 0x55},
	{0x68, 0xcf},
	{0x69, 0x76},
	{0x6a, 0x22},
	{0x6b, 0x00},
	{0x6c, 0x08},
	{0x6d, 0x48},	
	{0x6e, 0x80},
	{0x6f, 0x0c},
	{0x70, 0x89},
	{0x71, 0x00},
	{0x72, 0x14},
	{0x73, 0x54},	
	{0x75, 0x0e},
	{0x76, 0x00},
	{0x77, 0xff},
	{0x78, 0x80},
	{0x79, 0x80},
	{0x7a, 0x80},
	{0x7b, 0xe6},
	{0x7c, 0x00},	
	{0x13, 0x21},
	{0x14, 0x94},	
	{0x24, 0x10},
	{0x25, 0x8a},
	{0x28, 0x20},	// Progressive mode.
	{0x2d, 0x95},	//
	{0x67, 0x92},	// 
	{0x74, 0x00},	// -CJH

	{0x12, 0x74}		// set 8 Bit YUV mode, enable AGC/AWB, mirror image enabled.
};
*/
const unsigned char _OV9650_Init[] =
{
    //init for 9650
    //0x12, 0x80
    //Wait for 5ms after write register 0x12 to 0x80
        0x11, 0x80,        0x39, 0x43,         0x38, 0x12,         0x37, 0x00,
        0x0e, 0x20,        0x1e, 0x04,//Mirror & Vflip //0x04
        
        0x01, 0x80,        0x02, 0x80,        0x00, 0x00,        0x10, 0xf0,
        
        0x04, 0x00,        0x0c, 0x04,        0x0d, 0x80,        0x12, 0x40,
        0x14, 0x2A,        0x15, 0x00,        0x18, 0xc7,        0x17, 0x27,
        0x32, 0xad,        0x03, 0x00,        0x1a, 0x3d,        0x19, 0x01,
        0x3f, 0xa6,        0x41, 0x02,        0x42, 0x08,
        
        0x1b, 0x00,        0x16, 0x06,        0x33, 0xc0,        0x34, 0xbf,
        0xA8, 0x80,        0x96, 0x04,        0x3a, 0x00,        0x8e, 0x00,
        
        0x3c, 0x77,        0x8B, 0x06,        0x35, 0x91,        0x94, 0x88,
        0x95, 0x88,        0x40, 0xc1,        0x29, 0x3f,        0x0f, 0x42,
        
        0x13, 0xe5,
        
        0x3d, 0x92,        0x69, 0x80,        0x5C, 0x96,        0x5D, 0x96,
        0x5E, 0x10,        0x59, 0xeb,        0x5A, 0x9c,        0x5B, 0x55,
        0x43, 0xf0,        0x44, 0x10,        0x45, 0x55,        0x46, 0x86,
        0x47, 0x64,        0x48, 0x86,        0x5F, 0xe0,        0x60, 0x8c,
        0x61, 0x20,                  
        
        0xa5, 0xd9,        0xa4, 0x74,        0x8d, 0x02,
        
        0x13, 0xe7,
        
        0x4f, 0x3a,        0x50, 0x3d,        0x51, 0x03,        0x52, 0x12,
        0x53, 0x26,        0x54, 0x38,        0x55, 0x40,        0x56, 0x40,
        0x57, 0x40,        0x58, 0x0d,        0x8C, 0x23,        0x3E, 0x02,
        0xa9, 0xb8,        0xaa, 0x92,        0xab, 0x0a,
        
        0x8f, 0xdf,        0x90, 0x00,        0x91, 0x00,        0x9f, 0x00,
        0x3A, 0x05,
        
        0x24, 0x70,        0x25, 0x64,        0x26, 0xc3,        0x6a, 0x67,
        0x2a, 0x00,		   0x2b, 0xd0,        0x3b, 0x19,
        
        0x6c, 0x40,        0x6d, 0x30,        0x6e, 0x48,        0x6f, 0x60,
        0x70, 0x70,        0x71, 0x70,        0x72, 0x70,        0x73, 0x70,
        0x74, 0x60,        0x75, 0x60,        0x76, 0x50,        0x77, 0x48,
        0x78, 0x3a,        0x79, 0x2e,        0x7a, 0x28,        0x7b, 0x22,
        0x7c, 0x04,        0x7d, 0x07,        0x7e, 0x10,        0x7f, 0x28,
        0x80, 0x36,        0x81, 0x44,        0x82, 0x52,        0x83, 0x60,
        0x84, 0x6c,        0x85, 0x78,        0x86, 0x8c,        0x87, 0x9e,
        0x88, 0xbb,        0x89, 0xd2,        0x8a, 0xe6
};

const unsigned char _OV9650_Init_VGA[] =
{
    0x11,0x80,	0x12,0x40,	
        0x18,0xc7,	0x17,0x27,	0x32,0xad,	  	
        0x03,0x00,  0x1a,0x3d,	0x19,0x01,	
        0x2a,0x00,	0x2b,0xd0,	0x6a,0x30,
};

const unsigned char _OV9650_Init_CIF[] =
{
    0x11,0x81,	0x12,0x20,	0x0c,0x04,	  0x0d,0x80,	
        0x18,0x7e,	0x17,0x26,	0x32,0x24,	  	
        0x03,0x36,  0x1a,0x24,	0x19,0x00,	
        0x2a,0x00,	0x2b,0xd0,	0x6a,0x30,
};

const unsigned char _OV9650_Init_QVGA[] =
{
    0x11,0x81,	0x12,0x00,	0x0c,0x04,	  0x0d,0x80,	
        0x18,0xc6,	0x17,0x26,	0x32,0xa4,	  	
        0x03,0x36,  0x1a,0x1e,	0x19,0x00,	
        0x2a,0x10,	0x2b,0x40,	0x6a,0x1f,
};


const unsigned char S5X532_YCbCr8bit_TV[][2] = 
{
#if S5X532_VER == 30
	// page 5
	{0xec,0x05},
	{0x08,0x55},
	{0x0a,0x75},
	{0x0c,0x90},
	{0x0e,0x18},
	{0x12,0x09},
	{0x14,0x9d},
	{0x16,0x90},
	{0x1a,0x18},
	{0x1c,0x0c},
	{0x1e,0x09},
	{0x20,0x06},
	{0x22,0x20},
	{0x2a,0x00},
	{0x2d,0x04},
	{0x12,0x24},
	// page 3
	{0xec,0x03},
	{0x0c,0x09},
	{0x6c,0x09},
	{0x2b,0x10}, // momo clock inversion
	// page 2
	{0xec,0x02},
	{0x03,0x09},
	{0x05,0x08},
	{0x06,0x01},
	{0x07,0xf8},
	{0x15,0x25},
	{0x30,0x29},
	{0x36,0x12},
	{0x38,0x04},
	{0x1b,0x77}, // 24MHz : 0x77, 12MHz : 0x22
	{0x1c,0x77}, // 24MHz : 0x77, 12MHz : 0x22
	// page 1
	{0xec,0x01},
	{0x00,0x03}, // 
	{0x0a,0x08}, // 0x0-QQVGA, 0x06-CIF, 0x02-QCIF, 0x08-VGA, 0x04-QVGA, 0x0a-SXGA
	//{0x10,0x22}, // 0x22-ITU-R656(YCbYCr), 0x26-ITU-R601(YCbYCr)
	{0x10,0x26}, // 0x22-ITU-R656(YCbYCr), 0x26-ITU-R601(YCbYCr)
	{0x50,0x21},		// Hblank
	{0x51,0x00},		// Hblank
	{0x52,0xA1},		// Hblank
	{0x53,0x02},		// Hblank
	{0x54,0x01},		// Vblank
	{0x55,0x00},		// Vblank
	{0x56,0xE1},		// Vblank 		
	{0x57,0x01},		// Vblank
	{0x58,0x21},		// Hsync
	{0x59,0x00},		// Hsync
	{0x5a,0xA1},		// Hsync
	{0x5b,0x02},		// Hsync
	{0x5c,0x03},		// Vref
	{0x5d,0x00},		// Vref
	{0x5e,0x05},		// Vref
	{0x5f,0x00},		// Vref	
	{0x70,0x0E},
	{0x71,0xD6},
	{0x72,0x30},
	{0x73,0xDB},
	{0x74,0x0E},
	{0x75,0xD6},
	{0x76,0x18},
	{0x77,0xF5},
	{0x78,0x0E},
	{0x79,0xD6},
	{0x7a,0x28},
	{0x7b,0xE6},
	{0x50,0x00},
	{0x5c,0x00},

	// page 0
	{0xec,0x00},
	{0x79,0x01},
	{0x58,0x90},
	{0x59,0xA0},
	{0x5a,0x50},
	{0x5b,0x70},
	{0x5c,0xD0},
	{0x5d,0xC0},
	{0x5e,0x28},
	{0x5f,0x08},
	{0x50,0x90},
	{0x51,0xA0},
	{0x52,0x50},
	{0x53,0x70},
	{0x54,0xD0},
	{0x55,0xC0},
	{0x56,0x28},
	{0x57,0x00},
	{0x48,0x90},
	{0x49,0xA0},
	{0x4a,0x50},
	{0x4b,0x70},
	{0x4c,0xD0},
	{0x4d,0xC0},
	{0x4e,0x28},
	{0x4f,0x08},
	{0x72,0xd2}, // main clock = 24MHz:0xd2, 16M:0x82, 12M:0x54
	{0x75,0x05} // absolute vertical mirror.  junon


#elif  S5X532_VER == 36 // 2004.05.10 ISP_REV36
	//=============== page0 ===============//
	{0xec,0x00},
	{0x02,0x00},
	{0x14,0x60},
	{0x15,0x60},
	{0x16,0x60},
	{0x1b,0x20},
	{0x1c,0x20},
	{0x1d,0x20},
	{0x1e,0x20},
	{0x72,0xdc},
	{0x73,0x11},
	{0x76,0x82},
	{0x77,0x90},
	{0x78,0x6c},
	{0x0a,0x02},
	{0x34,0x0d},
	{0x35,0x0a},
	{0x36,0x05},
	{0x37,0x05},
	{0x38,0x06},
	{0x39,0x08},
	{0x3A,0x0d},
	{0x3B,0x0d},
	{0x3C,0x18},
	{0x3D,0xE0},
	{0x3E,0x20},
	{0x66,0x02},
	{0x6c,0x40},
	{0x7c,0x01},
	{0x0D,0x24},
	{0x40,0x1B},
	{0x41,0x4F},
	{0x42,0x24},
	{0x43,0x3E},
	{0x44,0x32},
	{0x45,0x30},
	{0x48,0xa0},
	{0x49,0xd0},
	{0x4A,0x28},
	{0x4B,0x7d},
	{0x4C,0xd0},
	{0x4D,0xe0},
	{0x4E,0x1a},
	{0x4F,0xa0},
	{0x50,0xc0},
	{0x51,0xc0},
	{0x52,0x42},
	{0x53,0x7e},
	{0x54,0xc0},
	{0x55,0xf0},
	{0x56,0x1e},
	{0x57,0xe0},
	{0x58,0xc0},
	{0x59,0xa0},
	{0x5A,0x4a},
	{0x5B,0x7e},
	{0x5C,0xc0},
	{0x5D,0xf0},
	{0x5E,0x2a},
	{0x5F,0x10},
	{0x79,0x00},          
	{0x7a,0x00},
	{0xe0,0x0f},
	{0xe3,0x14}, 
	{0xe5,0x48},
	{0xe7,0x58},

	//=============== page1 ===============//
	{0xec,0x01},
	{0x10,0x05},
	{0x20,0xde},
	{0x0b,0x06},
	{0x30,0x00},
	{0x31,0x00},
	{0x32,0x00},
	{0x24,0x28},
	{0x25,0x3F},
	{0x26,0x65},
	{0x27,0xA1},
	{0x28,0xFF},
	{0x29,0x96},
	{0x2A,0x85},
	{0x2B,0xFF},
	{0x2C,0x00},
	{0x2D,0x1B},
	{0xB0,0x28},
	{0xB1,0x3F},
	{0xB2,0x65},
	{0xB3,0xA1},
	{0xB4,0xFF},
	{0xB5,0x96},
	{0xB6,0x85},
	{0xB7,0xFF},
	{0xB8,0x00},
	{0xB9,0x1B},
	{0x15,0x15},
	{0x18,0x85},
	{0x1f,0x05},
	{0x87,0x40},
	{0x37,0x60},
	{0x38,0xd5},
	{0x48,0xa0},
	{0x61,0x54},
	{0x62,0x54},
	{0x63,0x14},
	{0x64,0x14},
	{0x6d,0x12},
	{0x78,0x09},
	{0x79,0xD7},
	{0x7A,0x14},
	{0x7B,0xEE},
	                 
	//=============== page2 ===============//
	{0xec,0x02},
	{0x2c,0x76},
	{0x25,0x25},
	{0x27,0x27},
	{0x30,0x29},
	{0x36,0x08},
	{0x38,0x04},

	//=============== page3 ===============//
	{0xec,0x03},
	{0x08,0x00},
	{0x09,0x33},

	//=============== page4 ===============//
	{0xec,0x04},
	{0x00,0x21},
	{0x01,0x00},            
	{0x02,0x9d},            
	{0x03,0x02},            
	{0x04,0x04},         
	{0x05,0x00},            
	{0x06,0x1f},          
	{0x07,0x02},            
	{0x08,0x21},            
	{0x09,0x00},            
	{0x0a,0x9d},           
	{0x0b,0x02},            
	{0x0c,0x04},             
	{0x0d,0x00},            
	{0x0e,0x20},            
	{0x0f,0x02},            
	{0x1b,0x3c},            
	{0x1c,0x3c},            

	//=============== page5 ===============//
	{0xec,0x05},                               
	{0x1f,0x00},                               
	{0x08,0x59},            
	{0x0a,0x71},            
	{0x1e,0x23},            
	{0x0e,0x3c},            

	//=============== page7 ===============//
	{0xec,0x07},
	{0x11,0xfe},

	// added by junon
	{0xec,0x01}, 
	{0x10,0x26}, // 0x21-ITU-R656(CbYCrY), 0x25-ITU-R601(CbYCrY), 0x26-ITU-R601(YCrYCb)

#elif  S5X532_VER == 37 // 2004.05.10 ISP_REV37

	{0xec,0x01},   
	{0x0f,0x03},   
	{0x8a,0x7e}, 

	{0x10,0x04},   
	{0x20,0x90},                 
	{0x22,0x26},   
	{0x0b,0x06},   

	{0x4c,0x03},   

	{0xc0,0xe0},   
	{0xc1,0xc0},   
	{0xc2,0xa0},   
	{0xc3,0x88},   
	{0xc4,0x90},   
	{0xc5,0xa0},   
	{0xc6,0xb0},   
	{0xc7,0xc0},   
	     
	{0xc8,0xfb},   
	{0xc9,0xf0},   
	{0xca,0xc0},   
	{0xcb,0x90},   
	{0xcc,0x82},   
	{0xcd,0x9c},   
	{0xce,0xb0},   
	{0xcf,0xe0},   

	{0x61,0x54},   
	{0x62,0x54},   
	{0x63,0x14},   
	{0x64,0x14},   
	{0x7A,0x14},   
	{0x7B,0xEE}, 
	 
	//page2             
	{0xec,0x02},   

	{0x1b,0x99},  //99 at 20Mhz  // aa at 19.2Mhz
	{0x1c,0x99},  //99 at 20Mhz  // aa at 19.2Mhz 
	{0x2c,0x75},   
	{0x25,0x25},   
	{0x27,0x27},   
	{0x30,0x29},  
	{0x36,0x08},  
	{0x38,0x04},  
	 
	//page3             
	{0xec,0x03},   
	{0x08,0x00},   
	{0x09,0x10},  // 33 at 20frame   
	 
	//page4	            
	{0xec,0x04},   
	{0x00,0x21},   
	{0x01,0x00},   
	{0x02,0x9d},   
	{0x03,0x02},   
	{0x04,0x04},   
	{0x05,0x00},   
	{0x06,0x1f},   
	{0x07,0x02},   
	{0x08,0x21},   
	{0x09,0x00},   

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?