libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
usbstd.h
Go to the documentation of this file.
1/** @defgroup usb_type_defines USB Standard Structure Definitions
2
3@brief <b>Defined Constants and Types for the USB Standard Structure
4Definitions</b>
5
6@ingroup USB_defines
7
8@version 1.0.0
9
10@author @htmlonly &copy; @endhtmlonly 2010
11Gareth McMullin <gareth@blacksphere.co.nz>
12
13@date 10 March 2013
14
15A set of structure definitions for the USB control structures
16defined in chapter 9 of the "Universal Serial Bus Specification Revision 2.0"
17Available from the USB Implementers Forum - http://www.usb.org/
18
19LGPL License Terms @ref lgpl_license
20*/
21
22/*
23 * This file is part of the libopencm3 project.
24 *
25 * Copyright (C) 2010 Gareth McMullin <gareth@blacksphere.co.nz>
26 *
27 * This library is free software: you can redistribute it and/or modify
28 * it under the terms of the GNU Lesser General Public License as published by
29 * the Free Software Foundation, either version 3 of the License, or
30 * (at your option) any later version.
31 *
32 * This library is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU Lesser General Public License for more details.
36 *
37 * You should have received a copy of the GNU Lesser General Public License
38 * along with this library. If not, see <http://www.gnu.org/licenses/>.
39 */
40
41/**@{*/
42
43#ifndef __USBSTD_H
44#define __USBSTD_H
45
46#include <stdint.h>
48
49/*
50 * This file contains structure definitions for the USB control structures
51 * defined in chapter 9 of the "Universal Serial Bus Specification Revision 2.0"
52 * Available from the USB Implementers Forum - http://www.usb.org/
53 */
54
55/* USB Setup Data structure - Table 9-2 */
58 uint8_t bRequest;
59 uint16_t wValue;
60 uint16_t wIndex;
61 uint16_t wLength;
62} __attribute__((packed));
63
64/* Class Definition */
65#define USB_CLASS_VENDOR 0xFF
66
67/* bmRequestType bit definitions */
68/* bit 7 : direction */
69#define USB_REQ_TYPE_DIRECTION 0x80
70#define USB_REQ_TYPE_IN 0x80
71#define USB_REQ_TYPE_OUT 0x0
72/* bits 6..5 : type */
73#define USB_REQ_TYPE_TYPE 0x60
74#define USB_REQ_TYPE_STANDARD 0x00
75#define USB_REQ_TYPE_CLASS 0x20
76#define USB_REQ_TYPE_VENDOR 0x40
77/* bits 4..0 : recipient */
78#define USB_REQ_TYPE_RECIPIENT 0x1F
79#define USB_REQ_TYPE_DEVICE 0x00
80#define USB_REQ_TYPE_INTERFACE 0x01
81#define USB_REQ_TYPE_ENDPOINT 0x02
82#define USB_REQ_TYPE_OTHER 0x03
83
84/* USB Standard Request Codes - Table 9-4 */
85#define USB_REQ_GET_STATUS 0
86#define USB_REQ_CLEAR_FEATURE 1
87/* Reserved for future use: 2 */
88#define USB_REQ_SET_FEATURE 3
89/* Reserved for future use: 3 */
90#define USB_REQ_SET_ADDRESS 5
91#define USB_REQ_GET_DESCRIPTOR 6
92#define USB_REQ_SET_DESCRIPTOR 7
93#define USB_REQ_GET_CONFIGURATION 8
94#define USB_REQ_SET_CONFIGURATION 9
95#define USB_REQ_GET_INTERFACE 10
96#define USB_REQ_SET_INTERFACE 11
97#define USB_REQ_SET_SYNCH_FRAME 12
98
99/* USB Descriptor Types - Table 9-5 */
100#define USB_DT_DEVICE 1
101#define USB_DT_CONFIGURATION 2
102#define USB_DT_STRING 3
103#define USB_DT_INTERFACE 4
104#define USB_DT_ENDPOINT 5
105#define USB_DT_DEVICE_QUALIFIER 6
106#define USB_DT_OTHER_SPEED_CONFIGURATION 7
107#define USB_DT_INTERFACE_POWER 8
108/* From ECNs */
109#define USB_DT_OTG 9
110#define USB_DT_DEBUG 10
111#define USB_DT_INTERFACE_ASSOCIATION 11
112
113/* USB Standard Feature Selectors - Table 9-6 */
114#define USB_FEAT_ENDPOINT_HALT 0
115#define USB_FEAT_DEVICE_REMOTE_WAKEUP 1
116#define USB_FEAT_TEST_MODE 2
117
118/* Information Returned by a GetStatus() Request to a Device - Figure 9-4 */
119#define USB_DEV_STATUS_SELF_POWERED 0x01
120#define USB_DEV_STATUS_REMOTE_WAKEUP 0x02
121
122/* USB Standard Device Descriptor - Table 9-8 */
124 uint8_t bLength;
126 uint16_t bcdUSB;
131 uint16_t idVendor;
132 uint16_t idProduct;
133 uint16_t bcdDevice;
135 uint8_t iProduct;
138} __attribute__((packed));
139
140#define USB_DT_DEVICE_SIZE sizeof(struct usb_device_descriptor)
141
142/* USB Device_Qualifier Descriptor - Table 9-9
143 * Not used in this implementation.
144 */
146 uint8_t bLength;
148 uint16_t bcdUSB;
154 uint8_t bReserved;
155} __attribute__((packed));
156
157/* This is only defined as a top level named struct to improve c++
158 * compatibility. You should never need to instance this struct
159 * in user code! */
165};
166
167/* USB Standard Configuration Descriptor - Table 9-10 */
169 uint8_t bLength;
171 uint16_t wTotalLength;
176 uint8_t bMaxPower;
177
178 /* Descriptor ends here. The following are used internally: */
180} __attribute__((packed));
181#define USB_DT_CONFIGURATION_SIZE 9
182
183/* USB Configuration Descriptor bmAttributes bit definitions */
184#define USB_CONFIG_ATTR_DEFAULT 0x80 /** always required (USB2.0 table 9-10) */
185#define USB_CONFIG_ATTR_SELF_POWERED 0x40
186#define USB_CONFIG_ATTR_REMOTE_WAKEUP 0x20
187
188/* Other Speed Configuration is the same as Configuration Descriptor.
189 * - Table 9-11
190 */
191
192/* USB Standard Interface Descriptor - Table 9-12 */
194 uint8_t bLength;
202 uint8_t iInterface;
203
204 /* Descriptor ends here. The following are used internally: */
206 const void *extra;
208} __attribute__((packed));
209#define USB_DT_INTERFACE_SIZE 9
210
211/* USB Standard Endpoint Descriptor - Table 9-13 */
213 uint8_t bLength;
218 uint8_t bInterval;
219
220 /* Descriptor ends here. The following are used internally: */
221 const void *extra;
223} __attribute__((packed));
224#define USB_DT_ENDPOINT_SIZE 7
225
226/* USB bEndpointAddress helper macros */
227#define USB_ENDPOINT_ADDR_OUT(x) (x)
228#define USB_ENDPOINT_ADDR_IN(x) (0x80 | (x))
229
230/* USB Endpoint Descriptor bmAttributes bit definitions - Table 9-13 */
231/* bits 1..0 : transfer type */
232#define USB_ENDPOINT_ATTR_CONTROL 0x00
233#define USB_ENDPOINT_ATTR_ISOCHRONOUS 0x01
234#define USB_ENDPOINT_ATTR_BULK 0x02
235#define USB_ENDPOINT_ATTR_INTERRUPT 0x03
236#define USB_ENDPOINT_ATTR_TYPE 0x03
237/* bits 3..2 : Sync type (only if ISOCHRONOUS) */
238#define USB_ENDPOINT_ATTR_NOSYNC 0x00
239#define USB_ENDPOINT_ATTR_ASYNC 0x04
240#define USB_ENDPOINT_ATTR_ADAPTIVE 0x08
241#define USB_ENDPOINT_ATTR_SYNC 0x0C
242#define USB_ENDPOINT_ATTR_SYNCTYPE 0x0C
243/* bits 5..4 : usage type (only if ISOCHRONOUS) */
244#define USB_ENDPOINT_ATTR_DATA 0x00
245#define USB_ENDPOINT_ATTR_FEEDBACK 0x10
246#define USB_ENDPOINT_ATTR_IMPLICIT_FEEDBACK_DATA 0x20
247#define USB_ENDPOINT_ATTR_USAGETYPE 0x30
248
249/* Table 9-15 specifies String Descriptor Zero.
250 * Table 9-16 specified UNICODE String Descriptor.
251 */
253 uint8_t bLength;
255 uint16_t wData[];
256} __attribute__((packed));
257
258/* From ECN: Interface Association Descriptors, Table 9-Z */
260 uint8_t bLength;
267 uint8_t iFunction;
268} __attribute__((packed));
269#define USB_DT_INTERFACE_ASSOCIATION_SIZE \
270 sizeof(struct usb_iface_assoc_descriptor)
271
274};
275#endif
276
277/**@}*/
278
usb_language_id
Definition: usbstd.h:272
@ USB_LANGID_ENGLISH_US
Definition: usbstd.h:273
uint16_t wTotalLength
Definition: usbstd.h:171
uint8_t bDescriptorType
Definition: usbstd.h:170
uint8_t bNumInterfaces
Definition: usbstd.h:172
uint8_t bmAttributes
Definition: usbstd.h:175
const struct usb_interface * interface
Definition: usbstd.h:179
uint8_t iConfiguration
Definition: usbstd.h:174
uint8_t bConfigurationValue
Definition: usbstd.h:173
uint16_t idVendor
Definition: usbstd.h:131
uint8_t iSerialNumber
Definition: usbstd.h:136
uint16_t bcdDevice
Definition: usbstd.h:133
uint8_t bDeviceProtocol
Definition: usbstd.h:129
uint8_t bNumConfigurations
Definition: usbstd.h:137
uint16_t idProduct
Definition: usbstd.h:132
uint8_t bDeviceClass
Definition: usbstd.h:127
uint8_t bMaxPacketSize0
Definition: usbstd.h:130
uint8_t iManufacturer
Definition: usbstd.h:134
uint8_t bDescriptorType
Definition: usbstd.h:125
uint8_t bDeviceSubClass
Definition: usbstd.h:128
uint16_t wMaxPacketSize
Definition: usbstd.h:217
const void * extra
Definition: usbstd.h:221
uint8_t bEndpointAddress
Definition: usbstd.h:215
uint8_t bDescriptorType
Definition: usbstd.h:214
uint8_t bInterfaceProtocol
Definition: usbstd.h:201
const struct usb_endpoint_descriptor * endpoint
Definition: usbstd.h:205
uint8_t bAlternateSetting
Definition: usbstd.h:197
uint8_t bInterfaceSubClass
Definition: usbstd.h:200
const void * extra
Definition: usbstd.h:206
uint8_t bInterfaceNumber
Definition: usbstd.h:196
const struct usb_iface_assoc_descriptor * iface_assoc
Definition: usbstd.h:163
const struct usb_interface_descriptor * altsetting
Definition: usbstd.h:164
uint8_t num_altsetting
Definition: usbstd.h:162
uint8_t * cur_altsetting
Definition: usbstd.h:161
uint16_t wIndex
Definition: usbstd.h:60
uint8_t bRequest
Definition: usbstd.h:58
uint8_t bmRequestType
Definition: usbstd.h:57
uint16_t wValue
Definition: usbstd.h:59
uint16_t wLength
Definition: usbstd.h:61
uint8_t bDescriptorType
Definition: usbstd.h:254
uint16_t wData[]
Definition: usbstd.h:255