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

📄 camif.c

📁 2440 cpu test
💻 C
📖 第 1 页 / 共 2 页
字号:
				break;
			default:
				break;
		}
			
		CamCodecIntUnmask();
	    camCodecCaptureCount++;	 
	}
	else
	{
		Uart_Printf("[P]"); 
		CamPreviewIntMask();
		rSUBSRCPND |= BIT_SUB_CAM_P;
		ClearPending(BIT_CAM) 	
		switch(camPviewStatus) {
			case CAM_STOP_ISSUED:
				_CamPviewStopHw();
				camPviewStatus=CAM_LAST_CAPTURING;	 
				Uart_Printf("pr=%x\n", rCIPRCTRL);
				//Uart_Printf("pS1\n");
				break;
			case CAM_LAST_CAPTURING:
				camPviewStatus=CAM_STOPPED;
				CamPreviewIntMask();
				//Uart_Printf("pS2\n"); 	
				return;
			case CAM_STARTED:
				flagCaptured_P = 1;
				if(camTestMode&CAM_TEST_MODE_PVIEW) {
					if(camPviewCaptureCount >0) 
						completedFrameIndex=(((rCIPRSTATUS>>26)&0x3)+4-2)%4;
					//Uart_Printf("FrameIndex:%d\n",completedFrameIndex);
				}
				else {
					//Uart_Printf("Preview Image Captured\n");
				} 		
			default:
				break;			
		} 	
		
		CamPreviewIntUnmask();
		camPviewCaptureCount++;
	}
}



/******************************************************************************
 *                                                                            *    
 *                   camera interface interrupts & controls                   *
 *                                                                            *     
 ******************************************************************************/


U32 Conv_YCbCr_Rgb(U8 y0, U8 y1, U8 cb0, U8 cr0)  // second solution... by junon
{
	// bit order is
	// YCbCr = [Cr0 Y1 Cb0 Y0], RGB=[R1,G1,B1,R0,G0,B0].
	
	int r0, g0, b0, r1, g1, b1;
	U32 rgb0, rgb1, rgb;
 
	#if 1 // 4 frames/s @192MHz, 12MHz ; 6 frames/s @450MHz, 12MHz
	r0 = YCbCrtoR(y0, cb0, cr0);
	g0 = YCbCrtoG(y0, cb0, cr0);
	b0 = YCbCrtoB(y0, cb0, cr0);
	r1 = YCbCrtoR(y1, cb0, cr0);
	g1 = YCbCrtoG(y1, cb0, cr0);
	b1 = YCbCrtoB(y1, cb0, cr0);
	#endif

	if (r0>255 ) r0 = 255;
	if (r0<0) r0 = 0;
	if (g0>255 ) g0 = 255;
	if (g0<0) g0 = 0;
	if (b0>255 ) b0 = 255;
	if (b0<0) b0 = 0;

	if (r1>255 ) r1 = 255;
	if (r1<0) r1 = 0;
	if (g1>255 ) g1 = 255;
	if (g1<0) g1 = 0;
	if (b1>255 ) b1 = 255;
	if (b1<0) b1 = 0;
	
	// 5:6:5 16bit format
	rgb0 = (((U16)r0>>3)<<11) | (((U16)g0>>2)<<5) | (((U16)b0>>3)<<0);	//RGB565.
	rgb1 = (((U16)r1>>3)<<11) | (((U16)g1>>2)<<5) | (((U16)b1>>3)<<0);	//RGB565.

	rgb = (rgb1<<16) | rgb0;

	return(rgb);
}


void Display_Cam_Image(U32 size_x, U32 size_y)
{
	U8 *buffer_y, *buffer_cb, *buffer_cr;
	U8 y0,y1,cb0,cr0;
	int r0,r1,g0,g1,b0,b1;
	U32 rgb_data0, rgb_data1; 
	U32 x, y;
	int temp;

	if (CAM_CODEC_4PP)
		temp = (((rCICOSTATUS>>26)&0x3)+4-2)%4; // current frame memory block
	else
		temp = 4;
	//Uart_Printf("Current Frame memory %d\n", temp);

	switch (temp) // current frame mem - 2
	{
	case 0:
		buffer_y = (U8 *)rCICOYSA1;
		buffer_cb = (U8 *)rCICOCBSA1;
		buffer_cr = (U8 *)rCICOCRSA1;
		break;
	case 1:
		buffer_y = (U8 *)rCICOYSA2;
		buffer_cb = (U8 *)rCICOCBSA2;
		buffer_cr = (U8 *)rCICOCRSA2;
		break;
	case 2:
		buffer_y = (U8 *)rCICOYSA3;
		buffer_cb = (U8 *)rCICOCBSA3;
		buffer_cr = (U8 *)rCICOCRSA3;
		break;
	case 3:
		buffer_y = (U8 *)rCICOYSA4;
		buffer_cb = (U8 *)rCICOCBSA4;
		buffer_cr = (U8 *)rCICOCRSA4;
		break;
	default :
		buffer_y = (U8 *)rCICOYSA1;
		buffer_cb = (U8 *)rCICOCBSA1;
		buffer_cr = (U8 *)rCICOCRSA1;
		break;
	}

	//Uart_Printf("End setting : Y-0x%x, Cb-0x%x, Cr-0x%x\n", buffer_y, buffer_cb, buffer_cr);	
#if 0
	// for checking converting time 
	rGPGCON = (rGPGCON&~(1<<23))|(1<<22); //EINT19 -> GPG11 output
	rGPGUP |= (1<<11);
	rGPGDAT &= ~(1<<11);
	Delay(90);
	rGPGDAT |=(1<<11);
	
	rgb_data0 = 0;
#endif

#if CAM_CODEC_OUTPUT==CAM_CCIR420
	for (y=0;y<size_y;y++) // YCbCr 4:2:0 format
	{
		for (x=0;x<size_x;x+=2)
		{		
			rgb_data0 = Conv_YCbCr_Rgb(*buffer_y++, *buffer_y++, *buffer_cb++, *buffer_cr++);
			frameBuffer16BitTft240320[y][x/2] = rgb_data0;

			if ( (x==(size_x-2)) && ((y%2)==0) ) // when x is last pixel & y is even number
			{
				buffer_cb -= size_x/2;
				buffer_cr -= size_x/2;
			} 	
		}
	}	
#else
	for (y=0;y<size_y;y++) // YCbCr 4:2:2 format
	{
		for (x=0;x<size_x;x+=2)
		{ 	
			rgb_data0 = Conv_YCbCr_Rgb(*buffer_y++, *buffer_y++, *buffer_cb++, *buffer_cr++);
			frameBuffer16BitTft240320[y][x/2] = rgb_data0;
		}
	} 
#endif

//	memcpy((unsigned char*)0x30100000,  frameBuffer16BitTft240320, 320*240*2); // QCIF=178*144*2
#if 0		
	rGPGDAT &= ~(1<<11);
	Delay(30);
	rGPGDAT |=(1<<11);
	rGPGCON = (rGPGCON&~(1<<22))|(1<<23); // GPG11 output -> EINT19
#endif
}

#if 0
void Display_Cam_Image(int offset_x, int offset_y, int size_x, int size_y)
{
	U8* CamFrameAddr, LcdFrameAddr;
	int i, temp;
	
	Lcd_MoveViewPort(offset_x, offset_y, USED_LCD_TYPE);	

	switch(camPviewCaptureCount%4)
	{
	case 2 : 
		temp = rCIPRCLRSA1;
		break;
	case 3 : 
		temp = rCIPRCLRSA2;
		break;
	case 0 : 
		temp = rCIPRCLRSA3;
		break;
	case 1 :
	default:
		temp = rCIPRCLRSA4;
		break;
	}

	*CamFrameAddr = temp;
	*LcdFrameAddr = LCDFRAMEBUFFER;
	for(i=0;i<size_y;i++)
	{
		memcpy(LcdFrameAddr, CamFrameAddr, size_x*2);
		*LcdFrameAddr += size_x*4; // added virtual screen
		*CamFrameAddr += size_x*2; 
	}
}
#endif

void Test_CamPreview(void)
{

	U8 flag;
	U32 i,j,k,value, *data;
	
	Uart_Printf("\n[ Camera Preview Test ]\n");

	//camera global variables
	camTestMode=CAM_TEST_MODE_PVIEW;
	camCodecCaptureCount=0;
	camPviewCaptureCount=0;
	camPviewStatus=CAM_STOPPED;
	camCodecStatus=CAM_STOPPED;
	flagCaptured_P=0;

	//Initialize LCD
#if CAM_PVIEW_OUTPUT==CAM_RGB24B
	Lcd_Start(MODE_TFT_24BIT_240320);
	Lcd_EnvidOnOff(0);
	// for 240x320 24bit setting
	rLCDCON5 &= ~1; // halfword swap disable -> Camera data is halfword swap type, 24bit
	rLCDSADDR3 &= ~(0x7ff<<11); // offset size 0
	rLCDSADDR2=M5D( (LCDFRAMEBUFFER+(LCD_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*4))>>1 );
	Lcd_EnvidOnOff(1);
	data = (U32 *)LCDFRAMEBUFFER;
	for (i=0;i<240*320;i++) // 24bpp test
	{
		if (i<240*80) *data++ = 0x000000ff; // blue
		else if ((i<240*160)&&(i>=240*80)) *data++ = 0x0000ff00; //green
		else if ((i<240*240)&&(i>=240*160)) *data++ = 0x00ff0000; //red
		else if (i>=240*240) *data++ = 0xff000000; // black
	}
#else // RGB16B
	Lcd_Start(MODE_TFT_16BIT_240320);
	Lcd_EnvidOnOff(0);
	// for 240x320 16bit haltword swap type setting
	rLCDCON5 |= 1; // halfword swap enable -> Camera data is halfword swap type, 16bit
	rLCDSADDR3 &= ~(0x7ff<<11); // offset size 0
	rLCDSADDR2=M5D( (LCDFRAMEBUFFER+(LCD_XSIZE_TFT_240320*LCD_YSIZE_TFT_240320*2))>>1 );
	Lcd_EnvidOnOff(1);
	data = (U32 *)LCDFRAMEBUFFER;
	for (i=0;i<240*160;i++) // 16bpp test
	{ 
		if (i<240*40) *data++ = 0x001f001f; // blue
		else if ((i<240*80)&&(i>=240*40)) *data++ = 0x07e007e0; //green
		else if ((i<240*120)&&(i>=240*80)) *data++ = 0xf800f800; //red
		else if (i>=240*120) *data++ = 0xf800001f; // blue & red
	}
#endif
	Uart_Printf("\nTFT 64K color mode test 1. Press any key!\n");
	Uart_Getch(); 	
 
 Uart_Printf(" preview sc control = %x\n", rCIPRSCCTRL);

	// Initialize Camera interface
	switch(USED_CAM_TYPE)
	{
	case CAM_S5X532 : // defualt for test : data-falling edge, ITU601, YCbCr
		CamInit(640, 480, 240, 320, 112, 20,  CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);
		break;
	case CAM_S5X3A1 : // defualt for test : data-falling edge, YCbCr
		CamInit(640, 480, 240, 320, 120, 100,	CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);
		rCISRCFMT = rCISRCFMT & ~(1<<31); // ITU656
//		rCIGCTRL &= ~(1<<26); // inverse PCLK, test pattern
		break;
	default : 	
		CamInit(640, 480, 240, 320, 0, 0,  CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);
		break;
	}
	Uart_Printf(" preview sc control = %x\n", rCIPRSCCTRL);

	// Start Capture	
	rSUBSRCPND |= BIT_SUB_CAM_C|BIT_SUB_CAM_P;
	ClearPending(BIT_CAM);
	pISR_CAM = (U32)CamIsr;    
	CamPreviewIntUnmask();
	CamCaptureStart(CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT);
	Uart_Printf("Press Enter key to exit!\n");
	while (1)
	{
		if (flagCaptured_P)
		{
			flagCaptured_P = 0;
//			Uart_Printf("Enter Cam A port, count = %d\n",camCodecCaptureCount);
		}
		if (Uart_GetKey()== '\r') break;			
	}
    
	CamCaptureStop();

	Uart_Printf("\nWait until the current frame capture is completed.\n");
	while(camPviewStatus!=CAM_STOPPED)
		if (Uart_GetKey()== '\r') break;			

	Uart_Printf(" CIS format = %x\n", rCISRCFMT);
	Uart_Printf(" image cap = %x\n", rCIIMGCPT);
	Uart_Printf(" preview sc control = %x\n", rCIPRSCCTRL);
	Uart_Printf(" preview control = %x\n", rCIPRCTRL);
	Uart_Printf(" codec sc control = %x\n", rCICOSCCTRL);
	Uart_Printf(" codec control = %x\n", rCICOCTRL);
	Uart_Printf(" pr addr1 = %x\n", rCIPRCLRSA1);
	Uart_Printf(" pr addr2 = %x\n", rCIPRCLRSA2);


	Uart_Printf("camCodecCaptureCount=%d\n",camCodecCaptureCount);
	Uart_Printf("camPviewCaptureCount=%d\n",camPviewCaptureCount);
//	CamPreviewIntMask();
}



void Test_CamCodec(void)
{

	U8 flag, fBypass='1';
	U32 i,j,k,value, *data;
	
	Uart_Printf("\n[ Camera Codec Test ]\n");

	//camera global variables
	camTestMode=CAM_TEST_MODE_CODEC;
	camCodecCaptureCount=0;
	camPviewCaptureCount=0;
	camPviewStatus=CAM_STOPPED;
	camCodecStatus=CAM_STOPPED;
	flagCaptured_C=0;

	//Initialize LCD
	Lcd_Start(MODE_TFT_16BIT_240320);
	Glib_FilledRectangle(0,0,239,79,0x001f); // B
	Glib_FilledRectangle(0,80,239,159,0x07e0); // G
	Glib_FilledRectangle(0,160,239,239,0xf800); // R
	Glib_FilledRectangle(0,240,239,319,0xffff); 	 
	Uart_Printf("\nTFT 64K color mode test 1. Press any key!\n");
	Uart_Getch(); 	

	// Initialize Camera interface
	switch(USED_CAM_TYPE)
	{
	case CAM_S5X532 : // defualt for test : data-falling edge, ITU601, YCbCr
		CamInit(240, 320, 240, 320, 112, 20,  CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);
		break;
	case CAM_S5X3A1 : // defualt for test : data-falling edge, ITU601, YCbCr
		CamInit(240, 320, 240, 320, 0, 0, CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);
		rCISRCFMT &= ~(1<<31); // ITU656
		break;
	default : 	
		CamInit(240, 320, 240, 320, 0, 0,  CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);	
		break;
	}

	// Start Capture	
	rSUBSRCPND |= BIT_SUB_CAM_C|BIT_SUB_CAM_P;
	ClearPending(BIT_CAM);
	pISR_CAM = (U32)CamIsr;    
	CamCodecIntUnmask();

	Uart_Printf("Select Code mode : 1. Scaler mode(D)   2. Bypass mode\n");
	fBypass = Uart_Getch();
	if (fBypass=='2'){
		CamInit(CAM_SRC_HSIZE, CAM_SRC_VSIZE, 240, 320, 0, 0, CAM_FRAMEBUFFER_C, CAM_FRAMEBUFFER_P);
		CamCaptureStart(CAM_CAMIF_GLOBAL_CAPTURE_ENABLE_BIT); //bypass
	}
	else
		CamCaptureStart(CAM_CODEC_SCALER_CAPTURE_ENABLE_BIT); //scaler

	// for test simultanious
//	rCIIMGCPT |= CAM_PVIEW_SCALER_CAPTURE_ENABLE_BIT;
//	rCIPRSCCTRL |= CAM_PVIEW_SACLER_START_BIT;

	
	Uart_Printf("Press Enter key to exit!\n");
	while (1)
	{
		if (flagCaptured_C)
		{
			flagCaptured_C = 0;
			if (fBypass=='2')
				Display_Cam_Image(CAM_SRC_HSIZE, CAM_SRC_VSIZE);
			else 
				Display_Cam_Image(240, 320);
//			Uart_Printf("Enter Cam B port, count = %d\n",camPviewCaptureCount);
		}
//		if (camCodecCaptureCount>=1) 
//		{ 
//			Uart_Printf("cnt = %d\n", camCodecCaptureCount); 
//		    break;			
//		}
		if (Uart_GetKey()== '\r') break;			
	}
    
	CamCaptureStop();

	Uart_Printf("\nWait until the current frame capture is completed.\n");
	while(camCodecStatus!=CAM_STOPPED)
		if (Uart_GetKey()== '\r') break;			
		
	Uart_Printf(" CIS format = %x\n", rCISRCFMT);
	Uart_Printf(" image cap = %x\n", rCIIMGCPT);
	Uart_Printf(" preview sc control = %x\n", rCIPRSCCTRL);
	Uart_Printf(" preview control = %x\n", rCIPRCTRL);
	Uart_Printf(" codec sc control = %x\n", rCICOSCCTRL);
	Uart_Printf(" codec control = %x\n", rCICOCTRL);
	Uart_Printf(" codec status = %x\n", rCICOSTATUS);
	
	Uart_Printf("camCodecCaptureCount=%d\n",camCodecCaptureCount);
	Uart_Printf("camPviewCaptureCount=%d\n",camPviewCaptureCount);
//	CamCodecIntMask();
}


void Test_YCbCr_to_RGB(void)
{
	U8 *buffer_y, *buffer_cb, *buffer_cr;
	int size_x, size_y, R, G, B, rgb_data; 
	int x, y;	
	int pos_x = 0;
	int pos_y = 0;
	U8 cSelType = 0;
	U8 *cBuffer;

	Lcd_Start(MODE_TFT_16BIT_240320);
	
	size_x = PQVGA_XSIZE;
	size_y = PQVGA_YSIZE;

	Uart_Printf("Select   1. 420[D] PQVGA    2. 422 PQVGA    3. 420 CIF  : \n");
	cSelType = Uart_Getch();
	if (cSelType == '\r') cSelType = '1';

	switch (cSelType)
	{
	case '1' : 
		cBuffer = (U8 *)c420jpeg;
		break;		
	case '2' : 
		cBuffer = (U8 *)c422jpeg;
		break;
	case '3' : 
		cBuffer = (U8 *)foreman_cif_420;
		size_x = CIF_XSIZE;
		size_y = CIF_YSIZE;
		break;
	}

	buffer_y = (U8 *)(cBuffer);
	buffer_cb = (U8 *)(cBuffer + size_x*size_y); // add y size
	buffer_cr = (U8 *)(buffer_cb + size_x*size_y/4); // add y,cb size
	if (cSelType == '2')
		buffer_cr = (U8 *)(buffer_cb + size_x*size_y/2); // add y,cb size
		

	Uart_Printf("End setting : Y-0x%x, Cb-0x%x, Cr-0x%x\n", buffer_y, buffer_cb, buffer_cr);	
	Uart_Printf("Address : Y-0x%x, foreman-0x%x, fa-0x%x\n", *buffer_y, cBuffer, *cBuffer);
	
	Glib_FilledRectangle(0,0,239,159,0xaaaa); 	 
	Glib_FilledRectangle(0,160,239,320,0xf800); 	 
	Uart_Printf("\nTFT 64K color mode test 1. Press any key!\n");
	Uart_Getch(); 	

	for (y=0;y<size_y;y++) // YCbCr 4:2:0 format
		for (x=0;x<size_x;x++)
		{	
			R = YCbCrtoR(*buffer_y, *buffer_cb, *buffer_cr);
			G = YCbCrtoG(*buffer_y, *buffer_cb, *buffer_cr);
			B = YCbCrtoB(*buffer_y, *buffer_cb, *buffer_cr);

			if (R>255 ) R = 255;
			if (G>255 ) G = 255;
			if (B>255 ) B = 255;
			if (R<0 ) R = 0;
			if (G<0 ) G = 0;
			if (B<0 ) B = 0;

			// 5:6:5 16bit format
			rgb_data =(R&0xf8)<<8;  // R 5bits
			rgb_data|=(G&0xfc)<<3; // G 6bits
			rgb_data|=(B&0xf8)>>3; // B 5bits
			PutPixel(pos_x+x, pos_y+y, rgb_data);

			// next usable bits..
			buffer_y++;
			if (x%2) // when x is odd number
			{
				buffer_cb++;
				buffer_cr++;
			}
			if (cSelType != '2')
				if ( (x==(size_x-1)) && ((y%2)==0) ) // when x is last pixel & y is even number
				{
					buffer_cb -= size_x/2;
					buffer_cr -= size_x/2;
				}		
		}

    Uart_Printf("Virtual Screen Test(TFT 64K color). Press any key[ijkm\\r]!\n");
    MoveViewPort(MODE_TFT_16BIT_240320); // user can adjust screen..
    
    Lcd_MoveViewPort(0,0,MODE_TFT_16BIT_240320); // return 0,0
    Glib_ClearScr(0, MODE_TFT_16BIT_240320);
    Lcd_EnvidOnOff(0);
    Lcd_PowerEnable(0, 0);
    Lcd_Port_Return();
    
}

⌨️ 快捷键说明

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