1 /**
2 ******************************************************************************
3 * @file    HAL_exti.c
4 * @author  AE Team
5 * @version V1.0.0
6 * @date    28/7/2017
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, MindMotion 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>&copy; COPYRIGHT 2017 MindMotion</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)85 void 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)102 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
103 {
104     /* Check the parameters */
105     assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
106     assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
107     assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
108     assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
109 
110     if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
111     {
112         /* Clear EXTI line configuration */
113         EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
114         EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
115 
116         *(__IO uint32_t *)(EXTI_BASE + (uint32_t)EXTI_InitStruct->EXTI_Mode)|= EXTI_InitStruct->EXTI_Line;
117         /* Clear Rising Falling edge configuration */
118         EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
119         EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
120 
121         /* Select the trigger for the selected external interrupts */
122         if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
123         {
124             /* Rising Falling edge */
125             EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
126             EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
127         }
128         else
129         {
130             *(__IO uint32_t *)(EXTI_BASE + (uint32_t)EXTI_InitStruct->EXTI_Trigger)|= EXTI_InitStruct->EXTI_Line;
131         }
132     }
133     else
134     {
135         /* Disable the selected external lines */
136         *(__IO uint32_t *)(EXTI_BASE + (uint32_t)EXTI_InitStruct->EXTI_Mode)&= ~EXTI_InitStruct->EXTI_Line;
137     }
138 }
139 
140 /**
141 * @brief  Fills each EXTI_InitStruct member with its reset value.
142 * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
143 *   which will be initialized.
144 * @retval : None
145 */
EXTI_StructInit(EXTI_InitTypeDef * EXTI_InitStruct)146 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
147 {
148     EXTI_InitStruct->EXTI_Line = EXTI_LineNone;
149     EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
150     EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
151     EXTI_InitStruct->EXTI_LineCmd = DISABLE;
152 }
153 
154 /**
155 * @brief  Generates a Software interrupt.
156 * @param EXTI_Line: specifies the EXTI lines to be enabled or
157 *   disabled.
158 *   This parameter can be any combination of EXTI_Linex where
159 *   x can be (0..18).
160 * @retval : None
161 */
EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)162 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
163 {
164     /* Check the parameters */
165     assert_param(IS_EXTI_LINE(EXTI_Line));
166 
167     EXTI->SWIER |= EXTI_Line;
168 }
169 
170 /**
171 * @brief  Checks whether the specified EXTI line flag is set or not.
172 * @param EXTI_Line: specifies the EXTI line flag to check.
173 *   This parameter can be:
174 * @arg EXTI_Linex: External interrupt line x where x(0..18)
175 * @retval : The new state of EXTI_Line (SET or RESET).
176 */
EXTI_GetFlagStatus(uint32_t EXTI_Line)177 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
178 {
179     FlagStatus bitstatus = RESET;
180     /* Check the parameters */
181     assert_param(IS_GET_EXTI_LINE(EXTI_Line));
182 
183     if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
184     {
185         bitstatus = SET;
186     }
187     else
188     {
189         bitstatus = RESET;
190     }
191     return bitstatus;
192 }
193 
194 /**
195 * @brief  Clears the EXTI�s line pending flags.
196 * @param EXTI_Line: specifies the EXTI lines flags to clear.
197 *   This parameter can be any combination of EXTI_Linex where
198 *   x can be (0..18).
199 * @retval : None
200 */
EXTI_ClearFlag(uint32_t EXTI_Line)201 void EXTI_ClearFlag(uint32_t EXTI_Line)
202 {
203     /* Check the parameters */
204     assert_param(IS_EXTI_LINE(EXTI_Line));
205 
206     EXTI->PR = EXTI_Line;
207 }
208 
209 /**
210 * @brief  Checks whether the specified EXTI line is asserted or not.
211 * @param EXTI_Line: specifies the EXTI line to check.
212 *   This parameter can be:
213 * @arg EXTI_Linex: External interrupt line x where x(0..18)
214 * @retval : The new state of EXTI_Line (SET or RESET).
215 */
EXTI_GetITStatus(uint32_t EXTI_Line)216 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
217 {
218     ITStatus bitstatus = RESET;
219     uint32_t enablestatus = 0;
220     /* Check the parameters */
221     assert_param(IS_GET_EXTI_LINE(EXTI_Line));
222 
223     enablestatus =  EXTI->IMR & EXTI_Line;
224     if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
225     {
226         bitstatus = SET;
227     }
228     else
229     {
230         bitstatus = RESET;
231     }
232     return bitstatus;
233 }
234 
235 /**
236 * @brief  Clears the EXTI�s line pending bits.
237 * @param EXTI_Line: specifies the EXTI lines to clear.
238 *   This parameter can be any combination of EXTI_Linex where
239 *   x can be (0..18).
240 * @retval : None
241 */
EXTI_ClearITPendingBit(uint32_t EXTI_Line)242 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
243 {
244     /* Check the parameters */
245     assert_param(IS_EXTI_LINE(EXTI_Line));
246 
247     EXTI->PR = EXTI_Line;
248 }
249 
250 /**
251 * @}
252 */
253 
254 /**
255 * @}
256 */
257 
258 /**
259 * @}
260 */
261 
262 /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/
263