1 /**
2 ******************************************************************************
3 * @file stm32h7rsxx_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 "stm32h7rsxx_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 STM32H7RSxx_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 #define IS_LL_EXTI_LINE_64_95(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_64_95) == 0x00000000U)
49
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))
53
54
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))
59
60 /**
61 * @}
62 */
63
64 /* Private function prototypes -----------------------------------------------*/
65
66 /* Exported functions --------------------------------------------------------*/
67 /** @addtogroup EXTI_LL_Exported_Functions
68 * @{
69 */
70
71 /** @addtogroup EXTI_LL_EF_Init
72 * @{
73 */
74
75 /**
76 * @brief De-initialize the EXTI registers to their default reset values.
77 * @retval An ErrorStatus enumeration value:
78 * - SUCCESS: EXTI registers are de-initialized
79 * - ERROR: not applicable
80 */
LL_EXTI_DeInit(void)81 ErrorStatus LL_EXTI_DeInit(void)
82 {
83 /* Interrupt mask register set to default reset values */
84 LL_EXTI_WriteReg(IMR1, 0xFFC00000U);
85 /* Event mask register set to default reset values */
86 LL_EXTI_WriteReg(EMR1, 0x00000000U);
87 /* Rising Trigger selection register set to default reset values */
88 LL_EXTI_WriteReg(RTSR1, 0x00000000U);
89 /* Falling Trigger selection register set to default reset values */
90 LL_EXTI_WriteReg(FTSR1, 0x00000000U);
91 /* Pending register clear */
92 LL_EXTI_WriteReg(PR1, 0x003FFFFFU);
93
94 /* Interrupt mask register 2 set to default reset values */
95 LL_EXTI_WriteReg(IMR2, 0xFFB5BFFBU);
96 /* Event mask register 2 set to default reset values */
97 LL_EXTI_WriteReg(EMR2, 0x00000000U);
98 /* Rising Trigger selection register 2 set to default reset values */
99 LL_EXTI_WriteReg(RTSR2, 0x00000000U);
100 /* Falling Trigger selection register 2 set to default reset values */
101 LL_EXTI_WriteReg(FTSR2, 0x00000000U);
102 /* Pending register 2 clear */
103 LL_EXTI_WriteReg(PR2, 0x004A4004U);
104
105 /* Interrupt mask register 3 set to default reset values */
106 LL_EXTI_WriteReg(IMR3, 0x00003FFFU);
107 /* Event mask register 3 set to default reset values */
108 LL_EXTI_WriteReg(EMR3, 0x00000000U);
109
110 return SUCCESS;
111 }
112
113 /**
114 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
115 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
116 * @retval An ErrorStatus enumeration value:
117 * - SUCCESS: EXTI registers are initialized
118 * - ERROR: not applicable
119 */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)120 ErrorStatus LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
121 {
122 ErrorStatus status = SUCCESS;
123 /* Check the parameters */
124 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
125 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
126 assert_param(IS_LL_EXTI_LINE_64_95(EXTI_InitStruct->Line_64_95));
127 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
128 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
129
130 /* ENABLE LineCommand */
131 if (EXTI_InitStruct->LineCommand != DISABLE)
132 {
133 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
134
135 /* Configure EXTI Lines in range from 0 to 31 */
136 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
137 {
138 switch (EXTI_InitStruct->Mode)
139 {
140 case LL_EXTI_MODE_IT:
141 /* First Disable Event on provided Lines */
142 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
143 /* Then Enable IT on provided Lines */
144 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
145 break;
146 case LL_EXTI_MODE_EVENT:
147 /* First Disable IT on provided Lines */
148 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
149 /* Then Enable Event on provided Lines */
150 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
151 break;
152 case LL_EXTI_MODE_IT_EVENT:
153 /* Directly Enable IT & Event on provided Lines */
154 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
155 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
156 break;
157 default:
158 status = ERROR;
159 break;
160 }
161 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
162 {
163 switch (EXTI_InitStruct->Trigger)
164 {
165 case LL_EXTI_TRIGGER_RISING:
166 /* First Disable Falling Trigger on provided Lines */
167 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
168 /* Then Enable Rising Trigger on provided Lines */
169 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
170 break;
171 case LL_EXTI_TRIGGER_FALLING:
172 /* First Disable Rising Trigger on provided Lines */
173 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
174 /* Then Enable Falling Trigger on provided Lines */
175 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
176 break;
177 case LL_EXTI_TRIGGER_RISING_FALLING:
178 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
179 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
180 break;
181 default:
182 status = ERROR;
183 break;
184 }
185 }
186 }
187 /* Configure EXTI Lines in range from 32 to 63 */
188 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
189 {
190 switch (EXTI_InitStruct->Mode)
191 {
192 case LL_EXTI_MODE_IT:
193 /* First Disable Event on provided Lines */
194 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
195 /* Then Enable IT on provided Lines */
196 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
197 break;
198 case LL_EXTI_MODE_EVENT:
199 /* First Disable IT on provided Lines */
200 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
201 /* Then Enable Event on provided Lines */
202 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
203 break;
204 case LL_EXTI_MODE_IT_EVENT:
205 /* Directly Enable IT & Event on provided Lines */
206 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
207 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
208 break;
209 default:
210 status = ERROR;
211 break;
212 }
213 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
214 {
215 switch (EXTI_InitStruct->Trigger)
216 {
217 case LL_EXTI_TRIGGER_RISING:
218 /* First Disable Falling Trigger on provided Lines */
219 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
220 /* Then Enable IT on provided Lines */
221 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
222 break;
223 case LL_EXTI_TRIGGER_FALLING:
224 /* First Disable Rising Trigger on provided Lines */
225 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
226 /* Then Enable Falling Trigger on provided Lines */
227 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
228 break;
229 case LL_EXTI_TRIGGER_RISING_FALLING:
230 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
231 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
232 break;
233 default:
234 status = ERROR;
235 break;
236 }
237 }
238 }
239 /* Configure EXTI Lines in range from 64 to 95 */
240 if (EXTI_InitStruct->Line_64_95 != LL_EXTI_LINE_NONE)
241 {
242 switch (EXTI_InitStruct->Mode)
243 {
244 case LL_EXTI_MODE_IT:
245 /* First Disable Event on provided Lines */
246 LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
247 /* Then Enable IT on provided Lines */
248 LL_EXTI_EnableIT_64_95(EXTI_InitStruct->Line_64_95);
249 break;
250 case LL_EXTI_MODE_EVENT:
251 /* First Disable IT on provided Lines */
252 LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
253 /* Then Enable Event on provided Lines */
254 LL_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
255 break;
256 case LL_EXTI_MODE_IT_EVENT:
257 /* Directly Enable IT & Event on provided Lines */
258 LL_EXTI_EnableIT_64_95(EXTI_InitStruct->Line_64_95);
259 LL_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
260 break;
261 default:
262 status = ERROR;
263 break;
264 }
265 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
266 {
267 status = ERROR;
268 }
269 }
270 }
271 /* DISABLE LineCommand */
272 else
273 {
274 /* De-configure EXTI Lines in range from 0 to 31 */
275 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
276 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
277 /* De-configure EXTI Lines in range from 32 to 63 */
278 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
279 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
280 /* De-configure EXTI Lines in range from 64 to 95 */
281 LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
282 LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
283 }
284 return status;
285 }
286
287 /**
288 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
289 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
290 * @retval None
291 */
LL_EXTI_StructInit(LL_EXTI_InitTypeDef * EXTI_InitStruct)292 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
293 {
294 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
295 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
296 EXTI_InitStruct->Line_64_95 = LL_EXTI_LINE_NONE;
297 EXTI_InitStruct->LineCommand = DISABLE;
298 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
299 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
300 }
301
302 /**
303 * @}
304 */
305
306 /**
307 * @}
308 */
309
310 /**
311 * @}
312 */
313
314 #endif /* defined (EXTI) */
315
316 /**
317 * @}
318 */
319
320 #endif /* USE_FULL_LL_DRIVER */
321