mikroSDK Reference Manual
usbd_desc.h
Go to the documentation of this file.
1
31#ifndef _USBD_DESC_H
32#define _USBD_DESC_H
33
34//Dependencies
35#include "os_port.h"
36
37//Endpoint identifiers
38#define USB_EP0 0
39#define USB_EP1 1
40#define USB_EP2 2
41#define USB_EP3 3
42
43//Data transfer direction
44#define USB_DIR_MASK 0x80
45#define USB_DIR_OUT 0x00
46#define USB_DIR_IN 0x80
47
48//Endpoint maximum packet size
49#define USB_EP0_MAX_PACKET_SIZE 64
50#define USB_EP1_MAX_PACKET_SIZE 64
51#define USB_EP2_MAX_PACKET_SIZE 64
52#define USB_EP3_MAX_PACKET_SIZE 64
53
54//bmAttributes field
55#define USB_SELF_POWERED 0xC0
56#define USB_BUS_POWERED 0x80
57#define USB_REMOTE_WAKEUP 0xA0
58#define USB_NO_REMOTE_WAKEUP 0x80
59
60//Endpoint types
61#define USB_ENDPOINT_TYPE_MASK 0x03
62#define USB_ENDPOINT_TYPE_CONTROL 0x00
63#define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
64#define USB_ENDPOINT_TYPE_BULK 0x02
65#define USB_ENDPOINT_TYPE_INTERRUPT 0x03
66
67//Device class
68#define USB_DEVICE_CLASS_CDC 0x02
69//Device subclass
70#define USB_DEVICE_SUBCLASS_CDC 0x00
71//Device protocol
72#define USB_DEVICE_PROTOCOL_CDC 0x00
73
74//CDC communication interface class
75#define CDC_INTERFACE_CLASS_COMMUNICATION 0x02
76#define CDC_INTERFACE_CLASS_RNDIS 0xEF
77//CDC communication interface subclass
78#define CDC_INTERFACE_SUBCLASS_ACM 0x02
79#define CDC_INTERFACE_SUBCLASS_RNDIS 0x04
80//CDC communication interface protocol
81#define CDC_INTERFACE_PROTOCOL_RNDIS 0x01
82#define CDC_INTERFACE_PROTOCOL_VENDOR_SPECIFIC 0xFF
83
84//CDC data interface class
85#define CDC_INTERFACE_CLASS_DATA 0x0A
86//CDC data interface subclass
87#define CDC_INTERFACE_SUBCLASS_DATA 0x00
88//CDC data interface protocol
89#define CDC_INTERFACE_PROTOCOL_DATA 0x00
90
91//CDC descriptor types
92#define CDC_CS_INTERFACE 0x24
93#define CDC_CS_ENDPOINT 0x25
94
95//CDC descriptor subtypes
96#define CDC_HEADER_DESC_SUBTYPE 0x00
97#define CDC_CALL_MANAGEMENT_DESC_SUBTYPE 0x01
98#define CDC_ACM_DESC_SUBTYPE 0x02
99#define CDC_UNION_DESC_SUBTYPE 0x06
100
101
107{
108 uint8_t bLength;
109 uint8_t bDescriptorType;
110 uint16_t bcdUsb;
111 uint8_t bDeviceClass;
112 uint8_t bDeviceSubClass;
113 uint8_t bDeviceProtocol;
114 uint8_t bMaxPacketSize0;
115 uint16_t idVendor;
116 uint16_t idProduct;
117 uint16_t bcdDevice;
118 uint8_t iManufacturer;
119 uint8_t iProduct;
120 uint8_t iSerialNumber;
121 uint8_t bNumConfigurations;
122} UsbDeviceDescriptor;
123
124
129typedef __packed_struct
130{
131 uint8_t bLength;
132 uint8_t bDescriptorType;
133 uint16_t wTotalLength;
134 uint8_t bNumInterfaces;
135 uint8_t bConfigurationValue;
136 uint8_t iConfiguration;
137 uint8_t bmAttributes;
138 uint8_t bMaxPower;
139} UsbConfigDescriptor;
140
141
146typedef __packed_struct
147{
148 uint8_t bLength;
149 uint8_t bDescriptorType;
150 uint8_t bInterfaceNumber;
151 uint8_t bAlternateSetting;
152 uint8_t bNumEndpoints;
153 uint8_t bInterfaceClass;
154 uint8_t bInterfaceSubClass;
155 uint8_t bInterfaceProtocol;
156 uint8_t iInterface;
157} UsbInterfaceDescriptor;
158
159
164typedef __packed_struct
165{
166 uint8_t bLength;
167 uint8_t bDescriptorType;
168 uint8_t bEndpointAddress;
169 uint8_t bmAttributes;
170 uint16_t wMaxPacketSize;
171 uint8_t bInterval;
172} UsbEndpointDescriptor;
173
174
179typedef __packed_struct
180{
181 uint8_t bLength;
182 uint8_t bDescriptorType;
183 uint16_t bString[];
184} UsbStringDescriptor;
185
186
191typedef __packed_struct
192{
193 uint8_t bFunctionLength;
194 uint8_t bDescriptorType;
195 uint8_t bDescriptorSubtype;
196 uint16_t bcdCdc;
197} CdcHeaderDescriptor;
198
199
204typedef __packed_struct
205{
206 uint8_t bFunctionLength;
207 uint8_t bDescriptorType;
208 uint8_t bDescriptorSubtype;
209 uint8_t bmCapabilities;
210 uint8_t bDataInterface;
211} CdcCallManagementDescriptor;
212
213
218typedef __packed_struct
219{
220 uint8_t bFunctionLength;
221 uint8_t bDescriptorType;
222 uint8_t bDescriptorSubtype;
223 uint8_t bmCapabilities;
224} CdcAcmDescriptor;
225
226
231typedef __packed_struct
232{
233 uint8_t bFunctionLength;
234 uint8_t bDescriptorType;
235 uint8_t bDescriptorSubtype;
236 uint8_t bMasterInterface;
237 uint8_t bSlaveInterface0;
238} CdcUnionDescriptor;
239
240
245typedef __packed_struct
246{
247 //Standard configuration descriptor
248 UsbConfigDescriptor configDescriptor;
249 //Communication class interface descriptor
250 UsbInterfaceDescriptor communicationInterfaceDescriptor;
251 //CDC header functional descriptor
252 CdcHeaderDescriptor cdcHeaderDescriptor;
253 //CDC call management functional descriptor
254 CdcCallManagementDescriptor cdcCallManagementDescriptor;
255 //CDC abstract control management functional descriptor
256 CdcAcmDescriptor cdcAcmDescriptor;
257 //CDC union functional descriptor
258 CdcUnionDescriptor cdcUnionDescriptor;
259 //Notification endpoint descriptor
260 UsbEndpointDescriptor notificationEndpointDescriptor;
261 //Data class interface descriptor
262 UsbInterfaceDescriptor dataInterfaceDescriptor;
263 //Data OUT endpoint descriptor
264 UsbEndpointDescriptor dataOutEndpointDescriptor;
265 //Data IN endpoint descriptor
266 UsbEndpointDescriptor dataInEndpointDescriptor;
267} UsbConfigDescriptors;
268
269
270//Global variables
271extern USBD_DescriptorsTypeDef usbdRndisDescriptors;
272extern const UsbDeviceDescriptor usbdDeviceDescriptor;
273extern const UsbConfigDescriptors usbdConfigDescriptors;
274
275//USB related functions
276uint8_t *usbdGetDeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
277uint8_t *usbdGetLangIdStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
278uint8_t *usbdGetManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
279uint8_t *usbdGetProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
280uint8_t *usbdGetSerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
281uint8_t *usbdGetConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
282uint8_t *usbdGetInterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
283
284#endif
RTOS abstraction layer.
typedef __packed_struct
Device descriptor.
Definition usbd_desc.h:107