ioswm_8xx.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * @brief LPC8xx IOCON driver
  3. *
  4. * @note
  5. * Copyright(C) NXP Semiconductors, 2012
  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 licenser 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. #define _CHIP_COMMON_
  32. #include "chip.h"
  33. /*****************************************************************************
  34. * Private types/enumerations/variables
  35. ****************************************************************************/
  36. #define PINASSIGN_IDX(movable) (((movable) >> 4))
  37. #define PINSHIFT(movable) (((movable) & 0xF) << 3)
  38. /*****************************************************************************
  39. * Public types/enumerations/variables
  40. ****************************************************************************/
  41. /*****************************************************************************
  42. * Private functions
  43. ****************************************************************************/
  44. /*****************************************************************************
  45. * Public functions
  46. ****************************************************************************/
  47. /* Set the pin mode (pull-up/pull-down). */
  48. void Chip_IOCON_PinSetMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_MODE_T mode)
  49. {
  50. uint32_t reg;
  51. reg = pIOCON->PIO0[pin] & ~(PIN_MODE_MASK);
  52. pIOCON->PIO0[pin] = reg | (mode << PIN_MODE_BITNUM);
  53. }
  54. /* Enables/disables the pin hysteresis. */
  55. void Chip_IOCON_PinSetHysteresis(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool enable)
  56. {
  57. if (enable == true) {
  58. Chip_IOCON_PinEnableHysteresis(pIOCON, pin);
  59. }
  60. else {
  61. Chip_IOCON_PinDisableHysteresis(pIOCON, pin);
  62. }
  63. }
  64. /*Inverts (or not) the input seen by a pin. */
  65. void Chip_IOCON_PinSetInputInverted(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool invert)
  66. {
  67. if (invert == true) {
  68. Chip_IOCON_PinEnableInputInverted(pIOCON, pin);
  69. }
  70. else {
  71. Chip_IOCON_PinDisableInputInverted(pIOCON, pin);
  72. }
  73. }
  74. /* Enables/disables Open-Drain mode for a pin. */
  75. void Chip_IOCON_PinSetOpenDrainMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, bool open_drain)
  76. {
  77. if (open_drain == true) {
  78. Chip_IOCON_PinEnableOpenDrainMode(pIOCON, pin);
  79. }
  80. else {
  81. Chip_IOCON_PinDisableOpenDrainMode(pIOCON, pin);
  82. }
  83. }
  84. /* Enable/configure digital filter sample mode for a pin. */
  85. void Chip_IOCON_PinSetSampleMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_SMODE_T smode)
  86. {
  87. uint32_t reg;
  88. reg = pIOCON->PIO0[pin] & ~(PIN_SMODE_MASK);
  89. pIOCON->PIO0[pin] = reg | (smode << PIN_SMODE_BITNUM);
  90. }
  91. /* Set the peripheral clock divisor for a pin. */
  92. void Chip_IOCON_PinSetClockDivisor(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_CLKDIV_T clkdiv)
  93. {
  94. uint32_t reg;
  95. reg = pIOCON->PIO0[pin] & ~(PIN_CLKDIV_MASK);
  96. pIOCON->PIO0[pin] = reg | (clkdiv << PIN_CLKDIV_BITNUM);
  97. }
  98. /* Set the I2C mode for a pin. */
  99. void Chip_IOCON_PinSetI2CMode(LPC_IOCON_T *pIOCON, CHIP_PINx_T pin, CHIP_PIN_I2CMODE_T mode)
  100. {
  101. uint32_t reg;
  102. /* I2C mode bits only for I2C pins */
  103. reg = pIOCON->PIO0[pin] & ~(PIN_I2CMODE_MASK);
  104. pIOCON->PIO0[pin] = reg | (mode << PIN_I2CMODE_BITNUM);
  105. }
  106. /* Set all I/O Control pin muxing */
  107. void Chip_IOCON_SetPinMuxing(LPC_IOCON_T *pIOCON, const PINMUX_GRP_T* pinArray, uint32_t arrayLength)
  108. {
  109. uint32_t ix;
  110. for (ix = 0; ix < arrayLength; ix++ ) {
  111. Chip_IOCON_PinMuxSet(pIOCON, pinArray[ix].pin, pinArray[ix].modefunc);
  112. }
  113. }
  114. /* assign a movable pin function to a physical pin */
  115. void Chip_SWM_MovablePinAssign(CHIP_SWM_PIN_MOVABLE_T movable, uint8_t pin)
  116. {
  117. uint32_t temp;
  118. int pinshift = PINSHIFT(movable), regIndex = PINASSIGN_IDX(movable);
  119. temp = LPC_SWM->PINASSIGN[regIndex] & (~(0xFF << pinshift));
  120. LPC_SWM->PINASSIGN[regIndex] = temp | (pin << pinshift);
  121. }
  122. /* true enables, false disables a Switch Matrix fixed-pin Function */
  123. void Chip_SWM_FixedPinEnable(CHIP_SWM_PIN_FIXED_T pin, bool enable)
  124. {
  125. if (enable) {
  126. Chip_SWM_EnableFixedPin(pin);
  127. }
  128. else {
  129. Chip_SWM_DisableFixedPin(pin);
  130. }
  131. }