1 /**
2 ******************************************************************************
3 * @file stm32wlxx_ll_exti.c
4 * @author MCD Application Team
5 * @brief EXTI LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2020 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
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32wlxx_ll_exti.h"
22 #ifdef USE_FULL_ASSERT
23 #include "stm32_assert.h"
24 #else
25 #define assert_param(expr) ((void)0U)
26 #endif /* USE_FULL_ASSERT */
27
28 /** @addtogroup STM32WLxx_LL_Driver
29 * @{
30 */
31
32 #if defined (EXTI)
33
34 /** @defgroup EXTI_LL EXTI
35 * @{
36 */
37
38 /* Private types -------------------------------------------------------------*/
39 /* Private variables ---------------------------------------------------------*/
40 /* Private constants ---------------------------------------------------------*/
41 /* Private macros ------------------------------------------------------------*/
42 /** @addtogroup EXTI_LL_Private_Macros
43 * @{
44 */
45
46 #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
47 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
48
49 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
50 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
51 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
52
53
54 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
55 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
56 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
57 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
58
59 /**
60 * @}
61 */
62
63 /* Private function prototypes -----------------------------------------------*/
64
65 /* Exported functions --------------------------------------------------------*/
66 /** @addtogroup EXTI_LL_Exported_Functions
67 * @{
68 */
69
70 /** @addtogroup EXTI_LL_EF_Init
71 * @{
72 */
73
74 /**
75 * @brief De-initialize the EXTI registers to their default reset values.
76 * @retval An ErrorStatus enumeration value:
77 * - SUCCESS: EXTI registers are de-initialized
78 * - ERROR: not applicable
79 */
LL_EXTI_DeInit(void)80 ErrorStatus LL_EXTI_DeInit(void)
81 {
82 /* Rising Trigger selection register set to default reset values */
83 LL_EXTI_WriteReg(RTSR1, 0x00000000U);
84
85 /* Falling Trigger selection register set to default reset values */
86 LL_EXTI_WriteReg(FTSR1, 0x00000000U);
87
88 /* Software interrupt event register set to default reset values */
89 LL_EXTI_WriteReg(SWIER1, 0x00000000U);
90
91 /* Pending register set to default reset values */
92 LL_EXTI_WriteReg(PR1, 0xFFFFFFFFU);
93
94 /* Rising Trigger selection register 2 set to default reset values */
95 LL_EXTI_WriteReg(RTSR2, 0x00000000U);
96
97 /* Falling Trigger selection register 2 set to default reset values */
98 LL_EXTI_WriteReg(FTSR2, 0x00000000U);
99
100 /* Software interrupt event register 2 set to default reset values */
101 LL_EXTI_WriteReg(SWIER2, 0x00000000U);
102
103 /* Pending register 2 set to default reset values */
104 LL_EXTI_WriteReg(PR2, 0xFFFFFFFFU);
105
106 /* Interrupt mask register set to default reset values */
107 #if defined(DUAL_CORE) && defined (CORE_CM0PLUS)
108 LL_EXTI_WriteReg(C2IMR1, 0x00000000U);
109 #else
110 LL_EXTI_WriteReg(IMR1, 0x00000000U);
111 #endif /* DUAL_CORE && CORE_CM0PLUS */
112
113 /* Event mask register set to default reset values */
114 #if defined(DUAL_CORE) && defined (CORE_CM0PLUS)
115 LL_EXTI_WriteReg(C2EMR1, 0x00000000U);
116 #else
117 LL_EXTI_WriteReg(EMR1, 0x00000000U);
118 #endif /* DUAL_CORE && CORE_CM0PLUS */
119
120 /* Interrupt mask register 2 set to default reset values */
121 #if defined(DUAL_CORE) && defined (CORE_CM0PLUS)
122 LL_EXTI_WriteReg(C2IMR2, 0x00000000U);
123 #else
124 LL_EXTI_WriteReg(IMR2, 0x00000000U);
125 #endif /* DUAL_CORE && CORE_CM0PLUS */
126
127 /* Event mask register 2 set to default reset values */
128 #if defined(DUAL_CORE) && defined (CORE_CM0PLUS)
129 LL_EXTI_WriteReg(C2EMR2, 0x00000000U);
130 #else
131 LL_EXTI_WriteReg(EMR2, 0x00000000U);
132 #endif /* DUAL_CORE && CORE_CM0PLUS */
133
134 return SUCCESS;
135 }
136
137 /**
138 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
139 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
140 * @retval An ErrorStatus enumeration value:
141 * - SUCCESS: EXTI registers are initialized
142 * - ERROR: not applicable
143 */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)144 ErrorStatus LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
145 {
146 ErrorStatus status = SUCCESS;
147 /* Check the parameters */
148 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
149 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
150 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
151 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
152
153 /* ENABLE LineCommand */
154 if (EXTI_InitStruct->LineCommand != DISABLE)
155 {
156 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
157
158 /* Configure EXTI Lines in range from 0 to 31 */
159 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
160 {
161 switch (EXTI_InitStruct->Mode)
162 {
163 #if defined(DUAL_CORE) && defined (CORE_CM0PLUS)
164 case LL_EXTI_MODE_IT:
165 /* First Disable Event on provided Lines */
166 LL_C2_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
167 /* Then Enable IT on provided Lines */
168 LL_C2_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
169 break;
170 case LL_EXTI_MODE_EVENT:
171 /* First Disable IT on provided Lines */
172 LL_C2_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
173 /* Then Enable Event on provided Lines */
174 LL_C2_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
175 break;
176 case LL_EXTI_MODE_IT_EVENT:
177 /* Directly Enable IT & Event on provided Lines */
178 LL_C2_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
179 LL_C2_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
180 break;
181 default:
182 status = ERROR;
183 break;
184 #else
185 case LL_EXTI_MODE_IT:
186 /* First Disable Event on provided Lines */
187 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
188 /* Then Enable IT on provided Lines */
189 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
190 break;
191 case LL_EXTI_MODE_EVENT:
192 /* First Disable IT on provided Lines */
193 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
194 /* Then Enable Event on provided Lines */
195 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
196 break;
197 case LL_EXTI_MODE_IT_EVENT:
198 /* Directly Enable IT & Event on provided Lines */
199 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
200 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
201 break;
202 default:
203 status = ERROR;
204 break;
205 #endif /* DUAL_CORE && CORE_CM0PLUS */
206 }
207 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
208 {
209 switch (EXTI_InitStruct->Trigger)
210 {
211 case LL_EXTI_TRIGGER_RISING:
212 /* First Disable Falling Trigger on provided Lines */
213 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
214 /* Then Enable Rising Trigger on provided Lines */
215 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
216 break;
217 case LL_EXTI_TRIGGER_FALLING:
218 /* First Disable Rising Trigger on provided Lines */
219 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
220 /* Then Enable Falling Trigger on provided Lines */
221 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
222 break;
223 case LL_EXTI_TRIGGER_RISING_FALLING:
224 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
225 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
226 break;
227 default:
228 status = ERROR;
229 break;
230 }
231 }
232 }
233 /* Configure EXTI Lines in range from 32 to 63 */
234 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
235 {
236 switch (EXTI_InitStruct->Mode)
237 {
238 #if defined(DUAL_CORE) && defined (CORE_CM0PLUS)
239 case LL_EXTI_MODE_IT:
240 /* First Disable Event on provided Lines */
241 LL_C2_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
242 /* Then Enable IT on provided Lines */
243 LL_C2_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
244 break;
245 case LL_EXTI_MODE_EVENT:
246 /* First Disable IT on provided Lines */
247 LL_C2_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
248 /* Then Enable Event on provided Lines */
249 LL_C2_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
250 break;
251 case LL_EXTI_MODE_IT_EVENT:
252 /* Directly Enable IT & Event on provided Lines */
253 LL_C2_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
254 LL_C2_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
255 break;
256 default:
257 status = ERROR;
258 break;
259 #else
260 case LL_EXTI_MODE_IT:
261 /* First Disable Event on provided Lines */
262 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
263 /* Then Enable IT on provided Lines */
264 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
265 break;
266 case LL_EXTI_MODE_EVENT:
267 /* First Disable IT on provided Lines */
268 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
269 /* Then Enable Event on provided Lines */
270 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
271 break;
272 case LL_EXTI_MODE_IT_EVENT:
273 /* Directly Enable IT & Event on provided Lines */
274 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
275 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
276 break;
277 default:
278 status = ERROR;
279 break;
280 #endif /* DUAL_CORE && CORE_CM0PLUS */
281 }
282 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
283 {
284 switch (EXTI_InitStruct->Trigger)
285 {
286 case LL_EXTI_TRIGGER_RISING:
287 /* First Disable Falling Trigger on provided Lines */
288 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
289 /* Then Enable IT on provided Lines */
290 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
291 break;
292 case LL_EXTI_TRIGGER_FALLING:
293 /* First Disable Rising Trigger on provided Lines */
294 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
295 /* Then Enable Falling Trigger on provided Lines */
296 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
297 break;
298 case LL_EXTI_TRIGGER_RISING_FALLING:
299 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
300 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
301 break;
302 default:
303 status = ERROR;
304 break;
305 }
306 }
307 }
308 }
309 /* DISABLE LineCommand */
310 else
311 {
312 #if defined(DUAL_CORE) && defined (CORE_CM0PLUS)
313 /* De-configure EXTI Lines in range from 0 to 31 */
314 LL_C2_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
315 LL_C2_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
316 /* De-configure EXTI Lines in range from 32 to 63 */
317 LL_C2_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
318 LL_C2_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
319 #else
320 /* De-configure EXTI Lines in range from 0 to 31 */
321 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
322 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
323 /* De-configure EXTI Lines in range from 32 to 63 */
324 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
325 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
326 #endif /* DUAL_CORE && CORE_CM0PLUS */
327 }
328 return status;
329 }
330
331 /**
332 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
333 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
334 * @retval None
335 */
LL_EXTI_StructInit(LL_EXTI_InitTypeDef * EXTI_InitStruct)336 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
337 {
338 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
339 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
340 EXTI_InitStruct->LineCommand = DISABLE;
341 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
342 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
343 }
344
345 /**
346 * @}
347 */
348
349 /**
350 * @}
351 */
352
353 /**
354 * @}
355 */
356
357 #endif /* defined (EXTI) */
358
359 /**
360 * @}
361 */
362
363 #endif /* USE_FULL_LL_DRIVER */
364