Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32f1xx_hal_gpio.h Source File

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