comparison Common/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_gpio.c @ 128:c78bcbd5deda FlipDisplay

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