drv_gpio.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-16 bigmagic first version
  9. */
  10. #ifndef __DRV_GPIO_H__
  11. #define __DRV_GPIO_H__
  12. #include <rtthread.h>
  13. #include <rtdevice.h>
  14. #include "board.h"
  15. #include "interrupt.h"
  16. struct gpio_irq_def
  17. {
  18. void *irq_arg[32];
  19. void (*irq_cb[32])(void *param);
  20. rt_uint8_t irq_type[32];
  21. rt_uint8_t state[32];
  22. };
  23. #define GPIO_REG_GPFSEL0(BASE) HWREG32(BASE + 0x00)
  24. #define GPIO_REG_GPFSEL1(BASE) HWREG32(BASE + 0x04)
  25. #define GPIO_REG_GPFSEL2(BASE) HWREG32(BASE + 0x08)
  26. #define GPIO_REG_GPFSEL3(BASE) HWREG32(BASE + 0x0C)
  27. #define GPIO_REG_GPFSEL4(BASE) HWREG32(BASE + 0x10)
  28. #define GPIO_REG_GPFSEL5(BASE) HWREG32(BASE + 0x14)
  29. #define GPIO_REG_REV0(BASE) HWREG32(BASE + 0x18)
  30. #define GPIO_REG_GPSET0(BASE) HWREG32(BASE + 0x1C)
  31. #define GPIO_REG_GPSET1(BASE) HWREG32(BASE + 0x20)
  32. #define GPIO_REG_REV1(BASE) HWREG32(BASE + 0x24)
  33. #define GPIO_REG_GPCLR0(BASE) HWREG32(BASE + 0x28)
  34. #define GPIO_REG_GPCLR1(BASE) HWREG32(BASE + 0x2C)
  35. #define GPIO_REG_REV2(BASE) HWREG32(BASE + 0x30)
  36. #define GPIO_REG_GPLEV0(BASE) HWREG32(BASE + 0x34)
  37. #define GPIO_REG_GPLEV1(BASE) HWREG32(BASE + 0x38)
  38. #define GPIO_REG_REV3(BASE) HWREG32(BASE + 0x3C)
  39. #define GPIO_REG_GPEDS0(BASE) HWREG32(BASE + 0x40)
  40. #define GPIO_REG_GPEDS1(BASE) HWREG32(BASE + 0x44)
  41. #define GPIO_REG_REV4(BASE) HWREG32(BASE + 0x48)
  42. #define GPIO_REG_GPREN0(BASE) HWREG32(BASE + 0x4C)
  43. #define GPIO_REG_GPREN1(BASE) HWREG32(BASE + 0x50)
  44. #define GPIO_REG_REV5(BASE) HWREG32(BASE + 0x54)
  45. #define GPIO_REG_GPFEN0(BASE) HWREG32(BASE + 0x58)
  46. #define GPIO_REG_GPFEN1(BASE) HWREG32(BASE + 0x5C)
  47. #define GPIO_REG_REV6(BASE) HWREG32(BASE + 0x60)
  48. #define GPIO_REG_GPHEN0(BASE) HWREG32(BASE + 0x64)
  49. #define GPIO_REG_GPHEN1(BASE) HWREG32(BASE + 0x68)
  50. #define GPIO_REG_REV7(BASE) HWREG32(BASE + 0x6C)
  51. #define GPIO_REG_GPLEN0(BASE) HWREG32(BASE + 0x70)
  52. #define GPIO_REG_GPLEN1(BASE) HWREG32(BASE + 0x74)
  53. #define GPIO_REG_REV8(BASE) HWREG32(BASE + 0x78)
  54. #define GPIO_REG_GPAREN0(BASE) HWREG32(BASE + 0x7C)
  55. #define GPIO_REG_GPAREN1(BASE) HWREG32(BASE + 0x80)
  56. #define GPIO_REG_REV11(BASE) HWREG32(BASE + 0x84)
  57. #define GPIO_REG_GPAFEN0(BASE) HWREG32(BASE + 0x88)
  58. #define GPIO_REG_GPAFEN1(BASE) HWREG32(BASE + 0x8C)
  59. #define GPIO_REG_REV10(BASE) HWREG32(BASE + 0x90)
  60. #define GPIO_REG_GPPUD(BASE) HWREG32(BASE + 0x94)
  61. #define GPIO_REG_GPPUDCLK0(BASE) HWREG32(BASE + 0x98)
  62. #define GPIO_REG_GPPUDCLK1(BASE) HWREG32(BASE + 0x9C)
  63. #define GPIO_REG_REV9(BASE) HWREG32(BASE + 0xA0)
  64. #define GPIO_REG_TEST(BASE) HWREG32(BASE + 0xA4)
  65. #define GPIO_PUP_PDN_CNTRL_REG0(BASE) HWREG32(BASE + 0xE4)
  66. #define GPIO_PUP_PDN_CNTRL_REG1(BASE) HWREG32(BASE + 0xE8)
  67. #define GPIO_PUP_PDN_CNTRL_REG2(BASE) HWREG32(BASE + 0xEC)
  68. #define GPIO_PUP_PDN_CNTRL_REG3(BASE) HWREG32(BASE + 0xF0)
  69. typedef enum {
  70. GPIO_PIN_0,
  71. GPIO_PIN_1,
  72. GPIO_PIN_2,
  73. GPIO_PIN_3,
  74. GPIO_PIN_4,
  75. GPIO_PIN_5,
  76. GPIO_PIN_6,
  77. GPIO_PIN_7,
  78. GPIO_PIN_8,
  79. GPIO_PIN_9,
  80. GPIO_PIN_10,
  81. GPIO_PIN_11,
  82. GPIO_PIN_12,
  83. GPIO_PIN_13,
  84. GPIO_PIN_14,
  85. GPIO_PIN_15,
  86. GPIO_PIN_16,
  87. GPIO_PIN_17,
  88. GPIO_PIN_18,
  89. GPIO_PIN_19,
  90. GPIO_PIN_20,
  91. GPIO_PIN_21,
  92. GPIO_PIN_22,
  93. GPIO_PIN_23,
  94. GPIO_PIN_24,
  95. GPIO_PIN_25,
  96. GPIO_PIN_26,
  97. GPIO_PIN_27,
  98. GPIO_PIN_28,
  99. GPIO_PIN_29,
  100. GPIO_PIN_30,
  101. GPIO_PIN_31,
  102. GPIO_PIN_32,
  103. GPIO_PIN_33,
  104. GPIO_PIN_34,
  105. GPIO_PIN_35,
  106. GPIO_PIN_36,
  107. GPIO_PIN_37,
  108. GPIO_PIN_38,
  109. GPIO_PIN_39,
  110. GPIO_PIN_40,
  111. } GPIO_PIN;
  112. typedef enum {
  113. INPUT = 0b000,
  114. OUTPUT = 0b001,
  115. ALT0 = 0b100,
  116. ALT1 = 0b101,
  117. ALT2 = 0b110,
  118. ALT3 = 0b111,
  119. ALT4 = 0b011,
  120. ALT5 = 0b010
  121. } GPIO_FUNC;
  122. typedef enum {
  123. RASPI_NO_RESISTOR = 0x00,
  124. RASPI_PULL_UP = 0x01,
  125. RASPI_PULL_DOWN = 0x10
  126. } GPIO_PUPD_FUNC;
  127. void prev_raspi_pin_mode(GPIO_PIN pin, GPIO_FUNC mode);
  128. void prev_raspi_pin_write(GPIO_PIN pin, int pin_value);
  129. int rt_hw_gpio_init(void);
  130. #endif /* __DRV_GPIO_H__ */