You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32l1xx_ll_exti.c 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_ll_exti.c
  4. * @author MCD Application Team
  5. * @brief EXTI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2017 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 "stm32l1xx_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 STM32L1xx_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. LL_EXTI_WriteReg(IMR, 0x00000000U);
  70. /* Event mask register set to default reset values */
  71. LL_EXTI_WriteReg(EMR, 0x00000000U);
  72. /* Rising Trigger selection register set to default reset values */
  73. LL_EXTI_WriteReg(RTSR, 0x00000000U);
  74. /* Falling Trigger selection register set to default reset values */
  75. LL_EXTI_WriteReg(FTSR, 0x00000000U);
  76. /* Software interrupt event register set to default reset values */
  77. LL_EXTI_WriteReg(SWIER, 0x00000000U);
  78. /* Pending register clear */
  79. LL_EXTI_WriteReg(PR, 0x00FFFFFFU);
  80. return SUCCESS;
  81. }
  82. /**
  83. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  84. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  85. * @retval An ErrorStatus enumeration value:
  86. * - SUCCESS: EXTI registers are initialized
  87. * - ERROR: not applicable
  88. */
  89. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  90. {
  91. ErrorStatus status = SUCCESS;
  92. /* Check the parameters */
  93. assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  94. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  95. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  96. /* ENABLE LineCommand */
  97. if (EXTI_InitStruct->LineCommand != DISABLE)
  98. {
  99. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  100. /* Configure EXTI Lines in range from 0 to 31 */
  101. if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  102. {
  103. switch (EXTI_InitStruct->Mode)
  104. {
  105. case LL_EXTI_MODE_IT:
  106. /* First Disable Event on provided Lines */
  107. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  108. /* Then Enable IT on provided Lines */
  109. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  110. break;
  111. case LL_EXTI_MODE_EVENT:
  112. /* First Disable IT on provided Lines */
  113. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  114. /* Then Enable Event on provided Lines */
  115. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  116. break;
  117. case LL_EXTI_MODE_IT_EVENT:
  118. /* Directly Enable IT & Event on provided Lines */
  119. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  120. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  121. break;
  122. default:
  123. status = ERROR;
  124. break;
  125. }
  126. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  127. {
  128. switch (EXTI_InitStruct->Trigger)
  129. {
  130. case LL_EXTI_TRIGGER_RISING:
  131. /* First Disable Falling Trigger on provided Lines */
  132. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  133. /* Then Enable Rising Trigger on provided Lines */
  134. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  135. break;
  136. case LL_EXTI_TRIGGER_FALLING:
  137. /* First Disable Rising Trigger on provided Lines */
  138. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  139. /* Then Enable Falling Trigger on provided Lines */
  140. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  141. break;
  142. case LL_EXTI_TRIGGER_RISING_FALLING:
  143. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  144. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  145. break;
  146. default:
  147. status = ERROR;
  148. break;
  149. }
  150. }
  151. }
  152. }
  153. /* DISABLE LineCommand */
  154. else
  155. {
  156. /* De-configure EXTI Lines in range from 0 to 31 */
  157. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  158. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  159. }
  160. return status;
  161. }
  162. /**
  163. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  164. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  165. * @retval None
  166. */
  167. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  168. {
  169. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  170. EXTI_InitStruct->LineCommand = DISABLE;
  171. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  172. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  173. }
  174. /**
  175. * @}
  176. */
  177. /**
  178. * @}
  179. */
  180. /**
  181. * @}
  182. */
  183. #endif /* defined (EXTI) */
  184. /**
  185. * @}
  186. */
  187. #endif /* USE_FULL_LL_DRIVER */
  188. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/