ft32f0xx_exti.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. ******************************************************************************
  3. * @file ft32f0xx_exti.c
  4. * @author FMD AE
  5. * @brief This file provides firmware functions to manage the following
  6. * functionalities of the EXTI peripheral:
  7. * + Initialization and Configuration
  8. * + Interrupts and flags management
  9. * @version V1.0.0
  10. * @data 2021-07-01
  11. ******************************************************************************
  12. */
  13. /* Includes ------------------------------------------------------------------*/
  14. #include "ft32f0xx_exti.h"
  15. /** @defgroup EXTI
  16. * @brief EXTI driver modules
  17. * @{
  18. */
  19. /* Private typedef -----------------------------------------------------------*/
  20. /* Private define ------------------------------------------------------------*/
  21. #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
  22. /**
  23. * @brief Deinitializes the EXTI peripheral registers to their default reset
  24. * values.
  25. * @param None
  26. * @retval None
  27. */
  28. void EXTI_DeInit(void)
  29. {
  30. EXTI->IMR = 0x0F940000;
  31. EXTI->EMR = 0x00000000;
  32. EXTI->RTSR = 0x00000000;
  33. EXTI->FTSR = 0x00000000;
  34. EXTI->PR = 0x006BFFFF;
  35. }
  36. /**
  37. * @brief Initializes the EXTI peripheral according to the specified
  38. * parameters in the EXTI_InitStruct.
  39. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure that
  40. * contains the configuration information for the EXTI peripheral.
  41. * @retval None
  42. */
  43. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
  44. {
  45. uint32_t tmp = 0;
  46. /* Check the parameters */
  47. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  48. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  49. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  50. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  51. tmp = (uint32_t)EXTI_BASE;
  52. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  53. {
  54. /* Clear EXTI line configuration */
  55. EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  56. EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  57. tmp += EXTI_InitStruct->EXTI_Mode;
  58. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  59. /* Clear Rising Falling edge configuration */
  60. EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  61. EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  62. /* Select the trigger for the selected interrupts */
  63. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  64. {
  65. /* Rising Falling edge */
  66. EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  67. EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  68. }
  69. else
  70. {
  71. tmp = (uint32_t)EXTI_BASE;
  72. tmp += EXTI_InitStruct->EXTI_Trigger;
  73. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  74. }
  75. }
  76. else
  77. {
  78. tmp += EXTI_InitStruct->EXTI_Mode;
  79. /* Disable the selected external lines */
  80. *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  81. }
  82. }
  83. /**
  84. * @brief Fills each EXTI_InitStruct member with its reset value.
  85. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  86. * be initialized.
  87. * @retval None
  88. */
  89. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
  90. {
  91. EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
  92. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  93. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  94. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  95. }
  96. /**
  97. * @brief Generates a Software interrupt on selected EXTI line.
  98. * @param EXTI_Line: specifies the EXTI line on which the software interrupt
  99. * will be generated.
  100. * This parameter can be any combination of EXTI_Linex where x can be (0..27).
  101. * @retval None
  102. */
  103. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  104. {
  105. /* Check the parameters */
  106. assert_param(IS_EXTI_LINE(EXTI_Line));
  107. EXTI->SWIER |= EXTI_Line;
  108. }
  109. /**
  110. * @brief Checks whether the specified EXTI line flag is set or not.
  111. * @param EXTI_Line: specifies the EXTI line flag to check.
  112. * This parameter can be EXTI_Linex where x can be (0..27).
  113. * @retval The new state of EXTI_Line (SET or RESET).
  114. */
  115. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
  116. {
  117. FlagStatus bitstatus = RESET;
  118. /* Check the parameters */
  119. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  120. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  121. {
  122. bitstatus = SET;
  123. }
  124. else
  125. {
  126. bitstatus = RESET;
  127. }
  128. return bitstatus;
  129. }
  130. /**
  131. * @brief Clears the EXTI's line pending flags.
  132. * @param EXTI_Line: specifies the EXTI lines flags to clear.
  133. * This parameter can be any combination of EXTI_Linex where x can be (0..27).
  134. * @retval None
  135. */
  136. void EXTI_ClearFlag(uint32_t EXTI_Line)
  137. {
  138. /* Check the parameters */
  139. assert_param(IS_EXTI_LINE(EXTI_Line));
  140. EXTI->PR = EXTI_Line;
  141. }
  142. /**
  143. * @brief Checks whether the specified EXTI line is asserted or not.
  144. * @param EXTI_Line: specifies the EXTI line to check.
  145. * This parameter can be EXTI_Linex where x can be (0..27).
  146. * @retval The new state of EXTI_Line (SET or RESET).
  147. */
  148. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  149. {
  150. ITStatus bitstatus = RESET;
  151. /* Check the parameters */
  152. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  153. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  154. {
  155. bitstatus = SET;
  156. }
  157. else
  158. {
  159. bitstatus = RESET;
  160. }
  161. return bitstatus;
  162. }
  163. /**
  164. * @brief Clears the EXTI's line pending bits.
  165. * @param EXTI_Line: specifies the EXTI lines to clear.
  166. * This parameter can be any combination of EXTI_Linex where x can be (0..27).
  167. * @retval None
  168. */
  169. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
  170. {
  171. /* Check the parameters */
  172. assert_param(IS_EXTI_LINE(EXTI_Line));
  173. EXTI->PR = EXTI_Line;
  174. }
  175. /**
  176. * @}
  177. */
  178. /**
  179. * @}
  180. */
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @}
  186. */
  187. /************************ (C) COPYRIGHT FMD *****END OF FILE****/