/** ****************************************************************************** * @file stm32f4xx_hal_exti.c * @author MCD Application Team * @brief EXTI HAL module driver. * This file provides firmware functions to manage the following * functionalities of the Extended Interrupts and events controller (EXTI) peripheral: * + Initialization and de-initialization functions * + IO operation functions * ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim ============================================================================== ##### EXTI Peripheral features ##### ============================================================================== [..] (+) Each Exti line can be configured within this driver. (+) Exti line can be configured in 3 different modes (++) Interrupt (++) Event (++) Both of them (+) Configurable Exti lines can be configured with 3 different triggers (++) Rising (++) Falling (++) Both of them (+) When set in interrupt mode, configurable Exti lines have two different interrupts pending registers which allow to distinguish which transition occurs: (++) Rising edge pending interrupt (++) Falling (+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can be selected through multiplexer. ##### How to use this driver ##### ============================================================================== [..] (#) Configure the EXTI line using HAL_EXTI_SetConfigLine(). (++) Choose the interrupt line number by setting "Line" member from EXTI_ConfigTypeDef structure. (++) Configure the interrupt and/or event mode using "Mode" member from EXTI_ConfigTypeDef structure. (++) For configurable lines, configure rising and/or falling trigger "Trigger" member from EXTI_ConfigTypeDef structure. (++) For Exti lines linked to gpio, choose gpio port using "GPIOSel" member from GPIO_InitTypeDef structure. (#) Get current Exti configuration of a dedicated line using HAL_EXTI_GetConfigLine(). (++) Provide exiting handle as parameter. (++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter. (#) Clear Exti configuration of a dedicated line using HAL_EXTI_ClearConfigLine(). (++) Provide exiting handle as parameter. (#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback(). (++) Provide exiting handle as first parameter. (++) Provide which callback will be registered using one value from EXTI_CallbackIDTypeDef. (++) Provide callback function pointer. (#) Get interrupt pending bit using HAL_EXTI_GetPending(). (#) Clear interrupt pending bit using HAL_EXTI_ClearPending(). (#) Generate software interrupt using HAL_EXTI_GenerateSWI(). @endverbatim *//* ... *//* Includes ------------------------------------------------------------------*/#include"stm32f4xx_hal.h"/** @addtogroup STM32F4xx_HAL_Driver * @{ *//* ... *//** @addtogroup EXTI * @{ *//* ... *//** MISRA C:2012 deviation rule has been granted for following rule: * Rule-18.1_b - Medium: Array `EXTICR' 1st subscript interval [0,7] may be out * of bounds [0,3] in following API : * HAL_EXTI_SetConfigLine * HAL_EXTI_GetConfigLine * HAL_EXTI_ClearConfigLine *//* ... */#ifdefHAL_EXTI_MODULE_ENABLED/* Private typedef -----------------------------------------------------------*//* Private defines -----------------------------------------------------------*//** @defgroup EXTI_Private_Constants EXTI Private Constants * @{ *//* ... *//** * @} *//* ... */Private defines/* Private macros ------------------------------------------------------------*//* Private variables ---------------------------------------------------------*//* Private function prototypes -----------------------------------------------*//* Exported functions --------------------------------------------------------*//** @addtogroup EXTI_Exported_Functions * @{ *//* ... *//** @addtogroup EXTI_Exported_Functions_Group1 * @brief Configuration functions *@verbatim =============================================================================== ##### Configuration functions ##### ===============================================================================@endverbatim * @{ *//* ... *//** * @brief Set configuration of a dedicated Exti line. * @param hexti Exti handle. * @param pExtiConfig Pointer on EXTI configuration to be set. * @retval HAL Status. *//* ... */HAL_StatusTypeDefHAL_EXTI_SetConfigLine(EXTI_HandleTypeDef*hexti,EXTI_ConfigTypeDef*pExtiConfig){uint32_tregval;uint32_tlinepos;uint32_tmaskline;/* Check null pointer */if((hexti==NULL)||(pExtiConfig==NULL)){returnHAL_ERROR;}if ((hexti == NULL) || (pExtiConfig == NULL)) { ... }/* Check parameters */assert_param(IS_EXTI_LINE(pExtiConfig->Line));assert_param(IS_EXTI_MODE(pExtiConfig->Mode));/* Assign line number to handle */hexti->Line=pExtiConfig->Line;/* Compute line mask */linepos=(pExtiConfig->Line&EXTI_PIN_MASK);maskline=(1uL<<linepos);/* Configure triggers for configurable lines */if((pExtiConfig->Line&EXTI_CONFIG)!=0x00u){assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger));/* Configure rising trigger *//* Mask or set line */if((pExtiConfig->Trigger&EXTI_TRIGGER_RISING)!=0x00u){EXTI->RTSR|=maskline;}if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x00u) { ... }else{EXTI->RTSR&=~maskline;}else { ... }/* Configure falling trigger *//* Mask or set line */if((pExtiConfig->Trigger&EXTI_TRIGGER_FALLING)!=0x00u){EXTI->FTSR|=maskline;}if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x00u) { ... }else{EXTI->FTSR&=~maskline;}else { ... }/* Configure gpio port selection in case of gpio exti line */if((pExtiConfig->Line&EXTI_GPIO)==EXTI_GPIO){assert_param(IS_EXTI_GPIO_PORT(pExtiConfig->GPIOSel));assert_param(IS_EXTI_GPIO_PIN(linepos));regval=SYSCFG->EXTICR[linepos>>2u];regval&=~(SYSCFG_EXTICR1_EXTI0<<(SYSCFG_EXTICR1_EXTI1_Pos*(linepos&0x03u)));regval|=(pExtiConfig->GPIOSel<<(SYSCFG_EXTICR1_EXTI1_Pos*(linepos&0x03u)));SYSCFG->EXTICR[linepos>>2u]=regval;}if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO) { ... }}if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u) { ... }/* Configure interrupt mode : read current mode *//* Mask or set line */if((pExtiConfig->Mode&EXTI_MODE_INTERRUPT)!=0x00u){EXTI->IMR|=maskline;}if ((pExtiConfig->Mode & EXTI_MODE_INTERRUPT) != 0x00u) { ... }else{EXTI->IMR&=~maskline;}else { ... }/* Configure event mode : read current mode *//* Mask or set line */if((pExtiConfig->Mode&EXTI_MODE_EVENT)!=0x00u){EXTI->EMR|=maskline;}if ((pExtiConfig->Mode & EXTI_MODE_EVENT) != 0x00u) { ... }else{EXTI->EMR&=~maskline;}else { ... }returnHAL_OK;}{ ... }/** * @brief Get configuration of a dedicated Exti line. * @param hexti Exti handle. * @param pExtiConfig Pointer on structure to store Exti configuration. * @retval HAL Status. *//* ... */HAL_StatusTypeDefHAL_EXTI_GetConfigLine(EXTI_HandleTypeDef*hexti,EXTI_ConfigTypeDef*pExtiConfig){uint32_tregval;uint32_tlinepos;uint32_tmaskline;/* Check null pointer */if((hexti==NULL)||(pExtiConfig==NULL)){returnHAL_ERROR;}if ((hexti == NULL) || (pExtiConfig == NULL)) { ... }/* Check the parameter */assert_param(IS_EXTI_LINE(hexti->Line));/* Store handle line number to configuration structure */pExtiConfig->Line=hexti->Line;/* Compute line mask */linepos=(pExtiConfig->Line&EXTI_PIN_MASK);maskline=(1uL<<linepos);/* 1] Get core mode : interrupt *//* Check if selected line is enable */if((EXTI->IMR&maskline)!=0x00u){pExtiConfig->Mode=EXTI_MODE_INTERRUPT;}if ((EXTI->IMR & maskline) != 0x00u) { ... }else{pExtiConfig->Mode=EXTI_MODE_NONE;}else { ... }/* Get event mode *//* Check if selected line is enable */if((EXTI->EMR&maskline)!=0x00u){pExtiConfig->Mode|=EXTI_MODE_EVENT;}if ((EXTI->EMR & maskline) != 0x00u) { ... }/* Get default Trigger and GPIOSel configuration */pExtiConfig->Trigger=EXTI_TRIGGER_NONE;pExtiConfig->GPIOSel=0x00u;/* 2] Get trigger for configurable lines : rising */if((pExtiConfig->Line&EXTI_CONFIG)!=0x00u){/* Check if configuration of selected line is enable */if((EXTI->RTSR&maskline)!=0x00u){pExtiConfig->Trigger=EXTI_TRIGGER_RISING;}if ((EXTI->RTSR & maskline) != 0x00u) { ... }/* Get falling configuration *//* Check if configuration of selected line is enable */if((EXTI->FTSR&maskline)!=0x00u){pExtiConfig->Trigger|=EXTI_TRIGGER_FALLING;}if ((EXTI->FTSR & maskline) != 0x00u) { ... }/* Get Gpio port selection for gpio lines */if((pExtiConfig->Line&EXTI_GPIO)==EXTI_GPIO){assert_param(IS_EXTI_GPIO_PIN(linepos));regval=SYSCFG->EXTICR[linepos>>2u];pExtiConfig->GPIOSel=(regval>>(SYSCFG_EXTICR1_EXTI1_Pos*(linepos&0x03u)))&SYSCFG_EXTICR1_EXTI0;}if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO) { ... }}if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u) { ... }returnHAL_OK;}{ ... }/** * @brief Clear whole configuration of a dedicated Exti line. * @param hexti Exti handle. * @retval HAL Status. *//* ... */HAL_StatusTypeDefHAL_EXTI_ClearConfigLine(EXTI_HandleTypeDef*hexti){uint32_tregval;uint32_tlinepos;uint32_tmaskline;/* Check null pointer */if(hexti==NULL){returnHAL_ERROR;}if (hexti == NULL) { ... }/* Check the parameter */assert_param(IS_EXTI_LINE(hexti->Line));/* compute line mask */linepos=(hexti->Line&EXTI_PIN_MASK);maskline=(1uL<<linepos);/* 1] Clear interrupt mode */EXTI->IMR=(EXTI->IMR&~maskline);/* 2] Clear event mode */EXTI->EMR=(EXTI->EMR&~maskline);/* 3] Clear triggers in case of configurable lines */if((hexti->Line&EXTI_CONFIG)!=0x00u){EXTI->RTSR=(EXTI->RTSR&~maskline);EXTI->FTSR=(EXTI->FTSR&~maskline);/* Get Gpio port selection for gpio lines */if((hexti->Line&EXTI_GPIO)==EXTI_GPIO){assert_param(IS_EXTI_GPIO_PIN(linepos));regval=SYSCFG->EXTICR[linepos>>2u];regval&=~(SYSCFG_EXTICR1_EXTI0<<(SYSCFG_EXTICR1_EXTI1_Pos*(linepos&0x03u)));SYSCFG->EXTICR[linepos>>2u]=regval;}if ((hexti->Line & EXTI_GPIO) == EXTI_GPIO) { ... }}if ((hexti->Line & EXTI_CONFIG) != 0x00u) { ... }returnHAL_OK;}{ ... }/** * @brief Register callback for a dedicated Exti line. * @param hexti Exti handle. * @param CallbackID User callback identifier. * This parameter can be one of @arg @ref EXTI_CallbackIDTypeDef values. * @param pPendingCbfn function pointer to be stored as callback. * @retval HAL Status. *//* ... */HAL_StatusTypeDefHAL_EXTI_RegisterCallback(EXTI_HandleTypeDef*hexti,EXTI_CallbackIDTypeDefCallbackID,void(*pPendingCbfn)(void)){HAL_StatusTypeDefstatus=HAL_OK;switch(CallbackID){caseHAL_EXTI_COMMON_CB_ID:hexti->PendingCallback=pPendingCbfn;break;case HAL_EXTI_COMMON_CB_ID:default:status=HAL_ERROR;break;default}switch (CallbackID) { ... }returnstatus;}{ ... }/** * @brief Store line number as handle private field. * @param hexti Exti handle. * @param ExtiLine Exti line number. * This parameter can be from 0 to @ref EXTI_LINE_NB. * @retval HAL Status. *//* ... */HAL_StatusTypeDefHAL_EXTI_GetHandle(EXTI_HandleTypeDef*hexti,uint32_tExtiLine){/* Check the parameters */assert_param(IS_EXTI_LINE(ExtiLine));/* Check null pointer */if(hexti==NULL){returnHAL_ERROR;}if (hexti == NULL) { ... }else{/* Store line number as handle private field */hexti->Line=ExtiLine;returnHAL_OK;}else { ... }}{ ... }/** * @} *//* ... *//** @addtogroup EXTI_Exported_Functions_Group2 * @brief EXTI IO functions. *@verbatim =============================================================================== ##### IO operation functions ##### ===============================================================================@endverbatim * @{ *//* ... *//** * @brief Handle EXTI interrupt request. * @param hexti Exti handle. * @retval none. *//* ... */voidHAL_EXTI_IRQHandler(EXTI_HandleTypeDef*hexti){uint32_tregval;uint32_tmaskline;/* Compute line mask */maskline=(1uL<<(hexti->Line&EXTI_PIN_MASK));/* Get pending bit */regval=(EXTI->PR&maskline);if(regval!=0x00u){/* Clear pending bit */EXTI->PR=maskline;/* Call callback */if(hexti->PendingCallback!=NULL){hexti->PendingCallback();}if (hexti->PendingCallback != NULL) { ... }}if (regval != 0x00u) { ... }}{ ... }/** * @brief Get interrupt pending bit of a dedicated line. * @param hexti Exti handle. * @param Edge Specify which pending edge as to be checked. * This parameter can be one of the following values: * @arg @ref EXTI_TRIGGER_RISING_FALLING * This parameter is kept for compatibility with other series. * @retval 1 if interrupt is pending else 0. *//* ... */uint32_tHAL_EXTI_GetPending(EXTI_HandleTypeDef*hexti,uint32_tEdge){uint32_tregval;uint32_tlinepos;uint32_tmaskline;/* Check parameters */assert_param(IS_EXTI_LINE(hexti->Line));assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));assert_param(IS_EXTI_PENDING_EDGE(Edge));/* Compute line mask */linepos=(hexti->Line&EXTI_PIN_MASK);maskline=(1uL<<linepos);/* return 1 if bit is set else 0 */regval=((EXTI->PR&maskline)>>linepos);returnregval;}{ ... }/** * @brief Clear interrupt pending bit of a dedicated line. * @param hexti Exti handle. * @param Edge Specify which pending edge as to be clear. * This parameter can be one of the following values: * @arg @ref EXTI_TRIGGER_RISING_FALLING * This parameter is kept for compatibility with other series. * @retval None. *//* ... */voidHAL_EXTI_ClearPending(EXTI_HandleTypeDef*hexti,uint32_tEdge){uint32_tmaskline;/* Check parameters */assert_param(IS_EXTI_LINE(hexti->Line));assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));assert_param(IS_EXTI_PENDING_EDGE(Edge));/* Compute line mask */maskline=(1uL<<(hexti->Line&EXTI_PIN_MASK));/* Clear Pending bit */EXTI->PR=maskline;}{ ... }/** * @brief Generate a software interrupt for a dedicated line. * @param hexti Exti handle. * @retval None. *//* ... */voidHAL_EXTI_GenerateSWI(EXTI_HandleTypeDef*hexti){uint32_tmaskline;/* Check parameters */assert_param(IS_EXTI_LINE(hexti->Line));assert_param(IS_EXTI_CONFIG_LINE(hexti->Line));/* Compute line mask */maskline=(1uL<<(hexti->Line&EXTI_PIN_MASK));/* Generate Software interrupt */EXTI->SWIER=maskline;}{ ... }/** * @} *//* ... *//** * @} *//* ... *//* ... */#endif/* HAL_EXTI_MODULE_ENABLED *//** * @} *//* ... *//** * @} *//* ... */
Details
Show: from
Types: Columns:
All items filtered out
All items filtered out
This file uses the notable symbols shown below. Click anywhere in the file to view more details.