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

📄 camera.c

📁 三星 s3c6400测试代码
💻 C
📖 第 1 页 / 共 5 页
字号:
		default: 
			Assert(0);
			break;
	}
	CAMERA_InitS5K3BAF(oCim.m_eCcir, oCim.m_eCamSrcFmt, eSub);
#elif (CAM_MODEL == CAM_OV7620)
	oCim.m_bInvPclk = false, 
	oCim.m_bInvVsync = false, 
	oCim.m_bInvHref = false;
	oCim.m_uSrcHsz = 640, oCim.m_uSrcVsz = 480;
	oCim.m_eCamSrcFmt = YCBYCR;

	CAMERA_InitOV7620(oCim.m_eCcir, oCim.m_uIfBits, false, oCim.m_eCamSrcFmt);
#else
	Assert(0);
#endif
}


//////////
// Function Name : CAMERA_SetSensorSize
// Function Description : this function use at JPEG Test.
// Input : 	IMG_SIZE eSize(Image Size)
// Output :    	None
void CAMERA_SetSensorSize(IMG_SIZE eSize)
{
	SUB_SAMPLING eSub; 

	// 1. Set the oCim.m_uSrcHsz & oCim.m_uSrcVsz according to eSize
	//=======================================
	if (eSize == UXGA)
		oCim.m_uSrcHsz = 1600, oCim.m_uSrcVsz = 1200; 
	else if (eSize == SXGA)
		oCim.m_uSrcHsz = 1280, oCim.m_uSrcVsz = 1024;
	else if (eSize == SVGA)
		oCim.m_uSrcHsz = 800, oCim.m_uSrcVsz = 600; 
	else if (eSize == VGA)
		oCim.m_uSrcHsz = 640, oCim.m_uSrcVsz = 480; 
	else if (eSize == QVGA)
		oCim.m_uSrcHsz = 320, oCim.m_uSrcVsz = 240; 
	else if (eSize == QQVGA)
		oCim.m_uSrcHsz = 160, oCim.m_uSrcVsz = 120; 
	else if (eSize == CIF)
		oCim.m_uSrcHsz = 352, oCim.m_uSrcVsz = 288; 
	else if (eSize == QCIF)
		oCim.m_uSrcHsz = 172, oCim.m_uSrcVsz = 144; 
	else
	{
		Assert(0);
	}

	// 2. Set the size in camera according to the camera model and eSize.
	//=============================================
#if (CAM_MODEL == CAM_S5K4AAF)
	oCim.m_eCamSrcFmt = (eSize == SXGA) ? YCBYCR : YCRYCB;
	oCim.m_oCamera.SetSizeInS5K4AAF(eSize);
#elif (CAM_MODEL == CAM_S5K3BA)

	switch(eSize)
	{
		case UXGA:case SXGA:
			eSub = SUB_SAMPLING0;
			oCim.m_uSrcHsz = 1600; oCim.m_uSrcVsz = 1200;
			break;
		case SVGA:case VGA:
			eSub = SUB_SAMPLING2;
			oCim.m_uSrcHsz = 800; oCim.m_uSrcVsz = 600; 
			break;
		case QVGA:case QQVGA:case CIF:case QCIF:
			eSub = SUB_SAMPLING4;
			oCim.m_uSrcHsz = 400; oCim.m_uSrcVsz = 300;
			break;
		default: 
			Assert(0);
			break;
	}
	CAMERA_SetSizeInS5K3BAF(eSub);
#elif (CAM_MODEL == CAM_OV7620)

#elif (CAM_MODEL == CAM_S5K3AA)
	CAMERA_SetSizeInS5K3AAE(eSize);
#else
	Assert(0);
#endif
}




//////////
// Function Name : CAMERA_ResetIp
// Function Description : Camera Interface reset function
// 					In ITU601 Case, ITU601_656n: 1 -> SwRst: 1 -> SwRst: 0
// 					In ITU656 Case, ITU601_656n: 1 -> SwRst: 1 -> SwRst: 0 -> ITU601_656n: 0
// Camera interface SW Reset Sequence
// Input : 	None
// Output :    	None
void CAMERA_ResetIp(void)
{
	u32 uSrcFmtRegVal = 0;
	u32 uCtrlRegVal = 0;
	
	uSrcFmtRegVal |= (1U<<31);
	Outp32(&CAMERAR->rCISRCFMT, uSrcFmtRegVal);

	uCtrlRegVal = Inp32(&CAMERAR->rCIGCTRL);
	//Inp32(&CAMERAR->rCIGCTRL, uCtrlRegVal); // Extremely important!! If deleted, cam module will be reset.
	uCtrlRegVal |= (1U<<31);
	Outp32(&CAMERAR->rCIGCTRL, uCtrlRegVal);

	uCtrlRegVal &= ~(1U<<31);
	Outp32(&CAMERAR->rCIGCTRL, uCtrlRegVal);

	if(oCim.m_eCcir == CCIR656)
	{
		uSrcFmtRegVal &= ~(1U<<31);
		Outp32(&CAMERAR->rCISRCFMT, uSrcFmtRegVal);
	}
}



//////////
// Function Name : CAMERA_ResetSencor
// Function Description : Camera Module reset function
// Input : 	None
// Output :    	None
void CAMERA_ResetSensor(void)
{
	u32 uCIGCTRL;
	u32 uDelay;
	
#if (CAM_MODEL == CAM_OV7620)
	oCim.m_bHighRst = true;
//#elif (CAM_MODEL == CAM_S5K3AA || CAM_MODEL == CAM_S5K3BA || CAM_MODEL == CAM_S5K4AAF) // jungil
#elif (CAM_MODEL == CAM_S5K3AA || CAM_MODEL == CAM_S5K3BA || CAM_MODEL == CAM_S5K4AAF || CAM_MODEL == CAM_A3AFX_VGA)
	oCim.m_bHighRst = false; 
#else
	Assert(0);
#endif 

	uCIGCTRL = Inp32(&CAMERAR->rCIGCTRL);
	if (oCim.m_bHighRst)
	{
		uCIGCTRL |= (1<<30);
		Outp32(&CAMERAR->rCIGCTRL, uCIGCTRL);
		for(uDelay = 0 ; uDelay<1000000 ; uDelay++);
		uCIGCTRL &= ~(1<<30);
		Outp32(&CAMERAR->rCIGCTRL, uCIGCTRL);		
		for(uDelay = 0 ; uDelay<1000000 ; uDelay++);		
		
	}
	else
	{
		uCIGCTRL &= ~(1<<30);
		Outp32(&CAMERAR->rCIGCTRL, uCIGCTRL);		
		for(uDelay = 0 ; uDelay<1000000 ; uDelay++);		
		uCIGCTRL |= (1<<30);
		Outp32(&CAMERAR->rCIGCTRL, uCIGCTRL);		
		for(uDelay = 0 ; uDelay<1000000 ; uDelay++);		
	}

}



//////////
// Function Name : CAMERA_SetBasicSft
// Function Description : Camera Interface(Preview/Codec) Basic SFR setting function
// Input : 	u32 uSrcCropStartX(Windoe Offset X1), u32 uSrcCropStartY(Window Offset Y1), u32 uSrcCropHsz(Wanted Source Crop H Size)
//                 u32 uSrcCropVsz(wanted soure V Size), u32 uDstHsz(Destination H Size), u32 uDstVsz(Destination VSzie)
//                 u32 uDstAddr0(Dstination DMA Address 0), u32 uDstAddr1(Destination DMA Address 1), CSPACE eDstDataFmt(Wanted Data Format),
//	              CAMIF_INOUT eInputPath(Input Data source), PROCESS_PATH ePath(Process Path), CAMIF_INOUT eOutputMode(output mode: DMA/FIFO)
//                , FLIP_DIR eFlip(Flip Mode Selection), ROT_DEG eRotDeg(Rotation mode Selection)
// Output :    	None
void CAMERA_SetBasicSfr(u32 uSrcCropStartX, u32 uSrcCropStartY, u32 uSrcCropHsz, u32 uSrcCropVsz,
	u32 uDstHsz, u32 uDstVsz, u32 uDstAddr0, u32 uDstAddr1, CSPACE eDstDataFmt,
	CAMIF_INOUT eInputPath, PROCESS_PATH ePath, CAMIF_INOUT eOutputMode, FLIP_DIR eFlip, ROT_DEG eRotDeg)
{
	u32 uSrcHOffset1, uSrcVOffset1, uSrcHOffset2, uSrcVOffset2;
	u32 uSrcCroppingHSz, uSrcCroppingVSz;
	u32 uFlip;
	bool bIsHScaleUp;
	bool bIsVScaleUp;	
	u32 uRemainBurstLen=0;
	u32 uCMainBurstLen =0;
	u32 uCRemainBurstLen = 0;
	u32 uPreHRatio, uPreVRatio;
	u32 uMainHRatio, uMainVRatio; 
	u32 uShiftFactor;
	u32 uPreDstHSz, uPreDstVSz;
	u32 uHShift, uVShift;
	u32 uLimitHsz;
	u32 uInputIntlvOrder=0;
	u32 uWinOfsEn;
	int nSrcFmt = 0;
	int nSrcYCbCrOrder;
	int nOutputIntlvOrder = 0;
	int nOutRGBFMTPr = 3 ;
	int nOutFormatPr;
	u32 uOutCbCrSz;
	u32 uOutYSz;
	u32 uTargetFmt;
	u32 uDMAControl;
	u32 uPreScalerCtrl1;
	u32 uPreScalerCtrl2;

	Assert(oCim.m_uSrcHsz != 0 && oCim.m_uSrcVsz != 0);

	// 1. Set input path, output path, process path and destination format 
	//=================================================
	oCim.m_eInputPath = eInputPath;
	oCim.m_eProcessPath = ePath;
	oCim.m_eOutputPath = eOutputMode;

	if (oCim.m_eOutputPath==DMA)
	{
		Assert(eDstDataFmt ==YCBYCR || eDstDataFmt==YCRYCB ||eDstDataFmt ==CRYCBY ||eDstDataFmt==CBYCRY
			|| eDstDataFmt==RGB16 || eDstDataFmt==RGB18 ||eDstDataFmt==RGB24 
			|| eDstDataFmt==YC420 || eDstDataFmt==YC422 );
		oCim.m_eDstFmt = eDstDataFmt;
	}
	else 
	{
		oCim.m_eDstFmt = eDstDataFmt; // In fifo output path
	}

	// 2. Compute the horizontal offset and vertical offset, check whether offset size and source size meet the limitation
	//=========================================================================
	uSrcHOffset1 = uSrcCropStartX;
	uSrcVOffset1 = uSrcCropStartY;

	uSrcHOffset2 = oCim.m_uSrcHsz - (uSrcCropHsz + uSrcHOffset1);
	uSrcVOffset2 = oCim.m_uSrcVsz - (uSrcCropVsz + uSrcVOffset1);

	Assert((uSrcHOffset1%2 == 0)); // manual p24 Window horizontal offset1 should be 2's multiple!
	Assert((uSrcHOffset2%2 == 0)); // manual p27 Window horizontal offset2 should be 2's multiple!
	Assert(oCim.m_uSrcHsz >= uSrcHOffset1 + uSrcCropHsz); // Invid horizontal size of original source or cropped window or start coordinate X
	Assert(oCim.m_uSrcVsz >= uSrcVOffset1 + uSrcCropVsz); // Invid vertical size of original source or cropped window or start coordinate Y
	if (oCim.m_eInputPath==FIFO)
	{
		Assert(oCim.m_uSrcHsz%8 == 0 && oCim.m_uSrcHsz >= 16 && oCim.m_uSrcVsz >= 8); // manual p23
	}

	// 3. Set input & output rotator degree and flip
	//=============================================
	oCim.m_eInRotDeg = ROT_0;
	oCim.m_eOutRotDeg = eRotDeg;
	if (eRotDeg==ROT_180 || eRotDeg==ROT_270)
	{
		Assert(eFlip==FLIP_NO);
	}
	if (eRotDeg==ROT_180)
	{
		eRotDeg = ROT_0;
		eFlip=FLIP_XY;
	}
	if(eRotDeg==ROT_270)
	{
		eRotDeg = ROT_90;
		eFlip=FLIP_XY;
	}
	uFlip = (eFlip == FLIP_X) ? 1 : (eFlip == FLIP_Y) ? 2 : (eFlip == FLIP_XY) ? 3 : 0;
	if (oCim.m_eOutputPath==FIFO)
	{ 
		Assert(uFlip == FLIP_NO);
		if (oCim.m_eInputPath==DMA && oCim.m_eMemSrcFmt==YC420)//just YC420 support input-rotation
			oCim.m_eInRotDeg = eRotDeg;
		else
		{
			Assert(eRotDeg== ROT_0);
		}
	}
	else
		oCim.m_eOutRotDeg = eRotDeg;

	// 4. Set destination size, check whether the destination size meet the limitation.
	//======================================================
	if (oCim.m_eOutRotDeg==ROT_0)
	{
		oCim.m_uDstHsz = uDstHsz;
		oCim.m_uDstVsz = uDstVsz;
	}
	else if (oCim.m_eOutRotDeg==ROT_90 )
	{
		oCim.m_uDstHsz = uDstVsz;
		oCim.m_uDstVsz = uDstHsz;
	}
	else
	{
		Assert(0);
	}

/*
if (oCim.m_eInputPath==FIFO) // Manual p44 
	{
		Assert(oCim.m_uDstHsz <= oCim.m_uSrcHsz); // Horiztonal size of destnation should be less than horizontal size of source
		Assert(oCim.m_uDstVsz <= oCim.m_uSrcVsz); // Vertical size of destnation should be less than the vertical size of source
	}
*/

	// 5. Set cropping size, check whether the cropping size meet the limitation.
	//====================================================
	if (oCim.m_eInRotDeg==ROT_0)
	{
		uSrcCroppingHSz = uSrcCropHsz;
		uSrcCroppingVSz = uSrcCropVsz;
	}
	else if (oCim.m_eInRotDeg==ROT_90 )
	{
		uSrcCroppingHSz = uSrcCropVsz;
		uSrcCroppingVSz = uSrcCropHsz;
	}
	else
	{
		Assert(0);
	}
	// manual p25 Source corpping horizontal size should be 8's multiple and minimum 16!
	Assert(uSrcCroppingHSz%8 == 0 && uSrcCroppingHSz >= 16); 


	// 6. Check whether destination size meet the limitation.
	//===================================================
	if (oCim.m_eOutputPath==DMA) // manual p31, p44
	{
		if (oCim.m_eOutRotDeg==ROT_0)
		{
			Assert(oCim.m_uDstHsz%16 == 0 && oCim.m_uDstHsz >= 16 && oCim.m_uDstVsz >= 4); 
		}
		else if(oCim.m_eOutRotDeg==ROT_90)
		{
			if (oCim.m_eProcessPath==P_PATH)
			{
				if ((oCim.m_eDstFmt==RGB24|| oCim.m_eDstFmt == RGB18) && oCim.m_uDstHsz>OUTPUT_MAX_HSIZE_ROT_RGB_P/2)
				{
					Assert(oCim.m_uDstVsz%4 ==0 ); // When output is RGB24 & h_width>160, Target vertical size should be 4's multiple!
				}
				else
				{
					Assert(oCim.m_uDstVsz%8 ==0); // When set rotation, Target vertical size should be 8's multiple!
				}
			}
			else //oCim.m_eProcessPath==C_PATH
			{
				if ((oCim.m_eDstFmt==RGB24|| oCim.m_eDstFmt == RGB18) && oCim.m_uDstHsz>OUTPUT_MAX_HSIZE_ROT_RGB_C/2)
				{
					Assert(oCim.m_uDstVsz%4 == 0); // When output is RGB24 & TargheHsize>400, Target vertical size should be 4's multiple!
				}
				else
				{
					Assert(oCim.m_uDstVsz%8 ==0); // When set rotation, Target vertical size should be 8's multiple!
				}
			}
		}
		else
		{
			Assert(0);
		}
	}

	// 7. Set bIsHScaleUp/bIsVScaleUp and oCim.m_bIsScalerBypass
	//===========================================
	bIsHScaleUp = (uSrcCroppingHSz <= oCim.m_uDstHsz) ? true : false; // Horizontal scale up/down - 1: Up, 0: Down
	bIsVScaleUp = (uSrcCroppingVSz <= oCim.m_uDstVsz) ? true : false; // Vertical scale up/donw - 1: up, 0: down

⌨️ 快捷键说明

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