HAL_EXTI.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. ******************************************************************************
  3. * @file HAL_EXTI.c
  4. * @version V1.0.0
  5. * @date 2020
  6. * @brief EXTI HAL module driver.
  7. * This file provides firmware functions to manage the following
  8. * functionalities of the General Purpose Input/Output (EXTI) peripheral:
  9. * + Initialization functions
  10. * + IO operation functions
  11. ******************************************************************************
  12. */
  13. #include "ACM32Fxx_HAL.h"
  14. /*********************************************************************************
  15. * Function : HAL_EXTI_IRQHandler
  16. * Description : Handle EXTI interrupt request.
  17. * Input : huart: EXTI handle.
  18. * Output :
  19. * Author : Chris_Kyle Data : 2020��
  20. **********************************************************************************/
  21. void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti)
  22. {
  23. if (EXTI->PDR & hexti->u32_Line)
  24. {
  25. EXTI->PDR = hexti->u32_Line;
  26. }
  27. }
  28. /*********************************************************************************
  29. * Function : HAL_EXTI_SetConfigLine
  30. * Description :
  31. * Input :
  32. * Outpu :
  33. * Author : Chris_Kyle Data : 2020年
  34. **********************************************************************************/
  35. HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti)
  36. {
  37. uint32_t lu32_IndexLine;
  38. #if (USE_FULL_ASSERT == 1)
  39. if (!IS_EXTI_ALL_LINE(hexti->u32_Line)) return HAL_ERROR;
  40. if (!IS_EXTI_MODE(hexti->u32_Mode)) return HAL_ERROR;
  41. if (!IS_EXTI_TRIGGER(hexti->u32_Trigger)) return HAL_ERROR;
  42. /* Line0 ~ 15 trigger from GPIO */
  43. if (!(hexti->u32_Line >> 16))
  44. {
  45. if (!IS_EXTI_GPIOSEL(hexti->u32_GPIOSel)) return HAL_ERROR;
  46. }
  47. #endif
  48. lu32_IndexLine = hexti->u32_Line;
  49. /* Interrupt Mode */
  50. if (hexti->u32_Mode == EXTI_MODE_INTERRUPT)
  51. {
  52. EXTI->IENR |= lu32_IndexLine;
  53. EXTI->EENR &= ~lu32_IndexLine;
  54. NVIC_ClearPendingIRQ(EXTI_IRQn);
  55. NVIC_EnableIRQ(EXTI_IRQn);
  56. }
  57. /* Event Mode */
  58. else if (hexti->u32_Mode == EXTI_MODE_EVENT)
  59. {
  60. EXTI->EENR |= lu32_IndexLine;
  61. EXTI->IENR &= ~lu32_IndexLine;
  62. }
  63. if (hexti->u32_Trigger == EXTI_TRIGGER_RISING)
  64. {
  65. EXTI->RTENR |= lu32_IndexLine;
  66. EXTI->FTENR &= ~lu32_IndexLine;
  67. }
  68. else if (hexti->u32_Trigger == EXTI_TRIGGER_FALLING)
  69. {
  70. EXTI->FTENR |= lu32_IndexLine;
  71. EXTI->RTENR &= ~lu32_IndexLine;
  72. }
  73. else
  74. {
  75. EXTI->FTENR |= lu32_IndexLine;
  76. EXTI->RTENR |= lu32_IndexLine;
  77. }
  78. /* Line0 ~ 15 trigger from GPIO */
  79. if (!(hexti->u32_Line >> 16))
  80. {
  81. lu32_IndexLine = 0;
  82. while(hexti->u32_Line >> lu32_IndexLine != 0x01)
  83. {
  84. lu32_IndexLine++;
  85. }
  86. /* Line0 ~ 7 */
  87. if (lu32_IndexLine < 8)
  88. {
  89. EXTI->EXTICR1 = (EXTI->EXTICR1 & ~(0x0F << (lu32_IndexLine * 4))) | hexti->u32_GPIOSel << (lu32_IndexLine * 4);
  90. }
  91. /* Line8 ~ 15 */
  92. else
  93. {
  94. lu32_IndexLine -= 8;
  95. EXTI->EXTICR2 = (EXTI->EXTICR2 & ~(0x0F << (lu32_IndexLine * 4))) | hexti->u32_GPIOSel << (lu32_IndexLine * 4);
  96. }
  97. }
  98. return HAL_OK;
  99. }
  100. /*********************************************************************************
  101. * Function : HAL_EXTI_SoftTrigger
  102. * Description : Software trigger EXTI
  103. * Input :
  104. * Outpu :
  105. * Author : Chris_Kyle Data : 2020年
  106. **********************************************************************************/
  107. void HAL_EXTI_SoftTrigger(EXTI_HandleTypeDef *hexti)
  108. {
  109. #if (USE_FULL_ASSERT == 1)
  110. if (!IS_EXTI_ALL_LINE(hexti->u32_Line)) return;
  111. #endif
  112. /* Set pending BIT */
  113. EXTI->SWIER |= hexti->u32_Line;
  114. }
  115. /*********************************************************************************
  116. * Function : HAL_EXTI_GetPending
  117. * Description : Get interrupt pending bit of a dedicated line.
  118. * Input :
  119. * Outpu :
  120. * Author : Chris_Kyle Data : 2020年
  121. **********************************************************************************/
  122. bool HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti)
  123. {
  124. #if (USE_FULL_ASSERT == 1)
  125. if (!IS_EXTI_ALL_LINE(hexti->u32_Line)) return HAL_ERROR;
  126. #endif
  127. if (hexti->u32_Line & EXTI->PDR)
  128. {
  129. return true;
  130. }
  131. else
  132. {
  133. return false;
  134. }
  135. }
  136. /*********************************************************************************
  137. * Function : HAL_EXTI_ClearPending
  138. * Description : Clear interrupt pending bit of a dedicated line.
  139. * Input :
  140. * Outpu :
  141. * Author : Chris_Kyle Data : 2020年
  142. **********************************************************************************/
  143. void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti)
  144. {
  145. #if (USE_FULL_ASSERT == 1)
  146. if (!IS_EXTI_ALL_LINE(hexti->u32_Line)) return;
  147. #endif
  148. /* Clear pending status */
  149. EXTI->PDR |= hexti->u32_Line;
  150. }
  151. /*********************************************************************************
  152. * Function : HAL_EXTI_ClearAllPending
  153. * Description : Clear all interrupt pending bit.
  154. * Input :
  155. * Outpu :
  156. * Author : xwl Data : 2021年
  157. **********************************************************************************/
  158. void HAL_EXTI_ClearAllPending(void)
  159. {
  160. /* Clear pending status */
  161. EXTI->PDR |= EXTI_LINE_MASK;
  162. }