stm32g0xx_ll_exti.c 11 KB

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