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

📄 ezkitutilities.c

📁 BlackFin LCD 显示, 简单GUI图形显示
💻 C
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************************

Copyright(c) 2005 Analog Devices, Inc. All Rights Reserved.

This software is proprietary and confidential.  By using this software you agree
to the terms of the associated Analog Devices License Agreement.

$RCSfile: ezkitutilities.c,v $
$Revision: 1.14 $
$Date: 2005/08/25 16:19:36 $

Description:	EZ-Kit utility routines.  This file contains a collection
				of functions that automate typical EZ-Kit functionality,
				including control of LEDs and push buttons.

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


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

Include files

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

#include <services/services.h>		// system service includes
#include <sysreg.h>					// system config definitions
#include "ezkitutilities.h"			// EZ-Kit utility definitions



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

Button/LED to Flag pin mappings

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

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
static ADI_FLAG_ID Button[] = {
	/* button[0] (PB1) */ ADI_FLAG_PF8, 	// EZ_FIRST_BUTTON
	/* button[1] (PB2) */ ADI_FLAG_PF9,
	/* button[2] (PB3) */ ADI_FLAG_PF10,
	/* button[3] (PB4) */ ADI_FLAG_PF11		// EZ_LAST_BUTTON
};
static ADI_FLAG_ID LED[] = {	//(not used on Edinburgh but needed as placeholder)
	/* led[4] */ ADI_FLAG_PF0, 				// EZ_FIRST_LED
	/* led[5] */ ADI_FLAG_PF0,
	/* led[6] */ ADI_FLAG_PF0,
	/* led[7] */ ADI_FLAG_PF0,
	/* led[8] */ ADI_FLAG_PF0,
	/* led[9] */ ADI_FLAG_PF0				// EZ_LAST_LED
};
#endif

#if defined(__ADSP_BRAEMAR__)			// ADSP-BF537 EZ-Kit specific info
static ADI_FLAG_ID Button[] = {
	/* button[0] (PB1) */ ADI_FLAG_PF2, 	// EZ_FIRST_BUTTON
	/* button[1] (PB2) */ ADI_FLAG_PF3,
	/* button[2] (PB3) */ ADI_FLAG_PF4,
	/* button[3] (PB4) */ ADI_FLAG_PF5		// EZ_LAST_BUTTON
};
static ADI_FLAG_ID LED[] = {
	/* led[1] */ ADI_FLAG_PF6, 				// EZ_FIRST_LED
	/* led[2] */ ADI_FLAG_PF7,
	/* led[3] */ ADI_FLAG_PF8,
	/* led[4] */ ADI_FLAG_PF9,
	/* led[5] */ ADI_FLAG_PF10,
	/* led[6] */ ADI_FLAG_PF11				// EZ_LAST_LED
};
#endif


#if defined(__ADSP_TETON__)
static ADI_FLAG_ID LED[] = {
	/* led[0]  (LED5)  */ ADI_FLAG_PF40, 	// EZ_FIRST_LED
	/* led[1]  (LED6)  */ ADI_FLAG_PF41,
	/* led[2]  (LED7)  */ ADI_FLAG_PF42,
	/* led[3]  (LED8)  */ ADI_FLAG_PF43,
	/* led[4]  (LED9)  */ ADI_FLAG_PF44,
	/* led[5]  (LED10) */ ADI_FLAG_PF45,
	/* led[6]  (LED11) */ ADI_FLAG_PF46,
	/* led[7]  (LED12) */ ADI_FLAG_PF47,
	/* led[8]  (LED13) */ ADI_FLAG_PF32,
	/* led[9]  (LED14) */ ADI_FLAG_PF33,
	/* led[10] (LED15) */ ADI_FLAG_PF34,
	/* led[11] (LED16) */ ADI_FLAG_PF35,
	/* led[12] (LED17) */ ADI_FLAG_PF36,
	/* led[13] (LED18) */ ADI_FLAG_PF37,
	/* led[14] (LED19) */ ADI_FLAG_PF38,
	/* led[15] (LED20) */ ADI_FLAG_PF39		// EZ_LAST_LED
};

static ADI_FLAG_ID Button[] = {
	/* button[0] (SW6) */ ADI_FLAG_PF5, 	// EZ_FIRST_BUTTON
	/* button[1] (SW7) */ ADI_FLAG_PF6,
	/* button[2] (SW8) */ ADI_FLAG_PF7,
	/* button[3] (SW9) */ ADI_FLAG_PF8		// EZ_LAST_BUTTON
};

#endif


#define EZ_NUM_BUTTONS					(sizeof(Button)/sizeof(Button[0]))		// number of buttons
#define EZ_BUTTON_TO_FLAG(ButtonNumber) Button[ButtonNumber-EZ_FIRST_BUTTON]	// converts button number to flag ID

#define EZ_NUM_LEDS						(sizeof(LED)/sizeof(LED[0]))			// number of LEDs
#define EZ_LED_TO_FLAG(LEDNumber) 		LED[LEDNumber-EZ_FIRST_LED]				// converts LED number to flag ID


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

Peripheral ID Macros

This program works on the EZ-Kits.  The macros
below are used to identify which EZ-Kit we're targeting.  Specifically,
the FLAG_PERIPHERAL_ID macro is set to the peripheral ID to which the
interrupt driven push buttons are mapped.  See the adi_int.h file
within the system services library (blackfin/include/services) for
more information on peripheral IDs.

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

#if defined(__ADSP_EDINBURGH__)
#define FLAG_PERIPHERAL_ID	(ADI_INT_PFA)
#endif

#if defined(__ADSP_BRAEMAR__)
#define FLAG_PERIPHERAL_ID	(ADI_INT_PORTFG_A)
#endif

#if defined(__ADSP_TETON__)
#define FLAG_PERIPHERAL_ID	(ADI_INT_PF0_15_A)
#endif


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

Enumerations and defines

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

#if defined(__ADSP_EDINBURGH__)			// the Edinburgh EZ-Kit uses a flash for ports

#define pFlashA_PortA_In	((volatile unsigned char *)0x20270000)	// address of flash A port A input data register
#define pFlashA_PortA_Out	((volatile unsigned char *)0x20270004)	// address of flash A port A output data register
#define pFlashA_PortA_Dir	((volatile unsigned char *)0x20270006)	// address of flash A port A direction register

#define pFlashA_PortB_In	((volatile unsigned char *)0x20270001)	// address of flash A port B input data register
#define pFlashA_PortB_Out	((volatile unsigned char *)0x20270005)	// address of flash A port B output data register
#define pFlashA_PortB_Dir	((volatile unsigned char *)0x20270007)	// address of flash A port B direction register

#define pFlashB_PortA_In	((volatile unsigned char *)0x202E0000)	// address of flash B port A input data register
#define pFlashB_PortA_Out	((volatile unsigned char *)0x202E0004)	// address of flash B port A output data register
#define pFlashB_PortA_Dir	((volatile unsigned char *)0x202E0006)	// address of flash B port A direction register

#define pFlashB_PortB_In	((volatile unsigned char *)0x202E0001)	// address of flash B port B input data register
#define pFlashB_PortB_Out	((volatile unsigned char *)0x202E0005)	// address of flash B port B output data register
#define pFlashB_PortB_Dir	((volatile unsigned char *)0x202E0007)	// address of flash B port B direction register

#endif


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

Miscellaneous defines

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

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
#define RST_7183 				(0x8) 	    //decoder reset bit #3 in flashA portA
#define PPICLK_ADV7183_SELECT 	(0x10)		//decoder clock to PPI bit #4 in flashA portA
#define ADV7183_OE_MASK 	(0x4)		//ADV7183 /OE = PF2
#define ADV7183_OE			(0)			//Index into Codec flag handler array
#define RST_7171 				(0x4)		// encoder reset
#endif


#if defined(__ADSP_TETON__)
#define ADV7183_RESET		(13)		//decoder reset bit
#define ADV7183_OE 		(2)		//ADV7183 /OE = PF2
#define ADV7183_Reset_Delay   	0x04000000	// For delay after reset
#define ADV7183_Lock   		0x0000ffff	// For startup locktime delay
#define ADV7179_RESET 		(14)		// encoder reset bit
#endif




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

static functions


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

static void ezInitPower(void);			// initializes power to 600/120
static void ezInitAsync(void);			// configures async memory for use
static void ezInitFlashA(void);			// sets up the flash
static void ezInitLEDs(void);			// initialized LEDs
static void ezInitButtons(void);		// initializes buttons

static void ezTerminateLEDs(void);		// terminates LEDs
static void ezTerminateButtons(void);	// terminates buttons


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

	Function:		ezInit

	Description:	Initializes the Utilities service.  Specifically:
					- configures async memories
					- configures flash (where applicable)
					- configures power to 600/120
					- configures all LEDs
					- configures all pushbuttons


*********************************************************************/
void ezInit(void)
{

	// configure async memory
#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	ezInitAsync();
#endif

	// configure flash
#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	ezInitFlashA();
#endif


#if !defined(__ADSP_TETON__)

	// configure power
	ezInitPower();

#endif

	// configure LEDs
	ezInitLEDs();

	// configure buttons
	ezInitButtons();

}

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

	Function:		ezTerminate

	Description:	Terminates the utilities.  Specifically
					- terminates LEDs
					- terminates buttons


*********************************************************************/
void ezTerminate()
{
	// terminate LEDs
	ezTerminateLEDs();

	// terminate buttons
	ezTerminateButtons();
}




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

	Function:		ezEnableVideoDecoder

	Description:	Connects up the bus, sets up the video clocking and
					enables the AD7183.

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

void ezEnableVideoDecoder(void)			// connects bus, sets up video clock and enables the 7183
{

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
#define ADV7183_OE_FLAG ADI_FLAG_PF2

	unsigned short tempReg;

	//The GPIOs of the flash are linked to the ADV7183 reset pin as well as to the
	//switch that drives the PPI clock. De-assert the ADV7183 reset and link the ADV7183
	//Clock "LLC1" to the Blackfin PPI clock input.  See EZ-KIT schematics for more details.
	tempReg = *pFlashA_PortA_Out;
	*pFlashA_PortA_Out = tempReg | RST_7183 | PPICLK_ADV7183_SELECT;

	//Setup the Blackfin PF registers
#if defined(__ADSP_EDINBURGH__) && (__SILICON_REVISION__==0xffff || __SILICON_REVISION__==0x1)
 		tempReg = *pFIO_INEN;
		*pFIO_INEN = tempReg | ADV7183_OE_MASK;
#endif

	// open PF2 and PF13
	adi_flag_Open(ADI_FLAG_PF2);
	adi_flag_Open(ADI_FLAG_PF13);

	//Blackfin PF2 pin must be set as output
	adi_flag_SetDirection(ADI_FLAG_PF2, ADI_FLAG_DIRECTION_OUTPUT);

	//Set the Blackfin pin PF2 to output enable the ADV7183 data bus
	adi_flag_Clear(ADI_FLAG_PF2);

#endif // Edinburgh


#if defined(__ADSP_TETON__)

 	volatile long delay_time;

	//Blackfin PF2 pin must be set as output
	adi_flag_SetDirection(ADI_FLAG_PF2, ADI_FLAG_DIRECTION_OUTPUT);

	//Blackfin PF13 pin must be set as output
	adi_flag_SetDirection(ADI_FLAG_PF13, ADI_FLAG_DIRECTION_OUTPUT);
	ssync();

	// set bit PF2 to disable ADV7183 outputs
	adi_flag_Set(ADI_FLAG_PF2);
	ssync();

	// clear bit PF13 to reset ADV7183
	adi_flag_Clear(ADI_FLAG_PF13);
	ssync();

	// set bit PF13 to re-enable ADV7183
	adi_flag_Set(ADI_FLAG_PF13);
	ssync();

	for (delay_time = 0; delay_time < ADV7183_Reset_Delay; delay_time++)
		asm("nop;");

	// clear bit to enable ADV7183 outputs
	adi_flag_Clear(ADI_FLAG_PF2);
	ssync();

	for (delay_time = 0; delay_time < ADV7183_Lock; delay_time++)
		asm("nop;");

#endif   // Teton

}

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

	Function:		ezEnableVideoEncoder

	Description:	Enables the AD7171 or AD7179

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

void ezEnableVideoEncoder(void)		// enables the 7171
{

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	*pFlashA_PortA_Out = 0;
	*pFlashA_PortA_Out |= RST_7171;
#endif // Edinburgh


#if defined(__ADSP_TETON__)

	// open PF14
	adi_flag_Open(ADI_FLAG_PF14);

	//Blackfin PF14 pin must be set as output
	adi_flag_SetDirection(ADI_FLAG_PF14, ADI_FLAG_DIRECTION_OUTPUT);
	ssync();

	// clear bit to reset ADV7179, Blackfin pin PF14
	adi_flag_Clear(ADI_FLAG_PF14);
	ssync();

	adi_flag_Set(ADI_FLAG_PF14);
	ssync();


#endif   // Teton

}




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

	Function:	ezDisableVideoEncoder

	Description:	Disables the AD7179.

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

void ezDisableVideoEncoder(void)
{

#if defined(__ADSP_TETON__)
	adi_flag_Clear(ADI_FLAG_PF14);

	// close PF14
	adi_flag_Close(ADI_FLAG_PF14);

	ssync();
#endif
}


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

	Function:		ezDisableVideoDecoder

	Description:	 Disables 7183
*********************************************************************/

void ezDisableVideoDecoder(void)
{

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	// do we need to do anything???
#endif // Edinburgh

#if defined(__ADSP_TETON__)

	// set bit PF2 to disable ADV7183 outputs
	adi_flag_Set(ADI_FLAG_PF2);
	ssync();

	// clear bit PF13 to reset ADV7183
	adi_flag_Clear(ADI_FLAG_PF13);
	ssync();
#endif

	// close PF2 and PF13
	adi_flag_Close(ADI_FLAG_PF2);
	adi_flag_Close(ADI_FLAG_PF13);

}


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

	Function:		ezTurnOnLED

	Description:	Turns an LED on.

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

void ezTurnOnLED(u32 LEDNumber)	// turns on an LED
{

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	switch(LEDNumber) {
		case 4:
			*pFlashA_PortB_Out |= 0x0001;
			break;
		case 5:
			*pFlashA_PortB_Out |= 0x0002;
			break;
		case 6:
			*pFlashA_PortB_Out |= 0x0004;
			break;
		case 7:
			*pFlashA_PortB_Out |= 0x0008;
			break;
		case 8:
			*pFlashA_PortB_Out |= 0x0010;
			break;
		case 9:
			*pFlashA_PortB_Out |= 0x0020;
			break;
	}
#endif // Edinburgh

#if defined(__ADSP_BRAEMAR__) || defined (__ADSP_TETON__) // ADSP-BF537 & BF561 EZ-Kit specific info
	adi_flag_Set(EZ_LED_TO_FLAG(LEDNumber));
#endif // Braemar or teton

}



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

	Function:		ezTurnOffLED

	Description:	Turns an LED off.

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

void ezTurnOffLED(u32 LEDNumber)	// turns on an LED
{

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	switch(LEDNumber) {
		case 4:
			*pFlashA_PortB_Out &= ~0x0001;
			break;
		case 5:
			*pFlashA_PortB_Out &= ~0x0002;
			break;
		case 6:
			*pFlashA_PortB_Out &= ~0x0004;
			break;
		case 7:
			*pFlashA_PortB_Out &= ~0x0008;
			break;
		case 8:
			*pFlashA_PortB_Out &= ~0x0010;
			break;
		case 9:
			*pFlashA_PortB_Out &= ~0x0020;

⌨️ 快捷键说明

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