source: trunk/firmware/Drivers/STM32G0xx_HAL_Driver/Inc/stm32g0xx_ll_gpio.h

Last change on this file was 6, checked in by f.jahn, 8 months ago
File size: 36.4 KB
Line 
1/**
2 ******************************************************************************
3 * @file stm32g0xx_ll_gpio.h
4 * @author MCD Application Team
5 * @brief Header file of GPIO LL module.
6 ******************************************************************************
7 * @attention
8 *
9 * Copyright (c) 2018 STMicroelectronics.
10 * All rights reserved.
11 *
12 * This software is licensed under terms that can be found in the LICENSE file
13 * in the root directory of this software component.
14 * If no LICENSE file comes with this software, it is provided AS-IS.
15 *
16 ******************************************************************************
17 */
18
19/* Define to prevent recursive inclusion -------------------------------------*/
20#ifndef STM32G0xx_LL_GPIO_H
21#define STM32G0xx_LL_GPIO_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* Includes ------------------------------------------------------------------*/
28#include "stm32g0xx.h"
29
30/** @addtogroup STM32G0xx_LL_Driver
31 * @{
32 */
33
34#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF)
35
36/** @defgroup GPIO_LL GPIO
37 * @{
38 */
39/** MISRA C:2012 deviation rule has been granted for following rules:
40 * Rule-18.1_d - Medium: Array pointer `GPIOx' is accessed with index [..,..]
41 * which may be out of array bounds [..,UNKNOWN] in following APIs:
42 * LL_GPIO_GetAFPin_0_7
43 * LL_GPIO_SetAFPin_0_7
44 * LL_GPIO_SetAFPin_8_15
45 * LL_GPIO_GetAFPin_8_15
46 */
47
48/* Private types -------------------------------------------------------------*/
49/* Private variables ---------------------------------------------------------*/
50/* Private constants ---------------------------------------------------------*/
51/* Private macros ------------------------------------------------------------*/
52#if defined(USE_FULL_LL_DRIVER)
53/** @defgroup GPIO_LL_Private_Macros GPIO Private Macros
54 * @{
55 */
56
57/**
58 * @}
59 */
60#endif /*USE_FULL_LL_DRIVER*/
61
62/* Exported types ------------------------------------------------------------*/
63#if defined(USE_FULL_LL_DRIVER)
64/** @defgroup GPIO_LL_ES_INIT GPIO Exported Init structures
65 * @{
66 */
67
68/**
69 * @brief LL GPIO Init Structure definition
70 */
71typedef struct
72{
73 uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
74 This parameter can be any value of @ref GPIO_LL_EC_PIN */
75
76 uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
77 This parameter can be a value of @ref GPIO_LL_EC_MODE.
78
79 GPIO HW configuration can be modified afterwards using unitary function @ref LL_GPIO_SetPinMode().*/
80
81 uint32_t Speed; /*!< Specifies the speed for the selected pins.
82 This parameter can be a value of @ref GPIO_LL_EC_SPEED.
83
84 GPIO HW configuration can be modified afterwards using unitary function @ref LL_GPIO_SetPinSpeed().*/
85
86 uint32_t OutputType; /*!< Specifies the operating output type for the selected pins.
87 This parameter can be a value of @ref GPIO_LL_EC_OUTPUT.
88
89 GPIO HW configuration can be modified afterwards using unitary function @ref LL_GPIO_SetPinOutputType().*/
90
91 uint32_t Pull; /*!< Specifies the operating Pull-up/Pull down for the selected pins.
92 This parameter can be a value of @ref GPIO_LL_EC_PULL.
93
94 GPIO HW configuration can be modified afterwards using unitary function @ref LL_GPIO_SetPinPull().*/
95
96 uint32_t Alternate; /*!< Specifies the Peripheral to be connected to the selected pins.
97 This parameter can be a value of @ref GPIO_LL_EC_AF.
98
99 GPIO HW configuration can be modified afterwards using unitary function @ref LL_GPIO_SetAFPin_0_7() and LL_GPIO_SetAFPin_8_15().*/
100} LL_GPIO_InitTypeDef;
101
102/**
103 * @}
104 */
105#endif /* USE_FULL_LL_DRIVER */
106
107/* Exported constants --------------------------------------------------------*/
108/** @defgroup GPIO_LL_Exported_Constants GPIO Exported Constants
109 * @{
110 */
111
112/** @defgroup GPIO_LL_EC_PIN PIN
113 * @{
114 */
115#define LL_GPIO_PIN_0 GPIO_BSRR_BS0 /*!< Select pin 0 */
116#define LL_GPIO_PIN_1 GPIO_BSRR_BS1 /*!< Select pin 1 */
117#define LL_GPIO_PIN_2 GPIO_BSRR_BS2 /*!< Select pin 2 */
118#define LL_GPIO_PIN_3 GPIO_BSRR_BS3 /*!< Select pin 3 */
119#define LL_GPIO_PIN_4 GPIO_BSRR_BS4 /*!< Select pin 4 */
120#define LL_GPIO_PIN_5 GPIO_BSRR_BS5 /*!< Select pin 5 */
121#define LL_GPIO_PIN_6 GPIO_BSRR_BS6 /*!< Select pin 6 */
122#define LL_GPIO_PIN_7 GPIO_BSRR_BS7 /*!< Select pin 7 */
123#define LL_GPIO_PIN_8 GPIO_BSRR_BS8 /*!< Select pin 8 */
124#define LL_GPIO_PIN_9 GPIO_BSRR_BS9 /*!< Select pin 9 */
125#define LL_GPIO_PIN_10 GPIO_BSRR_BS10 /*!< Select pin 10 */
126#define LL_GPIO_PIN_11 GPIO_BSRR_BS11 /*!< Select pin 11 */
127#define LL_GPIO_PIN_12 GPIO_BSRR_BS12 /*!< Select pin 12 */
128#define LL_GPIO_PIN_13 GPIO_BSRR_BS13 /*!< Select pin 13 */
129#define LL_GPIO_PIN_14 GPIO_BSRR_BS14 /*!< Select pin 14 */
130#define LL_GPIO_PIN_15 GPIO_BSRR_BS15 /*!< Select pin 15 */
131#define LL_GPIO_PIN_ALL (GPIO_BSRR_BS0 | GPIO_BSRR_BS1 | GPIO_BSRR_BS2 | \
132 GPIO_BSRR_BS3 | GPIO_BSRR_BS4 | GPIO_BSRR_BS5 | \
133 GPIO_BSRR_BS6 | GPIO_BSRR_BS7 | GPIO_BSRR_BS8 | \
134 GPIO_BSRR_BS9 | GPIO_BSRR_BS10 | GPIO_BSRR_BS11 | \
135 GPIO_BSRR_BS12 | GPIO_BSRR_BS13 | GPIO_BSRR_BS14 | \
136 GPIO_BSRR_BS15) /*!< Select all pins */
137/**
138 * @}
139 */
140
141/** @defgroup GPIO_LL_EC_MODE Mode
142 * @{
143 */
144#define LL_GPIO_MODE_INPUT (0x00000000U) /*!< Select input mode */
145#define LL_GPIO_MODE_OUTPUT GPIO_MODER_MODE0_0 /*!< Select output mode */
146#define LL_GPIO_MODE_ALTERNATE GPIO_MODER_MODE0_1 /*!< Select alternate function mode */
147#define LL_GPIO_MODE_ANALOG GPIO_MODER_MODE0 /*!< Select analog mode */
148/**
149 * @}
150 */
151
152/** @defgroup GPIO_LL_EC_OUTPUT Output Type
153 * @{
154 */
155#define LL_GPIO_OUTPUT_PUSHPULL (0x00000000U) /*!< Select push-pull as output type */
156#define LL_GPIO_OUTPUT_OPENDRAIN GPIO_OTYPER_OT0 /*!< Select open-drain as output type */
157/**
158 * @}
159 */
160
161/** @defgroup GPIO_LL_EC_SPEED Output Speed
162 * @{
163 */
164#define LL_GPIO_SPEED_FREQ_LOW (0x00000000U) /*!< Select I/O low output speed */
165#define LL_GPIO_SPEED_FREQ_MEDIUM GPIO_OSPEEDR_OSPEED0_0 /*!< Select I/O medium output speed */
166#define LL_GPIO_SPEED_FREQ_HIGH GPIO_OSPEEDR_OSPEED0_1 /*!< Select I/O fast output speed */
167#define LL_GPIO_SPEED_FREQ_VERY_HIGH GPIO_OSPEEDR_OSPEED0 /*!< Select I/O high output speed */
168/**
169 * @}
170 */
171#define LL_GPIO_SPEED_LOW LL_GPIO_SPEED_FREQ_LOW
172#define LL_GPIO_SPEED_MEDIUM LL_GPIO_SPEED_FREQ_MEDIUM
173#define LL_GPIO_SPEED_FAST LL_GPIO_SPEED_FREQ_HIGH
174#define LL_GPIO_SPEED_HIGH LL_GPIO_SPEED_FREQ_VERY_HIGH
175
176
177/** @defgroup GPIO_LL_EC_PULL Pull Up Pull Down
178 * @{
179 */
180#define LL_GPIO_PULL_NO (0x00000000U) /*!< Select I/O no pull */
181#define LL_GPIO_PULL_UP GPIO_PUPDR_PUPD0_0 /*!< Select I/O pull up */
182#define LL_GPIO_PULL_DOWN GPIO_PUPDR_PUPD0_1 /*!< Select I/O pull down */
183/**
184 * @}
185 */
186
187/** @defgroup GPIO_LL_EC_AF Alternate Function
188 * @{
189 */
190#define LL_GPIO_AF_0 (0x0000000U) /*!< Select alternate function 0 */
191#define LL_GPIO_AF_1 (0x0000001U) /*!< Select alternate function 1 */
192#define LL_GPIO_AF_2 (0x0000002U) /*!< Select alternate function 2 */
193#define LL_GPIO_AF_3 (0x0000003U) /*!< Select alternate function 3 */
194#define LL_GPIO_AF_4 (0x0000004U) /*!< Select alternate function 4 */
195#define LL_GPIO_AF_5 (0x0000005U) /*!< Select alternate function 5 */
196#define LL_GPIO_AF_6 (0x0000006U) /*!< Select alternate function 6 */
197#define LL_GPIO_AF_7 (0x0000007U) /*!< Select alternate function 7 */
198#if defined(STM32G0B0xx) || defined(STM32G0B1xx) || defined (STM32G0C1xx)
199#define LL_GPIO_AF_8 (0x0000008U) /*!< Select alternate function 8 */
200#define LL_GPIO_AF_9 (0x0000009U) /*!< Select alternate function 9 */
201#define LL_GPIO_AF_10 (0x000000AU) /*!< Select alternate function 10 */
202#endif /* STM32G0B0xx || STM32G0B1xx || STM32G0C1xx */
203/**
204 * @}
205 */
206
207/**
208 * @}
209 */
210
211/* Exported macro ------------------------------------------------------------*/
212/** @defgroup GPIO_LL_Exported_Macros GPIO Exported Macros
213 * @{
214 */
215
216/** @defgroup GPIO_LL_EM_WRITE_READ Common Write and read registers Macros
217 * @{
218 */
219
220/**
221 * @brief Write a value in GPIO register
222 * @param __INSTANCE__ GPIO Instance
223 * @param __REG__ Register to be written
224 * @param __VALUE__ Value to be written in the register
225 * @retval None
226 */
227#define LL_GPIO_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
228
229/**
230 * @brief Read a value in GPIO register
231 * @param __INSTANCE__ GPIO Instance
232 * @param __REG__ Register to be read
233 * @retval Register value
234 */
235#define LL_GPIO_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
236/**
237 * @}
238 */
239
240/**
241 * @}
242 */
243
244/* Exported functions --------------------------------------------------------*/
245/** @defgroup GPIO_LL_Exported_Functions GPIO Exported Functions
246 * @{
247 */
248
249/** @defgroup GPIO_LL_EF_Port_Configuration Port Configuration
250 * @{
251 */
252
253/**
254 * @brief Configure gpio mode for a dedicated pin on dedicated port.
255 * @note I/O mode can be Input mode, General purpose output, Alternate function mode or Analog.
256 * @note Warning: only one pin can be passed as parameter.
257 * @rmtoll MODER MODEy LL_GPIO_SetPinMode
258 * @param GPIOx GPIO Port
259 * @param Pin This parameter can be one of the following values:
260 * @arg @ref LL_GPIO_PIN_0
261 * @arg @ref LL_GPIO_PIN_1
262 * @arg @ref LL_GPIO_PIN_2
263 * @arg @ref LL_GPIO_PIN_3
264 * @arg @ref LL_GPIO_PIN_4
265 * @arg @ref LL_GPIO_PIN_5
266 * @arg @ref LL_GPIO_PIN_6
267 * @arg @ref LL_GPIO_PIN_7
268 * @arg @ref LL_GPIO_PIN_8
269 * @arg @ref LL_GPIO_PIN_9
270 * @arg @ref LL_GPIO_PIN_10
271 * @arg @ref LL_GPIO_PIN_11
272 * @arg @ref LL_GPIO_PIN_12
273 * @arg @ref LL_GPIO_PIN_13
274 * @arg @ref LL_GPIO_PIN_14
275 * @arg @ref LL_GPIO_PIN_15
276 * @param Mode This parameter can be one of the following values:
277 * @arg @ref LL_GPIO_MODE_INPUT
278 * @arg @ref LL_GPIO_MODE_OUTPUT
279 * @arg @ref LL_GPIO_MODE_ALTERNATE
280 * @arg @ref LL_GPIO_MODE_ANALOG
281 * @retval None
282 */
283__STATIC_INLINE void LL_GPIO_SetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Mode)
284{
285 MODIFY_REG(GPIOx->MODER, ((Pin * Pin) * GPIO_MODER_MODE0), ((Pin * Pin) * Mode));
286}
287
288/**
289 * @brief Return gpio mode for a dedicated pin on dedicated port.
290 * @note I/O mode can be Input mode, General purpose output, Alternate function mode or Analog.
291 * @note Warning: only one pin can be passed as parameter.
292 * @rmtoll MODER MODEy LL_GPIO_GetPinMode
293 * @param GPIOx GPIO Port
294 * @param Pin This parameter can be one of the following values:
295 * @arg @ref LL_GPIO_PIN_0
296 * @arg @ref LL_GPIO_PIN_1
297 * @arg @ref LL_GPIO_PIN_2
298 * @arg @ref LL_GPIO_PIN_3
299 * @arg @ref LL_GPIO_PIN_4
300 * @arg @ref LL_GPIO_PIN_5
301 * @arg @ref LL_GPIO_PIN_6
302 * @arg @ref LL_GPIO_PIN_7
303 * @arg @ref LL_GPIO_PIN_8
304 * @arg @ref LL_GPIO_PIN_9
305 * @arg @ref LL_GPIO_PIN_10
306 * @arg @ref LL_GPIO_PIN_11
307 * @arg @ref LL_GPIO_PIN_12
308 * @arg @ref LL_GPIO_PIN_13
309 * @arg @ref LL_GPIO_PIN_14
310 * @arg @ref LL_GPIO_PIN_15
311 * @retval Returned value can be one of the following values:
312 * @arg @ref LL_GPIO_MODE_INPUT
313 * @arg @ref LL_GPIO_MODE_OUTPUT
314 * @arg @ref LL_GPIO_MODE_ALTERNATE
315 * @arg @ref LL_GPIO_MODE_ANALOG
316 */
317__STATIC_INLINE uint32_t LL_GPIO_GetPinMode(GPIO_TypeDef *GPIOx, uint32_t Pin)
318{
319 return (uint32_t)(READ_BIT(GPIOx->MODER, ((Pin * Pin) * GPIO_MODER_MODE0)) / (Pin * Pin));
320}
321
322/**
323 * @brief Configure gpio output type for several pins on dedicated port.
324 * @note Output type as to be set when gpio pin is in output or
325 * alternate modes. Possible type are Push-pull or Open-drain.
326 * @rmtoll OTYPER OTy LL_GPIO_SetPinOutputType
327 * @param GPIOx GPIO Port
328 * @param PinMask This parameter can be a combination of the following values:
329 * @arg @ref LL_GPIO_PIN_0
330 * @arg @ref LL_GPIO_PIN_1
331 * @arg @ref LL_GPIO_PIN_2
332 * @arg @ref LL_GPIO_PIN_3
333 * @arg @ref LL_GPIO_PIN_4
334 * @arg @ref LL_GPIO_PIN_5
335 * @arg @ref LL_GPIO_PIN_6
336 * @arg @ref LL_GPIO_PIN_7
337 * @arg @ref LL_GPIO_PIN_8
338 * @arg @ref LL_GPIO_PIN_9
339 * @arg @ref LL_GPIO_PIN_10
340 * @arg @ref LL_GPIO_PIN_11
341 * @arg @ref LL_GPIO_PIN_12
342 * @arg @ref LL_GPIO_PIN_13
343 * @arg @ref LL_GPIO_PIN_14
344 * @arg @ref LL_GPIO_PIN_15
345 * @arg @ref LL_GPIO_PIN_ALL
346 * @param OutputType This parameter can be one of the following values:
347 * @arg @ref LL_GPIO_OUTPUT_PUSHPULL
348 * @arg @ref LL_GPIO_OUTPUT_OPENDRAIN
349 * @retval None
350 */
351__STATIC_INLINE void LL_GPIO_SetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t PinMask, uint32_t OutputType)
352{
353 MODIFY_REG(GPIOx->OTYPER, PinMask, (PinMask * OutputType));
354}
355
356/**
357 * @brief Return gpio output type for several pins on dedicated port.
358 * @note Output type as to be set when gpio pin is in output or
359 * alternate modes. Possible type are Push-pull or Open-drain.
360 * @note Warning: only one pin can be passed as parameter.
361 * @rmtoll OTYPER OTy LL_GPIO_GetPinOutputType
362 * @param GPIOx GPIO Port
363 * @param Pin This parameter can be one of the following values:
364 * @arg @ref LL_GPIO_PIN_0
365 * @arg @ref LL_GPIO_PIN_1
366 * @arg @ref LL_GPIO_PIN_2
367 * @arg @ref LL_GPIO_PIN_3
368 * @arg @ref LL_GPIO_PIN_4
369 * @arg @ref LL_GPIO_PIN_5
370 * @arg @ref LL_GPIO_PIN_6
371 * @arg @ref LL_GPIO_PIN_7
372 * @arg @ref LL_GPIO_PIN_8
373 * @arg @ref LL_GPIO_PIN_9
374 * @arg @ref LL_GPIO_PIN_10
375 * @arg @ref LL_GPIO_PIN_11
376 * @arg @ref LL_GPIO_PIN_12
377 * @arg @ref LL_GPIO_PIN_13
378 * @arg @ref LL_GPIO_PIN_14
379 * @arg @ref LL_GPIO_PIN_15
380 * @arg @ref LL_GPIO_PIN_ALL
381 * @retval Returned value can be one of the following values:
382 * @arg @ref LL_GPIO_OUTPUT_PUSHPULL
383 * @arg @ref LL_GPIO_OUTPUT_OPENDRAIN
384 */
385__STATIC_INLINE uint32_t LL_GPIO_GetPinOutputType(GPIO_TypeDef *GPIOx, uint32_t Pin)
386{
387 return (uint32_t)(READ_BIT(GPIOx->OTYPER, Pin) / Pin);
388}
389
390/**
391 * @brief Configure gpio speed for a dedicated pin on dedicated port.
392 * @note I/O speed can be Low, Medium, Fast or High speed.
393 * @note Warning: only one pin can be passed as parameter.
394 * @note Refer to datasheet for frequency specifications and the power
395 * supply and load conditions for each speed.
396 * @rmtoll OSPEEDR OSPEEDy LL_GPIO_SetPinSpeed
397 * @param GPIOx GPIO Port
398 * @param Pin This parameter can be one of the following values:
399 * @arg @ref LL_GPIO_PIN_0
400 * @arg @ref LL_GPIO_PIN_1
401 * @arg @ref LL_GPIO_PIN_2
402 * @arg @ref LL_GPIO_PIN_3
403 * @arg @ref LL_GPIO_PIN_4
404 * @arg @ref LL_GPIO_PIN_5
405 * @arg @ref LL_GPIO_PIN_6
406 * @arg @ref LL_GPIO_PIN_7
407 * @arg @ref LL_GPIO_PIN_8
408 * @arg @ref LL_GPIO_PIN_9
409 * @arg @ref LL_GPIO_PIN_10
410 * @arg @ref LL_GPIO_PIN_11
411 * @arg @ref LL_GPIO_PIN_12
412 * @arg @ref LL_GPIO_PIN_13
413 * @arg @ref LL_GPIO_PIN_14
414 * @arg @ref LL_GPIO_PIN_15
415 * @param Speed This parameter can be one of the following values:
416 * @arg @ref LL_GPIO_SPEED_FREQ_LOW
417 * @arg @ref LL_GPIO_SPEED_FREQ_MEDIUM
418 * @arg @ref LL_GPIO_SPEED_FREQ_HIGH
419 * @arg @ref LL_GPIO_SPEED_FREQ_VERY_HIGH
420 * @retval None
421 */
422__STATIC_INLINE void LL_GPIO_SetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Speed)
423{
424 MODIFY_REG(GPIOx->OSPEEDR, ((Pin * Pin) * GPIO_OSPEEDR_OSPEED0), ((Pin * Pin) * Speed));
425}
426
427/**
428 * @brief Return gpio speed for a dedicated pin on dedicated port.
429 * @note I/O speed can be Low, Medium, Fast or High speed.
430 * @note Warning: only one pin can be passed as parameter.
431 * @note Refer to datasheet for frequency specifications and the power
432 * supply and load conditions for each speed.
433 * @rmtoll OSPEEDR OSPEEDy LL_GPIO_GetPinSpeed
434 * @param GPIOx GPIO Port
435 * @param Pin This parameter can be one of the following values:
436 * @arg @ref LL_GPIO_PIN_0
437 * @arg @ref LL_GPIO_PIN_1
438 * @arg @ref LL_GPIO_PIN_2
439 * @arg @ref LL_GPIO_PIN_3
440 * @arg @ref LL_GPIO_PIN_4
441 * @arg @ref LL_GPIO_PIN_5
442 * @arg @ref LL_GPIO_PIN_6
443 * @arg @ref LL_GPIO_PIN_7
444 * @arg @ref LL_GPIO_PIN_8
445 * @arg @ref LL_GPIO_PIN_9
446 * @arg @ref LL_GPIO_PIN_10
447 * @arg @ref LL_GPIO_PIN_11
448 * @arg @ref LL_GPIO_PIN_12
449 * @arg @ref LL_GPIO_PIN_13
450 * @arg @ref LL_GPIO_PIN_14
451 * @arg @ref LL_GPIO_PIN_15
452 * @retval Returned value can be one of the following values:
453 * @arg @ref LL_GPIO_SPEED_FREQ_LOW
454 * @arg @ref LL_GPIO_SPEED_FREQ_MEDIUM
455 * @arg @ref LL_GPIO_SPEED_FREQ_HIGH
456 * @arg @ref LL_GPIO_SPEED_FREQ_VERY_HIGH
457 */
458__STATIC_INLINE uint32_t LL_GPIO_GetPinSpeed(GPIO_TypeDef *GPIOx, uint32_t Pin)
459{
460 return (uint32_t)(READ_BIT(GPIOx->OSPEEDR, ((Pin * Pin) * GPIO_OSPEEDR_OSPEED0)) / (Pin * Pin));
461}
462
463/**
464 * @brief Configure gpio pull-up or pull-down for a dedicated pin on a dedicated port.
465 * @note Warning: only one pin can be passed as parameter.
466 * @rmtoll PUPDR PUPDy LL_GPIO_SetPinPull
467 * @param GPIOx GPIO Port
468 * @param Pin This parameter can be one of the following values:
469 * @arg @ref LL_GPIO_PIN_0
470 * @arg @ref LL_GPIO_PIN_1
471 * @arg @ref LL_GPIO_PIN_2
472 * @arg @ref LL_GPIO_PIN_3
473 * @arg @ref LL_GPIO_PIN_4
474 * @arg @ref LL_GPIO_PIN_5
475 * @arg @ref LL_GPIO_PIN_6
476 * @arg @ref LL_GPIO_PIN_7
477 * @arg @ref LL_GPIO_PIN_8
478 * @arg @ref LL_GPIO_PIN_9
479 * @arg @ref LL_GPIO_PIN_10
480 * @arg @ref LL_GPIO_PIN_11
481 * @arg @ref LL_GPIO_PIN_12
482 * @arg @ref LL_GPIO_PIN_13
483 * @arg @ref LL_GPIO_PIN_14
484 * @arg @ref LL_GPIO_PIN_15
485 * @param Pull This parameter can be one of the following values:
486 * @arg @ref LL_GPIO_PULL_NO
487 * @arg @ref LL_GPIO_PULL_UP
488 * @arg @ref LL_GPIO_PULL_DOWN
489 * @retval None
490 */
491__STATIC_INLINE void LL_GPIO_SetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Pull)
492{
493 MODIFY_REG(GPIOx->PUPDR, ((Pin * Pin) * GPIO_PUPDR_PUPD0), ((Pin * Pin) * Pull));
494}
495
496/**
497 * @brief Return gpio pull-up or pull-down for a dedicated pin on a dedicated port
498 * @note Warning: only one pin can be passed as parameter.
499 * @rmtoll PUPDR PUPDy LL_GPIO_GetPinPull
500 * @param GPIOx GPIO Port
501 * @param Pin This parameter can be one of the following values:
502 * @arg @ref LL_GPIO_PIN_0
503 * @arg @ref LL_GPIO_PIN_1
504 * @arg @ref LL_GPIO_PIN_2
505 * @arg @ref LL_GPIO_PIN_3
506 * @arg @ref LL_GPIO_PIN_4
507 * @arg @ref LL_GPIO_PIN_5
508 * @arg @ref LL_GPIO_PIN_6
509 * @arg @ref LL_GPIO_PIN_7
510 * @arg @ref LL_GPIO_PIN_8
511 * @arg @ref LL_GPIO_PIN_9
512 * @arg @ref LL_GPIO_PIN_10
513 * @arg @ref LL_GPIO_PIN_11
514 * @arg @ref LL_GPIO_PIN_12
515 * @arg @ref LL_GPIO_PIN_13
516 * @arg @ref LL_GPIO_PIN_14
517 * @arg @ref LL_GPIO_PIN_15
518 * @retval Returned value can be one of the following values:
519 * @arg @ref LL_GPIO_PULL_NO
520 * @arg @ref LL_GPIO_PULL_UP
521 * @arg @ref LL_GPIO_PULL_DOWN
522 */
523__STATIC_INLINE uint32_t LL_GPIO_GetPinPull(GPIO_TypeDef *GPIOx, uint32_t Pin)
524{
525 return (uint32_t)(READ_BIT(GPIOx->PUPDR, ((Pin * Pin) * GPIO_PUPDR_PUPD0)) / (Pin * Pin));
526}
527
528/**
529 * @brief Configure gpio alternate function of a dedicated pin from 0 to 7 for a dedicated port.
530 * @note Possible values are from AF0 to AF7 depending on target.
531 * @note Warning: only one pin can be passed as parameter.
532 * @rmtoll AFRL AFSELy LL_GPIO_SetAFPin_0_7
533 * @param GPIOx GPIO Port
534 * @param Pin This parameter can be one of the following values:
535 * @arg @ref LL_GPIO_PIN_0
536 * @arg @ref LL_GPIO_PIN_1
537 * @arg @ref LL_GPIO_PIN_2
538 * @arg @ref LL_GPIO_PIN_3
539 * @arg @ref LL_GPIO_PIN_4
540 * @arg @ref LL_GPIO_PIN_5
541 * @arg @ref LL_GPIO_PIN_6
542 * @arg @ref LL_GPIO_PIN_7
543 * @param Alternate This parameter can be one of the following values:
544 * @arg @ref LL_GPIO_AF_0
545 * @arg @ref LL_GPIO_AF_1
546 * @arg @ref LL_GPIO_AF_2
547 * @arg @ref LL_GPIO_AF_3
548 * @arg @ref LL_GPIO_AF_4
549 * @arg @ref LL_GPIO_AF_5
550 * @arg @ref LL_GPIO_AF_6
551 * @arg @ref LL_GPIO_AF_7
552 * @retval None
553 */
554__STATIC_INLINE void LL_GPIO_SetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
555{
556 MODIFY_REG(GPIOx->AFR[0], ((((Pin * Pin) * Pin) * Pin) * GPIO_AFRL_AFSEL0),
557 ((((Pin * Pin) * Pin) * Pin) * Alternate));
558}
559
560/**
561 * @brief Return gpio alternate function of a dedicated pin from 0 to 7 for a dedicated port.
562 * @rmtoll AFRL AFSELy LL_GPIO_GetAFPin_0_7
563 * @param GPIOx GPIO Port
564 * @param Pin This parameter can be one of the following values:
565 * @arg @ref LL_GPIO_PIN_0
566 * @arg @ref LL_GPIO_PIN_1
567 * @arg @ref LL_GPIO_PIN_2
568 * @arg @ref LL_GPIO_PIN_3
569 * @arg @ref LL_GPIO_PIN_4
570 * @arg @ref LL_GPIO_PIN_5
571 * @arg @ref LL_GPIO_PIN_6
572 * @arg @ref LL_GPIO_PIN_7
573 * @retval Returned value can be one of the following values:
574 * @arg @ref LL_GPIO_AF_0
575 * @arg @ref LL_GPIO_AF_1
576 * @arg @ref LL_GPIO_AF_2
577 * @arg @ref LL_GPIO_AF_3
578 * @arg @ref LL_GPIO_AF_4
579 * @arg @ref LL_GPIO_AF_5
580 * @arg @ref LL_GPIO_AF_6
581 * @arg @ref LL_GPIO_AF_7
582 */
583__STATIC_INLINE uint32_t LL_GPIO_GetAFPin_0_7(GPIO_TypeDef *GPIOx, uint32_t Pin)
584{
585 return (uint32_t)(READ_BIT(GPIOx->AFR[0],
586 ((((Pin * Pin) * Pin) * Pin) * GPIO_AFRL_AFSEL0)) / (((Pin * Pin) * Pin) * Pin));
587}
588
589/**
590 * @brief Configure gpio alternate function of a dedicated pin from 8 to 15 for a dedicated port.
591 * @note Possible values are from AF0 to AF7 depending on target.
592 * @note Warning: only one pin can be passed as parameter.
593 * @rmtoll AFRH AFSELy LL_GPIO_SetAFPin_8_15
594 * @param GPIOx GPIO Port
595 * @param Pin This parameter can be one of the following values:
596 * @arg @ref LL_GPIO_PIN_8
597 * @arg @ref LL_GPIO_PIN_9
598 * @arg @ref LL_GPIO_PIN_10
599 * @arg @ref LL_GPIO_PIN_11
600 * @arg @ref LL_GPIO_PIN_12
601 * @arg @ref LL_GPIO_PIN_13
602 * @arg @ref LL_GPIO_PIN_14
603 * @arg @ref LL_GPIO_PIN_15
604 * @param Alternate This parameter can be one of the following values:
605 * @arg @ref LL_GPIO_AF_0
606 * @arg @ref LL_GPIO_AF_1
607 * @arg @ref LL_GPIO_AF_2
608 * @arg @ref LL_GPIO_AF_3
609 * @arg @ref LL_GPIO_AF_4
610 * @arg @ref LL_GPIO_AF_5
611 * @arg @ref LL_GPIO_AF_6
612 * @arg @ref LL_GPIO_AF_7
613 * @retval None
614 */
615__STATIC_INLINE void LL_GPIO_SetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin, uint32_t Alternate)
616{
617 MODIFY_REG(GPIOx->AFR[1], (((((Pin >> 8U) * (Pin >> 8U)) * (Pin >> 8U)) * (Pin >> 8U)) * GPIO_AFRH_AFSEL8),
618 (((((Pin >> 8U) * (Pin >> 8U)) * (Pin >> 8U)) * (Pin >> 8U)) * Alternate));
619}
620
621/**
622 * @brief Return gpio alternate function of a dedicated pin from 8 to 15 for a dedicated port.
623 * @note Possible values are from AF0 to AF7 depending on target.
624 * @rmtoll AFRH AFSELy LL_GPIO_GetAFPin_8_15
625 * @param GPIOx GPIO Port
626 * @param Pin This parameter can be one of the following values:
627 * @arg @ref LL_GPIO_PIN_8
628 * @arg @ref LL_GPIO_PIN_9
629 * @arg @ref LL_GPIO_PIN_10
630 * @arg @ref LL_GPIO_PIN_11
631 * @arg @ref LL_GPIO_PIN_12
632 * @arg @ref LL_GPIO_PIN_13
633 * @arg @ref LL_GPIO_PIN_14
634 * @arg @ref LL_GPIO_PIN_15
635 * @retval Returned value can be one of the following values:
636 * @arg @ref LL_GPIO_AF_0
637 * @arg @ref LL_GPIO_AF_1
638 * @arg @ref LL_GPIO_AF_2
639 * @arg @ref LL_GPIO_AF_3
640 * @arg @ref LL_GPIO_AF_4
641 * @arg @ref LL_GPIO_AF_5
642 * @arg @ref LL_GPIO_AF_6
643 * @arg @ref LL_GPIO_AF_7
644 */
645__STATIC_INLINE uint32_t LL_GPIO_GetAFPin_8_15(GPIO_TypeDef *GPIOx, uint32_t Pin)
646{
647 return (uint32_t)(READ_BIT(GPIOx->AFR[1],
648 (((((Pin >> 8U) * (Pin >> 8U)) * (Pin >> 8U)) * (Pin >> 8U)) * GPIO_AFRH_AFSEL8)) / ((((Pin >> 8U) *
649 (Pin >> 8U)) * (Pin >> 8U)) * (Pin >> 8U)));
650}
651
652
653/**
654 * @brief Lock configuration of several pins for a dedicated port.
655 * @note When the lock sequence has been applied on a port bit, the
656 * value of this port bit can no longer be modified until the
657 * next reset.
658 * @note Each lock bit freezes a specific configuration register
659 * (control and alternate function registers).
660 * @rmtoll LCKR LCKK LL_GPIO_LockPin
661 * @param GPIOx GPIO Port
662 * @param PinMask This parameter can be a combination of the following values:
663 * @arg @ref LL_GPIO_PIN_0
664 * @arg @ref LL_GPIO_PIN_1
665 * @arg @ref LL_GPIO_PIN_2
666 * @arg @ref LL_GPIO_PIN_3
667 * @arg @ref LL_GPIO_PIN_4
668 * @arg @ref LL_GPIO_PIN_5
669 * @arg @ref LL_GPIO_PIN_6
670 * @arg @ref LL_GPIO_PIN_7
671 * @arg @ref LL_GPIO_PIN_8
672 * @arg @ref LL_GPIO_PIN_9
673 * @arg @ref LL_GPIO_PIN_10
674 * @arg @ref LL_GPIO_PIN_11
675 * @arg @ref LL_GPIO_PIN_12
676 * @arg @ref LL_GPIO_PIN_13
677 * @arg @ref LL_GPIO_PIN_14
678 * @arg @ref LL_GPIO_PIN_15
679 * @arg @ref LL_GPIO_PIN_ALL
680 * @retval None
681 */
682__STATIC_INLINE void LL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
683{
684 __IO uint32_t temp;
685 WRITE_REG(GPIOx->LCKR, GPIO_LCKR_LCKK | PinMask);
686 WRITE_REG(GPIOx->LCKR, PinMask);
687 WRITE_REG(GPIOx->LCKR, GPIO_LCKR_LCKK | PinMask);
688 /* Read LCKK register. This read is mandatory to complete key lock sequence */
689 temp = READ_REG(GPIOx->LCKR);
690 (void) temp;
691}
692
693/**
694 * @brief Return 1 if all pins passed as parameter, of a dedicated port, are locked. else Return 0.
695 * @rmtoll LCKR LCKy LL_GPIO_IsPinLocked
696 * @param GPIOx GPIO Port
697 * @param PinMask This parameter can be a combination of the following values:
698 * @arg @ref LL_GPIO_PIN_0
699 * @arg @ref LL_GPIO_PIN_1
700 * @arg @ref LL_GPIO_PIN_2
701 * @arg @ref LL_GPIO_PIN_3
702 * @arg @ref LL_GPIO_PIN_4
703 * @arg @ref LL_GPIO_PIN_5
704 * @arg @ref LL_GPIO_PIN_6
705 * @arg @ref LL_GPIO_PIN_7
706 * @arg @ref LL_GPIO_PIN_8
707 * @arg @ref LL_GPIO_PIN_9
708 * @arg @ref LL_GPIO_PIN_10
709 * @arg @ref LL_GPIO_PIN_11
710 * @arg @ref LL_GPIO_PIN_12
711 * @arg @ref LL_GPIO_PIN_13
712 * @arg @ref LL_GPIO_PIN_14
713 * @arg @ref LL_GPIO_PIN_15
714 * @arg @ref LL_GPIO_PIN_ALL
715 * @retval State of bit (1 or 0).
716 */
717__STATIC_INLINE uint32_t LL_GPIO_IsPinLocked(GPIO_TypeDef *GPIOx, uint32_t PinMask)
718{
719 return ((READ_BIT(GPIOx->LCKR, PinMask) == (PinMask)) ? 1UL : 0UL);
720}
721
722/**
723 * @brief Return 1 if one of the pin of a dedicated port is locked. else return 0.
724 * @rmtoll LCKR LCKK LL_GPIO_IsAnyPinLocked
725 * @param GPIOx GPIO Port
726 * @retval State of bit (1 or 0).
727 */
728__STATIC_INLINE uint32_t LL_GPIO_IsAnyPinLocked(GPIO_TypeDef *GPIOx)
729{
730 return ((READ_BIT(GPIOx->LCKR, GPIO_LCKR_LCKK) == (GPIO_LCKR_LCKK)) ? 1UL : 0UL);
731}
732
733/**
734 * @}
735 */
736
737/** @defgroup GPIO_LL_EF_Data_Access Data Access
738 * @{
739 */
740
741/**
742 * @brief Return full input data register value for a dedicated port.
743 * @rmtoll IDR IDy LL_GPIO_ReadInputPort
744 * @param GPIOx GPIO Port
745 * @retval Input data register value of port
746 */
747__STATIC_INLINE uint32_t LL_GPIO_ReadInputPort(GPIO_TypeDef *GPIOx)
748{
749 return (uint32_t)(READ_REG(GPIOx->IDR));
750}
751
752/**
753 * @brief Return if input data level for several pins of dedicated port is high or low.
754 * @rmtoll IDR IDy LL_GPIO_IsInputPinSet
755 * @param GPIOx GPIO Port
756 * @param PinMask This parameter can be a combination of the following values:
757 * @arg @ref LL_GPIO_PIN_0
758 * @arg @ref LL_GPIO_PIN_1
759 * @arg @ref LL_GPIO_PIN_2
760 * @arg @ref LL_GPIO_PIN_3
761 * @arg @ref LL_GPIO_PIN_4
762 * @arg @ref LL_GPIO_PIN_5
763 * @arg @ref LL_GPIO_PIN_6
764 * @arg @ref LL_GPIO_PIN_7
765 * @arg @ref LL_GPIO_PIN_8
766 * @arg @ref LL_GPIO_PIN_9
767 * @arg @ref LL_GPIO_PIN_10
768 * @arg @ref LL_GPIO_PIN_11
769 * @arg @ref LL_GPIO_PIN_12
770 * @arg @ref LL_GPIO_PIN_13
771 * @arg @ref LL_GPIO_PIN_14
772 * @arg @ref LL_GPIO_PIN_15
773 * @arg @ref LL_GPIO_PIN_ALL
774 * @retval State of bit (1 or 0).
775 */
776__STATIC_INLINE uint32_t LL_GPIO_IsInputPinSet(GPIO_TypeDef *GPIOx, uint32_t PinMask)
777{
778 return ((READ_BIT(GPIOx->IDR, PinMask) == (PinMask)) ? 1UL : 0UL);
779}
780
781/**
782 * @brief Write output data register for the port.
783 * @rmtoll ODR ODy LL_GPIO_WriteOutputPort
784 * @param GPIOx GPIO Port
785 * @param PortValue Level value for each pin of the port
786 * @retval None
787 */
788__STATIC_INLINE void LL_GPIO_WriteOutputPort(GPIO_TypeDef *GPIOx, uint32_t PortValue)
789{
790 WRITE_REG(GPIOx->ODR, PortValue);
791}
792
793/**
794 * @brief Return full output data register value for a dedicated port.
795 * @rmtoll ODR ODy LL_GPIO_ReadOutputPort
796 * @param GPIOx GPIO Port
797 * @retval Output data register value of port
798 */
799__STATIC_INLINE uint32_t LL_GPIO_ReadOutputPort(GPIO_TypeDef *GPIOx)
800{
801 return (uint32_t)(READ_REG(GPIOx->ODR));
802}
803
804/**
805 * @brief Return if input data level for several pins of dedicated port is high or low.
806 * @rmtoll ODR ODy LL_GPIO_IsOutputPinSet
807 * @param GPIOx GPIO Port
808 * @param PinMask This parameter can be a combination of the following values:
809 * @arg @ref LL_GPIO_PIN_0
810 * @arg @ref LL_GPIO_PIN_1
811 * @arg @ref LL_GPIO_PIN_2
812 * @arg @ref LL_GPIO_PIN_3
813 * @arg @ref LL_GPIO_PIN_4
814 * @arg @ref LL_GPIO_PIN_5
815 * @arg @ref LL_GPIO_PIN_6
816 * @arg @ref LL_GPIO_PIN_7
817 * @arg @ref LL_GPIO_PIN_8
818 * @arg @ref LL_GPIO_PIN_9
819 * @arg @ref LL_GPIO_PIN_10
820 * @arg @ref LL_GPIO_PIN_11
821 * @arg @ref LL_GPIO_PIN_12
822 * @arg @ref LL_GPIO_PIN_13
823 * @arg @ref LL_GPIO_PIN_14
824 * @arg @ref LL_GPIO_PIN_15
825 * @arg @ref LL_GPIO_PIN_ALL
826 * @retval State of bit (1 or 0).
827 */
828__STATIC_INLINE uint32_t LL_GPIO_IsOutputPinSet(GPIO_TypeDef *GPIOx, uint32_t PinMask)
829{
830 return ((READ_BIT(GPIOx->ODR, PinMask) == (PinMask)) ? 1UL : 0UL);
831}
832
833/**
834 * @brief Set several pins to high level on dedicated gpio port.
835 * @rmtoll BSRR BSy LL_GPIO_SetOutputPin
836 * @param GPIOx GPIO Port
837 * @param PinMask This parameter can be a combination of the following values:
838 * @arg @ref LL_GPIO_PIN_0
839 * @arg @ref LL_GPIO_PIN_1
840 * @arg @ref LL_GPIO_PIN_2
841 * @arg @ref LL_GPIO_PIN_3
842 * @arg @ref LL_GPIO_PIN_4
843 * @arg @ref LL_GPIO_PIN_5
844 * @arg @ref LL_GPIO_PIN_6
845 * @arg @ref LL_GPIO_PIN_7
846 * @arg @ref LL_GPIO_PIN_8
847 * @arg @ref LL_GPIO_PIN_9
848 * @arg @ref LL_GPIO_PIN_10
849 * @arg @ref LL_GPIO_PIN_11
850 * @arg @ref LL_GPIO_PIN_12
851 * @arg @ref LL_GPIO_PIN_13
852 * @arg @ref LL_GPIO_PIN_14
853 * @arg @ref LL_GPIO_PIN_15
854 * @arg @ref LL_GPIO_PIN_ALL
855 * @retval None
856 */
857__STATIC_INLINE void LL_GPIO_SetOutputPin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
858{
859 WRITE_REG(GPIOx->BSRR, PinMask);
860}
861
862/**
863 * @brief Set several pins to low level on dedicated gpio port.
864 * @rmtoll BRR BRy LL_GPIO_ResetOutputPin
865 * @param GPIOx GPIO Port
866 * @param PinMask This parameter can be a combination of the following values:
867 * @arg @ref LL_GPIO_PIN_0
868 * @arg @ref LL_GPIO_PIN_1
869 * @arg @ref LL_GPIO_PIN_2
870 * @arg @ref LL_GPIO_PIN_3
871 * @arg @ref LL_GPIO_PIN_4
872 * @arg @ref LL_GPIO_PIN_5
873 * @arg @ref LL_GPIO_PIN_6
874 * @arg @ref LL_GPIO_PIN_7
875 * @arg @ref LL_GPIO_PIN_8
876 * @arg @ref LL_GPIO_PIN_9
877 * @arg @ref LL_GPIO_PIN_10
878 * @arg @ref LL_GPIO_PIN_11
879 * @arg @ref LL_GPIO_PIN_12
880 * @arg @ref LL_GPIO_PIN_13
881 * @arg @ref LL_GPIO_PIN_14
882 * @arg @ref LL_GPIO_PIN_15
883 * @arg @ref LL_GPIO_PIN_ALL
884 * @retval None
885 */
886__STATIC_INLINE void LL_GPIO_ResetOutputPin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
887{
888 WRITE_REG(GPIOx->BRR, PinMask);
889}
890
891/**
892 * @brief Toggle data value for several pin of dedicated port.
893 * @rmtoll ODR ODy LL_GPIO_TogglePin
894 * @param GPIOx GPIO Port
895 * @param PinMask This parameter can be a combination of the following values:
896 * @arg @ref LL_GPIO_PIN_0
897 * @arg @ref LL_GPIO_PIN_1
898 * @arg @ref LL_GPIO_PIN_2
899 * @arg @ref LL_GPIO_PIN_3
900 * @arg @ref LL_GPIO_PIN_4
901 * @arg @ref LL_GPIO_PIN_5
902 * @arg @ref LL_GPIO_PIN_6
903 * @arg @ref LL_GPIO_PIN_7
904 * @arg @ref LL_GPIO_PIN_8
905 * @arg @ref LL_GPIO_PIN_9
906 * @arg @ref LL_GPIO_PIN_10
907 * @arg @ref LL_GPIO_PIN_11
908 * @arg @ref LL_GPIO_PIN_12
909 * @arg @ref LL_GPIO_PIN_13
910 * @arg @ref LL_GPIO_PIN_14
911 * @arg @ref LL_GPIO_PIN_15
912 * @arg @ref LL_GPIO_PIN_ALL
913 * @retval None
914 */
915__STATIC_INLINE void LL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint32_t PinMask)
916{
917 uint32_t odr = READ_REG(GPIOx->ODR);
918 WRITE_REG(GPIOx->BSRR, ((odr & PinMask) << 16u) | (~odr & PinMask));
919}
920
921
922/**
923 * @}
924 */
925
926#if defined(USE_FULL_LL_DRIVER)
927/** @defgroup GPIO_LL_EF_Init Initialization and de-initialization functions
928 * @{
929 */
930
931ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx);
932ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct);
933void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct);
934
935/**
936 * @}
937 */
938#endif /* USE_FULL_LL_DRIVER */
939
940/**
941 * @}
942 */
943
944/**
945 * @}
946 */
947
948#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) */
949/**
950 * @}
951 */
952
953#ifdef __cplusplus
954}
955#endif
956
957#endif /* STM32G0xx_LL_GPIO_H */
958
Note: See TracBrowser for help on using the repository browser.