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

📄 videoinlcdout.c

📁 VideoInLcdOut for BF561
💻 C
📖 第 1 页 / 共 2 页
字号:
/********* MACROS ************************************************************************/
#define   NTSC_MODE     	// Video frame is of NTSC format
//#define READ_REG_VALUE	// read/print register value enable/disable
#define	  NEC_LCD	
/*********************************************************************

Include files

*********************************************************************/
#include <drivers/adi_dev.h>			// Device manager includes
#include <drivers/decoder/adi_adv7183.h>		// AD7183 device driver includes
#if defined NEC_LCD
#include <drivers/lcd/nec/adi_nl6448BC33_54.h>
#else
#include <drivers/lcd/sharp/adi_lq10d368.h>
#endif
#include <drivers/twi/adi_twi.h>			// TWI device driver includes
//#include <drivers/ppi/adi_ppi.h>			// PPI device driver includes
#include <SDK-ezkitutilities.h>
#include <adi_ssl_Init.h>

#include "stdio.h"
#include "math.h"

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

Prototypes

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


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

Static data

*****************************************************************************/
#define NTSC	0
#define PAL 	1

// NTSC or PAL Video input
#define ACTIVE_FIELD_DATA_LEN		720	// Active field data length per line for PAL video format

#if defined NTSC_MODE	// NTSC mode
#define ACTIVE_FIELD_LINES	507		// Number of lines per active field frame for NTSC format   
#else // PAL mode
#define ACTIVE_FIELD_LINES	576		// Number of lines per active field frame for PAL format   
#endif

#define ACTIVE_FIELD_FRAME_SIZE	(ACTIVE_FIELD_DATA_LEN * ACTIVE_FIELD_LINES)
#define VIDEOHORZLINES		ACTIVE_FIELD_DATA_LEN/2
#define CROP_HORIZONTAL_LINES	20

#if defined NTSC_MODE	// NTSC mode
#define CROP_VIDEO_LINES	13
#define OFFSET_TO_ODD_FRAME	((ACTIVE_FIELD_LINES+1)/2)
#define IPOFFSET_EVEN	(CROP_VIDEO_LINES*VIDEOHORZLINES)+CROP_HORIZONTAL_LINES// VIDEO buffer offset for even frame
#define IPOFFSET_ODD	IPOFFSET_EVEN + (OFFSET_TO_ODD_FRAME*VIDEOHORZLINES)// VIDEO buffer offset for odd frame
#else
#define CROP_VIDEO_LINES	24
#define OFFSET_TO_ODD_FRAME	288
#define IPOFFSET_EVEN	(CROP_VIDEO_LINES*VIDEOHORZLINES)+CROP_HORIZONTAL_LINES// VIDEO buffer offset for even frame
#define IPOFFSET_ODD	IPOFFSET_EVEN + (OFFSET_TO_ODD_FRAME*VIDEOHORZLINES)// VIDEO buffer offset for odd frame
#endif

// VGA LCD output
#define VGA_WIDTH		640
#define VGA_PADLEFT		0
#define VGA_PADRIGHT		0

#define VGA_HEIGHT		480
#define VGA_PADTOP		33
#define VGA_PADBOTTOM		12

#define VGA_FRAME_WIDTH		(VGA_WIDTH+VGA_PADLEFT+VGA_PADRIGHT) // 640
#define VGA_FRAME_HEIGHT	(VGA_HEIGHT+VGA_PADTOP+VGA_PADBOTTOM) // 525
#define VGA_FRAME_SIZE		(VGA_FRAME_WIDTH*VGA_FRAME_HEIGHT) // 640*525

#define LCDHORZLINES	VGA_FRAME_WIDTH/2
#define OPOFFSET_EVEN	(VGA_PADTOP*LCDHORZLINES)// LCD buffer offset for even frame
#define OPOFFSET_ODD	((VGA_PADTOP+1)*LCDHORZLINES)//LCD buffer offset for odd frame





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

memory for buffers and data

*********************************************************************/
// Define the DMA buffers for each frame.
// Because of SDRAM performance, each frame must be in a different bank.

section("vd0_sdram") volatile u16 sFrame0[ACTIVE_FIELD_FRAME_SIZE];
section("vd1_sdram") volatile u16 sFrame1[ACTIVE_FIELD_FRAME_SIZE];


section("vd2_sdram") volatile u16 sFrame2[VGA_FRAME_SIZE];

// Storage for YUV to RGB565 conversion
section("L1_data_a") static unsigned long InData[512],OutData[512];

// 2 input buffers used by AD7183
ADI_DEV_2D_BUFFER In1_Buffer2D, In2_Buffer2D;
 
// 2 output buffers used by LCD
ADI_DEV_2D_BUFFER Out1_Buffer2D, Out2_Buffer2D; 
/*********************************************************************

memory for initialization of system services and device manager

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

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

handles to device drivers

*********************************************************************/
ADI_DEV_DEVICE_HANDLE AD7183DriverHandle;// handle to the ad7183 driver
ADI_DEV_DEVICE_HANDLE LcdDriverHandle;// handle to the LCD driver

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

static function prototypes

*********************************************************************/
// exception handlers
static ADI_INT_HANDLER(ExceptionHandler);
static ADI_INT_HANDLER(HWErrorHandler);
static void InitSystemServices(void); // system services initialization
static void CallbackFunction( void *AppHandle, u32 Event,void *pArg);// device driver callback function
static void InitADV7183_Start(void);
static void InitLcd_Start(void);
void convertFrame(u32 num);   
static void convertyuvrgb(unsigned short OutSize, unsigned long *Output, unsigned short InSize, unsigned long *Input);
static void Set7183RangeReg(void);// Set AD7183 Extended Output Control register
static void Read7183StatusReg(void); // Read AD7183 Status register

volatile bool Frame0Flag;
volatile bool Frame1Flag;

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

	Function:	main
	Description:	Read in ITU656 NTSC or PAL video data into SDRAM input buffer.
			Convert YUV(4:2:2) to RGB565 format and store into SDRAM output buffer.
			Send the output buffer to the VGA LCD.
         
*********************************************************************/

void main(void)
{
	unsigned int i,Result;									// index
	u32	ResponseCount;								// response count
	
	
	// initialize the system services
	InitSystemServices();
	
	// enable LEDs and buttons
    	for (i = EZ_FIRST_LED; i < EZ_NUM_LEDS; i++){
        ezInitLED(i);
    	}
    	
    ezInitButton(EZ_LAST_BUTTON);
	
	// turn off LED's	
	ezTurnOffAllLEDs();

	
	                      
	//reset the processed buffer flag
	Frame0Flag = false;
	Frame1Flag = false;                      

	// initialize the decoder and start the input data flow
	InitADV7183_Start();

	// initialize the LCD and start the output data flow
	InitLcd_Start();
	
	
	// loop forever until the last push button is depressed
    	while (ezIsButtonPushed(EZ_LAST_BUTTON) == FALSE){
    	// convert processed buffer
    		if (Frame0Flag){
    		Frame0Flag = false;
    		convertFrame(0); // convert even field
    		}
    	
    		if (Frame1Flag){
    		Frame1Flag = false;
    		convertFrame(1); // convert odd field
    		}
 	
    	}

	// close the device
	ezErrorCheck(adi_dev_Close(AD7183DriverHandle));

	// close the device
	ezErrorCheck(adi_dev_Close(LcdDriverHandle));
	
	/* terminate the device */
	adi_ssl_Terminate();
	

}




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

	Function:	CallbackFunction

	Description:	Each type of callback event has it's own unique ID
			so we can use a single callback function for all
			callback events.  The switch statement tells us
			which event has occurred.
			In the example, we'll get a callback when the PPI 
			has completed processing of the input buffer.
			Note that in the device driver model, in order to 
			generate a callback for buffer completion, the 
			CallbackParameter of the buffer must be set to a non-NULL 
			value.
*********************************************************************/

static void CallbackFunction(void *AppHandle,u32  Event,void *pArg)
{
	ADI_DEV_2D_BUFFER *p2DBuffer;	// pointer to the buffer that was processed
		
    	p2DBuffer = (ADI_DEV_2D_BUFFER *)pArg;
	
	switch (Event)
	{
		// CASE (buffer processed)
        	case ADI_DEV_EVENT_BUFFER_PROCESSED:
   	    		
    	    	if(p2DBuffer == &In1_Buffer2D){
    	    	 Frame0Flag = true;
    	    	}
    	    	else if(p2DBuffer == &In2_Buffer2D){
    	    	 Frame1Flag = true;
    	    	}
      	 
           	break;
           
                  // CASE (an error)
		case ADI_DEV_EVENT_DMA_ERROR_INTERRUPT:
			// turn on all LEDs and wait for help
			ezTurnOnAllLEDs();
			while (1) ;
			

	}

	// return
}

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

	Function:		InitSystemServices

	Description:	Initializes the necessary system services.  

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

void InitSystemServices(void) {
    
    // initialize the ezKit power,EBIU,DMA....
	adi_ssl_Init();	
		
	// enable and configure async memory
	ezInit(1);
}

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

	Function: InitADV7183_Start
	
	Description: Open the ADV7183 device, configure the device, 
		     setup 2D output buffer and enable the data flow

******************************************************************************/
static void InitADV7183_Start(void)
{    
	
    	// this example uses the AV-Extender card, so disable the onboard video decoder
	ezDisableVideoDecoder();
	
	// Pseudo TWI will be used to access ADV7183 registers.
	// BF561 Ports (PF0=SCL,PF1=SDA) & Timer(Timer 3) used for Pseudo TWI
	adi_twi_pseudo_port TWIPseudo= {ADI_FLAG_PF0,ADI_FLAG_PF1,ADI_TMR_GP_TIMER_3,(ADI_INT_PERIPHERAL_ID)NULL};
	ADI_DEV_CMD_VALUE_PAIR PseudoTWIConfig[]={
	{ADI_TWI_CMD_SET_PSEUDO,(void *)(&TWIPseudo)},
	{ADI_DEV_CMD_SET_DATAFLOW_METHOD,(void *)ADI_DEV_MODE_SEQ_CHAINED},
	{ADI_DEV_CMD_SET_DATAFLOW,(void *)TRUE},
	{ADI_DEV_CMD_END,NULL}
	};
	
	
	// open the ad7183 driver
	ezErrorCheck(adi_dev_Open(adi_dev_ManagerHandle,		// DevMgr handle
				&ADIADV7183EntryPoint,		// pdd entry point
				0,				// device instance
	            (void *)0x7183,            // client handle (0x7183 will be given to the AD7183 decoder driver)
				&AD7183DriverHandle,			// DevMgr handle for this device
				ADI_DEV_DIRECTION_INBOUND,// 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
				
	/********* open AD7183-PPI ****************************************/		
	// open the AD7183-PPI device 0 (see Schematic)
	ezErrorCheck(adi_dev_Control(AD7183DriverHandle, ADI_AD7183_CMD_OPEN_PPI, (void *)0));
			
	// command PPI to work in NTSC or PAL mode

⌨️ 快捷键说明

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