Merge pull request #11189 from klutvott123/move-telemetry-displayport-init
[betaflight.git] / lib / main / STM32F3 / Drivers / STM32F3xx_HAL_Driver / Src / stm32f3xx_ll_gpio.c
blob9766eedbb03c088a870ca7a9091888ed81270a38
1 /**
2 ******************************************************************************
3 * @file stm32f3xx_ll_gpio.c
4 * @author MCD Application Team
5 * @brief GPIO LL module driver.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************
35 #if defined(USE_FULL_LL_DRIVER)
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f3xx_ll_gpio.h"
39 #include "stm32f3xx_ll_bus.h"
40 #ifdef USE_FULL_ASSERT
41 #include "stm32_assert.h"
42 #else
43 #define assert_param(expr) ((void)0U)
44 #endif
46 /** @addtogroup STM32F3xx_LL_Driver
47 * @{
50 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH)
52 /** @addtogroup GPIO_LL
53 * @{
56 /* Private types -------------------------------------------------------------*/
57 /* Private variables ---------------------------------------------------------*/
58 /* Private constants ---------------------------------------------------------*/
59 /* Private macros ------------------------------------------------------------*/
60 /** @addtogroup GPIO_LL_Private_Macros
61 * @{
63 #define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
65 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
66 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
67 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
68 ((__VALUE__) == LL_GPIO_MODE_ANALOG))
70 #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
71 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
73 #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
74 ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
75 ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH))
77 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
78 ((__VALUE__) == LL_GPIO_PULL_UP) ||\
79 ((__VALUE__) == LL_GPIO_PULL_DOWN))
81 #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
82 ((__VALUE__) == LL_GPIO_AF_1 ) ||\
83 ((__VALUE__) == LL_GPIO_AF_2 ) ||\
84 ((__VALUE__) == LL_GPIO_AF_3 ) ||\
85 ((__VALUE__) == LL_GPIO_AF_4 ) ||\
86 ((__VALUE__) == LL_GPIO_AF_5 ) ||\
87 ((__VALUE__) == LL_GPIO_AF_6 ) ||\
88 ((__VALUE__) == LL_GPIO_AF_7 ) ||\
89 ((__VALUE__) == LL_GPIO_AF_8 ) ||\
90 ((__VALUE__) == LL_GPIO_AF_9 ) ||\
91 ((__VALUE__) == LL_GPIO_AF_10 ) ||\
92 ((__VALUE__) == LL_GPIO_AF_11 ) ||\
93 ((__VALUE__) == LL_GPIO_AF_12 ) ||\
94 ((__VALUE__) == LL_GPIO_AF_13 ) ||\
95 ((__VALUE__) == LL_GPIO_AF_14 ) ||\
96 ((__VALUE__) == LL_GPIO_AF_15 ))
97 /**
98 * @}
101 /* Private function prototypes -----------------------------------------------*/
103 /* Exported functions --------------------------------------------------------*/
104 /** @addtogroup GPIO_LL_Exported_Functions
105 * @{
108 /** @addtogroup GPIO_LL_EF_Init
109 * @{
113 * @brief De-initialize GPIO registers (Registers restored to their default values).
114 * @param GPIOx GPIO Port
115 * @retval An ErrorStatus enumeration value:
116 * - SUCCESS: GPIO registers are de-initialized
117 * - ERROR: Wrong GPIO Port
119 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
121 ErrorStatus status = SUCCESS;
123 /* Check the parameters */
124 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
126 /* Force and Release reset on clock of GPIOx Port */
127 if (GPIOx == GPIOA)
129 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA);
130 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA);
132 else if (GPIOx == GPIOB)
134 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB);
135 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB);
137 else if (GPIOx == GPIOC)
139 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC);
140 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC);
142 #if defined(GPIOD)
143 else if (GPIOx == GPIOD)
145 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD);
146 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD);
148 #endif /* GPIOD */
149 #if defined(GPIOE)
150 else if (GPIOx == GPIOE)
152 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE);
153 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE);
155 #endif /* GPIOE */
156 #if defined(GPIOF)
157 else if (GPIOx == GPIOF)
159 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF);
160 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF);
162 #endif /* GPIOF */
163 #if defined(GPIOG)
164 else if (GPIOx == GPIOG)
166 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOG);
167 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOG);
169 #endif /* GPIOG */
170 #if defined(GPIOH)
171 else if (GPIOx == GPIOH)
173 LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOH);
174 LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOH);
176 #endif /* GPIOH */
177 else
179 status = ERROR;
182 return (status);
186 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
187 * @param GPIOx GPIO Port
188 * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
189 * that contains the configuration information for the specified GPIO peripheral.
190 * @retval An ErrorStatus enumeration value:
191 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
192 * - ERROR: Not applicable
194 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
196 uint32_t pinpos = 0x00000000U;
197 uint32_t currentpin = 0x00000000U;
199 /* Check the parameters */
200 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
201 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
202 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
203 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
205 /* ------------------------- Configure the port pins ---------------- */
206 /* Initialize pinpos on first pin set */
207 pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
209 /* Configure the port pins */
210 while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
212 /* Get current io position */
213 currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos);
215 if (currentpin)
217 /* Pin Mode configuration */
218 LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
220 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
222 /* Check Speed mode parameters */
223 assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
225 /* Speed mode configuration */
226 LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
229 /* Pull-up Pull down resistor configuration*/
230 LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
232 if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
234 /* Check Alternate parameter */
235 assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
237 /* Speed mode configuration */
238 if (POSITION_VAL(currentpin) < 0x00000008U)
240 LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
242 else
244 LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
248 pinpos++;
251 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
253 /* Check Output mode parameters */
254 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
256 /* Output mode configuration*/
257 LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
260 return (SUCCESS);
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
270 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
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;
282 * @}
286 * @}
290 * @}
293 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) || defined (GPIOH) */
296 * @}
299 #endif /* USE_FULL_LL_DRIVER */
301 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/