1 #ifndef __SWM320_GPIO_H__ 2 #define __SWM320_GPIO_H__ 3 4 5 void GPIO_Init(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t dir, uint32_t pull_up, uint32_t pull_down); //引脚初始化,包含引脚方向、上拉电阻、下拉电阻 6 7 #define GPIO_INPUT ((0 << 0) | (0 << 1) | (0 << 2)) 8 #define GPIO_INPUT_PullUp ((0 << 0) | (1 << 1) | (0 << 2)) 9 #define GPIO_INPUT_PullDown ((0 << 0) | (0 << 1) | (1 << 2)) 10 #define GPIO_OUTPUT ((1 << 0) | (0 << 1) | (0 << 2)) 11 12 #define GPIO_INIT(GPIOx, n, mode) GPIO_Init(GPIOx, n, (mode & 1) ? 1 : 0, (mode & 2) ? 1 : 0, (mode & 4) ? 1 : 0) 13 14 15 void GPIO_SetBit(GPIO_TypeDef * GPIOx, uint32_t n); //将参数指定的引脚电平置高 16 void GPIO_ClrBit(GPIO_TypeDef * GPIOx, uint32_t n); //将参数指定的引脚电平置低 17 void GPIO_InvBit(GPIO_TypeDef * GPIOx, uint32_t n); //将参数指定的引脚电平反转 18 uint32_t GPIO_GetBit(GPIO_TypeDef * GPIOx, uint32_t n); //读取参数指定的引脚的电平状态 19 void GPIO_SetBits(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t w); //将参数指定的从n开始的w位连续引脚的电平置高 20 void GPIO_ClrBits(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t w); //将参数指定的从n开始的w位连续引脚的电平置低 21 void GPIO_InvBits(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t w); //将参数指定的从n开始的w位连续引脚的电平反转 22 uint32_t GPIO_GetBits(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t w); //读取参数指定的从n开始的w位连续引脚的电平状态 23 24 25 void GPIO_AtomicSetBits(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t w); 26 void GPIO_AtomicClrBits(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t w); 27 void GPIO_AtomicInvBits(GPIO_TypeDef * GPIOx, uint32_t n, uint32_t w); 28 29 30 // for compatibility 31 #define GPIO_AtomicSetBit GPIO_SetBit 32 #define GPIO_AtomicClrBit GPIO_ClrBit 33 #define GPIO_AtomicInvBit GPIO_InvBit 34 35 36 #endif //__SWM320_GPIO_H__ 37