大家好我是逸风,第一次写博客,此文给那些想提供一个具有入门视角,易上手的代码讲解。
#ifndef GPIO_H_
#define GPIO_H_
namespace stm32 {
//作用域
extern int log2(unsigned int value);
/*
以下是引脚分组,模式等的枚举类型,mask都是从
官方库里复制粘贴的*/
typedef enum {
Port_A = 0x00,Port_B = 0x01,Port_C,Port_D,Port_E,Port_F,Port_G
} Port;
typedef enum {
Pin_0 = 0x0001,
Pin_1 = 0x0002,
Pin_2 = 0x0004,
Pin_3 = 0x0008,
Pin_4 = 0x0010,
Pin_5 = 0x0020,
Pin_6 = 0x0040,
Pin_7 = 0x0080,
Pin_8 = 0x0100,
Pin_9 = 0x0200,
Pin_10 = 0x0400,
Pin_11 = 0x0800,
Pin_12 = 0x1000,
Pin_13 = 0x2000,
Pin_14 = 0x4000,
Pin_15 = 0x8000,
Pin_Low8 = 0x00ff,
Pin_High8 = 0xff00,
Pin_All = 0xffff
} Pin;
typedef enum {
J_Mode_Output_10MHz = 1,
J_Mode_Output_2MHz,
J_Mode_Output_50MHz
} Mode;
typedef enum {
J_GPIO_Mode_AIN = 0x0,
J_GPIO_Mode_IN_FLOATING = 0x04,
J_GPIO_Mode_IPD = 0x28,
J_GPIO_Mode_IPU = 0x48,
J_GPIO_Mode_Out_OD = 0x14,
J_GPIO_Mode_Out_PP = 0x10,
J_GPIO_Mode_AF_OD = 0x1C,
J_GPIO_Mode_AF_PP = 0x18
} IOMode