stm32f0xx_ll_exti.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_ll_exti.c
  4. * @author MCD Application Team
  5. * @brief EXTI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f0xx_ll_exti.h"
  22. #ifdef USE_FULL_ASSERT
  23. #include "stm32_assert.h"
  24. #else
  25. #define assert_param(expr) ((void)0U)
  26. #endif
  27. /** @addtogroup STM32F0xx_LL_Driver
  28. * @{
  29. */
  30. #if defined (EXTI)
  31. /** @defgroup EXTI_LL EXTI
  32. * @{
  33. */
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /** @addtogroup EXTI_LL_Private_Macros
  39. * @{
  40. */
  41. #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
  42. #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
  43. || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
  44. || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
  45. #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
  46. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
  47. || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
  48. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
  49. /**
  50. * @}
  51. */
  52. /* Private function prototypes -----------------------------------------------*/
  53. /* Exported functions --------------------------------------------------------*/
  54. /** @addtogroup EXTI_LL_Exported_Functions
  55. * @{
  56. */
  57. /** @addtogroup EXTI_LL_EF_Init
  58. * @{
  59. */
  60. /**
  61. * @brief De-initialize the EXTI registers to their default reset values.
  62. * @retval An ErrorStatus enumeration value:
  63. * - SUCCESS: EXTI registers are de-initialized
  64. * - ERROR: not applicable
  65. */
  66. uint32_t LL_EXTI_DeInit(void)
  67. {
  68. /* Interrupt mask register set to default reset values */
  69. #if defined(STM32F030x6) || defined(STM32F031x6) ||defined(STM32F038xx)
  70. LL_EXTI_WriteReg(IMR, 0x0FF40000U);
  71. #elif defined(STM32F070x6) || defined(STM32F042x6) || defined(STM32F048xx)
  72. LL_EXTI_WriteReg(IMR, 0x7FF40000U);
  73. #elif defined(STM32F030x8) || defined(STM32F051x8) || defined(STM32F058xx)
  74. LL_EXTI_WriteReg(IMR, 0x0F940000U);
  75. #else
  76. LL_EXTI_WriteReg(IMR, 0x7F840000U);
  77. #endif
  78. /* Event mask register set to default reset values */
  79. LL_EXTI_WriteReg(EMR, 0x00000000U);
  80. /* Rising Trigger selection register set to default reset values */
  81. LL_EXTI_WriteReg(RTSR, 0x00000000U);
  82. /* Falling Trigger selection register set to default reset values */
  83. LL_EXTI_WriteReg(FTSR, 0x00000000U);
  84. /* Software interrupt event register set to default reset values */
  85. LL_EXTI_WriteReg(SWIER, 0x00000000U);
  86. /* Pending register clear */
  87. LL_EXTI_WriteReg(PR, 0x007BFFFFU);
  88. return SUCCESS;
  89. }
  90. /**
  91. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  92. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  93. * @retval An ErrorStatus enumeration value:
  94. * - SUCCESS: EXTI registers are initialized
  95. * - ERROR: not applicable
  96. */
  97. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  98. {
  99. ErrorStatus status = SUCCESS;
  100. /* Check the parameters */
  101. assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  102. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  103. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  104. /* ENABLE LineCommand */
  105. if (EXTI_InitStruct->LineCommand != DISABLE)
  106. {
  107. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  108. /* Configure EXTI Lines in range from 0 to 31 */
  109. if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  110. {
  111. switch (EXTI_InitStruct->Mode)
  112. {
  113. case LL_EXTI_MODE_IT:
  114. /* First Disable Event on provided Lines */
  115. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  116. /* Then Enable IT on provided Lines */
  117. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  118. break;
  119. case LL_EXTI_MODE_EVENT:
  120. /* First Disable IT on provided Lines */
  121. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  122. /* Then Enable Event on provided Lines */
  123. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  124. break;
  125. case LL_EXTI_MODE_IT_EVENT:
  126. /* Directly Enable IT & Event on provided Lines */
  127. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  128. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  129. break;
  130. default:
  131. status = ERROR;
  132. break;
  133. }
  134. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  135. {
  136. switch (EXTI_InitStruct->Trigger)
  137. {
  138. case LL_EXTI_TRIGGER_RISING:
  139. /* First Disable Falling Trigger on provided Lines */
  140. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  141. /* Then Enable Rising Trigger on provided Lines */
  142. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  143. break;
  144. case LL_EXTI_TRIGGER_FALLING:
  145. /* First Disable Rising Trigger on provided Lines */
  146. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  147. /* Then Enable Falling Trigger on provided Lines */
  148. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  149. break;
  150. case LL_EXTI_TRIGGER_RISING_FALLING:
  151. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  152. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  153. break;
  154. default:
  155. status = ERROR;
  156. break;
  157. }
  158. }
  159. }
  160. }
  161. /* DISABLE LineCommand */
  162. else
  163. {
  164. /* De-configure EXTI Lines in range from 0 to 31 */
  165. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  166. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  167. }
  168. return status;
  169. }
  170. /**
  171. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  172. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  173. * @retval None
  174. */
  175. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  176. {
  177. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  178. EXTI_InitStruct->LineCommand = DISABLE;
  179. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  180. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  181. }
  182. /**
  183. * @}
  184. */
  185. /**
  186. * @}
  187. */
  188. /**
  189. * @}
  190. */
  191. #endif /* defined (EXTI) */
  192. /**
  193. * @}
  194. */
  195. #endif /* USE_FULL_LL_DRIVER */
  196. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/