1 /** 2 ****************************************************************************** 3 * @file HAL_exti.c 4 * @author IC Applications Department 5 * @version V0.8 6 * @date 2019_08_02 7 * @brief This file provides all the EXTI firmware functions. 8 ****************************************************************************** 9 * @copy 10 * 11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 * TIME. AS A RESULT, HOLOCENE SHALL NOT BE HELD LIABLE FOR ANY 14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 * 18 * <h2><center>© COPYRIGHT 2016 HOLOCENE</center></h2> 19 */ 20 21 /* Includes ------------------------------------------------------------------*/ 22 #include "HAL_exti.h" 23 24 /** @addtogroup StdPeriph_Driver 25 * @{ 26 */ 27 28 /** @defgroup EXTI 29 * @brief EXTI driver modules 30 * @{ 31 */ 32 33 /** @defgroup EXTI_Private_TypesDefinitions 34 * @{ 35 */ 36 37 /** 38 * @} 39 */ 40 41 /** @defgroup EXTI_Private_Defines 42 * @{ 43 */ 44 45 #define EXTI_LineNone ((uint32_t)0x00000) /* No interrupt selected */ 46 47 /** 48 * @} 49 */ 50 51 /** @defgroup EXTI_Private_Macros 52 * @{ 53 */ 54 55 /** 56 * @} 57 */ 58 59 /** @defgroup EXTI_Private_Variables 60 * @{ 61 */ 62 63 /** 64 * @} 65 */ 66 67 /** @defgroup EXTI_Private_FunctionPrototypes 68 * @{ 69 */ 70 71 /** 72 * @} 73 */ 74 75 /** @defgroup EXTI_Private_Functions 76 * @{ 77 */ 78 79 /** 80 * @brief Deinitializes the EXTI peripheral registers to their default 81 * reset values. 82 * @param None 83 * @retval : None 84 */ EXTI_DeInit(void)85void EXTI_DeInit(void) 86 { 87 EXTI->IMR = 0x00000000; 88 EXTI->EMR = 0x00000000; 89 EXTI->RTSR = 0x00000000; 90 EXTI->FTSR = 0x00000000; 91 EXTI->PR = 0x001FFFFF; 92 } 93 94 /** 95 * @brief Initializes the EXTI peripheral according to the specified 96 * parameters in the EXTI_InitStruct. 97 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 98 * that contains the configuration information for the EXTI 99 * peripheral. 100 * @retval : None 101 */ EXTI_Init(EXTI_InitTypeDef * EXTI_InitStruct)102void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct) 103 { 104 uint32_t tmp = 0; 105 /* Check the parameters */ 106 assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); 107 assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); 108 assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); 109 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); 110 111 tmp = (uint32_t)EXTI_BASE; 112 113 if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) 114 { 115 /* Clear EXTI line configuration */ 116 EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; 117 EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; 118 119 tmp += EXTI_InitStruct->EXTI_Mode; 120 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 121 122 /* Clear Rising Falling edge configuration */ 123 EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; 124 EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; 125 126 /* Select the trigger for the selected external interrupts */ 127 if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) 128 { 129 /* Rising Falling edge */ 130 EXTI->RTSR |= EXTI_InitStruct->EXTI_Line; 131 EXTI->FTSR |= EXTI_InitStruct->EXTI_Line; 132 } 133 else 134 { 135 tmp = (uint32_t)EXTI_BASE; 136 tmp += EXTI_InitStruct->EXTI_Trigger; 137 138 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 139 } 140 } 141 else 142 { 143 tmp = (uint32_t)EXTI_BASE; 144 tmp += EXTI_InitStruct->EXTI_Mode; 145 /* Disable the selected external lines */ 146 *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; 147 } 148 } 149 150 /** 151 * @brief Fills each EXTI_InitStruct member with its reset value. 152 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 153 * which will be initialized. 154 * @retval : None 155 */ EXTI_StructInit(EXTI_InitTypeDef * EXTI_InitStruct)156void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct) 157 { 158 EXTI_InitStruct->EXTI_Line = EXTI_LineNone; 159 EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; 160 EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; 161 EXTI_InitStruct->EXTI_LineCmd = DISABLE; 162 } 163 164 /** 165 * @brief Generates a Software interrupt. 166 * @param EXTI_Line: specifies the EXTI lines to be enabled or 167 * disabled. 168 * This parameter can be any combination of EXTI_Linex where 169 * x can be (0..18). 170 * @retval : None 171 */ EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)172void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line) 173 { 174 /* Check the parameters */ 175 assert_param(IS_EXTI_LINE(EXTI_Line)); 176 177 EXTI->SWIER |= EXTI_Line; 178 } 179 180 /** 181 * @brief Checks whether the specified EXTI line flag is set or not. 182 * @param EXTI_Line: specifies the EXTI line flag to check. 183 * This parameter can be: 184 * @arg EXTI_Linex: External interrupt line x where x(0..18) 185 * @retval : The new state of EXTI_Line (SET or RESET). 186 */ EXTI_GetFlagStatus(uint32_t EXTI_Line)187FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line) 188 { 189 FlagStatus bitstatus = RESET; 190 /* Check the parameters */ 191 assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 192 193 if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 194 { 195 bitstatus = SET; 196 } 197 else 198 { 199 bitstatus = RESET; 200 } 201 return bitstatus; 202 } 203 204 /** 205 * @brief Clears the EXTI’s line pending flags. 206 * @param EXTI_Line: specifies the EXTI lines flags to clear. 207 * This parameter can be any combination of EXTI_Linex where 208 * x can be (0..18). 209 * @retval : None 210 */ EXTI_ClearFlag(uint32_t EXTI_Line)211void EXTI_ClearFlag(uint32_t EXTI_Line) 212 { 213 /* Check the parameters */ 214 assert_param(IS_EXTI_LINE(EXTI_Line)); 215 216 EXTI->PR = EXTI_Line; 217 } 218 219 /** 220 * @brief Checks whether the specified EXTI line is asserted or not. 221 * @param EXTI_Line: specifies the EXTI line to check. 222 * This parameter can be: 223 * @arg EXTI_Linex: External interrupt line x where x(0..18) 224 * @retval : The new state of EXTI_Line (SET or RESET). 225 */ EXTI_GetITStatus(uint32_t EXTI_Line)226ITStatus EXTI_GetITStatus(uint32_t EXTI_Line) 227 { 228 ITStatus bitstatus = RESET; 229 uint32_t enablestatus = 0; 230 /* Check the parameters */ 231 assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 232 233 enablestatus = EXTI->IMR & EXTI_Line; 234 if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 235 { 236 bitstatus = SET; 237 } 238 else 239 { 240 bitstatus = RESET; 241 } 242 return bitstatus; 243 } 244 245 /** 246 * @brief Clears the EXTI’s line pending bits. 247 * @param EXTI_Line: specifies the EXTI lines to clear. 248 * This parameter can be any combination of EXTI_Linex where 249 * x can be (0..18). 250 * @retval : None 251 */ EXTI_ClearITPendingBit(uint32_t EXTI_Line)252void EXTI_ClearITPendingBit(uint32_t EXTI_Line) 253 { 254 /* Check the parameters */ 255 assert_param(IS_EXTI_LINE(EXTI_Line)); 256 257 EXTI->PR = EXTI_Line; 258 } 259 260 /** 261 * @} 262 */ 263 264 /** 265 * @} 266 */ 267 268 /** 269 * @} 270 */ 271 272 /*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/ 273