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

📄 ezkitutilities.c

📁 BlackFin LCD 显示, 简单GUI图形显示
💻 C
📖 第 1 页 / 共 2 页
字号:
			break;
	}
#endif // Edinburgh

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

}


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

	Function:		ezToggleLED

	Description:	Toggles the state of an LED.

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

void ezToggleLED(u32 LEDNumber)	// toggles an LED
{
	if (ezIsLEDOn(LEDNumber)) {
		ezTurnOffLED(LEDNumber);
	} else {
		ezTurnOnLED(LEDNumber);
	}
}




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

	Function:		ezTurnOnAllLEDs

	Description:	Turns on all LEDs.

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

void ezTurnOnAllLEDs(void)					// turns on all LEDs
{
	int i;

	// turn them on
	for (i = EZ_FIRST_LED; i <= EZ_LAST_LED; i++) {
		ezTurnOnLED(i);
	}

}


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

	Function:		ezTurnOffAllLEDs

	Description:	Turns off all LEDs.

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

void ezTurnOffAllLEDs(void)					// turns off all LEDs
{
	int i;

	// turn them off
	for (i = EZ_FIRST_LED; i <= EZ_LAST_LED; i++) {
		ezTurnOffLED(i);
	}

}


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

	Function:		ezCycleLEDs

	Description:	Cycles through each LED in turn.

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

void ezCycleLEDs(void)						// cycles through LEDS
{												// changes each time called
static int LED = EZ_FIRST_LED;

			ezTurnOffLED(LED);
			LED++;
			if (LED > EZ_LAST_LED) LED = EZ_FIRST_LED;
			ezTurnOnLED(LED);
}


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

	Function:		ezIsLEDOn

	Description:	Returns TRUE if an LED is lit, FALSE otherwise.

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

u32 ezIsLEDOn(u32 LEDNumber)	// test to see if an LED is lit
{

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

	// return
	return (FALSE);
#endif

#if defined(__ADSP_BRAEMAR__) || defined (__ADSP_TETON__) // ADSP-BF537 & BF561 EZ-Kit specific info

	u32	Value;

	adi_flag_Sense(EZ_LED_TO_FLAG(LEDNumber), &Value);

	// return
	return (Value );

#endif // Braemar or Teton

}

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

	Function:		ezGetDisplay

	Description:	Returns the current status of the LED display

*********************************************************************/
u32 ezGetDisplay()
{
	int i;
	u32 Mask;
	u32 Display;

	// assume nothing's on and set our mask
	Display = 0;
	Mask = 1;

	// FOR (each LED)
	for (i = EZ_FIRST_LED; i <= EZ_LAST_LED; i++, Mask <<= 1) {

		// set the bit in Display if the LED is on
		if (ezIsLEDOn(i)) Display |= Mask;

	// ENDFOR
	}

	// return
	return (Display);
}

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

	Function:		ezSetDisplay

	Description:	Sets the LED display

*********************************************************************/
void ezSetDisplay(u32 Display)
{

	int i;

	// FOR (each LED)
	for (i = EZ_FIRST_LED; i <= EZ_LAST_LED; i++, Display >>= 1) {

		// light the LED if that bit in the display is set
		if (Display & 0x1) {
			ezTurnOnLED(i);
		} else {
			ezTurnOffLED(i);
		}

	// ENDFOR
	}

}



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

	Function:		ezErrorCheck

	Description:	This function is intended to be used as a means to
					quickly determine if a function has returned a non-zero
					(hence an error) return code.  All driver and system
					services functions return a value of zero for success and
					a non-zero value when a failure occurs.  This function
					lights all the LEDs and spins when a non-zero value is
					passed to it.

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

void ezErrorCheck(u32 Result)				// lights all LEDS and spins on nonzero value
{
	while (Result != 0) {
		ezTurnOnAllLEDs();
	}
}





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

	Function:		ezIsButtonPushed

	Description:	Returns TRUE if a button has been pushed, FALSE otherwise.

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

u32 ezIsButtonPushed(u32 ButtonNumber) 		// returns TRUE if button is pushed, FALSE otherwise
{
	u32	Value;

	// sense it
	adi_flag_Sense(EZ_BUTTON_TO_FLAG(ButtonNumber), &Value);

	// return
	return (Value);

}


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

	Function:		ezEnableButtonCallback

	Description:	Enables generation of a callback in response to
					a button being pushed.

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

u32	ezEnableButtonCallback		(					// enables generation of a push button callback
	u32 				ButtonNumber,
	void				*ClientHandle,
	ADI_DCB_HANDLE		DCBHandle,
	ADI_DCB_CALLBACK_FN	ClientCallback
) {

	// use the flag service to hook the interrupt
	return((u32)adi_flag_InstallCallback(EZ_BUTTON_TO_FLAG(ButtonNumber), FLAG_PERIPHERAL_ID, ADI_FLAG_TRIGGER_RISING_EDGE, TRUE, ClientHandle, DCBHandle, ClientCallback));

	// return
}



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

	Function:		ezDisableButtonCallback

	Description:	Disables generation of a callback in response to
					a button being pushed.

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

u32	ezDisableButtonCallback	(u32 ButtonNumber)	// disables generation of a push button callback
{

	// use the flag service to hook the interrupt
	return((u32)adi_flag_RemoveCallback(EZ_BUTTON_TO_FLAG(ButtonNumber)));

}




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

	Function:		ezClearButton

	Description:	Clears a push button latch.  This must be called to
					reset the latch for the push button, if a button has
					been pressed.

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

void	ezClearButton(u32 ButtonNumber)	// clears a button latch
{
	volatile int i;

	// delay to allow for any debounce to clear
	for (i = 0; i < 4000000; i++) ;

	// clear the flag corresponding to the button
	adi_flag_Clear(EZ_BUTTON_TO_FLAG(ButtonNumber));

}








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

	Function:		ezInitPower

	Description:	Initializes and sets Power managwmentSDRAM parameters on the EZ-Kit.
					(Replaces ezConfigurePLL & ezConfigureSDRAM )
					Processor clock set to max in each case

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

#define DO_NOT_CHANGE_MMR_SETTINGS 0

static void ezInitPower(void)
{
	ADI_EBIU_RESULT EBIUResult;
	ADI_PWR_RESULT 	PWRResult;

	// It is important that the EBIU module is configured before Power module
	// so that changes to the clock frequencies are correctly reflected in the
	// SDRAM settings

	//Initializes the EBIU module
	ADI_EBIU_COMMAND_PAIR ezkit_sdram[] = {
#if defined (__ADSP_EDINBURGH__)
		{ ADI_EBIU_CMD_SET_EZKIT, (void*)ADI_EBIU_EZKIT_BF533 },
#elif defined(__ADSP_BRAEMAR__)
		{ ADI_EBIU_CMD_SET_EZKIT, (void*)ADI_EBIU_EZKIT_BF537 },
#elif defined (__ADSP_TETON__)
		{ ADI_EBIU_CMD_SET_EZKIT, (void*)ADI_EBIU_EZKIT_BF561 },
#endif
		{ ADI_EBIU_CMD_END, 0}
	};
	EBIUResult = adi_ebiu_Init( ezkit_sdram, DO_NOT_CHANGE_MMR_SETTINGS );
	if ((EBIUResult != ADI_EBIU_RESULT_SUCCESS) && (EBIUResult != ADI_EBIU_RESULT_CALL_IGNORED)) {
		ezErrorCheck(EBIUResult);
	}

	//Initializes the power management module
	ADI_PWR_COMMAND_PAIR ezkit_power[] = {
#if defined (__ADSP_EDINBURGH__)
		{ ADI_PWR_CMD_SET_EZKIT, (void*)ADI_PWR_EZKIT_BF533_600MHZ },
#elif defined(__ADSP_BRAEMAR__)
		{ ADI_PWR_CMD_SET_EZKIT, (void*)ADI_PWR_EZKIT_BF537_600MHZ },
#elif defined (__ADSP_TETON__)
#ifndef __600_MHZ_TETON__
		// This is safe, on boards with ADSP-BF561SKBC500X rev 0.2
		{ ADI_PWR_CMD_SET_EZKIT, (void*)ADI_PWR_EZKIT_BF561_500MHZ },
#else
		// whilst this should be usable on all BF561 EZ-KITs
		{ ADI_PWR_CMD_SET_EZKIT, (void*)ADI_PWR_EZKIT_BF561_500MHZ },
#endif
#endif
		{ ADI_PWR_CMD_END, 0}
	};
	PWRResult = adi_pwr_Init( ezkit_power );
	if ((PWRResult != ADI_PWR_RESULT_SUCCESS) && (PWRResult != ADI_PWR_RESULT_CALL_IGNORED)) {
		ezErrorCheck(PWRResult);
	}

	// Crank up speed to max possible
#if !defined (__ADSP_TETON__) || defined(__600_MHZ_TETON__)
	ezErrorCheck( adi_pwr_SetFreq( 0, 0, ADI_PWR_DF_NONE ) );
#else
	// Again, this is safe, on boards with ADSP-BF561SKBC500X rev 0.2
	// There are issues with some BF561 EZ-kits for V >=1.2V
	ezErrorCheck( adi_pwr_SetMaxFreqForVolt( ADI_PWR_VLEV_115 ) );
#endif
}


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

	Function:		ezInitAsync

	Description:	Initializes and sets the appropriate wait states for
					the async memories on the EZKit.

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

static void ezInitAsync(void)						// configures async memory for use
{

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	*pEBIU_AMBCTL0	= 0x7bb07bb0;	// Write access time = 7 cycles, read access time = 11 cycles, no ARDY
	*pEBIU_AMBCTL1	= 0x7bb07bb0;	// Hold time = 2 cycles, setup time = 3 cycles, transition time = 4 cycles
	*pEBIU_AMGCTL	= 0x00FF;
#endif // Edinburgh

}



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

	Function:		ezInitFlashA

	Description:	Sets up the A flash on the board for use.

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

static void ezInitFlashA(void)						// sets up the flash
{

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	*pFlashA_PortA_Out = 0;			// resets port A to initial value
	*pFlashA_PortA_Dir = 0xFF;		// configure everything on port A as outputs
	*pFlashA_PortB_Out = 0;			// resets port B to initial value
	*pFlashA_PortB_Dir = 0x3f;		// configure everything on port B as outputs
#endif // Edinburgh

}



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

	Function:		ezInitLEDs

	Description:	Initializes and sets up the LEDs for use.

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

static void ezInitLEDs(void)			// configures the flags to drive LEDs
{
	int i;

#if defined(__ADSP_EDINBURGH__)			// ADSP-BF533 EZ-Kit specific info
	// nothing to do here on the BF533 EZ-Kit
#endif // Edinburgh

#if defined(__ADSP_BRAEMAR__) || defined (__ADSP_TETON__) // ADSP-BF537 & BF561 EZ-Kit specific info
	// configure flags connected to LEDs as inputs
	for (i = 0; i < EZ_NUM_LEDS; i++) {
		adi_flag_Open(LED[i]);
		adi_flag_SetDirection(LED[i], ADI_FLAG_DIRECTION_OUTPUT);
	}
#endif // Braemar or Teton


}


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

	Function:		ezTerminateLEDs

	Description:	Terminates the LEDs

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

static void ezTerminateLEDs (void)
{
	// nothing to do ?????

}

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

	Function:		ezInitButtons

	Description:	Initializes the push button as input flags

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

static void ezInitButtons(void) {

	u32 i;

	// configure flags connected to buttons as inputs
	for (i = 0; i < EZ_NUM_BUTTONS; i++) {
		adi_flag_Open(Button[i]);
		adi_flag_SetDirection(Button[i], ADI_FLAG_DIRECTION_INPUT);
	}

}



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

	Function:		ezTerminateButtons

	Description:	Terminates the buttons

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

static void ezTerminateButtons(void)
{
	// nothing to do ?????

}




⌨️ 快捷键说明

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