gd32e23x_exti.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*!
  2. \file gd32e23x_exti.h
  3. \brief definitions for the EXTI
  4. \version 2019-02-19, V1.0.0, firmware for GD32E23x
  5. \version 2020-12-12, V1.1.0, firmware for GD32E23x
  6. */
  7. /*
  8. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  9. Redistribution and use in source and binary forms, with or without modification,
  10. are permitted provided that the following conditions are met:
  11. 1. Redistributions of source code must retain the above copyright notice, this
  12. list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. 3. Neither the name of the copyright holder nor the names of its contributors
  17. may be used to endorse or promote products derived from this software without
  18. specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  23. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  24. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  28. OF SUCH DAMAGE.
  29. */
  30. #ifndef GD32E23X_EXTI_H
  31. #define GD32E23X_EXTI_H
  32. #include "gd32e23x.h"
  33. /* EXTI definitions */
  34. #define EXTI EXTI_BASE
  35. /* registers definitions */
  36. #define EXTI_INTEN REG32(EXTI + 0x00000000U) /*!< interrupt enable register */
  37. #define EXTI_EVEN REG32(EXTI + 0x00000004U) /*!< event enable register */
  38. #define EXTI_RTEN REG32(EXTI + 0x00000008U) /*!< rising edge trigger enable register */
  39. #define EXTI_FTEN REG32(EXTI + 0x0000000CU) /*!< falling trigger enable register */
  40. #define EXTI_SWIEV REG32(EXTI + 0x00000010U) /*!< software interrupt event register */
  41. #define EXTI_PD REG32(EXTI + 0x00000014U) /*!< pending register */
  42. /* bits definitions */
  43. /* EXTI_INTEN */
  44. #define EXTI_INTEN_INTEN0 BIT(0) /*!< interrupt from line 0 */
  45. #define EXTI_INTEN_INTEN1 BIT(1) /*!< interrupt from line 1 */
  46. #define EXTI_INTEN_INTEN2 BIT(2) /*!< interrupt from line 2 */
  47. #define EXTI_INTEN_INTEN3 BIT(3) /*!< interrupt from line 3 */
  48. #define EXTI_INTEN_INTEN4 BIT(4) /*!< interrupt from line 4 */
  49. #define EXTI_INTEN_INTEN5 BIT(5) /*!< interrupt from line 5 */
  50. #define EXTI_INTEN_INTEN6 BIT(6) /*!< interrupt from line 6 */
  51. #define EXTI_INTEN_INTEN7 BIT(7) /*!< interrupt from line 7 */
  52. #define EXTI_INTEN_INTEN8 BIT(8) /*!< interrupt from line 8 */
  53. #define EXTI_INTEN_INTEN9 BIT(9) /*!< interrupt from line 9 */
  54. #define EXTI_INTEN_INTEN10 BIT(10) /*!< interrupt from line 10 */
  55. #define EXTI_INTEN_INTEN11 BIT(11) /*!< interrupt from line 11 */
  56. #define EXTI_INTEN_INTEN12 BIT(12) /*!< interrupt from line 12 */
  57. #define EXTI_INTEN_INTEN13 BIT(13) /*!< interrupt from line 13 */
  58. #define EXTI_INTEN_INTEN14 BIT(14) /*!< interrupt from line 14 */
  59. #define EXTI_INTEN_INTEN15 BIT(15) /*!< interrupt from line 15 */
  60. #define EXTI_INTEN_INTEN16 BIT(16) /*!< interrupt from line 16 */
  61. #define EXTI_INTEN_INTEN17 BIT(17) /*!< interrupt from line 17 */
  62. #define EXTI_INTEN_INTEN18 BIT(18) /*!< interrupt from line 18 */
  63. #define EXTI_INTEN_INTEN19 BIT(19) /*!< interrupt from line 19 */
  64. #define EXTI_INTEN_INTEN20 BIT(20) /*!< interrupt from line 20 */
  65. #define EXTI_INTEN_INTEN21 BIT(21) /*!< interrupt from line 21 */
  66. #define EXTI_INTEN_INTEN22 BIT(22) /*!< interrupt from line 22 */
  67. #define EXTI_INTEN_INTEN23 BIT(23) /*!< interrupt from line 23 */
  68. #define EXTI_INTEN_INTEN24 BIT(24) /*!< interrupt from line 24 */
  69. #define EXTI_INTEN_INTEN25 BIT(25) /*!< interrupt from line 25 */
  70. #define EXTI_INTEN_INTEN26 BIT(26) /*!< interrupt from line 26 */
  71. #define EXTI_INTEN_INTEN27 BIT(27) /*!< interrupt from line 27 */
  72. /* EXTI_EVEN */
  73. #define EXTI_EVEN_EVEN0 BIT(0) /*!< event from line 0 */
  74. #define EXTI_EVEN_EVEN1 BIT(1) /*!< event from line 1 */
  75. #define EXTI_EVEN_EVEN2 BIT(2) /*!< event from line 2 */
  76. #define EXTI_EVEN_EVEN3 BIT(3) /*!< event from line 3 */
  77. #define EXTI_EVEN_EVEN4 BIT(4) /*!< event from line 4 */
  78. #define EXTI_EVEN_EVEN5 BIT(5) /*!< event from line 5 */
  79. #define EXTI_EVEN_EVEN6 BIT(6) /*!< event from line 6 */
  80. #define EXTI_EVEN_EVEN7 BIT(7) /*!< event from line 7 */
  81. #define EXTI_EVEN_EVEN8 BIT(8) /*!< event from line 8 */
  82. #define EXTI_EVEN_EVEN9 BIT(9) /*!< event from line 9 */
  83. #define EXTI_EVEN_EVEN10 BIT(10) /*!< event from line 10 */
  84. #define EXTI_EVEN_EVEN11 BIT(11) /*!< event from line 11 */
  85. #define EXTI_EVEN_EVEN12 BIT(12) /*!< event from line 12 */
  86. #define EXTI_EVEN_EVEN13 BIT(13) /*!< event from line 13 */
  87. #define EXTI_EVEN_EVEN14 BIT(14) /*!< event from line 14 */
  88. #define EXTI_EVEN_EVEN15 BIT(15) /*!< event from line 15 */
  89. #define EXTI_EVEN_EVEN16 BIT(16) /*!< event from line 16 */
  90. #define EXTI_EVEN_EVEN17 BIT(17) /*!< event from line 17 */
  91. #define EXTI_EVEN_EVEN18 BIT(18) /*!< event from line 18 */
  92. #define EXTI_EVEN_EVEN19 BIT(19) /*!< event from line 19 */
  93. #define EXTI_EVEN_EVEN20 BIT(20) /*!< event from line 20 */
  94. #define EXTI_EVEN_EVEN21 BIT(21) /*!< event from line 21 */
  95. #define EXTI_EVEN_EVEN22 BIT(22) /*!< event from line 22 */
  96. #define EXTI_EVEN_EVEN23 BIT(23) /*!< event from line 23 */
  97. #define EXTI_EVEN_EVEN24 BIT(24) /*!< event from line 24 */
  98. #define EXTI_EVEN_EVEN25 BIT(25) /*!< event from line 25 */
  99. #define EXTI_EVEN_EVEN26 BIT(26) /*!< event from line 26 */
  100. #define EXTI_EVEN_EVEN27 BIT(27) /*!< event from line 27 */
  101. /* EXTI_RTEN */
  102. #define EXTI_RTEN_RTEN0 BIT(0) /*!< rising edge from line 0 */
  103. #define EXTI_RTEN_RTEN1 BIT(1) /*!< rising edge from line 1 */
  104. #define EXTI_RTEN_RTEN2 BIT(2) /*!< rising edge from line 2 */
  105. #define EXTI_RTEN_RTEN3 BIT(3) /*!< rising edge from line 3 */
  106. #define EXTI_RTEN_RTEN4 BIT(4) /*!< rising edge from line 4 */
  107. #define EXTI_RTEN_RTEN5 BIT(5) /*!< rising edge from line 5 */
  108. #define EXTI_RTEN_RTEN6 BIT(6) /*!< rising edge from line 6 */
  109. #define EXTI_RTEN_RTEN7 BIT(7) /*!< rising edge from line 7 */
  110. #define EXTI_RTEN_RTEN8 BIT(8) /*!< rising edge from line 8 */
  111. #define EXTI_RTEN_RTEN9 BIT(9) /*!< rising edge from line 9 */
  112. #define EXTI_RTEN_RTEN10 BIT(10) /*!< rising edge from line 10 */
  113. #define EXTI_RTEN_RTEN11 BIT(11) /*!< rising edge from line 11 */
  114. #define EXTI_RTEN_RTEN12 BIT(12) /*!< rising edge from line 12 */
  115. #define EXTI_RTEN_RTEN13 BIT(13) /*!< rising edge from line 13 */
  116. #define EXTI_RTEN_RTEN14 BIT(14) /*!< rising edge from line 14 */
  117. #define EXTI_RTEN_RTEN15 BIT(15) /*!< rising edge from line 15 */
  118. #define EXTI_RTEN_RTEN16 BIT(16) /*!< rising edge from line 16 */
  119. #define EXTI_RTEN_RTEN17 BIT(17) /*!< rising edge from line 17 */
  120. #define EXTI_RTEN_RTEN19 BIT(19) /*!< rising edge from line 19 */
  121. #define EXTI_RTEN_RTEN21 BIT(21) /*!< rising edge from line 21 */
  122. /* EXTI_FTEN */
  123. #define EXTI_FTEN_FTEN0 BIT(0) /*!< falling edge from line 0 */
  124. #define EXTI_FTEN_FTEN1 BIT(1) /*!< falling edge from line 1 */
  125. #define EXTI_FTEN_FTEN2 BIT(2) /*!< falling edge from line 2 */
  126. #define EXTI_FTEN_FTEN3 BIT(3) /*!< falling edge from line 3 */
  127. #define EXTI_FTEN_FTEN4 BIT(4) /*!< falling edge from line 4 */
  128. #define EXTI_FTEN_FTEN5 BIT(5) /*!< falling edge from line 5 */
  129. #define EXTI_FTEN_FTEN6 BIT(6) /*!< falling edge from line 6 */
  130. #define EXTI_FTEN_FTEN7 BIT(7) /*!< falling edge from line 7 */
  131. #define EXTI_FTEN_FTEN8 BIT(8) /*!< falling edge from line 8 */
  132. #define EXTI_FTEN_FTEN9 BIT(9) /*!< falling edge from line 9 */
  133. #define EXTI_FTEN_FTEN10 BIT(10) /*!< falling edge from line 10 */
  134. #define EXTI_FTEN_FTEN11 BIT(11) /*!< falling edge from line 11 */
  135. #define EXTI_FTEN_FTEN12 BIT(12) /*!< falling edge from line 12 */
  136. #define EXTI_FTEN_FTEN13 BIT(13) /*!< falling edge from line 13 */
  137. #define EXTI_FTEN_FTEN14 BIT(14) /*!< falling edge from line 14 */
  138. #define EXTI_FTEN_FTEN15 BIT(15) /*!< falling edge from line 15 */
  139. #define EXTI_FTEN_FTEN16 BIT(16) /*!< falling edge from line 16 */
  140. #define EXTI_FTEN_FTEN17 BIT(17) /*!< falling edge from line 17 */
  141. #define EXTI_FTEN_FTEN19 BIT(19) /*!< falling edge from line 19 */
  142. #define EXTI_FTEN_FTEN21 BIT(21) /*!< falling edge from line 21 */
  143. /* EXTI_SWIEV */
  144. #define EXTI_SWIEV_SWIEV0 BIT(0) /*!< software interrupt/event request from line 0 */
  145. #define EXTI_SWIEV_SWIEV1 BIT(1) /*!< software interrupt/event request from line 1 */
  146. #define EXTI_SWIEV_SWIEV2 BIT(2) /*!< software interrupt/event request from line 2 */
  147. #define EXTI_SWIEV_SWIEV3 BIT(3) /*!< software interrupt/event request from line 3 */
  148. #define EXTI_SWIEV_SWIEV4 BIT(4) /*!< software interrupt/event request from line 4 */
  149. #define EXTI_SWIEV_SWIEV5 BIT(5) /*!< software interrupt/event request from line 5 */
  150. #define EXTI_SWIEV_SWIEV6 BIT(6) /*!< software interrupt/event request from line 6 */
  151. #define EXTI_SWIEV_SWIEV7 BIT(7) /*!< software interrupt/event request from line 7 */
  152. #define EXTI_SWIEV_SWIEV8 BIT(8) /*!< software interrupt/event request from line 8 */
  153. #define EXTI_SWIEV_SWIEV9 BIT(9) /*!< software interrupt/event request from line 9 */
  154. #define EXTI_SWIEV_SWIEV10 BIT(10) /*!< software interrupt/event request from line 10 */
  155. #define EXTI_SWIEV_SWIEV11 BIT(11) /*!< software interrupt/event request from line 11 */
  156. #define EXTI_SWIEV_SWIEV12 BIT(12) /*!< software interrupt/event request from line 12 */
  157. #define EXTI_SWIEV_SWIEV13 BIT(13) /*!< software interrupt/event request from line 13 */
  158. #define EXTI_SWIEV_SWIEV14 BIT(14) /*!< software interrupt/event request from line 14 */
  159. #define EXTI_SWIEV_SWIEV15 BIT(15) /*!< software interrupt/event request from line 15 */
  160. #define EXTI_SWIEV_SWIEV16 BIT(16) /*!< software interrupt/event request from line 16 */
  161. #define EXTI_SWIEV_SWIEV17 BIT(17) /*!< software interrupt/event request from line 17 */
  162. #define EXTI_SWIEV_SWIEV19 BIT(19) /*!< software interrupt/event request from line 19 */
  163. #define EXTI_SWIEV_SWIEV21 BIT(21) /*!< software interrupt/event request from line 21 */
  164. /* EXTI_PD */
  165. #define EXTI_PD_PD0 BIT(0) /*!< interrupt/event pending status from line 0 */
  166. #define EXTI_PD_PD1 BIT(1) /*!< interrupt/event pending status from line 1 */
  167. #define EXTI_PD_PD2 BIT(2) /*!< interrupt/event pending status from line 2 */
  168. #define EXTI_PD_PD3 BIT(3) /*!< interrupt/event pending status from line 3 */
  169. #define EXTI_PD_PD4 BIT(4) /*!< interrupt/event pending status from line 4 */
  170. #define EXTI_PD_PD5 BIT(5) /*!< interrupt/event pending status from line 5 */
  171. #define EXTI_PD_PD6 BIT(6) /*!< interrupt/event pending status from line 6 */
  172. #define EXTI_PD_PD7 BIT(7) /*!< interrupt/event pending status from line 7 */
  173. #define EXTI_PD_PD8 BIT(8) /*!< interrupt/event pending status from line 8 */
  174. #define EXTI_PD_PD9 BIT(9) /*!< interrupt/event pending status from line 9 */
  175. #define EXTI_PD_PD10 BIT(10) /*!< interrupt/event pending status from line 10 */
  176. #define EXTI_PD_PD11 BIT(11) /*!< interrupt/event pending status from line 11 */
  177. #define EXTI_PD_PD12 BIT(12) /*!< interrupt/event pending status from line 12 */
  178. #define EXTI_PD_PD13 BIT(13) /*!< interrupt/event pending status from line 13 */
  179. #define EXTI_PD_PD14 BIT(14) /*!< interrupt/event pending status from line 14 */
  180. #define EXTI_PD_PD15 BIT(15) /*!< interrupt/event pending status from line 15 */
  181. #define EXTI_PD_PD16 BIT(16) /*!< interrupt/event pending status from line 16 */
  182. #define EXTI_PD_PD17 BIT(17) /*!< interrupt/event pending status from line 17 */
  183. #define EXTI_PD_PD19 BIT(19) /*!< interrupt/event pending status from line 19 */
  184. #define EXTI_PD_PD21 BIT(21) /*!< interrupt/event pending status from line 21 */
  185. /* constants definitions */
  186. /* EXTI line number */
  187. typedef enum
  188. {
  189. EXTI_0 = BIT(0), /*!< EXTI line 0 */
  190. EXTI_1 = BIT(1), /*!< EXTI line 1 */
  191. EXTI_2 = BIT(2), /*!< EXTI line 2 */
  192. EXTI_3 = BIT(3), /*!< EXTI line 3 */
  193. EXTI_4 = BIT(4), /*!< EXTI line 4 */
  194. EXTI_5 = BIT(5), /*!< EXTI line 5 */
  195. EXTI_6 = BIT(6), /*!< EXTI line 6 */
  196. EXTI_7 = BIT(7), /*!< EXTI line 7 */
  197. EXTI_8 = BIT(8), /*!< EXTI line 8 */
  198. EXTI_9 = BIT(9), /*!< EXTI line 9 */
  199. EXTI_10 = BIT(10), /*!< EXTI line 10 */
  200. EXTI_11 = BIT(11), /*!< EXTI line 11 */
  201. EXTI_12 = BIT(12), /*!< EXTI line 12 */
  202. EXTI_13 = BIT(13), /*!< EXTI line 13 */
  203. EXTI_14 = BIT(14), /*!< EXTI line 14 */
  204. EXTI_15 = BIT(15), /*!< EXTI line 15 */
  205. EXTI_16 = BIT(16), /*!< EXTI line 16 */
  206. EXTI_17 = BIT(17), /*!< EXTI line 17 */
  207. EXTI_18 = BIT(18), /*!< EXTI line 18 */
  208. EXTI_19 = BIT(19), /*!< EXTI line 19 */
  209. EXTI_20 = BIT(20), /*!< EXTI line 20 */
  210. EXTI_21 = BIT(21), /*!< EXTI line 21 */
  211. EXTI_22 = BIT(22), /*!< EXTI line 22 */
  212. EXTI_23 = BIT(23), /*!< EXTI line 23 */
  213. EXTI_24 = BIT(24), /*!< EXTI line 24 */
  214. EXTI_25 = BIT(25), /*!< EXTI line 25 */
  215. EXTI_26 = BIT(26), /*!< EXTI line 26 */
  216. EXTI_27 = BIT(27), /*!< EXTI line 27 */
  217. }exti_line_enum;
  218. /* external interrupt and event */
  219. typedef enum
  220. {
  221. EXTI_INTERRUPT = 0, /*!< EXTI interrupt mode */
  222. EXTI_EVENT /*!< EXTI event mode */
  223. }exti_mode_enum;
  224. /* interrupt trigger mode */
  225. typedef enum
  226. {
  227. EXTI_TRIG_RISING = 0, /*!< EXTI rising edge trigger */
  228. EXTI_TRIG_FALLING, /*!< EXTI falling edge trigger */
  229. EXTI_TRIG_BOTH, /*!< EXTI rising and falling edge trigger */
  230. EXTI_TRIG_NONE /*!< without rising edge or falling edge trigger */
  231. }exti_trig_type_enum;
  232. /* function declarations */
  233. /* initialization functions */
  234. /* reset the value of all EXTI registers with initial values */
  235. void exti_deinit(void);
  236. /* initialize EXTI line x */
  237. void exti_init(exti_line_enum linex, exti_mode_enum mode, exti_trig_type_enum trig_type);
  238. /* enable functions */
  239. /* enable the interrupts from EXTI line x */
  240. void exti_interrupt_enable(exti_line_enum linex);
  241. /* disable the interrupts from EXTI line x */
  242. void exti_interrupt_disable(exti_line_enum linex);
  243. /* enable the events from EXTI line x */
  244. void exti_event_enable(exti_line_enum linex);
  245. /* disable the events from EXTI line x */
  246. void exti_event_disable(exti_line_enum linex);
  247. /* interrupt & flag functions */
  248. /* enable EXTI software interrupt event */
  249. void exti_software_interrupt_enable(exti_line_enum linex);
  250. /* disable EXTI software interrupt event */
  251. void exti_software_interrupt_disable(exti_line_enum linex);
  252. /* get EXTI line x pending flag */
  253. FlagStatus exti_flag_get(exti_line_enum linex);
  254. /* clear EXTI lines pending flag */
  255. void exti_flag_clear(exti_line_enum linex);
  256. /* get EXTI lines flag when the interrupt flag is set */
  257. FlagStatus exti_interrupt_flag_get(exti_line_enum linex);
  258. /* clear EXTI lines pending flag */
  259. void exti_interrupt_flag_clear(exti_line_enum linex);
  260. #endif /* GD32E23X_EXTI_H */