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