STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_exti.c 00004 * @author MCD Application Team 00005 * @brief EXTI LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 #if defined(USE_FULL_LL_DRIVER) 00019 00020 /* Includes ------------------------------------------------------------------*/ 00021 #include "stm32l4xx_ll_exti.h" 00022 #ifdef USE_FULL_ASSERT 00023 #include "stm32_assert.h" 00024 #else 00025 #define assert_param(expr) ((void)0U) 00026 #endif 00027 00028 /** @addtogroup STM32L4xx_LL_Driver 00029 * @{ 00030 */ 00031 00032 #if defined (EXTI) 00033 00034 /** @defgroup EXTI_LL EXTI 00035 * @{ 00036 */ 00037 00038 /* Private types -------------------------------------------------------------*/ 00039 /* Private variables ---------------------------------------------------------*/ 00040 /* Private constants ---------------------------------------------------------*/ 00041 /* Private macros ------------------------------------------------------------*/ 00042 /** @addtogroup EXTI_LL_Private_Macros 00043 * @{ 00044 */ 00045 00046 #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U) 00047 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U) 00048 00049 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \ 00050 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \ 00051 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT)) 00052 00053 00054 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \ 00055 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \ 00056 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \ 00057 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING)) 00058 00059 /** 00060 * @} 00061 */ 00062 00063 /* Private function prototypes -----------------------------------------------*/ 00064 00065 /* Exported functions --------------------------------------------------------*/ 00066 /** @addtogroup EXTI_LL_Exported_Functions 00067 * @{ 00068 */ 00069 00070 /** @addtogroup EXTI_LL_EF_Init 00071 * @{ 00072 */ 00073 00074 /** 00075 * @brief De-initialize the EXTI registers to their default reset values. 00076 * @retval An ErrorStatus enumeration value: 00077 * - 0x00: EXTI registers are de-initialized 00078 */ 00079 uint32_t LL_EXTI_DeInit(void) 00080 { 00081 /* Interrupt mask register set to default reset values */ 00082 LL_EXTI_WriteReg(IMR1, 0xFF820000U); 00083 /* Event mask register set to default reset values */ 00084 LL_EXTI_WriteReg(EMR1, 0x00000000U); 00085 /* Rising Trigger selection register set to default reset values */ 00086 LL_EXTI_WriteReg(RTSR1, 0x00000000U); 00087 /* Falling Trigger selection register set to default reset values */ 00088 LL_EXTI_WriteReg(FTSR1, 0x00000000U); 00089 /* Software interrupt event register set to default reset values */ 00090 LL_EXTI_WriteReg(SWIER1, 0x00000000U); 00091 /* Pending register clear */ 00092 LL_EXTI_WriteReg(PR1, 0x007DFFFFU); 00093 00094 /* Interrupt mask register 2 set to default reset values */ 00095 #if defined(LL_EXTI_LINE_40) 00096 LL_EXTI_WriteReg(IMR2, 0x00000187U); 00097 #else 00098 LL_EXTI_WriteReg(IMR2, 0x00000087U); 00099 #endif 00100 /* Event mask register 2 set to default reset values */ 00101 LL_EXTI_WriteReg(EMR2, 0x00000000U); 00102 /* Rising Trigger selection register 2 set to default reset values */ 00103 LL_EXTI_WriteReg(RTSR2, 0x00000000U); 00104 /* Falling Trigger selection register 2 set to default reset values */ 00105 LL_EXTI_WriteReg(FTSR2, 0x00000000U); 00106 /* Software interrupt event register 2 set to default reset values */ 00107 LL_EXTI_WriteReg(SWIER2, 0x00000000U); 00108 /* Pending register 2 clear */ 00109 LL_EXTI_WriteReg(PR2, 0x00000078U); 00110 00111 return 0x00u; 00112 } 00113 00114 /** 00115 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct. 00116 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure. 00117 * @retval An ErrorStatus enumeration value: 00118 * - 0x00: EXTI registers are initialized 00119 * - any other calue : wrong configuration 00120 */ 00121 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct) 00122 { 00123 uint32_t status = 0x00u; 00124 00125 /* Check the parameters */ 00126 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31)); 00127 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63)); 00128 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand)); 00129 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode)); 00130 00131 /* ENABLE LineCommand */ 00132 if (EXTI_InitStruct->LineCommand != DISABLE) 00133 { 00134 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger)); 00135 00136 /* Configure EXTI Lines in range from 0 to 31 */ 00137 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE) 00138 { 00139 switch (EXTI_InitStruct->Mode) 00140 { 00141 case LL_EXTI_MODE_IT: 00142 /* First Disable Event on provided Lines */ 00143 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31); 00144 /* Then Enable IT on provided Lines */ 00145 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31); 00146 break; 00147 case LL_EXTI_MODE_EVENT: 00148 /* First Disable IT on provided Lines */ 00149 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31); 00150 /* Then Enable Event on provided Lines */ 00151 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31); 00152 break; 00153 case LL_EXTI_MODE_IT_EVENT: 00154 /* Directly Enable IT & Event on provided Lines */ 00155 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31); 00156 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31); 00157 break; 00158 default: 00159 status = 0x01u; 00160 break; 00161 } 00162 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE) 00163 { 00164 switch (EXTI_InitStruct->Trigger) 00165 { 00166 case LL_EXTI_TRIGGER_RISING: 00167 /* First Disable Falling Trigger on provided Lines */ 00168 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 00169 /* Then Enable Rising Trigger on provided Lines */ 00170 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 00171 break; 00172 case LL_EXTI_TRIGGER_FALLING: 00173 /* First Disable Rising Trigger on provided Lines */ 00174 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 00175 /* Then Enable Falling Trigger on provided Lines */ 00176 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 00177 break; 00178 case LL_EXTI_TRIGGER_RISING_FALLING: 00179 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 00180 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 00181 break; 00182 default: 00183 status |= 0x02u; 00184 break; 00185 } 00186 } 00187 } 00188 /* Configure EXTI Lines in range from 32 to 63 */ 00189 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE) 00190 { 00191 switch (EXTI_InitStruct->Mode) 00192 { 00193 case LL_EXTI_MODE_IT: 00194 /* First Disable Event on provided Lines */ 00195 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63); 00196 /* Then Enable IT on provided Lines */ 00197 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63); 00198 break; 00199 case LL_EXTI_MODE_EVENT: 00200 /* First Disable IT on provided Lines */ 00201 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63); 00202 /* Then Enable Event on provided Lines */ 00203 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63); 00204 break; 00205 case LL_EXTI_MODE_IT_EVENT: 00206 /* Directly Enable IT & Event on provided Lines */ 00207 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63); 00208 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63); 00209 break; 00210 default: 00211 status |= 0x04u; 00212 break; 00213 } 00214 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE) 00215 { 00216 switch (EXTI_InitStruct->Trigger) 00217 { 00218 case LL_EXTI_TRIGGER_RISING: 00219 /* First Disable Falling Trigger on provided Lines */ 00220 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63); 00221 /* Then Enable IT on provided Lines */ 00222 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63); 00223 break; 00224 case LL_EXTI_TRIGGER_FALLING: 00225 /* First Disable Rising Trigger on provided Lines */ 00226 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63); 00227 /* Then Enable Falling Trigger on provided Lines */ 00228 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63); 00229 break; 00230 case LL_EXTI_TRIGGER_RISING_FALLING: 00231 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63); 00232 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63); 00233 break; 00234 default: 00235 status = ERROR; 00236 break; 00237 } 00238 } 00239 } 00240 } 00241 /* DISABLE LineCommand */ 00242 else 00243 { 00244 /* De-configure EXTI Lines in range from 0 to 31 */ 00245 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31); 00246 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31); 00247 /* De-configure EXTI Lines in range from 32 to 63 */ 00248 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63); 00249 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63); 00250 } 00251 00252 return status; 00253 } 00254 00255 /** 00256 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value. 00257 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure. 00258 * @retval None 00259 */ 00260 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct) 00261 { 00262 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE; 00263 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE; 00264 EXTI_InitStruct->LineCommand = DISABLE; 00265 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT; 00266 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING; 00267 } 00268 00269 /** 00270 * @} 00271 */ 00272 00273 /** 00274 * @} 00275 */ 00276 00277 /** 00278 * @} 00279 */ 00280 00281 #endif /* defined (EXTI) */ 00282 00283 /** 00284 * @} 00285 */ 00286 00287 #endif /* USE_FULL_LL_DRIVER */ 00288