stm32l4xx_ll_exti.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_ll_exti.c
  4. * @author MCD Application Team
  5. * @brief EXTI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2017 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 "stm32l4xx_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 STM32L4xx_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_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 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. * - 0x00: EXTI registers are de-initialized
  64. */
  65. uint32_t LL_EXTI_DeInit(void)
  66. {
  67. /* Interrupt mask register set to default reset values */
  68. LL_EXTI_WriteReg(IMR1, 0xFF820000U);
  69. /* Event mask register set to default reset values */
  70. LL_EXTI_WriteReg(EMR1, 0x00000000U);
  71. /* Rising Trigger selection register set to default reset values */
  72. LL_EXTI_WriteReg(RTSR1, 0x00000000U);
  73. /* Falling Trigger selection register set to default reset values */
  74. LL_EXTI_WriteReg(FTSR1, 0x00000000U);
  75. /* Software interrupt event register set to default reset values */
  76. LL_EXTI_WriteReg(SWIER1, 0x00000000U);
  77. /* Pending register clear */
  78. LL_EXTI_WriteReg(PR1, 0x007DFFFFU);
  79. /* Interrupt mask register 2 set to default reset values */
  80. #if defined(LL_EXTI_LINE_40)
  81. LL_EXTI_WriteReg(IMR2, 0x00000187U);
  82. #else
  83. LL_EXTI_WriteReg(IMR2, 0x00000087U);
  84. #endif
  85. /* Event mask register 2 set to default reset values */
  86. LL_EXTI_WriteReg(EMR2, 0x00000000U);
  87. /* Rising Trigger selection register 2 set to default reset values */
  88. LL_EXTI_WriteReg(RTSR2, 0x00000000U);
  89. /* Falling Trigger selection register 2 set to default reset values */
  90. LL_EXTI_WriteReg(FTSR2, 0x00000000U);
  91. /* Software interrupt event register 2 set to default reset values */
  92. LL_EXTI_WriteReg(SWIER2, 0x00000000U);
  93. /* Pending register 2 clear */
  94. LL_EXTI_WriteReg(PR2, 0x00000078U);
  95. return 0x00u;
  96. }
  97. /**
  98. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  99. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  100. * @retval An ErrorStatus enumeration value:
  101. * - 0x00: EXTI registers are initialized
  102. * - any other value : wrong configuration
  103. */
  104. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  105. {
  106. uint32_t status = 0x00u;
  107. /* Check the parameters */
  108. assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  109. assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
  110. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  111. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  112. /* ENABLE LineCommand */
  113. if (EXTI_InitStruct->LineCommand != DISABLE)
  114. {
  115. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  116. /* Configure EXTI Lines in range from 0 to 31 */
  117. if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  118. {
  119. switch (EXTI_InitStruct->Mode)
  120. {
  121. case LL_EXTI_MODE_IT:
  122. /* First Disable Event on provided Lines */
  123. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  124. /* Then Enable IT on provided Lines */
  125. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  126. break;
  127. case LL_EXTI_MODE_EVENT:
  128. /* First Disable IT on provided Lines */
  129. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  130. /* Then Enable Event on provided Lines */
  131. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  132. break;
  133. case LL_EXTI_MODE_IT_EVENT:
  134. /* Directly Enable IT & Event on provided Lines */
  135. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  136. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  137. break;
  138. default:
  139. status = 0x01u;
  140. break;
  141. }
  142. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  143. {
  144. switch (EXTI_InitStruct->Trigger)
  145. {
  146. case LL_EXTI_TRIGGER_RISING:
  147. /* First Disable Falling Trigger on provided Lines */
  148. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  149. /* Then Enable Rising Trigger on provided Lines */
  150. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  151. break;
  152. case LL_EXTI_TRIGGER_FALLING:
  153. /* First Disable Rising Trigger on provided Lines */
  154. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  155. /* Then Enable Falling Trigger on provided Lines */
  156. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  157. break;
  158. case LL_EXTI_TRIGGER_RISING_FALLING:
  159. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  160. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  161. break;
  162. default:
  163. status |= 0x02u;
  164. break;
  165. }
  166. }
  167. }
  168. /* Configure EXTI Lines in range from 32 to 63 */
  169. if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
  170. {
  171. switch (EXTI_InitStruct->Mode)
  172. {
  173. case LL_EXTI_MODE_IT:
  174. /* First Disable Event on provided Lines */
  175. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  176. /* Then Enable IT on provided Lines */
  177. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  178. break;
  179. case LL_EXTI_MODE_EVENT:
  180. /* First Disable IT on provided Lines */
  181. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  182. /* Then Enable Event on provided Lines */
  183. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  184. break;
  185. case LL_EXTI_MODE_IT_EVENT:
  186. /* Directly Enable IT & Event on provided Lines */
  187. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  188. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  189. break;
  190. default:
  191. status |= 0x04u;
  192. break;
  193. }
  194. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  195. {
  196. switch (EXTI_InitStruct->Trigger)
  197. {
  198. case LL_EXTI_TRIGGER_RISING:
  199. /* First Disable Falling Trigger on provided Lines */
  200. LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  201. /* Then Enable IT on provided Lines */
  202. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  203. break;
  204. case LL_EXTI_TRIGGER_FALLING:
  205. /* First Disable Rising Trigger on provided Lines */
  206. LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  207. /* Then Enable Falling Trigger on provided Lines */
  208. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  209. break;
  210. case LL_EXTI_TRIGGER_RISING_FALLING:
  211. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  212. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  213. break;
  214. default:
  215. status = ERROR;
  216. break;
  217. }
  218. }
  219. }
  220. }
  221. /* DISABLE LineCommand */
  222. else
  223. {
  224. /* De-configure EXTI Lines in range from 0 to 31 */
  225. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  226. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  227. /* De-configure EXTI Lines in range from 32 to 63 */
  228. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  229. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  230. }
  231. return status;
  232. }
  233. /**
  234. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  235. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  236. * @retval None
  237. */
  238. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  239. {
  240. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  241. EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
  242. EXTI_InitStruct->LineCommand = DISABLE;
  243. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  244. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  245. }
  246. /**
  247. * @}
  248. */
  249. /**
  250. * @}
  251. */
  252. /**
  253. * @}
  254. */
  255. #endif /* defined (EXTI) */
  256. /**
  257. * @}
  258. */
  259. #endif /* USE_FULL_LL_DRIVER */