stm32f3xx_ll_exti.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_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 "stm32f3xx_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 STM32F3xx_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. #if defined(EXTI_32_63_SUPPORT)
  42. #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
  43. #endif
  44. #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
  45. || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
  46. || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
  47. #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
  48. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
  49. || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
  50. || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
  51. /**
  52. * @}
  53. */
  54. /* Private function prototypes -----------------------------------------------*/
  55. /* Exported functions --------------------------------------------------------*/
  56. /** @addtogroup EXTI_LL_Exported_Functions
  57. * @{
  58. */
  59. /** @addtogroup EXTI_LL_EF_Init
  60. * @{
  61. */
  62. /**
  63. * @brief De-initialize the EXTI registers to their default reset values.
  64. * @retval An ErrorStatus enumeration value:
  65. * - SUCCESS: EXTI registers are de-initialized
  66. * - ERROR: not applicable
  67. */
  68. uint32_t LL_EXTI_DeInit(void)
  69. {
  70. /* Interrupt mask register set to default reset values */
  71. LL_EXTI_WriteReg(IMR, 0x1F800000U);
  72. /* Event mask register set to default reset values */
  73. LL_EXTI_WriteReg(EMR, 0x00000000U);
  74. /* Rising Trigger selection register set to default reset values */
  75. LL_EXTI_WriteReg(RTSR, 0x00000000U);
  76. /* Falling Trigger selection register set to default reset values */
  77. LL_EXTI_WriteReg(FTSR, 0x00000000U);
  78. /* Software interrupt event register set to default reset values */
  79. LL_EXTI_WriteReg(SWIER, 0x00000000U);
  80. /* Pending register clear */
  81. LL_EXTI_WriteReg(PR, 0x007FFFFFU);
  82. #if defined(EXTI_32_63_SUPPORT)
  83. /* Interrupt mask register 2 set to default reset values */
  84. #if defined(STM32F334x8)
  85. LL_EXTI_WriteReg(IMR2, 0xFFFFFFFEU);
  86. #else
  87. LL_EXTI_WriteReg(IMR2, 0xFFFFFFFCU);
  88. #endif
  89. /* Event mask register 2 set to default reset values */
  90. LL_EXTI_WriteReg(EMR2, 0x00000000U);
  91. /* Rising Trigger selection register 2 set to default reset values */
  92. LL_EXTI_WriteReg(RTSR2, 0x00000000U);
  93. /* Falling Trigger selection register 2 set to default reset values */
  94. LL_EXTI_WriteReg(FTSR2, 0x00000000U);
  95. /* Software interrupt event register 2 set to default reset values */
  96. LL_EXTI_WriteReg(SWIER2, 0x00000000U);
  97. /* Pending register 2 clear */
  98. LL_EXTI_WriteReg(PR2, 0x00000003U);
  99. #endif
  100. return SUCCESS;
  101. }
  102. /**
  103. * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
  104. * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
  105. * @retval An ErrorStatus enumeration value:
  106. * - SUCCESS: EXTI registers are initialized
  107. * - ERROR: not applicable
  108. */
  109. uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  110. {
  111. ErrorStatus status = SUCCESS;
  112. /* Check the parameters */
  113. assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
  114. #if defined(EXTI_32_63_SUPPORT)
  115. assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
  116. #endif
  117. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
  118. assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
  119. /* ENABLE LineCommand */
  120. if (EXTI_InitStruct->LineCommand != DISABLE)
  121. {
  122. assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
  123. /* Configure EXTI Lines in range from 0 to 31 */
  124. if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
  125. {
  126. switch (EXTI_InitStruct->Mode)
  127. {
  128. case LL_EXTI_MODE_IT:
  129. /* First Disable Event on provided Lines */
  130. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  131. /* Then Enable IT on provided Lines */
  132. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  133. break;
  134. case LL_EXTI_MODE_EVENT:
  135. /* First Disable IT on provided Lines */
  136. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  137. /* Then Enable Event on provided Lines */
  138. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  139. break;
  140. case LL_EXTI_MODE_IT_EVENT:
  141. /* Directly Enable IT & Event on provided Lines */
  142. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  143. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  144. break;
  145. default:
  146. status = ERROR;
  147. break;
  148. }
  149. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  150. {
  151. switch (EXTI_InitStruct->Trigger)
  152. {
  153. case LL_EXTI_TRIGGER_RISING:
  154. /* First Disable Falling Trigger on provided Lines */
  155. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  156. /* Then Enable Rising Trigger on provided Lines */
  157. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  158. break;
  159. case LL_EXTI_TRIGGER_FALLING:
  160. /* First Disable Rising Trigger on provided Lines */
  161. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  162. /* Then Enable Falling Trigger on provided Lines */
  163. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  164. break;
  165. case LL_EXTI_TRIGGER_RISING_FALLING:
  166. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  167. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  168. break;
  169. default:
  170. status = ERROR;
  171. break;
  172. }
  173. }
  174. }
  175. #if defined(EXTI_32_63_SUPPORT)
  176. /* Configure EXTI Lines in range from 32 to 63 */
  177. if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
  178. {
  179. switch (EXTI_InitStruct->Mode)
  180. {
  181. case LL_EXTI_MODE_IT:
  182. /* First Disable Event on provided Lines */
  183. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  184. /* Then Enable IT on provided Lines */
  185. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  186. break;
  187. case LL_EXTI_MODE_EVENT:
  188. /* First Disable IT on provided Lines */
  189. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  190. /* Then Enable Event on provided Lines */
  191. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  192. break;
  193. case LL_EXTI_MODE_IT_EVENT:
  194. /* Directly Enable IT & Event on provided Lines */
  195. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  196. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  197. break;
  198. default:
  199. status = ERROR;
  200. break;
  201. }
  202. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  203. {
  204. switch (EXTI_InitStruct->Trigger)
  205. {
  206. case LL_EXTI_TRIGGER_RISING:
  207. /* First Disable Falling Trigger on provided Lines */
  208. LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  209. /* Then Enable IT on provided Lines */
  210. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  211. break;
  212. case LL_EXTI_TRIGGER_FALLING:
  213. /* First Disable Rising Trigger on provided Lines */
  214. LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  215. /* Then Enable Falling Trigger on provided Lines */
  216. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  217. break;
  218. case LL_EXTI_TRIGGER_RISING_FALLING:
  219. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  220. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  221. break;
  222. default:
  223. status = ERROR;
  224. break;
  225. }
  226. }
  227. }
  228. #endif
  229. }
  230. /* DISABLE LineCommand */
  231. else
  232. {
  233. /* De-configure EXTI Lines in range from 0 to 31 */
  234. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  235. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  236. #if defined(EXTI_32_63_SUPPORT)
  237. /* De-configure EXTI Lines in range from 32 to 63 */
  238. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  239. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  240. #endif
  241. }
  242. return status;
  243. }
  244. /**
  245. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  246. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  247. * @retval None
  248. */
  249. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  250. {
  251. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  252. #if defined(EXTI_32_63_SUPPORT)
  253. EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
  254. #endif
  255. EXTI_InitStruct->LineCommand = DISABLE;
  256. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  257. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  258. }
  259. /**
  260. * @}
  261. */
  262. /**
  263. * @}
  264. */
  265. /**
  266. * @}
  267. */
  268. #endif /* defined (EXTI) */
  269. /**
  270. * @}
  271. */
  272. #endif /* USE_FULL_LL_DRIVER */