gpio.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #ifndef _GPIO_H
  3. #define _GPIO_H
  4. /* x = A to F */
  5. /* GPIO port mode register (GPIOx_MODER) */
  6. #define GPIO_MODE_IN 0x0
  7. #define GPIO_MODE_OUT 0x1
  8. #define GPIO_MODE_AFF 0x2
  9. #define GPIO_MODE_ANL 0x3
  10. /* GPIO port output type register (GPIOx_OTYPER) */
  11. #define GPIO_OTYPE_PP 0x0
  12. #define GPIO_OTYPE_OD 0x1
  13. /* GPIO port output speed register (GPIOx_OSPEEDR) */
  14. #define GPIO_OSPEED_VL 0x0
  15. #define GPIO_OSPEED_LW 0x1
  16. #define GPIO_OSPEED_HI 0x2
  17. #define GPIO_OSPEED_VH 0x3
  18. /* GPIO port pull-up/pull-down register (GPIOx_PUPDR) */
  19. #define GPIO_PUPD_NO 0x0
  20. #define GPIO_PUPD_UP 0x1
  21. #define GPIO_PUPD_DW 0x2
  22. #define GPIO_PUPD_NN 0x3
  23. /* GPIO port input data register (GPIOx_IDR) */
  24. /* GPIO port output data register (GPIOx_ODR) */
  25. /* GPIO port bit set/reset register (GPIOx_BSRR) */
  26. /* GPIO port bit reset register (GPIOx_BRR) (x = A to F) */
  27. /* GPIO port configuration lock register (GPIOx_LCKR) */
  28. /* GPIO alternate function low register (GPIOx_AFRL) for pin 0..7 */
  29. #define GPIO_AFRL_AF0 0x0
  30. #define GPIO_AFRL_AF1 0x1
  31. #define GPIO_AFRL_AF2 0x2
  32. #define GPIO_AFRL_AF3 0x3
  33. #define GPIO_AFRL_AF4 0x4
  34. #define GPIO_AFRL_AF5 0x5
  35. #define GPIO_AFRL_AF6 0x6
  36. #define GPIO_AFRL_AF7 0x7
  37. /* GPIO alternate function high register (GPIOx_AFRH) for pin 0..7 */
  38. #define GPIO_AFRH_AF0 0x0
  39. #define GPIO_AFRH_AF1 0x1
  40. #define GPIO_AFRH_AF2 0x2
  41. #define GPIO_AFRH_AF3 0x3
  42. #define GPIO_AFRH_AF4 0x4
  43. #define GPIO_AFRH_AF5 0x5
  44. #define GPIO_AFRH_AF6 0x6
  45. #define GPIO_AFRH_AF7 0x7
  46. /* PORT = GPIOA..GPIOF, PIN = 0..15 */
  47. #define GPIO_PIN_SET(PORT, PIN) PORT->BSRR = (1<<PIN)
  48. #define GPIO_PIN_RES(PORT, PIN) PORT->BRR = (1<<PIN)
  49. #endif