gd32f30x_exti.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*!
  2. \file gd32f30x_exti.h
  3. \brief definitions for the EXTI
  4. */
  5. /*
  6. Copyright (C) 2017 GigaDevice
  7. 2017-02-10, V1.0.0, firmware for GD32F30x
  8. */
  9. #ifndef GD32F30X_EXTI_H
  10. #define GD32F30X_EXTI_H
  11. #include "gd32f30x.h"
  12. /* EXTI definitions */
  13. #define EXTI EXTI_BASE
  14. /* registers definitions */
  15. #define EXTI_INTEN REG32(EXTI + 0x00U) /*!< interrupt enable register */
  16. #define EXTI_EVEN REG32(EXTI + 0x04U) /*!< event enable register */
  17. #define EXTI_RTEN REG32(EXTI + 0x08U) /*!< rising edge trigger enable register */
  18. #define EXTI_FTEN REG32(EXTI + 0x0CU) /*!< falling trigger enable register */
  19. #define EXTI_SWIEV REG32(EXTI + 0x10U) /*!< software interrupt event register */
  20. #define EXTI_PD REG32(EXTI + 0x14U) /*!< pending register */
  21. /* bits definitions */
  22. /* EXTI_INTEN */
  23. #define EXTI_INTEN_INTEN0 BIT(0) /*!< interrupt from line 0 */
  24. #define EXTI_INTEN_INTEN1 BIT(1) /*!< interrupt from line 1 */
  25. #define EXTI_INTEN_INTEN2 BIT(2) /*!< interrupt from line 2 */
  26. #define EXTI_INTEN_INTEN3 BIT(3) /*!< interrupt from line 3 */
  27. #define EXTI_INTEN_INTEN4 BIT(4) /*!< interrupt from line 4 */
  28. #define EXTI_INTEN_INTEN5 BIT(5) /*!< interrupt from line 5 */
  29. #define EXTI_INTEN_INTEN6 BIT(6) /*!< interrupt from line 6 */
  30. #define EXTI_INTEN_INTEN7 BIT(7) /*!< interrupt from line 7 */
  31. #define EXTI_INTEN_INTEN8 BIT(8) /*!< interrupt from line 8 */
  32. #define EXTI_INTEN_INTEN9 BIT(9) /*!< interrupt from line 9 */
  33. #define EXTI_INTEN_INTEN10 BIT(10) /*!< interrupt from line 10 */
  34. #define EXTI_INTEN_INTEN11 BIT(11) /*!< interrupt from line 11 */
  35. #define EXTI_INTEN_INTEN12 BIT(12) /*!< interrupt from line 12 */
  36. #define EXTI_INTEN_INTEN13 BIT(13) /*!< interrupt from line 13 */
  37. #define EXTI_INTEN_INTEN14 BIT(14) /*!< interrupt from line 14 */
  38. #define EXTI_INTEN_INTEN15 BIT(15) /*!< interrupt from line 15 */
  39. #define EXTI_INTEN_INTEN16 BIT(16) /*!< interrupt from line 16 */
  40. #define EXTI_INTEN_INTEN17 BIT(17) /*!< interrupt from line 17 */
  41. #define EXTI_INTEN_INTEN18 BIT(18) /*!< interrupt from line 18 */
  42. #define EXTI_INTEN_INTEN19 BIT(19) /*!< interrupt from line 19 */
  43. /* EXTI_EVEN */
  44. #define EXTI_EVEN_EVEN0 BIT(0) /*!< event from line 0 */
  45. #define EXTI_EVEN_EVEN1 BIT(1) /*!< event from line 1 */
  46. #define EXTI_EVEN_EVEN2 BIT(2) /*!< event from line 2 */
  47. #define EXTI_EVEN_EVEN3 BIT(3) /*!< event from line 3 */
  48. #define EXTI_EVEN_EVEN4 BIT(4) /*!< event from line 4 */
  49. #define EXTI_EVEN_EVEN5 BIT(5) /*!< event from line 5 */
  50. #define EXTI_EVEN_EVEN6 BIT(6) /*!< event from line 6 */
  51. #define EXTI_EVEN_EVEN7 BIT(7) /*!< event from line 7 */
  52. #define EXTI_EVEN_EVEN8 BIT(8) /*!< event from line 8 */
  53. #define EXTI_EVEN_EVEN9 BIT(9) /*!< event from line 9 */
  54. #define EXTI_EVEN_EVEN10 BIT(10) /*!< event from line 10 */
  55. #define EXTI_EVEN_EVEN11 BIT(11) /*!< event from line 11 */
  56. #define EXTI_EVEN_EVEN12 BIT(12) /*!< event from line 12 */
  57. #define EXTI_EVEN_EVEN13 BIT(13) /*!< event from line 13 */
  58. #define EXTI_EVEN_EVEN14 BIT(14) /*!< event from line 14 */
  59. #define EXTI_EVEN_EVEN15 BIT(15) /*!< event from line 15 */
  60. #define EXTI_EVEN_EVEN16 BIT(16) /*!< event from line 16 */
  61. #define EXTI_EVEN_EVEN17 BIT(17) /*!< event from line 17 */
  62. #define EXTI_EVEN_EVEN18 BIT(18) /*!< event from line 18 */
  63. #define EXTI_EVEN_EVEN19 BIT(19) /*!< event from line 19 */
  64. /* EXTI_RTEN */
  65. #define EXTI_RTEN_RTEN0 BIT(0) /*!< rising edge from line 0 */
  66. #define EXTI_RTEN_RTEN1 BIT(1) /*!< rising edge from line 1 */
  67. #define EXTI_RTEN_RTEN2 BIT(2) /*!< rising edge from line 2 */
  68. #define EXTI_RTEN_RTEN3 BIT(3) /*!< rising edge from line 3 */
  69. #define EXTI_RTEN_RTEN4 BIT(4) /*!< rising edge from line 4 */
  70. #define EXTI_RTEN_RTEN5 BIT(5) /*!< rising edge from line 5 */
  71. #define EXTI_RTEN_RTEN6 BIT(6) /*!< rising edge from line 6 */
  72. #define EXTI_RTEN_RTEN7 BIT(7) /*!< rising edge from line 7 */
  73. #define EXTI_RTEN_RTEN8 BIT(8) /*!< rising edge from line 8 */
  74. #define EXTI_RTEN_RTEN9 BIT(9) /*!< rising edge from line 9 */
  75. #define EXTI_RTEN_RTEN10 BIT(10) /*!< rising edge from line 10 */
  76. #define EXTI_RTEN_RTEN11 BIT(11) /*!< rising edge from line 11 */
  77. #define EXTI_RTEN_RTEN12 BIT(12) /*!< rising edge from line 12 */
  78. #define EXTI_RTEN_RTEN13 BIT(13) /*!< rising edge from line 13 */
  79. #define EXTI_RTEN_RTEN14 BIT(14) /*!< rising edge from line 14 */
  80. #define EXTI_RTEN_RTEN15 BIT(15) /*!< rising edge from line 15 */
  81. #define EXTI_RTEN_RTEN16 BIT(16) /*!< rising edge from line 16 */
  82. #define EXTI_RTEN_RTEN17 BIT(17) /*!< rising edge from line 17 */
  83. #define EXTI_RTEN_RTEN18 BIT(18) /*!< rising edge from line 18 */
  84. #define EXTI_RTEN_RTEN19 BIT(19) /*!< rising edge from line 19 */
  85. /* EXTI_FTEN */
  86. #define EXTI_FTEN_FTEN0 BIT(0) /*!< falling edge from line 0 */
  87. #define EXTI_FTEN_FTEN1 BIT(1) /*!< falling edge from line 1 */
  88. #define EXTI_FTEN_FTEN2 BIT(2) /*!< falling edge from line 2 */
  89. #define EXTI_FTEN_FTEN3 BIT(3) /*!< falling edge from line 3 */
  90. #define EXTI_FTEN_FTEN4 BIT(4) /*!< falling edge from line 4 */
  91. #define EXTI_FTEN_FTEN5 BIT(5) /*!< falling edge from line 5 */
  92. #define EXTI_FTEN_FTEN6 BIT(6) /*!< falling edge from line 6 */
  93. #define EXTI_FTEN_FTEN7 BIT(7) /*!< falling edge from line 7 */
  94. #define EXTI_FTEN_FTEN8 BIT(8) /*!< falling edge from line 8 */
  95. #define EXTI_FTEN_FTEN9 BIT(9) /*!< falling edge from line 9 */
  96. #define EXTI_FTEN_FTEN10 BIT(10) /*!< falling edge from line 10 */
  97. #define EXTI_FTEN_FTEN11 BIT(11) /*!< falling edge from line 11 */
  98. #define EXTI_FTEN_FTEN12 BIT(12) /*!< falling edge from line 12 */
  99. #define EXTI_FTEN_FTEN13 BIT(13) /*!< falling edge from line 13 */
  100. #define EXTI_FTEN_FTEN14 BIT(14) /*!< falling edge from line 14 */
  101. #define EXTI_FTEN_FTEN15 BIT(15) /*!< falling edge from line 15 */
  102. #define EXTI_FTEN_FTEN16 BIT(16) /*!< falling edge from line 16 */
  103. #define EXTI_FTEN_FTEN17 BIT(17) /*!< falling edge from line 17 */
  104. #define EXTI_FTEN_FTEN18 BIT(18) /*!< falling edge from line 18 */
  105. #define EXTI_FTEN_FTEN19 BIT(19) /*!< falling edge from line 19 */
  106. /* EXTI_SWIEV */
  107. #define EXTI_SWIEV_SWIEV0 BIT(0) /*!< software interrupt/event request from line 0 */
  108. #define EXTI_SWIEV_SWIEV1 BIT(1) /*!< software interrupt/event request from line 1 */
  109. #define EXTI_SWIEV_SWIEV2 BIT(2) /*!< software interrupt/event request from line 2 */
  110. #define EXTI_SWIEV_SWIEV3 BIT(3) /*!< software interrupt/event request from line 3 */
  111. #define EXTI_SWIEV_SWIEV4 BIT(4) /*!< software interrupt/event request from line 4 */
  112. #define EXTI_SWIEV_SWIEV5 BIT(5) /*!< software interrupt/event request from line 5 */
  113. #define EXTI_SWIEV_SWIEV6 BIT(6) /*!< software interrupt/event request from line 6 */
  114. #define EXTI_SWIEV_SWIEV7 BIT(7) /*!< software interrupt/event request from line 7 */
  115. #define EXTI_SWIEV_SWIEV8 BIT(8) /*!< software interrupt/event request from line 8 */
  116. #define EXTI_SWIEV_SWIEV9 BIT(9) /*!< software interrupt/event request from line 9 */
  117. #define EXTI_SWIEV_SWIEV10 BIT(10) /*!< software interrupt/event request from line 10 */
  118. #define EXTI_SWIEV_SWIEV11 BIT(11) /*!< software interrupt/event request from line 11 */
  119. #define EXTI_SWIEV_SWIEV12 BIT(12) /*!< software interrupt/event request from line 12 */
  120. #define EXTI_SWIEV_SWIEV13 BIT(13) /*!< software interrupt/event request from line 13 */
  121. #define EXTI_SWIEV_SWIEV14 BIT(14) /*!< software interrupt/event request from line 14 */
  122. #define EXTI_SWIEV_SWIEV15 BIT(15) /*!< software interrupt/event request from line 15 */
  123. #define EXTI_SWIEV_SWIEV16 BIT(16) /*!< software interrupt/event request from line 16 */
  124. #define EXTI_SWIEV_SWIEV17 BIT(17) /*!< software interrupt/event request from line 17 */
  125. #define EXTI_SWIEV_SWIEV18 BIT(18) /*!< software interrupt/event request from line 18 */
  126. #define EXTI_SWIEV_SWIEV19 BIT(19) /*!< software interrupt/event request from line 19 */
  127. /* EXTI_PD */
  128. #define EXTI_PD_PD0 BIT(0) /*!< interrupt/event pending status from line 0 */
  129. #define EXTI_PD_PD1 BIT(1) /*!< interrupt/event pending status from line 1 */
  130. #define EXTI_PD_PD2 BIT(2) /*!< interrupt/event pending status from line 2 */
  131. #define EXTI_PD_PD3 BIT(3) /*!< interrupt/event pending status from line 3 */
  132. #define EXTI_PD_PD4 BIT(4) /*!< interrupt/event pending status from line 4 */
  133. #define EXTI_PD_PD5 BIT(5) /*!< interrupt/event pending status from line 5 */
  134. #define EXTI_PD_PD6 BIT(6) /*!< interrupt/event pending status from line 6 */
  135. #define EXTI_PD_PD7 BIT(7) /*!< interrupt/event pending status from line 7 */
  136. #define EXTI_PD_PD8 BIT(8) /*!< interrupt/event pending status from line 8 */
  137. #define EXTI_PD_PD9 BIT(9) /*!< interrupt/event pending status from line 9 */
  138. #define EXTI_PD_PD10 BIT(10) /*!< interrupt/event pending status from line 10 */
  139. #define EXTI_PD_PD11 BIT(11) /*!< interrupt/event pending status from line 11 */
  140. #define EXTI_PD_PD12 BIT(12) /*!< interrupt/event pending status from line 12 */
  141. #define EXTI_PD_PD13 BIT(13) /*!< interrupt/event pending status from line 13 */
  142. #define EXTI_PD_PD14 BIT(14) /*!< interrupt/event pending status from line 14 */
  143. #define EXTI_PD_PD15 BIT(15) /*!< interrupt/event pending status from line 15 */
  144. #define EXTI_PD_PD16 BIT(16) /*!< interrupt/event pending status from line 16 */
  145. #define EXTI_PD_PD17 BIT(17) /*!< interrupt/event pending status from line 17 */
  146. #define EXTI_PD_PD18 BIT(18) /*!< interrupt/event pending status from line 18 */
  147. #define EXTI_PD_PD19 BIT(19) /*!< interrupt/event pending status from line 19 */
  148. /* constants definitions */
  149. /* EXTI line number */
  150. typedef enum
  151. {
  152. EXTI_0 = BIT(0), /*!< EXTI line 0 */
  153. EXTI_1 = BIT(1), /*!< EXTI line 1 */
  154. EXTI_2 = BIT(2), /*!< EXTI line 2 */
  155. EXTI_3 = BIT(3), /*!< EXTI line 3 */
  156. EXTI_4 = BIT(4), /*!< EXTI line 4 */
  157. EXTI_5 = BIT(5), /*!< EXTI line 5 */
  158. EXTI_6 = BIT(6), /*!< EXTI line 6 */
  159. EXTI_7 = BIT(7), /*!< EXTI line 7 */
  160. EXTI_8 = BIT(8), /*!< EXTI line 8 */
  161. EXTI_9 = BIT(9), /*!< EXTI line 9 */
  162. EXTI_10 = BIT(10), /*!< EXTI line 10 */
  163. EXTI_11 = BIT(11), /*!< EXTI line 11 */
  164. EXTI_12 = BIT(12), /*!< EXTI line 12 */
  165. EXTI_13 = BIT(13), /*!< EXTI line 13 */
  166. EXTI_14 = BIT(14), /*!< EXTI line 14 */
  167. EXTI_15 = BIT(15), /*!< EXTI line 15 */
  168. EXTI_16 = BIT(16), /*!< EXTI line 16 */
  169. EXTI_17 = BIT(17), /*!< EXTI line 17 */
  170. EXTI_18 = BIT(18), /*!< EXTI line 18 */
  171. EXTI_19 = BIT(19), /*!< EXTI line 19 */
  172. }exti_line_enum;
  173. /* external interrupt and event */
  174. typedef enum
  175. {
  176. EXTI_INTERRUPT = 0, /*!< EXTI interrupt mode */
  177. EXTI_EVENT /*!< EXTI event mode */
  178. }exti_mode_enum;
  179. /* interrupt trigger mode */
  180. typedef enum
  181. {
  182. EXTI_TRIG_RISING = 0, /*!< EXTI rising edge trigger */
  183. EXTI_TRIG_FALLING, /*!< EXTI falling edge trigger */
  184. EXTI_TRIG_BOTH /*!< EXTI rising and falling edge trigger */
  185. }exti_trig_type_enum;
  186. /* function declarations */
  187. /* deinitialize the EXTI */
  188. void exti_deinit(void);
  189. /* enable the configuration of EXTI initialize */
  190. void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum trig_type);
  191. /* enable the interrupts from EXTI line x */
  192. void exti_interrupt_enable(exti_line_enum linex);
  193. /* enable the events from EXTI line x */
  194. void exti_event_enable(exti_line_enum linex);
  195. /* disable the interrupts from EXTI line x */
  196. void exti_interrupt_disable(exti_line_enum linex);
  197. /* disable the events from EXTI line x */
  198. void exti_event_disable(exti_line_enum linex);
  199. /* get EXTI lines pending flag */
  200. FlagStatus exti_flag_get(exti_line_enum linex);
  201. /* clear EXTI lines pending flag */
  202. void exti_flag_clear(exti_line_enum linex);
  203. /* get EXTI lines flag when the interrupt flag is set */
  204. FlagStatus exti_interrupt_flag_get(exti_line_enum linex);
  205. /* clear EXTI lines pending flag */
  206. void exti_interrupt_flag_clear(exti_line_enum linex);
  207. /* enable the EXTI software interrupt event */
  208. void exti_software_interrupt_enable(exti_line_enum linex);
  209. /* disable the EXTI software interrupt event */
  210. void exti_software_interrupt_disable(exti_line_enum linex);
  211. #endif /* GD32F30X_EXTI_H */