📄 typedefint.h
字号:
rom byte* bRom; // Size depends on compiler setting
rom word* wRom;
//rom near byte* nbRom; // Near = 2 bytes pointer
//rom near word* nwRom;
//rom far byte* fbRom; // Far = 3 bytes pointer
//rom far word* fwRom;
} POINTER;
//----------------------------------USB缓冲描述符类型定义
typedef union _BD_STAT //缓冲描述符状态寄存器位定义
{
byte _byte;
struct{
unsigned BC8:1;
unsigned BC9:1;
unsigned BSTALL:1; //Buffer Stall Enable
unsigned DTSEN:1; //Data Toggle Synch Enable
unsigned INCDIS:1; //Address Increment Disable
unsigned KEN:1; //BD Keep Enable
unsigned DTS:1; //Data Toggle Synch Value
unsigned UOWN:1; //USB Ownership
};
struct{
unsigned BC8:1;
unsigned BC9:1;
unsigned PID0:1;
unsigned PID1:1;
unsigned PID2:1;
unsigned PID3:1;
unsigned :1;
unsigned UOWN:1;
};
struct{
unsigned :2;
unsigned PID:4; // PID包定义,占4位
unsigned :2;
};
} BD_STAT; // 缓冲描述状态寄存器
typedef union _BDT
{
struct
{
BD_STAT Stat; //缓冲描述符状态
byte Cnt; //缓冲描述符字节计数
byte ADRL; //缓冲区地址低字节
byte ADRH; //缓冲区地址高字节
};
struct
{
unsigned :8;
unsigned :8;
byte* ADR; //缓冲区地址,ADR占两个字节,但数据是一个字节
};
} BDT; //缓冲描述符表
//----------------------------控制传输配置标准数据字节类型定义
typedef union _CTRL_TRF_SETUP
{
// 排列间接地址
struct
{
byte _byte[EP0_BUFF_SIZE]; //#define EP0_BUFF_SIZE 8 ,8个字节的EP0缓冲区
};
// 标准的设备请求,在USB配置设备时用到的各个位下面都有定义,具体见USB标准请求
struct
{
byte bmRequestType; //设置数据的格式(标准的数据请求)
byte bRequest; //一个字节用来指定请求
word wValue; //主机用来传输信息给设备。每一个请求都可以自己定义这两个字节的意义
word wIndex; //主机用来传送信息给设备一般用来传送索引值或偏移
word wLength; //包含数据阶段中接下来的数据字节的数目,如果是主机设备的传输,表示主机设备传输的正确字节数目
//如果是设备到主机的传输,则是一个最大值,如果是0,表示没有数据阶段
};
struct
{
unsigned :8;
unsigned :8;
WORD W_Value;
WORD W_Index;
WORD W_Length;
};
struct
{
unsigned Recipient:5; //设备 接口 端点 其他,接收者定义,一般是00设备接收
unsigned RequestType:2; //是否是标准请求的标志
unsigned DataDir:1; //标志 主机到设备还是设备到主机
unsigned :8;
byte bFeature; //DEVICE_REMOTE_WAKEUP,ENDPOINT_HALT
unsigned :8;
unsigned :8;
unsigned :8;
unsigned :8;
unsigned :8;
};
struct
{
unsigned :8;
unsigned :8;
byte bDscIndex; //描述符值
byte bDscType; //Device,Configuration,String,驱动,配置,字符串,描述符类型
word wLangID; //Language ID,语言ID号
unsigned :8;
unsigned :8;
};
struct
{
unsigned :8;
unsigned :8;
BYTE bDevADR; //Device Address 0-127,驱动地址
byte bDevADRH; //Must equal zero 必须=0
unsigned :8;
unsigned :8;
unsigned :8;
unsigned :8;
};
struct
{
unsigned :8;
unsigned :8;
byte bCfgValue; //Configuration Value 0-255,配置取值范围
byte bCfgRSD; //Must equal zero (Reserved)
unsigned :8;
unsigned :8;
unsigned :8;
unsigned :8;
};
struct
{
unsigned :8;
unsigned :8;
byte bAltID; //Alternate Setting Value 0-255
byte bAltID_H; //Must equal zero
byte bIntfID; //Interface Number Value 0-255接口值
byte bIntfID_H; //Must equal zero
unsigned :8;
unsigned :8;
};
struct
{
unsigned :8;
unsigned :8;
unsigned :8;
unsigned :8;
byte bEPID; //Endpoint ID (Number & Direction)
byte bEPID_H; //Must equal zero
unsigned :8;
unsigned :8;
};
struct
{
unsigned :8;
unsigned :8;
unsigned :8;
unsigned :8;
unsigned EPNum:4; //Endpoint Number 0-15
unsigned :3;
unsigned EPDir:1; //Endpoint Direction: 0-OUT, 1-IN
unsigned :8;
unsigned :8;
unsigned :8;
};
//标准设备请求的数据定义
} CTRL_TRF_SETUP;
//----------------------------------USB数据类型定义
typedef union _CTRL_TRF_DATA //共8个字节
{
/** Array for indirect addressing ****************************************/
struct
{
byte _byte[EP0_BUFF_SIZE];
};
// 8个字节的间接地址 ***************************************/
struct
{
byte _byte0;
byte _byte1;
byte _byte2;
byte _byte3;
byte _byte4;
byte _byte5;
byte _byte6;
byte _byte7;
};
struct
{
word _word0;
word _word1;
word _word2;
word _word3;
};
} CTRL_TRF_DATA;
//********************USB 描述符定义***********************
/************** USB 描述符定义**************
************************ ******************/
//1.USB设备描述符类型定义
typedef struct _USB_DEV_DSC
{
byte bLength; //描述符大小
byte bDscType; //常数 0x01
word bcdUSB; //USB 版本号码 1.0是0100H,1.1是0110H,2.0是0200H
byte bDevCls; //类别码
byte bDevSubCls; //子类别
byte bDevProtocol; //协议码
byte bMaxPktSize0; //端点0的最大信息包大小
word idVendor; //厂商ID
word idProduct; //产品ID
word bcdDevice; //设备版本号码 (BCD)
byte iMFR; //制造者的字符串描述符的索引值
byte iProduct; //产品的字符串描述符的索引值
byte iSerialNum; //序号的字符串描述符的索引值
byte bNumCfg; //可能配置的数目
} USB_DEV_DSC;
// end USB_DEV_DSC
//2.USB配置描述符定义
//每一个配置描述符都有其附属属性,包括一个或多个接口描述符,以及选择性的端点描述符
typedef struct _USB_CFG_DSC
{
byte bLength; // 描述符大小
byte bDscType; // 常数 0x02
word wTotalLength; // 此配置符传回的所有数据大小(字节)
byte bNumIntf; // 此配置支持的接口数目
byte bCfgValue; // SET_Configuration与Get_Configuration请求的标识符。
// 如果SET_Configurationq请求值为0,设备会进入无配置状态
byte iCfg; // 此配置的字符串描述符
byte bmAttributes; // 位图自身电源/总线电源以及远程唤醒设置
byte bMaxPower; // 需要总线电源,表示法为(最大毫安/2)
} USB_CFG_DSC;
// end USB_CFG_DSC
//3.USB接口描述符定义
typedef struct _USB_INTF_DSC
{
byte bLength; // 描述符大小
byte bDscType; // 常数0x04
byte bIntfNum; // 识别此接口的数字
byte bAltSetting; // 用来选择一个替代设置的数值
byte bNumEPs; // 除了端点0外,支持的端点数目
byte bIntfCls; // 类别码
byte bIntfSubCls; // 子类别码
byte bIntfProtocol; // 协议码
byte iIntf; // 此接口的字符串描述符的索引值
} USB_INTF_DSC;
//4.USB 端点描述符
typedef struct _USB_EP_DSC
{
byte bLength; // 描述符大小
byte bDscType; // 常数0x05
byte bEPAdr; // 端点数目与方向
byte bmAttributes; // 支持的传输类型
word wMaxPktSize; // 支持的最大信息包大小
byte bInterval; // 最大延迟/轮询时距/NAK速率
} USB_EP_DSC;
//5.HID
//由于HID类别描述符最后有重复字节,最后部分可选(在使用多个描述符的设备)
typedef struct _USB_HID_HEADER
{
byte bDescriptorType;
word wDescriptorLength;
}USB_HID_HEADER;
typedef struct _USB_HID_DSC
{
byte bLength;
byte bDscType;
word bcdHID;
byte bCountryCode;
byte bNumDsc;
USB_HID_HEADER header[1]; //此例只使用一个
} USB_HID_DSC;
//这个是配置描述符定义(包含附属描述符)
#define CFG01 rom struct \
{ USB_CFG_DSC cd01; \
USB_INTF_DSC i00a00; \
USB_HID_DSC hid_i00a00; \
USB_EP_DSC ep01i_i00a00; \
USB_EP_DSC ep01o_i00a00; \
} cfg01
#define mUSBBufferReady(buffer_dsc) \
{ \
buffer_dsc.Stat._byte &= _DTSMASK; /* Save only DTS bit */ \
buffer_dsc.Stat.DTS = !buffer_dsc.Stat.DTS; /* Toggle DTS bit */ \
buffer_dsc.Stat._byte |= _USIE|_DTSEN; /* Turn ownership to SIE */ \
}
#define mUSBBufferReady(buffer_dsc) \
{ \
buffer_dsc.Stat._byte &= _DTSMASK; /* Save only DTS bit */ \
buffer_dsc.Stat.DTS = !buffer_dsc.Stat.DTS; /* Toggle DTS bit */ \
buffer_dsc.Stat._byte |= _USIE|_DTSEN; /* Turn ownership to SIE */ \
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -