fsl_iocon.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _FSL_IOCON_H_
  35. #define _FSL_IOCON_H_
  36. #include "fsl_common.h"
  37. /*!
  38. * @addtogroup lpc_iocon
  39. * @{
  40. */
  41. /*! @file */
  42. /*******************************************************************************
  43. * Definitions
  44. ******************************************************************************/
  45. /* Component ID definition, used by tools. */
  46. #ifndef FSL_COMPONENT_ID
  47. #define FSL_COMPONENT_ID "platform.drivers.lpc_iocon"
  48. #endif
  49. /*! @name Driver version */
  50. /*@{*/
  51. /*! @brief IOCON driver version 2.0.0. */
  52. #define FSL_IOCON_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  53. /*@}*/
  54. /**
  55. * @brief Array of IOCON pin definitions passed to IOCON_SetPinMuxing() must be in this format
  56. */
  57. typedef struct _iocon_group
  58. {
  59. uint32_t port : 8; /* Pin port */
  60. uint32_t pin : 8; /* Pin number */
  61. uint32_t ionumber : 8; /* IO number */
  62. uint32_t modefunc : 16; /* Function and mode */
  63. } iocon_group_t;
  64. /**
  65. * @brief IOCON function and mode selection definitions
  66. * @note See the User Manual for specific modes and functions supported by the various pins.
  67. */
  68. #if defined(FSL_FEATURE_IOCON_FUNC_FIELD_WIDTH) && (FSL_FEATURE_IOCON_FUNC_FIELD_WIDTH == 4)
  69. #define IOCON_FUNC0 0x0 /*!< Selects pin function 0 */
  70. #define IOCON_FUNC1 0x1 /*!< Selects pin function 1 */
  71. #define IOCON_FUNC2 0x2 /*!< Selects pin function 2 */
  72. #define IOCON_FUNC3 0x3 /*!< Selects pin function 3 */
  73. #define IOCON_FUNC4 0x4 /*!< Selects pin function 4 */
  74. #define IOCON_FUNC5 0x5 /*!< Selects pin function 5 */
  75. #define IOCON_FUNC6 0x6 /*!< Selects pin function 6 */
  76. #define IOCON_FUNC7 0x7 /*!< Selects pin function 7 */
  77. #define IOCON_FUNC8 0x8 /*!< Selects pin function 8 */
  78. #define IOCON_FUNC9 0x9 /*!< Selects pin function 9 */
  79. #define IOCON_FUNC10 0xA /*!< Selects pin function 10 */
  80. #define IOCON_FUNC11 0xB /*!< Selects pin function 11 */
  81. #define IOCON_FUNC12 0xC /*!< Selects pin function 12 */
  82. #define IOCON_FUNC13 0xD /*!< Selects pin function 13 */
  83. #define IOCON_FUNC14 0xE /*!< Selects pin function 14 */
  84. #define IOCON_FUNC15 0xF /*!< Selects pin function 15 */
  85. #define IOCON_MODE_INACT (0x0 << 4) /*!< No addition pin function */
  86. #define IOCON_MODE_PULLDOWN (0x1 << 4) /*!< Selects pull-down function */
  87. #define IOCON_MODE_PULLUP (0x2 << 4) /*!< Selects pull-up function */
  88. #define IOCON_MODE_REPEATER (0x3 << 4) /*!< Selects pin repeater function */
  89. #define IOCON_HYS_EN (0x1 << 6) /*!< Enables hysteresis */
  90. #define IOCON_GPIO_MODE (0x1 << 6) /*!< GPIO Mode */
  91. #define IOCON_I2C_SLEW (0x0 << 6) /*!< I2C Slew Rate Control */
  92. #define IOCON_INV_EN (0x1 << 7) /*!< Enables invert function on input */
  93. #define IOCON_ANALOG_EN (0x0 << 8) /*!< Enables analog function by setting 0 to bit 7 */
  94. #define IOCON_DIGITAL_EN (0x1 << 8) /*!< Enables digital function by setting 1 to bit 7(default) */
  95. #define IOCON_STDI2C_EN (0x1 << 9) /*!< I2C standard mode/fast-mode */
  96. #define IOCON_FASTI2C_EN (0x3 << 9) /*!< I2C Fast-mode Plus and high-speed slave */
  97. #define IOCON_INPFILT_OFF (0x1 << 9) /*!< Input filter Off for GPIO pins */
  98. #define IOCON_INPFILT_ON (0x0 << 9) /*!< Input filter On for GPIO pins */
  99. #define IOCON_OPENDRAIN_EN (0x1 << 11) /*!< Enables open-drain function */
  100. #define IOCON_S_MODE_0CLK (0x0 << 12) /*!< Bypass input filter */
  101. #define IOCON_S_MODE_1CLK (0x1 << 12) /*!< Input pulses shorter than 1 filter clock are rejected */
  102. #define IOCON_S_MODE_2CLK (0x2 << 12) /*!< Input pulses shorter than 2 filter clock2 are rejected */
  103. #define IOCON_S_MODE_3CLK (0x3 << 12) /*!< Input pulses shorter than 3 filter clock2 are rejected */
  104. #define IOCON_S_MODE(clks) ((clks) << 12) /*!< Select clocks for digital input filter mode */
  105. #define IOCON_CLKDIV(div) \
  106. ((div) << 14) /*!< Select peripheral clock divider for input filter sampling clock, 2^n, n=0-6 */
  107. #else
  108. #define IOCON_FUNC0 0x0 /*!< Selects pin function 0 */
  109. #define IOCON_FUNC1 0x1 /*!< Selects pin function 1 */
  110. #define IOCON_FUNC2 0x2 /*!< Selects pin function 2 */
  111. #define IOCON_FUNC3 0x3 /*!< Selects pin function 3 */
  112. #define IOCON_FUNC4 0x4 /*!< Selects pin function 4 */
  113. #define IOCON_FUNC5 0x5 /*!< Selects pin function 5 */
  114. #define IOCON_FUNC6 0x6 /*!< Selects pin function 6 */
  115. #define IOCON_FUNC7 0x7 /*!< Selects pin function 7 */
  116. #define IOCON_MODE_INACT (0x0 << 3) /*!< No addition pin function */
  117. #define IOCON_MODE_PULLDOWN (0x1 << 3) /*!< Selects pull-down function */
  118. #define IOCON_MODE_PULLUP (0x2 << 3) /*!< Selects pull-up function */
  119. #define IOCON_MODE_REPEATER (0x3 << 3) /*!< Selects pin repeater function */
  120. #define IOCON_HYS_EN (0x1 << 5) /*!< Enables hysteresis */
  121. #define IOCON_GPIO_MODE (0x1 << 5) /*!< GPIO Mode */
  122. #define IOCON_I2C_SLEW (0x0 << 5) /*!< I2C Slew Rate Control */
  123. #define IOCON_INV_EN (0x1 << 6) /*!< Enables invert function on input */
  124. #define IOCON_ANALOG_EN (0x0 << 7) /*!< Enables analog function by setting 0 to bit 7 */
  125. #define IOCON_DIGITAL_EN (0x1 << 7) /*!< Enables digital function by setting 1 to bit 7(default) */
  126. #define IOCON_STDI2C_EN (0x1 << 8) /*!< I2C standard mode/fast-mode */
  127. #define IOCON_FASTI2C_EN (0x3 << 8) /*!< I2C Fast-mode Plus and high-speed slave */
  128. #define IOCON_INPFILT_OFF (0x1 << 8) /*!< Input filter Off for GPIO pins */
  129. #define IOCON_INPFILT_ON (0x0 << 8) /*!< Input filter On for GPIO pins */
  130. #define IOCON_OPENDRAIN_EN (0x1 << 10) /*!< Enables open-drain function */
  131. #define IOCON_S_MODE_0CLK (0x0 << 11) /*!< Bypass input filter */
  132. #define IOCON_S_MODE_1CLK (0x1 << 11) /*!< Input pulses shorter than 1 filter clock are rejected */
  133. #define IOCON_S_MODE_2CLK (0x2 << 11) /*!< Input pulses shorter than 2 filter clock2 are rejected */
  134. #define IOCON_S_MODE_3CLK (0x3 << 11) /*!< Input pulses shorter than 3 filter clock2 are rejected */
  135. #define IOCON_S_MODE(clks) ((clks) << 11) /*!< Select clocks for digital input filter mode */
  136. #define IOCON_CLKDIV(div) \
  137. ((div) << 13) /*!< Select peripheral clock divider for input filter sampling clock, 2^n, n=0-6 */
  138. #endif
  139. #if defined(__cplusplus)
  140. extern "C" {
  141. #endif
  142. #if (defined(FSL_FEATURE_IOCON_ONE_DIMENSION) && (FSL_FEATURE_IOCON_ONE_DIMENSION == 1))
  143. /**
  144. * @brief Sets I/O Control pin mux
  145. * @param base : The base of IOCON peripheral on the chip
  146. * @param ionumber : GPIO number to mux
  147. * @param modefunc : OR'ed values of type IOCON_*
  148. * @return Nothing
  149. */
  150. __STATIC_INLINE void IOCON_PinMuxSet(IOCON_Type *base, uint8_t ionumber, uint32_t modefunc)
  151. {
  152. base->PIO[ionumber] = modefunc;
  153. }
  154. #else
  155. /**
  156. * @brief Sets I/O Control pin mux
  157. * @param base : The base of IOCON peripheral on the chip
  158. * @param port : GPIO port to mux
  159. * @param pin : GPIO pin to mux
  160. * @param modefunc : OR'ed values of type IOCON_*
  161. * @return Nothing
  162. */
  163. __STATIC_INLINE void IOCON_PinMuxSet(IOCON_Type *base, uint8_t port, uint8_t pin, uint32_t modefunc)
  164. {
  165. base->PIO[port][pin] = modefunc;
  166. }
  167. #endif
  168. /**
  169. * @brief Set all I/O Control pin muxing
  170. * @param base : The base of IOCON peripheral on the chip
  171. * @param pinArray : Pointer to array of pin mux selections
  172. * @param arrayLength : Number of entries in pinArray
  173. * @return Nothing
  174. */
  175. __STATIC_INLINE void IOCON_SetPinMuxing(IOCON_Type *base, const iocon_group_t *pinArray, uint32_t arrayLength)
  176. {
  177. uint32_t i;
  178. for (i = 0; i < arrayLength; i++)
  179. {
  180. #if (defined(FSL_FEATURE_IOCON_ONE_DIMENSION) && (FSL_FEATURE_IOCON_ONE_DIMENSION == 1))
  181. IOCON_PinMuxSet(base, pinArray[i].ionumber, pinArray[i].modefunc);
  182. #else
  183. IOCON_PinMuxSet(base, pinArray[i].port, pinArray[i].pin, pinArray[i].modefunc);
  184. #endif /* FSL_FEATURE_IOCON_ONE_DIMENSION */
  185. }
  186. }
  187. /* @} */
  188. #if defined(__cplusplus)
  189. }
  190. #endif
  191. #endif /* _FSL_IOCON_H_ */