1 |
786 |
skrzyp |
#ifndef CYGONCE_USB_H
|
2 |
|
|
# define CYGONCE_USB_H
|
3 |
|
|
//==========================================================================
|
4 |
|
|
//
|
5 |
|
|
// include/usb.h
|
6 |
|
|
//
|
7 |
|
|
// Data common to USB host and USB slave
|
8 |
|
|
//
|
9 |
|
|
//==========================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//==========================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): bartv
|
45 |
|
|
// Contributors: bartv
|
46 |
|
|
// Date: 2000-10-04
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//==========================================================================
|
50 |
|
|
|
51 |
|
|
#ifdef __cplusplus
|
52 |
|
|
extern "C" {
|
53 |
|
|
#endif
|
54 |
|
|
|
55 |
|
|
// USB device requests, the setup packet.
|
56 |
|
|
//
|
57 |
|
|
// The structure is defined entirely in terms of bytes, eliminating
|
58 |
|
|
// any confusion about who is supposed to swap what when. This avoids
|
59 |
|
|
// endianness-related portability problems, and eliminates any need
|
60 |
|
|
// to worry about alignment. Also for some requests the value field
|
61 |
|
|
// is split into separate bytes anyway.
|
62 |
|
|
typedef struct usb_devreq {
|
63 |
|
|
unsigned char type;
|
64 |
|
|
unsigned char request;
|
65 |
|
|
unsigned char value_lo;
|
66 |
|
|
unsigned char value_hi;
|
67 |
|
|
unsigned char index_lo;
|
68 |
|
|
unsigned char index_hi;
|
69 |
|
|
unsigned char length_lo;
|
70 |
|
|
unsigned char length_hi;
|
71 |
|
|
} __attribute__((packed)) usb_devreq;
|
72 |
|
|
|
73 |
|
|
// Encoding of the request_type
|
74 |
|
|
#define USB_DEVREQ_DIRECTION_OUT 0
|
75 |
|
|
#define USB_DEVREQ_DIRECTION_IN (1 << 7)
|
76 |
|
|
#define USB_DEVREQ_DIRECTION_MASK (1 << 7)
|
77 |
|
|
|
78 |
|
|
#define USB_DEVREQ_TYPE_STANDARD 0
|
79 |
|
|
#define USB_DEVREQ_TYPE_CLASS (0x1 << 5)
|
80 |
|
|
#define USB_DEVREQ_TYPE_VENDOR (0x2 << 5)
|
81 |
|
|
#define USB_DEVREQ_TYPE_RESERVED (0x3 << 5)
|
82 |
|
|
#define USB_DEVREQ_TYPE_MASK (0x3 << 5)
|
83 |
|
|
|
84 |
|
|
#define USB_DEVREQ_RECIPIENT_DEVICE 0x00
|
85 |
|
|
#define USB_DEVREQ_RECIPIENT_INTERFACE 0x01
|
86 |
|
|
#define USB_DEVREQ_RECIPIENT_ENDPOINT 0x02
|
87 |
|
|
#define USB_DEVREQ_RECIPIENT_OTHER 0x03
|
88 |
|
|
#define USB_DEVREQ_RECIPIENT_MASK 0x1F
|
89 |
|
|
|
90 |
|
|
// The standard request codes.
|
91 |
|
|
#define USB_DEVREQ_GET_STATUS 0
|
92 |
|
|
#define USB_DEVREQ_CLEAR_FEATURE 1
|
93 |
|
|
#define USB_DEVREQ_SET_FEATURE 3
|
94 |
|
|
#define USB_DEVREQ_SET_ADDRESS 5
|
95 |
|
|
#define USB_DEVREQ_GET_DESCRIPTOR 6
|
96 |
|
|
#define USB_DEVREQ_SET_DESCRIPTOR 7
|
97 |
|
|
#define USB_DEVREQ_GET_CONFIGURATION 8
|
98 |
|
|
#define USB_DEVREQ_SET_CONFIGURATION 9
|
99 |
|
|
#define USB_DEVREQ_GET_INTERFACE 10
|
100 |
|
|
#define USB_DEVREQ_SET_INTERFACE 11
|
101 |
|
|
#define USB_DEVREQ_SYNCH_FRAME 12
|
102 |
|
|
|
103 |
|
|
// Descriptor types. These are placed in value_hi for the
|
104 |
|
|
// GET_DESCRIPTOR and SET_DESCRIPTOR requests, with an index
|
105 |
|
|
// in value_lo. They also go into the type fields of the
|
106 |
|
|
// various descriptor structures.
|
107 |
|
|
#define USB_DEVREQ_DESCRIPTOR_TYPE_DEVICE 1
|
108 |
|
|
#define USB_DEVREQ_DESCRIPTOR_TYPE_CONFIGURATION 2
|
109 |
|
|
#define USB_DEVREQ_DESCRIPTOR_TYPE_STRING 3
|
110 |
|
|
#define USB_DEVREQ_DESCRIPTOR_TYPE_INTERFACE 4
|
111 |
|
|
#define USB_DEVREQ_DESCRIPTOR_TYPE_ENDPOINT 5
|
112 |
|
|
|
113 |
|
|
// Feature selectors. These go into value_lo for the CLEAR_FEATURE and
|
114 |
|
|
// SET_FEATURE requests, and in the first response byte for
|
115 |
|
|
// GET_STATUS.
|
116 |
|
|
#define USB_DEVREQ_FEATURE_DEVICE_REMOTE_WAKEUP 1
|
117 |
|
|
#define USB_DEVREQ_FEATURE_ENDPOINT_HALT 0
|
118 |
|
|
|
119 |
|
|
// Index decoding. When the CLEAR_FEATURE, SET_FEATURE and GET_STATUS
|
120 |
|
|
// requests is applied to an endpoint (as per the recipient field in
|
121 |
|
|
// the type field) index_lo identifies the endpoint.
|
122 |
|
|
#define USB_DEVREQ_INDEX_DIRECTION_OUT 0
|
123 |
|
|
#define USB_DEVREQ_INDEX_DIRECTION_IN (1 << 7)
|
124 |
|
|
#define USB_DEVREQ_INDEX_DIRECTION_MASK (1 << 7)
|
125 |
|
|
#define USB_DEVREQ_INDEX_ENDPOINT_MASK 0x0F
|
126 |
|
|
|
127 |
|
|
// Descriptors for the GET_DESCRIPTOR and SET_DESCRIPTOR requests.
|
128 |
|
|
typedef struct usb_device_descriptor {
|
129 |
|
|
unsigned char length; // USB_DEVICE_DESCRIPTOR_LENGTH == 18
|
130 |
|
|
unsigned char type; // USB_DEVREQ_DESCRIPTOR_TYPE
|
131 |
|
|
unsigned char usb_spec_lo;
|
132 |
|
|
unsigned char usb_spec_hi;
|
133 |
|
|
unsigned char device_class;
|
134 |
|
|
unsigned char device_subclass;
|
135 |
|
|
unsigned char device_protocol;
|
136 |
|
|
unsigned char max_packet_size;
|
137 |
|
|
unsigned char vendor_lo;
|
138 |
|
|
unsigned char vendor_hi;
|
139 |
|
|
unsigned char product_lo;
|
140 |
|
|
unsigned char product_hi;
|
141 |
|
|
unsigned char device_lo;
|
142 |
|
|
unsigned char device_hi;
|
143 |
|
|
unsigned char manufacturer_str;
|
144 |
|
|
unsigned char product_str;
|
145 |
|
|
unsigned char serial_number_str;
|
146 |
|
|
unsigned char number_configurations;
|
147 |
|
|
} __attribute__((packed)) usb_device_descriptor;
|
148 |
|
|
|
149 |
|
|
#define USB_DEVICE_DESCRIPTOR_LENGTH 18
|
150 |
|
|
#define USB_DEVICE_DESCRIPTOR_TYPE USB_DEVREQ_DESCRIPTOR_TYPE_DEVICE
|
151 |
|
|
#define USB_DEVICE_DESCRIPTOR_USB11_LO 0x10
|
152 |
|
|
#define USB_DEVICE_DESCRIPTOR_USB11_HI 0x01
|
153 |
|
|
|
154 |
|
|
#define USB_DEVICE_DESCRIPTOR_CLASS_INTERFACE 0x00
|
155 |
|
|
#define USB_DEVICE_DESCRIPTOR_CLASS_VENDOR 0x00FF
|
156 |
|
|
#define USB_DEVICE_DESCRIPTOR_SUBCLASS_INTERFACE 0x00
|
157 |
|
|
#define USB_DEVICE_DESCRIPTOR_SUBCLASS_VENDOR 0x00FF
|
158 |
|
|
#define USB_DEVICE_DESCRIPTOR_PROTOCOL_INTERFACE 0x00
|
159 |
|
|
#define USB_DEVICE_DESCRIPTOR_PROTOCOL_VENDOR 0x00FF
|
160 |
|
|
|
161 |
|
|
typedef struct usb_configuration_descriptor {
|
162 |
|
|
unsigned char length;
|
163 |
|
|
unsigned char type;
|
164 |
|
|
unsigned char total_length_lo;
|
165 |
|
|
unsigned char total_length_hi;
|
166 |
|
|
unsigned char number_interfaces;
|
167 |
|
|
unsigned char configuration_id;
|
168 |
|
|
unsigned char configuration_str;
|
169 |
|
|
unsigned char attributes;
|
170 |
|
|
unsigned char max_power;
|
171 |
|
|
} __attribute__((packed)) usb_configuration_descriptor;
|
172 |
|
|
|
173 |
|
|
#define USB_CONFIGURATION_DESCRIPTOR_LENGTH 9
|
174 |
|
|
#define USB_CONFIGURATION_DESCRIPTOR_TYPE USB_DEVREQ_DESCRIPTOR_TYPE_CONFIGURATION
|
175 |
|
|
#define USB_CONFIGURATION_DESCRIPTOR_ATTR_REQUIRED (1 << 7)
|
176 |
|
|
#define USB_CONFIGURATION_DESCRIPTOR_ATTR_SELF_POWERED (1 << 6)
|
177 |
|
|
#define USB_CONFIGURATION_DESCRIPTOR_ATTR_REMOTE_WAKEUP (1 << 5)
|
178 |
|
|
|
179 |
|
|
typedef struct usb_interface_descriptor {
|
180 |
|
|
unsigned char length;
|
181 |
|
|
unsigned char type;
|
182 |
|
|
unsigned char interface_id;
|
183 |
|
|
unsigned char alternate_setting;
|
184 |
|
|
unsigned char number_endpoints;
|
185 |
|
|
unsigned char interface_class;
|
186 |
|
|
unsigned char interface_subclass;
|
187 |
|
|
unsigned char interface_protocol;
|
188 |
|
|
unsigned char interface_str;
|
189 |
|
|
} __attribute__((packed)) usb_interface_descriptor;
|
190 |
|
|
|
191 |
|
|
#define USB_INTERFACE_DESCRIPTOR_LENGTH 9
|
192 |
|
|
#define USB_INTERFACE_DESCRIPTOR_TYPE USB_DEVREQ_DESCRIPTOR_TYPE_INTERFACE
|
193 |
|
|
#define USB_INTERFACE_DESCRIPTOR_CLASS_VENDOR 0x00FF
|
194 |
|
|
#define USB_INTERFACE_DESCRIPTOR_SUBCLASS_VENDOR 0x00FF
|
195 |
|
|
#define USB_INTERFACE_DESCRIPTOR_PROTOCOL_VENDOR 0x00FF
|
196 |
|
|
|
197 |
|
|
typedef struct usb_endpoint_descriptor {
|
198 |
|
|
unsigned char length;
|
199 |
|
|
unsigned char type;
|
200 |
|
|
unsigned char endpoint;
|
201 |
|
|
unsigned char attributes;
|
202 |
|
|
unsigned char max_packet_lo;
|
203 |
|
|
unsigned char max_packet_hi;
|
204 |
|
|
unsigned char interval;
|
205 |
|
|
} __attribute__((packed)) usb_endpoint_descriptor;
|
206 |
|
|
|
207 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_LENGTH 7
|
208 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_TYPE USB_DEVREQ_DESCRIPTOR_TYPE_ENDPOINT
|
209 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_ENDPOINT_OUT 0
|
210 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_ENDPOINT_IN (1 << 7)
|
211 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_ATTR_CONTROL 0x00
|
212 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_ATTR_ISOCHRONOUS 0x01
|
213 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_ATTR_BULK 0x02
|
214 |
|
|
#define USB_ENDPOINT_DESCRIPTOR_ATTR_INTERRUPT 0x03
|
215 |
|
|
|
216 |
|
|
// String descriptors. If these are used at all then string 0
|
217 |
|
|
// must be a table of supported LANGID codes. For a simple device
|
218 |
|
|
// which only supports US English, the following sequence of
|
219 |
|
|
// four bytes should suffice for string 0. In practice string
|
220 |
|
|
// constants tend to be used which makes the use of these
|
221 |
|
|
// #define's difficult.
|
222 |
|
|
#define USB_STRING_DESCRIPTOR_STRING0_LENGTH 4
|
223 |
|
|
#define USB_STRING_DESCRIPTOR_STRING0_TYPE USB_DEVREQ_DESCRIPTOR_TYPE_STRING
|
224 |
|
|
#define USB_STRING_DESCRIPTOR_STRING0_LANGID_LO 0x09
|
225 |
|
|
#define USB_STRING_DESCRIPTOR_STRING0_LANGID_HI 0x04
|
226 |
|
|
|
227 |
|
|
// For subsequent strings the length and data will have to be
|
228 |
|
|
// determined by the application developer or by a suitable tool.
|
229 |
|
|
#define USB_STRING_DESCRIPTOR_TYPE USB_DEVREQ_DESCRIPTOR_TYPE_STRING
|
230 |
|
|
|
231 |
|
|
// Utility macros to calculate the total_length fields in a
|
232 |
|
|
// configuration descriptor.
|
233 |
|
|
#define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH_LO(interfaces, endpoints) \
|
234 |
|
|
(USB_CONFIGURATION_DESCRIPTOR_LENGTH + \
|
235 |
|
|
(interfaces * USB_INTERFACE_DESCRIPTOR_LENGTH) + \
|
236 |
|
|
(endpoints * USB_ENDPOINT_DESCRIPTOR_LENGTH)) % 256
|
237 |
|
|
|
238 |
|
|
#define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH_HI(interfaces, endpoints) \
|
239 |
|
|
(USB_CONFIGURATION_DESCRIPTOR_LENGTH + \
|
240 |
|
|
(interfaces * USB_INTERFACE_DESCRIPTOR_LENGTH) + \
|
241 |
|
|
(endpoints * USB_ENDPOINT_DESCRIPTOR_LENGTH)) / 256
|
242 |
|
|
|
243 |
|
|
#ifdef __cplusplus
|
244 |
|
|
} // extern "C" {
|
245 |
|
|
#endif
|
246 |
|
|
|
247 |
|
|
#endif // CYGONCE_USB_H
|
248 |
|
|
|