/**
|
******************************************************************************
|
* @file fm33a0xxev_gpio.c
|
* @author FM33A0XXEV Application Team
|
* @version V1.0.0
|
* @date 16-April-2020
|
* @brief This file provides firmware functions to manage the following
|
* functionalities of....:
|
*
|
*/
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "fm33a0xxev_gpio.h"
|
#include "define_all.h"
|
/** @addtogroup fm33a0xxev_StdPeriph_Driver
|
* @{
|
*/
|
|
/** @defgroup GPIO
|
* @brief GPIO driver modules
|
* @{
|
*/
|
|
#ifdef USE_FULL_ASSERT
|
|
/**
|
* @brief The assert_param macro is used for function's parameters check.
|
* @param expr: If expr is false, it calls assert_failed function
|
* which reports the name of the source file and the source
|
* line number of the call that failed.
|
* If expr is true, it returns no value.
|
* @retval None
|
*/
|
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
|
/* Exported functions ------------------------------------------------------- */
|
void assert_failed(uint8_t* file, uint32_t line);
|
#else
|
#define assert_param(expr) ((void)0)
|
#endif /* USE_FULL_ASSERT */
|
|
/********************************
|
PortXÊä³öÊý¾Ý¼Ä´æÆ÷ÅäÖú¯Êý
|
¹¦ÄÜ: ÅäÖÃPortXÊä³öÊý¾Ý
|
ÊäÈ룺GPIOx_Type* GPIOx£¨¹Ü½ÅºÅ£©, uint32_t SetValue£¨Êä³öÖµ£©
|
Êä³ö:ÎÞ
|
********************************/
|
void GPIOx_DO_Write(GPIO_Type* GPIOx, uint32_t SetValue)
|
{
|
GPIOx->DO = (SetValue & GPIOx_DO_DO_Msk);
|
}
|
/********************************
|
¶ÁPortXÊä³öÊý¾Ý״̬º¯Êý
|
¹¦ÄÜ:¶ÁPortXÊä³öÊý¾Ý״̬
|
ÊäÈ룺ÎÞ
|
Êä³ö:PortXÊä³öÖµ
|
********************************/
|
uint32_t GPIOx_DO_Read(GPIO_Type* GPIOx)
|
{
|
return (GPIOx->DO & GPIOx_DO_DO_Msk);
|
}
|
|
/********************************
|
PortXÊä³öÊý¾ÝÖÃλ¼Ä´æÆ÷º¯Êý
|
¹¦ÄÜ:PortXÊä³öÊý¾ÝÖÃ룬ÈçÏòPADSETд0x0000_8000£¬ÔòPADO[15]ÖÃ룬ÆäÓàλ±£³Ö²»±ä¡£
|
ÊäÈ룺GPIOx_Type* GPIOx£¨¹Ü½ÅºÅ£©, uint32_t SetValue£¨Êä³öÖµ£©
|
Êä³ö:ÎÞ
|
********************************/
|
void GPIOx_DSET_Write(GPIO_Type* GPIOx, uint32_t SetValue)
|
{
|
GPIOx->DSET = (SetValue & GPIOx_DSET_DSET_Msk);
|
}
|
|
/********************************
|
PortXÊä³öÊý¾Ý¸´Î»¼Ä´æÆ÷º¯Êý
|
¹¦ÄÜ:PortXÊä³öÊý¾Ý¸´Î»£¬ÈçÏòPADRSTд0x0000_8000£¬ÔòPADO[15]ÇåÁ㣬ÆäÓàλ±£³Ö²»±ä¡£
|
ÊäÈ룺GPIOx_Type* GPIOx£¨¹Ü½ÅºÅ£©, uint32_t SetValue£¨Êä³öÖµ£©
|
Êä³ö:ÎÞ
|
********************************/
|
void GPIOx_DRST_Write(GPIO_Type* GPIOx, uint32_t SetValue)
|
{
|
GPIOx->DRST = (SetValue & GPIOx_DRST_DRESET_Msk);
|
}
|
|
/********************************
|
PortXÊäÈëÊý¾Ý¼Ä´æÆ÷º¯Êý
|
¹¦ÄÜ:PortXÊäÈëÊý¾Ý£¬´Ë¼Ä´æÆ÷½öÕ¼ÓõØÖ·¿Õ¼ä£¬ÎÞÎïÀíʵÏÖ¡£Èí¼þ¶Á´Ë¼Ä´æÆ÷Ö±½Ó·µ»ØÒý½ÅÊäÈëÐźţ¬Ð¾Æ¬²¢²»¶ÔÒý½ÅÊäÈë½øÐÐËø´æ
|
ÊäÈ룺GPIOx_Type* GPIOx£¨¹Ü½ÅºÅ£©, uint32_t SetValue£¨ÊäÈëÖµ£©
|
Êä³ö:ÎÞ
|
********************************/
|
uint32_t GPIOx_DIN_Read(GPIO_Type* GPIOx)
|
{
|
return (GPIOx->DIN & GPIOx_DIN_DIN_Msk);
|
}
|
|
/* PortX¶îÍâÊý×Ö¹¦ÄܼĴæÆ÷ Ïà¹Øº¯Êý */
|
void GPIOx_DFS_Setable(GPIO_Type* GPIOx, uint32_t GPIO_Pin, FunState NewState)
|
{
|
uint32_t tmpreg;
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
|
tmpreg = GPIOx->DFS;
|
if (NewState == ENABLE)
|
{
|
tmpreg |= (GPIO_Pin);
|
}
|
else
|
{
|
tmpreg &= ~(GPIO_Pin);
|
}
|
GPIOx->DFS = tmpreg;
|
}
|
|
FunState GPIOx_DFS_Getable(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
|
if (GPIOx->DFS & GPIO_Pin)
|
{
|
return ENABLE;
|
}
|
else
|
{
|
return DISABLE;
|
}
|
}
|
|
/* PortXÄ£Ä⿪¹ØÊ¹ÄܼĴæÆ÷ Ïà¹Øº¯Êý */
|
void GPIOx_ANEN_Setable(GPIO_Type* GPIOx, uint32_t GPIO_Pin, FunState NewState)
|
{
|
uint32_t tmpreg;
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
|
tmpreg = GPIOx->ANEN;
|
if (NewState == ENABLE)
|
{
|
tmpreg |= (GPIO_Pin);
|
}
|
else
|
{
|
tmpreg &= ~(GPIO_Pin);
|
}
|
GPIOx->ANEN = tmpreg;
|
}
|
|
FunState GPIOx_ANEN_Getable(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
|
if (GPIOx->ANEN & GPIO_Pin)
|
{
|
return ENABLE;
|
}
|
else
|
{
|
return DISABLE;
|
}
|
}
|
|
/********************************
|
GPIO³õʼ»¯ÅäÖú¯Êý
|
¹¦ÄÜ:GPIO³õʼ»¯ÅäÖÃ
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_Init(GPIO_Type* GPIOx, GPIO_InitTypeDef* para)
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00,currentpin =0x00;
|
uint32_t tmpreg;
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
|
for (pinpos = 0; pinpos < 16; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) << pinpos;
|
currentpin = (para->Pin) & pinbit;
|
|
if (currentpin == pinbit)
|
{
|
tmpreg = GPIOx->INEN;
|
tmpreg &= ~pinbit;
|
tmpreg |= (para->PxINEN) << pinpos;
|
GPIOx->INEN = tmpreg;
|
|
tmpreg = GPIOx->PUEN;
|
tmpreg &= ~pinbit;
|
tmpreg |= (para->PxPUEN) << pinpos;
|
GPIOx->PUEN = tmpreg;
|
|
tmpreg = GPIOx->ODEN;
|
tmpreg &= ~pinbit;
|
tmpreg |= (para->PxODEN) << pinpos;
|
GPIOx->ODEN = tmpreg;
|
|
pinbit = (((uint32_t)0x00000003)) << (pinpos*2);
|
tmpreg = GPIOx->FCR;
|
tmpreg &= ~pinbit;
|
tmpreg |= (para->PxFCR)<<(pinpos*2);
|
GPIOx->FCR = tmpreg;
|
}
|
}
|
}
|
|
/* »ñȡһ¸öIO¿ÚµÄÅäÖòÎÊý½á¹¹Ìå
|
×¢ÒâÒ»´ÎÖ»ÄܶÁȡһ¸öIOµÄÅäÖÃ
|
*/
|
/********************************
|
»ñȡһ¸öIOÅäÖòÎÊý½á¹¹Ì庯Êý
|
¹¦ÄÜ:»ñȡһ¸öIOÅäÖòÎÊý½á¹¹Ìå
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å Òý½ÅÀàÐÍ
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_Get_InitPara(GPIO_Type* GPIOx, uint32_t GPIO_Pin, GPIO_InitTypeDef* para)
|
{
|
uint32_t pinbit = 0x00;
|
uint32_t i,temp;
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
|
for (i = 0; i < 16; i++)
|
{
|
pinbit = GPIO_Pin & (1<<i);
|
if(pinbit > 0) break;
|
}
|
|
if(i < 16)
|
{
|
pinbit = i;
|
para->Pin = GPIO_Pin;
|
|
temp = (GPIOx->INEN&GPIO_Pin)>>pinbit;
|
if(temp == (uint32_t)GPIO_IN_En)
|
{
|
para->PxINEN = GPIO_IN_En;
|
}
|
else
|
{
|
para->PxINEN = GPIO_IN_Dis;
|
}
|
|
temp = (GPIOx->PUEN&GPIO_Pin)>>pinbit;
|
if(temp == (uint32_t)GPIO_PU_En)
|
{
|
para->PxPUEN = GPIO_PU_En;
|
}
|
else
|
{
|
para->PxPUEN = GPIO_PU_Dis;
|
}
|
|
temp = (GPIOx->ODEN&GPIO_Pin)>>pinbit;
|
if(temp == (uint32_t)GPIO_OD_En)
|
{
|
para->PxODEN = GPIO_OD_En;
|
}
|
else
|
{
|
para->PxODEN = GPIO_OD_Dis;
|
}
|
|
temp = (GPIOx->FCR>>(pinbit*2))&0x00000003;
|
if(temp == (uint32_t)GPIO_FCR_IN)
|
{
|
para->PxFCR = GPIO_FCR_IN;
|
}
|
else if(temp == (uint32_t)GPIO_FCR_OUT)
|
{
|
para->PxFCR = GPIO_FCR_OUT;
|
}
|
else if(temp == (uint32_t)GPIO_FCR_DIG)
|
{
|
para->PxFCR = GPIO_FCR_DIG;
|
}
|
else
|
{
|
para->PxFCR = GPIO_FCR_ANA;
|
}
|
}
|
}
|
|
/********************************
|
¶ÁÈ¡GPIOxÊäÈëÊý¾Ý¼Ä´æÆ÷º¯Êý
|
¹¦ÄÜ:¶ÁÈ¡GPIOxÊäÈëÊý¾Ý¼Ä´æÆ÷
|
ÊäÈ룺GPIOx_PINÒý½Å
|
Êä³ö: Êý¾Ý¼Ä´æÆ÷Öµ
|
********************************/
|
uint32_t GPIO_ReadInputData(GPIO_Type* GPIOx)
|
{
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
return (GPIOx->DIN);
|
}
|
|
/********************************
|
¶ÁÈ¡GPIOxÊäÈëÊý¾Ý¼Ä´æÆ÷bitº¯Êý
|
¹¦ÄÜ:GPIOxÊäÈëÊý¾Ý¼Ä´æÆ÷bit
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: bit״̬
|
********************************/
|
uint8_t GPIO_ReadInputDataBit(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
uint8_t bitstatus = 0x00;
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
|
if ((GPIOx->DIN & GPIO_Pin) != (uint32_t)Bit_RESET)
|
{
|
bitstatus = (uint8_t)Bit_SET;
|
}
|
else
|
{
|
bitstatus = (uint8_t)Bit_RESET;
|
}
|
return bitstatus;
|
}
|
|
/********************************
|
GPIOxÊä³öÖÃ1º¯Êý
|
¹¦ÄÜ: GPIOxÊä³öÖÃ1
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_SetBits(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
GPIOx->DSET = GPIO_Pin;
|
}
|
|
/********************************
|
GPIOxÊä³öÖÃ0º¯Êý
|
¹¦ÄÜ: GPIOxÊä³öÖÃ0
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_ResetBits(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
GPIOx->DRST = GPIO_Pin;
|
}
|
|
/********************************
|
GPIOxÊä³ö·×ªº¯Êý
|
¹¦ÄÜ: GPIOxÊä³öÖÃ0
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_ToggleBits(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
if(GPIO_Pin&GPIOx->DO)
|
{
|
GPIOx->DRST = GPIO_Pin;
|
}
|
else
|
{
|
GPIOx->DSET = GPIO_Pin;
|
}
|
}
|
|
/********************************
|
GPIOHÊä³öÖÃ1º¯Êý
|
¹¦ÄÜ: GPIOHÊä³öÖÃ1
|
ÊäÈ룺GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
********************************/
|
void GPIOH_SetBits(uint32_t GPIO_Pin)
|
{
|
GPIOH->DO |= GPIO_Pin;
|
}
|
|
/********************************
|
GPIOHÊä³öÖÃ0º¯Êý
|
¹¦ÄÜ: GPIOHÊä³öÖÃ0
|
ÊäÈ룺GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
********************************/
|
void GPIOH_ResetBits(uint32_t GPIO_Pin)
|
{
|
GPIOH->DO &= ~GPIO_Pin;
|
}
|
|
/********************************
|
GPIOHÊä³ö·×ªº¯Êý
|
¹¦ÄÜ: GPIOxÊä³öÖÃ0
|
ÊäÈ룺GPIOH¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
********************************/
|
void GPIOH_ToggleBits(uint32_t GPIO_Pin)
|
{
|
if(GPIO_Pin&GPIOH->DO)
|
{
|
GPIOH->DO &= ~GPIO_Pin;
|
}
|
else
|
{
|
GPIOH->DO |= GPIO_Pin;
|
}
|
}
|
|
/********************************
|
¶ÁÈ¡GPIOxÊä³öÊý¾Ý¼Ä´æÆ÷º¯Êý
|
¹¦ÄÜ:¶ÁÈ¡GPIOxÊä³öÊý¾Ý¼Ä´æÆ÷
|
ÊäÈ룺GPIOx_PINÒý½Å
|
Êä³ö: Êý¾Ý¼Ä´æÆ÷Öµ
|
********************************/
|
uint32_t GPIO_ReadOutputData(GPIO_Type* GPIOx)
|
{
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
|
return (GPIOx->DO);
|
}
|
|
/********************************
|
¶ÁÈ¡GPIOxÊä³öÊý¾Ý¼Ä´æÆ÷bitº¯Êý
|
¹¦ÄÜ:GPIOxÊä³öÊý¾Ý¼Ä´æÆ÷bit
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: bit״̬
|
********************************/
|
uint8_t GPIO_ReadOutputDataBit(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
uint8_t bitstatus = 0x00;
|
|
assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
|
assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
|
|
if (((GPIOx->DO) & GPIO_Pin) != (uint32_t)Bit_RESET)
|
{
|
bitstatus = (uint8_t)Bit_SET;
|
}
|
else
|
{
|
bitstatus = (uint8_t)Bit_RESET;
|
}
|
return bitstatus;
|
}
|
|
/********************************
|
WKUPÒý½ÅÅäÖú¯Êý
|
¹¦ÄÜ£ºWKUPÒý½ÅÅäÖÃ
|
ÊäÈ룺WKUP GPIO_PINÒý½Å
|
ENABLE ʹÄÜWKUP¹¦ÄÜ
|
DISABLE ¹Ø±ÕWKUP¹¦ÄÜ
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_PINWKEN_SetableEx(uint32_t NWKPinDef, FunState NewState)
|
{
|
if (NewState == ENABLE)
|
{
|
GPIO->PINWKEN |= (1 << NWKPinDef);
|
}
|
else
|
{
|
GPIO->PINWKEN &= ~ (1 << NWKPinDef);
|
}
|
}
|
|
FunState GPIO_PINWKEN_GetableEx(uint32_t NWKPinDef)
|
{
|
if (GPIO->PINWKEN & (1 << NWKPinDef))
|
{
|
return ENABLE;
|
}
|
else
|
{
|
return DISABLE;
|
}
|
}
|
|
|
|
/********************************
|
ÉèÖà WKUP±ßÑØÑ¡Ôñº¯Êý
|
¹¦ÄÜ£WWKUP±ßÑØÑ¡Ôñ
|
ÊäÈ룺WKUP GPIO_PINÒý½Å
|
SetValue£ºGPIO_PINWKEN_PINWKSEL_FALLING ¶ÔÓ¦µÄWKUPÒý½ÅΪϽµÑØ»½ÐÑ
|
SetValue£ºGPIO_PINWKEN_PINWKSEL_RISING ¶ÔÓ¦µÄWKUPÒý½ÅΪÉÏÉýÑØ»½ÐÑ
|
SetValue£ºGPIO_PINWKEN_PINWKSEL_BOTH ¶ÔÓ¦µÄWKUPÒý½ÅΪÉÏÉý¡¢Ï½µÑØ»½ÐÑ
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_PINWKSEL_SetEx(uint32_t NWKPinDef, uint32_t SetValue)
|
{
|
uint32_t tmpreg;
|
uint32_t postion;
|
postion = NWKPinDef * 2 + 8;
|
tmpreg = GPIO->PINWKEN;
|
tmpreg &= ~(3 << postion);
|
tmpreg |= ((SetValue << postion) & GPIO_PINWKEN_PINWKSEL_Msk);
|
GPIO->PINWKEN = tmpreg;
|
}
|
|
/********************************
|
¶ÁÈ¡ WKUP±ßÑØÑ¡Ôñº¯Êý
|
¹¦ÄÜ£WWKUP±ßÑØÑ¡Ôñ
|
ÊäÈ룺WKUP GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
·µ»ØÖµ£º GPIO_PINWKEN_PINWKSEL_FALLING ¶ÔÓ¦µÄWKUPÒý½ÅΪϽµÑØ»½ÐÑ
|
GPIO_PINWKEN_PINWKSEL_RISING ¶ÔÓ¦µÄWKUPÒý½ÅΪÉÏÉýÑØ»½ÐÑ
|
GPIO_PINWKEN_PINWKSEL_BOTH ¶ÔÓ¦µÄWKUPÒý½ÅΪÉÏÉý¡¢Ï½µÑØ»½ÐÑ
|
********************************/
|
uint32_t GPIO_PINWKSEL_GetEx(uint32_t NWKPinDef)
|
{
|
uint32_t postion;
|
postion = NWKPinDef * 2 + 8;
|
return (((GPIO->PINWKEN & (3 << postion)) & GPIO_PINWKEN_PINWKSEL_Msk) >> postion);
|
}
|
|
|
/********************************
|
WKUPÖжÏÈë¿ÚÑ¡Ôñº¯Êý
|
¹¦ÄÜ£WWKUPÖжÏÈë¿ÚÑ¡Ôñ
|
ÊäÈ룺GPIO_PINWKEN_WKISEL_NMI: NMIÖжÏ
|
GPIO_PINWKEN_WKISEL_46£º#46ÖжÏ
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIO_PINWKEN_WKISEL_Set(uint32_t SetValue)
|
{
|
uint32_t tmpreg;
|
tmpreg = GPIO->PINWKEN;
|
tmpreg &= ~(GPIO_PINWKEN_WKISEL_Msk);
|
tmpreg |= (SetValue & GPIO_PINWKEN_WKISEL_Msk);
|
GPIO->PINWKEN = tmpreg;
|
}
|
/********************************
|
¶ÁÈ¡WKUPÖжÏÈë¿ÚÑ¡Ôñº¯Êý
|
¹¦ÄÜ£º¶ÁÈ¡WKUPÖжÏÈë¿ÚÑ¡Ôñ
|
ÊäÈ룺ÎÞ
|
Êä³ö: GPIO_PINWKEN_WKISEL_NMI: NMIÖжÏ
|
GPIO_PINWKEN_WKISEL_46£º#46ÖжÏ
|
********************************/
|
uint32_t GPIO_PINWKEN_WKISEL_Get(void)
|
{
|
return (GPIO->PINWKEN & GPIO_PINWKEN_WKISEL_Msk);
|
}
|
|
/*************************************************************************
|
º¯ÊýÃû³Æ£ºGPIO_EXTI_Select_Pin
|
¹¦ÄÜ˵Ã÷£ºGPIO EXTI ÍⲿÒý½ÅÑ¡Ôñ
|
ÊäÈë²ÎÊý£ºGPIOx ¶Ë¿Ú GPIO_Pinpin ¶Ë¿ÚÄÚÒý½Å
|
Êä³ö²ÎÊý£ºÎÞ
|
·µ»Ø²ÎÊý£wÎÞ
|
*************************************************************************/
|
void GPIO_EXTI_Select_Pin(GPIO_Type* GPIOx,uint32_t GPIO_Pin)
|
{
|
uint32_t pin_num = 0,i;
|
uint32_t pin_shift;
|
uint32_t tmpreg;
|
|
for(i= 0;i<16;i++)
|
{
|
if(GPIO_Pin&(1<<i))
|
{
|
pin_num = i;
|
break;
|
}
|
}
|
|
if(i == 16) return;
|
|
switch((uint32_t)GPIOx)
|
{
|
case (uint32_t)GPIOE://
|
case (uint32_t)GPIOF://
|
if(pin_num > 11) break;
|
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 2;
|
}
|
else
|
{
|
pin_shift = 4;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOF)
|
{
|
pin_shift += 8;
|
}
|
pin_num = pin_num % 4;
|
tmpreg = GPIO->EXTISEL1;
|
tmpreg &= (~(0x00000003 << pin_shift));
|
tmpreg |= (pin_num << pin_shift);
|
GPIO->EXTISEL1 = tmpreg;
|
break;
|
|
case (uint32_t)GPIOA://
|
case (uint32_t)GPIOB://
|
case (uint32_t)GPIOC://
|
case (uint32_t)GPIOD://
|
if(((uint32_t)GPIOx == (uint32_t)GPIOA) ||((uint32_t)GPIOx == (uint32_t)GPIOB)||((uint32_t)GPIOx == (uint32_t)GPIOC))
|
if(pin_num > 15) break;
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOD)
|
if(pin_num > 11) break;
|
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 2;
|
}
|
else if((pin_num >= 8)&&(pin_num <= 11))
|
{
|
pin_shift = 4;
|
}
|
else
|
{
|
pin_shift = 6;
|
}
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOB)
|
{
|
pin_shift += 8;
|
}
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOC)
|
{
|
pin_shift += 16;
|
}
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOD)
|
{
|
pin_shift += 24;
|
}
|
|
pin_num = pin_num % 4;
|
tmpreg = GPIO->EXTISEL0;
|
tmpreg &= (~(0x00000003 << pin_shift));
|
tmpreg |= (pin_num << pin_shift);
|
GPIO->EXTISEL0 = tmpreg;
|
break;
|
default:
|
break;
|
}
|
}
|
/*************************************************************************
|
º¯ÊýÃû³Æ£ºGPIO_EXTI_Select_Edge
|
¹¦ÄÜ˵Ã÷£ºGPIO EXTI_Select_Edge ÍⲿÖжϱßÑØÑ¡Ôñ
|
ÊäÈë²ÎÊý£ºGPIOx ¶Ë¿Ú £¬GPIO_Pin ¶Ë¿ÚÄÚÒý½Å ,edge_select ´¥·¢ÑØ
|
Êä³ö²ÎÊý£ºÎÞ
|
·µ»Ø²ÎÊý£wÎÞ
|
*************************************************************************/
|
void GPIO_EXTI_Select_Edge(GPIO_Type* GPIOx,uint32_t GPIO_Pin,GPIOExtiEdge edge_select)
|
{
|
uint32_t pin_num = 0,i;
|
uint32_t pin_shift;
|
uint32_t tmpreg;
|
for(i= 0;i<16;i++)
|
{
|
if(GPIO_Pin&(1<<i))
|
{
|
pin_num = i;
|
break;
|
}
|
}
|
if(i == 16) return;
|
|
switch((uint32_t)GPIOx)
|
{
|
case (uint32_t)GPIOA:
|
case (uint32_t)GPIOB:
|
case (uint32_t)GPIOC:
|
case (uint32_t)GPIOD:
|
if(pin_num > 15) break;
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 2;
|
}
|
else if((pin_num >= 8)&&(pin_num <= 11))
|
{
|
pin_shift = 4;
|
}
|
else
|
{
|
pin_shift = 6;
|
}
|
|
if(((uint32_t)GPIOx == (uint32_t)GPIOB))
|
{
|
pin_shift += 8;
|
}
|
|
if(((uint32_t)GPIOx == (uint32_t)GPIOC))
|
{
|
pin_shift += 16;
|
}
|
|
if(((uint32_t)GPIOx == (uint32_t)GPIOD))
|
{
|
pin_shift += 24;
|
}
|
tmpreg = GPIO->EXTIEDS0;
|
tmpreg &= (~(0x00000003 << pin_shift));
|
tmpreg |= (edge_select << pin_shift);
|
GPIO->EXTIEDS0 = tmpreg;
|
break;
|
|
case (uint32_t)GPIOE:
|
case (uint32_t)GPIOF:
|
if(pin_num > 11) break;
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 2;
|
}
|
else
|
{
|
pin_shift = 4;
|
}
|
|
if(((uint32_t)GPIOx == (uint32_t)GPIOF))
|
{
|
pin_shift += 8;
|
}
|
tmpreg = GPIO->EXTIEDS1;
|
tmpreg &= (~(0x00000003 << pin_shift));
|
tmpreg |= (edge_select << pin_shift);
|
GPIO->EXTIEDS1 = tmpreg;
|
default:
|
break;
|
}
|
}
|
|
/* EXTIÊý×ÖÂ˲¨¿ØÖƼĴæÆ÷ Ïà¹Øº¯Êý */
|
void GPIO_EXTI_EXTIDF_Setable(GPIO_Type* GPIOx, uint32_t GPIO_Pin, FunState NewState)
|
{
|
uint32_t pin_num = 0,i;
|
uint32_t pin_shift;
|
uint32_t tmpreg;
|
for(i= 0;i<16;i++)
|
{
|
if(GPIO_Pin&(1<<i))
|
{
|
pin_num = i;
|
break;
|
}
|
}
|
if(i == 16) return;
|
|
switch((uint32_t)GPIOx)
|
{
|
case (uint32_t)GPIOA:
|
case (uint32_t)GPIOB:
|
case (uint32_t)GPIOC:
|
case (uint32_t)GPIOD:
|
case (uint32_t)GPIOE:
|
case (uint32_t)GPIOF:
|
if(((uint32_t)GPIOx == (uint32_t)GPIOE) || ((uint32_t)GPIOx == (uint32_t)GPIOF))
|
{
|
if(pin_num > 11) break;
|
}
|
else
|
{
|
if(pin_num > 15) break;
|
}
|
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 1;
|
}
|
else if((pin_num >= 8)&&(pin_num <= 11))
|
{
|
pin_shift = 2;
|
}
|
else
|
{
|
pin_shift = 3;
|
}
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOB)
|
{
|
pin_shift += 4;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOC)
|
{
|
pin_shift += 8;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOD)
|
{
|
pin_shift += 12;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOE)
|
{
|
pin_shift += 16;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOF)
|
{
|
pin_shift += 20;
|
}
|
|
tmpreg = GPIO->EXTIDF;
|
if(NewState == ENABLE)
|
{
|
tmpreg |= 1 << pin_shift;
|
}
|
else
|
{
|
tmpreg &= (~(1 << pin_shift));
|
}
|
GPIO->EXTIDF = tmpreg;
|
break;
|
|
default:
|
break;
|
}
|
|
}
|
|
/* ¶ÁÈ¡EXTIÊäÈëÐźżĴæÆ÷ */
|
FunState GPIO_EXTI_EXTIDI_Getable(GPIO_Type* GPIOx, uint32_t GPIO_Pin)
|
{
|
uint32_t pin_num = 0,i;
|
uint32_t pin_shift;
|
FunState Result = DISABLE;
|
for(i= 0;i<16;i++)
|
{
|
if(GPIO_Pin&(1<<i))
|
{
|
pin_num = i;
|
break;
|
}
|
}
|
|
if(i == 16) return Result;
|
|
switch((uint32_t)GPIOx)
|
{
|
case (uint32_t)GPIOA:
|
case (uint32_t)GPIOB:
|
case (uint32_t)GPIOC:
|
case (uint32_t)GPIOD:
|
case (uint32_t)GPIOE:
|
case (uint32_t)GPIOF:
|
if(((uint32_t)GPIOx == (uint32_t)GPIOE) || ((uint32_t)GPIOx == (uint32_t)GPIOF))
|
{
|
if(pin_num > 11) break;
|
}
|
else
|
{
|
if(pin_num > 15) break;
|
}
|
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 1;
|
}
|
else if((pin_num >= 8)&&(pin_num <= 11))
|
{
|
pin_shift = 2;
|
}
|
else
|
{
|
pin_shift = 3;
|
}
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOB)
|
{
|
pin_shift += 4;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOC)
|
{
|
pin_shift += 8;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOD)
|
{
|
pin_shift += 12;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOE)
|
{
|
pin_shift += 16;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOF)
|
{
|
pin_shift += 20;
|
}
|
|
if((GPIO->EXTIDI & (1 << pin_shift)) == (1 << pin_shift))
|
{
|
Result = ENABLE;
|
}
|
else
|
{
|
Result = DISABLE;
|
}
|
break;
|
default:
|
break;
|
}
|
|
return Result;
|
}
|
|
/*************************************************************************
|
º¯ÊýÃû³Æ£ºGPIO_EXTI_EXTIISR_ClrEx
|
¹¦ÄÜ˵Ã÷£ºGPIO_EXTI_EXTIISR_ClrEx Çå³ýÖжϱêÖ¾
|
ÊäÈë²ÎÊý£ºGPIOx ¶Ë¿Ú £¬GPIO_Pin ¶Ë¿ÚÄÚÒý½Å
|
Êä³ö²ÎÊý£ºÎÞ
|
·µ»Ø²ÎÊý£wÎÞ
|
*************************************************************************/
|
void GPIO_EXTI_EXTIISR_ClrEx(GPIO_Type* GPIOx,uint32_t GPIO_Pin)
|
{
|
uint32_t pin_num = 0,i;
|
uint32_t pin_shift;
|
uint32_t tmpreg;
|
for(i= 0;i<16;i++)
|
{
|
if(GPIO_Pin&(1<<i))
|
{
|
pin_num = i;
|
break;
|
}
|
}
|
|
if(i == 16) return ;
|
|
switch((uint32_t)GPIOx)
|
{
|
case (uint32_t)GPIOA:
|
case (uint32_t)GPIOB:
|
case (uint32_t)GPIOC:
|
case (uint32_t)GPIOD:
|
case (uint32_t)GPIOE:
|
case (uint32_t)GPIOF:
|
if(((uint32_t)GPIOx == (uint32_t)GPIOE) || ((uint32_t)GPIOx == (uint32_t)GPIOF))
|
{
|
if(pin_num > 11) break;
|
}
|
else
|
{
|
if(pin_num > 15) break;
|
}
|
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 1;
|
}
|
else if((pin_num >= 8)&&(pin_num <= 11))
|
{
|
pin_shift = 2;
|
}
|
else
|
{
|
pin_shift = 3;
|
}
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOB)
|
{
|
pin_shift += 4;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOC)
|
{
|
pin_shift += 8;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOD)
|
{
|
pin_shift += 12;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOE)
|
{
|
pin_shift += 16;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOF)
|
{
|
pin_shift += 20;
|
}
|
|
tmpreg = GPIO->EXTIISR;
|
// tmpreg |= (1 << pin_shift);
|
tmpreg &= (1 << pin_shift); //20240131 SiZhu_YeÐÞ¸Ä
|
GPIO->EXTIISR = tmpreg;
|
break;
|
|
default:
|
break;
|
}
|
}
|
|
/*************************************************************************
|
º¯ÊýÃû³Æ£ºGPIO_EXTI_EXTIISR_ChkEx
|
¹¦ÄÜ˵Ã÷£ºGPIO_EXTI_EXTIISR_ChkEx ¶ÁÈ¡Öжϱê־״̬
|
ÊäÈë²ÎÊý£ºGPIOx ¶Ë¿Ú £¬GPIO_Pin ¶Ë¿ÚÄÚÒý½Å
|
Êä³ö²ÎÊý£ºÎÞ
|
·µ»Ø²ÎÊý£wFlagStatus Öжϱê־״̬
|
*************************************************************************/
|
FlagStatus GPIO_EXTI_EXTIISR_ChkEx(GPIO_Type* GPIOx,uint32_t GPIO_Pin)
|
{
|
uint32_t pin_num = 0,i;
|
uint32_t pin_shift;
|
FlagStatus Result = RESET;
|
|
for(i= 0;i<16;i++)
|
{
|
if(GPIO_Pin&(1<<i))
|
{
|
pin_num = i;
|
break;
|
}
|
}
|
|
if(i == 16) return Result;
|
|
switch((uint32_t)GPIOx)
|
{
|
case (uint32_t)GPIOA:
|
case (uint32_t)GPIOB:
|
case (uint32_t)GPIOC:
|
case (uint32_t)GPIOD:
|
case (uint32_t)GPIOE:
|
case (uint32_t)GPIOF:
|
if(((uint32_t)GPIOx == (uint32_t)GPIOE) || ((uint32_t)GPIOx == (uint32_t)GPIOF))
|
{
|
if(pin_num > 11) break;
|
}
|
else
|
{
|
if(pin_num > 15) break;
|
}
|
|
if((pin_num <= 3))//
|
{
|
pin_shift = 0;
|
}
|
else if((pin_num >= 4)&&(pin_num <= 7))
|
{
|
pin_shift = 1;
|
}
|
else if((pin_num >= 8)&&(pin_num <= 11))
|
{
|
pin_shift = 2;
|
}
|
else
|
{
|
pin_shift = 3;
|
}
|
|
if((uint32_t)GPIOx == (uint32_t)GPIOB)
|
{
|
pin_shift += 4;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOC)
|
{
|
pin_shift += 8;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOD)
|
{
|
pin_shift += 12;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOE)
|
{
|
pin_shift += 16;
|
}
|
if((uint32_t)GPIOx == (uint32_t)GPIOF)
|
{
|
pin_shift += 20;
|
}
|
if((GPIO->EXTIISR & (1 << pin_shift)) == (1 << pin_shift)) Result = SET;
|
break;
|
default:
|
break;
|
}
|
|
return Result;
|
}
|
|
/********************************
|
FOUT1Êä³öÅäÖú¯Êý
|
¹¦ÄÜ: ÅäÖÃFOUT1Êä³ö
|
ÊäÈ룺Êä³öƵÂÊÑ¡ÔñÐźÅ
|
Êä³ö:ÎÞ
|
********************************/
|
void GPIO_FOUTSEL_FOUT1SEL_Set(uint32_t SetValue)
|
{
|
uint32_t tmpreg;
|
tmpreg = GPIO->FOUTSEL;
|
tmpreg &= ~(GPIO_FOUTSEL_FOUT1SEL_Msk);
|
tmpreg |= (SetValue & GPIO_FOUTSEL_FOUT1SEL_Msk);
|
GPIO->FOUTSEL = tmpreg;
|
}
|
/********************************
|
¶ÁFOUT1Êä³ö״̬º¯Êý
|
¹¦ÄÜ:¶ÁFOUT1Êä³ö״̬
|
ÊäÈ룺ÎÞ
|
Êä³ö:FOUTÊä³öÑ¡ÔñÖµ
|
********************************/
|
uint32_t GPIO_FOUTSEL_FOUT1SEL_Get(void)
|
{
|
return (GPIO->FOUTSEL & GPIO_FOUTSEL_FOUT1SEL_Msk);
|
}
|
|
/********************************
|
FOUT0Êä³öÅäÖú¯Êý
|
¹¦ÄÜ: ÅäÖÃFOUT0Êä³ö
|
ÊäÈ룺Êä³öƵÂÊÑ¡ÔñÐźÅ
|
Êä³ö:ÎÞ
|
********************************/
|
void GPIO_FOUTSEL_FOUT0SEL_Set(uint32_t SetValue)
|
{
|
uint32_t tmpreg;
|
tmpreg = GPIO->FOUTSEL;
|
tmpreg &= ~(GPIO_FOUTSEL_FOUT0SEL_Msk);
|
tmpreg |= (SetValue & GPIO_FOUTSEL_FOUT0SEL_Msk);
|
GPIO->FOUTSEL = tmpreg;
|
}
|
/********************************
|
¶ÁFOUT0Êä³ö״̬º¯Êý
|
¹¦ÄÜ:¶ÁFOUT0Êä³ö״̬
|
ÊäÈ룺ÎÞ
|
Êä³ö:FOUTÊä³öÑ¡ÔñÖµ
|
********************************/
|
uint32_t GPIO_FOUTSEL_FOUT0SEL_Get(void)
|
{
|
return (GPIO->FOUTSEL & GPIO_FOUTSEL_FOUT0SEL_Msk);
|
}
|
|
|
/*************************************************************************
|
º¯ÊýÃû³Æ£ºGPIO_EXTI_Init
|
¹¦ÄÜ˵Ã÷£ºGPIO_EXTI_Init ÍⲿÖжϳõʼ»¯
|
ÊäÈë²ÎÊý£ºport ¶Ë¿Ú £¬pin ¶Ë¿ÚÄÚÒý½Å ,edge ´¥·¢ÑØ
|
Êä³ö²ÎÊý£ºÎÞ
|
·µ»Ø²ÎÊý£wÎÞ
|
*************************************************************************/
|
void GPIO_EXTI_Init(GPIO_Type* GPIOx, uint32_t GPIO_Pin, GPIOExtiEdge edge_select, FunState DFState)
|
{
|
GPIO_EXTI_Select_Edge(GPIOx, GPIO_Pin, EXTIDISABLE); //¹Ø±Õ±ßÑØ´¥·¢
|
GPIO_EXTI_Select_Pin(GPIOx, GPIO_Pin); //ÍⲿÒý½ÅÑ¡Ôñ
|
GPIO_EXTI_EXTIDF_Setable(GPIOx, GPIO_Pin, DFState); //Êý×ÖÂ˲¨Ê¹ÄÜÑ¡Ôñ
|
GPIO_EXTI_Select_Edge(GPIOx, GPIO_Pin, edge_select); //Ð޸ıßÑØÑ¡Ôñ
|
delay_us(200); //µÈ´ýÖÁÉÙ4¸ölsclk
|
GPIO_EXTI_EXTIISR_ClrEx(GPIOx, GPIO_Pin); //Çå³ýÖжϱêÖ¾
|
NVIC_ClearPendingIRQ(GPIO_IRQn); //Çå³ýÖÐ¶Ï¹ÒÆð
|
}
|
|
/*************************************************************************
|
º¯ÊýÃû³Æ£ºGPIO_EXTI_Close
|
¹¦ÄÜ˵Ã÷£ºGPIO_EXTI_Close ÍⲿÖжϹرÕ
|
ÊäÈë²ÎÊý£ºport ¶Ë¿Ú £¬pin ¶Ë¿ÚÄÚÒý½Å
|
Êä³ö²ÎÊý£ºÎÞ
|
·µ»Ø²ÎÊý£wÎÞ
|
*************************************************************************/
|
void GPIO_EXTI_Close(GPIO_Type* GPIOx,uint32_t GPIO_Pin)
|
{
|
GPIO_EXTI_Select_Edge(GPIOx, GPIO_Pin, EXTIDISABLE);//¹Ø±Õ±ßÑØ´¥·¢
|
}
|
|
|
/********************************
|
GPIOH³õʼ»¯ÅäÖú¯Êý
|
¹¦ÄÜ:GPIO³õʼ»¯ÅäÖÃ
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIOH_Init(GPIO_InitTypeDef* para)
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00,currentpin =0x00;
|
uint32_t tmpreg;
|
|
for (pinpos = 0; pinpos < 4; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) <<pinpos;
|
currentpin = (para->Pin) & pinbit;
|
|
if (currentpin == pinbit)
|
{
|
tmpreg = GPIOH->INEN;
|
tmpreg &= ~pinbit;
|
tmpreg |= (para->PxINEN)<<pinpos;
|
GPIOH->INEN = tmpreg;
|
|
tmpreg = GPIOH->PUEN;
|
tmpreg &= ~pinbit;
|
tmpreg |= (para->PxPUEN)<<pinpos;
|
GPIOH->PUEN = tmpreg;
|
|
pinbit = (((uint32_t)0x00000003)) <<(pinpos*2);
|
tmpreg = GPIOH->FCR;
|
tmpreg &= ~pinbit;
|
tmpreg |= (para->PxFCR)<<(pinpos*2);
|
GPIOH->FCR = tmpreg;
|
}
|
}
|
}
|
|
/********************************
|
»ñȡһ¸öIOÅäÖòÎÊý½á¹¹Ì庯Êý
|
¹¦ÄÜ:»ñȡһ¸öIOÅäÖòÎÊý½á¹¹Ìå
|
ÊäÈ룺GPIO¶Ë¿Ú GPIO_PINÒý½Å Òý½ÅÀàÐÍ
|
Êä³ö: ÎÞ
|
********************************/
|
void GPIOH_Get_InitPara(uint32_t GPIO_Pin, GPIO_InitTypeDef* para)
|
{
|
uint32_t pinbit = 0x00;
|
uint32_t i,temp;
|
|
assert_param(IS_GET_GPIOH_PIN(GPIO_Pin));
|
for (i = 0; i < 4; i++)
|
{
|
pinbit = GPIO_Pin & (1<<i);
|
if(pinbit > 0) break;
|
}
|
|
if(i < 4)
|
{
|
pinbit = i;
|
para->Pin = GPIO_Pin;
|
|
temp = (GPIOH->INEN&GPIO_Pin)>>pinbit;
|
if(temp == (uint32_t)GPIO_IN_En)
|
{
|
para->PxINEN = GPIO_IN_En;
|
}
|
else
|
{
|
para->PxINEN = GPIO_IN_Dis;
|
}
|
|
temp = (GPIOH->PUEN&GPIO_Pin)>>pinbit;
|
if(temp == (uint32_t)GPIO_PU_En)
|
{
|
para->PxPUEN = GPIO_PU_En;
|
}
|
else
|
{
|
para->PxPUEN = GPIO_PU_Dis;
|
}
|
|
temp = (GPIOH->FCR>>(pinbit*2))&0x00000003;
|
if(temp == (uint32_t)GPIO_FCR_IN)
|
{
|
para->PxFCR = GPIO_FCR_IN;
|
}
|
else if(temp == (uint32_t)GPIO_FCR_OUT)
|
{
|
para->PxFCR = GPIO_FCR_OUT;
|
}
|
else if(temp == (uint32_t)GPIO_FCR_DIG)
|
{
|
para->PxFCR = GPIO_FCR_DIG;
|
}
|
else
|
{
|
para->PxFCR = GPIO_FCR_ANA;
|
}
|
}
|
}
|
|
/********************************
|
PortHÊä³öÊý¾Ý¼Ä´æÆ÷ÅäÖú¯Êý
|
¹¦ÄÜ: ÅäÖÃPortHÊä³öÊý¾Ý
|
ÊäÈ룺uint32_t SetValue£¨Êä³öÖµ£©
|
Êä³ö:ÎÞ
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
********************************/
|
void GPIOH_DO_Write(uint32_t SetValue)
|
{
|
GPIOH->DO = (SetValue & GPIOH_DO_PHDO_Msk);
|
}
|
/*
|
¶ÁÈ¡GPIOHÊä³ö¼Ä´æÆ÷
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
*/
|
uint32_t GPIOH_ReadOutputData(void)
|
{
|
return (GPIOH->DO & GPIOH_DO_PHDO_Msk);
|
}
|
|
/*
|
°´¹Ü½ÅPin¶ÁÈ¡Êä³ö¼Ä´æÆ÷
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
*/
|
uint8_t GPIOH_ReadOutputDataBit(uint32_t GPIO_Pin)
|
{
|
uint8_t bitstatus = 0x00;
|
assert_param(IS_GET_GPIOH_PIN(GPIO_Pin));
|
if ((GPIOH->DO & GPIO_Pin) != (uint32_t)Bit_RESET)
|
{
|
bitstatus = (uint8_t)Bit_SET;
|
}
|
else
|
{
|
bitstatus = (uint8_t)Bit_RESET;
|
}
|
return bitstatus;
|
}
|
|
/*
|
¶ÁÈ¡GPIOHÊäÈë¼Ä´æÆ÷
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
*/
|
uint32_t GPIOH_ReadInputData(void)
|
{
|
return (GPIOH->DIN & GPIOH_DIN_PHDIN_Msk);
|
}
|
|
/*
|
°´¹Ü½ÅPin¶ÁÈ¡ÊäÈë¼Ä´æÆ÷
|
Note:²Ù×÷GPIOHÐè´ò¿ªCDIF(CDIF_CR_INTF_EN_Setable(ENABLE);)
|
*/
|
uint8_t GPIOH_ReadInputDataBit(uint32_t GPIO_Pin)
|
{
|
uint8_t bitstatus = 0x00;
|
assert_param(IS_GET_GPIOH_PIN(GPIO_Pin));
|
if ((GPIOH->DIN & GPIO_Pin) != (uint32_t)Bit_RESET)
|
{
|
bitstatus = (uint8_t)Bit_SET;
|
}
|
else
|
{
|
bitstatus = (uint8_t)Bit_RESET;
|
}
|
return bitstatus;
|
}
|
|
/********************************
|
IOMCRËÄѡһÊä³öÅäÖú¯Êý
|
¹¦ÄÜ: ÅäÖÃIOËÄѡһÊä³ö
|
ÊäÈ룺Êä³öIOͨµÀÑ¡ÔñÅäÖÃ
|
Êä³ö:ÎÞ
|
********************************/
|
void GPIO_IOMCR_IOMUXSEL_Set(uint32_t SetValue)
|
{
|
uint32_t tmpreg;
|
tmpreg = GPIO->IOMCR;
|
tmpreg &= ~(GPIO_IOMCR_IOMUXSEL_Msk);
|
tmpreg |= (SetValue & GPIO_IOMCR_IOMUXSEL_Msk);
|
GPIO->IOMCR = tmpreg;
|
}
|
/********************************
|
¶ÁIOMCRËÄѡһÅäÖú¯Êý
|
¹¦ÄÜ:¶ÁIOMCRËÄѡһÅäÖÃ״̬
|
ÊäÈ룺ÎÞ
|
Êä³ö:IOMCRËÄѡһÅäÖÃÑ¡ÔñÖµ
|
********************************/
|
uint32_t GPIO_IOMCR_IOMUXSEL_Get(void)
|
{
|
return (GPIO->IOMCR & GPIO_IOMCR_IOMUXSEL_Msk);
|
}
|
|
/* GPIO ËÄѡһʹÄÜ º¯Êý */
|
void GPIO_IOMCR_Setable(FunState NewState)
|
{
|
if (NewState == ENABLE)
|
{
|
GPIO->IOMCR |= GPIO_IOMCR_IOMCUEN_Msk;
|
}
|
else
|
{
|
GPIO->IOMCR &= ~(GPIO_IOMCR_IOMCUEN_Msk);
|
}
|
}
|
|
FunState GPIO_IOMCR_Getable(void)
|
{
|
if (GPIO->IOMCR & (GPIO_IOMCR_IOMCUEN_Msk))
|
{
|
return ENABLE;
|
}
|
else
|
{
|
return DISABLE;
|
}
|
}
|
|
/******END OF FILE****/
|