2 ******************************************************************************
3 * @file stm32f7xx_ll_gpio.c
4 * @author MCD Application Team
5 * @brief GPIO LL module driver.
6 ******************************************************************************
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
12 * This software component is licensed by ST under BSD 3-Clause license,
13 * the "License"; You may not use this file except in compliance with the
14 * License. You may obtain a copy of the License at:
15 * opensource.org/licenses/BSD-3-Clause
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32f7xx_ll_gpio.h"
23 #include "stm32f7xx_ll_bus.h"
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
27 #define assert_param(expr) ((void)0U)
30 /** @addtogroup STM32F7xx_LL_Driver
34 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK)
36 /** @addtogroup GPIO_LL
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 /* Private constants ---------------------------------------------------------*/
43 /* Private macros ------------------------------------------------------------*/
44 /** @addtogroup GPIO_LL_Private_Macros
47 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
49 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
50 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
51 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
52 ((__VALUE__) == LL_GPIO_MODE_ANALOG))
54 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
55 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
57 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
58 ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
59 ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
60 ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
62 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
63 ((__VALUE__) == LL_GPIO_PULL_UP) ||\
64 ((__VALUE__) == LL_GPIO_PULL_DOWN))
66 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
67 ((__VALUE__) == LL_GPIO_AF_1 ) ||\
68 ((__VALUE__) == LL_GPIO_AF_2 ) ||\
69 ((__VALUE__) == LL_GPIO_AF_3 ) ||\
70 ((__VALUE__) == LL_GPIO_AF_4 ) ||\
71 ((__VALUE__) == LL_GPIO_AF_5 ) ||\
72 ((__VALUE__) == LL_GPIO_AF_6 ) ||\
73 ((__VALUE__) == LL_GPIO_AF_7 ) ||\
74 ((__VALUE__) == LL_GPIO_AF_8 ) ||\
75 ((__VALUE__) == LL_GPIO_AF_9 ) ||\
76 ((__VALUE__) == LL_GPIO_AF_10 ) ||\
77 ((__VALUE__) == LL_GPIO_AF_11 ) ||\
78 ((__VALUE__) == LL_GPIO_AF_12 ) ||\
79 ((__VALUE__) == LL_GPIO_AF_13 ) ||\
80 ((__VALUE__) == LL_GPIO_AF_14 ) ||\
81 ((__VALUE__) == LL_GPIO_AF_15 ))
86 /* Private function prototypes -----------------------------------------------*/
88 /* Exported functions --------------------------------------------------------*/
89 /** @addtogroup GPIO_LL_Exported_Functions
93 /** @addtogroup GPIO_LL_EF_Init
98 * @brief De-initialize GPIO registers (Registers restored to their default values).
99 * @param GPIOx GPIO Port
100 * @retval An ErrorStatus enumeration value:
101 * - SUCCESS: GPIO registers are de-initialized
102 * - ERROR: Wrong GPIO Port
104 ErrorStatus
LL_GPIO_DeInit(GPIO_TypeDef
*GPIOx
)
106 ErrorStatus status
= SUCCESS
;
108 /* Check the parameters */
109 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx
));
111 /* Force and Release reset on clock of GPIOx Port */
114 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA
);
115 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA
);
117 else if (GPIOx
== GPIOB
)
119 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB
);
120 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB
);
122 else if (GPIOx
== GPIOC
)
124 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC
);
125 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC
);
128 else if (GPIOx
== GPIOD
)
130 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD
);
131 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD
);
135 else if (GPIOx
== GPIOE
)
137 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE
);
138 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE
);
142 else if (GPIOx
== GPIOF
)
144 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF
);
145 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF
);
149 else if (GPIOx
== GPIOG
)
151 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOG
);
152 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOG
);
156 else if (GPIOx
== GPIOH
)
158 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOH
);
159 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOH
);
163 else if (GPIOx
== GPIOI
)
165 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOI
);
166 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOI
);
170 else if (GPIOx
== GPIOJ
)
172 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOJ
);
173 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOJ
);
177 else if (GPIOx
== GPIOK
)
179 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOK
);
180 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOK
);
192 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
193 * @param GPIOx GPIO Port
194 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
195 * that contains the configuration information for the specified GPIO peripheral.
196 * @retval An ErrorStatus enumeration value:
197 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
198 * - ERROR: Not applicable
200 ErrorStatus
LL_GPIO_Init(GPIO_TypeDef
*GPIOx
, LL_GPIO_InitTypeDef
*GPIO_InitStruct
)
202 uint32_t pinpos
= 0x00000000U
;
203 uint32_t currentpin
= 0x00000000U
;
205 /* Check the parameters */
206 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx
));
207 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct
->Pin
));
208 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct
->Mode
));
209 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct
->Pull
));
211 /* ------------------------- Configure the port pins ---------------- */
212 /* Initialize pinpos on first pin set */
213 pinpos
= POSITION_VAL(GPIO_InitStruct
->Pin
);
215 /* Configure the port pins */
216 while (((GPIO_InitStruct
->Pin
) >> pinpos
) != 0x00000000U
)
218 /* Get current io position */
219 currentpin
= (GPIO_InitStruct
->Pin
) & (0x00000001U
<< pinpos
);
223 /* Pin Mode configuration */
224 LL_GPIO_SetPinMode(GPIOx
, currentpin
, GPIO_InitStruct
->Mode
);
226 if ((GPIO_InitStruct
->Mode
== LL_GPIO_MODE_OUTPUT
) || (GPIO_InitStruct
->Mode
== LL_GPIO_MODE_ALTERNATE
))
228 /* Check Speed mode parameters */
229 assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct
->Speed
));
231 /* Speed mode configuration */
232 LL_GPIO_SetPinSpeed(GPIOx
, currentpin
, GPIO_InitStruct
->Speed
);
235 /* Pull-up Pull down resistor configuration*/
236 LL_GPIO_SetPinPull(GPIOx
, currentpin
, GPIO_InitStruct
->Pull
);
238 if (GPIO_InitStruct
->Mode
== LL_GPIO_MODE_ALTERNATE
)
240 /* Check Alternate parameter */
241 assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct
->Alternate
));
243 /* Speed mode configuration */
244 if (POSITION_VAL(currentpin
) < 0x00000008U
)
246 LL_GPIO_SetAFPin_0_7(GPIOx
, currentpin
, GPIO_InitStruct
->Alternate
);
250 LL_GPIO_SetAFPin_8_15(GPIOx
, currentpin
, GPIO_InitStruct
->Alternate
);
257 if ((GPIO_InitStruct
->Mode
== LL_GPIO_MODE_OUTPUT
) || (GPIO_InitStruct
->Mode
== LL_GPIO_MODE_ALTERNATE
))
259 /* Check Output mode parameters */
260 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct
->OutputType
));
262 /* Output mode configuration*/
263 LL_GPIO_SetPinOutputType(GPIOx
, GPIO_InitStruct
->Pin
, GPIO_InitStruct
->OutputType
);
270 * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
271 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
272 * whose fields will be set to default values.
276 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef
*GPIO_InitStruct
)
278 /* Reset GPIO init structure parameters values */
279 GPIO_InitStruct
->Pin
= LL_GPIO_PIN_ALL
;
280 GPIO_InitStruct
->Mode
= LL_GPIO_MODE_ANALOG
;
281 GPIO_InitStruct
->Speed
= LL_GPIO_SPEED_FREQ_LOW
;
282 GPIO_InitStruct
->OutputType
= LL_GPIO_OUTPUT_PUSHPULL
;
283 GPIO_InitStruct
->Pull
= LL_GPIO_PULL_NO
;
284 GPIO_InitStruct
->Alternate
= LL_GPIO_AF_0
;
299 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) || defined (GPIOI) || defined (GPIOJ) || defined (GPIOK) */
305 #endif /* USE_FULL_LL_DRIVER */
307 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/