1
0

at32f415_gpio.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. /**
  2. **************************************************************************
  3. * @file at32f415_gpio.h
  4. * @version v2.0.5
  5. * @date 2022-05-20
  6. * @brief at32f415 gpio header file
  7. **************************************************************************
  8. * Copyright notice & Disclaimer
  9. *
  10. * The software Board Support Package (BSP) that is made available to
  11. * download from Artery official website is the copyrighted work of Artery.
  12. * Artery authorizes customers to use, copy, and distribute the BSP
  13. * software and its related documentation for the purpose of design and
  14. * development in conjunction with Artery microcontrollers. Use of the
  15. * software is governed by this copyright notice and the following disclaimer.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  18. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  19. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  20. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  21. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  23. *
  24. **************************************************************************
  25. */
  26. /* define to prevent recursive inclusion -------------------------------------*/
  27. #ifndef __AT32F415_GPIO_H
  28. #define __AT32F415_GPIO_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* includes ------------------------------------------------------------------*/
  33. #include "at32f415.h"
  34. /** @addtogroup AT32F415_periph_driver
  35. * @{
  36. */
  37. /** @addtogroup GPIO
  38. * @{
  39. */
  40. /** @defgroup GPIO_pins_number_definition
  41. * @{
  42. */
  43. #define GPIO_PINS_0 0x0001 /*!< gpio pins number 0 */
  44. #define GPIO_PINS_1 0x0002 /*!< gpio pins number 1 */
  45. #define GPIO_PINS_2 0x0004 /*!< gpio pins number 2 */
  46. #define GPIO_PINS_3 0x0008 /*!< gpio pins number 3 */
  47. #define GPIO_PINS_4 0x0010 /*!< gpio pins number 4 */
  48. #define GPIO_PINS_5 0x0020 /*!< gpio pins number 5 */
  49. #define GPIO_PINS_6 0x0040 /*!< gpio pins number 6 */
  50. #define GPIO_PINS_7 0x0080 /*!< gpio pins number 7 */
  51. #define GPIO_PINS_8 0x0100 /*!< gpio pins number 8 */
  52. #define GPIO_PINS_9 0x0200 /*!< gpio pins number 9 */
  53. #define GPIO_PINS_10 0x0400 /*!< gpio pins number 10 */
  54. #define GPIO_PINS_11 0x0800 /*!< gpio pins number 11 */
  55. #define GPIO_PINS_12 0x1000 /*!< gpio pins number 12 */
  56. #define GPIO_PINS_13 0x2000 /*!< gpio pins number 13 */
  57. #define GPIO_PINS_14 0x4000 /*!< gpio pins number 14 */
  58. #define GPIO_PINS_15 0x8000 /*!< gpio pins number 15 */
  59. #define GPIO_PINS_ALL 0xFFFF /*!< gpio all pins */
  60. /**
  61. * @}
  62. */
  63. #define IOMUX_MAKE_VALUE(reg_offset, bit_addr ,bit_num, bit_val) \
  64. (uint32_t)(((reg_offset) << 24) | ((bit_addr) << 16) | ((bit_num) << 8) | (bit_val))
  65. /** @defgroup IOMUX_map_definition
  66. * @brief iomux map definitions
  67. * @{
  68. */
  69. #define SPI1_MUX_01 SPI1_GMUX_0001 /*!< spi1_cs/i2s1_ws(pa15), spi1_sck/i2s1_ck(pb3), spi1_miso(pb4), spi1_mosi/i2s1_sd(pb5), i2s1_mck(pb6) */
  70. #define I2C1_MUX I2C1_GMUX_0001 /*!< i2c1_scl(pb8), i2c1_sda(pb9), i2c1_smba(pb5) */
  71. #define USART1_MUX USART1_GMUX_0001 /*!< usart1_tx(pb6), usart1_rx(pb7) */
  72. #define USART3_MUX_01 USART3_GMUX_0001 /*!< usart3_tx(pc10), usart3_rx(pc11), usart3_ck(pc12), usart3_cts(pb13), usart3_rts(pb14) */
  73. #define USART3_MUX_10 USART3_GMUX_0010 /*!< usart3_tx(pa7), usart3_rx(pa6), usart3_ck(pa5), usart3_cts(pb1), usart3_rts(pb0) */
  74. #define TMR1_MUX_01 TMR1_GMUX_0001 /*!< tmr1_ext(pa12), tmr1_ch1(pa8), tmr1_ch2(pa9), tmr1_ch3(pa10), tmr1_ch4(pa11), tmr1_brkin(pa6), tmr1_ch1c(pa7), tmr1_ch2c(pb0), tmr1_ch3c(pb1) */
  75. #define TMR2_MUX_01 TMR2_GMUX_001 /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pa2), tmr2_ch4(pa3) */
  76. #define TMR2_MUX_10 TMR2_GMUX_010 /*!< tmr2_ch1_ext(pa0), tmr2_ch2(pa1), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  77. #define TMR2_MUX_11 TMR2_GMUX_011 /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  78. #define TMR3_MUX_10 TMR3_GMUX_0010 /*!< tmr3_ch1(pb4), tmr3_ch2(pb5), tmr3_ch3(pb0), tmr3_ch4(pb1) */
  79. #define TMR3_MUX_11 TMR3_GMUX_0011 /*!< tmr3_ch1(pc6), tmr3_ch2(pc7), tmr3_ch3(pc8), tmr3_ch4(pc9) */
  80. #define CAN_MUX_10 CAN1_GMUX_0010 /*!< can_rx(pb8), can_tx(pb9) */
  81. #define PD01_MUX PD01_GMUX /*!< pd0/pd1 mapping on osc_in/osc_out */
  82. #define TMR5CH4_MUX TMR5CH4_GMUX /*!< lick connected to tmr5_ch4 input capture for calibration */
  83. #define ADC1_ETP_MUX ADC1_ETP_GMUX /*!< adc1 external trigger preempted conversion muxing */
  84. #define ADC1_ETO_MUX ADC1_ETO_GMUX /*!< adc1 external trigger ordinary conversion muxing */
  85. #define SWJTAG_MUX_001 SWJTAG_GMUX_001 /*!< full swj enabled (jtag-dp + sw-dp) but without jtrst */
  86. #define SWJTAG_MUX_010 SWJTAG_GMUX_010 /*!< jtag-dp disabled and sw-dp enabled */
  87. #define SWJTAG_MUX_100 SWJTAG_GMUX_100 /*!< full swj disabled (jtag-dp + sw-dp) */
  88. /**
  89. * @}
  90. */
  91. /** @defgroup IOMUX_map2_definition
  92. * @brief iomux map2 definitions
  93. * @{
  94. */
  95. #define CMP_MUX_01 IOMUX_MAKE_VALUE(0x1C, 26, 2, 0x01) /*!< cmp1_out connect pa6, cmp2_out connect pa7 */
  96. #define CMP_MUX_10 IOMUX_MAKE_VALUE(0x1C, 26, 2, 0x02) /*!< cmp1_out connect pa11, cmp2_out connect pa12 */
  97. /**
  98. * @}
  99. */
  100. /** @defgroup IOMUX_map3_definition
  101. * @brief iomux map3 definitions
  102. * @{
  103. */
  104. #define TMR9_GMUX IOMUX_MAKE_VALUE(0x20, 0, 4, 0x02) /*!< tmr9_ch1(pb14), tmr9_ch2(pb15) */
  105. #define TMR10_GMUX IOMUX_MAKE_VALUE(0x20, 4, 4, 0x02) /*!< tmr10_ch1(pa6) */
  106. #define TMR11_GMUX IOMUX_MAKE_VALUE(0x20, 8, 4, 0x02) /*!< tmr11_ch1(pa7) */
  107. /**
  108. * @}
  109. */
  110. /** @defgroup IOMUX_map4_definition
  111. * @brief iomux map4 definitions
  112. * @{
  113. */
  114. #define TMR1_GMUX_0001 IOMUX_MAKE_VALUE(0x24, 0, 4, 0x01) /*!< tmr1_ext(pa12), tmr1_ch1(pa8), tmr1_ch2(pa9), tmr1_ch3(pa10), tmr1_ch4(pa11), tmr1_brkin(pa6), tmr1_ch1c(pa7), tmr1_ch2c(pb0), tmr1_ch3c(pb1) */
  115. #define TMR1_GMUX_0010 IOMUX_MAKE_VALUE(0x24, 0, 4, 0x02) /*!< tmr1_ext(pa0), tmr1_ch1(pc6), tmr1_ch2(pc7), tmr1_ch3(pc8), tmr1_ch4(pc9), tmr1_brkin(pa6), tmr1_ch1c(pa7), tmr1_ch2c(pb0), tmr1_ch3c(pb1) */
  116. #define TMR2_GMUX_001 IOMUX_MAKE_VALUE(0x24, 4, 3, 0x01) /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pa2), tmr2_ch4(pa3) */
  117. #define TMR2_GMUX_010 IOMUX_MAKE_VALUE(0x24, 4, 3, 0x02) /*!< tmr2_ch1_ext(pa0), tmr2_ch2(pa1), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  118. #define TMR2_GMUX_011 IOMUX_MAKE_VALUE(0x24, 4, 3, 0x03) /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  119. #define TMR3_GMUX_0010 IOMUX_MAKE_VALUE(0x24, 8, 4, 0x02) /*!< tmr3_ch1(pb4), tmr3_ch2(pb5), tmr3_ch3(pb0), tmr3_ch4(pb1) */
  120. #define TMR3_GMUX_0011 IOMUX_MAKE_VALUE(0x24, 8, 4, 0x03) /*!< tmr3_ch1(pc6), tmr3_ch2(pc7), tmr3_ch3(pc8), tmr3_ch4(pc9) */
  121. #define TMR5_GMUX_001 IOMUX_MAKE_VALUE(0x24, 16, 3, 0x01) /*!< tmr5_ch1(pf4), tmr5_ch2(pf5), tmr5_ch3(pa2), tmr5_ch4(pa3) */
  122. #define TMR5CH4_GMUX IOMUX_MAKE_VALUE(0x24, 19, 1, 0x01) /*!< lick connected to tmr5_ch4 input capture for calibration */
  123. /**
  124. * @}
  125. */
  126. /** @defgroup IOMUX_map5_definition
  127. * @brief iomux map5 definitions
  128. * @{
  129. */
  130. #define I2C1_GMUX_0001 IOMUX_MAKE_VALUE(0x28, 4, 4, 0x01) /*!< i2c1_scl(pb8), i2c1_sda(pb9), i2c1_smba(pb5) */
  131. #define I2C1_GMUX_0010 IOMUX_MAKE_VALUE(0x28, 4, 4, 0x02) /*!< i2c1_scl(pf6), i2c1_sda(pf7), i2c1_smba(pb5) */
  132. #define I2C2_GMUX_0001 IOMUX_MAKE_VALUE(0x28, 8, 4, 0x01) /*!< i2c2_scl(pa8), i2c2_sda(pc9), i2c2_smba(pa9) */
  133. #define I2C2_GMUX_0010 IOMUX_MAKE_VALUE(0x28, 8, 4, 0x02) /*!< i2c2_scl(pa8), i2c2_sda(pb4), i2c2_smba(pa9) */
  134. #define I2C2_GMUX_0011 IOMUX_MAKE_VALUE(0x28, 8, 4, 0x03) /*!< i2c2_scl(pf6), i2c2_sda(pf7), i2c2_smba(pa9) */
  135. #define SPI1_GMUX_0001 IOMUX_MAKE_VALUE(0x28, 16, 4, 0x01) /*!< spi1_cs/i2s1_ws(pa15), spi1_sck/i2s1_ck(pb3), spi1_miso(pb4), spi1_mosi/i2s1_sd(pb5), i2s1_mck(pb6) */
  136. #define SPI2_GMUX_0001 IOMUX_MAKE_VALUE(0x28, 20, 4, 0x01) /*!< spi2_cs/i2s2_ws(pa15), spi2_sck/i2s2_ck(pb3), spi2_miso(pb4), spi2_mosi/i2s2_sd(pb5), i2s2_mck(pc7) */
  137. /**
  138. * @}
  139. */
  140. /** @defgroup IOMUX_map6_definition
  141. * @brief iomux map6 definitions
  142. * @{
  143. */
  144. #define CAN1_GMUX_0010 IOMUX_MAKE_VALUE(0x2C, 0, 4, 0x02) /*!< can_rx(pb8), can_tx(pb9) */
  145. #define SDIO1_GMUX_0100 IOMUX_MAKE_VALUE(0x2C, 8, 4, 0x04) /*!< sdio1_ck(pc4), sdio1_cmd(pc5), sdio1_d0(pc0), sdio1_d1(pc1), sdio1_d2(pc2), sdio1_d3(pc3), sdio1_d4(pa4), sdio1_d5(pa5), sdio1_d6(pa6), sdio1_d7(pa7) */
  146. #define SDIO1_GMUX_0101 IOMUX_MAKE_VALUE(0x2C, 8, 4, 0x05) /*!< sdio1_ck(pc4), sdio1_cmd(pc5), sdio1_d0(pa4), sdio1_d1(pa5), sdio1_d2(pa6), sdio1_d3(pa7) */
  147. #define SDIO1_GMUX_0110 IOMUX_MAKE_VALUE(0x2C, 8, 4, 0x06) /*!< sdio1_ck(pa2), sdio1_cmd(pa3), sdio1_d0(pc0), sdio1_d1(pc1), sdio1_d2(pc2), sdio1_d3(pc3), sdio1_d4(pa4), sdio1_d5(pa5), sdio1_d6(pa6), sdio1_d7(pa7) */
  148. #define SDIO1_GMUX_0111 IOMUX_MAKE_VALUE(0x2C, 8, 4, 0x07) /*!< sdio1_ck(pa2), sdio1_cmd(pa3), sdio1_d0(pa4), sdio1_d1(pa5), sdio1_d2(pa6), sdio1_d3(pa7) */
  149. #define USART1_GMUX_0001 IOMUX_MAKE_VALUE(0x2C, 16, 4, 0x01) /*!< usart1_tx(pb6), usart1_rx(pb7) */
  150. #define USART3_GMUX_0001 IOMUX_MAKE_VALUE(0x2C, 24, 4, 0x01) /*!< usart3_tx(pc10), usart3_rx(pc11), usart3_ck(pc12), usart3_cts(pb13), usart3_rts(pb14) */
  151. #define USART3_GMUX_0010 IOMUX_MAKE_VALUE(0x2C, 24, 4, 0x02) /*!< usart3_tx(pa7), usart3_rx(pa6), usart3_ck(pa5), usart3_cts(pb1), usart3_rts(pb0) */
  152. #define UART4_GMUX_0001 IOMUX_MAKE_VALUE(0x2C, 28, 4, 0x01) /*!< uart4_tx(pf4), uart4_rx(pf5) */
  153. /**
  154. * @}
  155. */
  156. /** @defgroup IOMUX_map7_definition
  157. * @brief iomux map7 definitions
  158. * @{
  159. */
  160. #define ADC1_ETP_GMUX IOMUX_MAKE_VALUE(0x30, 4, 1, 0x01) /*!< adc1 external trigger preempted conversion muxing */
  161. #define ADC1_ETO_GMUX IOMUX_MAKE_VALUE(0x30, 5, 1, 0x01) /*!< adc1 external trigger ordinary conversion muxing */
  162. #define SWJTAG_GMUX_001 IOMUX_MAKE_VALUE(0x30, 16, 3, 0x01) /*!< full swj enabled (jtag-dp + sw-dp) but without jtrst */
  163. #define SWJTAG_GMUX_010 IOMUX_MAKE_VALUE(0x30, 16, 3, 0x02) /*!< jtag-dp disabled and sw-dp enabled */
  164. #define SWJTAG_GMUX_100 IOMUX_MAKE_VALUE(0x30, 16, 3, 0x04) /*!< full swj disabled (jtag-dp + sw-dp) */
  165. #define PD01_GMUX IOMUX_MAKE_VALUE(0x30, 20, 1, 0x01) /*!< pd0/pd1 mapping on osc_in/osc_out */
  166. /**
  167. * @}
  168. */
  169. /** @defgroup IOMUX_map8_definition
  170. * @brief iomux map8 definitions
  171. * @{
  172. */
  173. #define TMR1_BK1_CMP_GMUX_10 IOMUX_MAKE_VALUE(0x34, 0, 2, 0x02) /*!< cmp tmr1_bpr1 connect tmr1 bk1 */
  174. #define TMR1_BK1_CMP_GMUX_11 IOMUX_MAKE_VALUE(0x34, 0, 2, 0x03) /*!< cmp tmr1_bpr1 and io connect tmr1 bk1 */
  175. #define TMR1_CH1_CMP_GMUX_10 IOMUX_MAKE_VALUE(0x34, 2, 2, 0x02) /*!< cmp connect tmr1 ch1 */
  176. #define TMR1_CH1_CMP_GMUX_11 IOMUX_MAKE_VALUE(0x34, 2, 2, 0x03) /*!< cmp and io connect tmr1 ch1 */
  177. #define TMR2_CH4_CMP_GMUX_10 IOMUX_MAKE_VALUE(0x34, 4, 2, 0x02) /*!< cmp connect tmr2 ch4 */
  178. #define TMR2_CH4_CMP_GMUX_11 IOMUX_MAKE_VALUE(0x34, 4, 2, 0x03) /*!< cmp and io connect tmr2 ch4 */
  179. #define TMR3_CH1_CMP_GMUX_10 IOMUX_MAKE_VALUE(0x34, 6, 2, 0x02) /*!< cmp connect tmr3 ch1 */
  180. #define TMR3_CH1_CMP_GMUX_11 IOMUX_MAKE_VALUE(0x34, 6, 2, 0x03) /*!< cmp and io connect tmr3 ch1 */
  181. /**
  182. * @}
  183. */
  184. /** @defgroup GPIO_exported_types
  185. * @{
  186. */
  187. /**
  188. * @brief gpio mode select
  189. */
  190. typedef enum
  191. {
  192. GPIO_MODE_INPUT = 0x00, /*!< gpio input mode */
  193. GPIO_MODE_OUTPUT = 0x10, /*!< gpio output mode */
  194. GPIO_MODE_MUX = 0x08, /*!< gpio mux function mode */
  195. GPIO_MODE_ANALOG = 0x03 /*!< gpio analog in/out mode */
  196. } gpio_mode_type;
  197. /**
  198. * @brief gpio output drive strength select
  199. */
  200. typedef enum
  201. {
  202. GPIO_DRIVE_STRENGTH_STRONGER = 0x01, /*!< stronger sourcing/sinking strength */
  203. GPIO_DRIVE_STRENGTH_MODERATE = 0x02, /*!< moderate sourcing/sinking strength */
  204. GPIO_DRIVE_STRENGTH_MAXIMUM = 0x03 /*!< maximum sourcing/sinking strength */
  205. } gpio_drive_type;
  206. /**
  207. * @brief gpio output type
  208. */
  209. typedef enum
  210. {
  211. GPIO_OUTPUT_PUSH_PULL = 0x00, /*!< output push-pull */
  212. GPIO_OUTPUT_OPEN_DRAIN = 0x04 /*!< output open-drain */
  213. } gpio_output_type;
  214. /**
  215. * @brief gpio pull type
  216. */
  217. typedef enum
  218. {
  219. GPIO_PULL_NONE = 0x0004, /*!< floating for input, no pull for output */
  220. GPIO_PULL_UP = 0x0018, /*!< pull-up */
  221. GPIO_PULL_DOWN = 0x0028 /*!< pull-down */
  222. } gpio_pull_type;
  223. /**
  224. * @brief gpio pins source type
  225. */
  226. typedef enum
  227. {
  228. GPIO_PINS_SOURCE0 = 0x00, /*!< gpio pins source number 0 */
  229. GPIO_PINS_SOURCE1 = 0x01, /*!< gpio pins source number 1 */
  230. GPIO_PINS_SOURCE2 = 0x02, /*!< gpio pins source number 2 */
  231. GPIO_PINS_SOURCE3 = 0x03, /*!< gpio pins source number 3 */
  232. GPIO_PINS_SOURCE4 = 0x04, /*!< gpio pins source number 4 */
  233. GPIO_PINS_SOURCE5 = 0x05, /*!< gpio pins source number 5 */
  234. GPIO_PINS_SOURCE6 = 0x06, /*!< gpio pins source number 6 */
  235. GPIO_PINS_SOURCE7 = 0x07, /*!< gpio pins source number 7 */
  236. GPIO_PINS_SOURCE8 = 0x08, /*!< gpio pins source number 8 */
  237. GPIO_PINS_SOURCE9 = 0x09, /*!< gpio pins source number 9 */
  238. GPIO_PINS_SOURCE10 = 0x0A, /*!< gpio pins source number 10 */
  239. GPIO_PINS_SOURCE11 = 0x0B, /*!< gpio pins source number 11 */
  240. GPIO_PINS_SOURCE12 = 0x0C, /*!< gpio pins source number 12 */
  241. GPIO_PINS_SOURCE13 = 0x0D, /*!< gpio pins source number 13 */
  242. GPIO_PINS_SOURCE14 = 0x0E, /*!< gpio pins source number 14 */
  243. GPIO_PINS_SOURCE15 = 0x0F /*!< gpio pins source number 15 */
  244. } gpio_pins_source_type;
  245. /**
  246. * @brief gpio port source type
  247. */
  248. typedef enum
  249. {
  250. GPIO_PORT_SOURCE_GPIOA = 0x00, /*!< gpio port source gpioa */
  251. GPIO_PORT_SOURCE_GPIOB = 0x01, /*!< gpio port source gpiob */
  252. GPIO_PORT_SOURCE_GPIOC = 0x02, /*!< gpio port source gpioc */
  253. GPIO_PORT_SOURCE_GPIOD = 0x03, /*!< gpio port source gpiod */
  254. GPIO_PORT_SOURCE_GPIOF = 0x05, /*!< gpio port source gpiof */
  255. } gpio_port_source_type;
  256. /**
  257. * @brief gpio init type
  258. */
  259. typedef struct
  260. {
  261. uint32_t gpio_pins; /*!< pins number selection */
  262. gpio_output_type gpio_out_type; /*!< output type selection */
  263. gpio_pull_type gpio_pull; /*!< pull type selection */
  264. gpio_mode_type gpio_mode; /*!< mode selection */
  265. gpio_drive_type gpio_drive_strength; /*!< drive strength selection */
  266. } gpio_init_type;
  267. /**
  268. * @brief type define gpio register all
  269. */
  270. typedef struct
  271. {
  272. /**
  273. * @brief gpio cfglr register, offset:0x00
  274. */
  275. union
  276. {
  277. __IO uint32_t cfglr;
  278. struct
  279. {
  280. __IO uint32_t iomc0 : 2; /* [1:0] */
  281. __IO uint32_t iofc0 : 2; /* [3:2] */
  282. __IO uint32_t iomc1 : 2; /* [5:4] */
  283. __IO uint32_t iofc1 : 2; /* [7:6] */
  284. __IO uint32_t iomc2 : 2; /* [9:8] */
  285. __IO uint32_t iofc2 : 2; /* [11:10] */
  286. __IO uint32_t iomc3 : 2; /* [13:12] */
  287. __IO uint32_t iofc3 : 2; /* [15:14] */
  288. __IO uint32_t iomc4 : 2; /* [17:16] */
  289. __IO uint32_t iofc4 : 2; /* [19:18] */
  290. __IO uint32_t iomc5 : 2; /* [21:20] */
  291. __IO uint32_t iofc5 : 2; /* [23:22] */
  292. __IO uint32_t iomc6 : 2; /* [25:24] */
  293. __IO uint32_t iofc6 : 2; /* [27:26] */
  294. __IO uint32_t iomc7 : 2; /* [29:28] */
  295. __IO uint32_t iofc7 : 2; /* [31:30] */
  296. } cfglr_bit;
  297. };
  298. /**
  299. * @brief gpio cfghr register, offset:0x04
  300. */
  301. union
  302. {
  303. __IO uint32_t cfghr;
  304. struct
  305. {
  306. __IO uint32_t iomc8 : 2; /* [1:0] */
  307. __IO uint32_t iofc8 : 2; /* [3:2] */
  308. __IO uint32_t iomc9 : 2; /* [5:4] */
  309. __IO uint32_t iofc9 : 2; /* [7:6] */
  310. __IO uint32_t iomc10 : 2; /* [9:8] */
  311. __IO uint32_t iofc10 : 2; /* [11:10] */
  312. __IO uint32_t iomc11 : 2; /* [13:12] */
  313. __IO uint32_t iofc11 : 2; /* [15:14] */
  314. __IO uint32_t iomc12 : 2; /* [17:16] */
  315. __IO uint32_t iofc12 : 2; /* [19:18] */
  316. __IO uint32_t iomc13 : 2; /* [21:20] */
  317. __IO uint32_t iofc13 : 2; /* [23:22] */
  318. __IO uint32_t iomc14 : 2; /* [25:24] */
  319. __IO uint32_t iofc14 : 2; /* [27:26] */
  320. __IO uint32_t iomc15 : 2; /* [29:28] */
  321. __IO uint32_t iofc15 : 2; /* [31:30] */
  322. } cfghr_bit;
  323. };
  324. /**
  325. * @brief gpio idt register, offset:0x08
  326. */
  327. union
  328. {
  329. __IO uint32_t idt;
  330. struct
  331. {
  332. __IO uint32_t idt0 : 1; /* [0] */
  333. __IO uint32_t idt1 : 1; /* [1] */
  334. __IO uint32_t idt2 : 1; /* [2] */
  335. __IO uint32_t idt3 : 1; /* [3] */
  336. __IO uint32_t idt4 : 1; /* [4] */
  337. __IO uint32_t idt5 : 1; /* [5] */
  338. __IO uint32_t idt6 : 1; /* [6] */
  339. __IO uint32_t idt7 : 1; /* [7] */
  340. __IO uint32_t idt8 : 1; /* [8] */
  341. __IO uint32_t idt9 : 1; /* [9] */
  342. __IO uint32_t idt10 : 1; /* [10] */
  343. __IO uint32_t idt11 : 1; /* [11] */
  344. __IO uint32_t idt12 : 1; /* [12] */
  345. __IO uint32_t idt13 : 1; /* [13] */
  346. __IO uint32_t idt14 : 1; /* [14] */
  347. __IO uint32_t idt15 : 1; /* [15] */
  348. __IO uint32_t reserved1 : 16;/* [31:16] */
  349. } idt_bit;
  350. };
  351. /**
  352. * @brief gpio odt register, offset:0x0C
  353. */
  354. union
  355. {
  356. __IO uint32_t odt;
  357. struct
  358. {
  359. __IO uint32_t odt0 : 1; /* [0] */
  360. __IO uint32_t odt1 : 1; /* [1] */
  361. __IO uint32_t odt2 : 1; /* [2] */
  362. __IO uint32_t odt3 : 1; /* [3] */
  363. __IO uint32_t odt4 : 1; /* [4] */
  364. __IO uint32_t odt5 : 1; /* [5] */
  365. __IO uint32_t odt6 : 1; /* [6] */
  366. __IO uint32_t odt7 : 1; /* [7] */
  367. __IO uint32_t odt8 : 1; /* [8] */
  368. __IO uint32_t odt9 : 1; /* [9] */
  369. __IO uint32_t odt10 : 1; /* [10] */
  370. __IO uint32_t odt11 : 1; /* [11] */
  371. __IO uint32_t odt12 : 1; /* [12] */
  372. __IO uint32_t odt13 : 1; /* [13] */
  373. __IO uint32_t odt14 : 1; /* [14] */
  374. __IO uint32_t odt15 : 1; /* [15] */
  375. __IO uint32_t reserved1 : 16;/* [31:16] */
  376. } odt_bit;
  377. };
  378. /**
  379. * @brief gpio scr register, offset:0x10
  380. */
  381. union
  382. {
  383. __IO uint32_t scr;
  384. struct
  385. {
  386. __IO uint32_t iosb0 : 1; /* [0] */
  387. __IO uint32_t iosb1 : 1; /* [1] */
  388. __IO uint32_t iosb2 : 1; /* [2] */
  389. __IO uint32_t iosb3 : 1; /* [3] */
  390. __IO uint32_t iosb4 : 1; /* [4] */
  391. __IO uint32_t iosb5 : 1; /* [5] */
  392. __IO uint32_t iosb6 : 1; /* [6] */
  393. __IO uint32_t iosb7 : 1; /* [7] */
  394. __IO uint32_t iosb8 : 1; /* [8] */
  395. __IO uint32_t iosb9 : 1; /* [9] */
  396. __IO uint32_t iosb10 : 1; /* [10] */
  397. __IO uint32_t iosb11 : 1; /* [11] */
  398. __IO uint32_t iosb12 : 1; /* [12] */
  399. __IO uint32_t iosb13 : 1; /* [13] */
  400. __IO uint32_t iosb14 : 1; /* [14] */
  401. __IO uint32_t iosb15 : 1; /* [15] */
  402. __IO uint32_t iocb0 : 1; /* [16] */
  403. __IO uint32_t iocb1 : 1; /* [17] */
  404. __IO uint32_t iocb2 : 1; /* [18] */
  405. __IO uint32_t iocb3 : 1; /* [19] */
  406. __IO uint32_t iocb4 : 1; /* [20] */
  407. __IO uint32_t iocb5 : 1; /* [21] */
  408. __IO uint32_t iocb6 : 1; /* [22] */
  409. __IO uint32_t iocb7 : 1; /* [23] */
  410. __IO uint32_t iocb8 : 1; /* [24] */
  411. __IO uint32_t iocb9 : 1; /* [25] */
  412. __IO uint32_t iocb10 : 1; /* [26] */
  413. __IO uint32_t iocb11 : 1; /* [27] */
  414. __IO uint32_t iocb12 : 1; /* [28] */
  415. __IO uint32_t iocb13 : 1; /* [29] */
  416. __IO uint32_t iocb14 : 1; /* [30] */
  417. __IO uint32_t iocb15 : 1; /* [31] */
  418. } scr_bit;
  419. };
  420. /**
  421. * @brief gpio clr register, offset:0x14
  422. */
  423. union
  424. {
  425. __IO uint32_t clr;
  426. struct
  427. {
  428. __IO uint32_t iocb0 : 1; /* [0] */
  429. __IO uint32_t iocb1 : 1; /* [1] */
  430. __IO uint32_t iocb2 : 1; /* [2] */
  431. __IO uint32_t iocb3 : 1; /* [3] */
  432. __IO uint32_t iocb4 : 1; /* [4] */
  433. __IO uint32_t iocb5 : 1; /* [5] */
  434. __IO uint32_t iocb6 : 1; /* [6] */
  435. __IO uint32_t iocb7 : 1; /* [7] */
  436. __IO uint32_t iocb8 : 1; /* [8] */
  437. __IO uint32_t iocb9 : 1; /* [9] */
  438. __IO uint32_t iocb10 : 1; /* [10] */
  439. __IO uint32_t iocb11 : 1; /* [11] */
  440. __IO uint32_t iocb12 : 1; /* [12] */
  441. __IO uint32_t iocb13 : 1; /* [13] */
  442. __IO uint32_t iocb14 : 1; /* [14] */
  443. __IO uint32_t iocb15 : 1; /* [15] */
  444. __IO uint32_t reserved1 : 16;/* [31:16] */
  445. } clr_bit;
  446. };
  447. /**
  448. * @brief gpio wpr register, offset:0x18
  449. */
  450. union
  451. {
  452. __IO uint32_t wpr;
  453. struct
  454. {
  455. __IO uint32_t wpen0 : 1; /* [0] */
  456. __IO uint32_t wpen1 : 1; /* [1] */
  457. __IO uint32_t wpen2 : 1; /* [2] */
  458. __IO uint32_t wpen3 : 1; /* [3] */
  459. __IO uint32_t wpen4 : 1; /* [4] */
  460. __IO uint32_t wpen5 : 1; /* [5] */
  461. __IO uint32_t wpen6 : 1; /* [6] */
  462. __IO uint32_t wpen7 : 1; /* [7] */
  463. __IO uint32_t wpen8 : 1; /* [8] */
  464. __IO uint32_t wpen9 : 1; /* [9] */
  465. __IO uint32_t wpen10 : 1; /* [10] */
  466. __IO uint32_t wpen11 : 1; /* [11] */
  467. __IO uint32_t wpen12 : 1; /* [12] */
  468. __IO uint32_t wpen13 : 1; /* [13] */
  469. __IO uint32_t wpen14 : 1; /* [14] */
  470. __IO uint32_t wpen15 : 1; /* [15] */
  471. __IO uint32_t wpseq : 1; /* [16] */
  472. __IO uint32_t reserved1 : 15;/* [31:17] */
  473. } wpr_bit;
  474. };
  475. } gpio_type;
  476. /**
  477. * @brief type define iomux register all
  478. */
  479. typedef struct
  480. {
  481. /**
  482. * @brief mux event control register, offset:0x00
  483. */
  484. union
  485. {
  486. __IO uint32_t evtout;
  487. struct
  488. {
  489. __IO uint32_t selpin : 4; /* [3:0] */
  490. __IO uint32_t selport : 3; /* [6:4] */
  491. __IO uint32_t evoen : 1; /* [7] */
  492. __IO uint32_t reserved1 : 24;/* [31:8] */
  493. } evtout_bit;
  494. };
  495. /**
  496. * @brief iomux remap register, offset:0x04
  497. */
  498. union
  499. {
  500. __IO uint32_t remap;
  501. struct
  502. {
  503. __IO uint32_t spi1_mux_l : 1; /* [0] */
  504. __IO uint32_t i2c1_mux : 1; /* [1] */
  505. __IO uint32_t usart1_mux : 1; /* [2] */
  506. __IO uint32_t reserved1 : 1; /* [3] */
  507. __IO uint32_t usart3_mux : 2; /* [5:4] */
  508. __IO uint32_t tmr1_mux : 2; /* [7:6] */
  509. __IO uint32_t tmr2_mux : 2; /* [9:8] */
  510. __IO uint32_t tmr3_mux : 2; /* [11:10] */
  511. __IO uint32_t reserved2 : 1; /* [12] */
  512. __IO uint32_t can_mux : 2; /* [14:13] */
  513. __IO uint32_t pd01_mux : 1; /* [15] */
  514. __IO uint32_t tmr5ch4_mux : 1; /* [16] */
  515. __IO uint32_t adc1_extrgpre_mux : 1; /* [17] */
  516. __IO uint32_t adc1_extrgord_mux : 1; /* [18] */
  517. __IO uint32_t reserved3 : 5; /* [23:19] */
  518. __IO uint32_t swjtag_conf : 3; /* [26:24] */
  519. __IO uint32_t reserved4 : 4; /* [30:27] */
  520. __IO uint32_t spi1_mux_h : 1; /* [31] */
  521. } remap_bit;
  522. };
  523. /**
  524. * @brief mux external interrupt configuration register 1, offset:0x08
  525. */
  526. union
  527. {
  528. __IO uint32_t exintc1;
  529. struct
  530. {
  531. __IO uint32_t exint0 : 4; /* [3:0] */
  532. __IO uint32_t exint1 : 4; /* [7:4] */
  533. __IO uint32_t exint2 : 4; /* [11:8] */
  534. __IO uint32_t exint3 : 4; /* [15:12] */
  535. __IO uint32_t reserved1 : 16;/* [31:16] */
  536. } exintc1_bit;
  537. };
  538. /**
  539. * @brief mux external interrupt configuration register 2, offset:0x0c
  540. */
  541. union
  542. {
  543. __IO uint32_t exintc2;
  544. struct
  545. {
  546. __IO uint32_t exint4 : 4; /* [3:0] */
  547. __IO uint32_t exint5 : 4; /* [7:4] */
  548. __IO uint32_t exint6 : 4; /* [11:8] */
  549. __IO uint32_t exint7 : 4; /* [15:12] */
  550. __IO uint32_t reserved1 : 16;/* [31:16] */
  551. } exintc2_bit;
  552. };
  553. /**
  554. * @brief mux external interrupt configuration register 3, offset:0x10
  555. */
  556. union
  557. {
  558. __IO uint32_t exintc3;
  559. struct
  560. {
  561. __IO uint32_t exint8 : 4; /* [3:0] */
  562. __IO uint32_t exint9 : 4; /* [7:4] */
  563. __IO uint32_t exint10 : 4; /* [11:8] */
  564. __IO uint32_t exint11 : 4; /* [15:12] */
  565. __IO uint32_t reserved1 : 16;/* [31:16] */
  566. } exintc3_bit;
  567. };
  568. /**
  569. * @brief mux external interrupt configuration register 4, offset:0x14
  570. */
  571. union
  572. {
  573. __IO uint32_t exintc4;
  574. struct
  575. {
  576. __IO uint32_t exint12 : 4; /* [3:0] */
  577. __IO uint32_t exint13 : 4; /* [7:4] */
  578. __IO uint32_t exint14 : 4; /* [11:8] */
  579. __IO uint32_t exint15 : 4; /* [15:12] */
  580. __IO uint32_t reserved1 : 16;/* [31:16] */
  581. } exintc4_bit;
  582. };
  583. /**
  584. * @brief iomux reserved1 register, offset:0x18
  585. */
  586. __IO uint32_t reserved1;
  587. /**
  588. * @brief iomux remap register 2, offset:0x1C
  589. */
  590. union
  591. {
  592. __IO uint32_t remap2;
  593. struct
  594. {
  595. __IO uint32_t reserved1 : 26;/* [25:0] */
  596. __IO uint32_t cmp_mux : 2; /* [27:26] */
  597. __IO uint32_t reserved2 : 4; /* [31:28] */
  598. } remap2_bit;
  599. };
  600. /**
  601. * @brief iomux remap register 3, offset:0x20
  602. */
  603. union
  604. {
  605. __IO uint32_t remap3;
  606. struct
  607. {
  608. __IO uint32_t tmr9_gmux : 4; /* [3:0] */
  609. __IO uint32_t tmr10_gmux : 4; /* [7:4] */
  610. __IO uint32_t tmr11_gmux : 4; /* [11:8] */
  611. __IO uint32_t reserved1 : 20;/* [31:12] */
  612. } remap3_bit;
  613. };
  614. /**
  615. * @brief iomux remap register 4, offset:0x24
  616. */
  617. union
  618. {
  619. __IO uint32_t remap4;
  620. struct
  621. {
  622. __IO uint32_t tmr1_gmux : 4; /* [3:0] */
  623. __IO uint32_t tmr2_gmux : 3; /* [6:4] */
  624. __IO uint32_t reserved1 : 1; /* [7] */
  625. __IO uint32_t tmr3_gmux : 4; /* [11:8] */
  626. __IO uint32_t reserved2 : 4; /* [15:12] */
  627. __IO uint32_t tmr5_gmux : 3; /* [18:16] */
  628. __IO uint32_t tmr5ch4_gmux : 1; /* [19] */
  629. __IO uint32_t reserved3 : 12;/* [31:20] */
  630. } remap4_bit;
  631. };
  632. /**
  633. * @brief iomux remap register 5, offset:0x28
  634. */
  635. union
  636. {
  637. __IO uint32_t remap5;
  638. struct
  639. {
  640. __IO uint32_t reserved1 : 4; /* [3:0] */
  641. __IO uint32_t i2c1_gmux : 4; /* [7:4] */
  642. __IO uint32_t i2c2_gmux : 4; /* [11:8] */
  643. __IO uint32_t reserved2 : 4; /* [15:12] */
  644. __IO uint32_t spi1_gmux : 4; /* [19:16] */
  645. __IO uint32_t spi2_gmux : 4; /* [23:20] */
  646. __IO uint32_t reserved3 : 8; /* [31:24] */
  647. } remap5_bit;
  648. };
  649. /**
  650. * @brief iomux remap register 6, offset:0x2C
  651. */
  652. union
  653. {
  654. __IO uint32_t remap6;
  655. struct
  656. {
  657. __IO uint32_t can1_gmux : 4; /* [3:0] */
  658. __IO uint32_t reserved1 : 4; /* [7:4] */
  659. __IO uint32_t sdio1_gmux : 4; /* [11:8] */
  660. __IO uint32_t reserved2 : 4; /* [15:12] */
  661. __IO uint32_t usart1_gmux : 4; /* [19:16] */
  662. __IO uint32_t reserved3 : 4; /* [23:20] */
  663. __IO uint32_t usart3_gmux : 4; /* [27:24] */
  664. __IO uint32_t uart4_gmux : 4; /* [31:28] */
  665. } remap6_bit;
  666. };
  667. /**
  668. * @brief iomux remap register 7, offset:0x30
  669. */
  670. union
  671. {
  672. __IO uint32_t remap7;
  673. struct
  674. {
  675. __IO uint32_t reserved1 : 4; /* [3:0] */
  676. __IO uint32_t adc1_etp_gmux : 1; /* [4] */
  677. __IO uint32_t adc1_eto_gmux : 1; /* [5] */
  678. __IO uint32_t reserved2 : 10;/* [15:6] */
  679. __IO uint32_t swjtag_gmux : 3; /* [18:16] */
  680. __IO uint32_t reserved3 : 1; /* [19] */
  681. __IO uint32_t pd01_gmux : 1; /* [20] */
  682. __IO uint32_t reserved4 : 11;/* [31:21] */
  683. } remap7_bit;
  684. };
  685. /**
  686. * @brief iomux remap register 8, offset:0x34
  687. */
  688. union
  689. {
  690. __IO uint32_t remap8;
  691. struct
  692. {
  693. __IO uint32_t tmr1_bk1_cmp_gmux : 2; /* [1:0] */
  694. __IO uint32_t tmr1_ch1_cmp_gmux : 2; /* [3:2] */
  695. __IO uint32_t tmr2_ch4_cmp_gmux : 2; /* [5:4] */
  696. __IO uint32_t tmr3_ch1_cmp_gmux : 2; /* [7:6] */
  697. __IO uint32_t reserved1 : 24;/* [31:8] */
  698. } remap8_bit;
  699. };
  700. } iomux_type;
  701. /**
  702. * @}
  703. */
  704. #define GPIOA ((gpio_type *) GPIOA_BASE)
  705. #define GPIOB ((gpio_type *) GPIOB_BASE)
  706. #define GPIOC ((gpio_type *) GPIOC_BASE)
  707. #define GPIOD ((gpio_type *) GPIOD_BASE)
  708. #define GPIOF ((gpio_type *) GPIOF_BASE)
  709. #define IOMUX ((iomux_type *) IOMUX_BASE)
  710. /** @defgroup GPIO_exported_functions
  711. * @{
  712. */
  713. void gpio_reset(gpio_type *gpio_x);
  714. void gpio_iomux_reset(void);
  715. void gpio_init(gpio_type *gpio_x, gpio_init_type *gpio_init_struct);
  716. void gpio_default_para_init(gpio_init_type *gpio_init_struct);
  717. flag_status gpio_input_data_bit_read(gpio_type *gpio_x, uint16_t pins);
  718. uint16_t gpio_input_data_read(gpio_type *gpio_x);
  719. flag_status gpio_output_data_bit_read(gpio_type *gpio_x, uint16_t pins);
  720. uint16_t gpio_output_data_read(gpio_type *gpio_x);
  721. void gpio_bits_set(gpio_type *gpio_x, uint16_t pins);
  722. void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins);
  723. void gpio_bits_write(gpio_type *gpio_x, uint16_t pins, confirm_state bit_state);
  724. void gpio_port_wirte(gpio_type *gpio_x, uint16_t port_value);
  725. void gpio_pin_wp_config(gpio_type *gpio_x, uint16_t pins);
  726. void gpio_event_output_config(gpio_port_source_type gpio_port_source, gpio_pins_source_type gpio_pin_source);
  727. void gpio_event_output_enable(confirm_state new_state);
  728. void gpio_pin_remap_config(uint32_t gpio_remap, confirm_state new_state);
  729. void gpio_exint_line_config(gpio_port_source_type gpio_port_source, gpio_pins_source_type gpio_pin_source);
  730. /**
  731. * @}
  732. */
  733. /**
  734. * @}
  735. */
  736. /**
  737. * @}
  738. */
  739. #ifdef __cplusplus
  740. }
  741. #endif
  742. #endif