stm32f10x_exti.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_exti.c
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file provides all the EXTI firmware functions.
  8. ******************************************************************************
  9. * @attention
  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 2011 STMicroelectronics</center></h2>
  19. ******************************************************************************
  20. */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f10x_exti.h"
  23. /** @addtogroup STM32F10x_StdPeriph_Driver
  24. * @{
  25. */
  26. /** @defgroup EXTI
  27. * @brief EXTI driver modules
  28. * @{
  29. */
  30. /** @defgroup EXTI_Private_TypesDefinitions
  31. * @{
  32. */
  33. /**
  34. * @}
  35. */
  36. /** @defgroup EXTI_Private_Defines
  37. * @{
  38. */
  39. #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
  40. /**
  41. * @}
  42. */
  43. /** @defgroup EXTI_Private_Macros
  44. * @{
  45. */
  46. /**
  47. * @}
  48. */
  49. /** @defgroup EXTI_Private_Variables
  50. * @{
  51. */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup EXTI_Private_FunctionPrototypes
  56. * @{
  57. */
  58. /**
  59. * @}
  60. */
  61. /** @defgroup EXTI_Private_Functions
  62. * @{
  63. */
  64. /**
  65. * @brief Deinitializes the EXTI peripheral registers to their default 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 = 0x000FFFFF;
  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 peripheral.
  82. * @retval None
  83. */
  84. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
  85. {
  86. uint32_t tmp = 0;
  87. /* Check the parameters */
  88. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  89. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  90. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  91. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  92. tmp = (uint32_t)EXTI_BASE;
  93. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  94. {
  95. /* Clear EXTI line configuration */
  96. EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  97. EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  98. tmp += EXTI_InitStruct->EXTI_Mode;
  99. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  100. /* Clear Rising Falling edge configuration */
  101. EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  102. EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  103. /* Select the trigger for the selected external interrupts */
  104. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  105. {
  106. /* Rising Falling edge */
  107. EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  108. EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  109. }
  110. else
  111. {
  112. tmp = (uint32_t)EXTI_BASE;
  113. tmp += EXTI_InitStruct->EXTI_Trigger;
  114. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  115. }
  116. }
  117. else
  118. {
  119. tmp += EXTI_InitStruct->EXTI_Mode;
  120. /* Disable the selected external lines */
  121. *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  122. }
  123. }
  124. /**
  125. * @brief Fills each EXTI_InitStruct member with its reset value.
  126. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  127. * be initialized.
  128. * @retval None
  129. */
  130. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
  131. {
  132. EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
  133. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  134. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  135. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  136. }
  137. /**
  138. * @brief Generates a Software interrupt.
  139. * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled.
  140. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  141. * @retval None
  142. */
  143. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  144. {
  145. /* Check the parameters */
  146. assert_param(IS_EXTI_LINE(EXTI_Line));
  147. EXTI->SWIER |= EXTI_Line;
  148. }
  149. /**
  150. * @brief Checks whether the specified EXTI line flag is set or not.
  151. * @param EXTI_Line: specifies the EXTI line flag to check.
  152. * This parameter can be:
  153. * @arg EXTI_Linex: External interrupt line x where x(0..19)
  154. * @retval The new state of EXTI_Line (SET or RESET).
  155. */
  156. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
  157. {
  158. FlagStatus bitstatus = RESET;
  159. /* Check the parameters */
  160. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  161. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  162. {
  163. bitstatus = SET;
  164. }
  165. else
  166. {
  167. bitstatus = RESET;
  168. }
  169. return bitstatus;
  170. }
  171. /**
  172. * @brief Clears the EXTI's line pending flags.
  173. * @param EXTI_Line: specifies the EXTI lines flags to clear.
  174. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  175. * @retval None
  176. */
  177. void EXTI_ClearFlag(uint32_t EXTI_Line)
  178. {
  179. /* Check the parameters */
  180. assert_param(IS_EXTI_LINE(EXTI_Line));
  181. EXTI->PR = EXTI_Line;
  182. }
  183. /**
  184. * @brief Checks whether the specified EXTI line is asserted or not.
  185. * @param EXTI_Line: specifies the EXTI line to check.
  186. * This parameter can be:
  187. * @arg EXTI_Linex: External interrupt line x where x(0..19)
  188. * @retval The new state of EXTI_Line (SET or RESET).
  189. */
  190. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  191. {
  192. ITStatus bitstatus = RESET;
  193. uint32_t enablestatus = 0;
  194. /* Check the parameters */
  195. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  196. enablestatus = EXTI->IMR & EXTI_Line;
  197. if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
  198. {
  199. bitstatus = SET;
  200. }
  201. else
  202. {
  203. bitstatus = RESET;
  204. }
  205. return bitstatus;
  206. }
  207. /**
  208. * @brief Clears the EXTI's line pending bits.
  209. * @param EXTI_Line: specifies the EXTI lines to clear.
  210. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  211. * @retval None
  212. */
  213. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
  214. {
  215. /* Check the parameters */
  216. assert_param(IS_EXTI_LINE(EXTI_Line));
  217. EXTI->PR = EXTI_Line;
  218. }
  219. /**
  220. * @}
  221. */
  222. /**
  223. * @}
  224. */
  225. /**
  226. * @}
  227. */
  228. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/