1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_ll_exti.c
4   * @author  MCD Application Team
5   * @brief   EXTI LL module driver.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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 "stm32wbaxx_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 STM32WBAxx_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,   0xFF9E0000U);
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 #if defined(EXTI_PRIVCFGR1_PRIV0)
95   /* Privilege register set to default reset values */
96   LL_EXTI_WriteReg(PRIVCFGR1,  0x00000000U);
97 #endif /* EXTI_PRIVCFGR1_PRIV0 */
98 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
99   /* Secure register set to default reset values */
100   LL_EXTI_WriteReg(SECCFGR1,  0x00000000U);
101 #endif /* __ARM_FEATURE_CMSE */
102   return SUCCESS;
103 }
104 
105 /**
106   * @brief  Initialize the EXTI registers according to the specified parameters in EXTI_InitStruct.
107   * @param  EXTI_InitStruct pointer to a @ref LL_EXTI_InitTypeDef structure.
108   * @retval An ErrorStatus enumeration value:
109   *          - SUCCESS: EXTI registers are initialized
110   *          - ERROR: not applicable
111   */
LL_EXTI_Init(LL_EXTI_InitTypeDef * EXTI_InitStruct)112 ErrorStatus LL_EXTI_Init(LL_EXTI_InitTypeDef *EXTI_InitStruct)
113 {
114   ErrorStatus status = SUCCESS;
115   /* Check the parameters */
116   assert_param(IS_LL_EXTI_LINE_0_31(EXTI_InitStruct->Line_0_31));
117   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->LineCommand));
118   assert_param(IS_LL_EXTI_MODE(EXTI_InitStruct->Mode));
119 
120   /* ENABLE LineCommand */
121   if (EXTI_InitStruct->LineCommand != DISABLE)
122   {
123     assert_param(IS_LL_EXTI_TRIGGER(EXTI_InitStruct->Trigger));
124 
125     /* Configure EXTI Lines in range from 0 to 31 */
126     if (EXTI_InitStruct->Line_0_31 != LL_EXTI_LINE_NONE)
127     {
128       switch (EXTI_InitStruct->Mode)
129       {
130         case LL_EXTI_MODE_IT:
131           /* First Disable Event on provided Lines */
132           LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
133           /* Then Enable IT on provided Lines */
134           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
135           break;
136         case LL_EXTI_MODE_EVENT:
137           /* First Disable IT on provided Lines */
138           LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
139           /* Then Enable Event on provided Lines */
140           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
141           break;
142         case LL_EXTI_MODE_IT_EVENT:
143           /* Directly Enable IT & Event on provided Lines */
144           LL_EXTI_EnableIT_0_31(EXTI_InitStruct->Line_0_31);
145           LL_EXTI_EnableEvent_0_31(EXTI_InitStruct->Line_0_31);
146           break;
147         default:
148           status = ERROR;
149           break;
150       }
151       if (EXTI_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
152       {
153         switch (EXTI_InitStruct->Trigger)
154         {
155           case LL_EXTI_TRIGGER_RISING:
156             /* First Disable Falling Trigger on provided Lines */
157             LL_EXTI_DisableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
158             /* Then Enable Rising Trigger on provided Lines */
159             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
160             break;
161           case LL_EXTI_TRIGGER_FALLING:
162             /* First Disable Rising Trigger on provided Lines */
163             LL_EXTI_DisableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
164             /* Then Enable Falling Trigger on provided Lines */
165             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
166             break;
167           case LL_EXTI_TRIGGER_RISING_FALLING:
168             LL_EXTI_EnableRisingTrig_0_31(EXTI_InitStruct->Line_0_31);
169             LL_EXTI_EnableFallingTrig_0_31(EXTI_InitStruct->Line_0_31);
170             break;
171           default:
172             status = ERROR;
173             break;
174         }
175       }
176     }
177   }
178   /* DISABLE LineCommand */
179   else
180   {
181     /* De-configure EXTI Lines in range from 0 to 31 */
182     LL_EXTI_DisableIT_0_31(EXTI_InitStruct->Line_0_31);
183     LL_EXTI_DisableEvent_0_31(EXTI_InitStruct->Line_0_31);
184   }
185   return status;
186 }
187 
188 /**
189   * @brief  Set each @ref LL_EXTI_InitTypeDef field to default value.
190   * @param  EXTI_InitStruct Pointer to a @ref LL_EXTI_InitTypeDef structure.
191   * @retval None
192   */
LL_EXTI_StructInit(LL_EXTI_InitTypeDef * EXTI_InitStruct)193 void LL_EXTI_StructInit(LL_EXTI_InitTypeDef *EXTI_InitStruct)
194 {
195   EXTI_InitStruct->Line_0_31      = LL_EXTI_LINE_NONE;
196   EXTI_InitStruct->LineCommand    = DISABLE;
197   EXTI_InitStruct->Mode           = LL_EXTI_MODE_IT;
198   EXTI_InitStruct->Trigger        = LL_EXTI_TRIGGER_FALLING;
199 }
200 
201 /**
202   * @}
203   */
204 
205 /**
206   * @}
207   */
208 
209 /**
210   * @}
211   */
212 
213 #endif /* defined (EXTI) */
214 
215 /**
216   * @}
217   */
218 
219 #endif /* USE_FULL_LL_DRIVER */
220 
221