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