STM32L486xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_hal_gpio.h 00004 * @author MCD Application Team 00005 * @brief Header file of GPIO HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 /* Define to prevent recursive inclusion -------------------------------------*/ 00037 #ifndef __STM32L4xx_HAL_GPIO_H 00038 #define __STM32L4xx_HAL_GPIO_H 00039 00040 #ifdef __cplusplus 00041 extern "C" { 00042 #endif 00043 00044 /* Includes ------------------------------------------------------------------*/ 00045 #include "stm32l4xx_hal_def.h" 00046 00047 /** @addtogroup STM32L4xx_HAL_Driver 00048 * @{ 00049 */ 00050 00051 /** @addtogroup GPIO 00052 * @{ 00053 */ 00054 00055 /* Exported types ------------------------------------------------------------*/ 00056 00057 /** @defgroup GPIO_Exported_Types GPIO Exported Types 00058 * @{ 00059 */ 00060 /** 00061 * @brief GPIO Init structure definition 00062 */ 00063 typedef struct 00064 { 00065 uint32_t Pin; /*!< Specifies the GPIO pins to be configured. 00066 This parameter can be any value of @ref GPIO_pins */ 00067 00068 uint32_t Mode; /*!< Specifies the operating mode for the selected pins. 00069 This parameter can be a value of @ref GPIO_mode */ 00070 00071 uint32_t Pull; /*!< Specifies the Pull-up or Pull-Down activation for the selected pins. 00072 This parameter can be a value of @ref GPIO_pull */ 00073 00074 uint32_t Speed; /*!< Specifies the speed for the selected pins. 00075 This parameter can be a value of @ref GPIO_speed */ 00076 00077 uint32_t Alternate; /*!< Peripheral to be connected to the selected pins 00078 This parameter can be a value of @ref GPIOEx_Alternate_function_selection */ 00079 }GPIO_InitTypeDef; 00080 00081 /** 00082 * @brief GPIO Bit SET and Bit RESET enumeration 00083 */ 00084 typedef enum 00085 { 00086 GPIO_PIN_RESET = 0, 00087 GPIO_PIN_SET 00088 }GPIO_PinState; 00089 /** 00090 * @} 00091 */ 00092 00093 /* Exported constants --------------------------------------------------------*/ 00094 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants 00095 * @{ 00096 */ 00097 /** @defgroup GPIO_pins GPIO pins 00098 * @{ 00099 */ 00100 #define GPIO_PIN_0 ((uint16_t)0x0001) /* Pin 0 selected */ 00101 #define GPIO_PIN_1 ((uint16_t)0x0002) /* Pin 1 selected */ 00102 #define GPIO_PIN_2 ((uint16_t)0x0004) /* Pin 2 selected */ 00103 #define GPIO_PIN_3 ((uint16_t)0x0008) /* Pin 3 selected */ 00104 #define GPIO_PIN_4 ((uint16_t)0x0010) /* Pin 4 selected */ 00105 #define GPIO_PIN_5 ((uint16_t)0x0020) /* Pin 5 selected */ 00106 #define GPIO_PIN_6 ((uint16_t)0x0040) /* Pin 6 selected */ 00107 #define GPIO_PIN_7 ((uint16_t)0x0080) /* Pin 7 selected */ 00108 #define GPIO_PIN_8 ((uint16_t)0x0100) /* Pin 8 selected */ 00109 #define GPIO_PIN_9 ((uint16_t)0x0200) /* Pin 9 selected */ 00110 #define GPIO_PIN_10 ((uint16_t)0x0400) /* Pin 10 selected */ 00111 #define GPIO_PIN_11 ((uint16_t)0x0800) /* Pin 11 selected */ 00112 #define GPIO_PIN_12 ((uint16_t)0x1000) /* Pin 12 selected */ 00113 #define GPIO_PIN_13 ((uint16_t)0x2000) /* Pin 13 selected */ 00114 #define GPIO_PIN_14 ((uint16_t)0x4000) /* Pin 14 selected */ 00115 #define GPIO_PIN_15 ((uint16_t)0x8000) /* Pin 15 selected */ 00116 #define GPIO_PIN_All ((uint16_t)0xFFFF) /* All pins selected */ 00117 00118 #define GPIO_PIN_MASK ((uint32_t)0x0000FFFF) /* PIN mask for assert test */ 00119 /** 00120 * @} 00121 */ 00122 00123 /** @defgroup GPIO_mode GPIO mode 00124 * @brief GPIO Configuration Mode 00125 * Elements values convention: 0xX0yz00YZ 00126 * - X : GPIO mode or EXTI Mode 00127 * - y : External IT or Event trigger detection 00128 * - z : IO configuration on External IT or Event 00129 * - Y : Output type (Push Pull or Open Drain) 00130 * - Z : IO Direction mode (Input, Output, Alternate or Analog) 00131 * @{ 00132 */ 00133 #define GPIO_MODE_INPUT ((uint32_t)0x00000000) /*!< Input Floating Mode */ 00134 #define GPIO_MODE_OUTPUT_PP ((uint32_t)0x00000001) /*!< Output Push Pull Mode */ 00135 #define GPIO_MODE_OUTPUT_OD ((uint32_t)0x00000011) /*!< Output Open Drain Mode */ 00136 #define GPIO_MODE_AF_PP ((uint32_t)0x00000002) /*!< Alternate Function Push Pull Mode */ 00137 #define GPIO_MODE_AF_OD ((uint32_t)0x00000012) /*!< Alternate Function Open Drain Mode */ 00138 #define GPIO_MODE_ANALOG ((uint32_t)0x00000003) /*!< Analog Mode */ 00139 #define GPIO_MODE_ANALOG_ADC_CONTROL ((uint32_t)0x0000000B) /*!< Analog Mode for ADC conversion */ 00140 #define GPIO_MODE_IT_RISING ((uint32_t)0x10110000) /*!< External Interrupt Mode with Rising edge trigger detection */ 00141 #define GPIO_MODE_IT_FALLING ((uint32_t)0x10210000) /*!< External Interrupt Mode with Falling edge trigger detection */ 00142 #define GPIO_MODE_IT_RISING_FALLING ((uint32_t)0x10310000) /*!< External Interrupt Mode with Rising/Falling edge trigger detection */ 00143 #define GPIO_MODE_EVT_RISING ((uint32_t)0x10120000) /*!< External Event Mode with Rising edge trigger detection */ 00144 #define GPIO_MODE_EVT_FALLING ((uint32_t)0x10220000) /*!< External Event Mode with Falling edge trigger detection */ 00145 #define GPIO_MODE_EVT_RISING_FALLING ((uint32_t)0x10320000) /*!< External Event Mode with Rising/Falling edge trigger detection */ 00146 /** 00147 * @} 00148 */ 00149 00150 /** @defgroup GPIO_speed GPIO speed 00151 * @brief GPIO Output Maximum frequency 00152 * @{ 00153 */ 00154 #define GPIO_SPEED_FREQ_LOW ((uint32_t)0x00000000) /*!< range up to 5 MHz, please refer to the product datasheet */ 00155 #define GPIO_SPEED_FREQ_MEDIUM ((uint32_t)0x00000001) /*!< range 5 MHz to 25 MHz, please refer to the product datasheet */ 00156 #define GPIO_SPEED_FREQ_HIGH ((uint32_t)0x00000002) /*!< range 25 MHz to 50 MHz, please refer to the product datasheet */ 00157 #define GPIO_SPEED_FREQ_VERY_HIGH ((uint32_t)0x00000003) /*!< range 50 MHz to 80 MHz, please refer to the product datasheet */ 00158 /** 00159 * @} 00160 */ 00161 00162 /** @defgroup GPIO_pull GPIO pull 00163 * @brief GPIO Pull-Up or Pull-Down Activation 00164 * @{ 00165 */ 00166 #define GPIO_NOPULL ((uint32_t)0x00000000) /*!< No Pull-up or Pull-down activation */ 00167 #define GPIO_PULLUP ((uint32_t)0x00000001) /*!< Pull-up activation */ 00168 #define GPIO_PULLDOWN ((uint32_t)0x00000002) /*!< Pull-down activation */ 00169 /** 00170 * @} 00171 */ 00172 00173 /** 00174 * @} 00175 */ 00176 00177 /* Exported macro ------------------------------------------------------------*/ 00178 /** @defgroup GPIO_Exported_Macros GPIO Exported Macros 00179 * @{ 00180 */ 00181 00182 /** 00183 * @brief Check whether the specified EXTI line flag is set or not. 00184 * @param __EXTI_LINE__: specifies the EXTI line flag to check. 00185 * This parameter can be GPIO_PIN_x where x can be(0..15) 00186 * @retval The new state of __EXTI_LINE__ (SET or RESET). 00187 */ 00188 #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR1 & (__EXTI_LINE__)) 00189 00190 /** 00191 * @brief Clear the EXTI's line pending flags. 00192 * @param __EXTI_LINE__: specifies the EXTI lines flags to clear. 00193 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 00194 * @retval None 00195 */ 00196 #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR1 = (__EXTI_LINE__)) 00197 00198 /** 00199 * @brief Check whether the specified EXTI line is asserted or not. 00200 * @param __EXTI_LINE__: specifies the EXTI line to check. 00201 * This parameter can be GPIO_PIN_x where x can be(0..15) 00202 * @retval The new state of __EXTI_LINE__ (SET or RESET). 00203 */ 00204 #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR1 & (__EXTI_LINE__)) 00205 00206 /** 00207 * @brief Clear the EXTI's line pending bits. 00208 * @param __EXTI_LINE__: specifies the EXTI lines to clear. 00209 * This parameter can be any combination of GPIO_PIN_x where x can be (0..15) 00210 * @retval None 00211 */ 00212 #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR1 = (__EXTI_LINE__)) 00213 00214 /** 00215 * @brief Generate a Software interrupt on selected EXTI line. 00216 * @param __EXTI_LINE__: specifies the EXTI line to check. 00217 * This parameter can be GPIO_PIN_x where x can be(0..15) 00218 * @retval None 00219 */ 00220 #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER1 |= (__EXTI_LINE__)) 00221 00222 /** 00223 * @} 00224 */ 00225 00226 /* Private macros ------------------------------------------------------------*/ 00227 /** @addtogroup GPIO_Private_Macros GPIO Private Macros 00228 * @{ 00229 */ 00230 #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET)) 00231 00232 #define IS_GPIO_PIN(__PIN__) ((((__PIN__) & GPIO_PIN_MASK) != (uint32_t)0x00) &&\ 00233 (((__PIN__) & ~GPIO_PIN_MASK) == (uint32_t)0x00)) 00234 00235 #define IS_GPIO_MODE(__MODE__) (((__MODE__) == GPIO_MODE_INPUT) ||\ 00236 ((__MODE__) == GPIO_MODE_OUTPUT_PP) ||\ 00237 ((__MODE__) == GPIO_MODE_OUTPUT_OD) ||\ 00238 ((__MODE__) == GPIO_MODE_AF_PP) ||\ 00239 ((__MODE__) == GPIO_MODE_AF_OD) ||\ 00240 ((__MODE__) == GPIO_MODE_IT_RISING) ||\ 00241 ((__MODE__) == GPIO_MODE_IT_FALLING) ||\ 00242 ((__MODE__) == GPIO_MODE_IT_RISING_FALLING) ||\ 00243 ((__MODE__) == GPIO_MODE_EVT_RISING) ||\ 00244 ((__MODE__) == GPIO_MODE_EVT_FALLING) ||\ 00245 ((__MODE__) == GPIO_MODE_EVT_RISING_FALLING) ||\ 00246 ((__MODE__) == GPIO_MODE_ANALOG) ||\ 00247 ((__MODE__) == GPIO_MODE_ANALOG_ADC_CONTROL)) 00248 00249 #define IS_GPIO_SPEED(__SPEED__) (((__SPEED__) == GPIO_SPEED_FREQ_LOW) ||\ 00250 ((__SPEED__) == GPIO_SPEED_FREQ_MEDIUM) ||\ 00251 ((__SPEED__) == GPIO_SPEED_FREQ_HIGH) ||\ 00252 ((__SPEED__) == GPIO_SPEED_FREQ_VERY_HIGH)) 00253 00254 #define IS_GPIO_PULL(__PULL__) (((__PULL__) == GPIO_NOPULL) ||\ 00255 ((__PULL__) == GPIO_PULLUP) || \ 00256 ((__PULL__) == GPIO_PULLDOWN)) 00257 /** 00258 * @} 00259 */ 00260 00261 /* Include GPIO HAL Extended module */ 00262 #include "stm32l4xx_hal_gpio_ex.h" 00263 00264 /* Exported functions --------------------------------------------------------*/ 00265 /** @addtogroup GPIO_Exported_Functions GPIO Exported Functions 00266 * @{ 00267 */ 00268 00269 /** @addtogroup GPIO_Exported_Functions_Group1 Initialization/de-initialization functions 00270 * @brief Initialization and Configuration functions 00271 * @{ 00272 */ 00273 00274 /* Initialization and de-initialization functions *****************************/ 00275 void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init); 00276 void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin); 00277 00278 /** 00279 * @} 00280 */ 00281 00282 /** @addtogroup GPIO_Exported_Functions_Group2 IO operation functions 00283 * @{ 00284 */ 00285 00286 /* IO operation functions *****************************************************/ 00287 GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00288 void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState); 00289 void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00290 HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); 00291 void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin); 00292 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); 00293 00294 /** 00295 * @} 00296 */ 00297 00298 /** 00299 * @} 00300 */ 00301 00302 /** 00303 * @} 00304 */ 00305 00306 /** 00307 * @} 00308 */ 00309 00310 #ifdef __cplusplus 00311 } 00312 #endif 00313 00314 #endif /* __STM32L4xx_HAL_GPIO_H */ 00315 00316 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/