lpc_exti.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /**********************************************************************
  2. * $Id$ lpc_exti.c 2011-06-02
  3. *//**
  4. * @file lpc_exti.c
  5. * @brief Contains all functions support for External Interrupt
  6. * firmware library on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @addtogroup EXTI
  34. * @{
  35. */
  36. #ifdef __BUILD_WITH_EXAMPLE__
  37. #include "lpc_libcfg.h"
  38. #else
  39. #include "lpc_libcfg_default.h"
  40. #endif /* __BUILD_WITH_EXAMPLE__ */
  41. #ifdef _EXTI
  42. /* Includes ------------------------------------------------------------------- */
  43. #include "lpc_exti.h"
  44. /* Public Functions ----------------------------------------------------------- */
  45. /** @addtogroup EXTI_Public_Functions
  46. * @{
  47. */
  48. /*********************************************************************//**
  49. * @brief Initial for EXT
  50. * - Set EXTINT, EXTMODE, EXTPOLAR registers to default value
  51. * @param[in] None
  52. * @return None
  53. **********************************************************************/
  54. void EXTI_Init(void)
  55. {
  56. LPC_SC->EXTINT = 0xF;
  57. LPC_SC->EXTMODE = 0x0;
  58. LPC_SC->EXTPOLAR = 0x0;
  59. }
  60. /*********************************************************************//**
  61. * @brief Close EXT
  62. * @param[in] None
  63. * @return None
  64. **********************************************************************/
  65. void EXTI_DeInit(void)
  66. {
  67. ;
  68. }
  69. /*********************************************************************//**
  70. * @brief Configuration for EXT
  71. * - Set EXTINT, EXTMODE, EXTPOLAR register
  72. * @param[in] EXTICfg Pointer to a EXTI_InitTypeDef structure
  73. * that contains the configuration information for the
  74. * specified external interrupt
  75. * @return None
  76. **********************************************************************/
  77. void EXTI_Config(EXTI_InitTypeDef *EXTICfg)
  78. {
  79. LPC_SC->EXTINT = 0x0;
  80. EXTI_SetMode(EXTICfg->EXTI_Line, EXTICfg->EXTI_Mode);
  81. EXTI_SetPolarity(EXTICfg->EXTI_Line, EXTICfg->EXTI_polarity);
  82. }
  83. /*********************************************************************//**
  84. * @brief Set mode for EXTI pin
  85. * @param[in] EXTILine external interrupt line, should be:
  86. * - EXTI_EINT0: external interrupt line 0
  87. * - EXTI_EINT1: external interrupt line 1
  88. * - EXTI_EINT2: external interrupt line 2
  89. * - EXTI_EINT3: external interrupt line 3
  90. * @param[in] mode external mode, should be:
  91. * - EXTI_MODE_LEVEL_SENSITIVE
  92. * - EXTI_MODE_EDGE_SENSITIVE
  93. * @return None
  94. *********************************************************************/
  95. void EXTI_SetMode(EXTI_LINE_ENUM EXTILine, EXTI_MODE_ENUM mode)
  96. {
  97. if(mode == EXTI_MODE_EDGE_SENSITIVE)
  98. {
  99. LPC_SC->EXTMODE |= (1 << EXTILine);
  100. }
  101. else if(mode == EXTI_MODE_LEVEL_SENSITIVE)
  102. {
  103. LPC_SC->EXTMODE &= ~(1 << EXTILine);
  104. }
  105. }
  106. /*********************************************************************//**
  107. * @brief Set polarity for EXTI pin
  108. * @param[in] EXTILine external interrupt line, should be:
  109. * - EXTI_EINT0: external interrupt line 0
  110. * - EXTI_EINT1: external interrupt line 1
  111. * - EXTI_EINT2: external interrupt line 2
  112. * - EXTI_EINT3: external interrupt line 3
  113. * @param[in] polarity external polarity value, should be:
  114. * - EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE
  115. * - EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE
  116. * @return None
  117. *********************************************************************/
  118. void EXTI_SetPolarity(EXTI_LINE_ENUM EXTILine, EXTI_POLARITY_ENUM polarity)
  119. {
  120. if(polarity == EXTI_POLARITY_HIGH_ACTIVE_OR_RISING_EDGE)
  121. {
  122. LPC_SC->EXTPOLAR |= (1 << EXTILine);
  123. }
  124. else if(polarity == EXTI_POLARITY_LOW_ACTIVE_OR_FALLING_EDGE)
  125. {
  126. LPC_SC->EXTPOLAR &= ~(1 << EXTILine);
  127. }
  128. }
  129. /*********************************************************************//**
  130. * @brief Clear External interrupt flag
  131. * @param[in] EXTILine external interrupt line, should be:
  132. * - EXTI_EINT0: external interrupt line 0
  133. * - EXTI_EINT1: external interrupt line 1
  134. * - EXTI_EINT2: external interrupt line 2
  135. * - EXTI_EINT3: external interrupt line 3
  136. * @return None
  137. *********************************************************************/
  138. void EXTI_ClearEXTIFlag(EXTI_LINE_ENUM EXTILine)
  139. {
  140. LPC_SC->EXTINT |= (1 << EXTILine);
  141. }
  142. /**
  143. * @}
  144. */
  145. #endif /*_EXTI*/
  146. /**
  147. * @}
  148. */
  149. /* --------------------------------- End Of File ------------------------------ */