1 /**
2 ******************************************************************************
3 * @file stm32f7xx_ll_gpio.c
4 * @author MCD Application Team
5 * @brief GPIO LL module driver.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2017 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 "stm32f7xx_ll_gpio.h"
22 #include "stm32f7xx_ll_bus.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 STM32F7xx_LL_Driver
30 * @{
31 */
32
33 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK)
34
35 /** @addtogroup GPIO_LL
36 * @{
37 */
38
39 /* Private types -------------------------------------------------------------*/
40 /* Private variables ---------------------------------------------------------*/
41 /* Private constants ---------------------------------------------------------*/
42 /* Private macros ------------------------------------------------------------*/
43 /** @addtogroup GPIO_LL_Private_Macros
44 * @{
45 */
46 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
47
48 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
49 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
50 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
51 ((__VALUE__) == LL_GPIO_MODE_ANALOG))
52
53 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
54 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
55
56 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
57 ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
58 ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
59 ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
60
61 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
62 ((__VALUE__) == LL_GPIO_PULL_UP) ||\
63 ((__VALUE__) == LL_GPIO_PULL_DOWN))
64
65 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
66 ((__VALUE__) == LL_GPIO_AF_1 ) ||\
67 ((__VALUE__) == LL_GPIO_AF_2 ) ||\
68 ((__VALUE__) == LL_GPIO_AF_3 ) ||\
69 ((__VALUE__) == LL_GPIO_AF_4 ) ||\
70 ((__VALUE__) == LL_GPIO_AF_5 ) ||\
71 ((__VALUE__) == LL_GPIO_AF_6 ) ||\
72 ((__VALUE__) == LL_GPIO_AF_7 ) ||\
73 ((__VALUE__) == LL_GPIO_AF_8 ) ||\
74 ((__VALUE__) == LL_GPIO_AF_9 ) ||\
75 ((__VALUE__) == LL_GPIO_AF_10 ) ||\
76 ((__VALUE__) == LL_GPIO_AF_11 ) ||\
77 ((__VALUE__) == LL_GPIO_AF_12 ) ||\
78 ((__VALUE__) == LL_GPIO_AF_13 ) ||\
79 ((__VALUE__) == LL_GPIO_AF_14 ) ||\
80 ((__VALUE__) == LL_GPIO_AF_15 ))
81 /**
82 * @}
83 */
84
85 /* Private function prototypes -----------------------------------------------*/
86
87 /* Exported functions --------------------------------------------------------*/
88 /** @addtogroup GPIO_LL_Exported_Functions
89 * @{
90 */
91
92 /** @addtogroup GPIO_LL_EF_Init
93 * @{
94 */
95
96 /**
97 * @brief De-initialize GPIO registers (Registers restored to their default values).
98 * @param GPIOx GPIO Port
99 * @retval An ErrorStatus enumeration value:
100 * - SUCCESS: GPIO registers are de-initialized
101 * - ERROR: Wrong GPIO Port
102 */
LL_GPIO_DeInit(GPIO_TypeDef * GPIOx)103 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
104 {
105 ErrorStatus status = SUCCESS;
106
107 /* Check the parameters */
108 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
109
110 /* Force and Release reset on clock of GPIOx Port */
111 if (GPIOx == GPIOA)
112 {
113 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA);
114 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA);
115 }
116 else if (GPIOx == GPIOB)
117 {
118 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB);
119 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB);
120 }
121 else if (GPIOx == GPIOC)
122 {
123 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC);
124 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC);
125 }
126 #if defined(GPIOD)
127 else if (GPIOx == GPIOD)
128 {
129 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD);
130 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD);
131 }
132 #endif /* GPIOD */
133 #if defined(GPIOE)
134 else if (GPIOx == GPIOE)
135 {
136 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE);
137 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE);
138 }
139 #endif /* GPIOE */
140 #if defined(GPIOF)
141 else if (GPIOx == GPIOF)
142 {
143 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF);
144 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF);
145 }
146 #endif /* GPIOF */
147 #if defined(GPIOG)
148 else if (GPIOx == GPIOG)
149 {
150 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOG);
151 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOG);
152 }
153 #endif /* GPIOG */
154 #if defined(GPIOH)
155 else if (GPIOx == GPIOH)
156 {
157 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOH);
158 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOH);
159 }
160 #endif /* GPIOH */
161 #if defined(GPIOI)
162 else if (GPIOx == GPIOI)
163 {
164 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOI);
165 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOI);
166 }
167 #endif /* GPIOI */
168 #if defined(GPIOJ)
169 else if (GPIOx == GPIOJ)
170 {
171 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOJ);
172 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOJ);
173 }
174 #endif /* GPIOJ */
175 #if defined(GPIOK)
176 else if (GPIOx == GPIOK)
177 {
178 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOK);
179 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOK);
180 }
181 #endif /* GPIOK */
182 else
183 {
184 status = ERROR;
185 }
186
187 return (status);
188 }
189
190 /**
191 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
192 * @param GPIOx GPIO Port
193 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
194 * that contains the configuration information for the specified GPIO peripheral.
195 * @retval An ErrorStatus enumeration value:
196 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
197 * - ERROR: Not applicable
198 */
LL_GPIO_Init(GPIO_TypeDef * GPIOx,LL_GPIO_InitTypeDef * GPIO_InitStruct)199 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
200 {
201 uint32_t pinpos = 0x00000000U;
202 uint32_t currentpin = 0x00000000U;
203
204 /* Check the parameters */
205 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
206 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
207 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
208 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
209
210 /* ------------------------- Configure the port pins ---------------- */
211 /* Initialize pinpos on first pin set */
212 pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
213
214 /* Configure the port pins */
215 while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
216 {
217 /* Get current io position */
218 currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos);
219
220 if (currentpin)
221 {
222 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
223 {
224 /* Check Speed mode parameters */
225 assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
226
227 /* Speed mode configuration */
228 LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
229
230 /* Check Output mode parameters */
231 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
232
233 /* Output mode configuration*/
234 LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
235 }
236
237 /* Pull-up Pull down resistor configuration*/
238 LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
239
240 if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
241 {
242 /* Check Alternate parameter */
243 assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
244
245 /* Speed mode configuration */
246 if (POSITION_VAL(currentpin) < 0x00000008U)
247 {
248 LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
249 }
250 else
251 {
252 LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
253 }
254 }
255 /* Pin Mode configuration */
256 LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
257 }
258 pinpos++;
259 }
260 return (SUCCESS);
261 }
262
263 /**
264 * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
265 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
266 * whose fields will be set to default values.
267 * @retval None
268 */
269
LL_GPIO_StructInit(LL_GPIO_InitTypeDef * GPIO_InitStruct)270 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
271 {
272 /* Reset GPIO init structure parameters values */
273 GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
274 GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
275 GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
276 GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
277 GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
278 GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
279 }
280
281 /**
282 * @}
283 */
284
285 /**
286 * @}
287 */
288
289 /**
290 * @}
291 */
292
293 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */
294
295 /**
296 * @}
297 */
298
299 #endif /* USE_FULL_LL_DRIVER */
300
301