1 /* Includes ------------------------------------------------------------------*/ 2 #include "air32f10x_exti.h" 3 4 5 /** @defgroup EXTI 6 * @brief EXTI driver modules 7 * @{ 8 */ 9 10 /** @defgroup EXTI_Private_TypesDefinitions 11 * @{ 12 */ 13 14 /** 15 * @} 16 */ 17 18 /** @defgroup EXTI_Private_Defines 19 * @{ 20 */ 21 22 #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */ 23 24 /** 25 * @} 26 */ 27 28 /** @defgroup EXTI_Private_Macros 29 * @{ 30 */ 31 32 /** 33 * @} 34 */ 35 36 /** @defgroup EXTI_Private_Variables 37 * @{ 38 */ 39 40 /** 41 * @} 42 */ 43 44 /** @defgroup EXTI_Private_FunctionPrototypes 45 * @{ 46 */ 47 48 /** 49 * @} 50 */ 51 52 /** @defgroup EXTI_Private_Functions 53 * @{ 54 */ 55 56 /** 57 * @brief Deinitializes the EXTI peripheral registers to their default reset values. 58 * @param None 59 * @retval None 60 */ EXTI_DeInit(void)61void EXTI_DeInit(void) 62 { 63 EXTI->IMR = 0x00000000; 64 EXTI->EMR = 0x00000000; 65 EXTI->RTSR = 0x00000000; 66 EXTI->FTSR = 0x00000000; 67 EXTI->PR = 0x000FFFFF; 68 } 69 70 /** 71 * @brief Initializes the EXTI peripheral according to the specified 72 * parameters in the EXTI_InitStruct. 73 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure 74 * that contains the configuration information for the EXTI peripheral. 75 * @retval None 76 */ EXTI_Init(EXTI_InitTypeDef * EXTI_InitStruct)77void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct) 78 { 79 uint32_t tmp = 0; 80 81 /* Check the parameters */ 82 assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode)); 83 assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger)); 84 assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line)); 85 assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd)); 86 87 tmp = (uint32_t)EXTI_BASE; 88 89 if (EXTI_InitStruct->EXTI_LineCmd != DISABLE) 90 { 91 /* Clear EXTI line configuration */ 92 EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line; 93 EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line; 94 95 tmp += EXTI_InitStruct->EXTI_Mode; 96 97 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 98 99 /* Clear Rising Falling edge configuration */ 100 EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line; 101 EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line; 102 103 /* Select the trigger for the selected external interrupts */ 104 if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling) 105 { 106 /* Rising Falling edge */ 107 EXTI->RTSR |= EXTI_InitStruct->EXTI_Line; 108 EXTI->FTSR |= EXTI_InitStruct->EXTI_Line; 109 } 110 else 111 { 112 tmp = (uint32_t)EXTI_BASE; 113 tmp += EXTI_InitStruct->EXTI_Trigger; 114 115 *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line; 116 } 117 } 118 else 119 { 120 tmp += EXTI_InitStruct->EXTI_Mode; 121 122 /* Disable the selected external lines */ 123 *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line; 124 } 125 } 126 127 /** 128 * @brief Fills each EXTI_InitStruct member with its reset value. 129 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will 130 * be initialized. 131 * @retval None 132 */ EXTI_StructInit(EXTI_InitTypeDef * EXTI_InitStruct)133void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct) 134 { 135 EXTI_InitStruct->EXTI_Line = EXTI_LINENONE; 136 EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt; 137 EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling; 138 EXTI_InitStruct->EXTI_LineCmd = DISABLE; 139 } 140 141 /** 142 * @brief Generates a Software interrupt. 143 * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled. 144 * This parameter can be any combination of EXTI_Linex where x can be (0..19). 145 * @retval None 146 */ EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)147void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line) 148 { 149 /* Check the parameters */ 150 assert_param(IS_EXTI_LINE(EXTI_Line)); 151 152 EXTI->SWIER |= EXTI_Line; 153 } 154 155 /** 156 * @brief Checks whether the specified EXTI line flag is set or not. 157 * @param EXTI_Line: specifies the EXTI line flag to check. 158 * This parameter can be: 159 * @arg EXTI_Linex: External interrupt line x where x(0..19) 160 * @retval The new state of EXTI_Line (SET or RESET). 161 */ EXTI_GetFlagStatus(uint32_t EXTI_Line)162FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line) 163 { 164 FlagStatus bitstatus = RESET; 165 /* Check the parameters */ 166 assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 167 168 if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET) 169 { 170 bitstatus = SET; 171 } 172 else 173 { 174 bitstatus = RESET; 175 } 176 return bitstatus; 177 } 178 179 /** 180 * @brief Clears the EXTI's line pending flags. 181 * @param EXTI_Line: specifies the EXTI lines flags to clear. 182 * This parameter can be any combination of EXTI_Linex where x can be (0..19). 183 * @retval None 184 */ EXTI_ClearFlag(uint32_t EXTI_Line)185void EXTI_ClearFlag(uint32_t EXTI_Line) 186 { 187 /* Check the parameters */ 188 assert_param(IS_EXTI_LINE(EXTI_Line)); 189 190 EXTI->PR = EXTI_Line; 191 } 192 193 /** 194 * @brief Checks whether the specified EXTI line is asserted or not. 195 * @param EXTI_Line: specifies the EXTI line to check. 196 * This parameter can be: 197 * @arg EXTI_Linex: External interrupt line x where x(0..19) 198 * @retval The new state of EXTI_Line (SET or RESET). 199 */ EXTI_GetITStatus(uint32_t EXTI_Line)200ITStatus EXTI_GetITStatus(uint32_t EXTI_Line) 201 { 202 ITStatus bitstatus = RESET; 203 uint32_t enablestatus = 0; 204 /* Check the parameters */ 205 assert_param(IS_GET_EXTI_LINE(EXTI_Line)); 206 207 enablestatus = EXTI->IMR & EXTI_Line; 208 if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 209 { 210 bitstatus = SET; 211 } 212 else 213 { 214 bitstatus = RESET; 215 } 216 return bitstatus; 217 } 218 219 /** 220 * @brief Clears the EXTI's line pending bits. 221 * @param EXTI_Line: specifies the EXTI lines to clear. 222 * This parameter can be any combination of EXTI_Linex where x can be (0..19). 223 * @retval None 224 */ EXTI_ClearITPendingBit(uint32_t EXTI_Line)225void EXTI_ClearITPendingBit(uint32_t EXTI_Line) 226 { 227 /* Check the parameters */ 228 assert_param(IS_EXTI_LINE(EXTI_Line)); 229 230 EXTI->PR = EXTI_Line; 231 } 232 233 /** 234 * @} 235 */ 236 237 /** 238 * @} 239 */ 240 241 /** 242 * @} 243 */ 244 245