#include "gpio.h"
|
|
|
|
//GPIOA~G Ä£Ä⹦ÄÜÅäÖÃ
|
void AnalogIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin )
|
{
|
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructureRun;
|
|
GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
|
|
if( (GPIO_InitStructureRun.Pin != GPIO_Pin) ||
|
(GPIO_InitStructureRun.PxINEN != GPIO_IN_Dis) ||
|
(GPIO_InitStructureRun.PxODEN != GPIO_OD_Dis) ||
|
(GPIO_InitStructureRun.PxPUEN != GPIO_PU_Dis) ||
|
(GPIO_InitStructureRun.PxFCR != GPIO_FCR_ANA) )
|
{
|
GPIO_InitStructure.Pin = GPIO_Pin;
|
GPIO_InitStructure.PxINEN = GPIO_IN_Dis;
|
GPIO_InitStructure.PxODEN = GPIO_OD_Dis;
|
GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
|
GPIO_InitStructure.PxFCR = GPIO_FCR_ANA;
|
|
GPIO_Init(GPIOx, &GPIO_InitStructure);
|
}
|
}
|
|
//GPIOH Ä£Ä⹦ÄÜÅäÖÃ
|
void AnalogIO_H(uint32_t GPIO_Pin )
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00;
|
|
if(CDIF_CR_INTF_EN_Getable() == DISABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(ENABLE);
|
}
|
for (pinpos = 0; pinpos < 4; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) << pinpos;
|
if(GPIO_Pin & pinbit)
|
{
|
GPIOH->INEN &= (~(1<<pinpos));
|
GPIOH->FCR |= (3<<(pinpos*2)) ;
|
}
|
}
|
if(CDIF_CR_INTF_EN_Getable() == ENABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(DISABLE);
|
}
|
}
|
|
//GPIOA~G ÊäÈë¿ÚÅäÖÃ
|
//type 0 = ÆÕͨ
|
//type 1 = ÉÏÀ
|
//#define IN_NORMAL 0
|
//#define IN_PULLUP 1
|
void InputtIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin, uint8_t Type )
|
{
|
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructureRun;
|
|
GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
|
|
if( (GPIO_InitStructureRun.Pin != GPIO_Pin) ||
|
(GPIO_InitStructureRun.PxINEN != GPIO_IN_En) ||
|
(GPIO_InitStructureRun.PxODEN != GPIO_OD_En) ||
|
((Type == IN_NORMAL)&&(GPIO_InitStructureRun.PxPUEN != GPIO_PU_Dis)) ||
|
((Type == IN_PULLUP)&&(GPIO_InitStructureRun.PxPUEN != GPIO_PU_En)) ||
|
(GPIO_InitStructureRun.PxFCR != GPIO_FCR_IN) )
|
{
|
GPIO_InitStructure.Pin = GPIO_Pin;
|
GPIO_InitStructure.PxINEN = GPIO_IN_En;
|
GPIO_InitStructure.PxODEN = GPIO_OD_En;
|
if(Type == IN_NORMAL) GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
|
else GPIO_InitStructure.PxPUEN = GPIO_PU_En;
|
GPIO_InitStructure.PxFCR = GPIO_FCR_IN;
|
|
GPIO_Init(GPIOx, &GPIO_InitStructure);
|
}
|
}
|
|
//GPIOH ÊäÈë¿ÚÅäÖÃ
|
//type 0 = ÆÕͨ
|
//type 1 = ÉÏÀ
|
//#define IN_NORMAL 0
|
//#define IN_PULLUP 1
|
void InputtIO_H(uint32_t GPIO_Pin, uint8_t Type )
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00;
|
|
if(CDIF_CR_INTF_EN_Getable() == DISABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(ENABLE);
|
}
|
for (pinpos = 0; pinpos < 4; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) << pinpos;
|
if(GPIO_Pin & pinbit)
|
{
|
if(Type==0)
|
{
|
GPIOH->PUEN &= (~(1<<pinpos));
|
}
|
else
|
{
|
GPIOH->PUEN |= (1<<pinpos);
|
}
|
GPIOH->FCR &= (~(3<<(pinpos*2)));
|
GPIOH->INEN |= (1<<pinpos);
|
}
|
}
|
if(CDIF_CR_INTF_EN_Getable() == ENABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(DISABLE);
|
}
|
}
|
|
//GPIOA~GÊä³ö¿ÚÅäÖÃ
|
//type 0 = ÆÕͨ
|
//type 1 = OD
|
//#define OUT_PUSHPULL 0
|
//#define OUT_OPENDRAIN 1
|
void OutputIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin, uint8_t Type )
|
{
|
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructureRun;
|
|
GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
|
|
if( (GPIO_InitStructureRun.Pin != GPIO_Pin) ||
|
(GPIO_InitStructureRun.PxINEN != GPIO_IN_Dis) ||
|
((Type == OUT_PUSHPULL)&&(GPIO_InitStructureRun.PxODEN != GPIO_OD_Dis)) ||
|
((Type == OUT_OPENDRAIN)&&(GPIO_InitStructureRun.PxODEN != GPIO_OD_En)) ||
|
(GPIO_InitStructureRun.PxPUEN != GPIO_PU_Dis) ||
|
(GPIO_InitStructureRun.PxFCR != GPIO_FCR_OUT) )
|
{
|
GPIO_InitStructure.Pin = GPIO_Pin;
|
GPIO_InitStructure.PxINEN = GPIO_IN_Dis;
|
if(Type == OUT_PUSHPULL) GPIO_InitStructure.PxODEN = GPIO_OD_Dis;
|
else GPIO_InitStructure.PxODEN = GPIO_OD_En;
|
GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
|
GPIO_InitStructure.PxFCR = GPIO_FCR_OUT;
|
|
GPIO_Init(GPIOx, &GPIO_InitStructure);
|
}
|
}
|
|
//GPIOHÊä³ö¿ÚÅäÖÃ
|
void OutputIO_H(uint32_t GPIO_Pin)
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00;
|
|
if(CDIF_CR_INTF_EN_Getable() == DISABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(ENABLE);
|
}
|
for (pinpos = 0; pinpos < 4; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) << pinpos;
|
if(GPIO_Pin & pinbit)
|
{
|
GPIOH->INEN &= (~(1<<pinpos));
|
GPIOH->PUEN &= (~(1<<pinpos));
|
GPIOH->FCR &= (~(3<<(pinpos*2)));
|
GPIOH->FCR |= (1<<(pinpos*2));
|
}
|
}
|
if(CDIF_CR_INTF_EN_Getable() == ENABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(DISABLE);
|
}
|
}
|
|
//IOÊý×ÖÌØÊ⹦ÄÜ¿Ú
|
//type 0 = ÆÕͨ
|
//type 1 = OD (OD¹¦Äܽö²¿·ÖÌØÊ⹦ÄÜÖ§³Ö)
|
//type 2 = ÆÕͨ+ÉÏÀ
|
//type 3 = OD+ÉÏÀ
|
//#define ALTFUN_NORMAL 0
|
//#define ALTFUN_OPENDRAIN 1
|
//#define ALTFUN_PULLUP 2
|
//#define ALTFUN_OPENDRAIN_PULLUP 3
|
void AltFunIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin, uint8_t Type )
|
{
|
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructureRun;
|
|
GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
|
|
if( (GPIO_InitStructureRun.Pin != GPIO_Pin) ||
|
(GPIO_InitStructureRun.PxINEN != GPIO_IN_Dis) ||
|
(((Type & 0x01) == 0)&&(GPIO_InitStructureRun.PxODEN != GPIO_OD_Dis)) ||
|
(((Type & 0x01) != 0)&&(GPIO_InitStructureRun.PxODEN != GPIO_OD_En)) ||
|
(((Type & 0x02) == 0)&&(GPIO_InitStructureRun.PxPUEN != GPIO_PU_Dis)) ||
|
(((Type & 0x02) != 0)&&(GPIO_InitStructureRun.PxPUEN != GPIO_PU_En)) ||
|
(GPIO_InitStructureRun.PxFCR != GPIO_FCR_DIG) )
|
{
|
GPIO_InitStructure.Pin = GPIO_Pin;
|
GPIO_InitStructure.PxINEN = GPIO_IN_Dis;
|
if( (Type & 0x01) == 0 ) GPIO_InitStructure.PxODEN = GPIO_OD_Dis;
|
else GPIO_InitStructure.PxODEN = GPIO_OD_En;
|
if( (Type & 0x02) == 0 ) GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
|
else GPIO_InitStructure.PxPUEN = GPIO_PU_En;
|
GPIO_InitStructure.PxFCR = GPIO_FCR_DIG;
|
|
GPIO_Init(GPIOx, &GPIO_InitStructure);
|
}
|
}
|
|
//IOÊý×ÖÌØÊ⹦ÄÜ¿Ú
|
//type 0 = ÆÕͨ
|
//type 1= ÆÕͨ+ÉÏÀ
|
void AltFunIO_H(uint32_t GPIO_Pin, uint8_t Type )
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00;
|
|
if(CDIF_CR_INTF_EN_Getable() == DISABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(ENABLE);
|
}
|
for (pinpos = 0; pinpos < 4; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) << pinpos;
|
if(GPIO_Pin & pinbit)
|
{
|
GPIOH->INEN &= (~(1<<pinpos));
|
if(Type==0)
|
{
|
GPIOH->PUEN &= (~(1<<pinpos));
|
}
|
else
|
{
|
GPIOH->PUEN |= (1<<pinpos);
|
}
|
GPIOH->FCR &= (~(3<<(pinpos*2)));
|
GPIOH->FCR |= (2<<(pinpos*2));
|
}
|
}
|
if(CDIF_CR_INTF_EN_Getable() == ENABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(DISABLE);
|
}
|
}
|
|
//IO¹Ø±Õ£¨GPIOA,B,C,D,E,F,G£©£¨odÊä³ö¸ß£©
|
//ÅäÖÃIOΪ¸ß×è̬
|
void CloseIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin )
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00;
|
|
for (pinpos = 0; pinpos < 16; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) << pinpos;
|
if(GPIO_Pin & pinbit)
|
{
|
GPIOx->INEN &=~(1<<pinpos);
|
GPIOx->FCR &= ~(3<<(pinpos*2));
|
}
|
}
|
}
|
|
//IO GPIOH¹Ø±Õ£¨odÊä³ö¸ß£©
|
//ÅäÖÃIOΪ¸ß×è̬
|
void CloseH_IO( GPIOH_Type* GPIOx, uint32_t GPIO_Pin )
|
{
|
uint32_t pinpos = 0x00,pinbit = 0x00;
|
|
if(CDIF_CR_INTF_EN_Getable() == DISABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(ENABLE);
|
}
|
for (pinpos = 0; pinpos < 4; pinpos++)
|
{
|
pinbit = ((uint32_t)0x01) << pinpos;
|
if(GPIO_Pin & pinbit)
|
{
|
GPIOx->INEN &=~(1<<pinpos);
|
GPIOx->FCR &= ~(3<<(pinpos*2));
|
}
|
}
|
if(CDIF_CR_INTF_EN_Getable() == ENABLE)
|
{
|
CDIF_CR_INTF_EN_Setable(DISABLE);
|
}
|
}
|