gd32f10x_exti.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. ******************************************************************************
  3. * @brief EXTI functions of the firmware library.
  4. ******************************************************************************
  5. */
  6. /* Includes ------------------------------------------------------------------*/
  7. #include "gd32f10x_exti.h"
  8. /** @addtogroup GD32F10x_Firmware
  9. * @{
  10. */
  11. /** @defgroup EXTI
  12. * @brief EXTI driver modules
  13. * @{
  14. */
  15. /** @defgroup EXTI_Private_Defines
  16. * @{
  17. */
  18. /* No interrupt line is selected */
  19. #define EXTI_LINE_NULL ((uint32_t)0x00000000)
  20. /* ----------------- EXTI Reset Configuration Registers ------------------ */
  21. /* The reset value of EXTI_IER */
  22. #define EXTI_IER_RST ((uint32_t)0x00000000)
  23. /* The reset value of EXTI_EER */
  24. #define EXTI_EER_RST ((uint32_t)0x00000000)
  25. /* The reset value of EXTI_RTE */
  26. #define EXTI_RTE_RST ((uint32_t)0x00000000)
  27. /* The reset value of EXTI_FTE */
  28. #define EXTI_FTE_RST ((uint32_t)0x00000000)
  29. /* The reset value of EXTI_PD */
  30. #define EXTI_PD_RST ((uint32_t)0x000FFFFF)
  31. /**
  32. * @}
  33. */
  34. /** @defgroup EXTI_Private_Functions
  35. * @{
  36. */
  37. /**
  38. * @brief Reset the EXTI peripheral registers and the struct EXTI_InitPara.
  39. * @param EXTI_InitParaStruct: the struct EXTI_InitPara pointer.
  40. * @retval None
  41. */
  42. void EXTI_DeInit(EXTI_InitPara *EXTI_InitParaStruct)
  43. {
  44. /* Reset the EXTI peripheral registers */
  45. EXTI->IER = EXTI_IER_RST;
  46. EXTI->EER = EXTI_EER_RST;
  47. EXTI->RTE = EXTI_RTE_RST;
  48. EXTI->FTE = EXTI_FTE_RST;
  49. EXTI->PD = EXTI_PD_RST;
  50. /* Reset the struct EXTI_InitPara */
  51. EXTI_InitParaStruct->EXTI_LINE = EXTI_LINE_NULL;
  52. EXTI_InitParaStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  53. EXTI_InitParaStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  54. EXTI_InitParaStruct->EXTI_LINEEnable = DISABLE;
  55. }
  56. /**
  57. * @brief Initialize the EXTI peripheral registers.
  58. * @param EXTI_InitParaStruct: the struct EXTI_InitPara pointer.
  59. * @retval None
  60. */
  61. void EXTI_Init(EXTI_InitPara *EXTI_InitParaStruct)
  62. {
  63. uint32_t temp = 0;
  64. temp = (uint32_t)EXTI_BASE;
  65. if (EXTI_InitParaStruct->EXTI_LINEEnable != DISABLE) {
  66. /* Clear Interrupt and Event from EXTI Lines */
  67. EXTI->IER &= ~EXTI_InitParaStruct->EXTI_LINE;
  68. EXTI->EER &= ~EXTI_InitParaStruct->EXTI_LINE;
  69. temp += EXTI_InitParaStruct->EXTI_Mode;
  70. *(__IO uint32_t *) temp |= EXTI_InitParaStruct->EXTI_LINE;
  71. /* Clear the Rising and Falling edge trigger enable registers */
  72. EXTI->RTE &= ~EXTI_InitParaStruct->EXTI_LINE;
  73. EXTI->FTE &= ~EXTI_InitParaStruct->EXTI_LINE;
  74. /* Select the trigger type for the selected EXTI Lines */
  75. if (EXTI_InitParaStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) {
  76. /* Rising and Falling edge trigger are both selected */
  77. EXTI->RTE |= EXTI_InitParaStruct->EXTI_LINE;
  78. EXTI->FTE |= EXTI_InitParaStruct->EXTI_LINE;
  79. } else {
  80. temp = (uint32_t)EXTI_BASE;
  81. temp += EXTI_InitParaStruct->EXTI_Trigger;
  82. *(__IO uint32_t *) temp |= EXTI_InitParaStruct->EXTI_LINE;
  83. }
  84. } else {
  85. temp += EXTI_InitParaStruct->EXTI_Mode;
  86. /* Disable the selected EXTI lines */
  87. *(__IO uint32_t *) temp &= ~EXTI_InitParaStruct->EXTI_LINE;
  88. }
  89. }
  90. /**
  91. * @brief Activate the software interrupt or event request of the selected EXTI Lines.
  92. * @param EXTI_LINE: the selected EXTI lines.
  93. * This parameter can be any combination of EXTI_LINEx where x can be (0..19).
  94. * @retval None
  95. */
  96. void EXTI_SWINT_Enable(uint32_t EXTI_LINE)
  97. {
  98. /* Enable the software interrupt or event request of the selected EXTI Lines */
  99. EXTI->SIE |= EXTI_LINE;
  100. }
  101. /**
  102. * @brief Get the bit flag of the selected EXTI lines.
  103. * @param EXTI_LINE: the selected EXTI lines.
  104. * This parameter can be any combination of EXTI_LINEx where x can be (0..19).
  105. * @retval The new value of EXTI_LINE (SET or RESET).
  106. */
  107. TypeState EXTI_GetBitState(uint32_t EXTI_LINE)
  108. {
  109. /* Check and get the selected EXTI lines flag */
  110. if ((EXTI->PD & EXTI_LINE) != (uint32_t)RESET) {
  111. /* EXTI_LINE bit is SET */
  112. return SET;
  113. } else {
  114. /* EXTI_LINE bit is RESET */
  115. return RESET;
  116. }
  117. }
  118. /**
  119. * @brief Clear the bit flag of the selected EXTI lines.
  120. * @param EXTI_LINE: the selected EXTI lines.
  121. * This parameter can be any combination of EXTI_LINEx where x can be (0..19).
  122. * @retval None
  123. */
  124. void EXTI_ClearBitState(uint32_t EXTI_LINE)
  125. {
  126. /* Clear the bit flag of the selected EXTI lines */
  127. EXTI->PD = EXTI_LINE;
  128. }
  129. /**
  130. * @brief Get the interrupt bit flag of the selected EXTI lines..
  131. * @param EXTI_LINE: the selected EXTI lines.
  132. * This parameter can be any combination of EXTI_LINEx where x can be (0..19).
  133. * @retval The new value of EXTI_LINE (SET or RESET).
  134. */
  135. TypeState EXTI_GetIntBitState(uint32_t EXTI_LINE)
  136. {
  137. /* Check and get the interrupt source is set or not */
  138. if (((EXTI->PD & EXTI_LINE) != (uint32_t)RESET) && ((EXTI->IER & EXTI_LINE) != (uint32_t)RESET)) {
  139. /* The interrupt bit of EXTI_LINE is SET */
  140. return SET;
  141. } else {
  142. /* The interrupt bit of EXTI_LINE is RESET */
  143. return RESET;
  144. }
  145. }
  146. /**
  147. * @brief Clear the interrupt bit flag of the selected EXTI lines.
  148. * @param EXTI_LINE: the selected EXTI lines.
  149. * This parameter can be any combination of EXTI_LINEx where x can be (0..19).
  150. * @retval None
  151. */
  152. void EXTI_ClearIntBitState(uint32_t EXTI_LINE)
  153. {
  154. /* Clear the interrupt bit flag of the selected EXTI lines */
  155. EXTI->PD = EXTI_LINE;
  156. }
  157. /**
  158. * @}
  159. */
  160. /**
  161. * @}
  162. */
  163. /**
  164. * @}
  165. */