【GPIO配置】
typedef struct
{
union
{
__IO uint32_t cfglr;
struct
{
__IO uint32_t iomc0 : 2; /* [1:0] */
__IO uint32_t iofc0 : 2; /* [3:2] */
__IO uint32_t iomc1 : 2; /* [5:4] */
__IO uint32_t iofc1 : 2; /* [7:6] */
__IO uint32_t iomc2 : 2; /* [9:8] */
__IO uint32_t iofc2 : 2; /* [11:10] */
__IO uint32_t iomc3 : 2; /* [13:12] */
__IO uint32_t iofc3 : 2; /* [15:14] */
__IO uint32_t iomc4 : 2; /* [17:16] */
__IO uint32_t iofc4 : 2; /* [19:18] */
__IO uint32_t iomc5 : 2; /* [21:20] */
__IO uint32_t iofc5 : 2; /* [23:22] */
__IO uint32_t iomc6 : 2; /* [25:24] */
__IO uint32_t iofc6 : 2; /* [27:26] */
__IO uint32_t iomc7 : 2; /* [29:28] */
__IO uint32_t iofc7 : 2; /* [31:30] */
} cfglr_bit;
};
//……else cfg
}gpio_type;
上述列出为GPIO的配置低寄存器,对pin0~7进行配置,每pin占用4bits
两bits为IOMC,对GPIO模式进行配置,两bits为IMFC,对GPIO功能进行配置
用库函数配置GPIO模式时用下面枚举变量给gpio_init_struct->gpio_mode 赋值即可
typedef enum
{
GPIO_MODE_INPUT = 0x00, /*!< gpio input mode */
GPIO_MODE_OUTPUT = 0x10, /*!< gpio output mode */
GPIO_MODE_MUX = 0x08, /*!< gpio mux function mode */
GPIO_MODE_ANALOG = 0x03 /*!< gpio analog in/out mode */
} gpio_mode_type;
用库函数配置GPIO功能时,主要用下面枚举变量分别给gpio_init_struct->gpio_drive_strength、gpio_init_struct->gpio_out_type、gpio_init_struct->gpio_pull赋值即可(与STM32应该基本一致)
typedef enum
{
GPIO_DRIVE_STRENGTH_STRONGER = 0x01, /*!< stronger sourcing/sinking strength */
GPIO_DRIVE_STRENGTH_MODERATE = 0x02 /*!< moderate sourcing/sinking strength */
} gpio_drive_type;
/**
* @brief gpio output type
*/
typedef enum
{
GPIO_OUTPUT_PUSH_PULL = 0x00, /*!< output push-pull */
GPIO_OUTPUT_OPEN_DRAIN = 0x04 /*!< output open-drain */
} gpio_output_type;
/**
* @brief gpio pull type
*/
typedef enum
{
GPIO_PULL_NONE = 0x0004, /*!< floating for input, no pull for output */
GPIO_PULL_UP = 0x0018, /*!< pull-up */
GPIO_PULL_DOWN = 0x0028 /*!< pull-down */
} gpio_pull_type;
1206

被折叠的 条评论
为什么被折叠?



