STM32L486xx 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 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 #if defined(USE_FULL_LL_DRIVER) 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32l4xx_ll_exti.h" 00039 #ifdef USE_FULL_ASSERT 00040 #include "stm32_assert.h" 00041 #else 00042 #define assert_param(expr) ((void)0U) 00043 #endif 00044 00045 /** @addtogroup STM32L4xx_LL_Driver 00046 * @{ 00047 */ 00048 00049 #if defined (EXTI) 00050 00051 /** @defgroup EXTI_LL EXTI 00052 * @{ 00053 */ 00054 00055 /* Private types -------------------------------------------------------------*/ 00056 /* Private variables ---------------------------------------------------------*/ 00057 /* Private constants ---------------------------------------------------------*/ 00058 /* Private macros ------------------------------------------------------------*/ 00059 /** @addtogroup EXTI_LL_Private_Macros 00060 * @{ 00061 */ 00062 00063 #define IS_LL_EXTI_LINE_0_31(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U) 00064 #define IS_LL_EXTI_LINE_32_63(__VALUE__) (((__VALUE__) & ~LL_EXTI_LINE_ALL_32_63) == 0x00000000U) 00065 00066 #define IS_LL_EXTI_MODE(__VALUE__) (((__VALUE__) == LL_EXTI_MODE_IT) \ 00067 || ((__VALUE__) == LL_EXTI_MODE_EVENT) \ 00068 || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT)) 00069 00070 00071 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \ 00072 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \ 00073 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \ 00074 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING)) 00075 00076 /** 00077 * @} 00078 */ 00079 00080 /* Private function prototypes -----------------------------------------------*/ 00081 00082 /* Exported functions --------------------------------------------------------*/ 00083 /** @addtogroup EXTI_LL_Exported_Functions 00084 * @{ 00085 */ 00086 00087 /** @addtogroup EXTI_LL_EF_Init 00088 * @{ 00089 */ 00090 00091 /** 00092 * @brief De-initialize the EXTI registers to their default reset values. 00093 * @retval An ErrorStatus enumeration value: 00094 * - SUCCESS: EXTI registers are de-initialized 00095 * - ERROR: not applicable 00096 */ 00097 uint32_t LL_EXTI_DeInit(void) 00098 { 00099 /* Interrupt mask register set to default reset values */ 00100 LL_EXTI_WriteReg(IMR1, 0xFF820000U); 00101 /* Event mask register set to default reset values */ 00102 LL_EXTI_WriteReg(EMR1, 0x00000000U); 00103 /* Rising Trigger selection register set to default reset values */ 00104 LL_EXTI_WriteReg(RTSR1, 0x00000000U); 00105 /* Falling Trigger selection register set to default reset values */ 00106 LL_EXTI_WriteReg(FTSR1, 0x00000000U); 00107 /* Software interrupt event register set to default reset values */ 00108 LL_EXTI_WriteReg(SWIER1, 0x00000000U); 00109 /* Pending register clear */ 00110 LL_EXTI_WriteReg(PR1, 0x007DFFFFU); 00111 00112 /* Interrupt mask register 2 set to default reset values */ 00113 #if defined(LL_EXTI_LINE_40) 00114 LL_EXTI_WriteReg(IMR2, 0x00000187U); 00115 #else 00116 LL_EXTI_WriteReg(IMR2, 0x00000087U); 00117 #endif 00118 /* Event mask register 2 set to default reset values */ 00119 LL_EXTI_WriteReg(EMR2, 0x00000000U); 00120 /* Rising Trigger selection register 2 set to default reset values */ 00121 LL_EXTI_WriteReg(RTSR2, 0x00000000U); 00122 /* Falling Trigger selection register 2 set to default reset values */ 00123 LL_EXTI_WriteReg(FTSR2, 0x00000000U); 00124 /* Software interrupt event register 2 set to default reset values */ 00125 LL_EXTI_WriteReg(SWIER2, 0x00000000U); 00126 /* Pending register 2 clear */ 00127 LL_EXTI_WriteReg(PR2, 0x00000078U); 00128 00129 return SUCCESS; 00130 } 00131 00132 /** 00133 * @brief Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct. 00134 * @param EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure. 00135 * @retval An ErrorStatus enumeration value: 00136 * - SUCCESS: EXTI registers are initialized 00137 * - ERROR: not applicable 00138 */ 00139 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct) 00140 { 00141 ErrorStatus status = SUCCESS; 00142 /* Check the parameters */ 00143 assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31)); 00144 assert_param(IS_LL_EXTI_LINE_32_63(EXTI_InitStruct->Line_32_63)); 00145 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand)); 00146 assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode)); 00147 00148 /* ENABLE LineCommand */ 00149 if (EXTI_InitStruct->LineCommand != DISABLE) 00150 { 00151 assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger)); 00152 00153 /* Configure EXTI Lines in range from 0 to 31 */ 00154 if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE) 00155 { 00156 switch (EXTI_InitStruct->Mode) 00157 { 00158 case LL_EXTI_MODE_IT: 00159 /* First Disable Event on provided Lines */ 00160 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31); 00161 /* Then Enable IT on provided Lines */ 00162 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31); 00163 break; 00164 case LL_EXTI_MODE_EVENT: 00165 /* First Disable IT on provided Lines */ 00166 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31); 00167 /* Then Enable Event on provided Lines */ 00168 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31); 00169 break; 00170 case LL_EXTI_MODE_IT_EVENT: 00171 /* Directly Enable IT & Event on provided Lines */ 00172 LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31); 00173 LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31); 00174 break; 00175 default: 00176 status = ERROR; 00177 break; 00178 } 00179 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE) 00180 { 00181 switch (EXTI_InitStruct->Trigger) 00182 { 00183 case LL_EXTI_TRIGGER_RISING: 00184 /* First Disable Falling Trigger on provided Lines */ 00185 LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 00186 /* Then Enable Rising Trigger on provided Lines */ 00187 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 00188 break; 00189 case LL_EXTI_TRIGGER_FALLING: 00190 /* First Disable Rising Trigger on provided Lines */ 00191 LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 00192 /* Then Enable Falling Trigger on provided Lines */ 00193 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 00194 break; 00195 case LL_EXTI_TRIGGER_RISING_FALLING: 00196 LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31); 00197 LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31); 00198 break; 00199 default: 00200 status = ERROR; 00201 break; 00202 } 00203 } 00204 } 00205 /* Configure EXTI Lines in range from 32 to 63 */ 00206 if (EXTI_InitStruct->Line_32_63 != LL_EXTI_LINE_NONE) 00207 { 00208 switch (EXTI_InitStruct->Mode) 00209 { 00210 case LL_EXTI_MODE_IT: 00211 /* First Disable Event on provided Lines */ 00212 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63); 00213 /* Then Enable IT on provided Lines */ 00214 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63); 00215 break; 00216 case LL_EXTI_MODE_EVENT: 00217 /* First Disable IT on provided Lines */ 00218 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63); 00219 /* Then Enable Event on provided Lines */ 00220 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63); 00221 break; 00222 case LL_EXTI_MODE_IT_EVENT: 00223 /* Directly Enable IT & Event on provided Lines */ 00224 LL_EXTI_EnableIT_32_63(EXTI_InitStruct->Line_32_63); 00225 LL_EXTI_EnableEvent_32_63(EXTI_InitStruct->Line_32_63); 00226 break; 00227 default: 00228 status = ERROR; 00229 break; 00230 } 00231 if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE) 00232 { 00233 switch (EXTI_InitStruct->Trigger) 00234 { 00235 case LL_EXTI_TRIGGER_RISING: 00236 /* First Disable Falling Trigger on provided Lines */ 00237 LL_EXTI_DisableFallingTrig_32_63(EXTI_InitStruct->Line_32_63); 00238 /* Then Enable IT on provided Lines */ 00239 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63); 00240 break; 00241 case LL_EXTI_TRIGGER_FALLING: 00242 /* First Disable Rising Trigger on provided Lines */ 00243 LL_EXTI_DisableRisingTrig_32_63(EXTI_InitStruct->Line_32_63); 00244 /* Then Enable Falling Trigger on provided Lines */ 00245 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63); 00246 break; 00247 case LL_EXTI_TRIGGER_RISING_FALLING: 00248 LL_EXTI_EnableRisingTrig_32_63(EXTI_InitStruct->Line_32_63); 00249 LL_EXTI_EnableFallingTrig_32_63(EXTI_InitStruct->Line_32_63); 00250 break; 00251 default: 00252 status = ERROR; 00253 break; 00254 } 00255 } 00256 } 00257 } 00258 /* DISABLE LineCommand */ 00259 else 00260 { 00261 /* De-configure EXTI Lines in range from 0 to 31 */ 00262 LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31); 00263 LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31); 00264 /* De-configure EXTI Lines in range from 32 to 63 */ 00265 LL_EXTI_DisableIT_32_63(EXTI_InitStruct->Line_32_63); 00266 LL_EXTI_DisableEvent_32_63(EXTI_InitStruct->Line_32_63); 00267 } 00268 return status; 00269 } 00270 00271 /** 00272 * @brief Set each @ref LL_EXTI_InitTypeDef field to default value. 00273 * @param EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure. 00274 * @retval None 00275 */ 00276 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct) 00277 { 00278 EXTI_InitStruct->Line_0_31 = LL_EXTI_LINE_NONE; 00279 EXTI_InitStruct->Line_32_63 = LL_EXTI_LINE_NONE; 00280 EXTI_InitStruct->LineCommand = DISABLE; 00281 EXTI_InitStruct->Mode = LL_EXTI_MODE_IT; 00282 EXTI_InitStruct->Trigger = LL_EXTI_TRIGGER_FALLING; 00283 } 00284 00285 /** 00286 * @} 00287 */ 00288 00289 /** 00290 * @} 00291 */ 00292 00293 /** 00294 * @} 00295 */ 00296 00297 #endif /* defined (EXTI) */ 00298 00299 /** 00300 * @} 00301 */ 00302 00303 #endif /* USE_FULL_LL_DRIVER */ 00304 00305 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/