gpio_001.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * @brief GPIO Registers and Functions
  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 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 __GPIO_001_H_
  32. #define __GPIO_001_H_
  33. #include "sys_config.h"
  34. #include "cmsis.h"
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38. /** @defgroup GPIO_ADC_001 IP: GPIO register block and driver
  39. * @ingroup IP_Drivers
  40. * @{
  41. */
  42. #define GPIO_PORT_BITS 32
  43. #if defined(CHIP_LPC11UXX)
  44. #define GPIO_PORT_COUNT 2
  45. #endif
  46. #if defined(CHIP_LPC18XX) || defined(CHIP_LPC43XX)
  47. #define GPIO_PORT_COUNT 6
  48. #endif
  49. /**
  50. * @brief GPIO port register block structure
  51. */
  52. typedef struct { /*!< GPIO_PORT Structure */
  53. __IO uint8_t B[GPIO_PORT_COUNT][32]; /*!< Byte pin registers port 0 to 5; pins PIOn_0 to PIOn_31 */
  54. __I uint8_t RESERVED0[4096 - (GPIO_PORT_COUNT * 32 * sizeof(uint8_t))];
  55. __IO uint32_t W[GPIO_PORT_COUNT][32]; /*!< Word pin registers port 0 to 5 */
  56. __I uint8_t RESERVED1[4096 - (GPIO_PORT_COUNT * 32 * sizeof(uint32_t))];
  57. __IO uint32_t DIR[GPIO_PORT_COUNT]; /*!< Direction registers port n */
  58. __I uint32_t RESERVED2[32 - GPIO_PORT_COUNT];
  59. __IO uint32_t MASK[GPIO_PORT_COUNT]; /*!< Mask register port n */
  60. __I uint32_t RESERVED3[32 - GPIO_PORT_COUNT];
  61. __IO uint32_t PIN[GPIO_PORT_COUNT]; /*!< Portpin register port n */
  62. __I uint32_t RESERVED4[32 - GPIO_PORT_COUNT];
  63. __IO uint32_t MPIN[GPIO_PORT_COUNT]; /*!< Masked port register port n */
  64. __I uint32_t RESERVED5[32 - GPIO_PORT_COUNT];
  65. __IO uint32_t SET[GPIO_PORT_COUNT]; /*!< Write: Set register for port n Read: output bits for port n */
  66. __I uint32_t RESERVED6[32 - GPIO_PORT_COUNT];
  67. __O uint32_t CLR[GPIO_PORT_COUNT]; /*!< Clear port n */
  68. __I uint32_t RESERVED7[32 - GPIO_PORT_COUNT];
  69. __O uint32_t NOT[GPIO_PORT_COUNT]; /*!< Toggle port n */
  70. } IP_GPIO_001_Type;
  71. /**
  72. * @brief Initialize GPIO block
  73. * @param pGPIO : The Base Address of the GPIO block
  74. * @return Nothing
  75. */
  76. STATIC INLINE void IP_GPIO_Init(IP_GPIO_001_Type *pGPIO)
  77. {}
  78. /**
  79. * @brief Set a GPIO port/bit state
  80. * @param pGPIO : The Base Address of the GPIO block
  81. * @param Port : GPIO port to set
  82. * @param Bit : GPIO bit to set
  83. * @param Setting : true for high, false for low
  84. * @return Nothing
  85. */
  86. STATIC INLINE void IP_GPIO_WritePortBit(IP_GPIO_001_Type *pGPIO, uint32_t Port, uint8_t Bit, bool Setting)
  87. {
  88. pGPIO->B[Port][Bit] = Setting;
  89. }
  90. /**
  91. * @brief Seta GPIO direction
  92. * @param pGPIO : The Base Address of the GPIO block
  93. * @param Port : GPIO port to set
  94. * @param Bit : GPIO bit to set
  95. * @param Setting : true for output, false for input
  96. * @return Nothing
  97. */
  98. STATIC INLINE void IP_GPIO_WriteDirBit(IP_GPIO_001_Type *pGPIO, uint32_t Port, uint8_t Bit, bool Setting)
  99. {
  100. if (Setting) {
  101. pGPIO->DIR[Port] |= 1UL << Bit;
  102. }
  103. else {
  104. pGPIO->DIR[Port] &= ~(1UL << Bit);
  105. }
  106. }
  107. /**
  108. * @brief Read a GPIO state
  109. * @param pGPIO : The Base Address of the GPIO block
  110. * @param Port : GPIO port to read
  111. * @param Bit : GPIO bit to read
  112. * @return true of the GPIO is high, false if low
  113. */
  114. STATIC INLINE bool IP_GPIO_ReadPortBit(IP_GPIO_001_Type *pGPIO, uint32_t Port, uint8_t Bit)
  115. {
  116. return (bool) pGPIO->B[Port][Bit];
  117. }
  118. /**
  119. * @brief Read a GPIO direction (out ot in)
  120. * @param pGPIO : The Base Address of the GPIO block
  121. * @param Port : GPIO port to read
  122. * @param Bit : GPIO bit to read
  123. * @return true of the GPIO is an output, false if input
  124. */
  125. STATIC INLINE bool IP_GPIO_ReadDirBit(IP_GPIO_001_Type *pGPIO, uint32_t Port, uint8_t Bit)
  126. {
  127. return (bool) (((pGPIO->DIR[Port]) >> Bit) & 1);
  128. }
  129. /**
  130. * @}
  131. */
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif /* __GPIO_001_H_ */