1 /**
2   ******************************************************************************
3   * @file    stm32wb0x_ll_system.c
4   * @author  MCD Application Team
5   * @brief   HAL module driver.
6   *          This is the common part of the HAL initialization
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2024 STMicroelectronics.
11   * All rights reserved.
12   *
13   * This software is licensed under terms that can be found in the LICENSE file
14   * in the root directory of this software component.
15   * If no LICENSE file comes with this software, it is provided AS-IS.
16   *
17   ******************************************************************************
18   @verbatim
19   ==============================================================================
20                      ##### How to use this driver #####
21   ==============================================================================
22     [..]
23     The common HAL driver contains a set of generic and common APIs that can be
24     used by the PPP peripheral drivers and the user to start using the HAL.
25     [..]
26     The HAL contains two APIs' categories:
27          (+) Common HAL APIs
28          (+) Services HAL APIs
29 
30   @endverbatim
31   ******************************************************************************
32   */
33 
34 #if defined(USE_FULL_LL_DRIVER)
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "stm32wb0x_ll_system.h"
38 #ifdef  USE_FULL_ASSERT
39 #include "stm32_assert.h"
40 #else
41 #define assert_param(expr) ((void)0U)
42 #endif
43 
44 /** @addtogroup STM32WB0x_LL_Driver
45   * @{
46   */
47 
48 #if defined (SYSCFG)
49 /** @addtogroup SYSTEM_LL
50   * @{
51   */
52 
53 
54 /* Private types -------------------------------------------------------------*/
55 /* Private variables ---------------------------------------------------------*/
56 /* Private constants ---------------------------------------------------------*/
57 /* Private macros ------------------------------------------------------------*/
58 /** @addtogroup EXTI_Private_Macros
59   * @{
60   */
61 
62 #define IS_LL_EXTI_LINE(__VALUE__)              (((__VALUE__) & ~LL_EXTI_LINE_ALL) == 0x00000000U)
63 
64 #define IS_LL_EXTI_TYPE(__VALUE__)                   (((__VALUE__) == LL_EXTI_TYPE_EDGE)            \
65                                                       || ((__VALUE__) == LL_EXTI_TYPE_LEVEL))
66 
67 
68 #define IS_LL_EXTI_TRIGGER(__VALUE__)                (((__VALUE__) == LL_EXTI_TRIGGER_RISING_EDGE)  \
69                                                       || ((__VALUE__) == LL_EXTI_TRIGGER_FALLING_EDGE) \
70                                                       || ((__VALUE__) == LL_EXTI_TRIGGER_BOTH_EDGE)    \
71                                                       || ((__VALUE__) == LL_EXTI_TRIGGER_LOW_LEVEL)    \
72                                                       || ((__VALUE__) == LL_EXTI_TRIGGER_HIGH_LEVEL))
73 
74 /**
75   * @}
76   */
77 
78 /* Private function prototypes -----------------------------------------------*/
79 
80 /* Exported functions --------------------------------------------------------*/
81 
82 /** @addtogroup SYSCFG_IO_LL_EF_Init
83   * @{
84   */
85 
86 /**
87   * @brief  De-initialize the SYSCFG_IO registers to their default reset values.
88   * @retval An ErrorStatus enumeration value:
89   *          - SUCCESS: SYSCFG_IO registers are de-initialized
90   *          - ERROR: not applicable
91   */
LL_SYSCFG_IO_DeInit(void)92 ErrorStatus LL_SYSCFG_IO_DeInit(void)
93 {
94   /* I/O Interrupt detection type register set to default reset values */
95   LL_SYSCFG_WriteReg(IO_DTR,  0x00000000U);
96 
97   /* I/O Interrupt Edge register set to default reset values */
98   LL_SYSCFG_WriteReg(IO_IBER,  0x00000000U);
99 
100   /* I/O Interrupt polarity event register set to default reset values */
101   LL_SYSCFG_WriteReg(IO_IEVR, 0x00000000U);
102 
103   /* I/O Interrupt Enable register set to default reset values */
104   LL_SYSCFG_WriteReg(IO_IER, 0x00000000U);
105 
106   /* Clear all the I/O Interrupt */
107   LL_SYSCFG_WriteReg(IO_ISCR, LL_EXTI_LINE_ALL);
108 
109   return SUCCESS;
110 }
111 
112 /**
113   * @brief  Initialize the SYSCFG_IO registers according to the specified parameters in SYSCFG_IO_InitStruct.
114   * @param  SYSCFG_IO_InitStruct pointer to a @ref LL_SYSCFG_IO_InitTypeDef structure.
115   * @retval An ErrorStatus enumeration value:
116   *          - SUCCESS: SYSCFG_IO registers are initialized
117   *          - ERROR: not applicable
118   */
LL_SYSCFG_IO_Init(LL_SYSCFG_IO_InitTypeDef * SYSCFG_IO_InitStruct)119 ErrorStatus LL_SYSCFG_IO_Init(LL_SYSCFG_IO_InitTypeDef *SYSCFG_IO_InitStruct)
120 {
121   ErrorStatus status = SUCCESS;
122   /* Check the parameters */
123   assert_param(IS_LL_EXTI_LINE(SYSCFG_IO_InitStruct->Line));
124   assert_param(IS_FUNCTIONAL_STATE(SYSCFG_IO_InitStruct->LineCommand));
125   assert_param(IS_LL_EXTI_TYPE(SYSCFG_IO_InitStruct->Type));
126 
127   /* ENABLE LineCommand */
128   if (SYSCFG_IO_InitStruct->LineCommand != DISABLE)
129   {
130     assert_param(IS_LL_EXTI_TRIGGER(SYSCFG_IO_InitStruct->Trigger));
131 
132     /* Configure SYSCFG IO Lines in range from PA0 to PB15 */
133     if (SYSCFG_IO_InitStruct->Line != LL_EXTI_LINE_NONE)
134     {
135       /* Set the IT Type on provided Lines */
136       LL_EXTI_EnableEdgeDetection(SYSCFG_IO_InitStruct->Line);
137 
138       if (SYSCFG_IO_InitStruct->Trigger != LL_EXTI_TRIGGER_NONE)
139       {
140         switch (SYSCFG_IO_InitStruct->Trigger)
141         {
142           case LL_EXTI_TRIGGER_RISING_EDGE:
143             LL_EXTI_EnableEdgeDetection(SYSCFG_IO_InitStruct->Line);
144             LL_EXTI_EnableRisingTrig(SYSCFG_IO_InitStruct->Line);
145             break;
146           case LL_EXTI_TRIGGER_FALLING_EDGE:
147             LL_EXTI_EnableEdgeDetection(SYSCFG_IO_InitStruct->Line);
148             LL_EXTI_DisableRisingTrig(SYSCFG_IO_InitStruct->Line);
149             break;
150           case LL_EXTI_TRIGGER_BOTH_EDGE:
151             LL_EXTI_EnableEdgeDetection(SYSCFG_IO_InitStruct->Line);
152             LL_EXTI_EnableBothEdgeTrig(SYSCFG_IO_InitStruct->Line);
153             break;
154           case LL_EXTI_TRIGGER_LOW_LEVEL:
155             LL_EXTI_DisableEdgeDetection(SYSCFG_IO_InitStruct->Line);
156             LL_EXTI_DisableRisingTrig(SYSCFG_IO_InitStruct->Line);
157             break;
158           case LL_EXTI_TRIGGER_HIGH_LEVEL:
159             LL_EXTI_DisableEdgeDetection(SYSCFG_IO_InitStruct->Line);
160             LL_EXTI_EnableRisingTrig(SYSCFG_IO_InitStruct->Line);
161             break;
162           default:
163             status = ERROR;
164             break;
165         }
166         LL_EXTI_EnableIT(SYSCFG_IO_InitStruct->Line);
167         LL_EXTI_ClearFlag(SYSCFG_IO_InitStruct->Line);
168       }
169     }
170     /* DISABLE LineCommand */
171     else
172     {
173       LL_EXTI_DisableIT(SYSCFG_IO_InitStruct->Line);
174     }
175   }
176   return status;
177 }
178 
179 /**
180   * @brief  Set each @ref LL_SYSCFG_IO_InitTypeDef field to default value.
181   * @param  SYSCFG_IO_InitStruct Pointer to a @ref LL_SYSCFG_IO_InitTypeDef structure.
182   * @retval None
183   */
LL_SYSCFG_IO_StructInit(LL_SYSCFG_IO_InitTypeDef * SYSCFG_IO_InitStruct)184 void LL_SYSCFG_IO_StructInit(LL_SYSCFG_IO_InitTypeDef *SYSCFG_IO_InitStruct)
185 {
186   SYSCFG_IO_InitStruct->Line           = LL_EXTI_LINE_NONE;
187   SYSCFG_IO_InitStruct->LineCommand    = DISABLE;
188   SYSCFG_IO_InitStruct->Type           = LL_EXTI_TYPE_EDGE;
189   SYSCFG_IO_InitStruct->Trigger        = LL_EXTI_TRIGGER_NONE;
190 }
191 
192 /**
193   * @}
194   */
195 
196 /**
197   * @}
198   */
199 
200 
201 #endif /* defined (SYSCFG) */
202 
203 
204 /**
205   * @}
206   */
207 
208 #endif /* USE_FULL_LL_DRIVER */