1 /**
2 ******************************************************************************
3 * @file stm32mp1xx_ll_exti.c
4 * @author MCD Application Team
5 * @brief EXTI LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2019 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 "stm32mp1xx_ll_exti.h"
22 #ifdef USE_FULL_ASSERT
23 #include "stm32_assert.h"
24 #else
25 #define assert_param(expr) ((void)0U)
26 #endif
27
28 /** @addtogroup STM32MP1xx_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 #define EXTI_PR1_Msk 0x0001FFFFU
42 #define EXTI_PR3_Msk 0x00000616U
43
44 /* Private macros ------------------------------------------------------------*/
45 /** @addtogroup EXTI_LL_Private_Macros
46 * @{
47 */
48
49 #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
50 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
51 #define IS_LL_EXTI_LINE_64_95(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_64_95) == 0x00000000U)
52
53 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
54 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
55 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
56
57
58 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
59 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
60 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
61 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
62
63 /**
64 * @}
65 */
66
67 /* Private function prototypes -----------------------------------------------*/
68
69 /* Exported functions --------------------------------------------------------*/
70 /** @addtogroup EXTI_LL_Exported_Functions
71 * @{
72 */
73
74 /** @addtogroup EXTI_LL_EF_Init
75 * @{
76 */
77
78 /**
79 * @brief De-initialize the EXTI registers to their default reset values.
80 * @retval An ErrorStatus enumeration value:
81 * - SUCCESS: EXTI registers are de-initialized
82 * - ERROR: not applicable
83 */
LL_EXTI_DeInit(void)84 ErrorStatus LL_EXTI_DeInit(void)
85 {
86 /* Rising Trigger selection register set to default reset values */
87 LL_EXTI_WriteReg(RTSR1, 0x00000000U);
88
89 /* Falling Trigger selection register set to default reset values */
90 LL_EXTI_WriteReg(FTSR1, 0x00000000U);
91
92 /* Raising Pending Register 1set to default reset values */
93 LL_EXTI_WriteReg(RPR1, EXTI_PR1_Msk);
94
95 /* Raising Pending Register 1set to default reset values */
96 LL_EXTI_WriteReg(FPR1, EXTI_PR1_Msk);
97
98 /* Rising Trigger selection register set to default reset values */
99 LL_EXTI_WriteReg(RTSR3, 0x00000000U);
100
101 /* Falling Trigger selection register set to default reset values */
102 LL_EXTI_WriteReg(FTSR3, 0x00000000U);
103
104 /* Raising Pending Register 3set to default reset values */
105 LL_EXTI_WriteReg(RPR3, EXTI_PR3_Msk);
106
107 /* Raising Pending Register 3set to default reset values */
108 LL_EXTI_WriteReg(FPR3, EXTI_PR3_Msk);
109
110 /* Interrupt mask register set to default reset values */
111 LL_EXTI_WriteReg(C2IMR1, 0xFFFE0000U);
112
113 /* Event mask register set to default reset values */
114 LL_EXTI_WriteReg(C2EMR1, 0x00000000U);
115
116 /* Interrupt mask register 2 set to default reset values */
117 LL_EXTI_WriteReg(C2IMR2, 0xFFFFFFFFU);
118
119 /* Interrupt mask register 3 set to default reset values */
120 LL_EXTI_WriteReg(C2IMR3, 0x00000DE9U);
121
122 /* Event mask register 3 set to default reset values */
123 LL_EXTI_WriteReg(C2EMR3, 0x00000000U);
124
125 return SUCCESS;
126 }
127
128 /**
129 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
130 * @note When trying to apply a Trigger configuration to a Direct line or an
131 * EVENT Mode to a line which does not support this/these
132 * functionality(ies) will not return any error but change will not be
133 * applied by HW. In any case avoid doing this.
134 * Please note that for lines 32 to 63 only LL_EXTI_MODE_IT and
135 * LL_EXTI_TRIGGER_NONE are allowed values, ERROR will be returned if
136 * using other values.
137 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
138 * @retval An ErrorStatus enumeration value:
139 * - SUCCESS: EXTI registers are initialized
140 * - ERROR: EXTI registers are not well initialized
141 */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)142 ErrorStatus LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
143 {
144 ErrorStatus status = SUCCESS;
145 /* Check the parameters */
146 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
147 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
148 assert_param(IS_LL_EXTI_LINE_64_95(EXTI_InitStruct->Line_64_95));
149 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
150 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
151
152 /* ENABLE LineCommand */
153 if (EXTI_InitStruct->LineCommand != DISABLE)
154 {
155 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
156
157 /* Configure EXTI Lines in range from 0 to 31 */
158 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
159 {
160 switch (EXTI_InitStruct->Mode)
161 {
162 case LL_EXTI_MODE_IT:
163 /* First Disable Event on provided Lines */
164 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
165 /* Then Enable IT on provided Lines */
166 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
167 break;
168 case LL_EXTI_MODE_EVENT:
169 /* First Disable IT on provided Lines */
170 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
171 /* Then Enable Event on provided Lines */
172 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
173 break;
174 case LL_EXTI_MODE_IT_EVENT:
175 /* Directly Enable IT & Event on provided Lines */
176 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
177 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
178 break;
179 default:
180 status = ERROR;
181 break;
182 }
183 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
184 {
185 switch (EXTI_InitStruct->Trigger)
186 {
187 case LL_EXTI_TRIGGER_RISING:
188 /* First Disable Falling Trigger on provided Lines */
189 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
190 /* Then Enable Rising Trigger on provided Lines */
191 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
192 break;
193 case LL_EXTI_TRIGGER_FALLING:
194 /* First Disable Rising Trigger on provided Lines */
195 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
196 /* Then Enable Falling Trigger on provided Lines */
197 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
198 break;
199 case LL_EXTI_TRIGGER_RISING_FALLING:
200 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
201 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
202 break;
203 default:
204 status = ERROR;
205 break;
206 }
207 }
208 }
209 /* Configure EXTI Lines in range from 32 to 63 */
210 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
211 {
212 switch (EXTI_InitStruct->Mode)
213 {
214 case LL_EXTI_MODE_IT:
215 /* Then Enable IT on provided Lines */
216 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
217 break;
218 default:
219 status = ERROR;
220 break;
221 }
222 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
223 {
224 status = ERROR;
225 }
226 }
227
228 /* Configure EXTI Lines in range from 64 to 95 */
229 if (EXTI_InitStruct->Line_64_95 != LL_EXTI_LINE_NONE)
230 {
231 switch (EXTI_InitStruct->Mode)
232 {
233 case LL_EXTI_MODE_IT:
234 /* First Disable Event on provided Lines */
235 LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
236 /* Then Enable IT on provided Lines */
237 LL_EXTI_EnableIT_64_95(EXTI_InitStruct->Line_64_95);
238 break;
239 case LL_EXTI_MODE_EVENT:
240 /* First Disable IT on provided Lines */
241 LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
242 /* Then Enable Event on provided Lines */
243 LL_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
244 break;
245 case LL_EXTI_MODE_IT_EVENT:
246 /* Directly Enable IT & Event on provided Lines */
247 LL_EXTI_EnableIT_64_95(EXTI_InitStruct->Line_64_95);
248 LL_EXTI_EnableEvent_64_95(EXTI_InitStruct->Line_64_95);
249 break;
250 default:
251 status = ERROR;
252 break;
253 }
254 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
255 {
256 switch (EXTI_InitStruct->Trigger)
257 {
258 case LL_EXTI_TRIGGER_RISING:
259 /* First Disable Falling Trigger on provided Lines */
260 LL_EXTI_DisableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
261 /* Then Enable Rising Trigger on provided Lines */
262 LL_EXTI_EnableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
263 break;
264 case LL_EXTI_TRIGGER_FALLING:
265 /* First Disable Rising Trigger on provided Lines */
266 LL_EXTI_DisableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
267 /* Then Enable Falling Trigger on provided Lines */
268 LL_EXTI_EnableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
269 break;
270 case LL_EXTI_TRIGGER_RISING_FALLING:
271 LL_EXTI_EnableRisingTrig_64_95(EXTI_InitStruct->Line_64_95);
272 LL_EXTI_EnableFallingTrig_64_95(EXTI_InitStruct->Line_64_95);
273 break;
274 default:
275 status = ERROR;
276 break;
277 }
278 }
279 }
280 }
281 /* DISABLE LineCommand */
282 else
283 {
284 /* De-configure EXTI Lines in range from 0 to 31 */
285 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
286 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
287
288 /* De-configure EXTI Lines in range from 32 to 63 */
289 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
290
291 /* De-configure EXTI Lines in range from 64 to 95 */
292 LL_EXTI_DisableIT_64_95(EXTI_InitStruct->Line_64_95);
293 LL_EXTI_DisableEvent_64_95(EXTI_InitStruct->Line_64_95);
294 }
295 return status;
296 }
297
298 /**
299 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value.
300 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
301 * @retval None
302 */
LL_EXTI_StructInit(LL_EXTI_InitTypeDef * EXTI_InitStruct)303 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
304 {
305 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE;
306 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
307 EXTI_InitStruct->Line_64_95 = LL_EXTI_LINE_NONE;
308 EXTI_InitStruct->LineCommand = DISABLE;
309 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
310 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
311 }
312
313 /**
314 * @}
315 */
316
317 /**
318 * @}
319 */
320
321 /**
322 * @}
323 */
324
325 #endif /* defined (EXTI) */
326
327 /**
328 * @}
329 */
330
331 #endif /* USE_FULL_LL_DRIVER */
332