gpiogroup_5410x.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * @brief LPC5410x GPIO group 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 __GPIOGROUP_5410X_H_
  32. #define __GPIOGROUP_5410X_H_
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /** @defgroup GPIOGP_5410X CHIP: LPC5410x GPIO group driver
  37. * @ingroup CHIP_5410X_DRIVERS
  38. * @{
  39. */
  40. /**
  41. * @brief GPIO grouped interrupt register block structure
  42. */
  43. typedef struct { /*!< GPIO_GROUP_INTn Structure */
  44. __IO uint32_t CTRL; /*!< GPIO grouped interrupt control register */
  45. __I uint32_t RESERVED0[7];
  46. __IO uint32_t PORT_POL[8]; /*!< GPIO grouped interrupt port polarity register */
  47. __IO uint32_t PORT_ENA[8]; /*!< GPIO grouped interrupt port m enable register */
  48. uint32_t RESERVED1[4072];
  49. } LPC_GPIOGROUPINT_T;
  50. /**
  51. * LPC5410x GPIO group bit definitions
  52. */
  53. #define GPIOGR_INT (1 << 0) /*!< GPIO interrupt pending/clear bit */
  54. #define GPIOGR_COMB (1 << 1) /*!< GPIO interrupt OR(0)/AND(1) mode bit */
  55. #define GPIOGR_TRIG (1 << 2) /*!< GPIO interrupt edge(0)/level(1) mode bit */
  56. /**
  57. * @brief Initialize GPIO group interrupt block
  58. * @param pGPIOGPINT : The base of GPIO group peripheral on the chip
  59. * @return Nothing
  60. */
  61. STATIC INLINE void Chip_GPIOGP_Init(LPC_GPIOGROUPINT_T *pGPIOGPINT)
  62. {
  63. Chip_Clock_EnablePeriphClock(SYSCON_CLOCK_GINT);
  64. Chip_SYSCON_PeriphReset(RESET_GINT);
  65. }
  66. /**
  67. * @brief De-Initialize GPIO group interrupt block
  68. * @param pGPIOGPINT : The base of GPIO group peripheral on the chip
  69. * @return Nothing
  70. */
  71. STATIC INLINE void Chip_GPIOGP_DeInit(LPC_GPIOGROUPINT_T *pGPIOGPINT)
  72. {
  73. Chip_Clock_DisablePeriphClock(SYSCON_CLOCK_GINT);
  74. }
  75. /**
  76. * @brief Clear interrupt pending status for the selected group
  77. * @param pGPIOGPINT : Pointer to GPIO group register block
  78. * @param group : GPIO group number
  79. * @return None
  80. */
  81. STATIC INLINE void Chip_GPIOGP_ClearIntStatus(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group)
  82. {
  83. pGPIOGPINT[group].CTRL |= GPIOGR_INT;
  84. }
  85. /**
  86. * @brief Returns current GPIO group inetrrupt pending status
  87. * @param pGPIOGPINT : Pointer to GPIO group register block
  88. * @param group : GPIO group number
  89. * @return true if the group interrupt is pending, otherwise false.
  90. */
  91. STATIC INLINE bool Chip_GPIOGP_GetIntStatus(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group)
  92. {
  93. return (bool) ((pGPIOGPINT[group].CTRL & GPIOGR_INT) != 0);
  94. }
  95. /**
  96. * @brief Selected GPIO group functionality for trigger on any pin in group (OR mode)
  97. * @param pGPIOGPINT : Pointer to GPIO group register block
  98. * @param group : GPIO group number
  99. * @return None
  100. */
  101. STATIC INLINE void Chip_GPIOGP_SelectOrMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group)
  102. {
  103. pGPIOGPINT[group].CTRL &= ~(GPIOGR_COMB | GPIOGR_INT);
  104. }
  105. /**
  106. * @brief Selected GPIO group functionality for trigger on all matching pins in group (AND mode)
  107. * @param pGPIOGPINT : Pointer to GPIO group register block
  108. * @param group : GPIO group number
  109. * @return None
  110. */
  111. STATIC INLINE void Chip_GPIOGP_SelectAndMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group)
  112. {
  113. pGPIOGPINT[group].CTRL = (pGPIOGPINT[group].CTRL & ~GPIOGR_INT) | GPIOGR_COMB;
  114. }
  115. /**
  116. * @brief Selected GPIO group functionality edge trigger mode
  117. * @param pGPIOGPINT : Pointer to GPIO group register block
  118. * @param group : GPIO group number
  119. * @return None
  120. */
  121. STATIC INLINE void Chip_GPIOGP_SelectEdgeMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group)
  122. {
  123. pGPIOGPINT[group].CTRL &= ~(GPIOGR_TRIG | GPIOGR_INT);
  124. }
  125. /**
  126. * @brief Selected GPIO group functionality level trigger mode
  127. * @param pGPIOGPINT : Pointer to GPIO group register block
  128. * @param group : GPIO group number
  129. * @return None
  130. */
  131. STATIC INLINE void Chip_GPIOGP_SelectLevelMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group)
  132. {
  133. pGPIOGPINT[group].CTRL = (pGPIOGPINT[group].CTRL & ~GPIOGR_INT) | GPIOGR_TRIG;
  134. }
  135. /**
  136. * @brief Set selected pins for the group and port to low level trigger
  137. * @param pGPIOGPINT : Pointer to GPIO group register block
  138. * @param group : GPIO group number
  139. * @param port : GPIO port number
  140. * @param pinMask : Or'ed value of pins to select for low level (bit 0 = pin 0, 1 = pin1, etc.)
  141. * @return None
  142. */
  143. STATIC INLINE void Chip_GPIOGP_SelectLowLevel(LPC_GPIOGROUPINT_T *pGPIOGPINT,
  144. uint8_t group,
  145. uint8_t port,
  146. uint32_t pinMask)
  147. {
  148. pGPIOGPINT[group].PORT_POL[port] &= ~pinMask;
  149. }
  150. /**
  151. * @brief Set selected pins for the group and port to high level trigger
  152. * @param pGPIOGPINT : Pointer to GPIO group register block
  153. * @param group : GPIO group number
  154. * @param port : GPIO port number
  155. * @param pinMask : Or'ed value of pins to select for high level (bit 0 = pin 0, 1 = pin1, etc.)
  156. * @return None
  157. */
  158. STATIC INLINE void Chip_GPIOGP_SelectHighLevel(LPC_GPIOGROUPINT_T *pGPIOGPINT,
  159. uint8_t group,
  160. uint8_t port,
  161. uint32_t pinMask)
  162. {
  163. pGPIOGPINT[group].PORT_POL[port] |= pinMask;
  164. }
  165. /**
  166. * @brief Disabled selected pins for the group interrupt
  167. * @param pGPIOGPINT : Pointer to GPIO group register block
  168. * @param group : GPIO group number
  169. * @param port : GPIO port number
  170. * @param pinMask : Or'ed value of pins to disable interrupt for (bit 0 = pin 0, 1 = pin1, etc.)
  171. * @return None
  172. * @note Disabled pins do not contribute to the group interrupt.
  173. */
  174. STATIC INLINE void Chip_GPIOGP_DisableGroupPins(LPC_GPIOGROUPINT_T *pGPIOGPINT,
  175. uint8_t group,
  176. uint8_t port,
  177. uint32_t pinMask)
  178. {
  179. pGPIOGPINT[group].PORT_ENA[port] &= ~pinMask;
  180. }
  181. /**
  182. * @brief Enable selected pins for the group interrupt
  183. * @param pGPIOGPINT : Pointer to GPIO group register block
  184. * @param group : GPIO group number
  185. * @param port : GPIO port number
  186. * @param pinMask : Or'ed value of pins to enable interrupt for (bit 0 = pin 0, 1 = pin1, etc.)
  187. * @return None
  188. * @note Enabled pins contribute to the group interrupt.
  189. */
  190. STATIC INLINE void Chip_GPIOGP_EnableGroupPins(LPC_GPIOGROUPINT_T *pGPIOGPINT,
  191. uint8_t group,
  192. uint8_t port,
  193. uint32_t pinMask)
  194. {
  195. pGPIOGPINT[group].PORT_ENA[port] |= pinMask;
  196. }
  197. /**
  198. * @}
  199. */
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203. #endif /* __GPIOGROUP_5410X_H_ */