• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2   ******************************************************************************
3   * @file    stm32f4xx_exti.c
4   * @author  MCD Application Team
5   * @version V1.4.0
6   * @date    04-August-2014
7   * @brief   This file provides firmware functions to manage the following
8   *          functionalities of the EXTI peripheral:
9   *           + Initialization and Configuration
10   *           + Interrupts and flags management
11   *
12 @verbatim
13 
14  ===============================================================================
15                               ##### EXTI features #####
16  ===============================================================================
17 
18  [..] External interrupt/event lines are mapped as following:
19    (#) All available GPIO pins are connected to the 16 external
20        interrupt/event lines from EXTI0 to EXTI15.
21    (#) EXTI line 16 is connected to the PVD Output
22    (#) EXTI line 17 is connected to the RTC Alarm event
23    (#) EXTI line 18 is connected to the USB OTG FS Wakeup from suspend event
24    (#) EXTI line 19 is connected to the Ethernet Wakeup event
25    (#) EXTI line 20 is connected to the USB OTG HS (configured in FS) Wakeup event
26    (#) EXTI line 21 is connected to the RTC Tamper and Time Stamp events
27    (#) EXTI line 22 is connected to the RTC Wakeup event
28 
29                        ##### How to use this driver #####
30  ===============================================================================
31 
32  [..] In order to use an I/O pin as an external interrupt source, follow steps
33       below:
34    (#) Configure the I/O in input mode using GPIO_Init()
35    (#) Select the input source pin for the EXTI line using SYSCFG_EXTILineConfig()
36    (#) Select the mode(interrupt, event) and configure the trigger
37        selection (Rising, falling or both) using EXTI_Init()
38    (#) Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init()
39 
40  [..]
41    (@) SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
42        registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
43 
44 @endverbatim
45   *
46   ******************************************************************************
47   * @attention
48   *
49   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
50   *
51   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
52   * You may not use this file except in compliance with the License.
53   * You may obtain a copy of the License at:
54   *
55   *        http://www.st.com/software_license_agreement_liberty_v2
56   *
57   * Unless required by applicable law or agreed to in writing, software
58   * distributed under the License is distributed on an "AS IS" BASIS,
59   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
60   * See the License for the specific language governing permissions and
61   * limitations under the License.
62   *
63   ******************************************************************************
64   */
65 
66 /* Includes ------------------------------------------------------------------*/
67 #include "stm32f4xx_exti.h"
68 
69 /** @addtogroup STM32F4xx_StdPeriph_Driver
70   * @{
71   */
72 
73 /** @defgroup EXTI
74   * @brief EXTI driver modules
75   * @{
76   */
77 
78 /* Private typedef -----------------------------------------------------------*/
79 /* Private define ------------------------------------------------------------*/
80 
81 #define EXTI_LINENONE    ((uint32_t)0x00000)  /* No interrupt selected */
82 
83 /* Private macro -------------------------------------------------------------*/
84 /* Private variables ---------------------------------------------------------*/
85 /* Private function prototypes -----------------------------------------------*/
86 /* Private functions ---------------------------------------------------------*/
87 
88 /** @defgroup EXTI_Private_Functions
89   * @{
90   */
91 
92 /** @defgroup EXTI_Group1 Initialization and Configuration functions
93  *  @brief   Initialization and Configuration functions
94  *
95 @verbatim
96  ===============================================================================
97              ##### Initialization and Configuration functions #####
98  ===============================================================================
99 
100 @endverbatim
101   * @{
102   */
103 
104 /**
105   * @brief  Deinitializes the EXTI peripheral registers to their default reset values.
106   * @param  None
107   * @retval None
108   */
EXTI_DeInit(void)109 void EXTI_DeInit(void)
110 {
111   EXTI->IMR = 0x00000000;
112   EXTI->EMR = 0x00000000;
113   EXTI->RTSR = 0x00000000;
114   EXTI->FTSR = 0x00000000;
115   EXTI->PR = 0x007FFFFF;
116 }
117 
118 /**
119   * @brief  Initializes the EXTI peripheral according to the specified
120   *         parameters in the EXTI_InitStruct.
121   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
122   *         that contains the configuration information for the EXTI peripheral.
123   * @retval None
124   */
EXTI_Init(EXTI_InitTypeDef * EXTI_InitStruct)125 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
126 {
127   uint32_t tmp = 0;
128 
129   /* Check the parameters */
130   assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
131   assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
132   assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
133   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
134 
135   tmp = (uint32_t)EXTI_BASE;
136 
137   if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
138   {
139     /* Clear EXTI line configuration */
140     EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
141     EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
142 
143     tmp += EXTI_InitStruct->EXTI_Mode;
144 
145     *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
146 
147     /* Clear Rising Falling edge configuration */
148     EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
149     EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
150 
151     /* Select the trigger for the selected external interrupts */
152     if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
153     {
154       /* Rising Falling edge */
155       EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
156       EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
157     }
158     else
159     {
160       tmp = (uint32_t)EXTI_BASE;
161       tmp += EXTI_InitStruct->EXTI_Trigger;
162 
163       *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
164     }
165   }
166   else
167   {
168     tmp += EXTI_InitStruct->EXTI_Mode;
169 
170     /* Disable the selected external lines */
171     *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
172   }
173 }
174 
175 /**
176   * @brief  Fills each EXTI_InitStruct member with its reset value.
177   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
178   *         be initialized.
179   * @retval None
180   */
EXTI_StructInit(EXTI_InitTypeDef * EXTI_InitStruct)181 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
182 {
183   EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
184   EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
185   EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
186   EXTI_InitStruct->EXTI_LineCmd = DISABLE;
187 }
188 
189 /**
190   * @brief  Generates a Software interrupt on selected EXTI line.
191   * @param  EXTI_Line: specifies the EXTI line on which the software interrupt
192   *         will be generated.
193   *         This parameter can be any combination of EXTI_Linex where x can be (0..22)
194   * @retval None
195   */
EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)196 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
197 {
198   /* Check the parameters */
199   assert_param(IS_EXTI_LINE(EXTI_Line));
200 
201   EXTI->SWIER |= EXTI_Line;
202 }
203 
204 /**
205   * @}
206   */
207 
208 /** @defgroup EXTI_Group2 Interrupts and flags management functions
209  *  @brief   Interrupts and flags management functions
210  *
211 @verbatim
212  ===============================================================================
213              ##### Interrupts and flags management functions #####
214  ===============================================================================
215 
216 @endverbatim
217   * @{
218   */
219 
220 /**
221   * @brief  Checks whether the specified EXTI line flag is set or not.
222   * @param  EXTI_Line: specifies the EXTI line flag to check.
223   *          This parameter can be EXTI_Linex where x can be(0..22)
224   * @retval The new state of EXTI_Line (SET or RESET).
225   */
EXTI_GetFlagStatus(uint32_t EXTI_Line)226 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
227 {
228   FlagStatus bitstatus = RESET;
229   /* Check the parameters */
230   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
231 
232   if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
233   {
234     bitstatus = SET;
235   }
236   else
237   {
238     bitstatus = RESET;
239   }
240   return bitstatus;
241 }
242 
243 /**
244   * @brief  Clears the EXTI's line pending flags.
245   * @param  EXTI_Line: specifies the EXTI lines flags to clear.
246   *          This parameter can be any combination of EXTI_Linex where x can be (0..22)
247   * @retval None
248   */
EXTI_ClearFlag(uint32_t EXTI_Line)249 void EXTI_ClearFlag(uint32_t EXTI_Line)
250 {
251   /* Check the parameters */
252   assert_param(IS_EXTI_LINE(EXTI_Line));
253 
254   EXTI->PR = EXTI_Line;
255 }
256 
257 /**
258   * @brief  Checks whether the specified EXTI line is asserted or not.
259   * @param  EXTI_Line: specifies the EXTI line to check.
260   *          This parameter can be EXTI_Linex where x can be(0..22)
261   * @retval The new state of EXTI_Line (SET or RESET).
262   */
EXTI_GetITStatus(uint32_t EXTI_Line)263 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
264 {
265   FlagStatus bitstatus = RESET;
266   /* Check the parameters */
267   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
268 
269   if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
270   {
271     bitstatus = SET;
272   }
273   else
274   {
275     bitstatus = RESET;
276   }
277   return bitstatus;
278 
279 }
280 
281 /**
282   * @brief  Clears the EXTI's line pending bits.
283   * @param  EXTI_Line: specifies the EXTI lines to clear.
284   *          This parameter can be any combination of EXTI_Linex where x can be (0..22)
285   * @retval None
286   */
EXTI_ClearITPendingBit(uint32_t EXTI_Line)287 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
288 {
289   /* Check the parameters */
290   assert_param(IS_EXTI_LINE(EXTI_Line));
291 
292   EXTI->PR = EXTI_Line;
293 }
294 
295 /**
296   * @}
297   */
298 
299 /**
300   * @}
301   */
302 
303 /**
304   * @}
305   */
306 
307 /**
308   * @}
309   */
310 
311 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
312