Increment eeprom version
[betaflight.git] / lib / main / STM32F1 / Drivers / STM32F1xx_HAL_Driver / Src / stm32f1xx_ll_gpio.c
blobff5710ed72a1b8d88dbe7b7a85cbf0eeaf56cc1a
1 /**
2 ******************************************************************************
3 * @file stm32f1xx_ll_gpio.c
4 * @author MCD Application Team
5 * @version V1.1.1
6 * @date 12-May-2017
7 * @brief GPIO LL module driver.
8 ******************************************************************************
9 * @attention
11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 * 1. Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 ******************************************************************************
37 #if defined(USE_FULL_LL_DRIVER)
39 /* Includes ------------------------------------------------------------------*/
40 #include "stm32f1xx_ll_gpio.h"
41 #include "stm32f1xx_ll_bus.h"
42 #ifdef USE_FULL_ASSERT
43 #include "stm32_assert.h"
44 #else
45 #define assert_param(expr) ((void)0U)
46 #endif
48 /** @addtogroup STM32F1xx_LL_Driver
49 * @{
52 #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG)
54 /** @addtogroup GPIO_LL
55 * @{
58 /* Private types -------------------------------------------------------------*/
59 /* Private variables ---------------------------------------------------------*/
60 /* Private constants ---------------------------------------------------------*/
61 /* Private macros ------------------------------------------------------------*/
62 /** @addtogroup GPIO_LL_Private_Macros
63 * @{
65 #define IS_LL_GPIO_PIN(__VALUE__) ((((uint32_t)0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
67 #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_ANALOG) ||\
68 ((__VALUE__) == LL_GPIO_MODE_FLOATING) ||\
69 ((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
70 ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
71 ((__VALUE__) == LL_GPIO_MODE_ALTERNATE))
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_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
78 ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
80 #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_DOWN) ||\
81 ((__VALUE__) == LL_GPIO_PULL_UP))
83 /**
84 * @}
87 /* Private function prototypes -----------------------------------------------*/
89 /* Exported functions --------------------------------------------------------*/
90 /** @addtogroup GPIO_LL_Exported_Functions
91 * @{
94 /** @addtogroup GPIO_LL_EF_Init
95 * @{
98 /**
99 * @brief De-initialize GPIO registers (Registers restored to their default values).
100 * @param GPIOx GPIO Port
101 * @retval An ErrorStatus enumeration value:
102 * - SUCCESS: GPIO registers are de-initialized
103 * - ERROR: Wrong GPIO Port
105 ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
107 ErrorStatus status = SUCCESS;
109 /* Check the parameters */
110 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
112 /* Force and Release reset on clock of GPIOx Port */
113 if (GPIOx == GPIOA)
115 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOA);
116 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOA);
118 else if (GPIOx == GPIOB)
120 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOB);
121 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOB);
123 else if (GPIOx == GPIOC)
125 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOC);
126 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOC);
128 else if (GPIOx == GPIOD)
130 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOD);
131 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOD);
133 #if defined(GPIOE)
134 else if (GPIOx == GPIOE)
136 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOE);
137 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOE);
139 #endif
140 #if defined(GPIOF)
141 else if (GPIOx == GPIOF)
143 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOF);
144 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOF);
146 #endif
147 #if defined(GPIOG)
148 else if (GPIOx == GPIOG)
150 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOG);
151 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOG);
153 #endif
154 else
156 status = ERROR;
159 return (status);
163 * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
164 * @param GPIOx GPIO Port
165 * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
166 * that contains the configuration information for the specified GPIO peripheral.
167 * @retval An ErrorStatus enumeration value:
168 * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
169 * - ERROR: Not applicable
171 ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
173 uint32_t pinpos = 0x00000000U;
174 uint32_t currentpin = 0x00000000U;
176 /* Check the parameters */
177 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
178 assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
179 assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
180 assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
182 /* ------------------------- Configure the port pins ---------------- */
183 /* Initialize pinpos on first pin set */
184 pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
186 /* Configure the port pins */
187 while ((((GPIO_InitStruct->Pin) & 0x0000FFFFU) >> pinpos) != 0x00000000U)
189 /* Get current io position */
190 if(pinpos <8 )
192 currentpin = (GPIO_InitStruct->Pin) & (0x00000101U << pinpos);
194 else
196 currentpin = (GPIO_InitStruct->Pin) & ((0x00010001U << (pinpos-8)) | 0x04000000U);
199 if (currentpin)
201 /* Pin Mode configuration */
202 LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
204 /* Pull-up Pull down resistor configuration*/
205 LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
207 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_FLOATING))
209 /* Speed mode configuration */
210 LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
213 pinpos++;
216 if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_FLOATING))
218 /* Check Output mode parameters */
219 assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
221 /* Output mode configuration*/
222 LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
224 return (SUCCESS);
228 * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
229 * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
230 * whose fields will be set to default values.
231 * @retval None
234 void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
236 /* Reset GPIO init structure parameters values */
237 GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
238 GPIO_InitStruct->Mode = LL_GPIO_MODE_FLOATING;
239 GPIO_InitStruct->Speed = 0x00000000U;
240 GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
241 GPIO_InitStruct->Pull = LL_GPIO_PULL_DOWN;
245 * @}
249 * @}
253 * @}
256 #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) */
259 * @}
262 #endif /* USE_FULL_LL_DRIVER */
264 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/