hc32f460_gpio.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*****************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_gpio.h
  11. **
  12. ** A detailed description is available at
  13. ** @link GpioGroup Gpio description @endlink
  14. **
  15. ** - 2018-10-12 CDT First version for Device Driver Library of Gpio.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_GPIO_H__
  19. #define __HC32F460_GPIO_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_GPIO_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. ** \defgroup GpioGroup General Purpose Input/Output(GPIO)
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. /**
  41. *******************************************************************************
  42. ** \brief GPIO Configuration Mode enumeration
  43. **
  44. ******************************************************************************/
  45. typedef enum en_pin_mode
  46. {
  47. Pin_Mode_In = 0, ///< GPIO Input mode
  48. Pin_Mode_Out = 1, ///< GPIO Output mode
  49. Pin_Mode_Ana = 2, ///< GPIO Analog mode
  50. }en_pin_mode_t;
  51. /**
  52. *******************************************************************************
  53. ** \brief GPIO Drive Capacity enumeration
  54. **
  55. ******************************************************************************/
  56. typedef enum en_pin_drv
  57. {
  58. Pin_Drv_L = 0, ///< Low Drive Capacity
  59. Pin_Drv_M = 1, ///< Middle Drive Capacity
  60. Pin_Drv_H = 2, ///< High Drive Capacity
  61. }en_pin_drv_t;
  62. /**
  63. *******************************************************************************
  64. ** \brief GPIO Output Type enumeration
  65. ******************************************************************************/
  66. typedef enum en_pin_o_type
  67. {
  68. Pin_OType_Cmos = 0, ///< CMOS
  69. Pin_OType_Od = 1, ///< Open Drain
  70. }en_pin_o_type_t;
  71. typedef enum en_debug_port
  72. {
  73. TCK_SWCLK = 1 << 0, ///< TCK or SWCLK
  74. TMS_SWDIO = 1 << 1, ///< TMS or SWDIO
  75. TDO_SWO = 1 << 2, ///< TOD or SWD
  76. TDI = 1 << 3, ///< TDI
  77. TRST = 1 << 4, ///< TRest
  78. ALL_DBG_PIN = 0x1Fu ///< All above
  79. }en_debug_port_t;
  80. /**
  81. *******************************************************************************
  82. ** \brief GPIO Port Index enumeration
  83. ******************************************************************************/
  84. typedef enum en_port
  85. {
  86. PortA = 0, ///< port group A
  87. PortB = 1, ///< port group B
  88. PortC = 2, ///< port group C
  89. PortD = 3, ///< port group D
  90. PortE = 4, ///< port group E
  91. PortH = 5, ///< port group H
  92. }en_port_t;
  93. /**
  94. *******************************************************************************
  95. ** \brief GPIO Pin Index enumeration
  96. ******************************************************************************/
  97. typedef enum en_pin
  98. {
  99. Pin00 = (1 << 0), ///< Pin index 00 of each port group
  100. Pin01 = (1 << 1), ///< Pin index 01 of each port group
  101. Pin02 = (1 << 2), ///< Pin index 02 of each port group
  102. Pin03 = (1 << 3), ///< Pin index 03 of each port group
  103. Pin04 = (1 << 4), ///< Pin index 04 of each port group
  104. Pin05 = (1 << 5), ///< Pin index 05 of each port group
  105. Pin06 = (1 << 6), ///< Pin index 06 of each port group
  106. Pin07 = (1 << 7), ///< Pin index 07 of each port group
  107. Pin08 = (1 << 8), ///< Pin index 08 of each port group
  108. Pin09 = (1 << 9), ///< Pin index 09 of each port group
  109. Pin10 = (1 << 10), ///< Pin index 10 of each port group
  110. Pin11 = (1 << 11), ///< Pin index 11 of each port group
  111. Pin12 = (1 << 12), ///< Pin index 12 of each port group
  112. Pin13 = (1 << 13), ///< Pin index 13 of each port group
  113. Pin14 = (1 << 14), ///< Pin index 14 of each port group
  114. Pin15 = (1 << 15), ///< Pin index 15 of each port group
  115. PinAll= 0xFFFF, ///< All pins selected
  116. }en_pin_t;
  117. /**
  118. *******************************************************************************
  119. ** \brief GPIO Pin read wait cycle enumeration
  120. ******************************************************************************/
  121. typedef enum en_read_wait
  122. {
  123. WaitCycle0 = 0, ///< no wait cycle, operation freq. lower than 42MHz
  124. WaitCycle1 = 1, ///< one wait cycle, operation freq. @[42~84)MHz
  125. WaitCycle2 = 2, ///< two wait cycles, operation freq. @[84~126)MHz
  126. WaitCycle3 = 3, ///< three wait cycles, operation freq. @[126~200)MHz
  127. }en_read_wait_t;
  128. /**
  129. *******************************************************************************
  130. ** \brief GPIO Function enumeration
  131. ******************************************************************************/
  132. typedef enum en_port_func
  133. {
  134. Func_Gpio = 0u, ///< function set to gpio
  135. Func_Fcmref = 1u, ///< function set to fcm reference
  136. Func_Rtcout = 1u, ///< function set to rtc output
  137. Func_Vcout = 1u, ///< function set to vc output
  138. Func_Adtrg = 1u, ///< function set to adc trigger
  139. Func_Mclkout = 1u, ///< function set to mclk output
  140. Func_Tim4 = 2u, ///< function set to timer4
  141. Func_Tim6 = 3u, ///< function set to timer6
  142. Func_Tima0 = 4u, ///< function set to timerA
  143. Func_Tima1 = 5u, ///< function set to timerA
  144. Func_Tima2 = 6u, ///< function set to timerA
  145. Func_Emb = 6u, ///< function set to emb
  146. Func_Usart_Ck = 7u, ///< function set to usart clk
  147. Func_Spi_Nss = 7u, ///< function set to spi nss
  148. Func_Qspi = 7u, ///< function set to qspi
  149. Func_Key = 8u, ///< function set to key
  150. Func_Sdio = 9u, ///< function set to sdio
  151. Func_I2s = 10u, ///< function set to i2s
  152. Func_UsbF = 10u, ///< function set to usb full speed
  153. Func_Evnpt = 14u, ///< function set to event port
  154. Func_Eventout = 15u, ///< function set to event out
  155. Func_Usart1_Tx = 32u, ///< function set to usart tx of ch.1
  156. Func_Usart3_Tx = 32u, ///< function set to usart tx of ch.3
  157. Func_Usart1_Rx = 33u, ///< function set to usart rx of ch.1
  158. Func_Usart3_Rx = 33u, ///< function set to usart rx of ch.3
  159. Func_Usart1_Rts = 34u, ///< function set to usart rts of ch.1
  160. Func_Usart3_Rts = 34u, ///< function set to usart rts of ch.3
  161. Func_Usart1_Cts = 35u, ///< function set to usart cts of ch.1
  162. Func_Usart3_Cts = 35u, ///< function set to usart cts of ch.3
  163. Func_Usart2_Tx = 36u, ///< function set to usart tx of ch.2
  164. Func_Usart4_Tx = 36u, ///< function set to usart tx of ch.4
  165. Func_Usart2_Rx = 37u, ///< function set to usart rx of ch.2
  166. Func_Usart4_Rx = 37u, ///< function set to usart rx of ch.4
  167. Func_Usart2_Rts = 38u, ///< function set to usart rts of ch.2
  168. Func_Usart4_Rts = 38u, ///< function set to usart rts of ch.4
  169. Func_Usart2_Cts = 39u, ///< function set to usart cts of ch.2
  170. Func_Usart4_Cts = 39u, ///< function set to usart cts of ch.4
  171. Func_Spi1_Mosi = 40u, ///< function set to spi mosi of ch.1
  172. Func_Spi3_Mosi = 40u, ///< function set to spi mosi of ch.3
  173. Func_Spi1_Miso = 41u, ///< function set to spi miso of ch.1
  174. Func_Spi3_Miso = 41u, ///< function set to spi miso of ch.3
  175. Func_Spi1_Nss0 = 42u, ///< function set to spi nss0 of ch.1
  176. Func_Spi3_Nss0 = 42u, ///< function set to spi nss0 of ch.3
  177. Func_Spi1_Sck = 43u, ///< function set to spi sck of ch.1
  178. Func_Spi3_Sck = 43u, ///< function set to spi sck of ch.3
  179. Func_Spi2_Mosi = 44u, ///< function set to spi mosi of ch.2
  180. Func_Spi4_Mosi = 44u, ///< function set to spi mosi of ch.2
  181. Func_Spi2_Miso = 45u, ///< function set to spi miso of ch.4
  182. Func_Spi4_Miso = 45u, ///< function set to spi miso of ch.4
  183. Func_Spi2_Nss0 = 46u, ///< function set to spi nss0 of ch.2
  184. Func_Spi4_Nss0 = 46u, ///< function set to spi nss0 of ch.4
  185. Func_Spi2_Sck = 47u, ///< function set to spi sck of ch.2
  186. Func_Spi4_Sck = 47u, ///< function set to spi sck of ch.4
  187. Func_I2c1_Sda = 48u, ///< function set to i2c sda of ch.1
  188. Func_I2c3_Sda = 48u, ///< function set to i2c sda of ch.3
  189. Func_I2c1_Scl = 49u, ///< function set to i2c scl of ch.1
  190. Func_I2c3_Scl = 49u, ///< function set to i2c scl of ch.3
  191. Func_I2c2_Sda = 50u, ///< function set to i2c sda of ch.2
  192. Func_Can1_Tx = 50u, ///< function set to can tx of ch.1
  193. Func_I2c2_Scl = 51u, ///< function set to i2c scl of ch.2
  194. Func_Can1_Rx = 51u, ///< function set to can rx of ch.1
  195. Func_I2s1_Sd = 52u, ///< function set to i2s sd of ch.1
  196. Func_I2s3_Sd = 52u, ///< function set to i2s sd of ch.3
  197. Func_I2s1_Sdin = 53u, ///< function set to i2s sdin of ch.1
  198. Func_I2s3_Sdin = 53u, ///< function set to i2s sdin of ch.3
  199. Func_I2s1_Ws = 54u, ///< function set to i2s ws of ch.1
  200. Func_I2s3_Ws = 54u, ///< function set to i2s ws of ch.3
  201. Func_I2s1_Ck = 55u, ///< function set to i2s ck of ch.1
  202. Func_I2s3_Ck = 55u, ///< function set to i2s ck of ch.3
  203. Func_I2s2_Sd = 56u, ///< function set to i2s sd of ch.2
  204. Func_I2s4_Sd = 56u, ///< function set to i2s sd of ch.4
  205. Func_I2s2_Sdin = 57u, ///< function set to i2s sdin of ch.2
  206. Func_I2s4_Sdin = 57u, ///< function set to i2s sdin of ch.4
  207. Func_I2s2_Ws = 58u, ///< function set to i2s ws of ch.2
  208. Func_I2s4_Ws = 58u, ///< function set to i2s ws of ch.4
  209. Func_I2s2_Ck = 59u, ///< function set to i2s ck of ch.2
  210. Func_I2s4_Ck = 59u, ///< function set to i2s ck of ch.4
  211. }en_port_func_t;
  212. /**
  213. *******************************************************************************
  214. ** \brief GPIO init structure definition
  215. ******************************************************************************/
  216. typedef struct stc_port_init
  217. {
  218. en_pin_mode_t enPinMode; ///< Set pin mode @ref en_pin_mode_t
  219. en_functional_state_t enLatch; ///< Pin output latch enable
  220. en_functional_state_t enExInt; ///< External int enable
  221. en_functional_state_t enInvert; ///< Pin input/output invert enable
  222. en_functional_state_t enPullUp; ///< Internal pull-up resistor enable
  223. en_pin_drv_t enPinDrv; ///< Drive capacity setting @ref en_pin_drv_t
  224. en_pin_o_type_t enPinOType; ///< Output mode setting @ref en_pin_o_type_t
  225. en_functional_state_t enPinSubFunc; ///< Pin sub-function enable
  226. }stc_port_init_t;
  227. /**
  228. *******************************************************************************
  229. ** \brief GPIO public setting structure definition
  230. ******************************************************************************/
  231. typedef struct stc_port_pub_set
  232. {
  233. en_port_func_t enSubFuncSel; ///< Sub-function setting @ref en_port_func_t
  234. en_read_wait_t enReadWait; ///< Read wait cycle setting @ref en_read_wait_t
  235. }stc_port_pub_set_t;
  236. /*******************************************************************************
  237. * Global pre-processor symbols/macros ('#define')
  238. ******************************************************************************/
  239. /*******************************************************************************
  240. * Global variable definitions ('extern')
  241. ******************************************************************************/
  242. /*******************************************************************************
  243. Global function prototypes (definition in C source)
  244. ******************************************************************************/
  245. extern en_result_t PORT_Init(en_port_t enPort, uint16_t u16Pin, \
  246. const stc_port_init_t *pstcPortInit);
  247. extern en_result_t PORT_DeInit(void);
  248. extern void PORT_Unlock(void);
  249. extern void PORT_Lock(void);
  250. extern en_result_t PORT_DebugPortSetting(uint8_t u8DebugPort, en_functional_state_t enFunc);
  251. extern en_result_t PORT_PubSetting(const stc_port_pub_set_t *pstcPortPubSet);
  252. extern uint16_t PORT_GetData(en_port_t enPort);
  253. extern en_flag_status_t PORT_GetBit(en_port_t enPort, en_pin_t enPin);
  254. extern en_result_t PORT_SetPortData(en_port_t enPort, uint16_t u16Pin);
  255. extern en_result_t PORT_ResetPortData(en_port_t enPort, uint16_t u16Pin);
  256. extern en_result_t PORT_OE(en_port_t enPort, uint16_t u16Pin, en_functional_state_t enNewState);
  257. extern en_result_t PORT_SetBits(en_port_t enPort, uint16_t u16Pin);
  258. extern en_result_t PORT_ResetBits(en_port_t enPort, uint16_t u16Pin);
  259. extern en_result_t PORT_Toggle(en_port_t enPort, uint16_t u16Pin);
  260. extern en_result_t PORT_SetFunc(en_port_t enPort, uint16_t u16Pin, \
  261. en_port_func_t enFuncSel, en_functional_state_t enSubFunc);
  262. extern en_result_t PORT_SetSubFunc(en_port_func_t enFuncSel);
  263. //@} // GpioGroup
  264. #ifdef __cplusplus
  265. }
  266. #endif
  267. #endif /* DDL_GPIO_ENABLE */
  268. #endif /* __HC32F460_GPIO_H__ */
  269. /*******************************************************************************
  270. * EOF (not truncated)
  271. ******************************************************************************/