|
STM32G474xx HAL用户手册
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32g4xx_ll_exti.c 00004 * @author MCD Application Team 00005 * @brief EXTI LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2019 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 "stm32g4xx_ll_exti.h" 00022 #ifdef USE_FULL_ASSERT 00023 #include "stm32_assert.h" 00024 #else 00025 #define assert_param(expr) ((void)0U) 00026 #endif /* USE_FULL_ASSERT */ 00027 00028 /** @addtogroup STM32G4xx_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 #define IS_LL_EXTI_TRIGGER(__VALUE__) (((__VALUE__) == LL_EXTI_TRIGGER_NONE) \ 00054 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING) \ 00055 || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING) \ 00056 || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING)) 00057 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, 0x1F840000U); 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_32) && defined(LL_EXTI_LINE_33) && defined(LL_EXTI_LINE_35) && defined(LL_EXTI_LINE_42) 00096 LL_EXTI_WriteReg(IMR2, 0x0000043CU); 00097 #else 00098 LL_EXTI_WriteReg(IMR2, 0x00000034U); 00099 #endif /* LL_EXTI_LINE_xx */ 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 value : 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