STM32F103xB HAL User Manual
stm32f1xx_hal_gpio.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f1xx_hal_gpio.h
00004   * @author  MCD Application Team
00005   * @brief   Header file of GPIO HAL module.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 
00020 /* Define to prevent recursive inclusion -------------------------------------*/
00021 #ifndef STM32F1xx_HAL_GPIO_H
00022 #define STM32F1xx_HAL_GPIO_H
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "stm32f1xx_hal_def.h"
00030 
00031 /** @addtogroup STM32F1xx_HAL_Driver
00032   * @{
00033   */
00034 
00035 /** @addtogroup GPIO
00036   * @{
00037   */
00038 
00039 /* Exported types ------------------------------------------------------------*/
00040 /** @defgroup GPIO_Exported_Types GPIO Exported Types
00041   * @{
00042   */
00043 
00044 /**
00045   * @brief GPIO Init structure definition
00046   */
00047 typedef struct
00048 {
00049   uint32_t Pin;       /*!< Specifies the GPIO pins to be configured.
00050                            This parameter can be any value of @ref GPIO_pins_define */
00051 
00052   uint32_t Mode;      /*!< Specifies the operating mode for the selected pins.
00053                            This parameter can be a value of @ref GPIO_mode_define */
00054 
00055   uint32_t Pull;      /*!< Specifies the Pull-up or Pull-Down activation for the selected pins.
00056                            This parameter can be a value of @ref GPIO_pull_define */
00057 
00058   uint32_t Speed;     /*!< Specifies the speed for the selected pins.
00059                            This parameter can be a value of @ref GPIO_speed_define */
00060 } GPIO_InitTypeDef;
00061 
00062 /**
00063   * @brief  GPIO Bit SET and Bit RESET enumeration
00064   */
00065 typedef enum
00066 {
00067   GPIO_PIN_RESET = 0u,
00068   GPIO_PIN_SET
00069 } GPIO_PinState;
00070 /**
00071   * @}
00072   */
00073 
00074 /* Exported constants --------------------------------------------------------*/
00075 
00076 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants
00077   * @{
00078   */
00079 
00080 /** @defgroup GPIO_pins_define GPIO pins define
00081   * @{
00082   */
00083 #define GPIO_PIN_0                 ((uint16_t)0x0001)  /* Pin 0 selected    */
00084 #define GPIO_PIN_1                 ((uint16_t)0x0002)  /* Pin 1 selected    */
00085 #define GPIO_PIN_2                 ((uint16_t)0x0004)  /* Pin 2 selected    */
00086 #define GPIO_PIN_3                 ((uint16_t)0x0008)  /* Pin 3 selected    */
00087 #define GPIO_PIN_4                 ((uint16_t)0x0010)  /* Pin 4 selected    */
00088 #define GPIO_PIN_5                 ((uint16_t)0x0020)  /* Pin 5 selected    */
00089 #define GPIO_PIN_6                 ((uint16_t)0x0040)  /* Pin 6 selected    */
00090 #define GPIO_PIN_7                 ((uint16_t)0x0080)  /* Pin 7 selected    */
00091 #define GPIO_PIN_8                 ((uint16_t)0x0100)  /* Pin 8 selected    */
00092 #define GPIO_PIN_9                 ((uint16_t)0x0200)  /* Pin 9 selected    */
00093 #define GPIO_PIN_10                ((uint16_t)0x0400)  /* Pin 10 selected   */
00094 #define GPIO_PIN_11                ((uint16_t)0x0800)  /* Pin 11 selected   */
00095 #define GPIO_PIN_12                ((uint16_t)0x1000)  /* Pin 12 selected   */
00096 #define GPIO_PIN_13                ((uint16_t)0x2000)  /* Pin 13 selected   */
00097 #define GPIO_PIN_14                ((uint16_t)0x4000)  /* Pin 14 selected   */
00098 #define GPIO_PIN_15                ((uint16_t)0x8000)  /* Pin 15 selected   */
00099 #define GPIO_PIN_All               ((uint16_t)0xFFFF)  /* All pins selected */
00100 
00101 #define GPIO_PIN_MASK              0x0000FFFFu /* PIN mask for assert test */
00102 /**
00103   * @}
00104   */
00105 
00106 /** @defgroup GPIO_mode_define GPIO mode define
00107   * @brief GPIO Configuration Mode
00108   *        Elements values convention: 0xX0yz00YZ
00109   *           - X  : GPIO mode or EXTI Mode
00110   *           - y  : External IT or Event trigger detection
00111   *           - z  : IO configuration on External IT or Event
00112   *           - Y  : Output type (Push Pull or Open Drain)
00113   *           - Z  : IO Direction mode (Input, Output, Alternate or Analog)
00114   * @{
00115   */
00116 #define  GPIO_MODE_INPUT                        0x00000000u   /*!< Input Floating Mode                   */
00117 #define  GPIO_MODE_OUTPUT_PP                    0x00000001u   /*!< Output Push Pull Mode                 */
00118 #define  GPIO_MODE_OUTPUT_OD                    0x00000011u   /*!< Output Open Drain Mode                */
00119 #define  GPIO_MODE_AF_PP                        0x00000002u   /*!< Alternate Function Push Pull Mode     */
00120 #define  GPIO_MODE_AF_OD                        0x00000012u   /*!< Alternate Function Open Drain Mode    */
00121 #define  GPIO_MODE_AF_INPUT                     GPIO_MODE_INPUT          /*!< Alternate Function Input Mode         */
00122 
00123 #define  GPIO_MODE_ANALOG                       0x00000003u   /*!< Analog Mode  */
00124 
00125 #define  GPIO_MODE_IT_RISING                    0x10110000u   /*!< External Interrupt Mode with Rising edge trigger detection          */
00126 #define  GPIO_MODE_IT_FALLING                   0x10210000u   /*!< External Interrupt Mode with Falling edge trigger detection         */
00127 #define  GPIO_MODE_IT_RISING_FALLING            0x10310000u   /*!< External Interrupt Mode with Rising/Falling edge trigger detection  */
00128 
00129 #define  GPIO_MODE_EVT_RISING                   0x10120000u   /*!< External Event Mode with Rising edge trigger detection               */
00130 #define  GPIO_MODE_EVT_FALLING                  0x10220000u   /*!< External Event Mode with Falling edge trigger detection              */
00131 #define  GPIO_MODE_EVT_RISING_FALLING           0x10320000u   /*!< External Event Mode with Rising/Falling edge trigger detection       */
00132 
00133 /**
00134   * @}
00135   */
00136 
00137 /** @defgroup GPIO_speed_define  GPIO speed define
00138   * @brief GPIO Output Maximum frequency
00139   * @{
00140   */
00141 #define  GPIO_SPEED_FREQ_LOW              (GPIO_CRL_MODE0_1) /*!< Low speed */
00142 #define  GPIO_SPEED_FREQ_MEDIUM           (GPIO_CRL_MODE0_0) /*!< Medium speed */
00143 #define  GPIO_SPEED_FREQ_HIGH             (GPIO_CRL_MODE0)   /*!< High speed */
00144 
00145 /**
00146   * @}
00147   */
00148 
00149 /** @defgroup GPIO_pull_define GPIO pull define
00150   * @brief GPIO Pull-Up or Pull-Down Activation
00151   * @{
00152   */
00153 #define  GPIO_NOPULL        0x00000000u   /*!< No Pull-up or Pull-down activation  */
00154 #define  GPIO_PULLUP        0x00000001u   /*!< Pull-up activation                  */
00155 #define  GPIO_PULLDOWN      0x00000002u   /*!< Pull-down activation                */
00156 /**
00157   * @}
00158   */
00159 
00160 /**
00161   * @}
00162   */
00163 
00164 /* Exported macro ------------------------------------------------------------*/
00165 /** @defgroup GPIO_Exported_Macros GPIO Exported Macros
00166   * @{
00167   */
00168 
00169 /**
00170   * @brief  Checks whether the specified EXTI line flag is set or not.
00171   * @param  __EXTI_LINE__: specifies the EXTI line flag to check.
00172   *         This parameter can be GPIO_PIN_x where x can be(0..15)
00173   * @retval The new state of __EXTI_LINE__ (SET or RESET).
00174   */
00175 #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
00176 
00177 /**
00178   * @brief  Clears the EXTI's line pending flags.
00179   * @param  __EXTI_LINE__: specifies the EXTI lines flags to clear.
00180   *         This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
00181   * @retval None
00182   */
00183 #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
00184 
00185 /**
00186   * @brief  Checks whether the specified EXTI line is asserted or not.
00187   * @param  __EXTI_LINE__: specifies the EXTI line to check.
00188   *          This parameter can be GPIO_PIN_x where x can be(0..15)
00189   * @retval The new state of __EXTI_LINE__ (SET or RESET).
00190   */
00191 #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
00192 
00193 /**
00194   * @brief  Clears the EXTI's line pending bits.
00195   * @param  __EXTI_LINE__: specifies the EXTI lines to clear.
00196   *          This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
00197   * @retval None
00198   */
00199 #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
00200 
00201 /**
00202   * @brief  Generates a Software interrupt on selected EXTI line.
00203   * @param  __EXTI_LINE__: specifies the EXTI line to check.
00204   *          This parameter can be GPIO_PIN_x where x can be(0..15)
00205   * @retval None
00206   */
00207 #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__))
00208 /**
00209   * @}
00210   */
00211 
00212 /* Include GPIO HAL Extension module */
00213 #include "stm32f1xx_hal_gpio_ex.h"
00214 
00215 /* Exported functions --------------------------------------------------------*/
00216 /** @addtogroup GPIO_Exported_Functions
00217   * @{
00218   */
00219 
00220 /** @addtogroup GPIO_Exported_Functions_Group1
00221   * @{
00222   */
00223 /* Initialization and de-initialization functions *****************************/
00224 void  HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init);
00225 void  HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin);
00226 /**
00227   * @}
00228   */
00229 
00230 /** @addtogroup GPIO_Exported_Functions_Group2
00231   * @{
00232   */
00233 /* IO operation functions *****************************************************/
00234 GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
00235 void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
00236 void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
00237 HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin);
00238 void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
00239 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
00240 
00241 /**
00242   * @}
00243   */
00244 
00245 /**
00246   * @}
00247   */
00248 /* Private types -------------------------------------------------------------*/
00249 /* Private variables ---------------------------------------------------------*/
00250 /* Private constants ---------------------------------------------------------*/
00251 /** @defgroup GPIO_Private_Constants GPIO Private Constants
00252   * @{
00253   */
00254 
00255 /**
00256   * @}
00257   */
00258 
00259 /* Private macros ------------------------------------------------------------*/
00260 /** @defgroup GPIO_Private_Macros GPIO Private Macros
00261   * @{
00262   */
00263 #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET))
00264 #define IS_GPIO_PIN(PIN)           (((((uint32_t)PIN) & GPIO_PIN_MASK ) != 0x00u) && ((((uint32_t)PIN) & ~GPIO_PIN_MASK) == 0x00u))
00265 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT)              ||\
00266                             ((MODE) == GPIO_MODE_OUTPUT_PP)          ||\
00267                             ((MODE) == GPIO_MODE_OUTPUT_OD)          ||\
00268                             ((MODE) == GPIO_MODE_AF_PP)              ||\
00269                             ((MODE) == GPIO_MODE_AF_OD)              ||\
00270                             ((MODE) == GPIO_MODE_IT_RISING)          ||\
00271                             ((MODE) == GPIO_MODE_IT_FALLING)         ||\
00272                             ((MODE) == GPIO_MODE_IT_RISING_FALLING)  ||\
00273                             ((MODE) == GPIO_MODE_EVT_RISING)         ||\
00274                             ((MODE) == GPIO_MODE_EVT_FALLING)        ||\
00275                             ((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\
00276                             ((MODE) == GPIO_MODE_ANALOG))
00277 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_FREQ_LOW) || \
00278                               ((SPEED) == GPIO_SPEED_FREQ_MEDIUM) || ((SPEED) == GPIO_SPEED_FREQ_HIGH))
00279 #define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \
00280                             ((PULL) == GPIO_PULLDOWN))
00281 /**
00282   * @}
00283   */
00284 
00285 /* Private functions ---------------------------------------------------------*/
00286 /** @defgroup GPIO_Private_Functions GPIO Private Functions
00287   * @{
00288   */
00289 
00290 /**
00291   * @}
00292   */
00293 
00294 /**
00295   * @}
00296   */
00297 
00298 /**
00299   * @}
00300   */
00301 
00302 #ifdef __cplusplus
00303 }
00304 #endif
00305 
00306 #endif /* STM32F1xx_HAL_GPIO_H */
00307 
00308 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/