📄 define.h
字号:
#include <iom8v.h>
#include <macros.h>
#define USB_COMMAND_ADD 1
#define USB_DATA_ADD 0
//USB芯片连接引脚
#define USB_DATA PORTB
#define D12INT 2
#define D12A0 3
#define D12RD 4
#define D12WR 5
#define D12RESET 6
#define ENDPOINT_NUMBER 2
#define MAX_CONTROL_DATA_SIZE 16
#define setbit(x,y) x|=(1<<y)
#define clrbit(x,y) x&=(~(1<<y))
#define getbit(x,y) x&(1<<y)
//控制传输时保存数据
CONTROL_DATA_BUFF Control_Data;
//缓冲
unsigned char buffer[64];
//交换数据时用的指针
unsigned char *pData;
unsigned char idle; //空闲状态
unsigned char protocol; //当前协议
//高低字节交换
#define SWAP16(x) ((((unsigned int)(x))<<8)|(((unsigned int)(x))>>8))
//取一个整数的低字节
#define LSB(x) ((unsigned char)(x))
//取一个整数的高字节
#define MSB(x) ((unsigned char)(((unsigned int)(x))>>8))
//字符串描述符所用的语言种类
const unsigned char LANGUAGE_ID[4]={0x04,0x03,0x09,0x04};
//设备序列号
const unsigned char device_serial_number[]=
{22,STRING_DESCRIPTOR,'2',0,'0',0,'0',0,'7',0,'-',0,'0',0,'3',0,'-',0,'2',0,'3',0};
//厂商字符串
const unsigned char ManufacturerString[80]=
{80,STRING_DESCRIPTOR,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x84,0x76,0xB6,0x5B,
0x53,0x5F,'-',0x00,'-',0x00,'-',0x00,'-',0x00,'@',0,0x20,0x00,'H',0,'t',0,'t',0,
'p',0,':',0,'/',0,'/',0,'C',0,'o',0,'m',0,'p',0,'u',0,'t',0,'e',0,'r',0,'0',0,
'0',0,'.',0,'2',0,'1',0,'i',0,'c',0,'.',0,'o',0,'r',0,'g',0};
//产品字符串
const unsigned char ProducterString[80]=
{80,STRING_DESCRIPTOR,0x35,0x75,0x11,0x81,0x08,0x57,0x08,0x57,0x5A,0x50,0x84,0x76,
'U',0,'S',0,'B',0,0x20,0x9F,0x07,0x68,'@',0,0x20,0x00,'H',0,'t',0,'t',0,
'p',0,':',0,'/',0,'/',0,'C',0,'o',0,'m',0,'p',0,'u',0,'t',0,'e',0,'r',0,'0',0,
'0',0,'.',0,'2',0,'1',0,'i',0,'c',0,'.',0,'o',0,'r',0,'g',0};
const DEVICE_DESCRIPTOR_STRUCT device_descriptor= //设备描述符
{
sizeof(DEVICE_DESCRIPTOR_STRUCT), //设备描述符的字节数大小
DEVICE_DESCRIPTOR, //设备描述符类型编号
0x1001, //USB版本号
0x00, //USB分配的设备类代码
0x00, //USB分配的子类代码
0x00, //USB分配的设备协议代码
0x10, //端点0的最大包大小
0x3412, //厂商编号VID,这里只是作为测试用,请使用自己的VID
0x7956, //产品编号PID,这里只是作为测试用,请使用自己的PID
0x0100, //设备出厂编号
0x01, //设备厂商字符串的索引
0x02, //描述产品字符串的索引
0x03, //描述设备序列号字符串的索引
0x01 //可能的配置数量
};
//定义配置,接口,端点等描述符结构体,因为它们是随配置描述符一起返回的
typedef struct _CON_INT_ENDP_DESCRIPTOR_STRUCT
{
CONFIGURATION_DESCRIPTOR_STRUCT configuration_descriptor;
INTERFACE_DESCRIPTOR_STRUCT interface_descriptor;
HID_DESCRIPTOR_STRUCT hid_descriptor;
ENDPOINT_DESCRIPTOR_STRUCT endpoint_descriptor[ENDPOINT_NUMBER];
}CON_INT_ENDP_DESCRIPTOR_STRUCT;
const CON_INT_ENDP_DESCRIPTOR_STRUCT con_int_endp_descriptor=
{
//configuration_descriptor //配置描述符
{
sizeof(CONFIGURATION_DESCRIPTOR_STRUCT), //配置描述符的字节数大小
CONFIGURATION_DESCRIPTOR, //配置描述符类型编号
SWAP16(sizeof(CON_INT_ENDP_DESCRIPTOR_STRUCT)),
0x01, //只包含一个接口
0x01, //该配置的编号
0x00, //iConfiguration字段
0xA0, //采用总线供电,支持远程唤醒
0xC8 //从总线获取最大电流400mA
},
//interface_descritor //接口描述符
{
sizeof(INTERFACE_DESCRIPTOR_STRUCT), //接口描述符的字节数大小
INTERFACE_DESCRIPTOR, //接口描述符类型编号
0x00, //接口编号为0
0x00, //该接口描述符的编号
ENDPOINT_NUMBER, //非0端点数量为2,只使用端点主端点输入和输出
0x03, //人机接口设备(HID)类
0x01, //使用的子类:支持BIOS根启动Boot的子类
0x02, //使用的协议:鼠标
0x00 //接口描述符字符串索引
},
//hid_descriptor
{
sizeof(HID_DESCRIPTOR_STRUCT), //HID描述符的字节数大小
HID_DESCRIPTOR, //HID描述符类型编号
0x1001, //HID类协议版本号,为1.1
0x21, //固件的国家地区代号,0x21为美国
NUM_SUB_DESCRIPTORS, //下级描述符的数量
{
{
REPORT_DESCRIPTOR, //下级描述符为报告描述符
SWAP16(sizeof(MouseReportDescriptor)) //下级描述符的长度
}
},
},
//endpoint_descriptor[]
{
{ //主端点输入描述
sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端点描述符的字节数大小
ENDPOINT_DESCRIPTOR, //端点描述符类型编号
MAIN_POINT_IN, //端点号,主输入端点
ENDPOINT_TYPE_INTERRUPT, //使用的传输类型:中断传输
0x4000, //该端点支持的最大包尺寸,64字节
0x0A //中断扫描时间:设置为10ms
},
{ //主端点输出描述
sizeof(ENDPOINT_DESCRIPTOR_STRUCT), //端点描述符的字节数大小
ENDPOINT_DESCRIPTOR, //端点描述符类型编号
MAIN_POINT_OUT, //端点号,主输出端点
ENDPOINT_TYPE_INTERRUPT, //使用的传输类型:中断传输
0x4000, //该端点支持的最大包尺寸,64字节
0x0A //中断扫描时间:设置为10ms
}
}
};
union //程序标志位
{
uint16 Register;
struct
{
unsigned char bus_reset :1;
unsigned char suspend :1;
unsigned char remote_wakeup :1;
unsigned char int_isr :1;
unsigned char not_end :1;
unsigned char usb_idle :1;
unsigned char usb_busy :1;
unsigned char setup_packet_in :1;
unsigned char setup_packet_out :1;
unsigned char set_addr :1;
unsigned char usb_endp0_in :1;
unsigned char usb_endp2_in :1;
unsigned char usb_endp2_out :1;
}flags;
}usb_flags;
union //中断寄存器
{
unsigned char Register[2];
struct
{
unsigned char control_out_port :1;
unsigned char control_in_port :1;
unsigned char port_out_1 :1;
unsigned char port_in_1 :1;
unsigned char main_out_port :1;
unsigned char main_in_port :1;
unsigned char bus_reset :1;
unsigned char suspend_change :1;
unsigned char DMA_EOT :1;
unsigned char not_use :7;
}Interrupt;
}Interrupt_Register;
union //端点最后处理状态
{
unsigned char Register;
struct
{
unsigned char successful :1;
unsigned char error_code :4;
unsigned char setup_packet :1;
unsigned char data_1 :1;
unsigned char prestatus_not_read :1;
}Status;
}Last_Status;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -