www.pudn.com > OSBDM08.zip > usb.h


typedef struct {    /* 16 bit value in little endian notation */ 
	unsigned char lo; 
	unsigned char hi; 
} lendian_word; 
 
/* device descriptor */ 
typedef struct { 
	unsigned char bLength;				    /* Size of this Descriptor in Bytes */ 
	unsigned char bDescriptorType;		/* Descriptor Type (=1) */ 
	lendian_word  bcdUSB;				      /* USB Spec Release Number in BCD */ 
	unsigned char bDeviceClass;			  /* Device Class Code */ 
	unsigned char bDeviceSubClass;		/* Device Subclass Code */	 
	unsigned char bDeviceProtocol;		/* Device Protocol Code */ 
	unsigned char bMaxPacketSize0;		/* Maximum Packet Size for EP0 */ 
	lendian_word  idVendor; 			    /* Vendor ID */  
	lendian_word  idProduct;		      /* Product ID */ 
	lendian_word  bcdDevice;		      /* Device Release Number in BCD */ 
	unsigned char iManufacturer;		  /* Index of String Desc for Manufacturer */ 
	unsigned char iProduct;				    /* Index of String Desc for Product */ 
	unsigned char iSerialNumber;		  /* Index of String Desc for SerNo */ 
	unsigned char bNumConfigurations;	/* Number of possible Configurations */ 
} device_descriptor; 
 
/* Standard Configuration Descriptor */ 
typedef struct { 
	unsigned char bLength;				    /* Size of this Descriptor in Bytes */ 
	unsigned char bDescriptorType;		/* Descriptor Type (=2) */ 
	lendian_word wTotalLength;			  /* Total Length of Data for this Configuration */ 
	unsigned char bNumInterfaces;		  /* No of Interfaces supported by this Configuration */ 
	unsigned char bConfigurationValue;/* Designator Value for this Configuration */ 
	unsigned char iConfiguration;		  /* Index of String Desc for this Configuration */ 
	unsigned char bmAttributes;			  /* Configuration Characteristics */ 
	unsigned char bMaxPower;			    /* Max. Power Consumption in this Configuration (in 2mA steps) */ 
} configuration_descriptor; 
 
/* Standard Interface Descriptor */ 
typedef struct { 
	unsigned char bLength;				    /* Size of this Descriptor in Bytes */ 
	unsigned char bDescriptorType;		/* Descriptor Type (=4) */ 
	unsigned char bInterfaceNumber;		/* Number of this Interface (0..) */ 
	unsigned char bAlternateSetting;	/* Alternative for this Interface (if any) */ 
	unsigned char bNumEndpoints;		  /* No of EPs used by this IF (excl. EP0) */ 
	unsigned char bInterfaceClass;		/* Interface Class Code */ 
	unsigned char bInterfaceSubClass;	/* Interface Subclass Code */ 
	unsigned char bInterfaceProtocol;	/* Interface Protocol Code */ 
	unsigned char iInterface;			    /* Index of String Desc for this Interface */ 
} interface_descriptor; 
 
/* Standard Endpoint Descriptor */ 
typedef struct { 
	unsigned char bLength;				    /* Size of this Descriptor in Bytes */ 
	unsigned char bDescriptorType;		/* Descriptor Type (=5) */ 
	unsigned char bEndpointAddress;		/* Endpoint Address (Number + Direction) */ 
	unsigned char bmAttributes;			  /* Endpoint Attributes (Transfer Type) */ 
	lendian_word wMaxPacketSize;	    /* Max. Endpoint Packet Size */ 
	unsigned char bInterval;			    /* Polling Interval (Interrupt) in ms */ 
} endpoint_descriptor; 
 
/* Structure of Setup Packet sent during SETUP Stage of Standard Device Requests */ 
typedef struct { 
	unsigned char bmRequestType;		  /* Characteristics (Direction,Type,Recipient) */ 
	unsigned char bRequest;				    /* Standard Request Code */ 
	lendian_word wValue;				      /* Value Field */ 
	lendian_word wIndex;				      /* Index or Offset Field */ 
	lendian_word wLength;				      /* Number of Bytes to transfer (Data Stage) */ 
} setup_packet; 
 
/* USB Status Codes */ 
#define US_ATTACHED			0x00 
#define US_POWERED			0x01 
#define US_DEFAULT			0x02 
#define US_ADDRESSED		0x03 
#define US_CONFIGURED		0x04 
#define US_SUSPENDED		0x80 
 
/* USB Standard Device Request Codes */ 
#define GET_STATUS			0x00 
#define CLEAR_FEATURE		0x01 
#define SET_FEATURE			0x03 
#define SET_ADDRESS			0x05 
#define GET_DESCRIPTOR	0x06 
#define SET_DESCRIPTOR	0x07 
#define GET_CONFIGURATION	0x08 
#define SET_CONFIGURATION	0x09 
#define GET_INTERFACE		0x0a 
#define SET_INTERFACE		0x0b 
#define SYNCH_FRAME			0x0c 
 
/* Descriptor Types */ 
#define DT_DEVICE 			1 
#define DT_CONFIGURATION 2 
#define DT_STRING	  		3 
#define DT_INTERFACE		4 
#define DT_ENDPOINT			5 
 
/* Function Prototypes */ 
void copydown(unsigned char count, unsigned char * far src, unsigned char * dest); 
unsigned char copystring(unsigned char index, unsigned char * dest); 
void usb_1ms_tick(void); 
void USB_ep0_tx(void); 
void USB_ep2_tx(void); 
void USB_ep0_rx(void); 
void USB_ep2_rx(void); 
void USB_Setup(void); 
void interrupt usb_isr(void); 
void usb_init(void); 
 
/* shared variables */ 
#define COMMAND_BUFFER_SIZE MAX_DATA_SIZE+6 
extern unsigned char command_buffer[105];