HAL_gpio.h 10.3 KB
Newer Older
csdn_JZ_'s avatar
csdn_JZ_ 已提交
1 2 3 4 5 6
/**
******************************************************************************
* @file  HAL_gpio.h
* @author  IC Applications Department
* @version  V0.8
* @date  2019_08_02
csdn_JZ_'s avatar
csdn_JZ_ 已提交
7
* @brief  This file contains all the functions prototypes for the GPIO
csdn_JZ_'s avatar
csdn_JZ_ 已提交
8 9 10 11 12 13 14 15 16 17 18 19
*         firmware library.
******************************************************************************
* @copy
*
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
* TIME. AS A RESULT, HOLOCENE SHALL NOT BE HELD LIABLE FOR ANY
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*
* <h2><center>&copy; COPYRIGHT 2016 HOLOCENE</center></h2>
csdn_JZ_'s avatar
csdn_JZ_ 已提交
20
*/
csdn_JZ_'s avatar
csdn_JZ_ 已提交
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HAL_GPIO_H
#define __HAL_GPIO_H

/* Includes ------------------------------------------------------------------*/
#include "HAL_device.h"

/** @addtogroup StdPeriph_Driver
* @{
*/

/** @addtogroup GPIO
* @{
*/

/** @defgroup GPIO_Exported_Types
* @{
*/

#define IS_GPIO_ALL_PERIPH(PERIPH) (((*(uint32_t*)&(PERIPH)) == GPIOA_BASE) || \
((*(uint32_t*)&(PERIPH)) == GPIOB_BASE) || \
  ((*(uint32_t*)&(PERIPH)) == GPIOC_BASE) || \
    ((*(uint32_t*)&(PERIPH)) == GPIOD_BASE) || \
      ((*(uint32_t*)&(PERIPH)) == GPIOE_BASE) || \
        ((*(uint32_t*)&(PERIPH)) == GPIOF_BASE) || \
          ((*(uint32_t*)&(PERIPH)) == GPIOG_BASE))

csdn_JZ_'s avatar
csdn_JZ_ 已提交
49 50
/**
* @brief  Output Maximum frequency selection
csdn_JZ_'s avatar
csdn_JZ_ 已提交
51 52 53
*/

typedef enum
csdn_JZ_'s avatar
csdn_JZ_ 已提交
54
{
csdn_JZ_'s avatar
csdn_JZ_ 已提交
55
  GPIO_Speed_10MHz = 1,
csdn_JZ_'s avatar
csdn_JZ_ 已提交
56
  GPIO_Speed_2MHz,
csdn_JZ_'s avatar
csdn_JZ_ 已提交
57 58 59 60 61
  GPIO_Speed_50MHz
}GPIOSpeed_TypeDef;
#define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
((SPEED) == GPIO_Speed_50MHz))

csdn_JZ_'s avatar
csdn_JZ_ 已提交
62 63
/**
* @brief  Configuration Mode enumeration
csdn_JZ_'s avatar
csdn_JZ_ 已提交
64 65 66
*/

typedef enum
csdn_JZ_'s avatar
csdn_JZ_ 已提交
67 68 69 70 71 72 73 74 75
{
GPIO_Mode_AIN = 0x0,  //模拟输入
GPIO_Mode_IN_FLOATING = 0x04, //浮空输入
GPIO_Mode_IPD = 0x28,  //下拉输入
GPIO_Mode_IPU = 0x48,  //上拉输入
GPIO_Mode_Out_OD = 0x14,//通用开漏输出
GPIO_Mode_Out_PP = 0x10,//通用推免输出
GPIO_Mode_AF_OD = 0x1C, // 复用开漏输出
GPIO_Mode_AF_PP = 0x18  //复用推免输出
csdn_JZ_'s avatar
csdn_JZ_ 已提交
76 77 78 79 80 81 82
}GPIOMode_TypeDef;

#define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_AIN) || ((MODE) == GPIO_Mode_IN_FLOATING) || \
((MODE) == GPIO_Mode_IPD) || ((MODE) == GPIO_Mode_IPU) || \
  ((MODE) == GPIO_Mode_Out_OD) || ((MODE) == GPIO_Mode_Out_PP) || \
    ((MODE) == GPIO_Mode_AF_OD) || ((MODE) == GPIO_Mode_AF_PP))

csdn_JZ_'s avatar
csdn_JZ_ 已提交
83 84
/**
* @brief  GPIO Init structure definition
csdn_JZ_'s avatar
csdn_JZ_ 已提交
85 86 87 88 89 90 91 92 93
*/

typedef struct
{
  uint32_t GPIO_Pin;
  GPIOSpeed_TypeDef GPIO_Speed;
  GPIOMode_TypeDef GPIO_Mode;
}GPIO_InitTypeDef;

csdn_JZ_'s avatar
csdn_JZ_ 已提交
94 95
/**
* @brief  Bit_SET and Bit_RESET enumeration
csdn_JZ_'s avatar
csdn_JZ_ 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
*/

typedef enum
{ Bit_RESET = 0,
  Bit_SET
}BitAction;

#define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))

/**
* @}
*/

/** @defgroup GPIO_Exported_Constants
* @{
*/

csdn_JZ_'s avatar
csdn_JZ_ 已提交
113
/** @defgroup GPIO_pins_define
csdn_JZ_'s avatar
csdn_JZ_ 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
* @{
*/

#define GPIO_Pin_0                 ((uint16_t)0x0001)  /* Pin 0 selected */
#define GPIO_Pin_1                 ((uint16_t)0x0002)  /* Pin 1 selected */
#define GPIO_Pin_2                 ((uint16_t)0x0004)  /* Pin 2 selected */
#define GPIO_Pin_3                 ((uint16_t)0x0008)  /* Pin 3 selected */
#define GPIO_Pin_4                 ((uint16_t)0x0010)  /* Pin 4 selected */
#define GPIO_Pin_5                 ((uint16_t)0x0020)  /* Pin 5 selected */
#define GPIO_Pin_6                 ((uint16_t)0x0040)  /* Pin 6 selected */
#define GPIO_Pin_7                 ((uint16_t)0x0080)  /* Pin 7 selected */
#define GPIO_Pin_8                 ((uint16_t)0x0100)  /* Pin 8 selected */
#define GPIO_Pin_9                 ((uint16_t)0x0200)  /* Pin 9 selected */
#define GPIO_Pin_10                ((uint16_t)0x0400)  /* Pin 10 selected */
#define GPIO_Pin_11                ((uint16_t)0x0800)  /* Pin 11 selected */
#define GPIO_Pin_12                ((uint16_t)0x1000)  /* Pin 12 selected */
#define GPIO_Pin_13                ((uint16_t)0x2000)  /* Pin 13 selected */
#define GPIO_Pin_14                ((uint16_t)0x4000)  /* Pin 14 selected */
#define GPIO_Pin_15                ((uint16_t)0x8000)  /* Pin 15 selected */

#define GPIO_Pin_16              ((uint32_t)0x010000)  /* Pin 16 selected */
#define GPIO_Pin_17              ((uint32_t)0x020000)  /* Pin 17 selected */
#define GPIO_Pin_18              ((uint32_t)0x040000)  /* Pin 18 selected */
#define GPIO_Pin_19              ((uint32_t)0x080000)  /* Pin 19 selected */
#define GPIO_Pin_20              ((uint32_t)0x100000)  /* Pin 20 selected */
#define GPIO_Pin_21              ((uint32_t)0x200000)  /* Pin 21 selected */
#define GPIO_Pin_22              ((uint32_t)0x400000)  /* Pin 22 selected */
#define GPIO_Pin_23              ((uint32_t)0x800000)  /* Pin 23 selected */
#define GPIO_Pin_All             ((uint32_t)0xFFFFFF)  /* All pins selected */

#define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00))

#define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
((PIN) == GPIO_Pin_1) || \
  ((PIN) == GPIO_Pin_2) || \
    ((PIN) == GPIO_Pin_3) || \
      ((PIN) == GPIO_Pin_4) || \
        ((PIN) == GPIO_Pin_5) || \
          ((PIN) == GPIO_Pin_6) || \
            ((PIN) == GPIO_Pin_7) || \
              ((PIN) == GPIO_Pin_8) || \
                ((PIN) == GPIO_Pin_9) || \
                  ((PIN) == GPIO_Pin_10) || \
                    ((PIN) == GPIO_Pin_11) || \
                      ((PIN) == GPIO_Pin_12) || \
                        ((PIN) == GPIO_Pin_13) || \
                          ((PIN) == GPIO_Pin_14) || \
                            ((PIN) == GPIO_Pin_15))

/**
* @}
*/

csdn_JZ_'s avatar
csdn_JZ_ 已提交
167
/** @defgroup GPIO_Remap_define
csdn_JZ_'s avatar
csdn_JZ_ 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
* @{
*/

#define GPIO_Remap_SPI1            ((uint32_t)0x00000001)  /* SPI1 Alternate Function mapping */
#define GPIO_Remap_I2C1            ((uint32_t)0x00000002)  /* I2C1 Alternate Function mapping */
#define GPIO_Remap_UART1          ((uint32_t)0x00000004)  /* UART1 Alternate Function mapping */


#define GPIO_PartialRemap_TIM1     ((uint32_t)0x00160040)  /* TIM1 Partial Alternate Function mapping */
#define GPIO_FullRemap_TIM1        ((uint32_t)0x001600C0)  /* TIM1 Full Alternate Function mapping */
#define GPIO_PartialRemap1_TIM2    ((uint32_t)0x00180100)  /* TIM2 Partial1 Alternate Function mapping */
#define GPIO_PartialRemap2_TIM2    ((uint32_t)0x00180200)  /* TIM2 Partial2 Alternate Function mapping */
#define GPIO_FullRemap_TIM2        ((uint32_t)0x00180300)  /* TIM2 Full Alternate Function mapping */
#define GPIO_PartialRemap_TIM3     ((uint32_t)0x001A0800)  /* TIM3 Partial Alternate Function mapping */
#define GPIO_FullRemap_TIM3        ((uint32_t)0x001A0C00)  /* TIM3 Full Alternate Function mapping */


#define GPIO_Remap_PD01            ((uint32_t)0x00008000)  /* PD01 Alternate Function mapping */

#define GPIO_Remap_ADC1_ETRGINJ    ((uint32_t)0x00200002)  /* ADC1 External Trigger Injected Conversion remapping */
#define GPIO_Remap_ADC1_ETRGREG    ((uint32_t)0x00200004)  /* ADC1 External Trigger Regular Conversion remapping */

#define GPIO_Remap_SWJ_NoJTRST     ((uint32_t)0x00300100)  /* Full SWJ Enabled (JTAG-DP + SW-DP) but without JTRST */
#define GPIO_Remap_SWJ_JTAGDisable ((uint32_t)0x00300200)  /* JTAG-DP Disabled and SW-DP Enabled */
#define GPIO_Remap_SWJ_Disable     ((uint32_t)0x00300400)  /* Full SWJ Disabled (JTAG-DP + SW-DP) */

#define IS_GPIO_REMAP(REMAP) (((REMAP) == GPIO_Remap_SPI1) || ((REMAP) == GPIO_Remap_I2C1) || \
((REMAP) == GPIO_Remap_UART1) || ((REMAP) == GPIO_PartialRemap_TIM1) || \
   ((REMAP) == GPIO_FullRemap_TIM1) ||  ((REMAP) == GPIO_PartialRemap1_TIM2) ||\
      ((REMAP) == GPIO_PartialRemap2_TIM2) || ((REMAP) == GPIO_FullRemap_TIM2) || \
        ((REMAP) == GPIO_PartialRemap_TIM3) || ((REMAP) == GPIO_FullRemap_TIM3) ||\
           ((REMAP) == GPIO_Remap_TIM4) || ((REMAP) == GPIO_Remap_PD01) || \
                ((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
                    ((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable)|| \
                      ((REMAP) == GPIO_Remap_SWJ_Disable))


/**
* @}
*/
/**
* @}
*/

csdn_JZ_'s avatar
csdn_JZ_ 已提交
212
/** @defgroup GPIO_Alternate_function_selection_define
csdn_JZ_'s avatar
csdn_JZ_ 已提交
213 214 215 216 217 218
* @{
*/


#define GPIO_AF_MCO_SW            ((uint8_t)0x00) /* MC0, SWDIO,SWCLK */
#define GPIO_AF_TIM_1_2           ((uint8_t)0x01) /* TIM 1/2 */
csdn_JZ_'s avatar
csdn_JZ_ 已提交
219
#define GPIO_AF_TIM_34567             ((uint8_t)0x02) /* TIM 3/4/5/6/7 */
csdn_JZ_'s avatar
csdn_JZ_ 已提交
220 221 222
#define GPIO_AF_I2S               ((uint8_t)0x03)
#define GPIO_AF_I2C               ((uint8_t)0x04) /* I2C 1/2/3 */
#define GPIO_AF_SPI               ((uint8_t)0x05) /* SPI 1/2/3/4 */
csdn_JZ_'s avatar
csdn_JZ_ 已提交
223
#define GPIO_AF_QSPI              ((uint8_t)0x06)
csdn_JZ_'s avatar
csdn_JZ_ 已提交
224
#define GPIO_AF_UART_2345         ((uint8_t)0x07) /* UART 2/3/4/5 */
csdn_JZ_'s avatar
csdn_JZ_ 已提交
225 226 227 228
#define GPIO_AF_UART_1            ((uint8_t)0x08)
#define GPIO_AF_CAN                   ((uint8_t)0x09) /* CAN 1/2 */
#define GPIO_AF_USB                   ((uint8_t)0x0A)
#define GPIO_AF_GPIO                    ((uint8_t)0x0B) /* Normal GPIO */
csdn_JZ_'s avatar
csdn_JZ_ 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
#define GPIO_AF_TK80_SDIO         ((uint8_t)0x0C) /* TK80   SDIO 1/2 */
#define GPIO_AF_Touchpad          ((uint8_t)0x0D)
#define GPIO_AF_LTDC              ((uint8_t)0x0E) /* RGB_LTDC AF */


#define IS_GPIO_AF(AF)   (((AF) == GPIO_AF_0) || ((AF) == GPIO_AF_1) || \
((AF) == GPIO_AF_2) || ((AF) == GPIO_AF_3) || \
  ((AF) == GPIO_AF_4) || ((AF) == GPIO_AF_5) || \
    ((AF) == GPIO_AF_6) || ((AF) == GPIO_AF_7))

/**
* @}
*/

/** @defgroup GPIO_Exported_Macros
* @{
*/

/**
* @}
*/

/** @defgroup GPIO_Exported_Functions
* @{
*/

void GPIO_DeInit(GPIO_TypeDef* GPIOx);
void GPIO_AFIODeInit(void);
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin);
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin);
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint32_t GPIO_Pin, uint8_t GPIO_AF);
#endif /* __HAL_GPIO_H */
/**
* @}
*/

/**
* @}
*/

/**
* @}
*/

/*-------------------------(C) COPYRIGHT 2016 HOLOCENE ----------------------*/