at32f413_gpio.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /**
  2. **************************************************************************
  3. * @file at32f413_gpio.h
  4. * @version v2.0.5
  5. * @date 2022-05-20
  6. * @brief at32f413 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 __AT32F413_GPIO_H
  28. #define __AT32F413_GPIO_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* includes ------------------------------------------------------------------*/
  33. #include "at32f413.h"
  34. /** @addtogroup AT32F413_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(pb0) */
  70. #define I2C1_MUX I2C1_GMUX_0001 /*!< i2c1_scl(pb8), i2c1_sda(pb9) */
  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 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) */
  74. #define TMR2_MUX_01 TMR2_GMUX_001 /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pa2), tmr2_ch4(pa3) */
  75. #define TMR2_MUX_10 TMR2_GMUX_010 /*!< tmr2_ch1_ext(pa0), tmr2_ch2(pa1), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  76. #define TMR2_MUX_11 TMR2_GMUX_011 /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  77. #define TMR3_MUX_10 TMR3_GMUX_0010 /*!< tmr3_ch1(pb4), tmr3_ch2(pb5), tmr3_ch3(pb0), tmr3_ch4(pb1) */
  78. #define TMR3_MUX_11 TMR3_GMUX_0011 /*!< tmr3_ch1(pc6), tmr3_ch2(pc7), tmr3_ch3(pc8), tmr3_ch4(pc9) */
  79. #define CAN_MUX_10 CAN1_GMUX_0010 /*!< can_rx(pb8), can_tx(pb9) */
  80. #define PD01_MUX PD01_GMUX /*!< pd0/pd1 mapping on osc_in/osc_out */
  81. #define TMR5CH4_MUX TMR5CH4_GMUX /*!< lick connected to tmr5_ch4 input capture for calibration */
  82. #define ADC1_ETP_MUX ADC1_ETP_GMUX /*!< adc1 external trigger preempted conversion muxing */
  83. #define ADC1_ETO_MUX ADC1_ETO_GMUX /*!< adc1 external trigger ordinary conversion muxing */
  84. #define ADC2_ETP_MUX ADC2_ETP_GMUX /*!< adc2 external trigger preempted conversion muxing */
  85. #define ADC2_ETO_MUX ADC2_ETO_GMUX /*!< adc2 external trigger ordinary conversion muxing */
  86. #define SWJTAG_CONF_001 SWJTAG_GMUX_001 /*!< full swj enabled (jtag-dp + sw-dp) but without jtrst */
  87. #define SWJTAG_CONF_010 SWJTAG_GMUX_010 /*!< jtag-dp disabled and sw-dp enabled */
  88. #define SWJTAG_CONF_100 SWJTAG_GMUX_100 /*!< full swj disabled (jtag-dp + sw-dp) */
  89. /**
  90. * @}
  91. */
  92. /** @defgroup IOMUX_map2_definition
  93. * @brief iomux map2 definitions
  94. * @{
  95. */
  96. #define EXT_SPIM_EN_MUX EXT_SPIM_GMUX_1000 /*!< enable external spi-flash interface */
  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 TMR2_GMUX_001 IOMUX_MAKE_VALUE(0x24, 4, 3, 0x01) /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pa2), tmr2_ch4(pa3) */
  116. #define TMR2_GMUX_010 IOMUX_MAKE_VALUE(0x24, 4, 3, 0x02) /*!< tmr2_ch1_ext(pa0), tmr2_ch2(pa1), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  117. #define TMR2_GMUX_011 IOMUX_MAKE_VALUE(0x24, 4, 3, 0x03) /*!< tmr2_ch1_ext(pa15), tmr2_ch2(pb3), tmr2_ch3(pb10), tmr2_ch4(pb11) */
  118. #define TMR2ITR1_GMUX IOMUX_MAKE_VALUE(0x24, 7, 1, 0x01) /*!< usbdev sof as input to tmr2_int.1 */
  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) */
  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) */
  131. #define I2C1_GMUX_0011 IOMUX_MAKE_VALUE(0x28, 4, 4, 0x03) /*!< i2c1_scl(pf6), i2c1_sda(pf7) */
  132. #define I2C2_GMUX_0001 IOMUX_MAKE_VALUE(0x28, 8, 4, 0x01) /*!< i2c2_scl(pf6), i2c2_sda(pf7) */
  133. #define I2C2_GMUX_0010 IOMUX_MAKE_VALUE(0x28, 8, 4, 0x01) /*!< i2c2_scl(pa8), i2c2_sda(pc9) */
  134. #define I2C2_GMUX_0011 IOMUX_MAKE_VALUE(0x28, 8, 4, 0x01) /*!< i2c2_scl(pa8), i2c2_sda(pb4) */
  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 CAN2_GMUX_0001 IOMUX_MAKE_VALUE(0x2C, 4, 4, 0x01) /*!< can2_rx(pb5), can2_tx(pb6) */
  146. #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) */
  147. #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) */
  148. #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) */
  149. #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) */
  150. #define USART1_GMUX_0001 IOMUX_MAKE_VALUE(0x2C, 16, 4, 0x01) /*!< usart1_tx(pb6), usart1_rx(pb7) */
  151. #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) */
  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 EXT_SPIM_GMUX_1000 IOMUX_MAKE_VALUE(0x30, 0, 4, 0x08) /*!< spim_sck(pb1), spim_cs(pa8), spim_io0(pa11), spim_io1(pa12), spim_io2(pb7), spim_sio3(pb6) */
  161. #define EXT_SPIM_GMUX_1001 IOMUX_MAKE_VALUE(0x30, 0, 4, 0x09) /*!< spim_sck(pb1), spim_cs(pa8), spim_io0(pb10), spim_io1(pb11), spim_io2(pb7), spim_sio3(pb6) */
  162. #define ADC1_ETP_GMUX IOMUX_MAKE_VALUE(0x30, 4, 1, 0x01) /*!< adc1 external trigger preempted conversion muxing */
  163. #define ADC1_ETO_GMUX IOMUX_MAKE_VALUE(0x30, 5, 1, 0x01) /*!< adc1 external trigger ordinary conversion muxing */
  164. #define ADC2_ETP_GMUX IOMUX_MAKE_VALUE(0x30, 8, 1, 0x01) /*!< adc2 external trigger preempted conversion muxing */
  165. #define ADC2_ETO_GMUX IOMUX_MAKE_VALUE(0x30, 9, 1, 0x01) /*!< adc2 external trigger ordinary conversion muxing */
  166. #define SWJTAG_GMUX_001 IOMUX_MAKE_VALUE(0x30, 16, 3, 0x01) /*!< full swj enabled (jtag-dp + sw-dp) but without jtrst */
  167. #define SWJTAG_GMUX_010 IOMUX_MAKE_VALUE(0x30, 16, 3, 0x02) /*!< jtag-dp disabled and sw-dp enabled */
  168. #define SWJTAG_GMUX_100 IOMUX_MAKE_VALUE(0x30, 16, 3, 0x04) /*!< full swj disabled (jtag-dp + sw-dp) */
  169. #define PD01_GMUX IOMUX_MAKE_VALUE(0x30, 20, 1, 0x01) /*!< pd0/pd1 mapping on osc_in/osc_out */
  170. /**
  171. * @}
  172. */
  173. /** @defgroup GPIO_exported_types
  174. * @{
  175. */
  176. /**
  177. * @brief gpio mode select
  178. */
  179. typedef enum
  180. {
  181. GPIO_MODE_INPUT = 0x00, /*!< gpio input mode */
  182. GPIO_MODE_OUTPUT = 0x10, /*!< gpio output mode */
  183. GPIO_MODE_MUX = 0x08, /*!< gpio mux function mode */
  184. GPIO_MODE_ANALOG = 0x03 /*!< gpio analog in/out mode */
  185. } gpio_mode_type;
  186. /**
  187. * @brief gpio output drive strength select
  188. */
  189. typedef enum
  190. {
  191. GPIO_DRIVE_STRENGTH_STRONGER = 0x01, /*!< stronger sourcing/sinking strength */
  192. GPIO_DRIVE_STRENGTH_MODERATE = 0x02, /*!< moderate sourcing/sinking strength */
  193. GPIO_DRIVE_STRENGTH_MAXIMUM = 0x03 /*!< maximum sourcing/sinking strength */
  194. } gpio_drive_type;
  195. /**
  196. * @brief gpio output type
  197. */
  198. typedef enum
  199. {
  200. GPIO_OUTPUT_PUSH_PULL = 0x00, /*!< output push-pull */
  201. GPIO_OUTPUT_OPEN_DRAIN = 0x04 /*!< output open-drain */
  202. } gpio_output_type;
  203. /**
  204. * @brief gpio pull type
  205. */
  206. typedef enum
  207. {
  208. GPIO_PULL_NONE = 0x0004, /*!< floating for input, no pull for output */
  209. GPIO_PULL_UP = 0x0018, /*!< pull-up */
  210. GPIO_PULL_DOWN = 0x0028 /*!< pull-down */
  211. } gpio_pull_type;
  212. /**
  213. * @brief gpio pins source type
  214. */
  215. typedef enum
  216. {
  217. GPIO_PINS_SOURCE0 = 0x00, /*!< gpio pins source number 0 */
  218. GPIO_PINS_SOURCE1 = 0x01, /*!< gpio pins source number 1 */
  219. GPIO_PINS_SOURCE2 = 0x02, /*!< gpio pins source number 2 */
  220. GPIO_PINS_SOURCE3 = 0x03, /*!< gpio pins source number 3 */
  221. GPIO_PINS_SOURCE4 = 0x04, /*!< gpio pins source number 4 */
  222. GPIO_PINS_SOURCE5 = 0x05, /*!< gpio pins source number 5 */
  223. GPIO_PINS_SOURCE6 = 0x06, /*!< gpio pins source number 6 */
  224. GPIO_PINS_SOURCE7 = 0x07, /*!< gpio pins source number 7 */
  225. GPIO_PINS_SOURCE8 = 0x08, /*!< gpio pins source number 8 */
  226. GPIO_PINS_SOURCE9 = 0x09, /*!< gpio pins source number 9 */
  227. GPIO_PINS_SOURCE10 = 0x0A, /*!< gpio pins source number 10 */
  228. GPIO_PINS_SOURCE11 = 0x0B, /*!< gpio pins source number 11 */
  229. GPIO_PINS_SOURCE12 = 0x0C, /*!< gpio pins source number 12 */
  230. GPIO_PINS_SOURCE13 = 0x0D, /*!< gpio pins source number 13 */
  231. GPIO_PINS_SOURCE14 = 0x0E, /*!< gpio pins source number 14 */
  232. GPIO_PINS_SOURCE15 = 0x0F /*!< gpio pins source number 15 */
  233. } gpio_pins_source_type;
  234. /**
  235. * @brief gpio port source type
  236. */
  237. typedef enum
  238. {
  239. GPIO_PORT_SOURCE_GPIOA = 0x00, /*!< gpio port source gpioa */
  240. GPIO_PORT_SOURCE_GPIOB = 0x01, /*!< gpio port source gpiob */
  241. GPIO_PORT_SOURCE_GPIOC = 0x02, /*!< gpio port source gpioc */
  242. GPIO_PORT_SOURCE_GPIOD = 0x03, /*!< gpio port source gpiod */
  243. GPIO_PORT_SOURCE_GPIOF = 0x05, /*!< gpio port source gpiof */
  244. } gpio_port_source_type;
  245. /**
  246. * @brief gpio init type
  247. */
  248. typedef struct
  249. {
  250. uint32_t gpio_pins; /*!< pins number selection */
  251. gpio_output_type gpio_out_type; /*!< output type selection */
  252. gpio_pull_type gpio_pull; /*!< pull type selection */
  253. gpio_mode_type gpio_mode; /*!< mode selection */
  254. gpio_drive_type gpio_drive_strength; /*!< drive strength selection */
  255. } gpio_init_type;
  256. /**
  257. * @brief type define gpio register all
  258. */
  259. typedef struct
  260. {
  261. /**
  262. * @brief gpio cfglr register, offset:0x00
  263. */
  264. union
  265. {
  266. __IO uint32_t cfglr;
  267. struct
  268. {
  269. __IO uint32_t iomc0 : 2; /* [1:0] */
  270. __IO uint32_t iofc0 : 2; /* [3:2] */
  271. __IO uint32_t iomc1 : 2; /* [5:4] */
  272. __IO uint32_t iofc1 : 2; /* [7:6] */
  273. __IO uint32_t iomc2 : 2; /* [9:8] */
  274. __IO uint32_t iofc2 : 2; /* [11:10] */
  275. __IO uint32_t iomc3 : 2; /* [13:12] */
  276. __IO uint32_t iofc3 : 2; /* [15:14] */
  277. __IO uint32_t iomc4 : 2; /* [17:16] */
  278. __IO uint32_t iofc4 : 2; /* [19:18] */
  279. __IO uint32_t iomc5 : 2; /* [21:20] */
  280. __IO uint32_t iofc5 : 2; /* [23:22] */
  281. __IO uint32_t iomc6 : 2; /* [25:24] */
  282. __IO uint32_t iofc6 : 2; /* [27:26] */
  283. __IO uint32_t iomc7 : 2; /* [29:28] */
  284. __IO uint32_t iofc7 : 2; /* [31:30] */
  285. } cfglr_bit;
  286. };
  287. /**
  288. * @brief gpio cfghr register, offset:0x04
  289. */
  290. union
  291. {
  292. __IO uint32_t cfghr;
  293. struct
  294. {
  295. __IO uint32_t iomc8 : 2; /* [1:0] */
  296. __IO uint32_t iofc8 : 2; /* [3:2] */
  297. __IO uint32_t iomc9 : 2; /* [5:4] */
  298. __IO uint32_t iofc9 : 2; /* [7:6] */
  299. __IO uint32_t iomc10 : 2; /* [9:8] */
  300. __IO uint32_t iofc10 : 2; /* [11:10] */
  301. __IO uint32_t iomc11 : 2; /* [13:12] */
  302. __IO uint32_t iofc11 : 2; /* [15:14] */
  303. __IO uint32_t iomc12 : 2; /* [17:16] */
  304. __IO uint32_t iofc12 : 2; /* [19:18] */
  305. __IO uint32_t iomc13 : 2; /* [21:20] */
  306. __IO uint32_t iofc13 : 2; /* [23:22] */
  307. __IO uint32_t iomc14 : 2; /* [25:24] */
  308. __IO uint32_t iofc14 : 2; /* [27:26] */
  309. __IO uint32_t iomc15 : 2; /* [29:28] */
  310. __IO uint32_t iofc15 : 2; /* [31:30] */
  311. } cfghr_bit;
  312. };
  313. /**
  314. * @brief gpio idt register, offset:0x08
  315. */
  316. union
  317. {
  318. __IO uint32_t idt;
  319. struct
  320. {
  321. __IO uint32_t idt0 : 1; /* [0] */
  322. __IO uint32_t idt1 : 1; /* [1] */
  323. __IO uint32_t idt2 : 1; /* [2] */
  324. __IO uint32_t idt3 : 1; /* [3] */
  325. __IO uint32_t idt4 : 1; /* [4] */
  326. __IO uint32_t idt5 : 1; /* [5] */
  327. __IO uint32_t idt6 : 1; /* [6] */
  328. __IO uint32_t idt7 : 1; /* [7] */
  329. __IO uint32_t idt8 : 1; /* [8] */
  330. __IO uint32_t idt9 : 1; /* [9] */
  331. __IO uint32_t idt10 : 1; /* [10] */
  332. __IO uint32_t idt11 : 1; /* [11] */
  333. __IO uint32_t idt12 : 1; /* [12] */
  334. __IO uint32_t idt13 : 1; /* [13] */
  335. __IO uint32_t idt14 : 1; /* [14] */
  336. __IO uint32_t idt15 : 1; /* [15] */
  337. __IO uint32_t reserved1 : 16;/* [31:16] */
  338. } idt_bit;
  339. };
  340. /**
  341. * @brief gpio odt register, offset:0x0C
  342. */
  343. union
  344. {
  345. __IO uint32_t odt;
  346. struct
  347. {
  348. __IO uint32_t odt0 : 1; /* [0] */
  349. __IO uint32_t odt1 : 1; /* [1] */
  350. __IO uint32_t odt2 : 1; /* [2] */
  351. __IO uint32_t odt3 : 1; /* [3] */
  352. __IO uint32_t odt4 : 1; /* [4] */
  353. __IO uint32_t odt5 : 1; /* [5] */
  354. __IO uint32_t odt6 : 1; /* [6] */
  355. __IO uint32_t odt7 : 1; /* [7] */
  356. __IO uint32_t odt8 : 1; /* [8] */
  357. __IO uint32_t odt9 : 1; /* [9] */
  358. __IO uint32_t odt10 : 1; /* [10] */
  359. __IO uint32_t odt11 : 1; /* [11] */
  360. __IO uint32_t odt12 : 1; /* [12] */
  361. __IO uint32_t odt13 : 1; /* [13] */
  362. __IO uint32_t odt14 : 1; /* [14] */
  363. __IO uint32_t odt15 : 1; /* [15] */
  364. __IO uint32_t reserved1 : 16;/* [31:16] */
  365. } odt_bit;
  366. };
  367. /**
  368. * @brief gpio scr register, offset:0x10
  369. */
  370. union
  371. {
  372. __IO uint32_t scr;
  373. struct
  374. {
  375. __IO uint32_t iosb0 : 1; /* [0] */
  376. __IO uint32_t iosb1 : 1; /* [1] */
  377. __IO uint32_t iosb2 : 1; /* [2] */
  378. __IO uint32_t iosb3 : 1; /* [3] */
  379. __IO uint32_t iosb4 : 1; /* [4] */
  380. __IO uint32_t iosb5 : 1; /* [5] */
  381. __IO uint32_t iosb6 : 1; /* [6] */
  382. __IO uint32_t iosb7 : 1; /* [7] */
  383. __IO uint32_t iosb8 : 1; /* [8] */
  384. __IO uint32_t iosb9 : 1; /* [9] */
  385. __IO uint32_t iosb10 : 1; /* [10] */
  386. __IO uint32_t iosb11 : 1; /* [11] */
  387. __IO uint32_t iosb12 : 1; /* [12] */
  388. __IO uint32_t iosb13 : 1; /* [13] */
  389. __IO uint32_t iosb14 : 1; /* [14] */
  390. __IO uint32_t iosb15 : 1; /* [15] */
  391. __IO uint32_t iocb0 : 1; /* [16] */
  392. __IO uint32_t iocb1 : 1; /* [17] */
  393. __IO uint32_t iocb2 : 1; /* [18] */
  394. __IO uint32_t iocb3 : 1; /* [19] */
  395. __IO uint32_t iocb4 : 1; /* [20] */
  396. __IO uint32_t iocb5 : 1; /* [21] */
  397. __IO uint32_t iocb6 : 1; /* [22] */
  398. __IO uint32_t iocb7 : 1; /* [23] */
  399. __IO uint32_t iocb8 : 1; /* [24] */
  400. __IO uint32_t iocb9 : 1; /* [25] */
  401. __IO uint32_t iocb10 : 1; /* [26] */
  402. __IO uint32_t iocb11 : 1; /* [27] */
  403. __IO uint32_t iocb12 : 1; /* [28] */
  404. __IO uint32_t iocb13 : 1; /* [29] */
  405. __IO uint32_t iocb14 : 1; /* [30] */
  406. __IO uint32_t iocb15 : 1; /* [31] */
  407. } scr_bit;
  408. };
  409. /**
  410. * @brief gpio clr register, offset:0x14
  411. */
  412. union
  413. {
  414. __IO uint32_t clr;
  415. struct
  416. {
  417. __IO uint32_t iocb0 : 1; /* [0] */
  418. __IO uint32_t iocb1 : 1; /* [1] */
  419. __IO uint32_t iocb2 : 1; /* [2] */
  420. __IO uint32_t iocb3 : 1; /* [3] */
  421. __IO uint32_t iocb4 : 1; /* [4] */
  422. __IO uint32_t iocb5 : 1; /* [5] */
  423. __IO uint32_t iocb6 : 1; /* [6] */
  424. __IO uint32_t iocb7 : 1; /* [7] */
  425. __IO uint32_t iocb8 : 1; /* [8] */
  426. __IO uint32_t iocb9 : 1; /* [9] */
  427. __IO uint32_t iocb10 : 1; /* [10] */
  428. __IO uint32_t iocb11 : 1; /* [11] */
  429. __IO uint32_t iocb12 : 1; /* [12] */
  430. __IO uint32_t iocb13 : 1; /* [13] */
  431. __IO uint32_t iocb14 : 1; /* [14] */
  432. __IO uint32_t iocb15 : 1; /* [15] */
  433. __IO uint32_t reserved1 : 16;/* [31:16] */
  434. } clr_bit;
  435. };
  436. /**
  437. * @brief gpio wpr register, offset:0x18
  438. */
  439. union
  440. {
  441. __IO uint32_t wpr;
  442. struct
  443. {
  444. __IO uint32_t wpen0 : 1; /* [0] */
  445. __IO uint32_t wpen1 : 1; /* [1] */
  446. __IO uint32_t wpen2 : 1; /* [2] */
  447. __IO uint32_t wpen3 : 1; /* [3] */
  448. __IO uint32_t wpen4 : 1; /* [4] */
  449. __IO uint32_t wpen5 : 1; /* [5] */
  450. __IO uint32_t wpen6 : 1; /* [6] */
  451. __IO uint32_t wpen7 : 1; /* [7] */
  452. __IO uint32_t wpen8 : 1; /* [8] */
  453. __IO uint32_t wpen9 : 1; /* [9] */
  454. __IO uint32_t wpen10 : 1; /* [10] */
  455. __IO uint32_t wpen11 : 1; /* [11] */
  456. __IO uint32_t wpen12 : 1; /* [12] */
  457. __IO uint32_t wpen13 : 1; /* [13] */
  458. __IO uint32_t wpen14 : 1; /* [14] */
  459. __IO uint32_t wpen15 : 1; /* [15] */
  460. __IO uint32_t wpseq : 1; /* [16] */
  461. __IO uint32_t reserved1 : 15;/* [31:17] */
  462. } wpr_bit;
  463. };
  464. } gpio_type;
  465. /**
  466. * @brief type define iomux register all
  467. */
  468. typedef struct
  469. {
  470. /**
  471. * @brief mux event control register, offset:0x00
  472. */
  473. union
  474. {
  475. __IO uint32_t evtout;
  476. struct
  477. {
  478. __IO uint32_t selpin : 4; /* [3:0] */
  479. __IO uint32_t selport : 3; /* [6:4] */
  480. __IO uint32_t evoen : 1; /* [7] */
  481. __IO uint32_t reserved1 : 24;/* [31:8] */
  482. } evtout_bit;
  483. };
  484. /**
  485. * @brief iomux remap register, offset:0x04
  486. */
  487. union
  488. {
  489. __IO uint32_t remap;
  490. struct
  491. {
  492. __IO uint32_t spi1_mux_l : 1; /* [0] */
  493. __IO uint32_t i2c1_mux : 1; /* [1] */
  494. __IO uint32_t usart1_mux : 1; /* [2] */
  495. __IO uint32_t reserved1 : 1; /* [3] */
  496. __IO uint32_t usart3_mux : 2; /* [5:4] */
  497. __IO uint32_t tmr1_mux : 2; /* [7:6] */
  498. __IO uint32_t tmr2_mux : 2; /* [9:8] */
  499. __IO uint32_t tmr3_mux : 2; /* [11:10] */
  500. __IO uint32_t reserved2 : 1; /* [12] */
  501. __IO uint32_t can_mux : 2; /* [14:13] */
  502. __IO uint32_t pd01_mux : 1; /* [15] */
  503. __IO uint32_t tmr5ch4_mux : 1; /* [16] */
  504. __IO uint32_t adc1_extrgpre_mux : 1; /* [17] */
  505. __IO uint32_t adc1_extrgord_mux : 1; /* [18] */
  506. __IO uint32_t adc2_extrgpre_mux : 1; /* [19] */
  507. __IO uint32_t adc2_extrgord_mux : 1; /* [20] */
  508. __IO uint32_t reserved3 : 3; /* [23:21] */
  509. __IO uint32_t swjtag_conf : 3; /* [26:24] */
  510. __IO uint32_t reserved4 : 4; /* [30:27] */
  511. __IO uint32_t spi1_mux_h : 1; /* [31] */
  512. } remap_bit;
  513. };
  514. /**
  515. * @brief mux external interrupt configuration register 1, offset:0x08
  516. */
  517. union
  518. {
  519. __IO uint32_t exintc1;
  520. struct
  521. {
  522. __IO uint32_t exint0 : 4; /* [3:0] */
  523. __IO uint32_t exint1 : 4; /* [7:4] */
  524. __IO uint32_t exint2 : 4; /* [11:8] */
  525. __IO uint32_t exint3 : 4; /* [15:12] */
  526. __IO uint32_t reserved1 : 16;/* [31:16] */
  527. } exintc1_bit;
  528. };
  529. /**
  530. * @brief mux external interrupt configuration register 2, offset:0x0c
  531. */
  532. union
  533. {
  534. __IO uint32_t exintc2;
  535. struct
  536. {
  537. __IO uint32_t exint4 : 4; /* [3:0] */
  538. __IO uint32_t exint5 : 4; /* [7:4] */
  539. __IO uint32_t exint6 : 4; /* [11:8] */
  540. __IO uint32_t exint7 : 4; /* [15:12] */
  541. __IO uint32_t reserved1 : 16;/* [31:16] */
  542. } exintc2_bit;
  543. };
  544. /**
  545. * @brief mux external interrupt configuration register 3, offset:0x10
  546. */
  547. union
  548. {
  549. __IO uint32_t exintc3;
  550. struct
  551. {
  552. __IO uint32_t exint8 : 4; /* [3:0] */
  553. __IO uint32_t exint9 : 4; /* [7:4] */
  554. __IO uint32_t exint10 : 4; /* [11:8] */
  555. __IO uint32_t exint11 : 4; /* [15:12] */
  556. __IO uint32_t reserved1 : 16;/* [31:16] */
  557. } exintc3_bit;
  558. };
  559. /**
  560. * @brief mux external interrupt configuration register 4, offset:0x14
  561. */
  562. union
  563. {
  564. __IO uint32_t exintc4;
  565. struct
  566. {
  567. __IO uint32_t exint12 : 4; /* [3:0] */
  568. __IO uint32_t exint13 : 4; /* [7:4] */
  569. __IO uint32_t exint14 : 4; /* [11:8] */
  570. __IO uint32_t exint15 : 4; /* [15:12] */
  571. __IO uint32_t reserved1 : 16;/* [31:16] */
  572. } exintc4_bit;
  573. };
  574. /**
  575. * @brief iomux reserved1 register, offset:0x18
  576. */
  577. __IO uint32_t reserved1;
  578. /**
  579. * @brief iomux remap register 2, offset:0x1C
  580. */
  581. union
  582. {
  583. __IO uint32_t remap2;
  584. struct
  585. {
  586. __IO uint32_t reserved1 : 21;/* [20:0] */
  587. __IO uint32_t ext_spim_en_mux : 1; /* [21] */
  588. __IO uint32_t reserved2 : 10;/* [31:22] */
  589. } remap2_bit;
  590. };
  591. /**
  592. * @brief iomux remap register 3, offset:0x20
  593. */
  594. union
  595. {
  596. __IO uint32_t remap3;
  597. struct
  598. {
  599. __IO uint32_t tmr9_gmux : 4; /* [3:0] */
  600. __IO uint32_t tmr10_gmux : 4; /* [7:4] */
  601. __IO uint32_t tmr11_gmux : 4; /* [11:8] */
  602. __IO uint32_t reserved1 : 20;/* [31:12] */
  603. } remap3_bit;
  604. };
  605. /**
  606. * @brief iomux remap register 4, offset:0x24
  607. */
  608. union
  609. {
  610. __IO uint32_t remap4;
  611. struct
  612. {
  613. __IO uint32_t tmr1_gmux : 4; /* [3:0] */
  614. __IO uint32_t tmr2_gmux : 3; /* [6:4] */
  615. __IO uint32_t tmr2itr1_gmux : 1; /* [7] */
  616. __IO uint32_t tmr3_gmux : 4; /* [11:8] */
  617. __IO uint32_t reserved1 : 4; /* [15:12] */
  618. __IO uint32_t tmr5_gmux : 3; /* [18:16] */
  619. __IO uint32_t tmr5ch4_gmux : 1; /* [19] */
  620. __IO uint32_t reserved2 : 12;/* [31:20] */
  621. } remap4_bit;
  622. };
  623. /**
  624. * @brief iomux remap register 5, offset:0x28
  625. */
  626. union
  627. {
  628. __IO uint32_t remap5;
  629. struct
  630. {
  631. __IO uint32_t reserved1 : 4; /* [3:0] */
  632. __IO uint32_t i2c1_gmux : 4; /* [7:4] */
  633. __IO uint32_t i2c2_gmux : 4; /* [11:8] */
  634. __IO uint32_t reserved2 : 4; /* [15:12] */
  635. __IO uint32_t spi1_gmux : 4; /* [19:16] */
  636. __IO uint32_t spi2_gmux : 4; /* [23:20] */
  637. __IO uint32_t reserved3 : 8; /* [31:24] */
  638. } remap5_bit;
  639. };
  640. /**
  641. * @brief iomux remap register 6, offset:0x2C
  642. */
  643. union
  644. {
  645. __IO uint32_t remap6;
  646. struct
  647. {
  648. __IO uint32_t can1_gmux : 4; /* [3:0] */
  649. __IO uint32_t can2_gmux : 4; /* [7:4] */
  650. __IO uint32_t sdio1_gmux : 4; /* [11:8] */
  651. __IO uint32_t reserved1 : 4; /* [15:12] */
  652. __IO uint32_t usart1_gmux : 4; /* [19:16] */
  653. __IO uint32_t reserved2 : 4; /* [23:20] */
  654. __IO uint32_t usart3_gmux : 4; /* [27:24] */
  655. __IO uint32_t uart4_gmux : 4; /* [31:28] */
  656. } remap6_bit;
  657. };
  658. /**
  659. * @brief iomux remap register 7, offset:0x30
  660. */
  661. union
  662. {
  663. __IO uint32_t remap7;
  664. struct
  665. {
  666. __IO uint32_t ext_spim_gmux : 3; /* [2:0] */
  667. __IO uint32_t ext_spim_gen : 1; /* [3] */
  668. __IO uint32_t adc1_etp_gmux : 1; /* [4] */
  669. __IO uint32_t adc1_eto_gmux : 1; /* [5] */
  670. __IO uint32_t reserved1 : 2; /* [7:6] */
  671. __IO uint32_t adc2_etp_gmux : 1; /* [8] */
  672. __IO uint32_t adc2_eto_gmux : 1; /* [9] */
  673. __IO uint32_t reserved2 : 6; /* [15:10] */
  674. __IO uint32_t swjtag_gmux : 3; /* [18:16] */
  675. __IO uint32_t reserved3 : 1; /* [19] */
  676. __IO uint32_t pd01_gmux : 1; /* [20] */
  677. __IO uint32_t reserved4 : 11;/* [31:21] */
  678. } remap7_bit;
  679. };
  680. } iomux_type;
  681. /**
  682. * @}
  683. */
  684. #define GPIOA ((gpio_type *) GPIOA_BASE)
  685. #define GPIOB ((gpio_type *) GPIOB_BASE)
  686. #define GPIOC ((gpio_type *) GPIOC_BASE)
  687. #define GPIOD ((gpio_type *) GPIOD_BASE)
  688. #define GPIOF ((gpio_type *) GPIOF_BASE)
  689. #define IOMUX ((iomux_type *) IOMUX_BASE)
  690. /** @defgroup GPIO_exported_functions
  691. * @{
  692. */
  693. void gpio_reset(gpio_type *gpio_x);
  694. void gpio_iomux_reset(void);
  695. void gpio_init(gpio_type *gpio_x, gpio_init_type *gpio_init_struct);
  696. void gpio_default_para_init(gpio_init_type *gpio_init_struct);
  697. flag_status gpio_input_data_bit_read(gpio_type *gpio_x, uint16_t pins);
  698. uint16_t gpio_input_data_read(gpio_type *gpio_x);
  699. flag_status gpio_output_data_bit_read(gpio_type *gpio_x, uint16_t pins);
  700. uint16_t gpio_output_data_read(gpio_type *gpio_x);
  701. void gpio_bits_set(gpio_type *gpio_x, uint16_t pins);
  702. void gpio_bits_reset(gpio_type *gpio_x, uint16_t pins);
  703. void gpio_bits_write(gpio_type *gpio_x, uint16_t pins, confirm_state bit_state);
  704. void gpio_port_wirte(gpio_type *gpio_x, uint16_t port_value);
  705. void gpio_pin_wp_config(gpio_type *gpio_x, uint16_t pins);
  706. void gpio_event_output_config(gpio_port_source_type gpio_port_source, gpio_pins_source_type gpio_pin_source);
  707. void gpio_event_output_enable(confirm_state new_state);
  708. void gpio_pin_remap_config(uint32_t gpio_remap, confirm_state new_state);
  709. void gpio_exint_line_config(gpio_port_source_type gpio_port_source, gpio_pins_source_type gpio_pin_source);
  710. /**
  711. * @}
  712. */
  713. /**
  714. * @}
  715. */
  716. /**
  717. * @}
  718. */
  719. #ifdef __cplusplus
  720. }
  721. #endif
  722. #endif