Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32G4 / Drivers / STM32G4xx_HAL_Driver / Src / stm32g4xx_ll_exti.c
blob69e97bbd0ff750afe3201ee0f9c52eebeda97744
1 /**
2 ******************************************************************************
3 * @file stm32g4xx_ll_exti.c
4 * @author MCD Application Team
5 * @brief EXTI LL module driver.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32g4xx_ll_exti.h"
23 #ifdef USE_FULL_ASSERT
24 #include "stm32_assert.h"
25 #else
26 #define assert_param(expr) ((void)0U)
27 #endif /* USE_FULL_ASSERT */
29 /** @addtogroup STM32G4xx_LL_Driver
30 * @{
33 #if defined (EXTI)
35 /** @defgroup EXTI_LL EXTI
36 * @{
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
43 /** @addtogroup EXTI_LL_Private_Macros
44 * @{
47 #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
48 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
50 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
51 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
52 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
55 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
56 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
57 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
58 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
60 /**
61 * @}
64 /* Private function prototypes -----------------------------------------------*/
66 /* Exported functions --------------------------------------------------------*/
67 /** @addtogroup EXTI_LL_Exported_Functions
68 * @{
71 /** @addtogroup EXTI_LL_EF_Init
72 * @{
75 /**
76 * @brief De-initialize the EXTI registers to their default reset values.
77 * @retval An ErrorStatus enumeration value:
78 * - 0x00: EXTI registers are de-initialized
80 uint32_t LL_EXTI_DeInit(void)
82 /* Interrupt mask register set to default reset values */
83 LL_EXTI_WriteReg(IMR1, 0x1F840000U);
84 /* Event mask register set to default reset values */
85 LL_EXTI_WriteReg(EMR1, 0x00000000U);
86 /* Rising Trigger selection register set to default reset values */
87 LL_EXTI_WriteReg(RTSR1, 0x00000000U);
88 /* Falling Trigger selection register set to default reset values */
89 LL_EXTI_WriteReg(FTSR1, 0x00000000U);
90 /* Software interrupt event register set to default reset values */
91 LL_EXTI_WriteReg(SWIER1, 0x00000000U);
92 /* Pending register clear */
93 LL_EXTI_WriteReg(PR1, 0x007DFFFFU);
95 /* Interrupt mask register 2 set to default reset values */
96 #if defined(LL_EXTI_LINE_32) && defined(LL_EXTI_LINE_33) && defined(LL_EXTI_LINE_35) && defined(LL_EXTI_LINE_42)
97 LL_EXTI_WriteReg(IMR2, 0x0000043CU);
98 #else
99 LL_EXTI_WriteReg(IMR2, 0x00000034U);
100 #endif /* LL_EXTI_LINE_xx */
101 /* Event mask register 2 set to default reset values */
102 LL_EXTI_WriteReg(EMR2, 0x00000000U);
103 /* Rising Trigger selection register 2 set to default reset values */
104 LL_EXTI_WriteReg(RTSR2, 0x00000000U);
105 /* Falling Trigger selection register 2 set to default reset values */
106 LL_EXTI_WriteReg(FTSR2, 0x00000000U);
107 /* Software interrupt event register 2 set to default reset values */
108 LL_EXTI_WriteReg(SWIER2, 0x00000000U);
109 /* Pending register 2 clear */
110 LL_EXTI_WriteReg(PR2, 0x00000078U);
112 return 0x00u;
116 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
117 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
118 * @retval An ErrorStatus enumeration value:
119 * - 0x00: EXTI registers are initialized
120 * - any other calue : wrong configuration
122 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
124 uint32_t status = 0x00u;
126 /* Check the parameters */
127 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
128 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
129 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
130 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
132 /* ENABLE LineCommand */
133 if (EXTI_InitStruct->LineCommand != DISABLE)
135 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
137 /* Configure EXTI Lines in range from 0 to 31 */
138 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
140 switch (EXTI_InitStruct->Mode)
142 case LL_EXTI_MODE_IT:
143 /* First Disable Event on provided Lines */
144 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
145 /* Then Enable IT on provided Lines */
146 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
147 break;
148 case LL_EXTI_MODE_EVENT:
149 /* First Disable IT on provided Lines */
150 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
151 /* Then Enable Event on provided Lines */
152 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
153 break;
154 case LL_EXTI_MODE_IT_EVENT:
155 /* Directly Enable IT on provided Lines */
156 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
157 /* Directly Enable Event on provided Lines */
158 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
159 break;
160 default:
161 status = 0x01u;
162 break;
164 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
166 switch (EXTI_InitStruct->Trigger)
168 case LL_EXTI_TRIGGER_RISING:
169 /* First Disable Falling Trigger on provided Lines */
170 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
171 /* Then Enable Rising Trigger on provided Lines */
172 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
173 break;
174 case LL_EXTI_TRIGGER_FALLING:
175 /* First Disable Rising Trigger on provided Lines */
176 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
177 /* Then Enable Falling Trigger on provided Lines */
178 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
179 break;
180 case LL_EXTI_TRIGGER_RISING_FALLING:
181 /* Enable Rising Trigger on provided Lines */
182 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
183 /* Enable Falling Trigger on provided Lines */
184 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
185 break;
186 default:
187 status |= 0x02u;
188 break;
192 /* Configure EXTI Lines in range from 32 to 63 */
193 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
195 switch (EXTI_InitStruct->Mode)
197 case LL_EXTI_MODE_IT:
198 /* First Disable Event on provided Lines */
199 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
200 /* Then Enable IT on provided Lines */
201 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
202 break;
203 case LL_EXTI_MODE_EVENT:
204 /* First Disable IT on provided Lines */
205 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
206 /* Then Enable Event on provided Lines */
207 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
208 break;
209 case LL_EXTI_MODE_IT_EVENT:
210 /* Directly Enable IT on provided Lines */
211 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
212 /* Directly Enable IT on provided Lines */
213 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
214 break;
215 default:
216 status |= 0x04u;
217 break;
219 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
221 switch (EXTI_InitStruct->Trigger)
223 case LL_EXTI_TRIGGER_RISING:
224 /* First Disable Falling Trigger on provided Lines */
225 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
226 /* Then Enable IT on provided Lines */
227 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
228 break;
229 case LL_EXTI_TRIGGER_FALLING:
230 /* First Disable Rising Trigger on provided Lines */
231 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
232 /* Then Enable Falling Trigger on provided Lines */
233 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
234 break;
235 case LL_EXTI_TRIGGER_RISING_FALLING:
236 /* Enable Rising Trigger on provided Lines */
237 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
238 /* Enable Falling Trigger on provided Lines */
239 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
240 break;
241 default:
242 status |= 0x05u;
243 break;
248 /* DISABLE LineCommand */
249 else
251 /* De-configure IT EXTI Lines in range from 0 to 31 */
252 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
253 /* De-configure Event EXTI Lines in range from 0 to 31 */
254 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
255 /* De-configure IT EXTI Lines in range from 32 to 63 */
256 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
257 /* De-configure Event EXTI Lines in range from 32 to 63 */
258 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
261 return status;
265 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
266 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
267 * @retval None
269 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
271 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
272 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
273 EXTI_InitStruct->LineCommand = DISABLE;
274 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
275 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
279 * @}
283 * @}
287 * @}
290 #endif /* defined (EXTI) */
293 * @}
296 #endif /* USE_FULL_LL_DRIVER */
298 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/