STM32F439xx HAL User Manual
stm32f4xx_hal_gpio.h
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_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) 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 __STM32F4xx_HAL_GPIO_H
00038 #define __STM32F4xx_HAL_GPIO_H
00039 
00040 #ifdef __cplusplus
00041  extern "C" {
00042 #endif
00043 
00044 /* Includes ------------------------------------------------------------------*/
00045 #include "stm32f4xx_hal_def.h"
00046 
00047 /** @addtogroup STM32F4xx_HAL_Driver
00048   * @{
00049   */
00050 
00051 /** @addtogroup GPIO
00052   * @{
00053   */ 
00054 
00055 /* Exported types ------------------------------------------------------------*/
00056 /** @defgroup GPIO_Exported_Types GPIO Exported Types
00057   * @{
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_define */
00067 
00068   uint32_t Mode;      /*!< Specifies the operating mode for the selected pins.
00069                            This parameter can be a value of @ref GPIO_mode_define */
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_define */
00073 
00074   uint32_t Speed;     /*!< Specifies the speed for the selected pins.
00075                            This parameter can be a value of @ref GPIO_speed_define */
00076 
00077   uint32_t Alternate;  /*!< Peripheral to be connected to the selected pins. 
00078                             This parameter can be a value of @ref GPIO_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 
00095 /** @defgroup GPIO_Exported_Constants GPIO Exported Constants
00096   * @{
00097   */ 
00098 
00099 /** @defgroup GPIO_pins_define GPIO pins define
00100   * @{
00101   */
00102 #define GPIO_PIN_0                 ((uint16_t)0x0001)  /* Pin 0 selected    */
00103 #define GPIO_PIN_1                 ((uint16_t)0x0002)  /* Pin 1 selected    */
00104 #define GPIO_PIN_2                 ((uint16_t)0x0004)  /* Pin 2 selected    */
00105 #define GPIO_PIN_3                 ((uint16_t)0x0008)  /* Pin 3 selected    */
00106 #define GPIO_PIN_4                 ((uint16_t)0x0010)  /* Pin 4 selected    */
00107 #define GPIO_PIN_5                 ((uint16_t)0x0020)  /* Pin 5 selected    */
00108 #define GPIO_PIN_6                 ((uint16_t)0x0040)  /* Pin 6 selected    */
00109 #define GPIO_PIN_7                 ((uint16_t)0x0080)  /* Pin 7 selected    */
00110 #define GPIO_PIN_8                 ((uint16_t)0x0100)  /* Pin 8 selected    */
00111 #define GPIO_PIN_9                 ((uint16_t)0x0200)  /* Pin 9 selected    */
00112 #define GPIO_PIN_10                ((uint16_t)0x0400)  /* Pin 10 selected   */
00113 #define GPIO_PIN_11                ((uint16_t)0x0800)  /* Pin 11 selected   */
00114 #define GPIO_PIN_12                ((uint16_t)0x1000)  /* Pin 12 selected   */
00115 #define GPIO_PIN_13                ((uint16_t)0x2000)  /* Pin 13 selected   */
00116 #define GPIO_PIN_14                ((uint16_t)0x4000)  /* Pin 14 selected   */
00117 #define GPIO_PIN_15                ((uint16_t)0x8000)  /* Pin 15 selected   */
00118 #define GPIO_PIN_All               ((uint16_t)0xFFFF)  /* All pins selected */
00119 
00120 #define GPIO_PIN_MASK              0x0000FFFFU /* PIN mask for assert test */
00121 /**
00122   * @}
00123   */
00124 
00125 /** @defgroup GPIO_mode_define GPIO mode define
00126   * @brief GPIO Configuration Mode 
00127   *        Elements values convention: 0xX0yz00YZ
00128   *           - X  : GPIO mode or EXTI Mode
00129   *           - y  : External IT or Event trigger detection 
00130   *           - z  : IO configuration on External IT or Event
00131   *           - Y  : Output type (Push Pull or Open Drain)
00132   *           - Z  : IO Direction mode (Input, Output, Alternate or Analog)
00133   * @{
00134   */ 
00135 #define  GPIO_MODE_INPUT                        0x00000000U   /*!< Input Floating Mode                   */
00136 #define  GPIO_MODE_OUTPUT_PP                    0x00000001U   /*!< Output Push Pull Mode                 */
00137 #define  GPIO_MODE_OUTPUT_OD                    0x00000011U   /*!< Output Open Drain Mode                */
00138 #define  GPIO_MODE_AF_PP                        0x00000002U   /*!< Alternate Function Push Pull Mode     */
00139 #define  GPIO_MODE_AF_OD                        0x00000012U   /*!< Alternate Function Open Drain Mode    */
00140 
00141 #define  GPIO_MODE_ANALOG                       0x00000003U   /*!< Analog Mode  */
00142     
00143 #define  GPIO_MODE_IT_RISING                    0x10110000U   /*!< External Interrupt Mode with Rising edge trigger detection          */
00144 #define  GPIO_MODE_IT_FALLING                   0x10210000U   /*!< External Interrupt Mode with Falling edge trigger detection         */
00145 #define  GPIO_MODE_IT_RISING_FALLING            0x10310000U   /*!< External Interrupt Mode with Rising/Falling edge trigger detection  */
00146  
00147 #define  GPIO_MODE_EVT_RISING                   0x10120000U   /*!< External Event Mode with Rising edge trigger detection               */
00148 #define  GPIO_MODE_EVT_FALLING                  0x10220000U   /*!< External Event Mode with Falling edge trigger detection              */
00149 #define  GPIO_MODE_EVT_RISING_FALLING           0x10320000U   /*!< External Event Mode with Rising/Falling edge trigger detection       */
00150 /**
00151   * @}
00152   */
00153 
00154 /** @defgroup GPIO_speed_define  GPIO speed define
00155   * @brief GPIO Output Maximum frequency
00156   * @{
00157   */
00158 #define  GPIO_SPEED_FREQ_LOW         0x00000000U  /*!< IO works at 2 MHz, please refer to the product datasheet */
00159 #define  GPIO_SPEED_FREQ_MEDIUM      0x00000001U  /*!< range 12,5 MHz to 50 MHz, please refer to the product datasheet */
00160 #define  GPIO_SPEED_FREQ_HIGH        0x00000002U  /*!< range 25 MHz to 100 MHz, please refer to the product datasheet  */
00161 #define  GPIO_SPEED_FREQ_VERY_HIGH   0x00000003U  /*!< range 50 MHz to 200 MHz, please refer to the product datasheet  */
00162 /**
00163   * @}
00164   */
00165 
00166  /** @defgroup GPIO_pull_define GPIO pull define
00167    * @brief GPIO Pull-Up or Pull-Down Activation
00168    * @{
00169    */  
00170 #define  GPIO_NOPULL        0x00000000U   /*!< No Pull-up or Pull-down activation  */
00171 #define  GPIO_PULLUP        0x00000001U   /*!< Pull-up activation                  */
00172 #define  GPIO_PULLDOWN      0x00000002U   /*!< Pull-down activation                */
00173 /**
00174   * @}
00175   */
00176   
00177 /**
00178   * @}
00179   */
00180 
00181 /* Exported macro ------------------------------------------------------------*/
00182 /** @defgroup GPIO_Exported_Macros GPIO Exported Macros
00183   * @{
00184   */
00185 
00186 /**
00187   * @brief  Checks whether the specified EXTI line flag is set or not.
00188   * @param  __EXTI_LINE__ specifies the EXTI line flag to check.
00189   *         This parameter can be GPIO_PIN_x where x can be(0..15)
00190   * @retval The new state of __EXTI_LINE__ (SET or RESET).
00191   */
00192 #define __HAL_GPIO_EXTI_GET_FLAG(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
00193 
00194 /**
00195   * @brief  Clears the EXTI's line pending flags.
00196   * @param  __EXTI_LINE__ specifies the EXTI lines flags to clear.
00197   *         This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
00198   * @retval None
00199   */
00200 #define __HAL_GPIO_EXTI_CLEAR_FLAG(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
00201 
00202 /**
00203   * @brief  Checks whether the specified EXTI line is asserted or not.
00204   * @param  __EXTI_LINE__ specifies the EXTI line to check.
00205   *          This parameter can be GPIO_PIN_x where x can be(0..15)
00206   * @retval The new state of __EXTI_LINE__ (SET or RESET).
00207   */
00208 #define __HAL_GPIO_EXTI_GET_IT(__EXTI_LINE__) (EXTI->PR & (__EXTI_LINE__))
00209 
00210 /**
00211   * @brief  Clears the EXTI's line pending bits.
00212   * @param  __EXTI_LINE__ specifies the EXTI lines to clear.
00213   *          This parameter can be any combination of GPIO_PIN_x where x can be (0..15)
00214   * @retval None
00215   */
00216 #define __HAL_GPIO_EXTI_CLEAR_IT(__EXTI_LINE__) (EXTI->PR = (__EXTI_LINE__))
00217 
00218 /**
00219   * @brief  Generates a Software interrupt on selected EXTI line.
00220   * @param  __EXTI_LINE__ specifies the EXTI line to check.
00221   *          This parameter can be GPIO_PIN_x where x can be(0..15)
00222   * @retval None
00223   */
00224 #define __HAL_GPIO_EXTI_GENERATE_SWIT(__EXTI_LINE__) (EXTI->SWIER |= (__EXTI_LINE__))
00225 /**
00226   * @}
00227   */
00228 
00229 /* Include GPIO HAL Extension module */
00230 #include "stm32f4xx_hal_gpio_ex.h"
00231 
00232 /* Exported functions --------------------------------------------------------*/
00233 /** @addtogroup GPIO_Exported_Functions
00234   * @{
00235   */
00236 
00237 /** @addtogroup GPIO_Exported_Functions_Group1
00238   * @{
00239   */
00240 /* Initialization and de-initialization functions *****************************/
00241 void  HAL_GPIO_Init(GPIO_TypeDef  *GPIOx, GPIO_InitTypeDef *GPIO_Init);
00242 void  HAL_GPIO_DeInit(GPIO_TypeDef  *GPIOx, uint32_t GPIO_Pin);
00243 /**
00244   * @}
00245   */
00246 
00247 /** @addtogroup GPIO_Exported_Functions_Group2
00248   * @{
00249   */
00250 /* IO operation functions *****************************************************/
00251 GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00252 void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState);
00253 void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00254 HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
00255 void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin);
00256 void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin);
00257 
00258 /**
00259   * @}
00260   */ 
00261 
00262 /**
00263   * @}
00264   */ 
00265 /* Private types -------------------------------------------------------------*/
00266 /* Private variables ---------------------------------------------------------*/
00267 /* Private constants ---------------------------------------------------------*/
00268 /** @defgroup GPIO_Private_Constants GPIO Private Constants
00269   * @{
00270   */
00271 
00272 /**
00273   * @}
00274   */
00275 
00276 /* Private macros ------------------------------------------------------------*/
00277 /** @defgroup GPIO_Private_Macros GPIO Private Macros
00278   * @{
00279   */
00280 #define IS_GPIO_PIN_ACTION(ACTION) (((ACTION) == GPIO_PIN_RESET) || ((ACTION) == GPIO_PIN_SET))
00281 #define IS_GPIO_PIN(PIN)           ((((PIN) & GPIO_PIN_MASK ) != 0x00U) && (((PIN) & ~GPIO_PIN_MASK) == 0x00U))
00282 #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_MODE_INPUT)              ||\
00283                             ((MODE) == GPIO_MODE_OUTPUT_PP)          ||\
00284                             ((MODE) == GPIO_MODE_OUTPUT_OD)          ||\
00285                             ((MODE) == GPIO_MODE_AF_PP)              ||\
00286                             ((MODE) == GPIO_MODE_AF_OD)              ||\
00287                             ((MODE) == GPIO_MODE_IT_RISING)          ||\
00288                             ((MODE) == GPIO_MODE_IT_FALLING)         ||\
00289                             ((MODE) == GPIO_MODE_IT_RISING_FALLING)  ||\
00290                             ((MODE) == GPIO_MODE_EVT_RISING)         ||\
00291                             ((MODE) == GPIO_MODE_EVT_FALLING)        ||\
00292                             ((MODE) == GPIO_MODE_EVT_RISING_FALLING) ||\
00293                             ((MODE) == GPIO_MODE_ANALOG))
00294 #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_SPEED_FREQ_LOW)  || ((SPEED) == GPIO_SPEED_FREQ_MEDIUM) || \
00295                               ((SPEED) == GPIO_SPEED_FREQ_HIGH) || ((SPEED) == GPIO_SPEED_FREQ_VERY_HIGH))
00296 #define IS_GPIO_PULL(PULL) (((PULL) == GPIO_NOPULL) || ((PULL) == GPIO_PULLUP) || \
00297                             ((PULL) == GPIO_PULLDOWN))
00298 /**
00299   * @}
00300   */
00301 
00302 /* Private functions ---------------------------------------------------------*/
00303 /** @defgroup GPIO_Private_Functions GPIO Private Functions
00304   * @{
00305   */
00306 
00307 /**
00308   * @}
00309   */
00310 
00311 /**
00312   * @}
00313   */ 
00314 
00315 /**
00316   * @}
00317   */
00318 
00319 #ifdef __cplusplus
00320 }
00321 #endif
00322 
00323 #endif /* __STM32F4xx_HAL_GPIO_H */
00324 
00325 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/