Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Src / stm32f3xx_ll_exti.c
blobc21ffed0b920ed3b25beb0398522de8590211d36
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_exti.c
4 * @author MCD Application Team
5 * @brief EXTI LL module driver.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************
35 #if defined(USE_FULL_LL_DRIVER)
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f3xx_ll_exti.h"
39 #ifdef USE_FULL_ASSERT
40 #include "stm32_assert.h"
41 #else
42 #define assert_param(expr) ((void)0U)
43 #endif
45 /** @addtogroup STM32F3xx_LL_Driver
46 * @{
49 #if defined (EXTI)
51 /** @defgroup EXTI_LL EXTI
52 * @{
55 /* Private types -------------------------------------------------------------*/
56 /* Private variables ---------------------------------------------------------*/
57 /* Private constants ---------------------------------------------------------*/
58 /* Private macros ------------------------------------------------------------*/
59 /** @addtogroup EXTI_LL_Private_Macros
60 * @{
63 #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
64 #if defined(EXTI_32_63_SUPPORT)
65 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
66 #endif
68 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
69 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
70 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
73 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
74 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
75 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
76 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
78 /**
79 * @}
82 /* Private function prototypes -----------------------------------------------*/
84 /* Exported functions --------------------------------------------------------*/
85 /** @addtogroup EXTI_LL_Exported_Functions
86 * @{
89 /** @addtogroup EXTI_LL_EF_Init
90 * @{
93 /**
94 * @brief De-initialize the EXTI registers to their default reset values.
95 * @retval An ErrorStatus enumeration value:
96 * - SUCCESS: EXTI registers are de-initialized
97 * - ERROR: not applicable
99 uint32_t LL_EXTI_DeInit(void)
101 /* Interrupt mask register set to default reset values */
102 LL_EXTI_WriteReg(IMR, 0x1F800000U);
103 /* Event mask register set to default reset values */
104 LL_EXTI_WriteReg(EMR, 0x00000000U);
105 /* Rising Trigger selection register set to default reset values */
106 LL_EXTI_WriteReg(RTSR, 0x00000000U);
107 /* Falling Trigger selection register set to default reset values */
108 LL_EXTI_WriteReg(FTSR, 0x00000000U);
109 /* Software interrupt event register set to default reset values */
110 LL_EXTI_WriteReg(SWIER, 0x00000000U);
111 /* Pending register clear */
112 LL_EXTI_WriteReg(PR, 0x007FFFFFU);
114 #if defined(EXTI_32_63_SUPPORT)
115 /* Interrupt mask register 2 set to default reset values */
116 #if defined(STM32F334x8)
117 LL_EXTI_WriteReg(IMR2, 0xFFFFFFFEU);
118 #else
119 LL_EXTI_WriteReg(IMR2, 0xFFFFFFFCU);
120 #endif
121 /* Event mask register 2 set to default reset values */
122 LL_EXTI_WriteReg(EMR2, 0x00000000U);
123 /* Rising Trigger selection register 2 set to default reset values */
124 LL_EXTI_WriteReg(RTSR2, 0x00000000U);
125 /* Falling Trigger selection register 2 set to default reset values */
126 LL_EXTI_WriteReg(FTSR2, 0x00000000U);
127 /* Software interrupt event register 2 set to default reset values */
128 LL_EXTI_WriteReg(SWIER2, 0x00000000U);
129 /* Pending register 2 clear */
130 LL_EXTI_WriteReg(PR2, 0x00000003U);
132 #endif
133 return SUCCESS;
137 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
138 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
139 * @retval An ErrorStatus enumeration value:
140 * - SUCCESS: EXTI registers are initialized
141 * - ERROR: not applicable
143 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
145 ErrorStatus status = SUCCESS;
146 /* Check the parameters */
147 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
148 #if defined(EXTI_32_63_SUPPORT)
149 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
150 #endif
151 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
152 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
154 /* ENABLE LineCommand */
155 if (EXTI_InitStruct->LineCommand != DISABLE)
157 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
159 /* Configure EXTI Lines in range from 0 to 31 */
160 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
162 switch (EXTI_InitStruct->Mode)
164 case LL_EXTI_MODE_IT:
165 /* First Disable Event on provided Lines */
166 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
167 /* Then Enable IT on provided Lines */
168 LL_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_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
173 /* Then Enable Event on provided Lines */
174 LL_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_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
179 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
180 break;
181 default:
182 status = ERROR;
183 break;
185 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
187 switch (EXTI_InitStruct->Trigger)
189 case LL_EXTI_TRIGGER_RISING:
190 /* First Disable Falling Trigger on provided Lines */
191 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
192 /* Then Enable Rising Trigger on provided Lines */
193 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
194 break;
195 case LL_EXTI_TRIGGER_FALLING:
196 /* First Disable Rising Trigger on provided Lines */
197 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
198 /* Then Enable Falling Trigger on provided Lines */
199 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
200 break;
201 case LL_EXTI_TRIGGER_RISING_FALLING:
202 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
203 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
204 break;
205 default:
206 status = ERROR;
207 break;
211 #if defined(EXTI_32_63_SUPPORT)
212 /* Configure EXTI Lines in range from 32 to 63 */
213 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
215 switch (EXTI_InitStruct->Mode)
217 case LL_EXTI_MODE_IT:
218 /* First Disable Event on provided Lines */
219 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
220 /* Then Enable IT on provided Lines */
221 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
222 break;
223 case LL_EXTI_MODE_EVENT:
224 /* First Disable IT on provided Lines */
225 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
226 /* Then Enable Event on provided Lines */
227 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
228 break;
229 case LL_EXTI_MODE_IT_EVENT:
230 /* Directly Enable IT & Event on provided Lines */
231 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
232 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
233 break;
234 default:
235 status = ERROR;
236 break;
238 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
240 switch (EXTI_InitStruct->Trigger)
242 case LL_EXTI_TRIGGER_RISING:
243 /* First Disable Falling Trigger on provided Lines */
244 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
245 /* Then Enable IT on provided Lines */
246 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
247 break;
248 case LL_EXTI_TRIGGER_FALLING:
249 /* First Disable Rising Trigger on provided Lines */
250 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
251 /* Then Enable Falling Trigger on provided Lines */
252 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
253 break;
254 case LL_EXTI_TRIGGER_RISING_FALLING:
255 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
256 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
257 break;
258 default:
259 status = ERROR;
260 break;
264 #endif
266 /* DISABLE LineCommand */
267 else
269 /* De-configure EXTI Lines in range from 0 to 31 */
270 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
271 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
272 #if defined(EXTI_32_63_SUPPORT)
273 /* De-configure EXTI Lines in range from 32 to 63 */
274 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
275 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
276 #endif
278 return status;
282 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
283 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
284 * @retval None
286 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
288 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
289 #if defined(EXTI_32_63_SUPPORT)
290 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
291 #endif
292 EXTI_InitStruct->LineCommand = DISABLE;
293 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
294 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
298 * @}
302 * @}
306 * @}
309 #endif /* defined (EXTI) */
312 * @}
315 #endif /* USE_FULL_LL_DRIVER */
317 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/