⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cameram.c

📁 s3c6400 ADS下官方测试程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/**************************************************************************************
* 
*	Project Name : S3C6400 Validation
*
*	Copyright 2006 by Samsung Electronics, Inc.
*	All rights reserved.
*
*	Project Description :
*		This software is only for validating functions of the S3C6400.
*		Anybody can use this software without our permission.
*  
*--------------------------------------------------------------------------------------
* 
*	File Name : cameram.c
*  
*	File Description : Camera module setting code
*
*	Author : 
*	Dept. : AP Development Team
*	Created Date : 
*	Version : 0.1 
* 
*	History
*	- Created
*  
**************************************************************************************/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "system.h"
#include "cameram.h"
#include "iic.h"
#include "intc.h"
#include "option.h"
#include "library.h"
#include "sfr6400.h"
#include "sysc.h"
#include "Camera.h"

CAMERA oCamera;




void CAMERA_IICOpen(int Frequency)
{
	IIC_Open(Frequency);
}


void CAMERA_IICClose(void)
{
	IIC_Close();
}

//////////
// Function Name : CAMERA_Read_Write
// Function Description : Camera Module 2M / 1.3M SFR Read Write
// Input : 	u32 uCAMTYPE(0: S5K3AAE / 1:S5K3BAF) ,CAM_ATTR eCcir(601or656Format), CSPACE eSrcFmt(Camera Source Firmat)
//                  SUB_SAMPLING eSub(S5K3VAF module Camera Image Setting Value)
// Output :    	None
void CAMERA_Read_Write(u32 uCAMTYPE,CAM_ATTR eCcir, CSPACE eSrcFmt, SUB_SAMPLING eSub)
{
	u8 x;
	u32 uOutSel;
	u32 uYcSel;
	u32 uCrCbSel;
	
	CAMERA_IICOpen(300000);

	switch ( uCAMTYPE )
	{
		case 0:
			oCamera.m_ucSlaveAddr = 0x5a;

			CAMERA_SetReg(0xec, 0x00);
			//	CAMERA_SetReg(0x72, 0x7d);	//25 Mhz MCLK Setting
			//	CAMERA_SetReg(0x72, 0xc8);	// 40 Mhz MCLK Setting
			CAMERA_SetReg(0x72, 0x64);	// 20 Mhz MCLK Setting
			//	CAMERA_SetReg(0x72, 0x3c);	// 12.5 Mhz MCLK Setting
	
			CAMERA_SetReg(0xec, 0x00);
			CAMERA_GetReg(0x72, &x);
			//	printf("\nCheck 25Mhz Setting = 0x7D ---->  %x", x);
			printf("\nCheck 20Mhz Setting = 0x64 ---->  0x%x", x);	
	
			CAMERA_SetReg(0xec, 0x07);
			CAMERA_SetReg(0x37, 0x00);
			//	CAMERA_SetReg(0x37, 0x5);	// 12.5 Mhz Setting

			CAMERA_SetReg(0xec, 0x00);
			CAMERA_GetReg(0x02, &x);
			printf("\nImage Size Setting is 0x00 ===> 0x%x(0:SXGA 1:VGA)\n",  x);
			
			Delay(20000);

			// Camera data format, YC order setting
			uOutSel = (eCcir == CCIR601) ? (1<<2) : (0<<2);
			uYcSel = (eSrcFmt == YCBYCR || eSrcFmt == YCRYCB) ? (1<<1) : (0<<1);
			uCrCbSel = (eSrcFmt == YCRYCB || eSrcFmt == CRYCBY) ? (1<<0) : (0<<0);
			CAMERA_SetReg(0xec, 0x01);
			//	CAMERA_SetReg(0x6a, uOutSel | uYcSel | uCrCbSel);
			CAMERA_SetReg(0x6a, uOutSel | uYcSel | 1);

			CAMERA_SetReg(0xec, 0x01);
			CAMERA_GetReg(0x6a, &x);
			printf("\nImage Data 0x01======> 0x%x", x);

			break;
		case 1:
			CAMERA_SetReg(0xfc, 0x01);
			CAMERA_SetReg(0x03, 0x01); // sw reset
			//PLL SETTING MCLK = 27Mhz PLL_CLK = 64 PCLK = 32
			CAMERA_SetReg(0xfc, 0x01);
			CAMERA_SetReg(0x04, 0x03); //PCLK = PLL / 2^1

			CAMERA_SetReg(0xfc, 0x01);
			CAMERA_GetReg(0x04, &x); // PCLK Setting Value
			printf("\nPCLK Divider Setting Value 0x03 = 0x%x", x);
			
			CAMERA_SetReg(0xfc, 0x02);
			CAMERA_SetReg(0x52, 0x80);  //PLL M=128d

			CAMERA_SetReg(0xfc, 0x02);
			CAMERA_GetReg(0x52, &x); // PLL _M = 128
			printf("\nPLL_M Value 128 = 0x%d", x);
			
			CAMERA_SetReg(0xfc, 0x02);
			CAMERA_SetReg(0x50, 0x54); // PLL_S = 2 

			CAMERA_SetReg(0xfc, 0x02);
			CAMERA_GetReg(0x50, &x); // P , S Value
			printf("\nP/S Setting Value 0x54 = 0x%x", x);
			
			CAMERA_SetSizeInS5K3BAF(eSub);
			/// Camera data format, YC order setting
			uOutSel = (eCcir == CCIR601) ? (1<<2) : (0<<2);
			uYcSel = (eSrcFmt == YCBYCR || eSrcFmt == YCRYCB) ? (1<<1) : (0<<1);
			uCrCbSel = (eSrcFmt == YCRYCB || eSrcFmt == CRYCBY) ? (1<<0) : (0<<0);
			CAMERA_SetReg(0xfc, 0x01);
			CAMERA_SetReg(0x02, uOutSel|uYcSel|uCrCbSel);

			CAMERA_SetReg(0xfc, 0x01);
			CAMERA_GetReg(0x02, &x); // Image Size Setting Value
			printf("\nImage Size Setting  Value 0x07 = 0x%x\n\n", x);
			

			break;
		default : 
			break;
	}

	CAMERA_IICClose();
}



//////////
// Function Name : CAMERA_SetReg
// Function Description : camera module register setting
// Input : 	u8 ucSubAddr(adress), u8 ucData(data)
// Output :    	None
#if 1 
void CAMERA_SetReg(u8 ucSubAddr, u8 ucData)
{
	u8 D[2];

	D[0] = ucSubAddr;
	D[1] = ucData;
	IIC_SetWrite(oCamera.m_ucSlaveAddr, D, 2);
	IIC_Wait();
}
#else // for Debugg
void CAMERA_SetReg(u8 ucSubAddr, u8 ucData)
{
	u8 D[2];
	u8 x;

	D[0] = ucSubAddr;
	D[1] = ucData;
	IIC_SetWrite(oCamera.m_ucSlaveAddr, D, 2);
	IIC_Wait();

//	if ( ucSubAddr != 0xef)
	if ( ucSubAddr != 0xec)		
	{
		CAMERA_GetReg(ucSubAddr, &x);
		if ( ucData != x )
		{
			printf("Addr = %x, Value=%x, Real=%x\n", ucSubAddr, ucData, x);
		}
	}
	else
	{
		printf("-------------------Page = , %x\n", ucData);

	}
}

#endif


//////////
// Function Name : CAMERA_GetReg
// Function Description : get camera module data
// Input : 	None
// Output :    	None
void CAMERA_GetReg(u8 ucSubAddr, u8* ucData)
{
	IIC_SetWrite( oCamera.m_ucSlaveAddr, &ucSubAddr, 1);
	IIC_SetRead( oCamera.m_ucSlaveAddr, ucData, 1);
	IIC_Wait();
}

//////////
// Function Name : CAMERA_InitOV7620
// Function Description : cameramodule setting OV7620
// Input : 	None
// Output :    	None
void CAMERA_InitOV7620(CAM_ATTR eCcir, u32 uBits, bool bInv, CSPACE eSrcFmt)
{
	u8 ucVal;

//	IIC_Init();
	oCamera.m_ucSlaveAddr = 0x42;
	
//	CAMERA_SetReg(0x12, 0x80);	// Camera Soft reset. Self cleared after reset.
//	Delay(100);

	CAMERA_SetReg(0x00, 0x00);	// AGC gain
	CAMERA_SetReg(0x01, 0x80);	// blue gain
	CAMERA_SetReg(0x02, 0x80);	// red gain

	CAMERA_SetReg(0x03, 0xb0);	// saturation control
	CAMERA_SetReg(0x06, 0x60);	// set brightness - CJH
	CAMERA_SetReg(0x0c, 0x24);	// set white balance blue background
	CAMERA_SetReg(0x0d, 0x24);	// set white balance red background
	CAMERA_SetReg(0x10, 0xff);	// set auto exposure time, (not used in auto adjust mode)

	ucVal = 0;
	if (bInv)
	{
		ucVal |= (0<<7);
		ucVal |= (1<<6);
	}
	else
	{
		ucVal |= (1<<7);
		ucVal |= (0<<6);
	}
	ucVal |= (0<<0);
	CAMERA_SetReg(0x11, ucVal);

	ucVal = 0;
	if ( eSrcFmt == YCBYCR || eSrcFmt == YCRYCB)
		ucVal |= (1<<4); 
	ucVal |= (1<<2); // enable white balnace
	ucVal |= (1<<5); // enable AGC
	CAMERA_SetReg(0x12, ucVal);

	ucVal = 0;
	ucVal |= (uBits == 8 ? 1 : 0)<<5;
	ucVal |= (eCcir == CCIR656 ? 1 : 0)<<4;
	CAMERA_SetReg(0x13, ucVal);

	Delay(10);

	ucVal |= 0;
	if (eSrcFmt == CBYCRY || eSrcFmt == YCBYCR)
		ucVal |= (1<<0);
	ucVal |= (bInv  ? 1 : 0)<<6;
	CAMERA_SetReg(0x15, ucVal);

	Delay(10);	
	
	CAMERA_SetReg(0x16, 0x03);	// Field mode : 11b-FRAME mode -> FD<7:2> is useless (default)
	CAMERA_SetReg(0x17, 0x2f);	// 47 -> Horizontal Start
	CAMERA_SetReg(0x18, 0xcf);	// (207-47)*4=640 -> Horizontal End
	CAMERA_SetReg(0x19, 0x06);	// 6 -> Vertical Start
	CAMERA_SetReg(0x1a, 0xf5);	// (245-6+1)*2=480 -> Vertical End
	CAMERA_SetReg(0x1b, 0x00);	// pixel shift=0

				//(??old,incorrect) limit vertical size to 480, second stage aperture correction enable
	CAMERA_SetReg(0x20, (0<<7));	// limit vertical size to 480  -> bit 7: Modified CCIR656 format vertical sizing enabled
	CAMERA_SetReg(0x21, 0x80);	// Y Channel Offset Adjustment - 0 , direction - Subtract
	CAMERA_SetReg(0x22, 0x80);	// U Channel Offset Adjustment - 0
	CAMERA_SetReg(0x23, 0x00);	// Crystal Current control : maximum current
	CAMERA_SetReg(0x26, 0xa2);	// digital sharpness threshold(64mV), magnitude(100%). 
	
	CAMERA_SetReg(0x27, 0xe2 );	// default, disable CCIR rang clip
				//?? old value: 0xea, but bit[3] is reserved, why 1 ?
	CAMERA_SetReg(0x29, (0<<6));	// CHSYNC & VSYNC master mode
	CAMERA_SetReg(0x2a, 0x00);	// default(
				// (?? old,incorrect)frame rate high, 60Hz, 50Hz:0x80, UV delay 2 pixel. - CJH
	CAMERA_SetReg(0x2b, 0x00);	// default
				// (??old,incorrect) frame rate low, 60Hz, 50Hz:0xac
	CAMERA_SetReg(0x2c, 0x88);	// default
	CAMERA_SetReg(0x2e, 0x80);	// default
	CAMERA_SetReg(0x2f, 0x44);	// default
	CAMERA_SetReg(0x60, 0x27);	// default 
	CAMERA_SetReg(0x61, 0x82);	// YUV mode (7'st bit -> 1(YUV mode)) 
	CAMERA_SetReg(0x62, 0x5f);	// RGB Gamma control, gamma=010_1111b
	CAMERA_SetReg(0x63, 0xd5);	// reserved value ???
	CAMERA_SetReg(0x64, 0x57);	// enable Y Gamma,gammma=010_1011b	
	CAMERA_SetReg(0x65, 0x80+(3<<0));//??? bit[7:3]is reserved 01000b, why 0x80?, ADC_ref=11b(1.26V peak)
	CAMERA_SetReg(0x66, 0x55);	// default 
	CAMERA_SetReg(0x68, 0xcf);	// not default
	CAMERA_SetReg(0x69, 0x76);	// not default
	CAMERA_SetReg(0x6a, 0x22);	// not default
	CAMERA_SetReg(0x6b, 0x00);	// ??reserved
	CAMERA_SetReg(0x6c, 0x08);	// ??reserved
	CAMERA_SetReg(0x6d, 0x48);	// ??reserved
	CAMERA_SetReg(0x6e, 0x80);	// ??reserved
	CAMERA_SetReg(0x6f, 0x0c);	// ?? how? -CJH ( default=0x3a)
	CAMERA_SetReg(0x70, 0x89);	// -CJH, accelerated saturation mode(fast), -> if 3'st bit is zero, acclerated saturation mode
	CAMERA_SetReg(0x71, 0x00);	//  default, freerunning PCLK
	CAMERA_SetReg(0x72, 0x14);	//  default
	CAMERA_SetReg(0x73, 0x54);	//  default
	CAMERA_SetReg(0x75, 0x0e);	// ?? -CJH (bit[6:3]=reserved)
	CAMERA_SetReg(0x76, 0x00);	// default
	CAMERA_SetReg(0x77, 0xff);	// ??reserved
	CAMERA_SetReg(0x78, 0x80);	// ??reserved
	CAMERA_SetReg(0x79, 0x80);	// ??reserved
	CAMERA_SetReg(0x7a, 0x80);	// ??reserved
	CAMERA_SetReg(0x7b, 0xe6);	// ???reserved -CJH 
	CAMERA_SetReg(0x7c, 0x00);	// default

	ucVal = 0;
	ucVal |= (bInv ? 1 : 0)<<3;
	ucVal |= (1<<7);
	ucVal |= (1<<4);
	ucVal |= (1<<2);
	CAMERA_SetReg(0x14, ucVal);
	
	CAMERA_SetReg(0x24, 0x10);	// for progressive - CJH
	CAMERA_SetReg(0x25, 0x8a);	// for progressive - CJH 
	CAMERA_SetReg(0x28, 0x20);	// select progressive mode. -> if 5'st bit is '1', progressive scan mode 
	CAMERA_SetReg(0x2d, 0x95);	// auto brightness(4'st bit is '1'), banding filter enabled
	CAMERA_SetReg(0x67, 0x92);	// Color space=601 YCrCb, Y signal delay=0
	CAMERA_SetReg(0x74, 0x00);	// AGC maximum gain=2x.(COMM[6:5] is 00) -CJH
}

//////////
// Function Name : CAMERA_InitS5K3AAE
// Function Description : camera module(S5K3AAE) initaialize
// Input : 	CAM_ATTR eCcir(Camera Order), CSPACE eSrcFmt(Camera source format), IMG_SIZE eSrcSz(Camera source size)
// Output :    	None
void CAMERA_InitS5K3AAE_VGA(void)
{
	oCamera.m_ucSlaveAddr = 0x5a;

	CAMERA_IICOpen(100000);

	//***************************************************
	CAMERA_SetReg(0xec, 0x00);
	CAMERA_SetReg(0x72, 0x7d);	//25 Mhz MCLK Setting
//	CAMERA_SetReg(0x72, 0xc8);	//40 Mhz MCLK Setting	
	CAMERA_SetReg(0xec, 0x07);
	CAMERA_SetReg(0x37, 0x0);   //25 Mhz MCLK Setting

	CAMERA_SetReg(0xec,0x00);
	CAMERA_SetReg(0x02,0x01);	// VGA Setting, Scale Down
//	CAMERA_SetReg(0x02,0x30);	// VGA Setting, Sub Sampleing
	CAMERA_SetReg(0xec, 0x01);
	CAMERA_SetReg(0x6a, 0x01);  // CRYCBY Setting. ITU656 Format
	//***************************************************

#if 1 // VGA Scale down SFR Setting Code
	// ScaleDown
	CAMERA_SetReg(0xec,0x04);
	//VGA scaledown
	CAMERA_SetReg(0x2d,0x7d);//<1.69h>
	CAMERA_SetReg(0x2e,0x01);//06	//<1.6ah>
//	CAMERA_SetReg(0x2f,0x05);//HCNT_END_H
//	CAMERA_SetReg(0x30,0x9f);//HCNT_END_L
//	CAMERA_SetReg(0x36,0x10);//42	//HBLK_START_L   
//	CAMERA_SetReg(0x37,0x04);//HBLK_OFFSET_H
//	CAMERA_SetReg(0x38,0xff);  //HBLK_OFFSET_L
//	CAMERA_SetReg(0x3a,0x05);  //VBLK_START_L 
//	CAMERA_SetReg(0x40,0x11);//45   //HS656_START_L
//	CAMERA_SetReg(0x42,0x01);//HS656_OFFSET_L
//	CAMERA_SetReg(0x44,0x0a);//VS656_START_L
//	CAMERA_SetReg(0x4c,0x00);//<1.93h>
//	CAMERA_SetReg(0x4d,0x00);//<1.94h>
//	CAMERA_SetReg(0x4e,0x00);//<1.95h>
//-------------------------------------------------------------------------
#endif

#if 0
	/////////////////////////////
	///Flicker setting
	CAMERA_SetReg(0xec,0x00);
//	CAMERA_SetReg(0x74,0x18);  // Auto Flicker start 60hz for 7.5fps
	CAMERA_SetReg(0x74,0x00);  // Auto Flicker start 60hz for 7.5fps	

	/////////////////////////////
	// Frame AE 
	CAMERA_SetReg(0xec,0x00);
//	CAMERA_SetReg(0x73,0x11);	// frame 1/2
	CAMERA_SetReg(0x73,0x00);	// frame 1/2	
#endif

#if 0 // Subsampleing 640*480 Code
	//QVGA Subsampling 640x480

⌨️ 快捷键说明

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