📄 drvgpio.c
字号:
/* Description: */
/* Get the pin value from the specified input GPIO pin. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_GetBit(E_DRVGPIO_PORT port, int32_t i32Bit)
{
volatile uint32_t u32Reg;
if ((i32Bit < 0) || (i32Bit > 16))
{
return E_DRVGPIO_ARGUMENT;
}
u32Reg = (uint32_t)&GPIOA->PIN + (port*PORT_OFFSET);
return ((inpw(u32Reg)>>i32Bit) & 0x1);
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_ClrBit */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* i32Bit - [in] */
/* Specify pin of the GPIO port. It could be 0~15. */
/* Returns: */
/* E_SUCCESS Operation successful */
/* E_DRVGPIO_ARGUMENT Incorrect argument */
/* Description: */
/* Set the specified GPIO pin to 0. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_ClrBit(E_DRVGPIO_PORT port, int32_t i32Bit)
{
GPIO_T * tGPIO;
if ((i32Bit < 0) || (i32Bit > 16))
{
return E_DRVGPIO_ARGUMENT;
}
tGPIO = (GPIO_T *)((uint32_t)GPIOA + (port*PORT_OFFSET));
tGPIO->DOUT &= ~(1 << i32Bit);
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_SetPortBits */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* i32Data - [in] */
/* The data output value. It could be 0~0xFFFF */
/* Returns: */
/* E_SUCCESS Operation successful */
/* E_DRVGPIO_ARGUMENT Incorrect argument */
/* Description: */
/* Set the output port value to the specified GPIO port. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_SetPortBits(E_DRVGPIO_PORT port,int32_t i32Data)
{
GPIO_T * tGPIO;
tGPIO = (GPIO_T *)((uint32_t)GPIOA + (port*PORT_OFFSET));
tGPIO->DOUT = i32Data;
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_GetPortBits */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* Returns: */
/* The specified input port value 0 ~ 0xFFFF */
/* E_DRVGPIO_ARGUMENT Incorrect argument */
/* Description: */
/* Get the input port value from the specified GPIO port. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_GetPortBits(E_DRVGPIO_PORT port)
{
GPIO_T * tGPIO;
tGPIO = (GPIO_T *)((uint32_t)GPIOA + (port*PORT_OFFSET));
return tGPIO->PIN;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_GetDoutBit */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* i32Bit - [in] */
/* Specify pin of the GPIO port. It could be 0~15. */
/* Returns: */
/* The bit value of the specified register 0 / 1 */
/* E_DRVGPIO_ARGUMENT Incorrect argument */
/* Description: */
/* Get the bit value from the specified Data Output Value Register. */
/* If the bit value is 1, it's meaning the pin is output data to high. */
/* Otherwise, it's output data to low. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_GetDoutBit(E_DRVGPIO_PORT port, int32_t i32Bit)
{
if ((i32Bit < 0) || (i32Bit >= 15))
{
return E_DRVGPIO_ARGUMENT;
}
return ((inpw((uint32_t)&GPIOA->DOUT + (port*PORT_OFFSET))>>i32Bit) & 0x1);
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_GetPortDoutBits */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* Returns: */
/* The portt value of the specified register 0 ~ 0xFFFF */
/* E_DRVGPIO_ARGUMENT Incorrect argument */
/* Description: */
/* Get the port value from the specified Data Output Value Register. */
/* If the corresponding bit of the return port value is 1, it's meaning the the corresponding */
/* bit is output data to high. Otherwise, it's output data to low. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_GetPortDoutBits(E_DRVGPIO_PORT port)
{
if (port > 4)
{
return E_DRVGPIO_ARGUMENT;
}
return inpw((uint32_t)&GPIOA->DOUT + (port*PORT_OFFSET));
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_SetBitMask */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* i32Bit - [in] */
/* Specify pin of the GPIO port. It could be 0~15. */
/* Returns: */
/* E_SUCCESS Operation successful */
/* Description: */
/* This function is used to protect the write data function of the corresponding GPIO pin. */
/* When set the bit mask, the write signal is masked and write data to the protect bit is */
/* ignored. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_SetBitMask(E_DRVGPIO_PORT port, int32_t i32Bit)
{
volatile uint32_t u32Reg;
u32Reg = (uint32_t)&GPIOA->DMASK + (port*PORT_OFFSET);
outpw(u32Reg, inpw(u32Reg) | (1<<i32Bit));
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_GetBitMask */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* i32Bit - [in] */
/* Specify pin of the GPIO port. It could be 0~15. */
/* Returns: */
/* The bit value of the specified register 0 / 1 */
/* Description: */
/* Get the bit value from the specified Data Output Write Mask Register. */
/* If the bit value is 1, it's meaning the corresponding bit is protected. */
/* And write data to the bit is ignored. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_GetBitMask(E_DRVGPIO_PORT port, int32_t i32Bit)
{
volatile uint32_t u32Reg;
u32Reg = (uint32_t)&GPIOA->DMASK + (port*PORT_OFFSET);
return ((inpw(u32Reg)>>i32Bit) & 0x1);
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_ClrBitMask */
/* */
/* Parameter: */
/* port - [in] */
/* E_DRVGPIO_PORT, specify GPIO port. It could be E_GPA, E_GPB, E_GPC, E_GPD and E_GPE. */
/* i32Bit - [in] */
/* Specify pin of the GPIO port. It could be 0~15. */
/* Returns: */
/* E_SUCCESS Operation successful */
/* Description: */
/* This function is used to remove the write protect function of the the corresponding GPIO */
/* pin. After remove the bit mask, write data to the corresponding bit is workable. */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvGPIO_ClrBitMask(E_DRVGPIO_PORT port, int32_t i32Bit)
{
volatile uint32_t u32Reg;
u32Reg = (uint32_t)&GPIOA->DMASK + (port*PORT_OFFSET);
outpw(u32Reg, inpw(u32Reg) & ~(1<<i32Bit));
return E_SUCCESS;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvGPIO_SetPortMask */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -