326 lines
14 KiB
C
326 lines
14 KiB
C
|
/**
|
|||
|
******************************************************************************
|
|||
|
* @file HAL_gpio.h
|
|||
|
* @author AE Team
|
|||
|
* @version V1.1.0
|
|||
|
* @date 28/08/2019
|
|||
|
* @brief This file contains all the functions prototypes for the GPIO
|
|||
|
* 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, MindMotion 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>© COPYRIGHT 2019 MindMotion</center></h2>
|
|||
|
*/
|
|||
|
|
|||
|
/* 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))
|
|||
|
|
|||
|
/**
|
|||
|
* @brief Output Maximum frequency selection
|
|||
|
*/
|
|||
|
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
GPIO_Speed_10MHz = 1,
|
|||
|
GPIO_Speed_2MHz,
|
|||
|
GPIO_Speed_50MHz
|
|||
|
} GPIOSpeed_TypeDef;
|
|||
|
#define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_10MHz) || ((SPEED) == GPIO_Speed_2MHz) || \
|
|||
|
((SPEED) == GPIO_Speed_50MHz))
|
|||
|
|
|||
|
/**
|
|||
|
* @brief Configuration Mode enumeration
|
|||
|
*/
|
|||
|
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
GPIO_Mode_AIN = 0x0, //ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_Mode_IN_FLOATING = 0x04, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_Mode_IPD = 0x28, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_Mode_IPU = 0x48, //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_Mode_Out_OD = 0x14,//ͨ<>ÿ<EFBFBD>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
|||
|
GPIO_Mode_Out_PP = 0x10,//ͨ<><CDA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
GPIO_Mode_AF_OD = 0x1C, // <20><><EFBFBD>ÿ<EFBFBD>©<EFBFBD><C2A9><EFBFBD><EFBFBD>
|
|||
|
GPIO_Mode_AF_PP = 0x18 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
} 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))
|
|||
|
|
|||
|
/**
|
|||
|
* @brief GPIO Init structure definition
|
|||
|
*/
|
|||
|
|
|||
|
typedef struct
|
|||
|
{
|
|||
|
uint16_t GPIO_Pin;
|
|||
|
GPIOSpeed_TypeDef GPIO_Speed;
|
|||
|
GPIOMode_TypeDef GPIO_Mode;
|
|||
|
} GPIO_InitTypeDef;
|
|||
|
|
|||
|
/**
|
|||
|
* @brief Bit_SET and Bit_RESET enumeration
|
|||
|
*/
|
|||
|
|
|||
|
typedef enum
|
|||
|
{
|
|||
|
Bit_RESET = 0,
|
|||
|
Bit_SET
|
|||
|
} BitAction;
|
|||
|
|
|||
|
#define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/** @defgroup GPIO_Exported_Constants
|
|||
|
* @{
|
|||
|
*/
|
|||
|
|
|||
|
/** @defgroup GPIO_pins_define
|
|||
|
* @{
|
|||
|
*/
|
|||
|
|
|||
|
#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_All ((uint16_t)0xFFFF) /* 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))
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/** @defgroup GPIO_Remap_define
|
|||
|
* @{
|
|||
|
*/
|
|||
|
|
|||
|
#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_Remap_UART2 ((uint32_t)0x00000008) /* UART2 Alternate Function mapping */
|
|||
|
#define GPIO_PartialRemap_UART3 ((uint32_t)0x00140010) /* UART3 Partial Alternate Function mapping */
|
|||
|
#define GPIO_FullRemap_UART3 ((uint32_t)0x00140030) /* UART3 Full 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_TIM4 ((uint32_t)0x00001000) /* TIM4 Alternate Function mapping */
|
|||
|
#define GPIO_Remap1_CAN1 ((uint32_t)0x001D4000) /* CAN Alternate Function mapping */
|
|||
|
#define GPIO_Remap2_CAN1 ((uint32_t)0x001D0000) /* CAN Alternate Function mapping */
|
|||
|
#define GPIO_Remap_PD01 ((uint32_t)0x00008000) /* PD01 Alternate Function mapping */
|
|||
|
#define GPIO_Remap_TIM5CH4_LSI ((uint32_t)0x00200001) /* LSI connected to TIM5 Channel4 input capture for calibration */
|
|||
|
#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_ADC2_ETRGINJ ((uint32_t)0x00200008) /* ADC2 External Trigger Injected Conversion remapping */
|
|||
|
#define GPIO_Remap_ADC2_ETRGREG ((uint32_t)0x00200010) /* ADC2 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_Remap_UART2) || \
|
|||
|
((REMAP) == GPIO_PartialRemap_UART3) || ((REMAP) == GPIO_FullRemap_UART3) || \
|
|||
|
((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_Remap1_CAN1) || ((REMAP) == GPIO_Remap2_CAN1) || \
|
|||
|
((REMAP) == GPIO_Remap_PD01) || ((REMAP) == GPIO_Remap_TIM5CH4_LSI) || \
|
|||
|
((REMAP) == GPIO_Remap_ADC1_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC1_ETRGREG) || \
|
|||
|
((REMAP) == GPIO_Remap_ADC2_ETRGINJ) ||((REMAP) == GPIO_Remap_ADC2_ETRGREG) || \
|
|||
|
((REMAP) == GPIO_Remap_SWJ_NoJTRST) || ((REMAP) == GPIO_Remap_SWJ_JTAGDisable)|| \
|
|||
|
((REMAP) == GPIO_Remap_SWJ_Disable))
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/** @defgroup GPIO_Port_Sources
|
|||
|
* @{
|
|||
|
*/
|
|||
|
|
|||
|
#define GPIO_PortSourceGPIOA ((uint8_t)0x00)
|
|||
|
#define GPIO_PortSourceGPIOB ((uint8_t)0x01)
|
|||
|
#define GPIO_PortSourceGPIOC ((uint8_t)0x02)
|
|||
|
#define GPIO_PortSourceGPIOD ((uint8_t)0x03)
|
|||
|
#define GPIO_PortSourceGPIOE ((uint8_t)0x04)
|
|||
|
#define GPIO_PortSourceGPIOF ((uint8_t)0x05)
|
|||
|
#define GPIO_PortSourceGPIOG ((uint8_t)0x06)
|
|||
|
#define IS_GPIO_EVENTOUT_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOE))
|
|||
|
|
|||
|
#define IS_GPIO_EXTI_PORT_SOURCE(PORTSOURCE) (((PORTSOURCE) == GPIO_PortSourceGPIOA) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOB) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOC) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOD) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOE) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOF) || \
|
|||
|
((PORTSOURCE) == GPIO_PortSourceGPIOG))
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/** @defgroup GPIO_Pin_sources
|
|||
|
* @{
|
|||
|
*/
|
|||
|
|
|||
|
#define GPIO_PinSource0 ((uint8_t)0x00)
|
|||
|
#define GPIO_PinSource1 ((uint8_t)0x01)
|
|||
|
#define GPIO_PinSource2 ((uint8_t)0x02)
|
|||
|
#define GPIO_PinSource3 ((uint8_t)0x03)
|
|||
|
#define GPIO_PinSource4 ((uint8_t)0x04)
|
|||
|
#define GPIO_PinSource5 ((uint8_t)0x05)
|
|||
|
#define GPIO_PinSource6 ((uint8_t)0x06)
|
|||
|
#define GPIO_PinSource7 ((uint8_t)0x07)
|
|||
|
#define GPIO_PinSource8 ((uint8_t)0x08)
|
|||
|
#define GPIO_PinSource9 ((uint8_t)0x09)
|
|||
|
#define GPIO_PinSource10 ((uint8_t)0x0A)
|
|||
|
#define GPIO_PinSource11 ((uint8_t)0x0B)
|
|||
|
#define GPIO_PinSource12 ((uint8_t)0x0C)
|
|||
|
#define GPIO_PinSource13 ((uint8_t)0x0D)
|
|||
|
#define GPIO_PinSource14 ((uint8_t)0x0E)
|
|||
|
#define GPIO_PinSource15 ((uint8_t)0x0F)
|
|||
|
|
|||
|
#define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource1) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource2) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource3) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource4) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource5) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource6) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource7) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource8) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource9) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource10) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource11) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource12) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource13) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource14) || \
|
|||
|
((PINSOURCE) == GPIO_PinSource15))
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/** @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, uint16_t GPIO_Pin);
|
|||
|
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_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_EventOutputConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
|
|||
|
void GPIO_EventOutputCmd(FunctionalState NewState);
|
|||
|
void GPIO_PinRemapConfig(uint32_t GPIO_Remap, FunctionalState NewState);
|
|||
|
void GPIO_EXTILineConfig(uint8_t GPIO_PortSource, uint8_t GPIO_PinSource);
|
|||
|
|
|||
|
#endif /* __HAL_GPIO_H */
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/**
|
|||
|
* @}
|
|||
|
*/
|
|||
|
|
|||
|
/*-------------------------(C) COPYRIGHT 2019 MindMotion ----------------------*/
|