gpio.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. #ifndef GPIO_H_
  27. #define GPIO_H_
  28. #include <rtdef.h>
  29. /**
  30. * GPIO interrupt trigger type macro,
  31. * each represent an interrupt trigger mode
  32. *
  33. * @see gpio_set_irq_type();
  34. */
  35. enum
  36. {
  37. IRQ_TYPE_NONE = 0x00000000, /**< none*/
  38. IRQ_TYPE_EDGE_RISING = 0x00000001, /**< rising edge*/
  39. IRQ_TYPE_EDGE_FALLING = 0x00000002, /**< falling edge*/
  40. IRQ_TYPE_EDGE_BOTH = (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING),
  41. IRQ_TYPE_LEVEL_HIGH = 0x00000004, /**< high level*/
  42. IRQ_TYPE_LEVEL_LOW = 0x00000008, /**< low level*/
  43. IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH),
  44. IRQ_TYPE_TRIGGER_MASK = (IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW | \
  45. IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING),
  46. };
  47. /**
  48. * GPIO direction macro,
  49. * each represent a direction
  50. *
  51. * @see gpio_get_direction();
  52. * @see gpio_set_direction();
  53. */
  54. #define GPIO_DIR_OUTPUT 1 /**< output*/
  55. #define GPIO_DIR_INPUT 0 /**< input*/
  56. /**
  57. * convert GPIO number to IRQ number
  58. * @param gpio GPIO number to be converted
  59. * @return IRQ number
  60. */
  61. rt_uint32_t gpio_to_irq(rt_uint32_t gpio);
  62. /**
  63. * disable GPIO's debounce mode
  64. * controls whether an external signal that is the source
  65. * of an interrupt needs to be debounced to remove any
  66. * spurious glitches.
  67. * @param gpio GPIO number
  68. */
  69. void gpio_disable_debounce(rt_uint32_t gpio);
  70. /**
  71. * enable GPIO's debounce mode
  72. * controls whether an external signal that is the source
  73. * of an interrupt needs to be debounced to remove any
  74. * spurious glitches.
  75. * @param gpio GPIO number
  76. */
  77. void gpio_enable_debounce(rt_uint32_t gpio);
  78. /**
  79. * allows each GPIO to be configured for interrupts
  80. * it configures the corresponding GPIO to become an interrupt
  81. * @param gpio GPIO number
  82. */
  83. void gpio_irq_enable(rt_uint32_t irq);
  84. /**
  85. * GPIO operates as a normal GPIO signal
  86. * interrupts are disabled
  87. * @param gpio GPIO number
  88. */
  89. void gpio_irq_disable(rt_uint32_t irq);
  90. /**
  91. * it configures the interrupt type to be
  92. * falling-edge or active-low sensitive
  93. * rising-edge or active-high sensitive.
  94. * @param gpio GPIO number
  95. * @param type interrupt type
  96. * @return 0 if OK
  97. */
  98. int gpio_set_irq_type(rt_uint32_t gpio, rt_uint32_t type);
  99. /**
  100. * mask the interrupt
  101. * @param gpio GPIO number
  102. * @return 0 if OK
  103. */
  104. int gpio_irq_mask(rt_uint32_t irq);
  105. /**
  106. * unmask the interrupt
  107. * @param gpio GPIO number
  108. * @return 0 if OK
  109. */
  110. int gpio_irq_unmask(rt_uint32_t irq);
  111. /**
  112. * get corresponding GPIO's direction
  113. * @param gpio GPIO number
  114. * @return 0 - input
  115. * 1 - output
  116. */
  117. int gpio_get_direction(rt_uint32_t gpio);
  118. /**
  119. * set corresponding GPIO's direction
  120. * @param gpio GPIO number
  121. * @return 0 - input
  122. * 1 - output
  123. */
  124. void gpio_set_direction(rt_uint32_t gpio, rt_uint32_t direction);
  125. /**
  126. * get corresponding GPIO's value
  127. * @param gpio GPIO number
  128. * @return GPIO value
  129. */
  130. int gpio_get_value(rt_uint32_t gpio);
  131. /**
  132. * set corresponding GPIO's value
  133. * @param gpio GPIO number
  134. * @param val GPIO value
  135. */
  136. void gpio_set_value(rt_uint32_t gpio, int val);
  137. /**
  138. * set corresponding GPIO's direction to input
  139. * @param gpio GPIO number
  140. * @return 0 if OK
  141. */
  142. int gpio_direction_input(rt_uint32_t gpio);
  143. /**
  144. * set corresponding GPIO's value and set direction to output
  145. * @param gpio GPIO number
  146. * @param val GPIO value
  147. * @return 0 if OK
  148. */
  149. int gpio_direction_output(rt_uint32_t gpio, rt_uint32_t val);
  150. /**
  151. * request a GPIO
  152. * @param gpio GPIO number
  153. * @return 0 if OK
  154. */
  155. int gpio_request(rt_uint32_t gpio);
  156. /**
  157. * release a GPIO
  158. * @param gpio GPIO number
  159. * @return 0 if OK
  160. */
  161. int gpio_release(rt_uint32_t gpio);
  162. /**
  163. * initialize GPIO driver
  164. */
  165. void rt_hw_gpio_init(void);
  166. #endif /* GPIO_H_ */