181 lines
4.1 KiB
C
181 lines
4.1 KiB
C
#pragma once
|
|
|
|
#include <stdlib.h>
|
|
|
|
/*************************************************
|
|
|
|
usb_spec.h
|
|
|
|
Structures and Constants defined by USB 2.0 Spec.
|
|
|
|
*************************************************/
|
|
|
|
#include <stdint.h>
|
|
|
|
#define USB_VERSION_BCD 0x0110
|
|
|
|
#define DT_DEVICE 0x01
|
|
#define DT_CONFIGURATION 0x02
|
|
#define DT_STRING 0x03
|
|
#define DT_INTERFACE 0x04
|
|
#define DT_ENDPOINT 0x05
|
|
#define DT_DEVICE_QUALIFIER 0x06
|
|
#define DT_OTHER_SPEED_CONF 0x07
|
|
#define DT_INTERAFCE_POWER 0x08
|
|
|
|
#define USB_REQ_GET_STATUS 0x00
|
|
#define USB_REQ_CLEAR_FEATURE 0x01
|
|
#define USB_REQ_SET_FEATURE 0x03
|
|
#define USB_REQ_SET_ADDRESS 0x05
|
|
#define USB_REQ_GET_DESCRIPTOR 0x06
|
|
#define USB_REQ_SET_DESCRIPTOR 0x07
|
|
#define USB_REQ_GET_CONFIGURATION 0x08
|
|
#define USB_REQ_SET_CONFIGURATION 0x09
|
|
#define USB_REQ_GET_INTERFACE 0x0a
|
|
#define USB_REQ_SET_INTERFACE 0x0b
|
|
#define USB_REQ_SYNCH_FRAME 0x0c
|
|
|
|
#define REQT_HOSTTODEVICE (0)
|
|
#define REQT_DEVICETOHOST (1<<7)
|
|
|
|
#define REQT_STANDARD (0)
|
|
#define REQT_CLASS (1 << 5)
|
|
#define REQT_VENDOR (2 << 5)
|
|
|
|
#define REQT_REC_DEVICE (0)
|
|
#define REQT_REC_INTERFACE (1)
|
|
#define REQT_REC_ENDPOINT (2)
|
|
#define REQT_REC_OTHER (3)
|
|
|
|
#define REQT_CHECK(bmrt,dir,type,recipient) (bmrt == (dir | type | recipient))
|
|
#define REQT_CHECK_HOSTTODEVICE(bmrt) ((bmrt & REQT_HOSTTODEVICE) ? -1 : 0)
|
|
|
|
struct usb_descriptor_header;
|
|
struct usb_standard_device_descriptor;
|
|
struct usb_device_qualifier;
|
|
struct usb_standard_configuration_descriptor;
|
|
struct usb_other_speed_configuration;
|
|
struct usb_standard_interface_descriptor;
|
|
struct usb_standard_endpoint_descriptor;
|
|
struct usb_string_descriptor_zero;
|
|
struct usb_string_descriptor;
|
|
|
|
typedef struct usb_descriptor_header
|
|
usb_descriptor_header_t;
|
|
|
|
typedef struct usb_standard_device_descriptor
|
|
usb_standard_device_descriptor_t;
|
|
typedef struct usb_standard_endpoint_descriptor
|
|
usb_standard_endpoint_descriptor_t;
|
|
|
|
typedef struct usb_device_request
|
|
usb_device_request_t;
|
|
|
|
|
|
struct usb_descriptor_header
|
|
{
|
|
uint8_t bLength;
|
|
uint8_t bDescriptorType;
|
|
};
|
|
|
|
struct usb_standard_device_descriptor
|
|
{
|
|
uint8_t bLength;
|
|
uint8_t bDescriptorType;
|
|
uint16_t bcdUSB;
|
|
uint8_t bDeviceClass;
|
|
uint8_t bDeviceSubClass;
|
|
uint8_t bDeviceProtocol;
|
|
uint8_t bMaxPacketSize0;
|
|
uint16_t idVendor,
|
|
idProduct,
|
|
bcdDevice;
|
|
uint8_t iManufacturer,
|
|
iProduct,
|
|
iSerialNumber,
|
|
bNumConfigurations;
|
|
};
|
|
|
|
struct usb_device_qualifier
|
|
{
|
|
uint8_t bLength,
|
|
bDescriptorType;
|
|
uint16_t bcdUSB;
|
|
uint8_t bDeviceClass,
|
|
bDeviceSubClass,
|
|
bDeviceProtocol,
|
|
bMaxPacketSize0,
|
|
bNumConfigurations,
|
|
bReserved;
|
|
};
|
|
|
|
struct usb_standard_configuration_descriptor
|
|
{
|
|
uint8_t bLength,
|
|
bDescriptorType;
|
|
uint16_t wTotalLength;
|
|
uint8_t bNumInterfaces,
|
|
bConfigurationValue,
|
|
iConfiguration,
|
|
bmAttributes,
|
|
bMaxPower;
|
|
};
|
|
|
|
struct usb_other_speed_configuration
|
|
{
|
|
uint8_t bLength,
|
|
bDescriptorType;
|
|
uint16_t wTotalLength;
|
|
uint8_t bNumInterfaces,
|
|
bConfigurationValue,
|
|
iConfiguration,
|
|
bmAttributes,
|
|
bMaxPower;
|
|
};
|
|
|
|
struct usb_standard_interface_descriptor
|
|
{
|
|
uint8_t bLength,
|
|
bDescriptorType,
|
|
bInterfaceNumber,
|
|
bAlternateSetting,
|
|
bNumEndpoints,
|
|
bInterfaceClass,
|
|
bInterfaceSubClass,
|
|
bInterfaceProtocol,
|
|
iInterface;
|
|
};
|
|
|
|
struct usb_standard_endpoint_descriptor
|
|
{
|
|
uint8_t bLength,
|
|
bDescriptorType,
|
|
bEndpointAddress,
|
|
bmAttributes;
|
|
uint16_t wMaxPacketSize;
|
|
uint8_t bInterval;
|
|
};
|
|
|
|
struct usb_string_descriptor
|
|
{
|
|
uint8_t bLength,
|
|
bDescriptorType;
|
|
wchar_t data[0];
|
|
};
|
|
|
|
|
|
|
|
|
|
struct usb_device_request
|
|
{
|
|
uint8_t bmRequestType,
|
|
bRequest;
|
|
uint16_t wValue,
|
|
wIndex,
|
|
wLength;
|
|
};
|
|
|
|
|
|
|
|
|