Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32G4 / Drivers / STM32G4xx_HAL_Driver / Src / stm32g4xx_ll_gpio.c
blob6f520a78b1ab9ace1c987250ebc77cd1704cd8eb
1 /**
2 ******************************************************************************
3 * @file stm32g4xx_ll_gpio.c
4 * @author MCD Application Team
5 * @brief GPIO LL module driver.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; 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 "stm32g4xx_ll_gpio.h"
23 #include "stm32g4xx_ll_bus.h"
24 #ifdef USE_FULL_ASSERT
25 #include "stm32_assert.h"
26 #else
27 #define assert_param(expr) ((void)0U)
28 #endif /* USE_FULL_ASSERT */
30 /** @addtogroup STM32G4xx_LL_Driver
31 * @{
34 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG)
36 /** @addtogroup GPIO_LL
37 * @{
39 /** MISRA C:2012 deviation rule has been granted for following rules:
40 * Rule-12.2 - Medium: RHS argument is in interval [0,INF] which is out of
41 * range of the shift operator in following API :
42 * LL_GPIO_Init
45 /* Private types -------------------------------------------------------------*/
46 /* Private variables ---------------------------------------------------------*/
47 /* Private constants ---------------------------------------------------------*/
48 /* Private macros ------------------------------------------------------------*/
49 /** @addtogroup GPIO_LL_Private_Macros
50 * @{
52 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
54 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
55 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
56 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
57 ((__VALUE__) == LL_GPIO_MODE_ANALOG))
59 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
60 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
62 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
63 ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
64 ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
65 ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
67 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
68 ((__VALUE__) == LL_GPIO_PULL_UP) ||\
69 ((__VALUE__) == LL_GPIO_PULL_DOWN))
71 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
72 ((__VALUE__) == LL_GPIO_AF_1 ) ||\
73 ((__VALUE__) == LL_GPIO_AF_2 ) ||\
74 ((__VALUE__) == LL_GPIO_AF_3 ) ||\
75 ((__VALUE__) == LL_GPIO_AF_4 ) ||\
76 ((__VALUE__) == LL_GPIO_AF_5 ) ||\
77 ((__VALUE__) == LL_GPIO_AF_6 ) ||\
78 ((__VALUE__) == LL_GPIO_AF_7 ) ||\
79 ((__VALUE__) == LL_GPIO_AF_8 ) ||\
80 ((__VALUE__) == LL_GPIO_AF_9 ) ||\
81 ((__VALUE__) == LL_GPIO_AF_10 ) ||\
82 ((__VALUE__) == LL_GPIO_AF_11 ) ||\
83 ((__VALUE__) == LL_GPIO_AF_12 ) ||\
84 ((__VALUE__) == LL_GPIO_AF_13 ) ||\
85 ((__VALUE__) == LL_GPIO_AF_14 ) ||\
86 ((__VALUE__) == LL_GPIO_AF_15 ))
87 /**
88 * @}
91 /* Private function prototypes -----------------------------------------------*/
93 /* Exported functions --------------------------------------------------------*/
94 /** @addtogroup GPIO_LL_Exported_Functions
95 * @{
98 /** @addtogroup GPIO_LL_EF_Init
99 * @{
103 * @brief De-initialize GPIO registers (Registers restored to their default values).
104 * @param GPIOx GPIO Port
105 * @retval An ErrorStatus enumeration value:
106 * - SUCCESS: GPIO registers are de-initialized
107 * - ERROR: Wrong GPIO Port
109 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
111 ErrorStatus status = SUCCESS;
113 /* Check the parameters */
114 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
116 /* Force and Release reset on clock of GPIOx Port */
117 if (GPIOx == GPIOA)
119 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOA);
120 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOA);
122 else if (GPIOx == GPIOB)
124 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOB);
125 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOB);
127 else if (GPIOx == GPIOC)
129 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOC);
130 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOC);
132 else if (GPIOx == GPIOD)
134 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOD);
135 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOD);
137 else if (GPIOx == GPIOE)
139 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOE);
140 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOE);
142 else if (GPIOx == GPIOF)
144 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOF);
145 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOF);
147 else if (GPIOx == GPIOG)
149 LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOG);
150 LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOG);
152 else
154 status = ERROR;
157 return (status);
161 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
162 * @param GPIOx GPIO Port
163 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
164 * that contains the configuration information for the specified GPIO peripheral.
165 * @retval An ErrorStatus enumeration value:
166 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
167 * - ERROR: Not applicable
169 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
171 uint32_t pinpos;
172 uint32_t currentpin;
174 /* Check the parameters */
175 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
176 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
177 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
178 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
180 /* ------------------------- Configure the port pins ---------------- */
181 /* Initialize pinpos on first pin set */
182 pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
184 /* Configure the port pins */
185 while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
187 /* Get current io position */
188 currentpin = (GPIO_InitStruct->Pin) & (0x00000001UL << pinpos);
190 if (currentpin != 0x00u)
192 /* Pin Mode configuration */
193 LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
195 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
197 /* Check Speed mode parameters */
198 assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
200 /* Speed mode configuration */
201 LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
204 /* Pull-up Pull down resistor configuration*/
205 LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
207 if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
209 /* Check Alternate parameter */
210 assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
212 /* Speed mode configuration */
213 if (currentpin < LL_GPIO_PIN_8)
215 LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
217 else
219 LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
223 pinpos++;
226 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
228 /* Check Output mode parameters */
229 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
231 /* Output mode configuration*/
232 LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
235 return (SUCCESS);
239 * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
240 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
241 * whose fields will be set to default values.
242 * @retval None
245 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
247 /* Reset GPIO init structure parameters values */
248 GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
249 GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
250 GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
251 GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
252 GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
253 GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
257 * @}
261 * @}
265 * @}
268 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) */
271 * @}
274 #endif /* USE_FULL_LL_DRIVER */
276 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/