fsl_iocon.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. * All rights reserved.
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_IOCON_H_
  9. #define _FSL_IOCON_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup lpc_iocon
  13. * @{
  14. */
  15. /*! @file */
  16. /*******************************************************************************
  17. * Definitions
  18. ******************************************************************************/
  19. /* Component ID definition, used by tools. */
  20. #ifndef FSL_COMPONENT_ID
  21. #define FSL_COMPONENT_ID "platform.drivers.lpc_iocon"
  22. #endif
  23. /*! @name Driver version */
  24. /*@{*/
  25. /*! @brief IOCON driver version 2.0.0. */
  26. #define FSL_IOCON_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  27. /*@}*/
  28. /**
  29. * @brief Array of IOCON pin definitions passed to IOCON_SetPinMuxing() must be in this format
  30. */
  31. typedef struct _iocon_group
  32. {
  33. uint32_t port : 8; /* Pin port */
  34. uint32_t pin : 8; /* Pin number */
  35. uint32_t ionumber : 8; /* IO number */
  36. uint32_t modefunc : 16; /* Function and mode */
  37. } iocon_group_t;
  38. /**
  39. * @brief IOCON function and mode selection definitions
  40. * @note See the User Manual for specific modes and functions supported by the various pins.
  41. */
  42. #if defined(FSL_FEATURE_IOCON_FUNC_FIELD_WIDTH) && (FSL_FEATURE_IOCON_FUNC_FIELD_WIDTH == 4)
  43. #define IOCON_FUNC0 0x0 /*!< Selects pin function 0 */
  44. #define IOCON_FUNC1 0x1 /*!< Selects pin function 1 */
  45. #define IOCON_FUNC2 0x2 /*!< Selects pin function 2 */
  46. #define IOCON_FUNC3 0x3 /*!< Selects pin function 3 */
  47. #define IOCON_FUNC4 0x4 /*!< Selects pin function 4 */
  48. #define IOCON_FUNC5 0x5 /*!< Selects pin function 5 */
  49. #define IOCON_FUNC6 0x6 /*!< Selects pin function 6 */
  50. #define IOCON_FUNC7 0x7 /*!< Selects pin function 7 */
  51. #define IOCON_FUNC8 0x8 /*!< Selects pin function 8 */
  52. #define IOCON_FUNC9 0x9 /*!< Selects pin function 9 */
  53. #define IOCON_FUNC10 0xA /*!< Selects pin function 10 */
  54. #define IOCON_FUNC11 0xB /*!< Selects pin function 11 */
  55. #define IOCON_FUNC12 0xC /*!< Selects pin function 12 */
  56. #define IOCON_FUNC13 0xD /*!< Selects pin function 13 */
  57. #define IOCON_FUNC14 0xE /*!< Selects pin function 14 */
  58. #define IOCON_FUNC15 0xF /*!< Selects pin function 15 */
  59. #if defined(IOCON_PIO_MODE_SHIFT)
  60. #define IOCON_MODE_INACT (0x0 << IOCON_PIO_MODE_SHIFT) /*!< No addition pin function */
  61. #define IOCON_MODE_PULLDOWN (0x1 << IOCON_PIO_MODE_SHIFT) /*!< Selects pull-down function */
  62. #define IOCON_MODE_PULLUP (0x2 << IOCON_PIO_MODE_SHIFT) /*!< Selects pull-up function */
  63. #define IOCON_MODE_REPEATER (0x3 << IOCON_PIO_MODE_SHIFT) /*!< Selects pin repeater function */
  64. #endif
  65. #if defined(IOCON_PIO_I2CSLEW_SHIFT)
  66. #define IOCON_GPIO_MODE (0x1 << IOCON_PIO_I2CSLEW_SHIFT) /*!< GPIO Mode */
  67. #define IOCON_I2C_SLEW (0x0 << IOCON_PIO_I2CSLEW_SHIFT) /*!< I2C Slew Rate Control */
  68. #endif
  69. #if defined(IOCON_PIO_SLEW_SHIFT)
  70. #define IOCON_SLEW_STANDARD (0x0 << IOCON_PIO_SLEW_SHIFT) /*!< Driver Slew Rate Control */
  71. #define IOCON_SLEW_FAST (0x1 << IOCON_PIO_SLEW_SHIFT) /*!< Driver Slew Rate Control */
  72. #endif
  73. #if defined(IOCON_PIO_INVERT_SHIFT)
  74. #define IOCON_INV_EN (0x1 << IOCON_PIO_INVERT_SHIFT) /*!< Enables invert function on input */
  75. #endif
  76. #if defined(IOCON_PIO_DIGIMODE_SHIFT)
  77. #define IOCON_ANALOG_EN (0x0 << IOCON_PIO_DIGIMODE_SHIFT) /*!< Enables analog function by setting 0 to bit 7 */
  78. #define IOCON_DIGITAL_EN \
  79. (0x1 << IOCON_PIO_DIGIMODE_SHIFT) /*!< Enables digital function by setting 1 to bit 7(default) */
  80. #endif
  81. #if defined(IOCON_PIO_FILTEROFF_SHIFT)
  82. #define IOCON_INPFILT_OFF (0x1 << IOCON_PIO_FILTEROFF_SHIFT) /*!< Input filter Off for GPIO pins */
  83. #define IOCON_INPFILT_ON (0x0 << IOCON_PIO_FILTEROFF_SHIFT) /*!< Input filter On for GPIO pins */
  84. #endif
  85. #if defined(IOCON_PIO_I2CDRIVE_SHIFT)
  86. #define IOCON_I2C_LOWDRIVER (0x0 << IOCON_PIO_I2CDRIVE_SHIFT) /*!< Low drive, Output drive sink is 4 mA */
  87. #define IOCON_I2C_HIGHDRIVER (0x1 << IOCON_PIO_I2CDRIVE_SHIFT) /*!< High drive, Output drive sink is 20 mA */
  88. #endif
  89. #if defined(IOCON_PIO_OD_SHIFT)
  90. #define IOCON_OPENDRAIN_EN (0x1 << IOCON_PIO_OD_SHIFT) /*!< Enables open-drain function */
  91. #endif
  92. #if defined(IOCON_PIO_I2CFILTER_SHIFT)
  93. #define IOCON_I2CFILTER_OFF (0x1 << IOCON_PIO_I2CFILTER_SHIFT) /*!< I2C 50 ns glitch filter enabled */
  94. #define IOCON_I2CFILTER_ON (0x0 << IOCON_PIO_I2CFILTER_SHIFT) /*!< I2C 50 ns glitch filter not enabled, */
  95. #endif
  96. #if defined(IOCON_PIO_ASW_SHIFT)
  97. #define IOCON_AWS_EN (0x1 << IOCON_PIO_ASW_SHIFT) /*!< Enables analog switch function */
  98. #endif
  99. #if defined(IOCON_PIO_SSEL_SHIFT)
  100. #define IOCON_SSEL_3V3 (0x0 << IOCON_PIO_SSEL_SHIFT) /*!< 3V3 signaling in I2C mode */
  101. #define IOCON_SSEL_1V8 (0x1 << IOCON_PIO_SSEL_SHIFT) /*!< 1V8 signaling in I2C mode */
  102. #endif
  103. #if defined(IOCON_PIO_ECS_SHIFT)
  104. #define IOCON_ECS_OFF (0x0 << IOCON_PIO_ECS_SHIFT) /*!< IO is an open drain cell */
  105. #define IOCON_ECS_ON (0x1 << IOCON_PIO_ECS_SHIFT) /*!< Pull-up resistor is connected */
  106. #endif
  107. #if defined(IOCON_PIO_S_MODE_SHIFT)
  108. #define IOCON_S_MODE_0CLK (0x0 << IOCON_PIO_S_MODE_SHIFT) /*!< Bypass input filter */
  109. #define IOCON_S_MODE_1CLK \
  110. (0x1 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 1 filter clock are rejected \ \ \
  111. */
  112. #define IOCON_S_MODE_2CLK \
  113. (0x2 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 2 filter clock2 are rejected \ \ \
  114. */
  115. #define IOCON_S_MODE_3CLK \
  116. (0x3 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 3 filter clock2 are rejected \ \ \
  117. */
  118. #define IOCON_S_MODE(clks) ((clks) << IOCON_PIO_S_MODE_SHIFT) /*!< Select clocks for digital input filter mode */
  119. #endif
  120. #if defined(IOCON_PIO_CLK_DIV_SHIFT)
  121. #define IOCON_CLKDIV(div) \
  122. ((div) \
  123. << IOCON_PIO_CLK_DIV_SHIFT) /*!< Select peripheral clock divider for input filter sampling clock, 2^n, n=0-6 */
  124. #endif
  125. #else
  126. #define IOCON_FUNC0 0x0 /*!< Selects pin function 0 */
  127. #define IOCON_FUNC1 0x1 /*!< Selects pin function 1 */
  128. #define IOCON_FUNC2 0x2 /*!< Selects pin function 2 */
  129. #define IOCON_FUNC3 0x3 /*!< Selects pin function 3 */
  130. #define IOCON_FUNC4 0x4 /*!< Selects pin function 4 */
  131. #define IOCON_FUNC5 0x5 /*!< Selects pin function 5 */
  132. #define IOCON_FUNC6 0x6 /*!< Selects pin function 6 */
  133. #define IOCON_FUNC7 0x7 /*!< Selects pin function 7 */
  134. #if defined(IOCON_PIO_MODE_SHIFT)
  135. #define IOCON_MODE_INACT (0x0 << IOCON_PIO_MODE_SHIFT) /*!< No addition pin function */
  136. #define IOCON_MODE_PULLDOWN (0x1 << IOCON_PIO_MODE_SHIFT) /*!< Selects pull-down function */
  137. #define IOCON_MODE_PULLUP (0x2 << IOCON_PIO_MODE_SHIFT) /*!< Selects pull-up function */
  138. #define IOCON_MODE_REPEATER (0x3 << IOCON_PIO_MODE_SHIFT) /*!< Selects pin repeater function */
  139. #endif
  140. #if defined(IOCON_PIO_I2CSLEW_SHIFT)
  141. #define IOCON_GPIO_MODE (0x1 << IOCON_PIO_I2CSLEW_SHIFT) /*!< GPIO Mode */
  142. #define IOCON_I2C_SLEW (0x0 << IOCON_PIO_I2CSLEW_SHIFT) /*!< I2C Slew Rate Control */
  143. #endif
  144. #if defined(IOCON_PIO_INVERT_SHIFT)
  145. #define IOCON_INV_EN (0x1 << IOCON_PIO_INVERT_SHIFT) /*!< Enables invert function on input */
  146. #endif
  147. #if defined(IOCON_PIO_DIGIMODE_SHIFT)
  148. #define IOCON_ANALOG_EN (0x0 << IOCON_PIO_DIGIMODE_SHIFT) /*!< Enables analog function by setting 0 to bit 7 */
  149. #define IOCON_DIGITAL_EN \
  150. (0x1 << IOCON_PIO_DIGIMODE_SHIFT) /*!< Enables digital function by setting 1 to bit 7(default) */
  151. #endif
  152. #if defined(IOCON_PIO_FILTEROFF_SHIFT)
  153. #define IOCON_INPFILT_OFF (0x1 << IOCON_PIO_FILTEROFF_SHIFT) /*!< Input filter Off for GPIO pins */
  154. #define IOCON_INPFILT_ON (0x0 << IOCON_PIO_FILTEROFF_SHIFT) /*!< Input filter On for GPIO pins */
  155. #endif
  156. #if defined(IOCON_PIO_I2CDRIVE_SHIFT)
  157. #define IOCON_I2C_LOWDRIVER (0x0 << IOCON_PIO_I2CDRIVE_SHIFT) /*!< Low drive, Output drive sink is 4 mA */
  158. #define IOCON_I2C_HIGHDRIVER (0x1 << IOCON_PIO_I2CDRIVE_SHIFT) /*!< High drive, Output drive sink is 20 mA */
  159. #endif
  160. #if defined(IOCON_PIO_OD_SHIFT)
  161. #define IOCON_OPENDRAIN_EN (0x1 << IOCON_PIO_OD_SHIFT) /*!< Enables open-drain function */
  162. #endif
  163. #if defined(IOCON_PIO_I2CFILTER_SHIFT)
  164. #define IOCON_I2CFILTER_OFF (0x1 << IOCON_PIO_I2CFILTER_SHIFT) /*!< I2C 50 ns glitch filter enabled */
  165. #define IOCON_I2CFILTER_ON (0x0 << IOCON_PIO_I2CFILTER_SHIFT) /*!< I2C 50 ns glitch filter not enabled */
  166. #endif
  167. #if defined(IOCON_PIO_S_MODE_SHIFT)
  168. #define IOCON_S_MODE_0CLK (0x0 << IOCON_PIO_S_MODE_SHIFT) /*!< Bypass input filter */
  169. #define IOCON_S_MODE_1CLK \
  170. (0x1 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 1 filter clock are rejected \ \ \
  171. */
  172. #define IOCON_S_MODE_2CLK \
  173. (0x2 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 2 filter clock2 are rejected \ \ \
  174. */
  175. #define IOCON_S_MODE_3CLK \
  176. (0x3 << IOCON_PIO_S_MODE_SHIFT) /*!< Input pulses shorter than 3 filter clock2 are rejected \ \ \
  177. */
  178. #define IOCON_S_MODE(clks) ((clks) << IOCON_PIO_S_MODE_SHIFT) /*!< Select clocks for digital input filter mode */
  179. #endif
  180. #if defined(IOCON_PIO_CLK_DIV_SHIFT)
  181. #define IOCON_CLKDIV(div) \
  182. ((div) \
  183. << IOCON_PIO_CLK_DIV_SHIFT) /*!< Select peripheral clock divider for input filter sampling clock, 2^n, n=0-6 */
  184. #endif
  185. #endif
  186. #if defined(__cplusplus)
  187. extern "C" {
  188. #endif
  189. #if (defined(FSL_FEATURE_IOCON_ONE_DIMENSION) && (FSL_FEATURE_IOCON_ONE_DIMENSION == 1))
  190. /**
  191. * @brief Sets I/O Control pin mux
  192. * @param base : The base of IOCON peripheral on the chip
  193. * @param ionumber : GPIO number to mux
  194. * @param modefunc : OR'ed values of type IOCON_*
  195. * @return Nothing
  196. */
  197. __STATIC_INLINE void IOCON_PinMuxSet(IOCON_Type *base, uint8_t ionumber, uint32_t modefunc)
  198. {
  199. base->PIO[ionumber] = modefunc;
  200. }
  201. #else
  202. /**
  203. * @brief Sets I/O Control pin mux
  204. * @param base : The base of IOCON peripheral on the chip
  205. * @param port : GPIO port to mux
  206. * @param pin : GPIO pin to mux
  207. * @param modefunc : OR'ed values of type IOCON_*
  208. * @return Nothing
  209. */
  210. __STATIC_INLINE void IOCON_PinMuxSet(IOCON_Type *base, uint8_t port, uint8_t pin, uint32_t modefunc)
  211. {
  212. base->PIO[port][pin] = modefunc;
  213. }
  214. #endif
  215. /**
  216. * @brief Set all I/O Control pin muxing
  217. * @param base : The base of IOCON peripheral on the chip
  218. * @param pinArray : Pointer to array of pin mux selections
  219. * @param arrayLength : Number of entries in pinArray
  220. * @return Nothing
  221. */
  222. __STATIC_INLINE void IOCON_SetPinMuxing(IOCON_Type *base, const iocon_group_t *pinArray, uint32_t arrayLength)
  223. {
  224. uint32_t i;
  225. for (i = 0; i < arrayLength; i++)
  226. {
  227. #if (defined(FSL_FEATURE_IOCON_ONE_DIMENSION) && (FSL_FEATURE_IOCON_ONE_DIMENSION == 1))
  228. IOCON_PinMuxSet(base, pinArray[i].ionumber, pinArray[i].modefunc);
  229. #else
  230. IOCON_PinMuxSet(base, pinArray[i].port, pinArray[i].pin, pinArray[i].modefunc);
  231. #endif /* FSL_FEATURE_IOCON_ONE_DIMENSION */
  232. }
  233. }
  234. /* @} */
  235. #if defined(__cplusplus)
  236. }
  237. #endif
  238. #endif /* _FSL_IOCON_H_ */