wm_gpio.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * @file wm_gpio.h
  3. *
  4. * @brief GPIO Driver Module
  5. *
  6. * @author dave
  7. *
  8. * Copyright (c) 2014 Winner Microelectronics Co., Ltd.
  9. */
  10. #ifndef WM_GPIO_H
  11. #define WM_GPIO_H
  12. #include "wm_type_def.h"
  13. #include "wm_io.h"
  14. /** gpio interrupte callback function */
  15. typedef void (*tls_gpio_irq_callback)(void *arg);
  16. /** Indicating gpio direction */
  17. enum tls_gpio_dir {
  18. WM_GPIO_DIR_OUTPUT, /**< output */
  19. WM_GPIO_DIR_INPUT /**< input */
  20. };
  21. /** Indicating gpio attribute */
  22. enum tls_gpio_attr {
  23. WM_GPIO_ATTR_FLOATING, /**< floating status */
  24. WM_GPIO_ATTR_PULLHIGH, /**< pull high */
  25. WM_GPIO_ATTR_PULLLOW /**< pull low */
  26. };
  27. /** Indicating gpio interrupt trigger type */
  28. enum tls_gpio_irq_trig {
  29. WM_GPIO_IRQ_TRIG_RISING_EDGE, /**< rising edge arises the interrupt */
  30. WM_GPIO_IRQ_TRIG_FALLING_EDGE, /**< falling edge arises the interrupt */
  31. WM_GPIO_IRQ_TRIG_DOUBLE_EDGE, /**< both rising edge and falling edge arise the interrupt */
  32. WM_GPIO_IRQ_TRIG_HIGH_LEVEL, /**< high power level arises the interrupt */
  33. WM_GPIO_IRQ_TRIG_LOW_LEVEL /**< low power level arises the interrupt */
  34. };
  35. /**
  36. * @defgroup Driver_APIs Driver APIs
  37. * @brief Driver APIs
  38. */
  39. /**
  40. * @addtogroup Driver_APIs
  41. * @{
  42. */
  43. /**
  44. * @defgroup GPIO_Driver_APIs GPIO Driver APIs
  45. * @brief GPIO driver APIs
  46. */
  47. /**
  48. * @addtogroup GPIO_Driver_APIs
  49. * @{
  50. */
  51. /**
  52. * @brief This function is used to config gpio function
  53. *
  54. * @param[in] gpio_pin gpio pin num
  55. * @param[in] dir gpio direction
  56. * @param[in] attr gpio attribute
  57. *
  58. * @return None
  59. *
  60. * @note None
  61. */
  62. void tls_gpio_cfg(enum tls_io_name gpio_pin, enum tls_gpio_dir dir, enum tls_gpio_attr attr);
  63. /**
  64. * @brief This function is used to read gpio status
  65. *
  66. * @param[in] gpio_pin gpio pin num
  67. *
  68. * @retval 0 power level is low
  69. * @retval 1 power level is high
  70. *
  71. * @note None
  72. */
  73. u8 tls_gpio_read(enum tls_io_name gpio_pin);
  74. /**
  75. * @brief This function is used to modify gpio status
  76. *
  77. * @param[in] gpio_pin gpio pin num
  78. * @param[in] value power level
  79. * 0: low power level
  80. * 1: high power level
  81. *
  82. * @return None
  83. *
  84. * @note None
  85. */
  86. void tls_gpio_write(enum tls_io_name gpio_pin, u8 value);
  87. /**
  88. * @brief This function is used to config gpio interrupt
  89. *
  90. * @param[in] gpio_pin gpio pin num
  91. * @param[in] mode interrupt trigger type
  92. *
  93. * @return None
  94. *
  95. * @note None
  96. */
  97. void tls_gpio_irq_enable(enum tls_io_name gpio_pin, enum tls_gpio_irq_trig mode);
  98. /**
  99. * @brief This function is used to disable gpio interrupt
  100. *
  101. * @param[in] gpio_pin gpio pin num
  102. *
  103. * @return None
  104. *
  105. * @note None
  106. */
  107. void tls_gpio_irq_disable(enum tls_io_name gpio_pin);
  108. /**
  109. * @brief This function is used to get gpio interrupt status
  110. *
  111. * @param[in] gpio_pin gpio pin num
  112. *
  113. * @retval 0 no interrupt happened
  114. * @retval 1 interrupt happened
  115. *
  116. * @note None
  117. */
  118. u8 tls_get_gpio_irq_status(enum tls_io_name gpio_pin);
  119. /**
  120. * @brief This function is used to clear gpio interrupt flag
  121. *
  122. * @param[in] gpio_pin gpio pin num
  123. *
  124. * @return None
  125. *
  126. * @note None
  127. */
  128. void tls_clr_gpio_irq_status(enum tls_io_name gpio_pin);
  129. /**
  130. * @brief This function is used to register gpio interrupt
  131. *
  132. * @param[in] gpio_pin gpio pin num
  133. * @param[in] callback the gpio interrupt call back function
  134. * @param[in] arg parammeter for the callback
  135. *
  136. * @return None
  137. *
  138. * @note
  139. * gpio callback function is called in interrupt,
  140. * so can not operate the critical data in the callback fuuction,
  141. * recommendation to send messages to other tasks to operate it.
  142. */
  143. void tls_gpio_isr_register(enum tls_io_name gpio_pin,
  144. tls_gpio_irq_callback callback,
  145. void *arg);
  146. /**
  147. * @}
  148. */
  149. /**
  150. * @}
  151. */
  152. #endif /* end of WM_GPIO_H */