SWM320_gpio.h 2.0 KB

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