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.
 
 
 

300 lines
10 KiB

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