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

📄 videoinlcdout.c

📁 VideoInLcdOut for BF561
💻 C
📖 第 1 页 / 共 2 页
字号:
#if defined NTSC_MODE	// NTSC mode
		ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_SET_VIDEO_FORMAT, (void *)NTSC));
#else
		ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_SET_VIDEO_FORMAT, (void *)PAL));
#endif		
				
	/******************* AD7183 Inbound Buffers  ***********************************************/	
	// populate the buffers that we'll use for the PPI input
	In1_Buffer2D.Data = (void*)sFrame0;
	In1_Buffer2D.ElementWidth = 4;
	In1_Buffer2D.XCount = ACTIVE_FIELD_DATA_LEN/2;
	In1_Buffer2D.YCount = ACTIVE_FIELD_LINES;
	In1_Buffer2D.XModify = 4;
	In1_Buffer2D.YModify = 4;
	In1_Buffer2D.CallbackParameter = &In1_Buffer2D;
	In1_Buffer2D.pNext = &In2_Buffer2D;

	
	In2_Buffer2D.Data = (void*)sFrame1;
	In2_Buffer2D.ElementWidth = 4;
	In2_Buffer2D.XCount = ACTIVE_FIELD_DATA_LEN/2;
	In2_Buffer2D.YCount = ACTIVE_FIELD_LINES;
	In2_Buffer2D.XModify = 4;
	In2_Buffer2D.YModify = 4;
	In2_Buffer2D.CallbackParameter = &In2_Buffer2D;
	In2_Buffer2D.pNext = NULL;

	// configure the ad7183 dataflow method
	ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_CHAINED_LOOPBACK));
	// give the PPI driver the buffer to process
	ezErrorCheck(adi_dev_Read(AD7183DriverHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)&In1_Buffer2D));

	/********* AD7183 registers access ****************************************/		
	// Send Pseudo TWI Configuration table to AD7183 if register configuratian is needed
	ezErrorCheck(adi_dev_Control(AD7183DriverHandle,ADI_AD7183_CMD_SET_TWI_CONFIG_TABLE,(void*)PseudoTWIConfig)); 

	//set Extended Output Control register to ITU656 for 16<Y<235 and 16<C<240
	Set7183RangeReg();
	
	 // configure the PPI driver for receiving active field only
	ezErrorCheck( adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_SET_ACTIVE_VIDEO, (void*)TRUE));
	
	// start capturing video data
	ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE));

#if defined(READ_REG_VALUE)
	// read AD7183 status register
	Read7183StatusReg();
#endif	

}	


/******************************************************************************

	Function: InitLcd_Start
	
	Description: Open the NEC LCD device, configure the device, 
		     setup 2D output buffer and enable the data flow

******************************************************************************/
static void InitLcd_Start(void)
{	
	// open the nl6448BC3354 driver
	ezErrorCheck(adi_dev_Open(adi_dev_ManagerHandle,		// DevMgr handle
#if defined NEC_LCD
				&ADI_NL6448BC3354_EntryPoint,// pdd entry point for nec lcd driver
#else
				&ADI_LQ10D368_EntryPoint,// pdd entry point for sharp lcd driver
#endif				
				
				0,				// device instance
				NULL,				// client handle callback identifier
				&LcdDriverHandle,			// DevMgr handle for this device
				ADI_DEV_DIRECTION_OUTBOUND,// data direction for this device
				adi_dma_ManagerHandle,			// handle to DmaMgr for this device
				NULL,				// handle to deferred callback service
				CallbackFunction));		// client's callback function
	
	// Select PPI device number and open it for LCD driver.
#if defined NEC_LCD
	ezErrorCheck(adi_dev_Control(LcdDriverHandle, ADI_NL6448BC3354_CMD_OPEN_PPI, (void*)1));
#else
	ezErrorCheck(adi_dev_Control(LcdDriverHandle, ADI_LQ10D368_CMD_OPEN_PPI, (void*)1));
#endif
	// populate LCD outbound buffers
	Out1_Buffer2D.Data = (void*)sFrame2;// address of the data storage
	Out1_Buffer2D.ElementWidth = 4; //4 bytes wide
	Out1_Buffer2D.XCount = (VGA_FRAME_WIDTH/2);
	Out1_Buffer2D.XModify = 4;
	Out1_Buffer2D.YCount = VGA_FRAME_HEIGHT;
	Out1_Buffer2D.YModify = 4;
	Out1_Buffer2D.CallbackParameter = NULL;// no callback
	Out1_Buffer2D.pNext = NULL; // terminate the chain of buffers

	
	// configure the LCD dataflow method
	ezErrorCheck(adi_dev_Control(LcdDriverHandle, ADI_DEV_CMD_SET_DATAFLOW_METHOD, (void *)ADI_DEV_MODE_CHAINED_LOOPBACK));
    	ezErrorCheck(adi_dev_Write(LcdDriverHandle, ADI_DEV_2D, (ADI_DEV_BUFFER *)&Out1_Buffer2D));
	        	 	
	// start outputting LCD video data
	ezErrorCheck ( adi_dev_Control(LcdDriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*)TRUE));


}





/******************************************************************************

	Function: convertFrame
	
	Description: When a input buffer is filled by the ADV7183 driver,
		     a function is called to convert each line of the buffer
		     into RGB format.	
******************************************************************************/
void convertFrame(u32 frameNum){
	u32 m;	
	u32 *ipF, *opF;

	if(frameNum == 0){ // process video frame 0
	    
	   ipF =((u32 *)sFrame0)+ IPOFFSET_EVEN; // input point to even section of sFrame0
	   opF=(u32 *)sFrame2+OPOFFSET_EVEN;// output point to even section of sFrame2

	}
	else{// process video frame 1
	   ipF =((u32 *)sFrame1)+ IPOFFSET_ODD; // input point to even section of sFrame0
	   opF=(u32 *)sFrame2+OPOFFSET_ODD;// output point to even section of sFrame2

	}
		
	for(m=0;m<VGA_HEIGHT/2;m++,opF+=LCDHORZLINES*2,ipF+=VIDEOHORZLINES){ //output to every second line.

		convertyuvrgb(LCDHORZLINES,opF,VIDEOHORZLINES,ipF);	
	
	}

}

/******************************************************************************

Exception interrupt handlers

Note: should never get an exception or hardware error...

******************************************************************************/

static ADI_INT_HANDLER(ExceptionHandler)
{
	// turn on all LEDs and wait for help
	ezTurnOnAllLEDs();
	while (1) ;
}


static ADI_INT_HANDLER(HWErrorHandler)
{
	// turn on all LEDs and wait for help
	ezTurnOnAllLEDs();
	while (1) ;
}



/******************************************************************************

	Function: convert_yuv_rgb
	
	Description: This function takes an input buffer, output buffer and
		overlay buffer and combines the input and overlay and writes back to
		the output.

		Cb=*(pYUV+n);
		Y0=*(pYUV+n+1);
		Cr=*(pYUV+n+2);
		Y1=*(pYUV+n+3); 
				
		C = Y - 16
		D = Cb - 128
		E = Cr - 128

		R = clip((298*C + 409*E         ) >> 8)
		G = clip((298*C - 100*D - 208*E ) >> 8)
		B = clip((298*C + 516*D         ) >> 8)



******************************************************************************/

static void convertyuvrgb(
	unsigned short OutSize, unsigned long *Output,
 	unsigned short InSize, unsigned long *Input)
{
 	unsigned short i,j;
 
 	long r,g,b,r1,g1,b1,cb,cr,y0,y1; 
	u8 *yuv;
	
 	for (i=0;i<OutSize;i++) 
  		InData[i]=*Input++;
 
	for (i=0,j=0;i<OutSize;i++,j++)
  	{   

    	
 	    yuv = (u8*)(&InData[j]);
  	    y1 = (*(yuv+3)*298)-16;
  	    cr = *(yuv+2)-128;
   	    y0 = (*(yuv+1)*298)-16;
  	    cb = *yuv-128;
  	    
		r = (409*cr);
  	    g = (100*cb + 208*cr);
  	    b = (516*cb);

		r1=y0+r;
		g1=y0-g;
		b1=y0+b;
		
  	    if(r1>0xFFFF)  r1 = 255; 
  	    else if(r1<0)  r1 = 0;   	    
    	else r1>>=8;
    
    	if(g1>0xFFFF)  g1 = 255; 
    	else if(g1<0)  g1 = 0; 
    	else g1>>=8;
    
    	if(b1>0xFFFF)  b1 = 255; 
    	else if(b1<0)  b1 = 0; 
    	else b1>>=8;
        
    	r=y1+r;
		g=y1-g;
		b=y1+b;
    	
    	if(r>0xFFFF)  r = 255; 
    	else if(r<0)  r = 0; 
    	else r>>=8; 
    
    	if(g>0xFFFF)  g = 255; 
    	else if(g<0)  g = 0; 
    	else g>>=8;
    
    	if(b>0xFFFF)  b = 255; 
    	else if(b<0)  b = 0; 
    	else b>>=8;    		    
  	      	    
    	OutData[j]=
    		((b<<24) & 0xF8000000)|
    		((g<<19) & 0x07E00000)|
    		((r<<13) & 0x001F0000)|
    		((b1<<8) & 0x0000F800)|
    		((g1<<3) & 0x000007E0)|
    		((r1>>3) & 0x0000001F);
	}

 	for (i=0;i<OutSize;i++) *Output++=OutData[i];
}



/**********************************************************************
* Example how to read ADV7183 status registers 
**********************************************************************/
static void Read7183StatusReg(void)	
{
    	u32 Result = 0, i;

    
    ADI_DEV_ACCESS_REGISTER Regs[] = 
	{{ ADV7183_STATUS1_RO, 	0 },		// Register address to access, corresponding register data
         { ADV7183_IDENT_RO, 	0 },
         { ADV7183_STATUS2_RO, 	0 },
         { ADV7183_STATUS3_RO, 	0 },
         { ADI_DEV_REGEND,	0 }};	// Register access delimiter (indicates end of register access)

//To read list of registers in DevRegs
    Result =  adi_dev_Control(AD7183DriverHandle, ADI_DEV_CMD_REGISTER_TABLE_READ, (void *)&Regs);    
    if (Result != 0) printf("CMD_REGISTER_TABLE_READ failed(error:%x)\n",Result);
    else {
    	// print the values	
		printf("AD7183: STATUS1 IDENT STATUS2 STATUS3\n ");
		for (i=0; i<4; i++){
		printf("0x%02X ",Regs[i].Data);
		}
		printf("\n");

    }

}

/**********************************************************************
* Example how to write ADV7183 status registers 
* set field ADV7183_RANGE of register ADV7183_EXTENDED_OUTPUT_CTR to 0
**********************************************************************/
static void Set7183RangeReg(void)	
{
    	u32 Result;

    	ADI_DEV_ACCESS_REGISTER_FIELD RegField	
    	= { ADV7183_EXTENDED_OUTPUT_CTR, ADV7183_RANGE, 0};	// Register address to access, Register field to access, corresponding register field data


// to configure Reg1Field1
	Result = adi_dev_Control(AD7183DriverHandle, ADI_DEV_CMD_REGISTER_FIELD_WRITE, (void *) &RegField);
    if (Result != 0) printf("CMD_REGISTER_FIELD_WRITE failed(error:%x)\n",Result);

}






⌨️ 快捷键说明

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