HAL_exti.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /**
  2. ******************************************************************************
  3. * @file HAL_exti.c
  4. * @author IC Applications Department
  5. * @version V0.8
  6. * @date 2019_08_02
  7. * @brief This file provides all the EXTI firmware functions.
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, HOLOCENE SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2016 HOLOCENE</center></h2>
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "HAL_exti.h"
  22. /** @addtogroup StdPeriph_Driver
  23. * @{
  24. */
  25. /** @defgroup EXTI
  26. * @brief EXTI driver modules
  27. * @{
  28. */
  29. /** @defgroup EXTI_Private_TypesDefinitions
  30. * @{
  31. */
  32. /**
  33. * @}
  34. */
  35. /** @defgroup EXTI_Private_Defines
  36. * @{
  37. */
  38. #define EXTI_LineNone ((uint32_t)0x00000) /* No interrupt selected */
  39. /**
  40. * @}
  41. */
  42. /** @defgroup EXTI_Private_Macros
  43. * @{
  44. */
  45. /**
  46. * @}
  47. */
  48. /** @defgroup EXTI_Private_Variables
  49. * @{
  50. */
  51. /**
  52. * @}
  53. */
  54. /** @defgroup EXTI_Private_FunctionPrototypes
  55. * @{
  56. */
  57. /**
  58. * @}
  59. */
  60. /** @defgroup EXTI_Private_Functions
  61. * @{
  62. */
  63. /**
  64. * @brief Deinitializes the EXTI peripheral registers to their default
  65. * reset values.
  66. * @param None
  67. * @retval : None
  68. */
  69. void EXTI_DeInit(void)
  70. {
  71. EXTI->IMR = 0x00000000;
  72. EXTI->EMR = 0x00000000;
  73. EXTI->RTSR = 0x00000000;
  74. EXTI->FTSR = 0x00000000;
  75. EXTI->PR = 0x001FFFFF;
  76. }
  77. /**
  78. * @brief Initializes the EXTI peripheral according to the specified
  79. * parameters in the EXTI_InitStruct.
  80. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
  81. * that contains the configuration information for the EXTI
  82. * peripheral.
  83. * @retval : None
  84. */
  85. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
  86. {
  87. uint32_t tmp = 0;
  88. /* Check the parameters */
  89. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  90. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  91. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  92. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  93. tmp = (uint32_t)EXTI_BASE;
  94. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  95. {
  96. /* Clear EXTI line configuration */
  97. EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  98. EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  99. tmp += EXTI_InitStruct->EXTI_Mode;
  100. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  101. /* Clear Rising Falling edge configuration */
  102. EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  103. EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  104. /* Select the trigger for the selected external interrupts */
  105. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  106. {
  107. /* Rising Falling edge */
  108. EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  109. EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  110. }
  111. else
  112. {
  113. tmp = (uint32_t)EXTI_BASE;
  114. tmp += EXTI_InitStruct->EXTI_Trigger;
  115. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  116. }
  117. }
  118. else
  119. {
  120. tmp = (uint32_t)EXTI_BASE;
  121. tmp += EXTI_InitStruct->EXTI_Mode;
  122. /* Disable the selected external lines */
  123. *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  124. }
  125. }
  126. /**
  127. * @brief Fills each EXTI_InitStruct member with its reset value.
  128. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
  129. * which will be initialized.
  130. * @retval : None
  131. */
  132. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
  133. {
  134. EXTI_InitStruct->EXTI_Line = EXTI_LineNone;
  135. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  136. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  137. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  138. }
  139. /**
  140. * @brief Generates a Software interrupt.
  141. * @param EXTI_Line: specifies the EXTI lines to be enabled or
  142. * disabled.
  143. * This parameter can be any combination of EXTI_Linex where
  144. * x can be (0..18).
  145. * @retval : None
  146. */
  147. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  148. {
  149. /* Check the parameters */
  150. assert_param(IS_EXTI_LINE(EXTI_Line));
  151. EXTI->SWIER |= EXTI_Line;
  152. }
  153. /**
  154. * @brief Checks whether the specified EXTI line flag is set or not.
  155. * @param EXTI_Line: specifies the EXTI line flag to check.
  156. * This parameter can be:
  157. * @arg EXTI_Linex: External interrupt line x where x(0..18)
  158. * @retval : The new state of EXTI_Line (SET or RESET).
  159. */
  160. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
  161. {
  162. FlagStatus bitstatus = RESET;
  163. /* Check the parameters */
  164. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  165. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  166. {
  167. bitstatus = SET;
  168. }
  169. else
  170. {
  171. bitstatus = RESET;
  172. }
  173. return bitstatus;
  174. }
  175. /**
  176. * @brief Clears the EXTI’s line pending flags.
  177. * @param EXTI_Line: specifies the EXTI lines flags to clear.
  178. * This parameter can be any combination of EXTI_Linex where
  179. * x can be (0..18).
  180. * @retval : None
  181. */
  182. void EXTI_ClearFlag(uint32_t EXTI_Line)
  183. {
  184. /* Check the parameters */
  185. assert_param(IS_EXTI_LINE(EXTI_Line));
  186. EXTI->PR = EXTI_Line;
  187. }
  188. /**
  189. * @brief Checks whether the specified EXTI line is asserted or not.
  190. * @param EXTI_Line: specifies the EXTI line to check.
  191. * This parameter can be:
  192. * @arg EXTI_Linex: External interrupt line x where x(0..18)
  193. * @retval : The new state of EXTI_Line (SET or RESET).
  194. */
  195. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  196. {
  197. ITStatus bitstatus = RESET;
  198. uint32_t enablestatus = 0;
  199. /* Check the parameters */
  200. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  201. enablestatus = EXTI->IMR & EXTI_Line;
  202. if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
  203. {
  204. bitstatus = SET;
  205. }
  206. else
  207. {
  208. bitstatus = RESET;
  209. }
  210. return bitstatus;
  211. }
  212. /**
  213. * @brief Clears the EXTI’s line pending bits.
  214. * @param EXTI_Line: specifies the EXTI lines to clear.
  215. * This parameter can be any combination of EXTI_Linex where
  216. * x can be (0..18).
  217. * @retval : None
  218. */
  219. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
  220. {
  221. /* Check the parameters */
  222. assert_param(IS_EXTI_LINE(EXTI_Line));
  223. EXTI->PR = EXTI_Line;
  224. }
  225. /**
  226. * @}
  227. */
  228. /**
  229. * @}
  230. */
  231. /**
  232. * @}
  233. */
  234. /*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/