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

📄 lcd.c

📁 ADSP-BF537Display部分的代码
💻 C
字号:
/*=============================================================================
=
= Name:     QVGA Display and Timer Verification and Example Code
=
===============================================================================
=
= (C) Copyright 2006 - Analog Devices, Inc.  All rights reserved.
=
= File Name :   lcd.c
=
= Date      :   12/21/06
=
= Target    :   ADSP-BF537
=
= Version   :   1.0
=
= Purpose   :   Test the display with a bitmap
=
=
=
==============================================================================*/

#undef  BF537_EZKIT_PPI_DEBUG
#define BF537_EZKIT_PPI_PICTURE

#ifdef BF537_EZKIT_PPI_PICTURE
#define BMP_Header_Length	54				// 54 Byte header
#endif /* BF537_EZKIT_PPI_PICTURE */

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



	File:			LCD channel



	Description:	Controls the interface to the LCD of the BF537_EZKIT board



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


#ifdef BF537_EZKIT_PPI_PICTURE
#include <stdio.h>
#endif /* BF537_EZKIT_PPI_PICTURE */
#include <drivers/adi_dev.h>
#include <drivers/ppi/adi_ppi.h>
#include "timers.h"
#include "debug.h"

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------

// BF537 EZ-Kit LCD Flags
#define BF537_EZKIT_LCD_FLAG_MOD		ADI_FLAG_PF10
#define BF537_EZKIT_LCD_FLAG_UD			ADI_FLAG_PF13
#define BF537_EZKIT_LCD_FLAG_LBR		ADI_FLAG_PF14

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------

// PPI Driver
ADI_DEV_DEVICE_HANDLE PPIDriverHandle;
static ADI_DEV_2D_BUFFER PictureDMADescriptor;

 
#ifdef BF537_EZKIT_PPI_PICTURE
char Bitmap[320*240*3+BMP_Header_Length];
#endif /* BF537_EZKIT_PPI_PICTURE */
int Frame[240*(320+START_LINES+U_LINES)];

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------

void PPICallback (void *appHandle, unsigned long  event, void *pArg)
{
	// watch for errors
	if (event != ADI_DEV_EVENT_BUFFER_PROCESSED)
		BF537_EZKIT_Throw ("PPI event error %x\n", event);
}

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------

void OpenLCD (ADI_DEV_MANAGER_HANDLE DeviceManagerHandle, 
			  ADI_DMA_MANAGER_HANDLE DMAManagerHandle, 
			  ADI_DCB_HANDLE DeferredCallbackManagerHandle)
{
	int data;
	int ret;

	//----------------------------------------------------------

	// Turn on the LCD
	ret = adi_flag_Open (BF537_EZKIT_LCD_FLAG_MOD);
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag open BF537_EZKIT_LCD_FLAG_MOD\n");
	ret = adi_flag_SetDirection (BF537_EZKIT_LCD_FLAG_MOD, ADI_FLAG_DIRECTION_OUTPUT); 
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag SetDirection BF537_EZKIT_LCD_FLAG_MOD\n");
	ret = adi_flag_Set (BF537_EZKIT_LCD_FLAG_MOD); 
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag Setting BF537_EZKIT_LCD_FLAG_MOD\n");


	ret = adi_flag_Open (BF537_EZKIT_LCD_FLAG_UD);
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag open BF537_EZKIT_LCD_FLAG_UD\n");
	ret = adi_flag_SetDirection (BF537_EZKIT_LCD_FLAG_UD, ADI_FLAG_DIRECTION_OUTPUT); 
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag SetDirection BF537_EZKIT_LCD_FLAG_UD\n");
	ret = adi_flag_Set (BF537_EZKIT_LCD_FLAG_UD); 
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag Setting BF537_EZKIT_LCD_FLAG_UD\n");
		
	ret = adi_flag_Open (BF537_EZKIT_LCD_FLAG_LBR);
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag open BF537_EZKIT_LCD_FLAG_LBR\n");
	ret = adi_flag_SetDirection (BF537_EZKIT_LCD_FLAG_LBR, ADI_FLAG_DIRECTION_OUTPUT); 
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag SetDirection BF537_EZKIT_LCD_FLAG_LBR\n");
	ret = adi_flag_Set (BF537_EZKIT_LCD_FLAG_LBR); 
	if (ret != ADI_FLAG_RESULT_SUCCESS)
		BF537_EZKIT_Throw ("Error Flag Setting BF537_EZKIT_LCD_FLAG_LBR\n");
	
	//----------------------------------------------------------

#ifdef BF537_EZKIT_PPI_PICTURE
	FILE* fpBitmap;
	char* pBitmap;
	short* debug_buffer = (short*) Frame;
	char blue, green, red;
	short temp_pixel;
	int i, j;

	// Open Bitmap file. Note: Only 240x320 files accepted	
	fpBitmap = fopen ("..\\picture.bmp", "rb");
	if (fpBitmap == NULL)
		BF537_EZKIT_Throw ("Error opening bitmap file\nMake sure that c:\\temp\\picture.bmp exists\n");
    ret = fread (Bitmap, 1, 320*240*3+BMP_Header_Length, fpBitmap);
	if (ret == 0)
		BF537_EZKIT_Throw ("Error reading bitmap file\n");
	
	//Create_Data (Frame, Image_BMP);
    pBitmap = Bitmap + BMP_Header_Length;
	for (i=0; i<START_LINES; i++)
	{
	    for (j=0; j<240; j++)
	    {
			*debug_buffer++ = 0xFFFF;
	    }
	}
	for (i=0; i<320; i++)
	{
	    for (j=0; j<240; j++)
	    {
	        blue = *pBitmap++;
	        green = *pBitmap++;
	        red = *pBitmap++;
	        temp_pixel = (blue & 0xF8) << 8;
	        temp_pixel |= (green & 0xFC) << 3;
	        temp_pixel |= (red & 0xF8) >> 3;
	        *debug_buffer++ = temp_pixel;
	    }
	}
	fclose (fpBitmap);
#endif /* BF537_EZKIT_PPI_PICTURE */

#ifdef BF537_EZKIT_PPI_DEBUG
	short* debug_buffer = (short*) Frame;
	int i, j;
	
	for (i=0; i<START_LINES; i++)
	{
	    for (j=0; j<240; j++)
	    {
			*debug_buffer++ = 0xFFFF;
	    }
	}
	for (i=0; i<320; i++)
	{
	    for (j=0; j<240; j++)
	    {
			// Color map
			// [15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00]
			// [b4 b3 b2 b1 b0 g5 g4 g3 g2 g1 g0 r4 r3 r2 r1 r0]

			if (i<20) debug_buffer[240*i+j] = 				0x0000;
			if ((i>=20)&&(i<40)) debug_buffer[240*i+j] = 	0x0007;
			if ((i>=40)&&(i<60)) debug_buffer[240*i+j] = 	0x000F;
			if ((i>=60)&&(i<80)) debug_buffer[240*i+j] = 	0x0017;
			if ((i>=80)&&(i<100)) debug_buffer[240*i+j] = 	0x001F;
			if ((i>=100)&&(i<120)) debug_buffer[240*i+j] = 	0x0000;
			if ((i>=120)&&(i<140)) debug_buffer[240*i+j] = 	0x01E0;
			if ((i>=140)&&(i<160)) debug_buffer[240*i+j] = 	0x03E0;
			if ((i>=160)&&(i<180)) debug_buffer[240*i+j] =	0x05E0;
			if ((i>=180)&&(i<200)) debug_buffer[240*i+j] =	0x07E0;
			if ((i>=200)&&(i<220)) debug_buffer[240*i+j] = 	0x0000;
			if ((i>=220)&&(i<240)) debug_buffer[240*i+j] = 	0x3800;
			if ((i>=240)&&(i<260)) debug_buffer[240*i+j] = 	0x7800;
			if ((i>=260)&&(i<280)) debug_buffer[240*i+j] = 	0xB800;
			if ((i>=280)&&(i<300)) debug_buffer[240*i+j] = 	0xF800;
			if ((i>=300)&&(i<320)&&(j<120)) debug_buffer[240*i+j] = 0x0000;
			if ((i>=300)&&(i<320)&&(j>=120)) debug_buffer[240*i+j] = 0xFFFF;
	    }
	}
#endif /* BF537_EZKIT_PPI_DEBUG */
 
	//----------------------------------------------------------
	
	// Prepare the DMA Descriptor
	PictureDMADescriptor.Data = Frame;
	PictureDMADescriptor.ElementWidth = 2;
	PictureDMADescriptor.XCount = 240;
	PictureDMADescriptor.XModify = 2;
	PictureDMADescriptor.YCount = 320+START_LINES+U_LINES;
	PictureDMADescriptor.YModify = 2;
	PictureDMADescriptor.CallbackParameter = (void*) Frame;
	PictureDMADescriptor.pNext = 0;
	
	// open the PPI driver for output
	ret = adi_dev_Open (DeviceManagerHandle, &ADIPPIEntryPoint, 0, NULL, 
		&PPIDriverHandle, ADI_DEV_DIRECTION_OUTBOUND, 
		DMAManagerHandle, DeferredCallbackManagerHandle, PPICallback);
//		DMAManagerHandle, NULL, PPICallback);
	if (ret != 0) 
		BF537_EZKIT_Throw ("adi_dev_Open PPI error\n");

	// configure the PPI driver with the values from the configuration table
	// QVGA configuration table
	static ADI_DEV_CMD_VALUE_PAIR Configuration_BF537_EZKIT_ppi[] = 
	{		
		{ ADI_DEV_CMD_SET_DATAFLOW_METHOD, 		(void*) ADI_DEV_MODE_CHAINED_LOOPBACK },
		{ ADI_PPI_CMD_SET_CONTROL_REG,	 		(void*) 0x0000				},	// Reset settings
		{ ADI_PPI_CMD_SET_DELAY_COUNT_REG,		(void*) (0)					},	// 3 cycles after HSYNC and VSYNC high
		{ ADI_PPI_CMD_SET_TRANSFER_COUNT_REG,	(void*) (240-1)				},	// 240 pixels / line
		{ ADI_PPI_CMD_SET_LINES_PER_FRAME_REG,	(void*) (320+START_LINES+U_LINES) },	// 320 lines / frame
		{ ADI_PPI_CMD_SET_FS_INVERT,			(void*) FALSE				},	// HSYNC and VSYNC rising edge asserted
		{ ADI_PPI_CMD_SET_CLK_INVERT,			(void*) FALSE				},	// PPI drives data on falling edge of PPI_CLK
		{ ADI_PPI_CMD_SET_DATA_LENGTH,			(void*) 0x7					},	// 16 bit of data 565 RGB
		{ ADI_PPI_CMD_SET_SKIP_EVEN_ODD,		(void*) 0					},	// Don't care
		{ ADI_PPI_CMD_SET_SKIP_ENABLE,			(void*) 0					},	// Skipping disabled
		{ ADI_PPI_CMD_SET_PACK_ENABLE,			(void*) 0					},	// Don't care
		{ ADI_PPI_CMD_SET_ACTIVE_FIELD_SELECT,	(void*) 0					},	// Don't care
		{ ADI_PPI_CMD_SET_PORT_CFG,				(void*) 1					},	// 2 or 3 frame syncs
		{ ADI_PPI_CMD_SET_TRANSFER_TYPE,		(void*) 3					},	// Output mode with 1, 2 or 3 frame syncs
		{ ADI_PPI_CMD_SET_PORT_DIRECTION,		(void*) TRUE				},	// Outbound
		{ ADI_PPI_CMD_SET_TRIPLE_FRAME_SYNC,	(void*) FALSE				},	// No triple frame sync
		{ ADI_PPI_CMD_SET_TIMER_FRAME_SYNC_1,	(void*) FALSE				},	// All timers are controlled by system services
		{ ADI_PPI_CMD_SET_TIMER_FRAME_SYNC_2,	(void*) FALSE				},	// All timers are controlled by system services
		{ ADI_DEV_CMD_SET_STREAMING,			(void*) TRUE				},	// Enables streaming mode of the driver
		{ ADI_DEV_CMD_END, NULL	}
	};
	
	ret = adi_dev_Control (PPIDriverHandle, ADI_DEV_CMD_TABLE, Configuration_BF537_EZKIT_ppi);
	if (ret != 0) 
		BF537_EZKIT_Throw ("adi_dev_Control PPI error\n");

	//----------------------------------------------------------

	// Initialize the timers for the LCD
	OpenTimersForLCD ();
}

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------

void CloseLCD (void)
{
//	void* address = (void*) I2C_ADDRESS_16BIT_IO_EXPANDER;
	int data;
	int ret;

	// Stop the PPI driver
	ret = adi_dev_Control (PPIDriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*) FALSE);
	if (ret != 0) 
		BF537_EZKIT_Throw ("adi_dev_Control PPI close error\n");
		
}

//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------

void StartLCD (void)
{
	int ret;

    // Start the timers first
    StartTimersForLCD ();
    
    // Start the PPI	
	ret = adi_dev_Write (PPIDriverHandle, ADI_DEV_2D, (ADI_DEV_BUFFER*) &PictureDMADescriptor);
	if (ret != 0) 
		BF537_EZKIT_Throw ("adi_dev_Write PPI StartLCD error\n");

	// enable data flow
	ret = adi_dev_Control (PPIDriverHandle, ADI_DEV_CMD_SET_DATAFLOW, (void*) TRUE);
	if (ret != 0) 
		BF537_EZKIT_Throw ("adi_dev_Control PPI StartLCD error\n");
}

⌨️ 快捷键说明

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