1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_ll_exti.c
4   * @author  MCD Application Team
5   * @brief   EXTI LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35 #if defined(USE_FULL_LL_DRIVER)
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f0xx_ll_exti.h"
39 #ifdef  USE_FULL_ASSERT
40 #include "stm32_assert.h"
41 #else
42 #define assert_param(expr) ((void)0U)
43 #endif
44 
45 /** @addtogroup STM32F0xx_LL_Driver
46   * @{
47   */
48 
49 #if defined (EXTI)
50 
51 /** @defgroup EXTI_LL EXTI
52   * @{
53   */
54 
55 /* Private types -------------------------------------------------------------*/
56 /* Private variables ---------------------------------------------------------*/
57 /* Private constants ---------------------------------------------------------*/
58 /* Private macros ------------------------------------------------------------*/
59 /** @addtogroup EXTI_LL_Private_Macros
60   * @{
61   */
62 
63 #define IS_LL_EXTI_LINE_0_31(__VALUE__)              (((__VALUE__) & ~LL_EXTI_LINE_ALL_0_31) == 0x00000000U)
64 
65 #define IS_LL_EXTI_MODE(__VALUE__)                   (((__VALUE__) == LL_EXTI_MODE_IT)            \
66                                                    || ((__VALUE__) == LL_EXTI_MODE_EVENT)         \
67                                                    || ((__VALUE__) == LL_EXTI_MODE_IT_EVENT))
68 
69 
70 #define IS_LL_EXTI_TRIGGER(__VALUE__)                (((__VALUE__) == LL_EXTI_TRIGGER_NONE)       \
71                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING)     \
72                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING)    \
73                                                    || ((__VALUE__) == LL_EXTI_TRIGGER_RISING_FALLING))
74 
75 /**
76   * @}
77   */
78 
79 /* Private function prototypes -----------------------------------------------*/
80 
81 /* Exported functions --------------------------------------------------------*/
82 /** @addtogroup EXTI_LL_Exported_Functions
83   * @{
84   */
85 
86 /** @addtogroup EXTI_LL_EF_Init
87   * @{
88   */
89 
90 /**
91   * @brief  De-initialize the EXTI registers to their default reset values.
92   * @retval An ErrorStatus enumeration value:
93   *          - SUCCESS: EXTI registers are de-initialized
94   *          - ERROR: not applicable
95   */
LL_EXTI_DeInit(void)96 uint32_t LL_EXTI_DeInit(void)
97 {
98   /* Interrupt mask register set to default reset values */
99 #if defined(STM32F030x6) || defined(STM32F031x6) ||defined(STM32F038xx)
100   LL_EXTI_WriteReg(IMR,   0x0FF40000U);
101 #elif defined(STM32F070x6) || defined(STM32F042x6) || defined(STM32F048xx)
102   LL_EXTI_WriteReg(IMR,   0x7FF40000U);
103 #elif defined(STM32F030x8) || defined(STM32F051x8) || defined(STM32F058xx)
104   LL_EXTI_WriteReg(IMR,   0x0F940000U);
105 #else
106   LL_EXTI_WriteReg(IMR,   0x7F840000U);
107 #endif
108   /* Event mask register set to default reset values */
109   LL_EXTI_WriteReg(EMR,   0x00000000U);
110   /* Rising Trigger selection register set to default reset values */
111   LL_EXTI_WriteReg(RTSR,  0x00000000U);
112   /* Falling Trigger selection register set to default reset values */
113   LL_EXTI_WriteReg(FTSR,  0x00000000U);
114   /* Software interrupt event register set to default reset values */
115   LL_EXTI_WriteReg(SWIER, 0x00000000U);
116   /* Pending register clear */
117   LL_EXTI_WriteReg(PR,    0x007BFFFFU);
118 
119   return SUCCESS;
120 }
121 
122 /**
123   * @brief  Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
124   * @param  EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
125   * @retval An ErrorStatus enumeration value:
126   *          - SUCCESS: EXTI registers are initialized
127   *          - ERROR: not applicable
128   */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)129 uint32_t LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
130 {
131   ErrorStatus status = SUCCESS;
132   /* Check the parameters */
133   assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
134   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
135   assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
136 
137   /* ENABLE LineCommand */
138   if (EXTI_InitStruct->LineCommand != DISABLE)
139   {
140     assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
141 
142     /* Configure EXTI Lines in range from 0 to 31 */
143     if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
144     {
145       switch (EXTI_InitStruct->Mode)
146       {
147         case LL_EXTI_MODE_IT:
148           /* First Disable Event on provided Lines */
149           LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
150           /* Then Enable IT on provided Lines */
151           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
152           break;
153         case LL_EXTI_MODE_EVENT:
154           /* First Disable IT on provided Lines */
155           LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
156           /* Then Enable Event on provided Lines */
157           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
158           break;
159         case LL_EXTI_MODE_IT_EVENT:
160           /* Directly Enable IT & Event on provided Lines */
161           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
162           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
163           break;
164         default:
165           status = ERROR;
166           break;
167       }
168       if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
169       {
170         switch (EXTI_InitStruct->Trigger)
171         {
172           case LL_EXTI_TRIGGER_RISING:
173             /* First Disable Falling Trigger on provided Lines */
174             LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
175             /* Then Enable Rising Trigger on provided Lines */
176             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
177             break;
178           case LL_EXTI_TRIGGER_FALLING:
179             /* First Disable Rising Trigger on provided Lines */
180             LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
181             /* Then Enable Falling Trigger on provided Lines */
182             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
183             break;
184           case LL_EXTI_TRIGGER_RISING_FALLING:
185             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
186             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
187             break;
188           default:
189             status = ERROR;
190             break;
191         }
192       }
193     }
194   }
195   /* DISABLE LineCommand */
196   else
197   {
198     /* De-configure EXTI Lines in range from 0 to 31 */
199     LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
200     LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
201   }
202   return status;
203 }
204 
205 /**
206   * @brief  Set each @ref LL_EXTI_InitTypeDef field to default value.
207   * @param  EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
208   * @retval None
209   */
LL_EXTI_StructInit(LL_EXTI_InitTypeDef * EXTI_InitStruct)210 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
211 {
212   EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_NONE;
213   EXTI_InitStruct->LineCommand    = DISABLE;
214   EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
215   EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;
216 }
217 
218 /**
219   * @}
220   */
221 
222 /**
223   * @}
224   */
225 
226 /**
227   * @}
228   */
229 
230 #endif /* defined (EXTI) */
231 
232 /**
233   * @}
234   */
235 
236 #endif /* USE_FULL_LL_DRIVER */
237 
238 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
239