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

📄 camif.c

📁 s3c24a0固件测试代码 ? ? ? ? ?啊 
💻 C
📖 第 1 页 / 共 3 页
字号:
{

	//rCLKDIVN=(rCLKDIVN&~(0xf<<8))|(0x1<<8);

	switch(CAMTYPE) {
		case CAM_OV7620:
		case CAM_OV7620_16:
			rCIGCTRL|= (1<<31)|(1<<29); //camera I/F soft reset
			Delay(1);
			rCIGCTRL&= ~(1<<31);

			rCIGCTRL|=(1<<30);	//external camera reset assertion (OV7620=high active)	
			Delay(200);
			rCIGCTRL&=~(1<<30);		//external camera reset deassertion

			rCIGCTRL|=(1<<26);  // XciPCLK Polarity setting
			break;
		case CAM_S5X532:
		case CAM_S5K3BAFX:
			rCIGCTRL|= (1<<31)|(1<<30)|(1<<29); //camera I/F soft reset
			Delay(1);
			rCIGCTRL&= ~(1<<31);
			
			rCIGCTRL&=~(1<<30);	//external camera reset assertion (S5X433,AU70H=low active)	
			Delay(1000);
			rCIGCTRL|=(1<<30);		//external camera reset deassertion	

			rCIGCTRL|=(1<<26);  // XciPCLK Polarity setting
			break;
		default:
			break;
	}	

}

void SetCAMClockDivider(int divn)
{
    rCLKDIVN= (rCLKDIVN & ~(0xf<<8))|(divn<<8);    
}

/* Description of Parameters
CoDstWidth: Destination Width of Codec Path
CoDstHeight: Destination Height of Codec Path
PrDstWidth: Destination Width of Preview Path
PrDstHeight: Destination Height of Preview Path
WinHorOffset: Size of Window Offset for Horizontal Direction
WinVerOffset: Size of Window Offset for Vertical Direction
CoFrameBuffer: Start Address for Codec DMA
PrFrameBuffer: Start Address for Previe DMA
*/
void CamInit(U32 CoDstWidth, U32 CoDstHeight, U32 PrDstWidth, U32 PrDstHeight, 
			U32 WinHorOffset, U32 WinVerOffset,  U32 CoFrameBuffer, U32 PrFrameBuffer)
{
	U32 WinOfsEn;
	U32 divisor, multiplier;
	U32 MainBurstSizeY, RemainedBurstSizeY, MainBurstSizeC, RemainedBurstSizeC, MainBurstSizeRGB, RemainedBurstSizeRGB;
	U32 H_Shift, V_Shift, PreHorRatio, PreVerRatio, MainHorRatio, MainVerRatio;
	U32 SrcWidth, SrcHeight;
	U32 OrgSrcWidth, OrgSrcHeight;
	U32 ScaleUp_H_Co, ScaleUp_V_Co, ScaleUp_H_Pr, ScaleUp_V_Pr;

	//constraint for size setting is checked here.........

	//constant for calculating codec dma address
	if(camCodecOutput)
		divisor=2; //CCIR-422
	else
		divisor=4; //CCIR-420
		
	//constant for calculating preview dma address
	if(camPviewOutput)
		multiplier=4;
	else
		multiplier=2;
	
	if(WinHorOffset==0 && WinVerOffset==0)
		WinOfsEn=0;
	else
		WinOfsEn=1;

	switch(CAMSIZE) {
		case VGA_XSIZE:
			OrgSrcWidth=VGA_XSIZE;
			OrgSrcHeight=VGA_YSIZE;
			break;
		case SVGA_XSIZE:
			OrgSrcWidth=SVGA_XSIZE;
			OrgSrcHeight=SVGA_YSIZE;
			break;
		case MEGA1_XSIZE:			
			OrgSrcWidth=MEGA1_XSIZE;
			OrgSrcHeight=MEGA1_YSIZE;
			break;
		case MEGA2_XSIZE:
			OrgSrcWidth=MEGA2_XSIZE;
			OrgSrcHeight=MEGA2_YSIZE;
			break;
		default:
			OrgSrcWidth=VGA_XSIZE;
			OrgSrcHeight=VGA_YSIZE;
			break;
	}		
		

	SrcWidth=OrgSrcWidth-2*WinHorOffset;
	SrcHeight=OrgSrcHeight-2*WinVerOffset;

	if(SrcWidth<=CoDstWidth) ScaleUp_H_Co=1;
	else ScaleUp_H_Co=0;		

	if(SrcHeight<=CoDstHeight) ScaleUp_V_Co=1;
	else ScaleUp_V_Co=0;		

	if(SrcWidth<=PrDstWidth) ScaleUp_H_Pr=1;
	else ScaleUp_H_Pr=0;		

	if(SrcHeight<=PrDstHeight) ScaleUp_V_Pr=1;
	else ScaleUp_V_Pr=0;		

	//rCISRCFMT=(CAM_ITU601<<31)|(0<<30)|(CAM_ITU601_8B<<29)|(OrgSrcWidth<<16)|(CAM_ORDER_YCBYCR<<14)|(OrgSrcHeight);
	rCISRCFMT=(CAM_ITU601<<31)|(0<<30)|(CAM_ITU601_8B<<29)|(OrgSrcWidth<<16)|(CAM_ORDER_YCBYCR<<14)|(OrgSrcHeight);
	rCIWDOFST=(WinOfsEn<<31)|(WinHorOffset<<16)|(WinVerOffset);

	if(CAM_CODEC_PINGPONG) {
		rCICOYSA1=CoFrameBuffer;
		rCICOYSA2=rCICOYSA1+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
		rCICOYSA3=rCICOYSA2+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
		rCICOYSA4=rCICOYSA3+CoDstWidth*CoDstHeight+2*CoDstWidth*CoDstHeight/divisor;
		
		rCICOCBSA1=rCICOYSA1+CoDstWidth*CoDstHeight;
		rCICOCBSA2=rCICOYSA2+CoDstWidth*CoDstHeight;
		rCICOCBSA3=rCICOYSA3+CoDstWidth*CoDstHeight;
		rCICOCBSA4=rCICOYSA4+CoDstWidth*CoDstHeight;

		rCICOCRSA1=rCICOCBSA1+CoDstWidth*CoDstHeight/divisor;
		rCICOCRSA2=rCICOCBSA2+CoDstWidth*CoDstHeight/divisor;
		rCICOCRSA3=rCICOCBSA3+CoDstWidth*CoDstHeight/divisor;
		rCICOCRSA4=rCICOCBSA4+CoDstWidth*CoDstHeight/divisor;
	}
	else {
		rCICOYSA1=CoFrameBuffer;
		rCICOYSA2=rCICOYSA1;
		rCICOYSA3=rCICOYSA1;
		rCICOYSA4=rCICOYSA1;
		
		rCICOCBSA1=rCICOYSA1+CoDstWidth*CoDstHeight;
		rCICOCBSA2=rCICOCBSA1;
		rCICOCBSA3=rCICOCBSA1;
		rCICOCBSA4=rCICOCBSA1;

		rCICOCRSA1=rCICOCBSA1+CoDstWidth*CoDstHeight/divisor;
		rCICOCRSA2=rCICOCRSA1;
		rCICOCRSA3=rCICOCRSA1;
		rCICOCRSA4=rCICOCRSA1;		
	}
	
	rCICOTRGFMT=(camCodecInput<<31)|(camCodecOutput<<30)|(CoDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(CoDstHeight);

	CalculateBurstSize(CoDstWidth, &MainBurstSizeY, &RemainedBurstSizeY);
	CalculateBurstSize(CoDstWidth/2, &MainBurstSizeC, &RemainedBurstSizeC);
	rCICOCTRL=(MainBurstSizeY<<19)|(RemainedBurstSizeY<<14)|(MainBurstSizeC<<9)|(RemainedBurstSizeC<<4);

	CalculatePrescalerRatioShift(SrcWidth, CoDstWidth, &PreHorRatio, &H_Shift);
	CalculatePrescalerRatioShift(SrcHeight, CoDstHeight, &PreVerRatio, &V_Shift);
	MainHorRatio=(SrcWidth<<8)/(CoDstWidth<<H_Shift);
	MainVerRatio=(SrcHeight<<8)/(CoDstHeight<<V_Shift);
    			
	rCICOSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio<<0);
	rCICOSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio); 
	rCICOSCCTRL=(CAM_SCALER_BYPASS_OFF<<31)|(ScaleUp_H_Co<<30)|(ScaleUp_V_Co<<29)|(MainHorRatio<<16)|(MainVerRatio);

	rCICOTAREA=CoDstWidth*CoDstHeight;

	if(CAM_PVIEW_PINGPONG) {
		rCIPRCLRSA1=PrFrameBuffer;
		rCIPRCLRSA2=rCIPRCLRSA1+PrDstWidth*PrDstHeight*multiplier;
		rCIPRCLRSA3=rCIPRCLRSA2+PrDstWidth*PrDstHeight*multiplier;
		rCIPRCLRSA4=rCIPRCLRSA3+PrDstWidth*PrDstHeight*multiplier;
	}	
	else {
		rCIPRCLRSA1=PrFrameBuffer;
		rCIPRCLRSA2=PrFrameBuffer;
		rCIPRCLRSA3=PrFrameBuffer;
		rCIPRCLRSA4=PrFrameBuffer;
	}	
    
	rCIPRTRGFMT=(PrDstWidth<<16)|(CAM_FLIP_NORMAL<<14)|(PrDstHeight);

	CalculateBurstSize(PrDstWidth*multiplier, &MainBurstSizeRGB, &RemainedBurstSizeRGB);
    	rCIPRCTRL=(MainBurstSizeRGB<<19)|(RemainedBurstSizeRGB<<14);

	CalculatePrescalerRatioShift(SrcWidth, PrDstWidth, &PreHorRatio, &H_Shift);
	CalculatePrescalerRatioShift(SrcHeight, PrDstHeight, &PreVerRatio, &V_Shift);
	MainHorRatio=(SrcWidth<<8)/(PrDstWidth<<H_Shift);
	MainVerRatio=(SrcHeight<<8)/(PrDstHeight<<V_Shift);
	rCIPRSCPRERATIO=((10-H_Shift-V_Shift)<<28)|(PreHorRatio<<16)|(PreVerRatio);		 
	rCIPRSCPREDST=((SrcWidth/PreHorRatio)<<16)|(SrcHeight/PreVerRatio);
	rCIPRSCCTRL=(1<<31)|(camPviewOutput<<30)|(ScaleUp_H_Pr<<29)|(ScaleUp_V_Pr<<28)|(MainHorRatio<<16)|(MainVerRatio);
    
	rCIPRTAREA= PrDstWidth*PrDstHeight;

	//clear overflow because unintentional overflow may be existed...
	rCIWDOFST|=(1<<30)|(0xf<<12);
	rCIWDOFST&=~((1<<30)|(0xf<<12));	

}



/********************************************************
 CalculateBurstSize - Calculate the busrt lengths
 
 Description:	
 - dstHSize: the number of the byte of H Size.
 
*/
void CalculateBurstSize(U32 hSize,U32 *mainBurstSize,U32 *remainedBurstSize)
{
	U32 tmp;	
	tmp=(hSize/4)%16;
	switch(tmp) {
		case 0:
			*mainBurstSize=16;
			*remainedBurstSize=16;
			break;
		case 4:
			*mainBurstSize=16;
			*remainedBurstSize=4;
			break;
		case 8:
			*mainBurstSize=16;
			*remainedBurstSize=8;
			break;
		default: 
			tmp=(hSize/4)%8;
			switch(tmp) {
				case 0:
					*mainBurstSize=8;
					*remainedBurstSize=8;
					break;
				case 4:
					*mainBurstSize=8;
					*remainedBurstSize=4;
				default:
					*mainBurstSize=4;
					tmp=(hSize/4)%4;
					*remainedBurstSize= (tmp) ? tmp: 4;
					break;
			}
			break;
	}		    	    		
}



/********************************************************
 CalculatePrescalerRatioShift - none
 
 Description:	
 - none
 
*/
void CalculatePrescalerRatioShift(U32 SrcSize, U32 DstSize, U32 *ratio,U32 *shift)
{
	if(SrcSize>=64*DstSize) {
		Uart_Printf("ERROR: out of the prescaler range: SrcSize/DstSize = %d(< 64)\n",SrcSize/DstSize);
		while(1);
	}
	else if(SrcSize>=32*DstSize) {
		*ratio=32;
		*shift=5;
	}
	else if(SrcSize>=16*DstSize) {
		*ratio=16;
		*shift=4;
	}
	else if(SrcSize>=8*DstSize) {
		*ratio=8;
		*shift=3;
	}
	else if(SrcSize>=4*DstSize) {
		*ratio=4;
		*shift=2;
	}
	else if(SrcSize>=2*DstSize) {
		*ratio=2;
		*shift=1;
	}
	else {
		*ratio=1;
		*shift=0;
	}    	
}


void Test_CamPreviewTestQVGADisplay(void)
{

	camTestMode=CAM_TEST_MODE_PVIEW;
	camCodecCaptureCount=0;
	camPviewCaptureCount=0;
	camPviewStatus=CAM_STOPPED;
	camCodecStatus=CAM_STOPPED;

	InitLDI();

#if TEST_DETAIL_EN	
	Uart_Printf("Select bpp of LCD\n");
	Uart_Printf("0: 16bpp, 1:24bpp\n");
	Uart_Printf("Select one:");
	i=Uart_GetIntNum();
	switch(i) {
		case 0:
			LcdBGInit(MODE_PAR_16BIT565_240320|MODE_NO_VIRTUAL_16B);
			GlibInit(MODE_PAR_16BIT565_240320, BGBUFFER1);
			LcdEnvidOnOff(1);			// Enable ENVID Bit
			camCodecOutput=CAM_CCIR420;
			camPviewOutput=CAM_RGB16B;
			break;
		case 1:
			LcdBGInit(MODE_PAR_18BIT_240320|MODE_NO_VIRTUAL_24B);
			GlibInit(MODE_PAR_18BIT_240320, BGBUFFER1);
			LcdEnvidOnOff(1); 			// Enable ENVID Bit			
			camCodecOutput=CAM_CCIR420;
			camPviewOutput=CAM_RGB24B;
			break;
		default:
			LcdBGInit(MODE_PAR_16BIT565_240320|MODE_NO_VIRTUAL_16B);
			GlibInit(MODE_PAR_16BIT565_240320, BGBUFFER1);
			LcdEnvidOnOff(1);			// Enable ENVID Bit
			camCodecOutput=CAM_CCIR420;
			camPviewOutput=CAM_RGB16B;	
			break;
	}	 	
#else
	LcdBGInit(MODE_PAR_16BIT565_240320|MODE_NO_VIRTUAL_16B);
	GlibInit(MODE_PAR_16BIT565_240320, BGBUFFER1);
	LcdEnvidOnOff(1);			// Enable ENVID Bit
	camCodecOutput=CAM_CCIR420;
	camPviewOutput=CAM_RGB16B;	

#endif
	//Camera I/F initialization
	if(CAMTYPE==CAM_S5X532)
		CamInit(640, 480, 240, 320, 112, 40,  0x11000000, LCDFRAMEBUFFERBG1);
	else
		CamInit(640, 480, 240, 320, 0, 0,  0x11000000, LCDFRAMEBUFFERBG1);

#if TEST_DETAIL_EN
	Uart_Printf("Select Shape of Test Pattern\n");
	Uart_Printf("0:camera input, 1:color bar, 2:horizontal increment, 3:vertical increment\n");
	Uart_Printf("Select One:");
	i=Uart_GetIntNum();
	rCIGCTRL&=~(0x3<<27);
	switch(i) {		
		case 0:
			rCIGCTRL|=(0<<27);
			break;
		case 1:
			rCIGCTRL|=(1<<27);
			break;
		case 2:
			rCIGCTRL|=(2<<27);
			break;
		case 3:
			rCIGCTRL|=(3<<27);
			break;
		default:
			break;
	}		
#endif

#if TEST_DETAIL_EN
	Uart_Printf("Select Flip mode\n");
	Uart_Printf("0:normal, 1:X-axis mirror, 2:Y-axis mirror, 3:180 rotation\n");
	Uart_Printf("Select One:");
	i=Uart_GetIntNum();
	rCIPRTRGFMT&=~(0x3<<14);
	switch(i) {
		case 0:
			rCIPRTRGFMT|=(0<<14);
			break;
		case 1:
			rCIPRTRGFMT|=(1<<14);
			break;
		case 2:
			rCIPRTRGFMT|=(2<<14);
			break;
		case 3:
			rCIPRTRGFMT|=(3<<14);
			break;
		default:
			break;
	}		
#endif

	rCIGCTRL|=(1<<26); // Signals of Synchronization are not inverted

	if(CAMTYPE==CAM_OV7620_16) {
		Uart_Printf("16bit YCbYCr is enabled\n");
		rCISRCFMT|=(1<<29);
	}
		
	pISR_CAMIF_PREVIEW=(U32)CamPviewIsr;    
	rINTMSK&=~(BIT_CAMIF_PREVIEW);
	
	Uart_Printf("Camera preview for preview will be started!\n");
	Uart_Printf("Press any key to continue\n");

	CamCaptureStart(CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT);
	Uart_Getch();
	CamCaptureStop();

	while(!(camPviewStatus==CAM_STOPPED )); 

⌨️ 快捷键说明

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