1 /**
2 ******************************************************************************
3 * @file stm32h5xx_ll_exti.c
4 * @author MCD Application Team
5 * @brief EXTI LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2022 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 "stm32h5xx_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 STM32H5xx_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 /* Interrupt mask register set to default reset values */
83 LL_EXTI_WriteReg(IMR1, 0xFFFE0000U);
84 #if (defined(STM32H573xx) || defined(STM32H563xx) || defined(STM32H562xx))
85 LL_EXTI_WriteReg(IMR2, 0x03DBBFFFU);
86 #else
87 LL_EXTI_WriteReg(IMR2, 0x001BFFFFU);
88 #endif /* defined(STM32H573xx) || defined(STM32H563xx) || defined(STM32H562xx) */
89
90 /* Event mask register set to default reset values */
91 LL_EXTI_WriteReg(EMR1, 0x00000000U);
92 LL_EXTI_WriteReg(EMR2, 0x00000000U);
93
94 /* Rising Trigger selection register set to default reset values */
95 LL_EXTI_WriteReg(RTSR1, 0x00000000U);
96 LL_EXTI_WriteReg(RTSR2, 0x00000000U);
97
98 /* Falling Trigger selection register set to default reset values */
99 LL_EXTI_WriteReg(FTSR1, 0x00000000U);
100 LL_EXTI_WriteReg(FTSR2, 0x00000000U);
101
102 /* Software interrupt event register set to default reset values */
103 LL_EXTI_WriteReg(SWIER1, 0x00000000U);
104 LL_EXTI_WriteReg(SWIER2, 0x00000000U);
105
106 /* Pending register set to default reset values */
107 LL_EXTI_WriteReg(RPR1, 0xFFFFFFFFU);
108 LL_EXTI_WriteReg(FPR1, 0xFFFFFFFFU);
109 LL_EXTI_WriteReg(RPR2, 0xFFFFFFFFU);
110 LL_EXTI_WriteReg(FPR2, 0xFFFFFFFFU);
111
112 /* Privilege register set to default reset values */
113 LL_EXTI_WriteReg(PRIVCFGR1, 0x00000000U);
114 LL_EXTI_WriteReg(PRIVCFGR2, 0x00000000U);
115 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
116 /* Secure register set to default reset values */
117 LL_EXTI_WriteReg(SECCFGR1, 0x00000000U);
118 LL_EXTI_WriteReg(SECCFGR2, 0x00000000U);
119 #endif /* __ARM_FEATURE_CMSE */
120 return SUCCESS;
121 }
122
123 /**
124 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
125 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
126 * @retval An ErrorStatus enumeration value:
127 * - SUCCESS: EXTI registers are initialized
128 * - ERROR: not applicable
129 */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)130 ErrorStatus LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
131 {
132 ErrorStatus status = SUCCESS;
133 /* Check the parameters */
134 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
135 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
136 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
137 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
138
139 /* ENABLE LineCommand */
140 if (EXTI_InitStruct->LineCommand != DISABLE)
141 {
142 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
143
144 /* Configure EXTI Lines in range from 0 to 31 */
145 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
146 {
147 switch (EXTI_InitStruct->Mode)
148 {
149 case LL_EXTI_MODE_IT:
150 /* First Disable Event on provided Lines */
151 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
152 /* Then Enable IT on provided Lines */
153 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
154 break;
155 case LL_EXTI_MODE_EVENT:
156 /* First Disable IT on provided Lines */
157 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
158 /* Then Enable Event on provided Lines */
159 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
160 break;
161 case LL_EXTI_MODE_IT_EVENT:
162 /* Directly Enable IT & Event on provided Lines */
163 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
164 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
165 break;
166 default:
167 status = ERROR;
168 break;
169 }
170 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
171 {
172 switch (EXTI_InitStruct->Trigger)
173 {
174 case LL_EXTI_TRIGGER_RISING:
175 /* First Disable Falling Trigger on provided Lines */
176 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
177 /* Then Enable Rising Trigger on provided Lines */
178 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
179 break;
180 case LL_EXTI_TRIGGER_FALLING:
181 /* First Disable Rising Trigger on provided Lines */
182 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
183 /* Then Enable Falling Trigger on provided Lines */
184 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
185 break;
186 case LL_EXTI_TRIGGER_RISING_FALLING:
187 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
188 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
189 break;
190 default:
191 status = ERROR;
192 break;
193 }
194 }
195 }
196
197 /* Configure EXTI Lines in range from 32 to 63 */
198 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
199 {
200 switch (EXTI_InitStruct->Mode)
201 {
202 case LL_EXTI_MODE_IT:
203 /* First Disable Event on provided Lines */
204 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
205 /* Then Enable IT on provided Lines */
206 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
207 break;
208 case LL_EXTI_MODE_EVENT:
209 /* First Disable IT on provided Lines */
210 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
211 /* Then Enable Event on provided Lines */
212 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
213 break;
214 case LL_EXTI_MODE_IT_EVENT:
215 /* Directly Enable IT & Event on provided Lines */
216 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
217 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
218 break;
219 default:
220 status = ERROR;
221 break;
222 }
223 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
224 {
225 switch (EXTI_InitStruct->Trigger)
226 {
227 case LL_EXTI_TRIGGER_RISING:
228 /* First Disable Falling Trigger on provided Lines */
229 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
230 /* Then Enable Rising Trigger on provided Lines */
231 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
232 break;
233 case LL_EXTI_TRIGGER_FALLING:
234 /* First Disable Rising Trigger on provided Lines */
235 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
236 /* Then Enable Falling Trigger on provided Lines */
237 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
238 break;
239 case LL_EXTI_TRIGGER_RISING_FALLING:
240 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
241 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
242 break;
243 default:
244 status = ERROR;
245 break;
246 }
247 }
248 }
249 }
250 /* DISABLE LineCommand */
251 else
252 {
253 /* De-configure EXTI Lines in range from 0 to 31 */
254 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
255 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
256
257 /* De-configure EXTI Lines in range from 32 to 63 */
258 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
259 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
260 }
261 return status;
262 }
263
264 /**
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
268 */
LL_EXTI_StructInit(LL_EXTI_InitTypeDef * EXTI_InitStruct)269 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
270 {
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;
276 }
277
278 /**
279 * @}
280 */
281
282 /**
283 * @}
284 */
285
286 /**
287 * @}
288 */
289
290 #endif /* defined (EXTI) */
291
292 /**
293 * @}
294 */
295
296 #endif /* USE_FULL_LL_DRIVER */
297