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

📄 lpc177x_8x_pinsel.c

📁 NXPl788上lwip的无操作系统移植,基于Embest开发板
💻 C
📖 第 1 页 / 共 2 页
字号:
	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_SLEW_ENABLE;//Clear hys bits
	}
	else
		*(uint32_t *)pPIN |= IOCON_SLEW_ENABLE;

    return PINSEL_RET_OK;
}

/*********************************************************************//**
 * @brief 		Setup I2CMode for only pins that provide special I2C functionality
 * @param[in]	portnum Port number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	I2CMode I2C mode, should be:
 * 				- PINSEL_I2CMODE_FAST_STANDARD: Fast mode and standard I2C mode
 * 				- PINSEL_I2CMODE_OPENDRAINIO: Open drain I/O
 * 				- PINSEL_I2CMODE_FASTMODEPLUS: Fast Mode Plus I/O
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetI2CMode(uint8_t portnum, uint8_t pinnum, PinSel_I2cMode I2CMode)
{
	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_I )
		return PINSEL_RET_NOT_SUPPORT;
	
	pPIN = PIN_GetPointer(portnum, pinnum);

	switch(I2CMode)
	{
		// Standard/Fast Mode I2C: HS = HIDRIVE = 0
		case PINSEL_I2CMODE_FAST_STANDARD: 
			PINSEL_SetI2CFilter(portnum,pinnum,ENABLE);
			*(uint32_t *)pPIN &= ~(IOCON_I2CMODE_FASTPLUS);
			break;

		// Non-I2C: HS = 1, HIDRIVE = 0
		case PINSEL_I2CMODE_OPENDRAINIO:
			PINSEL_SetI2CFilter(portnum,pinnum,DISABLE);
			*(uint32_t *)pPIN &= ~(IOCON_I2CMODE_FASTPLUS);
			break;

		// Fast Mode Plus I2C: HS = 0, HIDRIVE =1
		case PINSEL_I2CMODE_FASTMODEPLUS:	
			PINSEL_SetI2CFilter(portnum,pinnum,ENABLE);
			*(uint32_t *)pPIN |= (IOCON_I2CMODE_FASTPLUS);
			break;
		default:
			return PINSEL_RET_ERR;
	}

	return PINSEL_RET_OK;
}

/*********************************************************************//**
 * @brief 		Setup Open-drain mode in 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] 	NewState new state of Open-drain mode:
 * 				- DISABLE: Normal pin I/O mode
 * 				- ENABLE: Open-drain enable
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetOpenDrainMode(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_A ) &&
		(type != PINSEL_PIN_TYPE_W ))
		return PINSEL_RET_NOT_SUPPORT;
	
	pPIN = PIN_GetPointer(portnum, pinnum);
	if(NewState == DISABLE)
	{
		*(uint32_t *)pPIN &= ~IOCON_OPENDRAIN_MODE;//Clear hys bits
	}
	else
	{
		*(uint32_t *)pPIN |= IOCON_OPENDRAIN_MODE;
	}
	return PINSEL_RET_OK;
}

/*********************************************************************//**
 * @brief 		Enable the Analog mode for each pin  of Type A(default is as Digital pins)
 * @param[in]	portnum PORT number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	enable: the state of the pin that is expected to run
				- ENABLE: Enable the DAC mode of the pin
				- DISABLE: Disable the DAC mode
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetAnalogPinMode (uint8_t portnum, uint8_t pinnum, uint8_t enable)
{
	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_A )
		return PINSEL_RET_NOT_SUPPORT;

	pPIN = PIN_GetPointer(portnum, pinnum);

	if(enable)
	{
		*(uint32_t *)pPIN &= ~(IOCON_DIGITIAL_MODE);
	}
	else
	{
		*(uint32_t *)pPIN |= IOCON_DIGITIAL_MODE;//Set 7th bit to one
	}

	return PINSEL_RET_OK;
}



/*********************************************************************//**
 * @brief 		Choose the DAC mode for pin P0.26
 * @param[in]	portnum PORT number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	enable: the state of the pin that is expected to run
				- ENABLE: Enable the DAC mode of the pin
				- DISABLE: Disable the DAC mode
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_DacEnable (uint8_t portnum, uint8_t pinnum, uint8_t enable)
{
	uint32_t *pPIN = NULL;
	
	PinSel_PinType type = PINSEL_GetPinType(portnum,pinnum);
	
	if(type == PINSEL_PIN_TYPE_UNKNOWN)
		return PINSEL_RET_INVALID_PIN;

	// This setting is only for DAC pin (output pin)
	if(!((portnum == 0) && (pinnum == 26)))
	{
		return PINSEL_RET_NOT_SUPPORT;
	}

	pPIN = PIN_GetPointer(portnum, pinnum);

	if(enable)
	{
		*(uint32_t *)pPIN |= IOCON_DAC_ENABLE;//Set 16th bit to one
	}
	else
	{
		*(uint32_t *)pPIN &= ~IOCON_DAC_ENABLE;//Set 16th bit to one

	}

	return PINSEL_RET_OK;
}

/*********************************************************************//**
 * @brief 		Control the 10ns glitch filter for pin of type 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] 	enable: the state of the pin that is expected to run
				- ENABLE: The noise pulses below approximately 10ns are filtered out
				- DISABLE: No input filtering is done.
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetFilter (uint8_t portnum, uint8_t pinnum, uint8_t enable)
{
	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_A ) &&
		(type != PINSEL_PIN_TYPE_W ))
		return PINSEL_RET_NOT_SUPPORT;

	pPIN = PIN_GetPointer(portnum, pinnum);


	if(enable)
	{
		*(uint32_t *)pPIN &= ~(IOCON_10ns_FILTER_DISABLE);//Clear 8th bit to 0
	}
	else
	{
		*(uint32_t *)pPIN |= (IOCON_10ns_FILTER_DISABLE);//Set 8th bit to one
	}


	return PINSEL_RET_OK;
}
/*********************************************************************//**
 * @brief 		Control the 50ns glitch filter for I2C pins (type I)
 * @param[in]	portnum PORT number, should be in range: 0..3
 * @param[in]	pinnum	Pin number, should be in range: 0..31
 * @param[in] 	enable: the state of the pin that is expected to run
				- ENABLE: The noise pulses below approximately 10ns are filtered out
				- DISABLE: No input filtering is done.
 * @return 		PINSEL Return Code
 *				- PINSEL_RET_INVALID_PIN
 *				- PINSEL_RET_NOT_SUPPORT
 *				- PINSEL_RET_OK
 **********************************************************************/
PINSEL_RET_CODE PINSEL_SetI2CFilter (uint8_t portnum, uint8_t pinnum, uint8_t enable)
{
	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_I)
		return PINSEL_RET_NOT_SUPPORT;

	pPIN = PIN_GetPointer(portnum, pinnum);


	if(enable)
	{
		*(uint32_t *)pPIN &= ~(IOCON_HS_MASK);//Clear 8th bit to 0
	}
	else
	{
		*(uint32_t *)pPIN |= (IOCON_I2C_FILTER_DISABLE);//Set 8th bit to one
	}


	return PINSEL_RET_OK;
}


/**
 * @}
 */
#endif /*_PINSEL*/

/**
 * @}
 */

/* --------------------------------- End Of File ------------------------------ */

⌨️ 快捷键说明

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