1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_ll_exti.c
4   * @author  MCD Application Team
5   * @brief   EXTI LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 #if defined(USE_FULL_LL_DRIVER)
20 
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32f0xx_ll_exti.h"
23 #ifdef  USE_FULL_ASSERT
24 #include "stm32_assert.h"
25 #else
26 #define assert_param(expr) ((void)0U)
27 #endif
28 
29 /** @addtogroup STM32F0xx_LL_Driver
30   * @{
31   */
32 
33 #if defined (EXTI)
34 
35 /** @defgroup EXTI_LL EXTI
36   * @{
37   */
38 
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
43 /** @addtogroup EXTI_LL_Private_Macros
44   * @{
45   */
46 
47 #define IS_LL_EXTI_LINE_0_31(__VALUE__)              (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
48 
49 #define IS_LL_EXTI_MODE(__VALUE__)                   (((__VALUE__) == LL_EXTI_MODE_IT)            \
50                                                    || ((__VALUE__) == LL_EXTI_MODE_EVENT)         \
51                                                    || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
52 
53 
54 #define IS_LL_EXTI_TRIGGER(__VALUE__)                (((__VALUE__) == LL_EXTI_TRIGGER_NONE)       \
55                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING)     \
56                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING)    \
57                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
58 
59 /**
60   * @}
61   */
62 
63 /* Private function prototypes -----------------------------------------------*/
64 
65 /* Exported functions --------------------------------------------------------*/
66 /** @addtogroup EXTI_LL_Exported_Functions
67   * @{
68   */
69 
70 /** @addtogroup EXTI_LL_EF_Init
71   * @{
72   */
73 
74 /**
75   * @brief  De-initialize the EXTI registers to their default reset values.
76   * @retval An ErrorStatus enumeration value:
77   *          - SUCCESS: EXTI registers are de-initialized
78   *          - ERROR: not applicable
79   */
LL_EXTI_DeInit(void)80 uint32_t LL_EXTI_DeInit(void)
81 {
82   /* Interrupt mask register set to default reset values */
83 #if defined(STM32F030x6) || defined(STM32F031x6) ||defined(STM32F038xx)
84   LL_EXTI_WriteReg(IMR,   0x0FF40000U);
85 #elif defined(STM32F070x6) || defined(STM32F042x6) || defined(STM32F048xx)
86   LL_EXTI_WriteReg(IMR,   0x7FF40000U);
87 #elif defined(STM32F030x8) || defined(STM32F051x8) || defined(STM32F058xx)
88   LL_EXTI_WriteReg(IMR,   0x0F940000U);
89 #else
90   LL_EXTI_WriteReg(IMR,   0x7F840000U);
91 #endif
92   /* Event mask register set to default reset values */
93   LL_EXTI_WriteReg(EMR,   0x00000000U);
94   /* Rising Trigger selection register set to default reset values */
95   LL_EXTI_WriteReg(RTSR,  0x00000000U);
96   /* Falling Trigger selection register set to default reset values */
97   LL_EXTI_WriteReg(FTSR,  0x00000000U);
98   /* Software interrupt event register set to default reset values */
99   LL_EXTI_WriteReg(SWIER, 0x00000000U);
100   /* Pending register clear */
101   LL_EXTI_WriteReg(PR,    0x007BFFFFU);
102 
103   return SUCCESS;
104 }
105 
106 /**
107   * @brief  Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
108   * @param  EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
109   * @retval An ErrorStatus enumeration value:
110   *          - SUCCESS: EXTI registers are initialized
111   *          - ERROR: not applicable
112   */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)113 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
114 {
115   ErrorStatus status = SUCCESS;
116   /* Check the parameters */
117   assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
118   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
119   assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
120 
121   /* ENABLE LineCommand */
122   if (EXTI_InitStruct->LineCommand != DISABLE)
123   {
124     assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
125 
126     /* Configure EXTI Lines in range from 0 to 31 */
127     if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
128     {
129       switch (EXTI_InitStruct->Mode)
130       {
131         case LL_EXTI_MODE_IT:
132           /* First Disable Event on provided Lines */
133           LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
134           /* Then Enable IT on provided Lines */
135           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
136           break;
137         case LL_EXTI_MODE_EVENT:
138           /* First Disable IT on provided Lines */
139           LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
140           /* Then Enable Event on provided Lines */
141           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
142           break;
143         case LL_EXTI_MODE_IT_EVENT:
144           /* Directly Enable IT & Event on provided Lines */
145           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
146           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
147           break;
148         default:
149           status = ERROR;
150           break;
151       }
152       if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
153       {
154         switch (EXTI_InitStruct->Trigger)
155         {
156           case LL_EXTI_TRIGGER_RISING:
157             /* First Disable Falling Trigger on provided Lines */
158             LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
159             /* Then Enable Rising Trigger on provided Lines */
160             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
161             break;
162           case LL_EXTI_TRIGGER_FALLING:
163             /* First Disable Rising Trigger on provided Lines */
164             LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
165             /* Then Enable Falling Trigger on provided Lines */
166             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
167             break;
168           case LL_EXTI_TRIGGER_RISING_FALLING:
169             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
170             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
171             break;
172           default:
173             status = ERROR;
174             break;
175         }
176       }
177     }
178   }
179   /* DISABLE LineCommand */
180   else
181   {
182     /* De-configure EXTI Lines in range from 0 to 31 */
183     LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
184     LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
185   }
186   return status;
187 }
188 
189 /**
190   * @brief  Set each @ref LL_EXTI_InitTypeDef field to default value.
191   * @param  EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
192   * @retval None
193   */
LL_EXTI_StructInit(LL_EXTI_InitTypeDef * EXTI_InitStruct)194 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
195 {
196   EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_NONE;
197   EXTI_InitStruct->LineCommand    = DISABLE;
198   EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
199   EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;
200 }
201 
202 /**
203   * @}
204   */
205 
206 /**
207   * @}
208   */
209 
210 /**
211   * @}
212   */
213 
214 #endif /* defined (EXTI) */
215 
216 /**
217   * @}
218   */
219 
220 #endif /* USE_FULL_LL_DRIVER */
221 
222