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

📄 led.c

📁 老外的一个开源项目
💻 C
字号:
// Copyright (c) David Vescovi.  All rights reserved.
// Part of Project DrumStix
// Windows Embedded Developers Interest Group (WE-DIG) community project.
// http://www.we-dig.org
// Copyright (c) Microsoft Corporation.  All rights reserved.
//------------------------------------------------------------------------------
//
//  File:  led.c            
//
//  This module implements the Debug LED.
//
//------------------------------------------------------------------------------
#include "bsp.h"
#include <nkintr.h>
 
//------------------------------------------------------------------------------
// Defines 
//
 
//------------------------------------------------------------------------------
// Externs
//
 
//------------------------------------------------------------------------------
// Global Variables 
static BOOL g_debugLedState;
 
//------------------------------------------------------------------------------
// Local Variables 
//

//------------------------------------------------------------------------------
// Local Functions 
//

//------------------------------------------------------------------------------
//
//  Function: OEMInitLED
//
//  Configure GPIO for LED output.
//
//------------------------------------------------------------------------------
BOOL OEMInitLED(void)
{
    volatile GPIO_REG_T *pGPIORegs = NULL;

    pGPIORegs = (volatile GPIO_REG_T *) OALPAtoVA(PXA255_BASE_REG_PA_GPIO, FALSE);
	pGPIORegs->GPDR2 |= DEBUG_LED_GPIO;
	OEMWriteDebugLED(0, 0);
	g_debugLedState = FALSE;
	return (TRUE);
}

//------------------------------------------------------------------------------
//
//  Function: OEMInitDebugLED
//
//  Configure GPIO for LED output.
//
//------------------------------------------------------------------------------
void OEMInitDebugLED(void)
{
    volatile GPIO_REG_T *pGPIORegs = NULL;

    pGPIORegs = (volatile GPIO_REG_T *) OALPAtoVA(PXA255_BASE_REG_PA_GPIO, FALSE);
#ifdef USE_DEBUG_LED
	pGPIORegs->GPDR2 |= DEBUG_LED_GPIO;
#endif
	OEMWriteDebugLED(0, 0);
	g_debugLedState = FALSE;
}

//------------------------------------------------------------------------------
//
//  Function: OEMWriteDebugLED
//
//  Writes to debug LED.
//  Turns off LED if Pattern 0
//  Turns on LED if Pattern 1
//  Toggle LED if Pattern 2
//  Index not used.
//
//------------------------------------------------------------------------------
void OEMWriteDebugLED(UINT16 Index, DWORD Pattern)
{
    volatile GPIO_REG_T *pGPIORegs = NULL;

    pGPIORegs = (volatile GPIO_REG_T *) OALPAtoVA(PXA255_BASE_REG_PA_GPIO, FALSE);
	if (Pattern == 2)
	{ // toggle
		g_debugLedState ? (pGPIORegs->GPSR2 = DEBUG_LED_GPIO) : (pGPIORegs->GPCR2 = DEBUG_LED_GPIO);
		g_debugLedState = !g_debugLedState;
	}
	else
	{ // ON or OFF
		Pattern ? (pGPIORegs->GPCR2 = DEBUG_LED_GPIO) : (pGPIORegs->GPSR2 = DEBUG_LED_GPIO);
		g_debugLedState = (BOOL)Pattern;
	}
}

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

⌨️ 快捷键说明

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