```html
|
STM32G474xx HAL用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_hal_exti.c 00004 * @author MCD Application Team 00005 * @brief EXTI HAL module driver. 00006 * This file provides firmware functions to manage the following 00007 * functionalities of the Extended Interrupts and events controller (EXTI) peripheral: 00008 * functionalities of the General Purpose Input/Output (EXTI) peripheral: 00009 * + Initialization and de-initialization functions 00010 * + IO operation functions 00011 * 00012 ****************************************************************************** 00013 * @attention 00014 * 00015 * Copyright (c) 2019 STMicroelectronics. 00016 * All rights reserved. 00017 * 00018 * This software is licensed under terms that can be found in the LICENSE file 00019 * in the root directory of this software component. 00020 * If no LICENSE file comes with this software, it is provided AS-IS. 00021 * 00022 ****************************************************************************** 00023 @verbatim 00024 ============================================================================== 00025 ##### EXTI Peripheral features ##### 00026 ============================================================================== 00027 [..] 00028 (+) Each Exti line can be configured within this driver. 00029 00030 (+) Exti line can be configured in 3 different modes 00031 (++) Interrupt 00032 (++) Event 00033 (++) Both of them 00034 00035 (+) Configurable Exti lines can be configured with 3 different triggers 00036 (++) Rising 00037 (++) Falling 00038 (++) Both of them 00039 00040 (+) When set in interrupt mode, configurable Exti lines have two different 00041 interrupt pending registers which allow to distinguish which transition 00042 occurs: 00043 (++) Rising edge pending interrupt 00044 (++) Falling 00045 00046 (+) Exti lines 0 to 15 are linked to gpio pin number 0 to 15. Gpio port can 00047 be selected through multiplexer. 00048 00049 ##### How to use this driver ##### 00050 ============================================================================== 00051 [..] 00052 00053 (#) Configure the EXTI line using HAL_EXTI_SetConfigLine(). 00054 (++) Choose the interrupt line number by setting "Line" member from 00055 EXTI_ConfigTypeDef structure. 00056 (++) Configure the interrupt and/or event mode using "Mode" member from 00057 EXTI_ConfigTypeDef structure. 00058 (++) For configurable lines, configure rising and/or falling trigger 00059 "Trigger" member from EXTI_ConfigTypeDef structure. 00060 (++) For Exti lines linked to gpio, choose gpio port using "GPIOSel" 00061 member from GPIO_InitTypeDef structure. 00062 00063 (#) Get current Exti configuration of a dedicated line using 00064 HAL_EXTI_GetConfigLine(). 00065 (++) Provide exiting handle as parameter. 00066 (++) Provide pointer on EXTI_ConfigTypeDef structure as second parameter. 00067 00068 (#) Clear Exti configuration of a dedicated line using HAL_EXTI_ClearConfigLine(). 00069 (++) Provide exiting handle as parameter. 00070 00071 (#) Register callback to treat Exti interrupts using HAL_EXTI_RegisterCallback(). 00072 (++) Provide exiting handle as first parameter. 00073 (++) Provide which callback will be registered using one value from 00074 EXTI_CallbackIDTypeDef. 00075 (++) Provide callback function pointer. 00076 00077 (#) Get interrupt pending bit using HAL_EXTI_GetPending(). 00078 00079 (#) Clear interrupt pending bit using HAL_EXTI_ClearPending(). 00080 00081 (#) Generate software interrupt using HAL_EXTI_GenerateSWI(). 00082 00083 @endverbatim 00084 */ 00085 00086 /* Includes ------------------------------------------------------------------*/ 00087 #include "stm32g4xx_hal.h" 00088 00089 /** @addtogroup STM32G4xx_HAL_Driver 00090 * @{ 00091 */ 00092 00093 /** @addtogroup EXTI 00094 * @{ 00095 */ 00096 /** MISRA C:2012 deviation rule has been granted for following rule: 00097 * Rule-18.1_b - Medium: Array `EXTICR' 1st subscript interval [0,7] may be out 00098 * of bounds [0,3] in following API : 00099 * HAL_EXTI_SetConfigLine 00100 * HAL_EXTI_GetConfigLine 00101 * HAL_EXTI_ClearConfigLine 00102 */ 00103 00104 #ifdef HAL_EXTI_MODULE_ENABLED 00105 00106 /* Private typedef -----------------------------------------------------------*/ 00107 /* Private defines ------------------------------------------------------------*/ 00108 /** @defgroup EXTI_Private_Constants EXTI Private Constants 00109 * @{ 00110 */ 00111 #define EXTI_MODE_OFFSET 0x08U /* 0x20: offset between MCU IMR/EMR registers */ 00112 #define EXTI_CONFIG_OFFSET 0x08U /* 0x20: offset between MCU Rising/Falling configuration registers */ 00113 /** 00114 * @} 00115 */ 00116 00117 /* Private macros ------------------------------------------------------------*/ 00118 /* Private variables ---------------------------------------------------------*/ 00119 /* Private function prototypes -----------------------------------------------*/ 00120 /* Exported functions --------------------------------------------------------*/ 00121 00122 /** @addtogroup EXTI_Exported_Functions 00123 * @{ 00124 */ 00125 00126 /** @addtogroup EXTI_Exported_Functions_Group1 00127 * @brief Configuration functions 00128 * 00129 @verbatim 00130 =============================================================================== 00131 ##### Configuration functions ##### 00132 =============================================================================== 00133 00134 @endverbatim 00135 * @{ 00136 */ 00137 00138 /** 00139 * @brief Set configuration of a dedicated Exti line. 00140 * @param hexti Exti handle. 00141 * @param pExtiConfig Pointer on EXTI configuration to be set. 00142 * @retval HAL Status. 00143 */ 00144 HAL_StatusTypeDef HAL_EXTI_SetConfigLine(EXTI_HandleTypeDef *hexti, EXTI_ConfigTypeDef *pExtiConfig) 00145 { 00146 __IO uint32_t *regaddr; 00147 uint32_t regval; 00148 uint32_t linepos; 00149 uint32_t maskline; 00150 uint32_t offset; 00151 00152 /* Check null pointer */ 00153 if ((hexti == NULL) || (pExtiConfig == NULL)) 00154 { 00155 return HAL_ERROR; 00156 } 00157 00158 /* Check parameters */ 00159 assert_param(IS_EXTI_LINE(pExtiConfig->Line)); 00160 assert_param(IS_EXTI_MODE(pExtiConfig->Mode)); 00161 00162 /* Assign line number to handle */ 00163 hexti->Line = pExtiConfig->Line; 00164 00165 /* Compute line register offset */ 00166 offset = ((pExtiConfig->Line & EXTI_REG_MASK) >> EXTI_REG_SHIFT); 00167 /* Compute line position */ 00168 linepos = (pExtiConfig->Line & EXTI_PIN_MASK); 00169 /* Compute line mask */ 00170 maskline = (1uL << linepos); 00171 00172 /* Configure triggers for configurable lines */ 00173 if ((pExtiConfig->Line & EXTI_CONFIG) != 0x00u) 00174 { 00175 assert_param(IS_EXTI_TRIGGER(pExtiConfig->Trigger)); 00176 00177 /* Configure rising trigger */ 00178 regaddr = (&EXTI->RTSR1 + (EXTI_CONFIG_OFFSET * offset)); 00179 regval = *regaddr; 00180 00181 /* Mask or set line */ 00182 if ((pExtiConfig->Trigger & EXTI_TRIGGER_RISING) != 0x00u) 00183 { 00184 regval |= maskline; 00185 } 00186 else 00187 { 00188 regval &= ~maskline; 00189 } 00190 00191 /* Store rising trigger mode */ 00192 *regaddr = regval; 00193 00194 /* Configure falling trigger */ 00195 regaddr = (&EXTI->FTSR1 + (EXTI_CONFIG_OFFSET * offset)); 00196 regval = *regaddr; 00197 00198 /* Mask or set line */ 00199 if ((pExtiConfig->Trigger & EXTI_TRIGGER_FALLING) != 0x00u) 00200 { 00201 regval |= maskline; 00202 } 00203 else 00204 { 00205 regval &= ~maskline; 00206 } 00207 00208 /* Store falling trigger mode */ 00209 *regaddr = regval; 00210 00211 /* Configure gpio port selection in case of gpio exti line */ 00212 if ((pExtiConfig->Line & EXTI_GPIO) == EXTI_GPIO) 00213 { 00214