stm32g4xx_ll_exti.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /**
  2. ******************************************************************************
  3. * @file stm32g4xx_ll_exti.c
  4. * @author MCD Application Team
  5. * @brief EXTI LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * Copyright (c) 2019 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 "stm32g4xx_ll_exti.h"
  21. #ifdef USE_FULL_ASSERT
  22. #include "stm32_assert.h"
  23. #else
  24. #define assert_param(expr) ((void)0U)
  25. #endif /* USE_FULL_ASSERT */
  26. /** @addtogroup STM32G4xx_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, 0x1F840000U);
  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_32) && defined(LL_EXTI_LINE_33) && defined(LL_EXTI_LINE_35) && defined(LL_EXTI_LINE_42)
  81. LL_EXTI_WriteReg(IMR2, 0x0000043CU);
  82. #else
  83. LL_EXTI_WriteReg(IMR2, 0x00000034U);
  84. #endif /* LL_EXTI_LINE_xx */
  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 on provided Lines */
  135. LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
  136. /* Directly Enable Event on provided Lines */
  137. LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
  138. break;
  139. default:
  140. status = 0x01u;
  141. break;
  142. }
  143. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  144. {
  145. switch (EXTI_InitStruct->Trigger)
  146. {
  147. case LL_EXTI_TRIGGER_RISING:
  148. /* First Disable Falling Trigger on provided Lines */
  149. LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  150. /* Then Enable Rising Trigger on provided Lines */
  151. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  152. break;
  153. case LL_EXTI_TRIGGER_FALLING:
  154. /* First Disable Rising Trigger on provided Lines */
  155. LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  156. /* Then Enable Falling Trigger on provided Lines */
  157. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  158. break;
  159. case LL_EXTI_TRIGGER_RISING_FALLING:
  160. /* Enable Rising Trigger on provided Lines */
  161. LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
  162. /* Enable Falling Trigger on provided Lines */
  163. LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
  164. break;
  165. default:
  166. status |= 0x02u;
  167. break;
  168. }
  169. }
  170. }
  171. /* Configure EXTI Lines in range from 32 to 63 */
  172. if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
  173. {
  174. switch (EXTI_InitStruct->Mode)
  175. {
  176. case LL_EXTI_MODE_IT:
  177. /* First Disable Event on provided Lines */
  178. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  179. /* Then Enable IT on provided Lines */
  180. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  181. break;
  182. case LL_EXTI_MODE_EVENT:
  183. /* First Disable IT on provided Lines */
  184. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  185. /* Then Enable Event on provided Lines */
  186. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  187. break;
  188. case LL_EXTI_MODE_IT_EVENT:
  189. /* Directly Enable IT on provided Lines */
  190. LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
  191. /* Directly Enable IT on provided Lines */
  192. LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
  193. break;
  194. default:
  195. status |= 0x04u;
  196. break;
  197. }
  198. if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
  199. {
  200. switch (EXTI_InitStruct->Trigger)
  201. {
  202. case LL_EXTI_TRIGGER_RISING:
  203. /* First Disable Falling Trigger on provided Lines */
  204. LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  205. /* Then Enable IT on provided Lines */
  206. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  207. break;
  208. case LL_EXTI_TRIGGER_FALLING:
  209. /* First Disable Rising Trigger on provided Lines */
  210. LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  211. /* Then Enable Falling Trigger on provided Lines */
  212. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  213. break;
  214. case LL_EXTI_TRIGGER_RISING_FALLING:
  215. /* Enable Rising Trigger on provided Lines */
  216. LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
  217. /* Enable Falling Trigger on provided Lines */
  218. LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
  219. break;
  220. default:
  221. status |= 0x05u;
  222. break;
  223. }
  224. }
  225. }
  226. }
  227. /* DISABLE LineCommand */
  228. else
  229. {
  230. /* De-configure IT EXTI Lines in range from 0 to 31 */
  231. LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
  232. /* De-configure Event EXTI Lines in range from 0 to 31 */
  233. LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
  234. /* De-configure IT EXTI Lines in range from 32 to 63 */
  235. LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
  236. /* De-configure Event EXTI Lines in range from 32 to 63 */
  237. LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
  238. }
  239. return status;
  240. }
  241. /**
  242. * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
  243. * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
  244. * @retval None
  245. */
  246. void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
  247. {
  248. EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
  249. EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
  250. EXTI_InitStruct->LineCommand = DISABLE;
  251. EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
  252. EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
  253. }
  254. /**
  255. * @}
  256. */
  257. /**
  258. * @}
  259. */
  260. /**
  261. * @}
  262. */
  263. #endif /* defined (EXTI) */
  264. /**
  265. * @}
  266. */
  267. #endif /* USE_FULL_LL_DRIVER */