iocon_5410x.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * @brief LPC5410X IOCON register block and driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2014
  6. * All rights reserved.
  7. *
  8. * @par
  9. * Software that is described herein is for illustrative purposes only
  10. * which provides customers with programming information regarding the
  11. * LPC products. This software is supplied "AS IS" without any warranties of
  12. * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. * all warranties, express or implied, including all implied warranties of
  14. * merchantability, fitness for a particular purpose and non-infringement of
  15. * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. * or liability for the use of the software, conveys no license or rights under any
  17. * patent, copyright, mask work right, or any other intellectual property rights in
  18. * or to any products. NXP Semiconductors reserves the right to make changes
  19. * in the software without notification. NXP Semiconductors also makes no
  20. * representation or warranty that such application will be suitable for the
  21. * specified use without further testing or modification.
  22. *
  23. * @par
  24. * Permission to use, copy, modify, and distribute this software and its
  25. * documentation is hereby granted, under NXP Semiconductors' and its
  26. * licensor's relevant copyrights in the software, without fee, provided that it
  27. * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. * copyright, permission, and disclaimer notice must appear in all copies of
  29. * this code.
  30. */
  31. #ifndef __IOCON_5410X_H_
  32. #define __IOCON_5410X_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup IOCON_5410X CHIP: LPC5410X IOCON register block and driver
  37. * @ingroup CHIP_5410X_DRIVERS
  38. * @{
  39. */
  40. /**
  41. * @brief LPC5410X IO Configuration Unit register block structure
  42. */
  43. typedef struct { /*!< LPC5410X IOCON Structure */
  44. __IO uint32_t PIO[2][32];
  45. } LPC_IOCON_T;
  46. /**
  47. * @brief Array of IOCON pin definitions passed to Chip_IOCON_SetPinMuxing() must be in this format
  48. */
  49. typedef struct {
  50. uint32_t port : 8; /* Pin port */
  51. uint32_t pin : 8; /* Pin number */
  52. uint32_t modefunc : 16; /* Function and mode */
  53. } PINMUX_GRP_T;
  54. /**
  55. * IOCON function and mode selection definitions
  56. * See the User Manual for specific modes and functions supported by the
  57. * various LPC15XX pins.
  58. */
  59. #define IOCON_FUNC0 0x0 /*!< Selects pin function 0 */
  60. #define IOCON_FUNC1 0x1 /*!< Selects pin function 1 */
  61. #define IOCON_FUNC2 0x2 /*!< Selects pin function 2 */
  62. #define IOCON_FUNC3 0x3 /*!< Selects pin function 3 */
  63. #define IOCON_FUNC4 0x4 /*!< Selects pin function 4 */
  64. #define IOCON_FUNC5 0x5 /*!< Selects pin function 5 */
  65. #define IOCON_FUNC6 0x6 /*!< Selects pin function 6 */
  66. #define IOCON_FUNC7 0x7 /*!< Selects pin function 7 */
  67. #define IOCON_MODE_INACT (0x0 << 3) /*!< No addition pin function */
  68. #define IOCON_MODE_PULLDOWN (0x1 << 3) /*!< Selects pull-down function */
  69. #define IOCON_MODE_PULLUP (0x2 << 3) /*!< Selects pull-up function */
  70. #define IOCON_MODE_REPEATER (0x3 << 3) /*!< Selects pin repeater function */
  71. #define IOCON_HYS_EN (0x1 << 5) /*!< Enables hysteresis */
  72. #define IOCON_GPIO_MODE (0x1 << 5) /*!< GPIO Mode */
  73. #define IOCON_I2C_SLEW (0x1 << 5) /*!< I2C Slew Rate Control */
  74. #define IOCON_INV_EN (0x1 << 6) /*!< Enables invert function on input */
  75. #define IOCON_ANALOG_EN (0x0 << 7) /*!< Enables analog function by setting 0 to bit 7 */
  76. #define IOCON_DIGITAL_EN (0x1 << 7) /*!< Enables digital function by setting 1 to bit 7(default) */
  77. #define IOCON_STDI2C_EN (0x1 << 8) /*!< I2C standard mode/fast-mode */
  78. #define IOCON_FASTI2C_EN (0x3 << 8) /*!< I2C Fast-mode Plus and high-speed slave */
  79. #define IOCON_INPFILT_OFF (0x1 << 8) /*!< Input filter Off for GPIO pins */
  80. #define IOCON_INPFILT_ON (0x0 << 8) /*!< Input filter On for GPIO pins */
  81. #define IOCON_OPENDRAIN_EN (0x1 << 10) /*!< Enables open-drain function */
  82. #define IOCON_S_MODE_0CLK (0x0 << 11) /*!< Bypass input filter */
  83. #define IOCON_S_MODE_1CLK (0x1 << 11) /*!< Input pulses shorter than 1 filter clock are rejected */
  84. #define IOCON_S_MODE_2CLK (0x2 << 11) /*!< Input pulses shorter than 2 filter clock2 are rejected */
  85. #define IOCON_S_MODE_3CLK (0x3 << 11) /*!< Input pulses shorter than 3 filter clock2 are rejected */
  86. #define IOCON_S_MODE(clks) ((clks) << 11) /*!< Select clocks for digital input filter mode */
  87. #define IOCON_CLKDIV(div) ((div) << 13) /*!< Select peripheral clock divider for input filter sampling clock, 2^n, n=0-6 */
  88. /**
  89. * @brief Sets I/O Control pin mux
  90. * @param pIOCON : The base of IOCON peripheral on the chip
  91. * @param port : GPIO port to mux
  92. * @param pin : GPIO pin to mux
  93. * @param modefunc : OR'ed values or type IOCON_*
  94. * @return Nothing
  95. */
  96. STATIC INLINE void Chip_IOCON_PinMuxSet(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t modefunc)
  97. {
  98. pIOCON->PIO[port][pin] = modefunc;
  99. }
  100. /**
  101. * @brief I/O Control pin mux
  102. * @param pIOCON : The base of IOCON peripheral on the chip
  103. * @param port : GPIO port to mux
  104. * @param pin : GPIO pin to mux
  105. * @param mode : OR'ed values or type IOCON_*
  106. * @param func : Pin function, value of type IOCON_FUNC?
  107. * @return Nothing
  108. */
  109. STATIC INLINE void Chip_IOCON_PinMux(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint16_t mode, uint8_t func)
  110. {
  111. Chip_IOCON_PinMuxSet(pIOCON, port, pin, (uint32_t) (mode | func));
  112. }
  113. /**
  114. * @brief Set all I/O Control pin muxing
  115. * @param pIOCON : The base of IOCON peripheral on the chip
  116. * @param pinArray : Pointer to array of pin mux selections
  117. * @param arrayLength : Number of entries in pinArray
  118. * @return Nothing
  119. */
  120. void Chip_IOCON_SetPinMuxing(LPC_IOCON_T *pIOCON, const PINMUX_GRP_T *pinArray, uint32_t arrayLength);
  121. /**
  122. * @}
  123. */
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. #endif /* __IOCON_5410X_H_ */