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