stm32f1xx_ll_exti.c 6.9 KB

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