Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
/* Copyright 2009-2011 Oleg Mazurov, Circuits At Home, http://www.circuitsathome.com */
2
/* USB chapter 9 structures */
3
#ifndef _ch9_h_
4
#define _ch9_h_
5
 
6
/* Misc.USB constants */
7
#define DEV_DESCR_LEN   18      //device descriptor length
8
#define CONF_DESCR_LEN  9       //configuration descriptor length
9
#define INTR_DESCR_LEN  9       //interface descriptor length
10
#define EP_DESCR_LEN    7       //endpoint descriptor length
11
 
12
/* Standard Device Requests */
13
 
14
#define USB_REQUEST_GET_STATUS                  0       // Standard Device Request - GET STATUS
15
#define USB_REQUEST_CLEAR_FEATURE               1       // Standard Device Request - CLEAR FEATURE
16
#define USB_REQUEST_SET_FEATURE                 3       // Standard Device Request - SET FEATURE
17
#define USB_REQUEST_SET_ADDRESS                 5       // Standard Device Request - SET ADDRESS
18
#define USB_REQUEST_GET_DESCRIPTOR              6       // Standard Device Request - GET DESCRIPTOR
19
#define USB_REQUEST_SET_DESCRIPTOR              7       // Standard Device Request - SET DESCRIPTOR
20
#define USB_REQUEST_GET_CONFIGURATION           8       // Standard Device Request - GET CONFIGURATION
21
#define USB_REQUEST_SET_CONFIGURATION           9       // Standard Device Request - SET CONFIGURATION
22
#define USB_REQUEST_GET_INTERFACE               10      // Standard Device Request - GET INTERFACE
23
#define USB_REQUEST_SET_INTERFACE               11      // Standard Device Request - SET INTERFACE
24
#define USB_REQUEST_SYNCH_FRAME                 12      // Standard Device Request - SYNCH FRAME
25
 
26
#define USB_FEATURE_ENDPOINT_HALT               0       // CLEAR/SET FEATURE - Endpoint Halt
27
#define USB_FEATURE_DEVICE_REMOTE_WAKEUP        1       // CLEAR/SET FEATURE - Device remote wake-up
28
#define USB_FEATURE_TEST_MODE                   2       // CLEAR/SET FEATURE - Test mode
29
 
30
/* Setup Data Constants */
31
 
32
#define USB_SETUP_HOST_TO_DEVICE                0x00    // Device Request bmRequestType transfer direction - host to device transfer
33
#define USB_SETUP_DEVICE_TO_HOST                0x80    // Device Request bmRequestType transfer direction - device to host transfer
34
#define USB_SETUP_TYPE_STANDARD                 0x00    // Device Request bmRequestType type - standard
35
#define USB_SETUP_TYPE_CLASS                    0x20    // Device Request bmRequestType type - class
36
#define USB_SETUP_TYPE_VENDOR                   0x40    // Device Request bmRequestType type - vendor
37
#define USB_SETUP_RECIPIENT_DEVICE              0x00    // Device Request bmRequestType recipient - device
38
#define USB_SETUP_RECIPIENT_INTERFACE           0x01    // Device Request bmRequestType recipient - interface
39
#define USB_SETUP_RECIPIENT_ENDPOINT            0x02    // Device Request bmRequestType recipient - endpoint
40
#define USB_SETUP_RECIPIENT_OTHER               0x03    // Device Request bmRequestType recipient - other
41
 
42
/* USB descriptors  */
43
 
44
#define USB_DESCRIPTOR_DEVICE           0x01    // bDescriptorType for a Device Descriptor.
45
#define USB_DESCRIPTOR_CONFIGURATION    0x02    // bDescriptorType for a Configuration Descriptor.
46
#define USB_DESCRIPTOR_STRING           0x03    // bDescriptorType for a String Descriptor.
47
#define USB_DESCRIPTOR_INTERFACE        0x04    // bDescriptorType for an Interface Descriptor.
48
#define USB_DESCRIPTOR_ENDPOINT         0x05    // bDescriptorType for an Endpoint Descriptor.
49
#define USB_DESCRIPTOR_DEVICE_QUALIFIER 0x06    // bDescriptorType for a Device Qualifier.
50
#define USB_DESCRIPTOR_OTHER_SPEED      0x07    // bDescriptorType for a Other Speed Configuration.
51
#define USB_DESCRIPTOR_INTERFACE_POWER  0x08    // bDescriptorType for Interface Power.
52
#define USB_DESCRIPTOR_OTG              0x09    // bDescriptorType for an OTG Descriptor.
53
 
54
/* OTG SET FEATURE Constants    */
55
#define OTG_FEATURE_B_HNP_ENABLE                3       // SET FEATURE OTG - Enable B device to perform HNP
56
#define OTG_FEATURE_A_HNP_SUPPORT               4       // SET FEATURE OTG - A device supports HNP
57
#define OTG_FEATURE_A_ALT_HNP_SUPPORT           5       // SET FEATURE OTG - Another port on the A device supports HNP
58
 
59
/* USB Endpoint Transfer Types  */
60
#define USB_TRANSFER_TYPE_CONTROL               0x00    // Endpoint is a control endpoint.
61
#define USB_TRANSFER_TYPE_ISOCHRONOUS           0x01    // Endpoint is an isochronous endpoint.
62
#define USB_TRANSFER_TYPE_BULK                  0x02    // Endpoint is a bulk endpoint.
63
#define USB_TRANSFER_TYPE_INTERRUPT             0x03    // Endpoint is an interrupt endpoint.
64
#define bmUSB_TRANSFER_TYPE                     0x03    // bit mask to separate transfer type from ISO attributes
65
 
66
 
67
/* Standard Feature Selectors for CLEAR_FEATURE Requests    */
68
#define USB_FEATURE_ENDPOINT_STALL              0       // Endpoint recipient
69
#define USB_FEATURE_DEVICE_REMOTE_WAKEUP        1       // Device recipient
70
#define USB_FEATURE_TEST_MODE                   2       // Device recipient
71
 
72
/* HID constants. Not part of chapter 9 */
73
/* Class-Specific Requests */
74
#define HID_REQUEST_GET_REPORT      0x01
75
#define HID_REQUEST_GET_IDLE        0x02
76
#define HID_REQUEST_GET_PROTOCOL    0x03
77
#define HID_REQUEST_SET_REPORT      0x09
78
#define HID_REQUEST_SET_IDLE        0x0A
79
#define HID_REQUEST_SET_PROTOCOL    0x0B
80
 
81
/* Class Descriptor Types */
82
#define HID_DESCRIPTOR_HID      0x21
83
#define HID_DESCRIPTOR_REPORT   0x22
84
#define HID_DESRIPTOR_PHY       0x23
85
 
86
/* Protocol Selection */
87
#define BOOT_PROTOCOL   0x00
88
#define RPT_PROTOCOL    0x01
89
/* HID Interface Class Code */
90
#define HID_INTF                    0x03
91
/* HID Interface Class SubClass Codes */
92
#define BOOT_INTF_SUBCLASS          0x01
93
/* HID Interface Class Protocol Codes */
94
#define HID_PROTOCOL_NONE           0x00
95
#define HID_PROTOCOL_KEYBOARD       0x01
96
#define HID_PROTOCOL_MOUSE          0x02
97
 
98
 
99
/* descriptor data structures */
100
 
101
/* Device descriptor structure */
102
typedef struct {
103
    byte bLength;               // Length of this descriptor.
104
    byte bDescriptorType;       // DEVICE descriptor type (USB_DESCRIPTOR_DEVICE).
105
    unsigned int bcdUSB;        // USB Spec Release Number (BCD).
106
    byte bDeviceClass;          // Class code (assigned by the USB-IF). 0xFF-Vendor specific.
107
    byte bDeviceSubClass;       // Subclass code (assigned by the USB-IF).
108
    byte bDeviceProtocol;       // Protocol code (assigned by the USB-IF). 0xFF-Vendor specific.
109
    byte bMaxPacketSize0;       // Maximum packet size for endpoint 0.
110
    unsigned int idVendor;      // Vendor ID (assigned by the USB-IF).
111
    unsigned int idProduct;     // Product ID (assigned by the manufacturer).
112
    unsigned int bcdDevice;      // Device release number (BCD).
113
    byte iManufacturer;         // Index of String Descriptor describing the manufacturer.
114
    byte iProduct;              // Index of String Descriptor describing the product.
115
    byte iSerialNumber;         // Index of String Descriptor with the device's serial number.
116
    byte bNumConfigurations;    // Number of possible configurations.
117
} USB_DEVICE_DESCRIPTOR;
118
 
119
/* Configuration descriptor structure */
120
typedef struct
121
{
122
    byte bLength;               // Length of this descriptor.
123
    byte bDescriptorType;       // CONFIGURATION descriptor type (USB_DESCRIPTOR_CONFIGURATION).
124
    unsigned int wTotalLength;          // Total length of all descriptors for this configuration.
125
    byte bNumInterfaces;        // Number of interfaces in this configuration.
126
    byte bConfigurationValue;   // Value of this configuration (1 based).
127
    byte iConfiguration;        // Index of String Descriptor describing the configuration.
128
    byte bmAttributes;          // Configuration characteristics.
129
    byte bMaxPower;             // Maximum power consumed by this configuration.
130
} USB_CONFIGURATION_DESCRIPTOR;
131
 
132
/* Interface descriptor structure */
133
typedef struct
134
{
135
    byte bLength;               // Length of this descriptor.
136
    byte bDescriptorType;       // INTERFACE descriptor type (USB_DESCRIPTOR_INTERFACE).
137
    byte bInterfaceNumber;      // Number of this interface (0 based).
138
    byte bAlternateSetting;     // Value of this alternate interface setting.
139
    byte bNumEndpoints;         // Number of endpoints in this interface.
140
    byte bInterfaceClass;       // Class code (assigned by the USB-IF).  0xFF-Vendor specific.
141
    byte bInterfaceSubClass;    // Subclass code (assigned by the USB-IF).
142
    byte bInterfaceProtocol;    // Protocol code (assigned by the USB-IF).  0xFF-Vendor specific.
143
    byte iInterface;            // Index of String Descriptor describing the interface.
144
} USB_INTERFACE_DESCRIPTOR;
145
 
146
/* Endpoint descriptor structure */
147
typedef struct
148
{
149
    byte bLength;               // Length of this descriptor.
150
    byte bDescriptorType;       // ENDPOINT descriptor type (USB_DESCRIPTOR_ENDPOINT).
151
    byte bEndpointAddress;      // Endpoint address. Bit 7 indicates direction (0=OUT, 1=IN).
152
    byte bmAttributes;          // Endpoint transfer type.
153
    unsigned int wMaxPacketSize;        // Maximum packet size.
154
    byte bInterval;             // Polling interval in frames.
155
} USB_ENDPOINT_DESCRIPTOR;
156
 
157
/* HID descriptor */
158
typedef struct {
159
    byte bLength;                      
160
        byte bDescriptorType;  
161
        unsigned int bcdHID;                    
162
    byte bCountryCode;          
163
        byte bNumDescriptors;
164
        byte bDescrType;                        
165
    unsigned int wDescriptorLength;
166
} USB_HID_DESCRIPTOR;
167
 
168
#endif // _ch9_h_