]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F3XX/stm32f30x_exti.c
Merge commit '1fe4406f374291ab2e86e95a97341fd9c475fcb8'
[qmk_firmware.git] / tmk_core / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F3XX / stm32f30x_exti.c
1 /**
2   ******************************************************************************
3   * @file    stm32f30x_exti.c
4   * @author  MCD Application Team
5   * @version V1.1.0
6   * @date    27-February-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                           ##### EXTI features #####
15  ===============================================================================
16     [..] External interrupt/event lines are mapped as following:
17          (#) All available GPIO pins are connected to the 16 external 
18              interrupt/event lines from EXTI0 to EXTI15.
19          (#) EXTI line 16 is connected to the PVD output
20          (#) EXTI line 17 is connected to the RTC Alarm event
21          (#) EXTI line 18 is connected to USB Device wakeup event  
22          (#) EXTI line 19 is connected to the RTC Tamper and TimeStamp events
23          (#) EXTI line 20 is connected to the RTC wakeup event  
24          (#) EXTI line 21 is connected to the Comparator 1 wakeup event 
25          (#) EXTI line 22 is connected to the Comparator 2 wakeup event
26          (#) EXTI line 23 is connected to the I2C1 wakeup event
27          (#) EXTI line 24 is connected to the I2C2 wakeup event  
28          (#) EXTI line 25 is connected to the USART1 wakeup event
29          (#) EXTI line 26 is connected to the USART2 wakeup event  
30          (#) EXTI line 27 is reserved
31          (#) EXTI line 28 is connected to the USART3 wakeup event
32          (#) EXTI line 29 is connected to the Comparator 3 event
33          (#) EXTI line 30 is connected to the Comparator 4 event
34          (#) EXTI line 31 is connected to the Comparator 5 event
35          (#) EXTI line 32 is connected to the Comparator 6 event
36          (#) EXTI line 33 is connected to the Comparator 7 event
37          (#) EXTI line 34 is connected for thr UART4 wakeup event
38          (#) EXTI line 35 is connected for the UART5 wakeup event               
39
40                        ##### How to use this driver #####
41  ===============================================================================
42     [..] In order to use an I/O pin as an external interrupt source, 
43          follow steps below:
44          (#) Configure the I/O in input mode using GPIO_Init().
45          (#) Select the input source pin for the EXTI line using
46              SYSCFG_EXTILineConfig().
47          (#) Select the mode(interrupt, event) and configure the trigger 
48              selection (Rising, falling or both) using EXTI_Init(). For the 
49              internal interrupt, the trigger selection is not needed 
50              (the active edge is always the rising one).
51          (#) Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init().
52          (#) Optionally, you can generate a software interrupt using the function 
53              EXTI_GenerateSWInterrupt().
54     [..]
55     (@) SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
56       registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
57                 
58   @endverbatim
59
60   ******************************************************************************
61   * @attention
62   *
63   * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
64   *
65   * Redistribution and use in source and binary forms, with or without modification,
66   * are permitted provided that the following conditions are met:
67   *   1. Redistributions of source code must retain the above copyright notice,
68   *      this list of conditions and the following disclaimer.
69   *   2. Redistributions in binary form must reproduce the above copyright notice,
70   *      this list of conditions and the following disclaimer in the documentation
71   *      and/or other materials provided with the distribution.
72   *   3. Neither the name of STMicroelectronics nor the names of its contributors
73   *      may be used to endorse or promote products derived from this software
74   *      without specific prior written permission.
75   *
76   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
77   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
79   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
80   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
82   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
83   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
84   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
85   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
86   *
87   ******************************************************************************
88   */
89
90 /* Includes ------------------------------------------------------------------*/
91 #include "stm32f30x_exti.h"
92
93 /** @addtogroup STM32F30x_StdPeriph_Driver
94   * @{
95   */
96
97 /** @defgroup EXTI 
98   * @brief EXTI driver modules
99   * @{
100   */
101
102
103 /* Private typedef -----------------------------------------------------------*/
104 /* Private define ------------------------------------------------------------*/
105 #define EXTI_LINENONE     ((uint32_t)0x00000)        /* No interrupt selected */
106
107 /* Private macro -------------------------------------------------------------*/
108 /* Private variables ---------------------------------------------------------*/
109 /* Private function prototypes -----------------------------------------------*/
110 /* Private functions ---------------------------------------------------------*/
111
112 /** @defgroup EXTI_Private_Functions 
113   * @{
114   */
115
116 /** @defgroup EXTI_Group1 Initialization and Configuration functions
117  *  @brief   Initialization and Configuration functions
118  *
119 @verbatim
120  ===============================================================================
121               ##### Initialization and Configuration functions #####
122  ===============================================================================
123
124 @endverbatim
125   * @{
126   */
127     
128 /**
129   * @brief  Deinitializes the EXTI peripheral registers to their default reset 
130   *         values.
131   * @param  None
132   * @retval None
133   */
134 void EXTI_DeInit(void)
135 {
136   EXTI->IMR    = 0x1F800000;
137   EXTI->EMR    = 0x00000000;
138   EXTI->RTSR   = 0x00000000;
139   EXTI->FTSR   = 0x00000000;
140   EXTI->SWIER  = 0x00000000;
141   EXTI->PR     = 0xE07FFFFF;
142   EXTI->IMR2   = 0x0000000C;
143   EXTI->EMR2   = 0x00000000;
144   EXTI->RTSR2  = 0x00000000;
145   EXTI->FTSR2  = 0x00000000;
146   EXTI->SWIER2 = 0x00000000;
147   EXTI->PR2    = 0x00000003;
148 }
149
150 /**
151   * @brief  Initializes the EXTI peripheral according to the specified
152   *         parameters in the EXTI_InitStruct.
153   *    EXTI_Line specifies the EXTI line (EXTI0....EXTI35).
154   *    EXTI_Mode specifies which EXTI line is used as interrupt or an event.
155   *    EXTI_Trigger selects the trigger. When the trigger occurs, interrupt
156   *                 pending bit will be set.
157   *    EXTI_LineCmd controls (Enable/Disable) the EXTI line.
158   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure that 
159   *         contains the configuration information for the EXTI peripheral.
160   * @retval None
161   */
162   
163
164 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
165 {
166   uint32_t tmp = 0;
167
168   /* Check the parameters */
169   assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
170   assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
171   assert_param(IS_EXTI_LINE_ALL(EXTI_InitStruct->EXTI_Line));
172   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
173
174   tmp = (uint32_t)EXTI_BASE;
175       
176   if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
177   {
178     /* Clear EXTI line configuration */   
179     *(__IO uint32_t *) (((uint32_t) &(EXTI->IMR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));   
180     *(__IO uint32_t *) (((uint32_t) &(EXTI->EMR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
181      
182     tmp += EXTI_InitStruct->EXTI_Mode + (((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20);
183
184     *(__IO uint32_t *) tmp |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
185     
186     tmp = (uint32_t)EXTI_BASE;
187
188     /* Clear Rising Falling edge configuration */
189     *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
190     *(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
191     
192       /* Select the trigger for the selected interrupts */
193     if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
194     {
195       /* Rising Falling edge */
196     *(__IO uint32_t *) (((uint32_t) &(EXTI->RTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
197     *(__IO uint32_t *) (((uint32_t) &(EXTI->FTSR)) + ((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));      
198     }
199     else
200     {
201       tmp += EXTI_InitStruct->EXTI_Trigger + (((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20);
202
203       *(__IO uint32_t *) tmp |= (uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
204     }
205   }
206       
207   else
208   {
209     tmp += EXTI_InitStruct->EXTI_Mode + (((EXTI_InitStruct->EXTI_Line) >> 5 ) * 0x20);
210
211     /* Disable the selected external lines */
212     *(__IO uint32_t *) tmp &= ~(uint32_t)(1 << (EXTI_InitStruct->EXTI_Line & 0x1F));
213   }
214          
215 }
216
217 /**
218   * @brief  Fills each EXTI_InitStruct member with its reset value.
219   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
220   *         be initialized.
221   * @retval None
222   */
223 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
224 {
225   EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
226   EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
227   EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Rising_Falling;
228   EXTI_InitStruct->EXTI_LineCmd = DISABLE;
229 }
230
231 /**
232   * @brief  Generates a Software interrupt on selected EXTI line.
233   * @param  EXTI_Line: specifies the EXTI line on which the software interrupt
234   *         will be generated.
235   *   This parameter can be any combination of EXTI_Linex where x can be (0..20).
236   * @retval None
237   */
238 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
239 {
240   /* Check the parameters */
241   assert_param(IS_EXTI_LINE_EXT(EXTI_Line));
242
243   *(__IO uint32_t *) (((uint32_t) &(EXTI->SWIER)) + ((EXTI_Line) >> 5 ) * 0x20) |= (uint32_t)(1 << (EXTI_Line & 0x1F));
244
245 }
246
247 /**
248   * @}
249   */
250   
251 /** @defgroup EXTI_Group2 Interrupts and flags management functions
252  *  @brief    EXTI Interrupts and flags management functions
253  *
254 @verbatim  
255  ===============================================================================
256               ##### Interrupts and flags management functions #####
257  ===============================================================================
258     [..]
259     This section provides functions allowing to configure the EXTI Interrupts 
260     sources and check or clear the flags or pending bits status.
261     
262 @endverbatim
263   * @{
264   */
265
266 /**
267   * @brief  Checks whether the specified EXTI line flag is set or not.
268   * @param  EXTI_Line: specifies the EXTI line flag to check.
269   *   This parameter can be any combination of EXTI_Linex where x can be (0..20).
270   * @retval The new state of EXTI_Line (SET or RESET).                  
271   */
272 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
273 {
274   FlagStatus bitstatus = RESET;
275   
276   /* Check the parameters */
277   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
278    
279   if ((*(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20)& (uint32_t)(1 << (EXTI_Line & 0x1F))) != (uint32_t)RESET)
280   {
281     bitstatus = SET;
282   }
283   else
284   {
285     bitstatus = RESET;
286   }
287   return bitstatus;
288 }
289
290 /**
291   * @brief  Clears the EXTI's line pending flags.
292   * @param  EXTI_Line: specifies the EXTI lines flags to clear.
293   *   This parameter can be any combination of EXTI_Linex where x can be (0..20).
294   * @retval None
295   */
296 void EXTI_ClearFlag(uint32_t EXTI_Line)
297 {
298   /* Check the parameters */
299   assert_param(IS_EXTI_LINE_EXT(EXTI_Line));
300
301   *(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20) = (1 << (EXTI_Line & 0x1F));  
302 }
303
304 /**
305   * @brief  Checks whether the specified EXTI line is asserted or not.
306   * @param  EXTI_Line: specifies the EXTI line to check.
307   *   This parameter can be any combination of EXTI_Linex where x can be (0..20).
308   * @retval The new state of EXTI_Line (SET or RESET).
309   */
310 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
311 {
312   ITStatus bitstatus = RESET;
313   
314   /* Check the parameters */
315   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
316   
317   if ((*(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20)& (uint32_t)(1 << (EXTI_Line & 0x1F))) != (uint32_t)RESET)
318   {
319     bitstatus = SET;
320   }
321   else
322   {
323     bitstatus = RESET;
324   }
325   return bitstatus;
326   
327 }
328
329 /**
330   * @brief  Clears the EXTI's line pending bits.
331   * @param  EXTI_Line: specifies the EXTI lines to clear.
332   *   This parameter can be any combination of EXTI_Linex where x can be (0..20).
333   * @retval None
334   */
335 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
336 {
337   /* Check the parameters */
338   assert_param(IS_EXTI_LINE_EXT(EXTI_Line));
339   
340   *(__IO uint32_t *) (((uint32_t) &(EXTI->PR)) + ((EXTI_Line) >> 5 ) * 0x20) = (1 << (EXTI_Line & 0x1F));
341 }
342
343 /**
344   * @}
345   */
346
347 /**
348   * @}
349   */
350
351 /**
352   * @}
353   */
354
355 /**
356   * @}
357   */
358
359 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/