2 ******************************************************************************
3 * @file stm32f10x_exti.c
4 * @author MCD Application Team
7 * @brief This file provides all the EXTI firmware functions.
8 ******************************************************************************
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, STMICROELECTRONICS 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.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x_exti.h"
25 /** @addtogroup STM32F10x_StdPeriph_Driver
30 * @brief EXTI driver modules
34 /** @defgroup EXTI_Private_TypesDefinitions
42 /** @defgroup EXTI_Private_Defines
46 #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
52 /** @defgroup EXTI_Private_Macros
60 /** @defgroup EXTI_Private_Variables
68 /** @defgroup EXTI_Private_FunctionPrototypes
76 /** @defgroup EXTI_Private_Functions
81 * @brief Deinitializes the EXTI peripheral registers to their default reset values.
85 void EXTI_DeInit(void)
87 EXTI
->IMR
= 0x00000000;
88 EXTI
->EMR
= 0x00000000;
89 EXTI
->RTSR
= 0x00000000;
90 EXTI
->FTSR
= 0x00000000;
91 EXTI
->PR
= 0x000FFFFF;
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 peripheral.
101 void EXTI_Init(EXTI_InitTypeDef
* EXTI_InitStruct
)
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
));
111 tmp
= (uint32_t)EXTI_BASE
;
113 if (EXTI_InitStruct
->EXTI_LineCmd
!= DISABLE
)
115 /* Clear EXTI line configuration */
116 EXTI
->IMR
&= ~EXTI_InitStruct
->EXTI_Line
;
117 EXTI
->EMR
&= ~EXTI_InitStruct
->EXTI_Line
;
119 tmp
+= EXTI_InitStruct
->EXTI_Mode
;
121 *(__IO
uint32_t *) tmp
|= EXTI_InitStruct
->EXTI_Line
;
123 /* Clear Rising Falling edge configuration */
124 EXTI
->RTSR
&= ~EXTI_InitStruct
->EXTI_Line
;
125 EXTI
->FTSR
&= ~EXTI_InitStruct
->EXTI_Line
;
127 /* Select the trigger for the selected external interrupts */
128 if (EXTI_InitStruct
->EXTI_Trigger
== EXTI_Trigger_Rising_Falling
)
130 /* Rising Falling edge */
131 EXTI
->RTSR
|= EXTI_InitStruct
->EXTI_Line
;
132 EXTI
->FTSR
|= EXTI_InitStruct
->EXTI_Line
;
136 tmp
= (uint32_t)EXTI_BASE
;
137 tmp
+= EXTI_InitStruct
->EXTI_Trigger
;
139 *(__IO
uint32_t *) tmp
|= EXTI_InitStruct
->EXTI_Line
;
144 tmp
+= EXTI_InitStruct
->EXTI_Mode
;
146 /* Disable the selected external lines */
147 *(__IO
uint32_t *) tmp
&= ~EXTI_InitStruct
->EXTI_Line
;
152 * @brief Fills each EXTI_InitStruct member with its reset value.
153 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
157 void EXTI_StructInit(EXTI_InitTypeDef
* EXTI_InitStruct
)
159 EXTI_InitStruct
->EXTI_Line
= EXTI_LINENONE
;
160 EXTI_InitStruct
->EXTI_Mode
= EXTI_Mode_Interrupt
;
161 EXTI_InitStruct
->EXTI_Trigger
= EXTI_Trigger_Falling
;
162 EXTI_InitStruct
->EXTI_LineCmd
= DISABLE
;
166 * @brief Generates a Software interrupt.
167 * @param EXTI_Line: specifies the EXTI lines to be enabled or disabled.
168 * This parameter can be any combination of EXTI_Linex where x can be (0..19).
171 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line
)
173 /* Check the parameters */
174 assert_param(IS_EXTI_LINE(EXTI_Line
));
176 EXTI
->SWIER
|= EXTI_Line
;
180 * @brief Checks whether the specified EXTI line flag is set or not.
181 * @param EXTI_Line: specifies the EXTI line flag to check.
182 * This parameter can be:
183 * @arg EXTI_Linex: External interrupt line x where x(0..19)
184 * @retval The new state of EXTI_Line (SET or RESET).
186 FlagStatus
EXTI_GetFlagStatus(uint32_t EXTI_Line
)
188 FlagStatus bitstatus
= RESET
;
189 /* Check the parameters */
190 assert_param(IS_GET_EXTI_LINE(EXTI_Line
));
192 if ((EXTI
->PR
& EXTI_Line
) != (uint32_t)RESET
)
204 * @brief Clears the EXTI's line pending flags.
205 * @param EXTI_Line: specifies the EXTI lines flags to clear.
206 * This parameter can be any combination of EXTI_Linex where x can be (0..19).
209 void EXTI_ClearFlag(uint32_t EXTI_Line
)
211 /* Check the parameters */
212 assert_param(IS_EXTI_LINE(EXTI_Line
));
214 EXTI
->PR
= EXTI_Line
;
218 * @brief Checks whether the specified EXTI line is asserted or not.
219 * @param EXTI_Line: specifies the EXTI line to check.
220 * This parameter can be:
221 * @arg EXTI_Linex: External interrupt line x where x(0..19)
222 * @retval The new state of EXTI_Line (SET or RESET).
224 ITStatus
EXTI_GetITStatus(uint32_t EXTI_Line
)
226 ITStatus bitstatus
= RESET
;
227 uint32_t enablestatus
= 0;
228 /* Check the parameters */
229 assert_param(IS_GET_EXTI_LINE(EXTI_Line
));
231 enablestatus
= EXTI
->IMR
& EXTI_Line
;
232 if (((EXTI
->PR
& EXTI_Line
) != (uint32_t)RESET
) && (enablestatus
!= (uint32_t)RESET
))
244 * @brief Clears the EXTI's line pending bits.
245 * @param EXTI_Line: specifies the EXTI lines to clear.
246 * This parameter can be any combination of EXTI_Linex where x can be (0..19).
249 void EXTI_ClearITPendingBit(uint32_t EXTI_Line
)
251 /* Check the parameters */
252 assert_param(IS_EXTI_LINE(EXTI_Line
));
254 EXTI
->PR
= EXTI_Line
;
269 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/