Merge maintenance-8.x.x fixes into master
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_ll_exti.c
blob1ce50a24f5e9eb45a4a1243a7b61351b0aff5e40
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_ll_exti.c
4 * @author MCD Application Team
5 * @brief EXTI LL module driver.
6 ******************************************************************************
7 * @attention
9 * Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.
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.
16 ******************************************************************************
18 #if defined(USE_FULL_LL_DRIVER)
20 /* Includes ------------------------------------------------------------------*/
21 #include "stm32h7xx_ll_exti.h"
22 #ifdef USE_FULL_ASSERT
23 #include "stm32_assert.h"
24 #else
25 #ifndef assert_param
26 #define assert_param(expr) ((void)0U)
27 #endif
28 #endif
30 /** @addtogroup STM32H7xx_LL_Driver
31 * @{
34 #if defined (EXTI)
36 /** @defgroup EXTI_LL EXTI
37 * @{
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44 /** @addtogroup EXTI_LL_Private_Macros
45 * @{
48 #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
49 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
50 #define IS_LL_EXTI_LINE_64_95(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_64_95) == 0x00000000U)
52 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
53 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
54 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
57 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
58 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
59 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
60 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
62 /**
63 * @}
66 /* Private function prototypes -----------------------------------------------*/
68 /* Exported functions --------------------------------------------------------*/
69 /** @addtogroup EXTI_LL_Exported_Functions
70 * @{
73 /** @addtogroup EXTI_LL_EF_Init
74 * @{
77 /**
78 * @brief De-initialize the EXTI registers to their default reset values.
79 * @retval An ErrorStatus enumeration value:
80 * - SUCCESS: EXTI registers are de-initialized
81 * - ERROR: not applicable
83 ErrorStatus LL_EXTI_DeInit(void)
85 /* Rising Trigger selection register set to default reset values */
86 LL_EXTI_WriteReg(RTSR1, 0x00000000U);
87 LL_EXTI_WriteReg(RTSR2, 0x00000000U);
88 LL_EXTI_WriteReg(RTSR3, 0x00000000U);
90 /* Falling Trigger selection register set to default reset values */
91 LL_EXTI_WriteReg(FTSR1, 0x00000000U);
92 LL_EXTI_WriteReg(FTSR2, 0x00000000U);
93 LL_EXTI_WriteReg(FTSR3, 0x00000000U);
95 /* Software interrupt event register set to default reset values */
96 LL_EXTI_WriteReg(SWIER1, 0x00000000U);
97 LL_EXTI_WriteReg(SWIER2, 0x00000000U);
98 LL_EXTI_WriteReg(SWIER3, 0x00000000U);
100 /* D3 Pending register set to default reset values */
101 LL_EXTI_WriteReg(D3PMR1, 0x00000000U);
102 LL_EXTI_WriteReg(D3PMR2, 0x00000000U);
103 LL_EXTI_WriteReg(D3PMR3, 0x00000000U);
105 /* D3 Pending clear selection register low to default reset values */
106 LL_EXTI_WriteReg(D3PCR1L, 0x00000000U);
107 LL_EXTI_WriteReg(D3PCR2L, 0x00000000U);
108 LL_EXTI_WriteReg(D3PCR3L, 0x00000000U);
110 /* D3 Pending clear selection register high to default reset values */
111 LL_EXTI_WriteReg(D3PCR1H, 0x00000000U);
112 LL_EXTI_WriteReg(D3PCR2H, 0x00000000U);
113 LL_EXTI_WriteReg(D3PCR3H, 0x00000000U);
115 /* Interrupt mask register reset */
116 LL_EXTI_WriteReg(IMR1, 0x00000000U);
117 LL_EXTI_WriteReg(IMR2, 0x00000000U);
118 LL_EXTI_WriteReg(IMR3, 0x00000000U);
120 /* Event mask register reset */
121 LL_EXTI_WriteReg(EMR1, 0x00000000U);
122 LL_EXTI_WriteReg(EMR2, 0x00000000U);
123 LL_EXTI_WriteReg(EMR3, 0x00000000U);
125 /* Clear Pending requests */
126 LL_EXTI_WriteReg(PR1, EXTI_PR1_PR_Msk);
127 LL_EXTI_WriteReg(PR2, EXTI_PR2_PR_Msk);
128 LL_EXTI_WriteReg(PR3, EXTI_PR3_PR_Msk);
130 #if defined(DUAL_CORE)
131 /* Interrupt mask register set to default reset values for Core 2 (Coretx-M4)*/
132 LL_EXTI_WriteReg(C2IMR1, 0x00000000U);
133 LL_EXTI_WriteReg(C2IMR2, 0x00000000U);
134 LL_EXTI_WriteReg(C2IMR3, 0x00000000U);
136 /* Event mask register set to default reset values */
137 LL_EXTI_WriteReg(C2EMR1, 0x00000000U);
138 LL_EXTI_WriteReg(C2EMR2, 0x00000000U);
139 LL_EXTI_WriteReg(C2EMR3, 0x00000000U);
141 /* Clear Pending requests */
142 LL_EXTI_WriteReg(C2PR1, EXTI_PR1_PR_Msk);
143 LL_EXTI_WriteReg(C2PR2, EXTI_PR2_PR_Msk);
144 LL_EXTI_WriteReg(C2PR3, EXTI_PR3_PR_Msk);
146 #endif /* DUAL_CORE*/
147 return SUCCESS;
151 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
152 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
153 * @retval An ErrorStatus enumeration value:
154 * - SUCCESS: EXTI registers are initialized
155 * - ERROR: not applicable
157 ErrorStatus LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
159 ErrorStatus status = SUCCESS;
160 /* Check the parameters */
161 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
162 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
163 assert_param(IS_LL_EXTI_LINE_64_95(EXTI_InitStruct->Line_64_95));
164 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
165 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
167 /* ENABLE LineCommand */
168 if (EXTI_InitStruct->LineCommand != DISABLE)
170 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
172 /* Configure EXTI Lines in range from 0 to 31 */
173 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
175 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_IT) == LL_EXTI_MODE_IT)
177 /* Enable IT on provided Lines for Cortex-M7*/
178 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
180 else
182 /* Disable IT on provided Lines for Cortex-M7*/
183 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
186 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_EVENT) == LL_EXTI_MODE_EVENT)
188 /* Enable event on provided Lines for Cortex-M7 */
189 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
191 else
193 /* Disable event on provided Lines for Cortex-M7 */
194 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
196 #if defined(DUAL_CORE)
197 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_IT) == LL_EXTI_MODE_C2_IT)
199 /* Enable IT on provided Lines for Cortex-M4 */
200 LL_C2_EXTI_EnableIT_0_31 (EXTI_InitStruct->Line_0_31);
202 else
204 /* Disable IT on provided Lines for Cortex-M4*/
205 LL_C2_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
208 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_EVENT) == LL_EXTI_MODE_C2_EVENT)
210 /* Enable event on provided Lines for Cortex-M4 */
211 LL_C2_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
213 else
215 /* Disable event on provided Lines for Cortex-M4*/
216 LL_C2_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
218 #endif /* DUAL_CORE */
220 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
222 switch (EXTI_InitStruct->Trigger)
224 case LL_EXTI_TRIGGER_RISING:
225 /* First Disable Falling Trigger on provided Lines */
226 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
227 /* Then Enable Rising Trigger on provided Lines */
228 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
229 break;
230 case LL_EXTI_TRIGGER_FALLING:
231 /* First Disable Rising Trigger on provided Lines */
232 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
233 /* Then Enable Falling Trigger on provided Lines */
234 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
235 break;
236 case LL_EXTI_TRIGGER_RISING_FALLING:
237 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
238 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
239 break;
240 default:
241 status = ERROR;
242 break;
246 /* Configure EXTI Lines in range from 32 to 63 */
247 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
249 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_IT) == LL_EXTI_MODE_IT)
251 /* Enable IT on provided Lines for Cortex-M7*/
252 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
254 else
256 /* Disable IT on provided Lines for Cortex-M7*/
257 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
260 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_EVENT) == LL_EXTI_MODE_EVENT)
262 /* Enable event on provided Lines for Cortex-M7 */
263 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
265 else
267 /* Disable event on provided Lines for Cortex-M7 */
268 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
270 #if defined(DUAL_CORE)
271 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_IT) == LL_EXTI_MODE_C2_IT)
273 /* Enable IT on provided Lines for Cortex-M4 */
274 LL_C2_EXTI_EnableIT_32_63 (EXTI_InitStruct->Line_32_63);
276 else
278 /* Disable IT on provided Lines for Cortex-M4 */
279 LL_C2_EXTI_DisableIT_32_63 (EXTI_InitStruct->Line_32_63);
282 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_EVENT) == LL_EXTI_MODE_C2_EVENT)
284 /* Enable event on provided Lines for Cortex-M4 */
285 LL_C2_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
287 else
289 /* Disable event on provided Lines for Cortex-M4 */
290 LL_C2_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
292 #endif /* DUAL_CORE */
294 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
296 switch (EXTI_InitStruct->Trigger)
298 case LL_EXTI_TRIGGER_RISING:
299 /* First Disable Falling Trigger on provided Lines */
300 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
301 /* Then Enable IT on provided Lines */
302 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
303 break;
304 case LL_EXTI_TRIGGER_FALLING:
305 /* First Disable Rising Trigger on provided Lines */
306 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
307 /* Then Enable Falling Trigger on provided Lines */
308 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
309 break;
310 case LL_EXTI_TRIGGER_RISING_FALLING:
311 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
312 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
313 break;
314 default:
315 status = ERROR;
316 break;
320 /* Configure EXTI Lines in range from 64 to 95 */
321 if (EXTI_InitStruct->Line_64_95 != LL_EXTI_LINE_NONE)
323 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_IT) == LL_EXTI_MODE_IT)
325 /* Enable IT on provided Lines for Cortex-M7*/
326 LL_EXTI_EnableIT_64_95(EXTI_InitStruct->Line_64_95);
328 else
330 /* Disable IT on provided Lines for Cortex-M7*/
331 LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
334 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_EVENT) == LL_EXTI_MODE_EVENT)
336 /* Enable event on provided Lines for Cortex-M7 */
337 LL_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
339 else
341 /* Disable event on provided Lines for Cortex-M7 */
342 LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
345 #if defined(DUAL_CORE)
346 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_IT) == LL_EXTI_MODE_C2_IT)
348 /* Enable IT on provided Lines for Cortex-M4 */
349 LL_C2_EXTI_EnableIT_64_95 (EXTI_InitStruct->Line_64_95);
351 else
353 /* Disable IT on provided Lines for Cortex-M4 */
354 LL_C2_EXTI_DisableIT_64_95 (EXTI_InitStruct->Line_64_95);
357 if((EXTI_InitStruct->Mode & LL_EXTI_MODE_C2_EVENT) == LL_EXTI_MODE_C2_EVENT)
359 /* Enable event on provided Lines for Cortex-M4 */
360 LL_C2_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
362 else
364 /* Disable event on provided Lines for Cortex-M4 */
365 LL_C2_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
367 #endif /* DUAL_CORE */
369 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
371 switch (EXTI_InitStruct->Trigger)
373 case LL_EXTI_TRIGGER_RISING:
374 /* First Disable Falling Trigger on provided Lines */
375 LL_EXTI_DisableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
376 /* Then Enable IT on provided Lines */
377 LL_EXTI_EnableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
378 break;
379 case LL_EXTI_TRIGGER_FALLING:
380 /* First Disable Rising Trigger on provided Lines */
381 LL_EXTI_DisableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
382 /* Then Enable Falling Trigger on provided Lines */
383 LL_EXTI_EnableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
384 break;
385 case LL_EXTI_TRIGGER_RISING_FALLING:
386 LL_EXTI_EnableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
387 LL_EXTI_EnableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
388 break;
389 default:
390 status = ERROR;
391 break;
396 else /* DISABLE LineCommand */
398 /* Disable IT on provided Lines for Cortex-M7*/
399 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
400 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
401 LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
403 /* Disable event on provided Lines for Cortex-M7 */
404 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
405 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
406 LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
408 #if defined(DUAL_CORE)
409 /* Disable IT on provided Lines for Cortex-M4*/
410 LL_C2_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
411 LL_C2_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
412 LL_C2_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
414 /* Disable event on provided Lines for Cortex-M4 */
415 LL_C2_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
416 LL_C2_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
417 LL_C2_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
418 #endif /* DUAL_CORE */
421 return status;
425 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
426 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
427 * @retval None
429 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
431 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
432 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
433 EXTI_InitStruct->Line_64_95 = LL_EXTI_LINE_NONE;
434 EXTI_InitStruct->LineCommand = DISABLE;
435 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
436 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
440 * @}
444 * @}
448 * @}
451 #endif /* defined (EXTI) */
454 * @}
457 #endif /* USE_FULL_LL_DRIVER */