nu_gpio.h 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /**************************************************************************//**
  2. * @file GPIO.h
  3. * @brief GPIO driver header file
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. * @copyright (C) 2018 Nuvoton Technology Corp. All rights reserved.
  7. ******************************************************************************/
  8. #ifndef __NU_GPIO_H__
  9. #define __NU_GPIO_H__
  10. #ifdef __cplusplus
  11. #define __I volatile /*!< Defines 'read only' permissions */
  12. #else
  13. #define __I volatile const /*!< Defines 'read only' permissions */
  14. #endif
  15. #define __O volatile /*!< Defines 'write only' permissions */
  16. #define __IO volatile /*!< Defines 'read / write' permissions */
  17. #ifdef __cplusplus
  18. extern "C"
  19. {
  20. #endif
  21. /**
  22. @addtogroup REGISTER Control Register
  23. @{
  24. */
  25. /**
  26. @addtogroup GPIO General Purpose Input/Output Controller(GPIO)
  27. Memory Mapped Structure for GPIO Controller
  28. @{ */
  29. typedef struct
  30. {
  31. /**
  32. * @var GPIO_T::MODE
  33. * Offset: 0x00/0x40/0x80/0xC0/0x100/0x140/0x180/0x1C0 Port A-H I/O Mode Control
  34. * ---------------------------------------------------------------------------------------------------
  35. * |Bits |Field |Descriptions
  36. * | :----: | :----: | :---- |
  37. * |[2n+1:2n]|MODEn |Port A-H I/O Pin[n] Mode Control
  38. * | | |Determine each I/O mode of Px.n pins.
  39. * | | |00 = Px.n is in Input mode.
  40. * | | |01 = Px.n is in Push-pull Output mode.
  41. * | | |10 = Px.n is in Open-drain Output mode.
  42. * | | |11 = Px.n is in Quasi-bidirectional mode.
  43. * | | |Note1: The initial value of this field is defined by CIOINI (CONFIG0 [10]).
  44. * | | |If CIOINI is set to 0, the default value is 0xFFFF_FFFF and all pins will be quasi-bidirectional mode after chip powered on.
  45. * | | |If CIOINI is set to 1, the default value is 0x0000_0000 and all pins will be input mode after chip powered on.
  46. * | | |Note2:
  47. * | | |Max. n=15 for port A/B/E/G.
  48. * | | |Max. n=14 for port C/D.
  49. * | | |Max. n=11 for port F/H.
  50. * @var GPIO_T::DINOFF
  51. * Offset: 0x04/0x44/0x84/0xC4/0x104/0x144/0x184/0x1C4 Port A-H Digital Input Path Disable Control
  52. * ---------------------------------------------------------------------------------------------------
  53. * |Bits |Field |Descriptions
  54. * | :----: | :----: | :---- |
  55. * |[n+16] |DINOFFn |Port A-H Pin[n] Digital Input Path Disable Control
  56. * | | |Each of these bits is used to control if the digital input path of corresponding Px.n pin is disabled.
  57. * | | |If input is analog signal, users can disable Px.n digital input path to avoid input current leakage.
  58. * | | |0 = Px.n digital input path Enabled.
  59. * | | |1 = Px.n digital input path Disabled (digital input tied to low).
  60. * | | |Note:
  61. * | | |Max. n=15 for port A/B/E/G.
  62. * | | |Max. n=14 for port C/D.
  63. * | | |Max. n=11 for port F/H.
  64. * @var GPIO_T::DOUT
  65. * Offset: 0x08/0x48/0x88/0xC8/0x108/0x148/0x188/0x1C8 Port A-H Data Output Value
  66. * ---------------------------------------------------------------------------------------------------
  67. * |Bits |Field |Descriptions
  68. * | :----: | :----: | :---- |
  69. * |[n] |DOUTn |Port A-H Pin[n] Output Value
  70. * | | |Each of these bits controls the status of a Px.n pin when the Px.n is configured as Push-pull output, Open-drain output or Quasi-bidirectional mode.
  71. * | | |0 = Px.n will drive Low if the Px.n pin is configured as Push-pull output, Open-drain output or Quasi-bidirectional mode.
  72. * | | |1 = Px.n will drive High if the Px.n pin is configured as Push-pull output or Quasi-bidirectional mode.
  73. * | | |Note:
  74. * | | |Max. n=15 for port A/B/E/G.
  75. * | | |Max. n=14 for port C/D.
  76. * | | |Max. n=11 for port F/H.
  77. * @var GPIO_T::DATMSK
  78. * Offset: 0x0C/0x4C/0x8C/0xCC/0x10C/0x14C/0x18C/0x1CC Port A-H Data Output Write Mask
  79. * ---------------------------------------------------------------------------------------------------
  80. * |Bits |Field |Descriptions
  81. * | :----: | :----: | :---- |
  82. * |[n] |DATMSKn |Port A-H Pin[n] Data Output Write Mask
  83. * | | |These bits are used to protect the corresponding DOUT (Px_DOUT[n]) bit.
  84. * | | |When the DATMSK (Px_DATMSK[n]) bit is set to 1, the corresponding DOUT (Px_DOUT[n]) bit is protected.
  85. * | | |If the write signal is masked, writing data to the protect bit is ignored.
  86. * | | |0 = Corresponding DOUT (Px_DOUT[n]) bit can be updated.
  87. * | | |1 = Corresponding DOUT (Px_DOUT[n]) bit protected.
  88. * | | |Note1: This function only protects the corresponding DOUT (Px_DOUT[n]) bit, and will not protect the corresponding PDIO (Pxn_PDIO[n]) bit.
  89. * | | |Note2:
  90. * | | |Max. n=15 for port A/B/E/G.
  91. * | | |Max. n=14 for port C/D.
  92. * | | |Max. n=11 for port F/H.
  93. * @var GPIO_T::PIN
  94. * Offset: 0x10/0x50/0x90/0xD0/0x110/0x150/0x190/0x1D0 Port A-H Pin Value
  95. * ---------------------------------------------------------------------------------------------------
  96. * |Bits |Field |Descriptions
  97. * | :----: | :----: | :---- |
  98. * |[n] |PINn |Port A-H Pin[n] Pin Value
  99. * | | |Each bit of the register reflects the actual status of the respective Px.n pin.
  100. * | | |If the bit is 1, it indicates the corresponding pin status is high; else the pin status is low.
  101. * | | |Note:
  102. * | | |Max. n=15 for port A/B/E/G.
  103. * | | |Max. n=14 for port C/D.
  104. * | | |Max. n=11 for port F/H.
  105. * @var GPIO_T::DBEN
  106. * Offset: 0x14/0x54/0x94/0xD4/0x114/0x154/0x194/0x1D4 Port A-H De-Bounce Enable Control Register
  107. * ---------------------------------------------------------------------------------------------------
  108. * |Bits |Field |Descriptions
  109. * | :----: | :----: | :---- |
  110. * |[n] |DBENn |Port A-H Pin[n] Input Signal De-Bounce Enable Bit
  111. * | | |The DBEN[n] bit is used to enable the de-bounce function for each corresponding bit.
  112. * | | |If the input signal pulse width cannot be sampled by continuous two de-bounce sample cycle, the input signal transition is seen as the signal bounce and will not trigger the interrupt.
  113. * | | |The de-bounce clock source is controlled by DBCLKSRC (GPIO_DBCTL [4]), one de-bounce sample cycle period is controlled by DBCLKSEL (GPIO_DBCTL [3:0]).
  114. * | | |0 = Px.n de-bounce function Disabled.
  115. * | | |1 = Px.n de-bounce function Enabled.
  116. * | | |The de-bounce function is valid only for edge triggered interrupt.
  117. * | | |If the interrupt mode is level triggered, the de-bounce enable bit is ignored.
  118. * | | |Note:
  119. * | | |Max. n=15 for port A/B/E/G.
  120. * | | |Max. n=14 for port C/D.
  121. * | | |Max. n=11 for port F/H.
  122. * @var GPIO_T::INTTYPE
  123. * Offset: 0x18/0x58/0x98/0xD8/0x118/0x158/0x198/0x1D8 Port A-H Interrupt Trigger Type Control
  124. * ---------------------------------------------------------------------------------------------------
  125. * |Bits |Field |Descriptions
  126. * | :----: | :----: | :---- |
  127. * |[n] |TYPEn |Port A-H Pin[n] Edge or Level Detection Interrupt Trigger Type Control
  128. * | | |TYPE (Px_INTTYPE[n]) bit is used to control the triggered interrupt is by level trigger or by edge trigger.
  129. * | | |If the interrupt is by edge trigger, the trigger source can be controlled by de-bounce.
  130. * | | |If the interrupt is by level trigger, the input source is sampled by one HCLK clock and generates the interrupt.
  131. * | | |0 = Edge trigger interrupt.
  132. * | | |1 = Level trigger interrupt.
  133. * | | |If the pin is set as the level trigger interrupt, only one level can be set on the registers RHIEN (Px_INTEN[n+16])/FLIEN (Px_INTEN[n]).
  134. * | | |If both levels to trigger interrupt are set, the setting is ignored and no interrupt will occur.
  135. * | | |The de-bounce function is valid only for edge triggered interrupt.
  136. * | | |If the interrupt mode is level triggered, the de-bounce enable bit is ignored.
  137. * | | |Note:
  138. * | | |Max. n=15 for port A/B/E/G.
  139. * | | |Max. n=14 for port C/D.
  140. * | | |Max. n=11 for port F/H.
  141. * @var GPIO_T::INTEN
  142. * Offset: 0x1C/0x5C/0x9C/0xDC/0x11C/0x15C/0x19C/0x1DC Port A-H Interrupt Enable Control Register
  143. * ---------------------------------------------------------------------------------------------------
  144. * |Bits |Field |Descriptions
  145. * | :----: | :----: | :---- |
  146. * |[n] |FLIENn |Port A-H Pin[n] Falling Edge or Low Level Interrupt Trigger Type Enable Bit
  147. * | | |The FLIEN (Px_INTEN[n]) bit is used to enable the interrupt for each of the corresponding input Px.n pin.
  148. * | | |Set bit to 1 also enable the pin wake-up function.
  149. * | | |When setting the FLIEN (Px_INTEN[n]) bit to 1 :
  150. * | | |If the interrupt is level trigger (TYPE (Px_INTTYPE[n]) bit is set to 1), the input Px.n pin will generate the interrupt while this pin state is at low level.
  151. * | | |If the interrupt is edge trigger(TYPE (Px_INTTYPE[n]) bit is set to 0), the input Px.n pin will generate the interrupt while this pin state changed from high to low.
  152. * | | |0 = Px.n level low or high to low interrupt Disabled.
  153. * | | |1 = Px.n level low or high to low interrupt Enabled.
  154. * | | |Note:
  155. * | | |Max. n=15 for port A/B/E/G.
  156. * | | |Max. n=14 for port C/D.
  157. * | | |Max. n=11 for port F/H.
  158. * |[n+16] |RHIENn |Port A-H Pin[n] Rising Edge or High Level Interrupt Trigger Type Enable Bit
  159. * | | |The RHIEN (Px_INTEN[n+16]) bit is used to enable the interrupt for each of the corresponding input Px.n pin
  160. * | | |Set bit to 1 also enable the pin wake-up function.
  161. * | | |When setting the RHIEN (Px_INTEN[n+16]) bit to 1 :
  162. * | | |If the interrupt is level trigger (TYPE (Px_INTTYPE[n]) bit is set to 1), the input Px.n pin will generate the interrupt while this pin state is at high level.
  163. * | | |If the interrupt is edge trigger (TYPE (Px_INTTYPE[n]) bit is set to 0), the input Px.n pin will generate the interrupt while this pin state changed from low to high.
  164. * | | |0 = Px.n level high or low to high interrupt Disabled.
  165. * | | |1 = Px.n level high or low to high interrupt Enabled.
  166. * | | |Note:
  167. * | | |Max. n=15 for port A/B/E/G.
  168. * | | |Max. n=14 for port C/D.
  169. * | | |Max. n=11 for port F/H.
  170. * @var GPIO_T::INTSRC
  171. * Offset: 0x20/0x60/0xA0/0xE0/0x120/0x160/0x1A0/0x1E0 Port A-H Interrupt Source Flag
  172. * ---------------------------------------------------------------------------------------------------
  173. * |Bits |Field |Descriptions
  174. * | :----: | :----: | :---- |
  175. * |[n] |INTSRCn |Port A-H Pin[n] Interrupt Source Flag
  176. * | | |Write Operation :
  177. * | | |0 = No action.
  178. * | | |1 = Clear the corresponding pending interrupt.
  179. * | | |Read Operation :
  180. * | | |0 = No interrupt at Px.n.
  181. * | | |1 = Px.n generates an interrupt.
  182. * | | |Note:
  183. * | | |Max. n=15 for port A/B/E/G.
  184. * | | |Max. n=14 for port C/D.
  185. * | | |Max. n=11 for port F/H.
  186. * @var GPIO_T::SMTEN
  187. * Offset: 0x24/0x64/0xA4/0xE4/0x124/0x164/0x1A4/0x1E4 Port A-H Input Schmitt Trigger Enable Register
  188. * ---------------------------------------------------------------------------------------------------
  189. * |Bits |Field |Descriptions
  190. * | :----: | :----: | :---- |
  191. * |[n] |SMTENn |Port A-H Pin[n] Input Schmitt Trigger Enable Bit
  192. * | | |0 = Px.n input Schmitt trigger function Disabled.
  193. * | | |1 = Px.n input Schmitt trigger function Enabled.
  194. * | | |Note:
  195. * | | |Max. n=15 for port A/B/E/G.
  196. * | | |Max. n=14 for port C/D.
  197. * | | |Max. n=11 for port F/H.
  198. * @var GPIO_T::SLEWCTL
  199. * Offset: 0x28/0x68/0xA8/0xE8/0x128/0x168/0x1A8/0x1E8 Port A-H High Slew Rate Control Register
  200. * ---------------------------------------------------------------------------------------------------
  201. * |Bits |Field |Descriptions
  202. * | :----: | :----: | :---- |
  203. * |[2n+1:2n]|HSRENn |Port A-H Pin[n] High Slew Rate Control
  204. * | | |00 = Px.n output with normal slew rate mode (maximum 40 MHz at 2.7V).
  205. * | | |01 = Px.n output with high slew rate mode (maximum 80 MHz at 2.7V).
  206. * | | |10 = Px.n output with fast slew rate mode (maximum 100 MHz at 2.7V.
  207. * | | |11 = Reserved.
  208. * | | |Note:
  209. * | | |Max. n=15 for port A/B/E/G.
  210. * | | |Max. n=14 for port C/D.
  211. * | | |Max. n=11 for port F/H.
  212. * @var GPIO_T::PUSEL
  213. * Offset: 0x30/0x70/0xB0/0xF0/0x130/0x170/0x1B0/0x1F0 Port A-H Pull-up and Pull-down Selection Register
  214. * ---------------------------------------------------------------------------------------------------
  215. * |Bits |Field |Descriptions
  216. * | :----: | :----: | :---- |
  217. * |[2n+1:2n]|PUSELn |Port A-H Pin[n] Pull-up and Pull-down Enable Register
  218. * | | |Determine each I/O Pull-up/pull-down of Px.n pins.
  219. * | | |00 = Px.n pull-up and pull-up disable.
  220. * | | |01 = Px.n pull-up enable.
  221. * | | |10 = Px.n pull-down enable.
  222. * | | |11 = Px.n pull-up and pull-up disable.
  223. * | | |Note1:
  224. * | | |Basically, the pull-up control and pull-down control has following behavior limitation
  225. * | | |The independent pull-up control register only valid when MODEn set as tri-state and open-drain mode
  226. * | | |The independent pull-down control register only valid when MODEn set as tri-state mode
  227. * | | |When both pull-up pull-down is set as 1 at tri-state mode, keep I/O in tri-state mode
  228. * | | |Note2:
  229. * | | |Max. n=15 for port A/B/E/G.
  230. * | | |Max. n=14 for port C/D.
  231. * | | |Max. n=11 for port F/H.
  232. */
  233. __IO uint32_t MODE; /* Offset: 0x00/0x40/0x80/0xC0/0x100/0x140/0x180/0x1C0 Port A-H I/O Mode Control */
  234. __IO uint32_t DINOFF; /* Offset: 0x04/0x44/0x84/0xC4/0x104/0x144/0x184/0x1C4 Port A-H Digital Input Path Disable Control */
  235. __IO uint32_t DOUT; /* Offset: 0x08/0x48/0x88/0xC8/0x108/0x148/0x188/0x1C8 Port A-H Data Output Value */
  236. __IO uint32_t DATMSK; /* Offset: 0x0C/0x4C/0x8C/0xCC/0x10C/0x14C/0x18C/0x1CC Port A-H Data Output Write Mask */
  237. __I uint32_t PIN; /* Offset: 0x10/0x50/0x90/0xD0/0x110/0x150/0x190/0x1D0 Port A-H Pin Value */
  238. __IO uint32_t DBEN; /* Offset: 0x14/0x54/0x94/0xD4/0x114/0x154/0x194/0x1D4 Port A-H De-Bounce Enable Control Register */
  239. __IO uint32_t INTTYPE; /* Offset: 0x18/0x58/0x98/0xD8/0x118/0x158/0x198/0x1D8 Port A-H Interrupt Trigger Type Control */
  240. __IO uint32_t INTEN; /* Offset: 0x1C/0x5C/0x9C/0xDC/0x11C/0x15C/0x19C/0x1DC Port A-H Interrupt Enable Control Register */
  241. __IO uint32_t INTSRC; /* Offset: 0x20/0x60/0xA0/0xE0/0x120/0x160/0x1A0/0x1E0 Port A-H Interrupt Source Flag */
  242. __IO uint32_t SMTEN; /* Offset: 0x24/0x64/0xA4/0xE4/0x124/0x164/0x1A4/0x1E4 Port A-H Input Schmitt Trigger Enable Register */
  243. __IO uint32_t SLEWCTL; /* Offset: 0x28/0x68/0xA8/0xE8/0x128/0x168/0x1A8/0x1E8 Port A-H High Slew Rate Control Register */
  244. /// @cond HIDDEN_SYMBOLS
  245. __I uint32_t RESERVE0[1];
  246. /// @endcond //HIDDEN_SYMBOLS
  247. __IO uint32_t PUSEL; /* Offset: 0x30/0x70/0xB0/0xF0/0x130/0x170/0x1B0/0x1F0 Port A-H Pull-up and Pull-down Enable Register */
  248. } GPIO_T;
  249. typedef struct
  250. {
  251. /**
  252. * @var GPIO_DBCTL_T::DBCTL
  253. * Offset: 0x440 Interrupt De-bounce Control Register
  254. * ---------------------------------------------------------------------------------------------------
  255. * |Bits |Field |Descriptions
  256. * | :----: | :----: | :---- |
  257. * |[3:0] |DBCLKSEL |De-Bounce Sampling Cycle Selection
  258. * | | |0000 = Sample interrupt input once per 1 clocks.
  259. * | | |0001 = Sample interrupt input once per 2 clocks.
  260. * | | |0010 = Sample interrupt input once per 4 clocks.
  261. * | | |0011 = Sample interrupt input once per 8 clocks.
  262. * | | |0100 = Sample interrupt input once per 16 clocks.
  263. * | | |0101 = Sample interrupt input once per 32 clocks.
  264. * | | |0110 = Sample interrupt input once per 64 clocks.
  265. * | | |0111 = Sample interrupt input once per 128 clocks.
  266. * | | |1000 = Sample interrupt input once per 256 clocks.
  267. * | | |1001 = Sample interrupt input once per 2*256 clocks.
  268. * | | |1010 = Sample interrupt input once per 4*256 clocks.
  269. * | | |1011 = Sample interrupt input once per 8*256 clocks.
  270. * | | |1100 = Sample interrupt input once per 16*256 clocks.
  271. * | | |1101 = Sample interrupt input once per 32*256 clocks.
  272. * | | |1110 = Sample interrupt input once per 64*256 clocks.
  273. * | | |1111 = Sample interrupt input once per 128*256 clocks.
  274. * |[4] |DBCLKSRC |De-Bounce Counter Clock Source Selection
  275. * | | |0 = De-bounce counter clock source is the HCLK.
  276. * | | |1 = De-bounce counter clock source is the 10 kHz internal low speed RC oscillator (LIRC).
  277. * |[5] |ICLKON |Interrupt Clock On Mode
  278. * | | |0 = Edge detection circuit is active only if I/O pin corresponding RHIEN (Px_INTEN[n+16])/FLIEN (Px_INTEN[n]) bit is set to 1.
  279. * | | |1 = All I/O pins edge detection circuit is always active after reset.
  280. * | | |Note: It is recommended to disable this bit to save system power if no special application concern.
  281. */
  282. __IO uint32_t DBCTL; /* Offset: 0x440 Interrupt De-bounce Control Register */
  283. } GPIO_DBCTL_T;
  284. /**
  285. @addtogroup GPIO_CONST GPIO Bit Field Definition
  286. Constant Definitions for GPIO Controller
  287. @{ */
  288. #define GPIO_DBCTL_DBCLKSEL_Pos (0) /*!< GPIO_T::DBCTL: DBCLKSEL Position */
  289. #define GPIO_DBCTL_DBCLKSEL_Msk (0xFul << GPIO_DBCTL_DBCLKSEL_Pos) /*!< GPIO_T::DBCTL: DBCLKSEL Mask */
  290. #define GPIO_DBCTL_DBCLKSRC_Pos (4) /*!< GPIO_T::DBCTL: DBCLKSRC Position */
  291. #define GPIO_DBCTL_DBCLKSRC_Msk (1ul << GPIO_DBCTL_DBCLKSRC_Pos) /*!< GPIO_T::DBCTL: DBCLKSRC Mask */
  292. #define GPIO_DBCTL_ICLKON_Pos (5) /*!< GPIO_T::DBCTL: ICLKON Position */
  293. #define GPIO_DBCTL_ICLKON_Msk (1ul << GPIO_DBCTL_ICLKON_Pos) /*!< GPIO_T::DBCTL: ICLKON Mask */
  294. /**@}*/ /* GPIO_CONST */
  295. /**@}*/ /* end of GPIO register group */
  296. /**@}*/ /* end of REGISTER group */
  297. /** @addtogroup PERIPHERAL_DECLARATION Peripheral Pointer
  298. The Declaration of Peripherals
  299. @{
  300. */
  301. #define GPIO_DBCTL_BASE (0xB0004440ul)
  302. #define PA ((GPIO_T *) PA_BA)
  303. #define PB ((GPIO_T *) PB_BA)
  304. #define PC ((GPIO_T *) PC_BA)
  305. #define PD ((GPIO_T *) PD_BA)
  306. #define PE ((GPIO_T *) PE_BA)
  307. #define PF ((GPIO_T *) PF_BA)
  308. #define PG ((GPIO_T *) PG_BA)
  309. #define GPIOA ((GPIO_T *) PA_BA)
  310. #define GPIOB ((GPIO_T *) PB_BA)
  311. #define GPIOC ((GPIO_T *) PC_BA)
  312. #define GPIOD ((GPIO_T *) PD_BA)
  313. #define GPIOE ((GPIO_T *) PE_BA)
  314. #define GPIOF ((GPIO_T *) PF_BA)
  315. #define GPIOG ((GPIO_T *) PG_BA)
  316. #define GPIO ((GPIO_DBCTL_T *) GPIO_DBCTL_BASE)
  317. #define GPIO_PIN_DATA_BASE (0xB0004800ul)
  318. /*@}*/ /* end of group ERIPHERAL_DECLARATION */
  319. /** @addtogroup Standard_Driver Standard Driver
  320. @{
  321. */
  322. /** @addtogroup GPIO_Driver GPIO Driver
  323. @{
  324. */
  325. /** @addtogroup GPIO_EXPORTED_CONSTANTS GPIO Exported Constants
  326. @{
  327. */
  328. #define GPIO_PIN_MAX 16UL /*!< Specify Maximum Pins of Each GPIO Port \hideinitializer */
  329. /*---------------------------------------------------------------------------------------------------------*/
  330. /* GPIO_MODE Constant Definitions */
  331. /*---------------------------------------------------------------------------------------------------------*/
  332. #define GPIO_MODE_INPUT 0x0UL /*!< Input Mode \hideinitializer */
  333. #define GPIO_MODE_OUTPUT 0x1UL /*!< Output Mode \hideinitializer */
  334. #define GPIO_MODE_OPEN_DRAIN 0x2UL /*!< Open-Drain Mode \hideinitializer */
  335. /*---------------------------------------------------------------------------------------------------------*/
  336. /* GPIO Interrupt Type Constant Definitions */
  337. /*---------------------------------------------------------------------------------------------------------*/
  338. #define GPIO_INT_RISING 0x00010000UL /*!< Interrupt enable by Input Rising Edge \hideinitializer */
  339. #define GPIO_INT_FALLING 0x00000001UL /*!< Interrupt enable by Input Falling Edge \hideinitializer */
  340. #define GPIO_INT_BOTH_EDGE 0x00010001UL /*!< Interrupt enable by both Rising Edge and Falling Edge \hideinitializer */
  341. #define GPIO_INT_HIGH 0x01010000UL /*!< Interrupt enable by Level-High \hideinitializer */
  342. #define GPIO_INT_LOW 0x01000001UL /*!< Interrupt enable by Level-Level \hideinitializer */
  343. /*---------------------------------------------------------------------------------------------------------*/
  344. /* GPIO_INTTYPE Constant Definitions */
  345. /*---------------------------------------------------------------------------------------------------------*/
  346. #define GPIO_INTTYPE_EDGE 0UL /*!< GPIO_INTTYPE Setting for Edge Trigger Mode \hideinitializer */
  347. #define GPIO_INTTYPE_LEVEL 1UL /*!< GPIO_INTTYPE Setting for Edge Level Mode \hideinitializer */
  348. /*---------------------------------------------------------------------------------------------------------*/
  349. /* GPIO Slew Rate Type Constant Definitions */
  350. /*---------------------------------------------------------------------------------------------------------*/
  351. #define GPIO_SLEWCTL_NORMAL 0x0UL /*!< GPIO slew setting for nornal Mode \hideinitializer */
  352. #define GPIO_SLEWCTL_HIGH 0x1UL /*!< GPIO slew setting for high Mode \hideinitializer */
  353. #define GPIO_SLEWCTL_FAST 0x2UL /*!< GPIO slew setting for fast Mode \hideinitializer */
  354. /*---------------------------------------------------------------------------------------------------------*/
  355. /* GPIO Pull-up And Pull-down Type Constant Definitions */
  356. /*---------------------------------------------------------------------------------------------------------*/
  357. #define GPIO_PUSEL_DISABLE 0x0UL /*!< GPIO PUSEL setting for Disable Mode \hideinitializer */
  358. #define GPIO_PUSEL_PULL_UP 0x1UL /*!< GPIO PUSEL setting for Pull-up Mode \hideinitializer */
  359. #define GPIO_PUSEL_PULL_DOWN 0x2UL /*!< GPIO PUSEL setting for Pull-down Mode \hideinitializer */
  360. /*---------------------------------------------------------------------------------------------------------*/
  361. /* GPIO External interrupt Constant Definitions */
  362. /*---------------------------------------------------------------------------------------------------------*/
  363. #define GPIO_MFP_PA0MFP_EINT0 outpw(REG_SYS_GPA_MFPL, ((inpw(REG_SYS_GPA_MFPL) & 0xFFFFFFF0) | 0x00000005)) /*!< PA0 MFP setting for EINT0 \hideinitializer */
  364. #define GPIO_MFP_PA13MFP_EINT0 outpw(REG_SYS_GPA_MFPH, ((inpw(REG_SYS_GPA_MFPH) & 0xFF0FFFFF) | 0x00D00000)) /*!< PA13 MFP setting for EINT0 \hideinitializer */
  365. #define GPIO_MFP_PA1MFP_EINT1 outpw(REG_SYS_GPA_MFPL, ((inpw(REG_SYS_GPA_MFPL) & 0xFFFFFF0F) | 0x000000D0)) /*!< PA1 MFP setting for EINT1 \hideinitializer */
  366. #define GPIO_MFP_PA14MFP_EINT1 outpw(REG_SYS_GPA_MFPH, ((inpw(REG_SYS_GPA_MFPH) & 0xF0FFFFFF) | 0x08000000)) /*!< PA14 MFP setting for EINT1 \hideinitializer */
  367. #define GPIO_MFP_PD0MFP_EINT2 outpw(REG_SYS_GPD_MFPL, ((inpw(REG_SYS_GPD_MFPL) & 0xFFFFFFF0) | 0x00000004)) /*!< PD0 MFP setting for EINT2 \hideinitializer */
  368. #define GPIO_MFP_PE10MFP_EINT2 outpw(REG_SYS_GPE_MFPH, ((inpw(REG_SYS_GPE_MFPH) & 0xFFFFF0FF) | 0x00000500)) /*!< PE10 MFP setting for EINT2 \hideinitializer */
  369. #define GPIO_MFP_PB3MFP_EINT2 outpw(REG_SYS_GPB_MFPL, ((inpw(REG_SYS_GPB_MFPL) & 0xFFFF0FFF) | 0x00003000)) /*!< PB3 MFP setting for EINT2 \hideinitializer */
  370. #define GPIO_MFP_PB13MFP_EINT2 outpw(REG_SYS_GPB_MFPH, ((inpw(REG_SYS_GPB_MFPH) & 0xFF0FFFFF) | 0x00200000)) /*!< PB13 MFP setting for EINT2 \hideinitializer */
  371. #define GPIO_MFP_PD1MFP_EINT3 outpw(REG_SYS_GPD_MFPL, ((inpw(REG_SYS_GPD_MFPL) & 0xFFFFFF0F) | 0x00000040)) /*!< PD1 MFP setting for EINT3 \hideinitializer */
  372. #define GPIO_MFP_PE12MFP_EINT3 outpw(REG_SYS_GPE_MFPH, ((inpw(REG_SYS_GPE_MFPH) & 0xFFF0FFFF) | 0x00050000)) /*!< PE12 MFP setting for EINT3 \hideinitializer */
  373. #define GPIO_MFP_PG15MFP_EINT3 outpw(REG_SYS_GPG_MFPH, ((inpw(REG_SYS_GPG_MFPH) & 0x0FFFFFFF) | 0x40000000)) /*!< PG15 MFP setting for EINT3 \hideinitializer */
  374. /*---------------------------------------------------------------------------------------------------------*/
  375. /* GPIO_DBCTL Constant Definitions */
  376. /*---------------------------------------------------------------------------------------------------------*/
  377. #define GPIO_DBCTL_ICLK_ON 0x00000020UL /*!< GPIO_DBCTL setting for all IO pins edge detection circuit is always active after reset \hideinitializer */
  378. #define GPIO_DBCTL_ICLK_OFF 0x00000000UL /*!< GPIO_DBCTL setting for edge detection circuit is active only if IO pin corresponding GPIOx_IEN bit is set to 1 \hideinitializer */
  379. #define GPIO_DBCTL_DBCLKSRC_LIRC 0x00000010UL /*!< GPIO_DBCTL setting for de-bounce counter clock source is the internal 10 kHz \hideinitializer */
  380. #define GPIO_DBCTL_DBCLKSRC_HCLK 0x00000000UL /*!< GPIO_DBCTL setting for de-bounce counter clock source is the HCLK \hideinitializer */
  381. #define GPIO_DBCTL_DBCLKSEL_1 0x00000000UL /*!< GPIO_DBCTL setting for sampling cycle = 1 clocks \hideinitializer */
  382. #define GPIO_DBCTL_DBCLKSEL_2 0x00000001UL /*!< GPIO_DBCTL setting for sampling cycle = 2 clocks \hideinitializer */
  383. #define GPIO_DBCTL_DBCLKSEL_4 0x00000002UL /*!< GPIO_DBCTL setting for sampling cycle = 4 clocks \hideinitializer */
  384. #define GPIO_DBCTL_DBCLKSEL_8 0x00000003UL /*!< GPIO_DBCTL setting for sampling cycle = 8 clocks \hideinitializer */
  385. #define GPIO_DBCTL_DBCLKSEL_16 0x00000004UL /*!< GPIO_DBCTL setting for sampling cycle = 16 clocks \hideinitializer */
  386. #define GPIO_DBCTL_DBCLKSEL_32 0x00000005UL /*!< GPIO_DBCTL setting for sampling cycle = 32 clocks \hideinitializer */
  387. #define GPIO_DBCTL_DBCLKSEL_64 0x00000006UL /*!< GPIO_DBCTL setting for sampling cycle = 64 clocks \hideinitializer */
  388. #define GPIO_DBCTL_DBCLKSEL_128 0x00000007UL /*!< GPIO_DBCTL setting for sampling cycle = 128 clocks \hideinitializer */
  389. #define GPIO_DBCTL_DBCLKSEL_256 0x00000008UL /*!< GPIO_DBCTL setting for sampling cycle = 256 clocks \hideinitializer */
  390. #define GPIO_DBCTL_DBCLKSEL_512 0x00000009UL /*!< GPIO_DBCTL setting for sampling cycle = 512 clocks \hideinitializer */
  391. #define GPIO_DBCTL_DBCLKSEL_1024 0x0000000AUL /*!< GPIO_DBCTL setting for sampling cycle = 1024 clocks \hideinitializer */
  392. #define GPIO_DBCTL_DBCLKSEL_2048 0x0000000BUL /*!< GPIO_DBCTL setting for sampling cycle = 2048 clocks \hideinitializer */
  393. #define GPIO_DBCTL_DBCLKSEL_4096 0x0000000CUL /*!< GPIO_DBCTL setting for sampling cycle = 4096 clocks \hideinitializer */
  394. #define GPIO_DBCTL_DBCLKSEL_8192 0x0000000DUL /*!< GPIO_DBCTL setting for sampling cycle = 8192 clocks \hideinitializer */
  395. #define GPIO_DBCTL_DBCLKSEL_16384 0x0000000EUL /*!< GPIO_DBCTL setting for sampling cycle = 16384 clocks \hideinitializer */
  396. #define GPIO_DBCTL_DBCLKSEL_32768 0x0000000FUL /*!< GPIO_DBCTL setting for sampling cycle = 32768 clocks \hideinitializer */
  397. /* Define GPIO Pin Data Input/Output. It could be used to control each I/O pin by pin address mapping.
  398. Example 1:
  399. PA0 = 1;
  400. It is used to set GPIO PA.0 to high;
  401. Example 2:
  402. if (PA0)
  403. PA0 = 0;
  404. If GPIO PA.0 pin status is high, then set GPIO PA.0 data output to low.
  405. */
  406. #define GPIO_PIN_DATA(port, pin) (*((volatile uint32_t *)((GPIO_PIN_DATA_BASE+(0x40*(port))) + ((pin)<<2)))) /*!< Pin Data Input/Output \hideinitializer */
  407. #define PA0 GPIO_PIN_DATA(0, 0 ) /*!< Specify PA.0 Pin Data Input/Output \hideinitializer */
  408. #define PA1 GPIO_PIN_DATA(0, 1 ) /*!< Specify PA.1 Pin Data Input/Output \hideinitializer */
  409. #define PA2 GPIO_PIN_DATA(0, 2 ) /*!< Specify PA.2 Pin Data Input/Output \hideinitializer */
  410. #define PA3 GPIO_PIN_DATA(0, 3 ) /*!< Specify PA.3 Pin Data Input/Output \hideinitializer */
  411. #define PA4 GPIO_PIN_DATA(0, 4 ) /*!< Specify PA.4 Pin Data Input/Output \hideinitializer */
  412. #define PA5 GPIO_PIN_DATA(0, 5 ) /*!< Specify PA.5 Pin Data Input/Output \hideinitializer */
  413. #define PA6 GPIO_PIN_DATA(0, 6 ) /*!< Specify PA.6 Pin Data Input/Output \hideinitializer */
  414. #define PA7 GPIO_PIN_DATA(0, 7 ) /*!< Specify PA.7 Pin Data Input/Output \hideinitializer */
  415. #define PA8 GPIO_PIN_DATA(0, 8 ) /*!< Specify PA.8 Pin Data Input/Output \hideinitializer */
  416. #define PA9 GPIO_PIN_DATA(0, 9 ) /*!< Specify PA.9 Pin Data Input/Output \hideinitializer */
  417. #define PA10 GPIO_PIN_DATA(0, 10) /*!< Specify PA.10 Pin Data Input/Output \hideinitializer */
  418. #define PA11 GPIO_PIN_DATA(0, 11) /*!< Specify PA.11 Pin Data Input/Output \hideinitializer */
  419. #define PA12 GPIO_PIN_DATA(0, 12) /*!< Specify PA.12 Pin Data Input/Output \hideinitializer */
  420. #define PA13 GPIO_PIN_DATA(0, 13) /*!< Specify PA.13 Pin Data Input/Output \hideinitializer */
  421. #define PA14 GPIO_PIN_DATA(0, 14) /*!< Specify PA.14 Pin Data Input/Output \hideinitializer */
  422. #define PA15 GPIO_PIN_DATA(0, 15) /*!< Specify PA.15 Pin Data Input/Output \hideinitializer */
  423. #define PB0 GPIO_PIN_DATA(1, 0 ) /*!< Specify PB.0 Pin Data Input/Output \hideinitializer */
  424. #define PB1 GPIO_PIN_DATA(1, 1 ) /*!< Specify PB.1 Pin Data Input/Output \hideinitializer */
  425. #define PB2 GPIO_PIN_DATA(1, 2 ) /*!< Specify PB.2 Pin Data Input/Output \hideinitializer */
  426. #define PB3 GPIO_PIN_DATA(1, 3 ) /*!< Specify PB.3 Pin Data Input/Output \hideinitializer */
  427. #define PB4 GPIO_PIN_DATA(1, 4 ) /*!< Specify PB.4 Pin Data Input/Output \hideinitializer */
  428. #define PB5 GPIO_PIN_DATA(1, 5 ) /*!< Specify PB.5 Pin Data Input/Output \hideinitializer */
  429. #define PB6 GPIO_PIN_DATA(1, 6 ) /*!< Specify PB.6 Pin Data Input/Output \hideinitializer */
  430. #define PB7 GPIO_PIN_DATA(1, 7 ) /*!< Specify PB.7 Pin Data Input/Output \hideinitializer */
  431. #define PB8 GPIO_PIN_DATA(1, 8 ) /*!< Specify PB.8 Pin Data Input/Output \hideinitializer */
  432. #define PB9 GPIO_PIN_DATA(1, 9 ) /*!< Specify PB.9 Pin Data Input/Output \hideinitializer */
  433. #define PB10 GPIO_PIN_DATA(1, 10) /*!< Specify PB.10 Pin Data Input/Output \hideinitializer */
  434. #define PB11 GPIO_PIN_DATA(1, 11) /*!< Specify PB.11 Pin Data Input/Output \hideinitializer */
  435. #define PB12 GPIO_PIN_DATA(1, 12) /*!< Specify PB.12 Pin Data Input/Output \hideinitializer */
  436. #define PB13 GPIO_PIN_DATA(1, 13) /*!< Specify PB.13 Pin Data Input/Output \hideinitializer */
  437. #define PB14 GPIO_PIN_DATA(1, 14) /*!< Specify PB.14 Pin Data Input/Output \hideinitializer */
  438. #define PB15 GPIO_PIN_DATA(1, 15) /*!< Specify PB.15 Pin Data Input/Output \hideinitializer */
  439. #define PC0 GPIO_PIN_DATA(2, 0 ) /*!< Specify PC.0 Pin Data Input/Output \hideinitializer */
  440. #define PC1 GPIO_PIN_DATA(2, 1 ) /*!< Specify PC.1 Pin Data Input/Output \hideinitializer */
  441. #define PC2 GPIO_PIN_DATA(2, 2 ) /*!< Specify PC.2 Pin Data Input/Output \hideinitializer */
  442. #define PC3 GPIO_PIN_DATA(2, 3 ) /*!< Specify PC.3 Pin Data Input/Output \hideinitializer */
  443. #define PC4 GPIO_PIN_DATA(2, 4 ) /*!< Specify PC.4 Pin Data Input/Output \hideinitializer */
  444. #define PC5 GPIO_PIN_DATA(2, 5 ) /*!< Specify PC.5 Pin Data Input/Output \hideinitializer */
  445. #define PC6 GPIO_PIN_DATA(2, 6 ) /*!< Specify PC.6 Pin Data Input/Output \hideinitializer */
  446. #define PC7 GPIO_PIN_DATA(2, 7 ) /*!< Specify PC.7 Pin Data Input/Output \hideinitializer */
  447. #define PC8 GPIO_PIN_DATA(2, 8 ) /*!< Specify PC.8 Pin Data Input/Output \hideinitializer */
  448. #define PC9 GPIO_PIN_DATA(2, 9 ) /*!< Specify PC.9 Pin Data Input/Output \hideinitializer */
  449. #define PC10 GPIO_PIN_DATA(2, 10) /*!< Specify PC.10 Pin Data Input/Output \hideinitializer */
  450. #define PC11 GPIO_PIN_DATA(2, 11) /*!< Specify PC.11 Pin Data Input/Output \hideinitializer */
  451. #define PC12 GPIO_PIN_DATA(2, 12) /*!< Specify PC.12 Pin Data Input/Output \hideinitializer */
  452. #define PC13 GPIO_PIN_DATA(2, 13) /*!< Specify PC.13 Pin Data Input/Output \hideinitializer */
  453. #define PC14 GPIO_PIN_DATA(2, 14) /*!< Specify PC.14 Pin Data Input/Output \hideinitializer */
  454. #define PC15 GPIO_PIN_DATA(2, 15) /*!< Specify PC.15 Pin Data Input/Output \hideinitializer */
  455. #define PD0 GPIO_PIN_DATA(3, 0 ) /*!< Specify PD.0 Pin Data Input/Output \hideinitializer */
  456. #define PD1 GPIO_PIN_DATA(3, 1 ) /*!< Specify PD.1 Pin Data Input/Output \hideinitializer */
  457. #define PD2 GPIO_PIN_DATA(3, 2 ) /*!< Specify PD.2 Pin Data Input/Output \hideinitializer */
  458. #define PD3 GPIO_PIN_DATA(3, 3 ) /*!< Specify PD.3 Pin Data Input/Output \hideinitializer */
  459. #define PD4 GPIO_PIN_DATA(3, 4 ) /*!< Specify PD.4 Pin Data Input/Output \hideinitializer */
  460. #define PD5 GPIO_PIN_DATA(3, 5 ) /*!< Specify PD.5 Pin Data Input/Output \hideinitializer */
  461. #define PD6 GPIO_PIN_DATA(3, 6 ) /*!< Specify PD.6 Pin Data Input/Output \hideinitializer */
  462. #define PD7 GPIO_PIN_DATA(3, 7 ) /*!< Specify PD.7 Pin Data Input/Output \hideinitializer */
  463. #define PD8 GPIO_PIN_DATA(3, 8 ) /*!< Specify PD.8 Pin Data Input/Output \hideinitializer */
  464. #define PD9 GPIO_PIN_DATA(3, 9 ) /*!< Specify PD.9 Pin Data Input/Output \hideinitializer */
  465. #define PD10 GPIO_PIN_DATA(3, 10) /*!< Specify PD.10 Pin Data Input/Output \hideinitializer */
  466. #define PD11 GPIO_PIN_DATA(3, 11) /*!< Specify PD.11 Pin Data Input/Output \hideinitializer */
  467. #define PD12 GPIO_PIN_DATA(3, 12) /*!< Specify PD.12 Pin Data Input/Output \hideinitializer */
  468. #define PD13 GPIO_PIN_DATA(3, 13) /*!< Specify PD.13 Pin Data Input/Output \hideinitializer */
  469. #define PD14 GPIO_PIN_DATA(3, 14) /*!< Specify PD.14 Pin Data Input/Output \hideinitializer */
  470. #define PE0 GPIO_PIN_DATA(4, 0 ) /*!< Specify PE.0 Pin Data Input/Output \hideinitializer */
  471. #define PE1 GPIO_PIN_DATA(4, 1 ) /*!< Specify PE.1 Pin Data Input/Output \hideinitializer */
  472. #define PE2 GPIO_PIN_DATA(4, 2 ) /*!< Specify PE.2 Pin Data Input/Output \hideinitializer */
  473. #define PE3 GPIO_PIN_DATA(4, 3 ) /*!< Specify PE.3 Pin Data Input/Output \hideinitializer */
  474. #define PE4 GPIO_PIN_DATA(4, 4 ) /*!< Specify PE.4 Pin Data Input/Output \hideinitializer */
  475. #define PE5 GPIO_PIN_DATA(4, 5 ) /*!< Specify PE.5 Pin Data Input/Output \hideinitializer */
  476. #define PE6 GPIO_PIN_DATA(4, 6 ) /*!< Specify PE.6 Pin Data Input/Output \hideinitializer */
  477. #define PE7 GPIO_PIN_DATA(4, 7 ) /*!< Specify PE.7 Pin Data Input/Output \hideinitializer */
  478. #define PE8 GPIO_PIN_DATA(4, 8 ) /*!< Specify PE.8 Pin Data Input/Output \hideinitializer */
  479. #define PE9 GPIO_PIN_DATA(4, 9 ) /*!< Specify PE.9 Pin Data Input/Output \hideinitializer */
  480. #define PE10 GPIO_PIN_DATA(4, 10) /*!< Specify PE.10 Pin Data Input/Output \hideinitializer */
  481. #define PE11 GPIO_PIN_DATA(4, 11) /*!< Specify PE.11 Pin Data Input/Output \hideinitializer */
  482. #define PE12 GPIO_PIN_DATA(4, 12) /*!< Specify PE.12 Pin Data Input/Output \hideinitializer */
  483. #define PE13 GPIO_PIN_DATA(4, 13) /*!< Specify PE.13 Pin Data Input/Output \hideinitializer */
  484. #define PE14 GPIO_PIN_DATA(4, 14) /*!< Specify PE.14 Pin Data Input/Output \hideinitializer */
  485. #define PE15 GPIO_PIN_DATA(4, 15) /*!< Specify PE.15 Pin Data Input/Output \hideinitializer */
  486. #define PF0 GPIO_PIN_DATA(5, 0 ) /*!< Specify PF.0 Pin Data Input/Output \hideinitializer */
  487. #define PF1 GPIO_PIN_DATA(5, 1 ) /*!< Specify PF.1 Pin Data Input/Output \hideinitializer */
  488. #define PF2 GPIO_PIN_DATA(5, 2 ) /*!< Specify PF.2 Pin Data Input/Output \hideinitializer */
  489. #define PF3 GPIO_PIN_DATA(5, 3 ) /*!< Specify PF.3 Pin Data Input/Output \hideinitializer */
  490. #define PF4 GPIO_PIN_DATA(5, 4 ) /*!< Specify PF.4 Pin Data Input/Output \hideinitializer */
  491. #define PF5 GPIO_PIN_DATA(5, 5 ) /*!< Specify PF.5 Pin Data Input/Output \hideinitializer */
  492. #define PF6 GPIO_PIN_DATA(5, 6 ) /*!< Specify PF.6 Pin Data Input/Output \hideinitializer */
  493. #define PF7 GPIO_PIN_DATA(5, 7 ) /*!< Specify PF.7 Pin Data Input/Output \hideinitializer */
  494. #define PF8 GPIO_PIN_DATA(5, 8 ) /*!< Specify PF.8 Pin Data Input/Output \hideinitializer */
  495. #define PF9 GPIO_PIN_DATA(5, 9 ) /*!< Specify PF.9 Pin Data Input/Output \hideinitializer */
  496. #define PF10 GPIO_PIN_DATA(5, 10) /*!< Specify PF.10 Pin Data Input/Output \hideinitializer */
  497. #define PF11 GPIO_PIN_DATA(5, 11) /*!< Specify PF.11 Pin Data Input/Output \hideinitializer */
  498. #define PG0 GPIO_PIN_DATA(6, 0 ) /*!< Specify PG.0 Pin Data Input/Output \hideinitializer */
  499. #define PG1 GPIO_PIN_DATA(6, 1 ) /*!< Specify PG.1 Pin Data Input/Output \hideinitializer */
  500. #define PG2 GPIO_PIN_DATA(6, 2 ) /*!< Specify PG.2 Pin Data Input/Output \hideinitializer */
  501. #define PG3 GPIO_PIN_DATA(6, 3 ) /*!< Specify PG.3 Pin Data Input/Output \hideinitializer */
  502. #define PG4 GPIO_PIN_DATA(6, 4 ) /*!< Specify PG.4 Pin Data Input/Output \hideinitializer */
  503. #define PG5 GPIO_PIN_DATA(6, 5 ) /*!< Specify PG.5 Pin Data Input/Output \hideinitializer */
  504. #define PG6 GPIO_PIN_DATA(6, 6 ) /*!< Specify PG.6 Pin Data Input/Output \hideinitializer */
  505. #define PG7 GPIO_PIN_DATA(6, 7 ) /*!< Specify PG.7 Pin Data Input/Output \hideinitializer */
  506. #define PG8 GPIO_PIN_DATA(6, 8 ) /*!< Specify PG.8 Pin Data Input/Output \hideinitializer */
  507. #define PG9 GPIO_PIN_DATA(6, 9 ) /*!< Specify PG.9 Pin Data Input/Output \hideinitializer */
  508. #define PG10 GPIO_PIN_DATA(6, 10) /*!< Specify PG.10 Pin Data Input/Output \hideinitializer */
  509. #define PG11 GPIO_PIN_DATA(6, 11) /*!< Specify PG.11 Pin Data Input/Output \hideinitializer */
  510. #define PG12 GPIO_PIN_DATA(6, 12) /*!< Specify PG.12 Pin Data Input/Output \hideinitializer */
  511. #define PG13 GPIO_PIN_DATA(6, 13) /*!< Specify PG.13 Pin Data Input/Output \hideinitializer */
  512. #define PG14 GPIO_PIN_DATA(6, 14) /*!< Specify PG.14 Pin Data Input/Output \hideinitializer */
  513. #define PG15 GPIO_PIN_DATA(6, 15) /*!< Specify PG.15 Pin Data Input/Output \hideinitializer */
  514. #define PH0 GPIO_PIN_DATA(7, 0 ) /*!< Specify PH.0 Pin Data Input/Output \hideinitializer */
  515. #define PH1 GPIO_PIN_DATA(7, 1 ) /*!< Specify PH.1 Pin Data Input/Output \hideinitializer */
  516. #define PH2 GPIO_PIN_DATA(7, 2 ) /*!< Specify PH.2 Pin Data Input/Output \hideinitializer */
  517. #define PH3 GPIO_PIN_DATA(7, 3 ) /*!< Specify PH.3 Pin Data Input/Output \hideinitializer */
  518. #define PH4 GPIO_PIN_DATA(7, 4 ) /*!< Specify PH.4 Pin Data Input/Output \hideinitializer */
  519. #define PH5 GPIO_PIN_DATA(7, 5 ) /*!< Specify PH.5 Pin Data Input/Output \hideinitializer */
  520. #define PH6 GPIO_PIN_DATA(7, 6 ) /*!< Specify PH.6 Pin Data Input/Output \hideinitializer */
  521. #define PH7 GPIO_PIN_DATA(7, 7 ) /*!< Specify PH.7 Pin Data Input/Output \hideinitializer */
  522. #define PH8 GPIO_PIN_DATA(7, 8 ) /*!< Specify PH.8 Pin Data Input/Output \hideinitializer */
  523. #define PH9 GPIO_PIN_DATA(7, 9 ) /*!< Specify PH.9 Pin Data Input/Output \hideinitializer */
  524. #define PH10 GPIO_PIN_DATA(7, 10) /*!< Specify PH.10 Pin Data Input/Output \hideinitializer */
  525. #define PH11 GPIO_PIN_DATA(7, 11) /*!< Specify PH.11 Pin Data Input/Output \hideinitializer */
  526. /*@}*/ /* end of group GPIO_EXPORTED_CONSTANTS */
  527. /** @addtogroup GPIO_EXPORTED_FUNCTIONS GPIO Exported Functions
  528. @{
  529. */
  530. /**
  531. * @brief Clear GPIO Pin Interrupt Flag
  532. *
  533. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  534. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  535. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  536. * It could be BIT0 ~ BIT13 for PE GPIO port.
  537. * It could be BIT0 ~ BIT11 for PG GPIO port.
  538. *
  539. * @return None
  540. *
  541. * @details Clear the interrupt status of specified GPIO pin.
  542. * \hideinitializer
  543. */
  544. #define GPIO_CLR_INT_FLAG(port, u32PinMask) ((port)->INTSRC = (u32PinMask))
  545. /**
  546. * @brief Disable Pin De-bounce Function
  547. *
  548. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  549. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  550. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  551. * It could be BIT0 ~ BIT13 for PE GPIO port.
  552. * It could be BIT0 ~ BIT11 for PG GPIO port.
  553. *
  554. * @return None
  555. *
  556. * @details Disable the interrupt de-bounce function of specified GPIO pin.
  557. * \hideinitializer
  558. */
  559. #define GPIO_DISABLE_DEBOUNCE(port, u32PinMask) ((port)->DBEN &= ~(u32PinMask))
  560. /**
  561. * @brief Enable Pin De-bounce Function
  562. *
  563. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  564. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  565. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  566. * It could be BIT0 ~ BIT13 for PE GPIO port.
  567. * It could be BIT0 ~ BIT11 for PG GPIO port.
  568. * @return None
  569. *
  570. * @details Enable the interrupt de-bounce function of specified GPIO pin.
  571. * \hideinitializer
  572. */
  573. #define GPIO_ENABLE_DEBOUNCE(port, u32PinMask) ((port)->DBEN |= (u32PinMask))
  574. /**
  575. * @brief Disable I/O Digital Input Path
  576. *
  577. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  578. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  579. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  580. * It could be BIT0 ~ BIT13 for PE GPIO port.
  581. * It could be BIT0 ~ BIT11 for PG GPIO port.
  582. *
  583. * @return None
  584. *
  585. * @details Disable I/O digital input path of specified GPIO pin.
  586. * \hideinitializer
  587. */
  588. #define GPIO_DISABLE_DIGITAL_PATH(port, u32PinMask) ((port)->DINOFF |= ((u32PinMask)<<16))
  589. /**
  590. * @brief Enable I/O Digital Input Path
  591. *
  592. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  593. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  594. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  595. * It could be BIT0 ~ BIT13 for PE GPIO port.
  596. * It could be BIT0 ~ BIT11 for PG GPIO port.
  597. *
  598. * @return None
  599. *
  600. * @details Enable I/O digital input path of specified GPIO pin.
  601. * \hideinitializer
  602. */
  603. #define GPIO_ENABLE_DIGITAL_PATH(port, u32PinMask) ((port)->DINOFF &= ~((u32PinMask)<<16))
  604. /**
  605. * @brief Disable I/O DOUT mask
  606. *
  607. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  608. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  609. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  610. * It could be BIT0 ~ BIT13 for PE GPIO port.
  611. * It could be BIT0 ~ BIT11 for PG GPIO port.
  612. *
  613. * @return None
  614. *
  615. * @details Disable I/O DOUT mask of specified GPIO pin.
  616. * \hideinitializer
  617. */
  618. #define GPIO_DISABLE_DOUT_MASK(port, u32PinMask) ((port)->DATMSK &= ~(u32PinMask))
  619. /**
  620. * @brief Enable I/O DOUT mask
  621. *
  622. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  623. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  624. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  625. * It could be BIT0 ~ BIT13 for PE GPIO port.
  626. * It could be BIT0 ~ BIT11 for PG GPIO port.
  627. *
  628. * @return None
  629. *
  630. * @details Enable I/O DOUT mask of specified GPIO pin.
  631. * \hideinitializer
  632. */
  633. #define GPIO_ENABLE_DOUT_MASK(port, u32PinMask) ((port)->DATMSK |= (u32PinMask))
  634. /**
  635. * @brief Get GPIO Pin Interrupt Flag
  636. *
  637. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  638. * @param[in] u32PinMask The single or multiple pins of specified GPIO port.
  639. * It could be BIT0 ~ BIT15 for PA, PB, PC, PD, PF and PH GPIO port.
  640. * It could be BIT0 ~ BIT13 for PE GPIO port.
  641. * It could be BIT0 ~ BIT11 for PG GPIO port.
  642. *
  643. * @retval 0 No interrupt at specified GPIO pin
  644. * @retval 1 The specified GPIO pin generate an interrupt
  645. *
  646. * @details Get the interrupt status of specified GPIO pin.
  647. * \hideinitializer
  648. */
  649. #define GPIO_GET_INT_FLAG(port, u32PinMask) ((port)->INTSRC & (u32PinMask))
  650. /**
  651. * @brief Set De-bounce Sampling Cycle Time
  652. *
  653. * @param[in] u32ClkSrc The de-bounce counter clock source. It could be GPIO_DBCTL_DBCLKSRC_HCLK or GPIO_DBCTL_DBCLKSRC_LIRC.
  654. * @param[in] u32ClkSel The de-bounce sampling cycle selection. It could be
  655. * - \ref GPIO_DBCTL_DBCLKSEL_1
  656. * - \ref GPIO_DBCTL_DBCLKSEL_2
  657. * - \ref GPIO_DBCTL_DBCLKSEL_4
  658. * - \ref GPIO_DBCTL_DBCLKSEL_8
  659. * - \ref GPIO_DBCTL_DBCLKSEL_16
  660. * - \ref GPIO_DBCTL_DBCLKSEL_32
  661. * - \ref GPIO_DBCTL_DBCLKSEL_64
  662. * - \ref GPIO_DBCTL_DBCLKSEL_128
  663. * - \ref GPIO_DBCTL_DBCLKSEL_256
  664. * - \ref GPIO_DBCTL_DBCLKSEL_512
  665. * - \ref GPIO_DBCTL_DBCLKSEL_1024
  666. * - \ref GPIO_DBCTL_DBCLKSEL_2048
  667. * - \ref GPIO_DBCTL_DBCLKSEL_4096
  668. * - \ref GPIO_DBCTL_DBCLKSEL_8192
  669. * - \ref GPIO_DBCTL_DBCLKSEL_16384
  670. * - \ref GPIO_DBCTL_DBCLKSEL_32768
  671. *
  672. * @return None
  673. *
  674. * @details Set the interrupt de-bounce sampling cycle time based on the debounce counter clock source. \n
  675. * Example: _GPIO_SET_DEBOUNCE_TIME(GPIO_DBCTL_DBCLKSRC_LIRC, GPIO_DBCTL_DBCLKSEL_4). \n
  676. * It's meaning the De-debounce counter clock source is internal 10 KHz and sampling cycle selection is 4. \n
  677. * Then the target de-bounce sampling cycle time is (4)*(1/(10*1000)) s = 4*0.0001 s = 400 us,
  678. * and system will sampling interrupt input once per 00 us.
  679. * \hideinitializer
  680. */
  681. #define GPIO_SET_DEBOUNCE_TIME(u32ClkSrc, u32ClkSel) (GPIO->DBCTL = (GPIO_DBCTL_ICLKON_Msk | (u32ClkSrc) | (u32ClkSel)))
  682. /**
  683. * @brief Get GPIO Port IN Data
  684. *
  685. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  686. *
  687. * @return The specified port data
  688. *
  689. * @details Get the PIN register of specified GPIO port.
  690. * \hideinitializer
  691. */
  692. #define GPIO_GET_IN_DATA(port) ((port)->PIN)
  693. /**
  694. * @brief Set GPIO Port OUT Data
  695. *
  696. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  697. * @param[in] u32Data GPIO port data.
  698. *
  699. * @return None
  700. *
  701. * @details Set the Data into specified GPIO port.
  702. * \hideinitializer
  703. */
  704. #define GPIO_SET_OUT_DATA(port, u32Data) ((port)->DOUT = (u32Data))
  705. /**
  706. * @brief Toggle Specified GPIO pin
  707. *
  708. * @param[in] u32Pin Pxy
  709. *
  710. * @return None
  711. *
  712. * @details Toggle the specified GPIO pint.
  713. * \hideinitializer
  714. */
  715. #define GPIO_TOGGLE(u32Pin) ((u32Pin) ^= 1)
  716. /**
  717. * @brief Enable External GPIO interrupt
  718. *
  719. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  720. * @param[in] u32Pin The pin of specified GPIO port.
  721. * It could be 0 ~ 15 for PA, PB, PC, PD, PF and PH GPIO port.
  722. * It could be 0 ~ 13 for PE GPIO port.
  723. * It could be 0 ~ 11 for PG GPIO port.
  724. * @param[in] u32IntAttribs The interrupt attribute of specified GPIO pin. It could be \n
  725. * GPIO_INT_RISING, GPIO_INT_FALLING, GPIO_INT_BOTH_EDGE, GPIO_INT_HIGH, GPIO_INT_LOW.
  726. *
  727. * @return None
  728. *
  729. * @details This function is used to enable specified GPIO pin interrupt.
  730. * \hideinitializer
  731. */
  732. #define GPIO_EnableEINT GPIO_EnableInt
  733. /**
  734. * @brief Disable External GPIO interrupt
  735. *
  736. * @param[in] port GPIO port. It could be It could be PA, PB, PC, PD, PE, PF, PG or PH.
  737. * @param[in] u32Pin The pin of specified GPIO port.
  738. * It could be 0 ~ 15 for PA, PB, PC, PD, PF and PH GPIO port.
  739. * It could be 0 ~ 13 for PE GPIO port.
  740. * It could be 0 ~ 11 for PG GPIO port.
  741. *
  742. * @return None
  743. *
  744. * @details This function is used to enable specified GPIO pin interrupt.
  745. * \hideinitializer
  746. */
  747. #define GPIO_DisableEINT GPIO_DisableInt
  748. void GPIO_SetMode(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode);
  749. void GPIO_EnableInt(GPIO_T *port, uint32_t u32Pin, uint32_t u32IntAttribs);
  750. void GPIO_DisableInt(GPIO_T *port, uint32_t u32Pin);
  751. void GPIO_SetSlewCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode);
  752. void GPIO_SetPullCtl(GPIO_T *port, uint32_t u32PinMask, uint32_t u32Mode);
  753. /*@}*/ /* end of group GPIO_EXPORTED_FUNCTIONS */
  754. /*@}*/ /* end of group GPIO_Driver */
  755. /*@}*/ /* end of group Standard_Driver */
  756. #ifdef __cplusplus
  757. }
  758. #endif
  759. #endif /* __GPIO_H__ */