1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_exti.c
4 * @author MCD Application Team
5 * @brief EXTI LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2016 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 "stm32f3xx_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 STM32F3xx_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 #if defined(EXTI_32_63_SUPPORT)
48 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U)
49 #endif
50
51 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \
52 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \
53 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
54
55
56 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \
57 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \
58 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \
59 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
60
61 /**
62 * @}
63 */
64
65 /* Private function prototypes -----------------------------------------------*/
66
67 /* Exported functions --------------------------------------------------------*/
68 /** @addtogroup EXTI_LL_Exported_Functions
69 * @{
70 */
71
72 /** @addtogroup EXTI_LL_EF_Init
73 * @{
74 */
75
76 /**
77 * @brief De-initialize the EXTI registers to their default reset values.
78 * @retval An ErrorStatus enumeration value:
79 * - SUCCESS: EXTI registers are de-initialized
80 * - ERROR: not applicable
81 */
LL_EXTI_DeInit(void)82 uint32_t LL_EXTI_DeInit(void)
83 {
84 /* Interrupt mask register set to default reset values */
85 LL_EXTI_WriteReg(IMR, 0x1F800000U);
86 /* Event mask register set to default reset values */
87 LL_EXTI_WriteReg(EMR, 0x00000000U);
88 /* Rising Trigger selection register set to default reset values */
89 LL_EXTI_WriteReg(RTSR, 0x00000000U);
90 /* Falling Trigger selection register set to default reset values */
91 LL_EXTI_WriteReg(FTSR, 0x00000000U);
92 /* Software interrupt event register set to default reset values */
93 LL_EXTI_WriteReg(SWIER, 0x00000000U);
94 /* Pending register clear */
95 LL_EXTI_WriteReg(PR, 0x007FFFFFU);
96
97 #if defined(EXTI_32_63_SUPPORT)
98 /* Interrupt mask register 2 set to default reset values */
99 #if defined(STM32F334x8)
100 LL_EXTI_WriteReg(IMR2, 0xFFFFFFFEU);
101 #else
102 LL_EXTI_WriteReg(IMR2, 0xFFFFFFFCU);
103 #endif
104 /* Event mask register 2 set to default reset values */
105 LL_EXTI_WriteReg(EMR2, 0x00000000U);
106 /* Rising Trigger selection register 2 set to default reset values */
107 LL_EXTI_WriteReg(RTSR2, 0x00000000U);
108 /* Falling Trigger selection register 2 set to default reset values */
109 LL_EXTI_WriteReg(FTSR2, 0x00000000U);
110 /* Software interrupt event register 2 set to default reset values */
111 LL_EXTI_WriteReg(SWIER2, 0x00000000U);
112 /* Pending register 2 clear */
113 LL_EXTI_WriteReg(PR2, 0x00000003U);
114
115 #endif
116 return SUCCESS;
117 }
118
119 /**
120 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
121 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
122 * @retval An ErrorStatus enumeration value:
123 * - SUCCESS: EXTI registers are initialized
124 * - ERROR: not applicable
125 */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)126 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
127 {
128 ErrorStatus status = SUCCESS;
129 /* Check the parameters */
130 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
131 #if defined(EXTI_32_63_SUPPORT)
132 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63));
133 #endif
134 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
135 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
136
137 /* ENABLE LineCommand */
138 if (EXTI_InitStruct->LineCommand != DISABLE)
139 {
140 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
141
142 /* Configure EXTI Lines in range from 0 to 31 */
143 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
144 {
145 switch (EXTI_InitStruct->Mode)
146 {
147 case LL_EXTI_MODE_IT:
148 /* First Disable Event on provided Lines */
149 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
150 /* Then Enable IT on provided Lines */
151 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
152 break;
153 case LL_EXTI_MODE_EVENT:
154 /* First Disable IT on provided Lines */
155 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
156 /* Then Enable Event on provided Lines */
157 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
158 break;
159 case LL_EXTI_MODE_IT_EVENT:
160 /* Directly Enable IT & Event on provided Lines */
161 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
162 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
163 break;
164 default:
165 status = ERROR;
166 break;
167 }
168 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
169 {
170 switch (EXTI_InitStruct->Trigger)
171 {
172 case LL_EXTI_TRIGGER_RISING:
173 /* First Disable Falling Trigger on provided Lines */
174 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
175 /* Then Enable Rising Trigger on provided Lines */
176 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
177 break;
178 case LL_EXTI_TRIGGER_FALLING:
179 /* First Disable Rising Trigger on provided Lines */
180 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
181 /* Then Enable Falling Trigger on provided Lines */
182 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
183 break;
184 case LL_EXTI_TRIGGER_RISING_FALLING:
185 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
186 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
187 break;
188 default:
189 status = ERROR;
190 break;
191 }
192 }
193 }
194 #if defined(EXTI_32_63_SUPPORT)
195 /* Configure EXTI Lines in range from 32 to 63 */
196 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE)
197 {
198 switch (EXTI_InitStruct->Mode)
199 {
200 case LL_EXTI_MODE_IT:
201 /* First Disable Event on provided Lines */
202 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
203 /* Then Enable IT on provided Lines */
204 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
205 break;
206 case LL_EXTI_MODE_EVENT:
207 /* First Disable IT on provided Lines */
208 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
209 /* Then Enable Event on provided Lines */
210 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
211 break;
212 case LL_EXTI_MODE_IT_EVENT:
213 /* Directly Enable IT & Event on provided Lines */
214 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63);
215 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63);
216 break;
217 default:
218 status = ERROR;
219 break;
220 }
221 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
222 {
223 switch (EXTI_InitStruct->Trigger)
224 {
225 case LL_EXTI_TRIGGER_RISING:
226 /* First Disable Falling Trigger on provided Lines */
227 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
228 /* Then Enable IT on provided Lines */
229 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
230 break;
231 case LL_EXTI_TRIGGER_FALLING:
232 /* First Disable Rising Trigger on provided Lines */
233 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
234 /* Then Enable Falling Trigger on provided Lines */
235 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
236 break;
237 case LL_EXTI_TRIGGER_RISING_FALLING:
238 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63);
239 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63);
240 break;
241 default:
242 status = ERROR;
243 break;
244 }
245 }
246 }
247 #endif
248 }
249 /* DISABLE LineCommand */
250 else
251 {
252 /* De-configure EXTI Lines in range from 0 to 31 */
253 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
254 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
255 #if defined(EXTI_32_63_SUPPORT)
256 /* De-configure EXTI Lines in range from 32 to 63 */
257 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63);
258 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63);
259 #endif
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 #if defined(EXTI_32_63_SUPPORT)
273 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE;
274 #endif
275 EXTI_InitStruct->LineCommand = DISABLE;
276 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT;
277 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING;
278 }
279
280 /**
281 * @}
282 */
283
284 /**
285 * @}
286 */
287
288 /**
289 * @}
290 */
291
292 #endif /* defined (EXTI) */
293
294 /**
295 * @}
296 */
297
298 #endif /* USE_FULL_LL_DRIVER */
299
300