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

📄 lpc177x_8x_pinsel.c

📁 NXPl788上lwip的无操作系统移植,基于Embest开发板
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************
* $Id$		lpc177x_8x_pinsel.c			2011-06-02
*//**
* @file		lpc177x_8x_pinsel.c
* @brief	Contains all functions support for Pin-connection block
*			firmware library on LPC177x_8x
* @version	1.0
* @date		02. June. 2011
* @author	NXP MCU SW Application Team
* 
* Copyright(C) 2011, NXP Semiconductor
* All rights reserved.
*
***********************************************************************
* Software that is described herein is for illustrative purposes only
* which provides customers with programming information regarding the
* products. This software is supplied "AS IS" without any warranties.
* NXP Semiconductors assumes no responsibility or liability for the
* use of the software, conveys no license or title under any patent,
* copyright, or mask work right to the product. NXP Semiconductors
* reserves the right to make changes in the software without
* notification. NXP Semiconductors also make no representation or
* warranty that such application will be suitable for the specified
* use without further testing or modification.
* Permission to use, copy, modify, and distribute this software and its
* documentation is hereby granted, under NXP Semiconductors'
* relevant copyright in the software, without fee, provided that it
* is used in conjunction with NXP Semiconductors microcontrollers.  This
* copyright, permission, and disclaimer notice must appear in all copies of
* this code.
**********************************************************************/

/* Peripheral group ----------------------------------------------------------- */
/** @addtogroup PINSEL
 * @{
 */
#ifdef __BUILD_WITH_EXAMPLE__
#include "lpc177x_8x_libcfg.h"
#else
#include "lpc177x_8x_libcfg_default.h"
#endif /* __BUILD_WITH_EXAMPLE__ */
#ifdef _PINSEL

/* Includes ------------------------------------------------------------------- */
#include "lpc177x_8x_pinsel.h"

/* Private Functions ---------------------------------------------------------- */

/*********************************************************************//**
 * @brief		Get pointer to GPIO peripheral due to GPIO port
 * @param[in]	portnum		Port Number value, should be in range from 0..3.
 * @param[in]	pinnum		Pin number value, should be in range from 0..31
 * @return		Pointer to GPIO peripheral
 **********************************************************************/
static uint32_t * PIN_GetPointer(uint8_t portnum, uint8_t pinnum)
{
	uint32_t *pPIN = NULL;
	pPIN = (uint32_t *)(LPC_IOCON_BASE + ((portnum * 32 + pinnum)*sizeof(uint32_t)));
	return pPIN;
}

/* Public Functions ----------------------------------------------------------- */
/** @addtogroup PINSEL_Public_Functions
 * @{
 */

/*********************************************************************//**
 * @brief 		Get type of a pin.
 * @param[in]	portnum PORT number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @return 		Port type:
 *				- PINSEL_PIN_TYPE_D
 *				- PINSEL_PIN_TYPE_A
 *				- PINSEL_PIN_TYPE_I
 *				- PINSEL_PIN_TYPE_W
 *				- PINSEL_PIN_TYPE_U   
 *				- PINSEL_PIN_TYPE_UNKNOWN: Invalid pin
 **********************************************************************/
PinSel_PinType PINSEL_GetPinType(uint8_t portnum, uint8_t pinnum)
{
	PinSel_PinType Ret = PINSEL_PIN_TYPE_UNKNOWN;
	switch(portnum)
	{
		case 0:
			if((pinnum <=6)||
				((pinnum >= 10)&&(pinnum <=11))||
				((pinnum >= 14)&&(pinnum <=22)))
				Ret = PINSEL_PIN_TYPE_D;
			else if ((pinnum == 12)||(pinnum==13)||
					((pinnum >= 23)&&(pinnum <=26)))
				Ret = PINSEL_PIN_TYPE_A;
			else if ((pinnum == 29) || (pinnum==30)|| (pinnum==31))
				Ret = PINSEL_PIN_TYPE_U;
			else if ((pinnum == 27) || (pinnum==28))
				Ret = PINSEL_PIN_TYPE_I;
			else if ((pinnum == 7) || (pinnum==8)|| (pinnum==9))
				Ret = PINSEL_PIN_TYPE_W;
			break;
		case 1:
			if(pinnum <=29)
				Ret = PINSEL_PIN_TYPE_D;
			else if ((pinnum == 30) || (pinnum==31))
				Ret = PINSEL_PIN_TYPE_A;
			break;
		case 2:
		case 3:
		case 4:
			Ret = PINSEL_PIN_TYPE_D;
			break;
		case 5:
			if((pinnum <=1)||
				(pinnum == 4))
				Ret = PINSEL_PIN_TYPE_D;
			else if ((pinnum == 2) || (pinnum==3))
				Ret = PINSEL_PIN_TYPE_I;
			break;
		default:
			break;
	}

	return Ret;
}

/*********************************************************************//**
 * @brief 		Setup the pin selection function
 * @param[in]	portnum PORT number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	funcnum Function number, should be range: 0..7
 * 				- 0: Select GPIO (Default)
 * 				- 1: Selects the 1st alternate function
 * 				- 2: Selects the 2nd alternate function
 * 				...
 *				- 7: Selects the 7th alternate function
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_ConfigPin ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum)
{
	uint32_t *pPIN = NULL;
	PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);

	if(type == PINSEL_PIN_TYPE_UNKNOWN)
		return PINSEL_RET_INVALID_PIN;
	
	pPIN = PIN_GetPointer(portnum, pinnum);
	*pPIN &= ~IOCON_FUNC_MASK;//Clear function bits
	*pPIN |= funcnum&IOCON_FUNC_MASK;

	return PINSEL_RET_OK;
}


/*********************************************************************//**
 * @brief 		Setup resistor mode for pin of type D,A,W
 * @param[in]	portnum PORT number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	modenum: Mode number, should be in range: 0..3
				- IOCON_MODE_PLAIN: Plain output
				- IOCON_MODE_PULLDOWN: Pull-down enable
				- IOCON_MODE_PULLUP: Pull-up enable
				- IOCON_MODE_REPEATER: Repeater mode
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetPinMode ( uint8_t portnum, uint8_t pinnum, PinSel_BasicMode modenum)
{
	uint32_t *pPIN = NULL;
	PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);

	if(type == PINSEL_PIN_TYPE_UNKNOWN)
		return PINSEL_RET_INVALID_PIN;
	if((type != PINSEL_PIN_TYPE_D )&&
		(type != PINSEL_PIN_TYPE_A )&&
		(type != PINSEL_PIN_TYPE_W))
		return PINSEL_RET_NOT_SUPPORT;
	
	pPIN = PIN_GetPointer(portnum, pinnum);
	*(uint32_t *)pPIN &= ~(IOCON_MODE_MASK);//Clear function bits
	*(uint32_t *)pPIN |= (modenum << IOCON_MODE_POS)&IOCON_MODE_MASK;

	return PINSEL_RET_OK;
}

/*********************************************************************//**
 * @brief 		Setup hysteresis for pin of type D, W
 * @param[in]	portnum Port number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	NewState new state of Hysteresis mode, should be:
 * 				- ENABLE: Hysteresis enable
 * 				- DISABLE: Hysteresis disable
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetHysMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState)
{
	uint32_t *pPIN = NULL;
	PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);

	if(type == PINSEL_PIN_TYPE_UNKNOWN)
		return PINSEL_RET_INVALID_PIN;
	if((type != PINSEL_PIN_TYPE_D )&&
		(type != PINSEL_PIN_TYPE_W))
		return PINSEL_RET_NOT_SUPPORT;
	
	pPIN = PIN_GetPointer(portnum, pinnum);
	if(NewState == DISABLE)
	{
		*(uint32_t *)pPIN &= ~IOCON_HYS_ENABLE;//Clear hys bits
	}
	else
		*(uint32_t *)pPIN |= IOCON_HYS_ENABLE;

	return PINSEL_RET_OK;
}
/*********************************************************************//**
 * @brief 		Setup input polarity for pin of type A,I,D,W
 * @param[in]	portnum Port number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	NewState new state of Invert mode, should be:
 * 				- ENABLE: Input is inverted.
 * 				- DISABLE: Input isn't inverted.
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetInvertInput(uint8_t portnum, uint8_t pinnum, FunctionalState NewState)
{
	uint32_t *pPIN = NULL;
	PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);

	if(type == PINSEL_PIN_TYPE_UNKNOWN)
		return PINSEL_RET_INVALID_PIN;
	if(type== PINSEL_PIN_TYPE_U)
		return PINSEL_RET_NOT_SUPPORT;
	
	pPIN = PIN_GetPointer(portnum, pinnum);
	if(NewState == DISABLE)
	{
		*(uint32_t *)pPIN &= ~IOCON_INVERT_INPUT;//Clear hys bits
	}
	else
		*(uint32_t *)pPIN |= IOCON_INVERT_INPUT;

	return PINSEL_RET_OK;
}

/*********************************************************************//**
 * @brief 		Setup Slew rate for pin of type D,W
 * @param[in]	portnum Port number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	NewState new state of Slew rate control, should be:
 * 				- ENABLE: Output slew rate control is enable
 * 				- DISABLE: Output slew rate control is disable
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetSlewMode(uint8_t portnum, uint8_t pinnum, FunctionalState NewState)
{
	uint32_t *pPIN = NULL;
	PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);

	if(type == PINSEL_PIN_TYPE_UNKNOWN)
		return PINSEL_RET_INVALID_PIN;

⌨️ 快捷键说明

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