STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal_exti.c
Go to the documentation of this file.
1
85/* Includes ------------------------------------------------------------------*/
86#include "stm32f4xx_hal.h"
87
103#ifdef HAL_EXTI_MODULE_ENABLED
104
105/* Private typedef -----------------------------------------------------------*/
106/* Private defines -----------------------------------------------------------*/
115/* Private macros ------------------------------------------------------------*/
116/* Private variables ---------------------------------------------------------*/
117/* Private function prototypes -----------------------------------------------*/
118/* Exported functions --------------------------------------------------------*/
119
143{
144 uint32_t regval;
145 uint32_t linepos;
146 uint32_t maskline;
147
148 /* Check null pointer */
149 if ((hexti == NULL) || (pExtiConfig == NULL))
150 {
151 return HAL_ERROR;
152 }
153
154 /* Check parameters */
155 assert_param(IS_EXTI_LINE(pExtiConfig->Line));
156 assert_param(IS_EXTI_MODE(pExtiConfig->Mode));
157
158 /* Assign line number to handle */
159 hexti->Line = pExtiConfig->Line;
160
161 /* Compute line mask */
162 linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
163 maskline = (1uL << linepos);
164
165 /* Configure triggers for configurable lines */
166 if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
167 {
168 assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));
169
170 /* Configure rising trigger */
171 /* Mask or set line */
172 if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x00u)
173 {
174 EXTI->RTSR |= maskline;
175 }
176 else
177 {
178 EXTI->RTSR &= ~maskline;
179 }
180
181 /* Configure falling trigger */
182 /* Mask or set line */
183 if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x00u)
184 {
185 EXTI->FTSR |= maskline;
186 }
187 else
188 {
189 EXTI->FTSR &= ~maskline;
190 }
191
192
193 /* Configure gpio port selection in case of gpio exti line */
194 if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
195 {
198
199 regval = SYSCFG->EXTICR[linepos >> 2u];
200 regval &= ~(SYSCFG_EXTICR1_EXTI0 << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
201 regval |= (pExtiConfig->GPIOSel << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
202 SYSCFG->EXTICR[linepos >> 2u] = regval;
203 }
204 }
205
206 /* Configure interrupt mode : read current mode */
207 /* Mask or set line */
208 if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x00u)
209 {
210 EXTI->IMR |= maskline;
211 }
212 else
213 {
214 EXTI->IMR &= ~maskline;
215 }
216
217 /* Configure event mode : read current mode */
218 /* Mask or set line */
219 if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0x00u)
220 {
221 EXTI->EMR |= maskline;
222 }
223 else
224 {
225 EXTI->EMR &= ~maskline;
226 }
227
228 return HAL_OK;
229}
230
238{
239 uint32_t regval;
240 uint32_t linepos;
241 uint32_t maskline;
242
243 /* Check null pointer */
244 if ((hexti == NULL) || (pExtiConfig == NULL))
245 {
246 return HAL_ERROR;
247 }
248
249 /* Check the parameter */
251
252 /* Store handle line number to configuration structure */
253 pExtiConfig->Line = hexti->Line;
254
255 /* Compute line mask */
256 linepos = (pExtiConfig->Line & EXTI_PIN_MASK);
257 maskline = (1uL << linepos);
258
259 /* 1] Get core mode : interrupt */
260
261 /* Check if selected line is enable */
262 if ((EXTI->IMR & maskline) != 0x00u)
263 {
264 pExtiConfig->Mode = EXTI_MODE_INTERRUPT;
265 }
266 else
267 {
268 pExtiConfig->Mode = EXTI_MODE_NONE;
269 }
270
271 /* Get event mode */
272 /* Check if selected line is enable */
273 if ((EXTI->EMR & maskline) != 0x00u)
274 {
275 pExtiConfig->Mode |= EXTI_MODE_EVENT;
276 }
277
278 /* Get default Trigger and GPIOSel configuration */
279 pExtiConfig->Trigger = EXTI_TRIGGER_NONE;
280 pExtiConfig->GPIOSel = 0x00u;
281
282 /* 2] Get trigger for configurable lines : rising */
283 if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u)
284 {
285 /* Check if configuration of selected line is enable */
286 if ((EXTI->RTSR & maskline) != 0x00u)
287 {
288 pExtiConfig->Trigger = EXTI_TRIGGER_RISING;
289 }
290
291 /* Get falling configuration */
292 /* Check if configuration of selected line is enable */
293 if ((EXTI->FTSR & maskline) != 0x00u)
294 {
295 pExtiConfig->Trigger |= EXTI_TRIGGER_FALLING;
296 }
297
298 /* Get Gpio port selection for gpio lines */
299 if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO)
300 {
302
303 regval = SYSCFG->EXTICR[linepos >> 2u];
304 pExtiConfig->GPIOSel = (regval >> (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u))) & SYSCFG_EXTICR1_EXTI0;
305 }
306 }
307
308 return HAL_OK;
309}
310
317{
318 uint32_t regval;
319 uint32_t linepos;
320 uint32_t maskline;
321
322 /* Check null pointer */
323 if (hexti == NULL)
324 {
325 return HAL_ERROR;
326 }
327
328 /* Check the parameter */
330
331 /* compute line mask */
332 linepos = (hexti->Line & EXTI_PIN_MASK);
333 maskline = (1uL << linepos);
334
335 /* 1] Clear interrupt mode */
336 EXTI->IMR = (EXTI->IMR & ~maskline);
337
338 /* 2] Clear event mode */
339 EXTI->EMR = (EXTI->EMR & ~maskline);
340
341 /* 3] Clear triggers in case of configurable lines */
342 if ((hexti->Line & EXTI_CONFIG) != 0x00u)
343 {
344 EXTI->RTSR = (EXTI->RTSR & ~maskline);
345 EXTI->FTSR = (EXTI->FTSR & ~maskline);
346
347 /* Get Gpio port selection for gpio lines */
348 if ((hexti->Line & EXTI_GPIO) == EXTI_GPIO)
349 {
351
352 regval = SYSCFG->EXTICR[linepos >> 2u];
353 regval &= ~(SYSCFG_EXTICR1_EXTI0 << (SYSCFG_EXTICR1_EXTI1_Pos * (linepos & 0x03u)));
354 SYSCFG->EXTICR[linepos >> 2u] = regval;
355 }
356 }
357
358 return HAL_OK;
359}
360
370{
371 HAL_StatusTypeDef status = HAL_OK;
372
373 switch (CallbackID)
374 {
376 hexti->PendingCallback = pPendingCbfn;
377 break;
378
379 default:
380 status = HAL_ERROR;
381 break;
382 }
383
384 return status;
385}
386
395{
396 /* Check the parameters */
397 assert_param(IS_EXTI_LINE(ExtiLine));
398
399 /* Check null pointer */
400 if (hexti == NULL)
401 {
402 return HAL_ERROR;
403 }
404 else
405 {
406 /* Store line number as handle private field */
407 hexti->Line = ExtiLine;
408
409 return HAL_OK;
410 }
411}
412
435{
436 uint32_t regval;
437 uint32_t maskline;
438
439 /* Compute line mask */
440 maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
441
442 /* Get pending bit */
443 regval = (EXTI->PR & maskline);
444 if (regval != 0x00u)
445 {
446 /* Clear pending bit */
447 EXTI->PR = maskline;
448
449 /* Call callback */
450 if (hexti->PendingCallback != NULL)
451 {
452 hexti->PendingCallback();
453 }
454 }
455}
456
466uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
467{
468 uint32_t regval;
469 uint32_t linepos;
470 uint32_t maskline;
471
472 /* Prevent unused argument(s) compilation warning */
473 UNUSED(Edge);
474
475 /* Check parameters */
479
480 /* Compute line mask */
481 linepos = (hexti->Line & EXTI_PIN_MASK);
482 maskline = (1uL << linepos);
483
484 /* return 1 if bit is set else 0 */
485 regval = ((EXTI->PR & maskline) >> linepos);
486 return regval;
487}
488
498void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
499{
500 uint32_t maskline;
501
502 /* Prevent unused argument(s) compilation warning */
503 UNUSED(Edge);
504
505 /* Check parameters */
509
510 /* Compute line mask */
511 maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
512
513 /* Clear Pending bit */
514 EXTI->PR = maskline;
515}
516
523{
524 uint32_t maskline;
525
526 /* Check parameters */
529
530 /* Compute line mask */
531 maskline = (1uL << (hexti->Line & EXTI_PIN_MASK));
532
533 /* Generate Software interrupt */
534 EXTI->SWIER = maskline;
535}
536
545#endif /* HAL_EXTI_MODULE_ENABLED */
HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
Set configuration of a dedicated Exti line.
HAL_StatusTypeDef HAL_EXTI_GetHandle(EXTI_HandleTypeDef *hexti, uint32_t ExtiLine)
Store line number as handle private field.
HAL_StatusTypeDef HAL_EXTI_GetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig)
Get configuration of a dedicated Exti line.
HAL_StatusTypeDef HAL_EXTI_RegisterCallback(EXTI_HandleTypeDef *hexti, EXTI_CallbackIDTypeDef CallbackID, void(*pPendingCbfn)(void))
Register callback for a dedicated Exti line.
HAL_StatusTypeDef HAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef *hexti)
Clear whole configuration of a dedicated Exti line.
void HAL_EXTI_IRQHandler(EXTI_HandleTypeDef *hexti)
Handle EXTI interrupt request.
void HAL_EXTI_GenerateSWI(EXTI_HandleTypeDef *hexti)
Generate a software interrupt for a dedicated line.
uint32_t HAL_EXTI_GetPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
Get interrupt pending bit of a dedicated line.
void HAL_EXTI_ClearPending(EXTI_HandleTypeDef *hexti, uint32_t Edge)
Clear interrupt pending bit of a dedicated line.
EXTI_CallbackIDTypeDef
@ HAL_EXTI_COMMON_CB_ID
#define EXTI_MODE_EVENT
#define EXTI_MODE_NONE
#define EXTI_MODE_INTERRUPT
#define EXTI_CONFIG
#define EXTI_PIN_MASK
EXTI bit usage.
#define EXTI_GPIO
#define IS_EXTI_CONFIG_LINE(__EXTI_LINE__)
#define IS_EXTI_GPIO_PIN(__PIN__)
#define IS_EXTI_GPIO_PORT(__PORT__)
#define IS_EXTI_PENDING_EDGE(__EXTI_LINE__)
#define IS_EXTI_MODE(__EXTI_LINE__)
#define IS_EXTI_TRIGGER(__EXTI_LINE__)
#define IS_EXTI_LINE(__EXTI_LINE__)
#define EXTI_TRIGGER_RISING
#define EXTI_TRIGGER_FALLING
#define EXTI_TRIGGER_NONE
#define assert_param(expr)
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition
@ HAL_ERROR
@ HAL_OK
#define UNUSED(X)
EXTI Configuration structure definition.
EXTI Handle structure definition.
void(* PendingCallback)(void)