blob: d313cb525c09cfe8240fb7c078140c5d44fb8bba (
plain)
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
#ifndef __PROTO_H__
#define __PROTO_H__
#include "../types.h"
// ---------- USB Protocol ----------
#define USB_DATA typedef struct __attribute__((__packed__))
// USB token PIDs
#define USB_PID_OUT 0b0001
#define USB_PID_IN 0b1001
#define USB_PID_SOF 0b0101
#define USB_PID_SETUP 0b1101
// USB data PIDs
#define USB_PID_DATA0 0b0011
#define USB_PID_DATA1 0b1011
#define USB_PID_DATA2 0b0111
#define USB_PID_MDATA 0b1111
// Standard Requests Code (bRequest)
#define USB_REQUEST_CODE_GET_STATUS 0
#define USB_REQUEST_CODE_CLEAR_FEATURE 1
#define USB_REQUEST_CODE_SET_FEATURE 3
#define USB_REQUEST_CODE_SET_ADDRESS 5
#define USB_REQUEST_CODE_GET_DESCRIPTOR 6
#define USB_REQUEST_CODE_SET_DESCRIPTOR 7
#define USB_REQUEST_CODE_GET_CONFIGURATION 8
#define USB_REQUEST_CODE_SET_CONFIGURATION 9
#define USB_REQUEST_CODE_GET_INTERFACE 10
#define USB_REQUEST_CODE_SET_INTERFACE 11
#define USB_REQUEST_CODE_SYNCH_FRAME 12
// Descriptor Types (wValue)
#define USB_DESCRIPTOR_TYPE_DEVICE 1
#define USB_DESCRIPTOR_TYPE_CONFIGURATION 2
#define USB_DESCRIPTOR_TYPE_STRING 3
#define USB_DESCRIPTOR_TYPE_INTERFACE 4
#define USB_DESCRIPTOR_TYPE_ENDPOINT 5
#define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 6
#define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 7
#define USB_DESCRIPTOR_TYPE_INTERFACE_POWER 8
// Feature Selector (wvalue)
#define USB_FEATURE_SELECTOR_DEVICE_REMOTE_WAKEUP 1
#define USB_FEATURE_SELECTOR_ENDPOINT_HALT 0
#define USB_FEATURE_SELECTOR_TEST_MODE 2
// Device class code https://developerhelp.microchip.com/xwiki/bin/view/applications/usb/how-it-works/device-classes/
#define USB_DEVICE_CLASS_DEVICE 0x00
#define USB_DEVICE_CLASS_AUDIO 0x01
#define USB_DEVICE_CLASS_CDC 0x02
#define USB_DEVICE_CLASS_HID 0x03
#define USB_DEVICE_CLASS_PHYSICAL 0x05
#define USB_TRANSFERT_TYPE_CONTROL 0b00
#define USB_TRANSFERT_TYPE_ISOCHRONOUS 0b01
#define USB_TRANSFERT_TYPE_BULK 0b10
#define USB_TRANSFERT_TYPE_INTERRUPT 0b11
#define USB_DIRECTION_OUT 0x00
#define USB_DIRECTION_IN 0x80
// Supported languages http://www.baiheee.com/Documents/090518/090518112619/USB_LANGIDs.pdf
#define USB_LANG_ENGLISH_US 0x0409
#define USB_LANG_ENGLISH_UNITED_KINGDOM 0x0809
#define B_ENDPOINT_ADDRESS(NUM, DIR) ((NUM)&0xF | (DIR))
#define BM_REQUEST_TYPE_DIR_BIT (USB_DIRECTION_IN)
#define USB_INTERFACE_CLASS_COMMUNICATION 0x02 // Communication interface class
#define USB_INTERFACE_CLASS_DATA 0x0a // Data interface class
#define USB_INTERFACE_SUBCLASS_ACM 0x02 // Abstract Control Mode
#define USB_INTERFACE_COMMUNICATION_PROTOCOL_NOPROTO 0x00 // No protocol
USB_DATA { // P250
u8 bmRequestType;
u8 bRequest;
u16 wValue;
u16 wIndex;
u16 wLength;
} UD_SETUP;
// ----- Descriptors -----
USB_DATA { // P262
u8 bLength;
u8 bDescriptorType;
u16 bcdUSB;
u8 bDeviceClass;
u8 bDeviceSubClass;
u8 bDeviceProtocol;
u8 bMaxPacketSize0;
u16 idVendor;
u16 idProduct;
u16 bcdDevice;
u8 iManufacturer;
u8 iProduct;
u8 iSerialNumber;
u8 bNumConfigurations;
} USB_DEVICE_DESCRIPTOR;
USB_DATA { // P264 (may not be used in this code)
u8 bLength;
u8 bDescriptorType;
u16 bcdUSB;
u8 bDeviceClass;
u8 bDeviceSubClass;
u8 bDeviceProtocol;
u8 bMaxPacketSize0;
u8 bNumConfigurations;
u8 bReserved;
} USB_DEVICE_QUALIFIER_DESCRIPTOR;
USB_DATA { // P265
u8 bLength;
u8 bDescriptorType;
u16 wTotalLength;
u8 bNumInterfaces;
u8 bConfigurationValue;
u8 iConfiguration;
u8 bmAttributes;
u8 bMaxPower;
} USB_CONFIGURATION_DESCRIPTOR;
USB_DATA {
u8 bLength;
u8 bDescriptorType;
u16 wTotalLength;
u8 bNumInterfaces;
u8 bConfigurationValue;
u8 iConfiguration;
u8 bmAttributes;
u8 bMaxPower;
} USB_OTHER_SPEED_CONFIGURATION_DESCRIPTOR;
USB_DATA {
u8 bLength;
u8 bDescriptorType;
u8 bInterfaceNumber;
u8 bAlternateSetting;
u8 bNumEndpoints;
u8 bInterfaceClass;
u8 bInterfaceSubClass;
u8 bInterfaceProtocol;
u8 iInterface;
} USB_INTERFACE_DESCRIPTOR;
USB_DATA {
u8 bLength;
u8 bDescriptorType;
u8 bEndpointAddress;
u8 bmAttributes;
u16 wMaxPacketSize;
u8 bInterval;
} USB_ENDPOINT_DESCRIPTOR;
USB_DATA {
u8 bLength;
u8 bDescriptorType;
u16 wLANGID0;
// Can be more wLANGIDX but stop here!
} USB_STRING_DESCRIPTOR_ZERO;
USB_DATA {
u8 bLength;
u8 bDescriptorType;
// You add your unicode string there
} USB_UNICODE_STRING_DESCRIPTOR;
// ----- CDC Device Class -----
// p10 PSTN120.pdf in CDC Specification
// p10-.. CDC120-20101103-track.pdf
// p10-.. usbcdc11.pdf
#define USB_INTERFACE_CLASS_COMMUNICATION 0x02 // Communication interface class
#define USB_INTERFACE_CLASS_DATA 0x0a // Data interface class
#define USB_INTERFACE_SUBCLASS_ACM 0x02 // Abstract Control Mode
#define USB_INTERFACE_COMMUNICATION_PROTOCOL_NOPROTO 0x00 // No protocol
#define USB_RS232_BMCAPABILITIES 0b10
#define USB_REQUEST_CODE_SET_LINE_CODING 0x20
#define USB_REQUEST_CODE_SET_CONTROL_LINE_STATE 0x22
#define USB_REQUEST_CODE_SEND_BREAK 0x23
// p34
USB_DATA {
u8 bFunctionLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u16 bcdCDC;
} USB_CDC_HEADER_FUNCTIONAL_DESCRIPTOR;
// p35
USB_DATA {
u8 bFunctionLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bmCapabilities;
} USB_ACM_FUNCTIONAL_DESCRIPTOR;
// p40
USB_DATA {
u8 bFunctionLength;
u8 bDescriptorType;
u8 bDescriptorSubtype;
u8 bMasterInterface;
u8 bSlaveInterface0;
// Can be more! I guess for RS-232 it is enough
} USB_UNION_INTERFACE_DESCRIPTOR;
// SEE p49!!!! it is all there it seems
// the last descriptor on that page is the "Call management functional
// descriptor" (p34). It seems not required according to chatgpt for rs-232
USB_DATA {
USB_CDC_HEADER_FUNCTIONAL_DESCRIPTOR header_descriptor;
USB_ACM_FUNCTIONAL_DESCRIPTOR acm_descriptor;
USB_UNION_INTERFACE_DESCRIPTOR union_descriptor;
} USB_CDC_ACM_FUNCTIONAL_DESCRIPTOR;
#endif
|