-
Notifications
You must be signed in to change notification settings - Fork 11
/
descriptor.h
166 lines (140 loc) · 6.63 KB
/
descriptor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#ifndef _DESCRIPTOR_H
#define _DESCRIPTOR_H
#include <stdint.h>
#define DL_DEVICE 0x12
#define DL_CONFIGURATION 0x09
#define DL_INTERFACE 0x09
#define DL_ENDPOINT 0x07
#define DL_LANGUAGE 0x04
#define mA /2
#define DT_DEVICE 1
#define DT_CONFIGURATION 2
#define DT_STRING 3
#define DT_LANGUAGE 3
#define DT_INTERFACE 4
#define DT_ENDPOINT 5
#define USB_VERSION_1_0 0x0100
#define USB_VERSION_1_1 0x0110
#define USB_VERSION_2_0 0x0200
#define USB_VERSION_3_0 0x0300
#define UC_PER_INTERFACE 0x00
#define UC_AUDIO 0x01
#define UC_COMM 0x02
#define UC_HID 0x03
#define UC_PHYSICAL 0x05
#define UC_STILL_IMAGE 0x06
#define UC_PRINTER 0x07
#define UC_MASS_STORAGE 0x08
#define UC_HUB 0x09
#define UC_CDC_DATA 0x0A
#define UC_CSCID 0x0B
#define UC_CONTENT_SEC 0x0D
#define UC_VIDEO 0x0E
#define UC_WIRELESS_CONTROLLER 0xE0
#define UC_MISC 0xEF
#define UC_APP_SPEC 0xFE
#define UC_VENDOR_SPEC 0xFF
#define CA_BUSPOWERED 0x80
#define CA_SELFPOWERED 0x40
#define CA_REMOTEWAKEUP 0x20
#define EP_DIR_MASK 0x80
#define EP_DIR_OUT 0x00
#define EP_DIR_IN 0x80
#define EA_CONTROL 0x00
#define EA_ISOCHRONOUS 0x01
#define EA_BULK 0x02
#define EA_INTERRUPT 0x03
#define EA_ISO_NONE 0x00
#define EA_ISO_ASYNC 0x04
#define EA_ISO_ADAPTIVE 0x08
#define EA_ISO_SYNC 0x0C
#define EA_ISO_TYPE_DATA 0x00
#define EA_ISO_TYPE_FEEDBACK 0x10
#define EA_ISO_TYPE_EXPLICIT 0x20
#define SL_USENGLISH 0x0409
#define SL_AUENGLISH 0x0C09
#define SL_GERMAN 0x0407
// #include "USBEndpoints.h"
typedef struct
__attribute__ ((packed))
{
uint8_t bLength; // descriptor length
uint8_t bDescType; // descriptor type: see DT_* defines
}
usbdesc_base;
typedef struct
__attribute__ ((packed))
{
uint8_t bLength; // Device descriptor length (0x12)
uint8_t bDescType; // DT_DEVICE (0x01)
uint16_t bcdUSB; // USB Specification Number which device complies to - see USB_VERSION_* defines
uint8_t bDeviceClass; // USB Device Class - see UC_* defines
uint8_t bDeviceSubClass; // Subclass Code
uint8_t bDeviceProtocol; // Protocol Code
uint8_t bMaxPacketSize; // Maximum Packet Size for Zero Endpoint. Valid Sizes are 8, 16, 32, 64
uint16_t idVendor; // Vendor ID
uint16_t idProduct; // Product ID
uint16_t bcdDevice; // Device Release Number
uint8_t iManufacturer; // Index of Manufacturer String Descriptor
uint8_t iProduct; // Index of Product String Descriptor
uint8_t iSerialNumber; // Index of Serial Number String Descriptor
uint8_t bNumConfigurations; // Number of Possible Configurations
}
usbdesc_device;
typedef struct
__attribute__ ((packed))
{
uint8_t bLength; // Configuration Descriptor Length (0x09)
uint8_t bDescType; // DT_CONFIGURATION (0x02)
uint16_t wTotalLength; // Total length in bytes of this descriptor plus all this configuration's interfaces plus their endpoints, see http://www.beyondlogic.org/usbnutshell/confsize.gif
uint8_t bNumInterfaces; // Number of Interfaces
uint8_t bConfigurationValue; // Value that host uses to select this configuration
uint8_t iConfiguration; // Index of String Descriptor describing this configuration
uint8_t bmAttributes; // bitmap. see CA_* defines
uint8_t bMaxPower; // Max. Current = bMaxPower * 2mA
}
usbdesc_configuration;
typedef struct
__attribute__ ((packed))
{
uint8_t bLength; // Interface Descriptor Length (0x09)
uint8_t bDescType; // DT_INTERFACE (0x04)
uint8_t bInterfaceNumber; // Number of Interface
uint8_t bAlternateSetting; // Value used to select alternative setting
uint8_t bNumEndPoints; // Number of Endpoints used for this interface
uint8_t bInterfaceClass; // Class Code - see Device_Class_Enum
uint8_t bInterfaceSubClass; // Subclass Code
uint8_t bInterfaceProtocol; // Protocol Code
uint8_t iInterface; // Index of String Descriptor Describing this interface
}
usbdesc_interface;
typedef struct
__attribute__ ((packed))
{
uint8_t bLength; // Endpoint Descriptor Length (0x07)
uint8_t bDescType; // DT_ENDPOINT (0x05)
uint8_t bEndpointAddress; // 0x00-0x0F = OUT endpoints, 0x80-0x8F = IN endpoints
uint8_t bmAttributes; // bitmap, see Endpoint_Attributes_Enum
uint16_t wMaxPacketSize; // Maximum Packet Size this endpoint is capable of sending or receiving
uint8_t bInterval; // Interval for polling endpoint data transfers. Value in frame counts. Ignored for Bulk & Control Endpoints. Isochronous must equal 1 and field may range from 1 to 255 for interrupt endpoints.
}
usbdesc_endpoint;
typedef struct
__attribute__ ((packed))
{
uint8_t bLength; // String Descriptor Length (2 + 2*nLang)
uint8_t bDescType; // DT_STRING (0x03)
uint16_t wLangID[1]; // language code(s)
}
usbdesc_language;
typedef struct
__attribute__ ((packed))
{
uint8_t bLength; // 2 + strlen
uint8_t bDescType; // DT_STRING (0x03)
uint16_t str[]; // UNICODE string
}
usbdesc_string;
#define usbdesc_string_l(l) struct __attribute__ ((packed)) { uint8_t bLength; uint8_t bDescType; uint16_t str[l]; }
#define usbstring(size, string) { (2 + (2 * (size))), DT_STRING, u ## string }
#endif /* _DESCRIPTOR_H */