2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_gpio.h
\r
4 * @author MCD Application Team
\r
5 * @brief Header file of GPIO HAL module.
\r
6 ******************************************************************************
\r
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
10 * All rights reserved.</center></h2>
\r
12 * This software component is licensed by ST under BSD 3-Clause license,
\r
13 * the "License"; You may not use this file except in compliance with the
\r
14 * License. You may obtain a copy of the License at:
\r
15 * opensource.org/licenses/BSD-3-Clause
\r
17 ******************************************************************************
\r
20 /* Define to prevent recursive inclusion -------------------------------------*/
\r
21 #ifndef __STM32L4xx_HAL_GPIO_H
\r
22 #define __STM32L4xx_HAL_GPIO_H
\r
28 /* Includes ------------------------------------------------------------------*/
\r
29 #include "stm32l4xx_hal_def.h"
\r
31 /** @addtogroup STM32L4xx_HAL_Driver
\r
35 /** @addtogroup GPIO
\r
39 /* Exported types ------------------------------------------------------------*/
\r
41 /** @defgroup GPIO_Exported_Types GPIO Exported Types
\r
45 * @brief GPIO Init structure definition
\r
49 uint32_t Pin; /*!< Specifies the GPIO pins to be configured.
\r
50 This parameter can be any value of @ref GPIO_pins */
\r
52 uint32_t Mode; /*!< Specifies the operating mode for the selected pins.
\r
53 This parameter can be a value of @ref GPIO_mode */
\r
55 uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
\r
56 This parameter can be a value of @ref GPIO_pull */
\r
58 uint32_t Speed; /*!< Specifies the speed for the selected pins.
\r
59 This parameter can be a value of @ref GPIO_speed */
\r
61 uint32_t Alternate; /*!< Peripheral to be connected to the selected pins
\r
62 This parameter can be a value of @ref GPIOEx_Alternate_function_selection */
\r
66 * @brief GPIO Bit SET and Bit RESET enumeration
\r
70 GPIO_PIN_RESET = 0U,
\r
77 /* Exported constants --------------------------------------------------------*/
\r
78 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants
\r
81 /** @defgroup GPIO_pins GPIO pins
\r
84 #define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */
\r
85 #define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */
\r
86 #define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */
\r
87 #define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */
\r
88 #define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */
\r
89 #define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */
\r
90 #define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */
\r
91 #define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */
\r
92 #define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */
\r
93 #define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */
\r
94 #define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */
\r
95 #define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */
\r
96 #define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */
\r
97 #define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */
\r
98 #define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */
\r
99 #define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */
\r
100 #define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */
\r
102 #define GPIO_PIN_MASK (0x0000FFFFu) /* PIN mask for assert test */
\r
107 /** @defgroup GPIO_mode GPIO mode
\r
108 * @brief GPIO Configuration Mode
\r
109 * Elements values convention: 0xX0yz00YZ
\r
110 * - X : GPIO mode or EXTI Mode
\r
111 * - y : External IT or Event trigger detection
\r
112 * - z : IO configuration on External IT or Event
\r
113 * - Y : Output type (Push Pull or Open Drain)
\r
114 * - Z : IO Direction mode (Input, Output, Alternate or Analog)
\r
117 #define GPIO_MODE_INPUT (0x00000000u) /*!< Input Floating Mode */
\r
118 #define GPIO_MODE_OUTPUT_PP (0x00000001u) /*!< Output Push Pull Mode */
\r
119 #define GPIO_MODE_OUTPUT_OD (0x00000011u) /*!< Output Open Drain Mode */
\r
120 #define GPIO_MODE_AF_PP (0x00000002u) /*!< Alternate Function Push Pull Mode */
\r
121 #define GPIO_MODE_AF_OD (0x00000012u) /*!< Alternate Function Open Drain Mode */
\r
122 #define GPIO_MODE_ANALOG (0x00000003u) /*!< Analog Mode */
\r
123 #define GPIO_MODE_ANALOG_ADC_CONTROL (0x0000000Bu) /*!< Analog Mode for ADC conversion */
\r
124 #define GPIO_MODE_IT_RISING (0x10110000u) /*!< External Interrupt Mode with Rising edge trigger detection */
\r
125 #define GPIO_MODE_IT_FALLING (0x10210000u) /*!< External Interrupt Mode with Falling edge trigger detection */
\r
126 #define GPIO_MODE_IT_RISING_FALLING (0x10310000u) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */
\r
127 #define GPIO_MODE_EVT_RISING (0x10120000u) /*!< External Event Mode with Rising edge trigger detection */
\r
128 #define GPIO_MODE_EVT_FALLING (0x10220000u) /*!< External Event Mode with Falling edge trigger detection */
\r
129 #define GPIO_MODE_EVT_RISING_FALLING (0x10320000u) /*!< External Event Mode with Rising/Falling edge trigger detection */
\r
134 /** @defgroup GPIO_speed GPIO speed
\r
135 * @brief GPIO Output Maximum frequency
\r
138 #define GPIO_SPEED_FREQ_LOW (0x00000000u) /*!< range up to 5 MHz, please refer to the product datasheet */
\r
139 #define GPIO_SPEED_FREQ_MEDIUM (0x00000001u) /*!< range 5 MHz to 25 MHz, please refer to the product datasheet */
\r
140 #define GPIO_SPEED_FREQ_HIGH (0x00000002u) /*!< range 25 MHz to 50 MHz, please refer to the product datasheet */
\r
141 #define GPIO_SPEED_FREQ_VERY_HIGH (0x00000003u) /*!< range 50 MHz to 80 MHz, please refer to the product datasheet */
\r
146 /** @defgroup GPIO_pull GPIO pull
\r
147 * @brief GPIO Pull-Up or Pull-Down Activation
\r
150 #define GPIO_NOPULL (0x00000000u) /*!< No Pull-up or Pull-down activation */
\r
151 #define GPIO_PULLUP (0x00000001u) /*!< Pull-up activation */
\r
152 #define GPIO_PULLDOWN (0x00000002u) /*!< Pull-down activation */
\r
161 /* Exported macro ------------------------------------------------------------*/
\r
162 /** @defgroup GPIO_Exported_Macros GPIO Exported Macros
\r
167 * @brief Check whether the specified EXTI line flag is set or not.
\r
168 * @param __EXTI_LINE__: specifies the EXTI line flag to check.
\r
169 * This parameter can be GPIO_PIN_x where x can be(0..15)
\r
170 * @retval The new state of __EXTI_LINE__ (SET or RESET).
\r
172 #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR1 & (__EXTI_LINE__))
\r
175 * @brief Clear the EXTI's line pending flags.
\r
176 * @param __EXTI_LINE__: specifies the EXTI lines flags to clear.
\r
177 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
\r
180 #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR1 = (__EXTI_LINE__))
\r
183 * @brief Check whether the specified EXTI line is asserted or not.
\r
184 * @param __EXTI_LINE__: specifies the EXTI line to check.
\r
185 * This parameter can be GPIO_PIN_x where x can be(0..15)
\r
186 * @retval The new state of __EXTI_LINE__ (SET or RESET).
\r
188 #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR1 & (__EXTI_LINE__))
\r
191 * @brief Clear the EXTI's line pending bits.
\r
192 * @param __EXTI_LINE__: specifies the EXTI lines to clear.
\r
193 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
\r
196 #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR1 = (__EXTI_LINE__))
\r
199 * @brief Generate a Software interrupt on selected EXTI line.
\r
200 * @param __EXTI_LINE__: specifies the EXTI line to check.
\r
201 * This parameter can be GPIO_PIN_x where x can be(0..15)
\r
204 #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER1 |= (__EXTI_LINE__))
\r
210 /* Private macros ------------------------------------------------------------*/
\r
211 /** @addtogroup GPIO_Private_Macros GPIO Private Macros
\r
214 #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET))
\r
216 #define IS_GPIO_PIN(__PIN__) ((((uint32_t)(__PIN__) & GPIO_PIN_MASK) != 0x00U) &&\
\r
217 (((uint32_t)(__PIN__) & ~GPIO_PIN_MASK) == 0x00U))
\r
219 #define IS_GPIO_MODE(__MODE__) (((__MODE__) == GPIO_MODE_INPUT) ||\
\r
220 ((__MODE__) == GPIO_MODE_OUTPUT_PP) ||\
\r
221 ((__MODE__) == GPIO_MODE_OUTPUT_OD) ||\
\r
222 ((__MODE__) == GPIO_MODE_AF_PP) ||\
\r
223 ((__MODE__) == GPIO_MODE_AF_OD) ||\
\r
224 ((__MODE__) == GPIO_MODE_IT_RISING) ||\
\r
225 ((__MODE__) == GPIO_MODE_IT_FALLING) ||\
\r
226 ((__MODE__) == GPIO_MODE_IT_RISING_FALLING) ||\
\r
227 ((__MODE__) == GPIO_MODE_EVT_RISING) ||\
\r
228 ((__MODE__) == GPIO_MODE_EVT_FALLING) ||\
\r
229 ((__MODE__) == GPIO_MODE_EVT_RISING_FALLING) ||\
\r
230 ((__MODE__) == GPIO_MODE_ANALOG) ||\
\r
231 ((__MODE__) == GPIO_MODE_ANALOG_ADC_CONTROL))
\r
233 #define IS_GPIO_SPEED(__SPEED__) (((__SPEED__) == GPIO_SPEED_FREQ_LOW) ||\
\r
234 ((__SPEED__) == GPIO_SPEED_FREQ_MEDIUM) ||\
\r
235 ((__SPEED__) == GPIO_SPEED_FREQ_HIGH) ||\
\r
236 ((__SPEED__) == GPIO_SPEED_FREQ_VERY_HIGH))
\r
238 #define IS_GPIO_PULL(__PULL__) (((__PULL__) == GPIO_NOPULL) ||\
\r
239 ((__PULL__) == GPIO_PULLUP) || \
\r
240 ((__PULL__) == GPIO_PULLDOWN))
\r
245 /* Include GPIO HAL Extended module */
\r
246 #include "stm32l4xx_hal_gpio_ex.h"
\r
248 /* Exported functions --------------------------------------------------------*/
\r
249 /** @addtogroup GPIO_Exported_Functions GPIO Exported Functions
\r
253 /** @addtogroup GPIO_Exported_Functions_Group1 Initialization/de-initialization functions
\r
254 * @brief Initialization and Configuration functions
\r
258 /* Initialization and de-initialization functions *****************************/
\r
259 void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init);
\r
260 void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin);
\r
266 /** @addtogroup GPIO_Exported_Functions_Group2 IO operation functions
\r
270 /* IO operation functions *****************************************************/
\r
271 GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
\r
272 void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
\r
273 void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
\r
274 HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
\r
275 void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
\r
276 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
\r
298 #endif /* __STM32L4xx_HAL_GPIO_H */
\r
300 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r