stm32f10x_exti.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_exti.c
  4. * @author MCD Application Team
  5. * @version V3.3.0
  6. * @date 04/16/2010
  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, STMICROELECTRONICS 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 2010 STMicroelectronics</center></h2>
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x_exti.h"
  22. /** @addtogroup STM32F10x_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 reset values.
  65. * @param None
  66. * @retval None
  67. */
  68. void EXTI_DeInit(void)
  69. {
  70. EXTI->IMR = 0x00000000;
  71. EXTI->EMR = 0x00000000;
  72. EXTI->RTSR = 0x00000000;
  73. EXTI->FTSR = 0x00000000;
  74. EXTI->PR = 0x000FFFFF;
  75. }
  76. /**
  77. * @brief Initializes the EXTI peripheral according to the specified
  78. * parameters in the EXTI_InitStruct.
  79. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
  80. * that contains the configuration information for the EXTI peripheral.
  81. * @retval None
  82. */
  83. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
  84. {
  85. uint32_t tmp = 0;
  86. /* Check the parameters */
  87. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  88. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  89. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  90. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  91. tmp = (uint32_t)EXTI_BASE;
  92. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  93. {
  94. /* Clear EXTI line configuration */
  95. EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  96. EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  97. tmp += EXTI_InitStruct->EXTI_Mode;
  98. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  99. /* Clear Rising Falling edge configuration */
  100. EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  101. EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  102. /* Select the trigger for the selected external interrupts */
  103. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  104. {
  105. /* Rising Falling edge */
  106. EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  107. EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  108. }
  109. else
  110. {
  111. tmp = (uint32_t)EXTI_BASE;
  112. tmp += EXTI_InitStruct->EXTI_Trigger;
  113. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  114. }
  115. }
  116. else
  117. {
  118. tmp += EXTI_InitStruct->EXTI_Mode;
  119. /* Disable the selected external lines */
  120. *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  121. }
  122. }
  123. /**
  124. * @brief Fills each EXTI_InitStruct member with its reset value.
  125. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  126. * be initialized.
  127. * @retval None
  128. */
  129. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
  130. {
  131. EXTI_InitStruct->EXTI_Line = EXTI_LineNone;
  132. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  133. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  134. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  135. }
  136. /**
  137. * @brief Generates a Software interrupt.
  138. * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled.
  139. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  140. * @retval None
  141. */
  142. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  143. {
  144. /* Check the parameters */
  145. assert_param(IS_EXTI_LINE(EXTI_Line));
  146. EXTI->SWIER |= EXTI_Line;
  147. }
  148. /**
  149. * @brief Checks whether the specified EXTI line flag is set or not.
  150. * @param EXTI_Line: specifies the EXTI line flag to check.
  151. * This parameter can be:
  152. * @arg EXTI_Linex: External interrupt line x where x(0..19)
  153. * @retval The new state of EXTI_Line (SET or RESET).
  154. */
  155. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
  156. {
  157. FlagStatus bitstatus = RESET;
  158. /* Check the parameters */
  159. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  160. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  161. {
  162. bitstatus = SET;
  163. }
  164. else
  165. {
  166. bitstatus = RESET;
  167. }
  168. return bitstatus;
  169. }
  170. /**
  171. * @brief Clears the EXTI’s line pending flags.
  172. * @param EXTI_Line: specifies the EXTI lines flags to clear.
  173. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  174. * @retval None
  175. */
  176. void EXTI_ClearFlag(uint32_t EXTI_Line)
  177. {
  178. /* Check the parameters */
  179. assert_param(IS_EXTI_LINE(EXTI_Line));
  180. EXTI->PR = EXTI_Line;
  181. }
  182. /**
  183. * @brief Checks whether the specified EXTI line is asserted or not.
  184. * @param EXTI_Line: specifies the EXTI line to check.
  185. * This parameter can be:
  186. * @arg EXTI_Linex: External interrupt line x where x(0..19)
  187. * @retval The new state of EXTI_Line (SET or RESET).
  188. */
  189. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  190. {
  191. ITStatus bitstatus = RESET;
  192. uint32_t enablestatus = 0;
  193. /* Check the parameters */
  194. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  195. enablestatus = EXTI->IMR & EXTI_Line;
  196. if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
  197. {
  198. bitstatus = SET;
  199. }
  200. else
  201. {
  202. bitstatus = RESET;
  203. }
  204. return bitstatus;
  205. }
  206. /**
  207. * @brief Clears the EXTI’s line pending bits.
  208. * @param EXTI_Line: specifies the EXTI lines to clear.
  209. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  210. * @retval None
  211. */
  212. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
  213. {
  214. /* Check the parameters */
  215. assert_param(IS_EXTI_LINE(EXTI_Line));
  216. EXTI->PR = EXTI_Line;
  217. }
  218. /**
  219. * @}
  220. */
  221. /**
  222. * @}
  223. */
  224. /**
  225. * @}
  226. */
  227. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/