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