|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32\include\usb.h |
|
15 // Definitions of USB-specific constants and macros. |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file usb.h |
|
21 @publishedPartner |
|
22 @released |
|
23 */ |
|
24 |
|
25 #ifndef __USB_H__ |
|
26 #define __USB_H__ |
|
27 |
|
28 // |
|
29 // 'Chapter 9' Request Types (bmRequestType) |
|
30 // |
|
31 const TUint8 KUsbRequestType_DirShift = 7; |
|
32 const TUint8 KUsbRequestType_DirMask = (1 << KUsbRequestType_DirShift); |
|
33 |
|
34 const TUint8 KUsbRequestType_DirToDev = (0 << KUsbRequestType_DirShift); |
|
35 const TUint8 KUsbRequestType_DirToHost = (1 << KUsbRequestType_DirShift); |
|
36 |
|
37 const TUint8 KUsbRequestType_TypeShift = 5; |
|
38 const TUint8 KUsbRequestType_TypeMask = (3 << KUsbRequestType_TypeShift); |
|
39 const TUint8 KUsbRequestType_TypeStd = (0 << KUsbRequestType_TypeShift); |
|
40 const TUint8 KUsbRequestType_TypeClass = (1 << KUsbRequestType_TypeShift); |
|
41 const TUint8 KUsbRequestType_TypeVendor = (2 << KUsbRequestType_TypeShift); |
|
42 |
|
43 const TUint8 KUsbRequestType_DestShift = 0; |
|
44 const TUint8 KUsbRequestType_DestMask = (0x1f << KUsbRequestType_DestShift); |
|
45 const TUint8 KUsbRequestType_DestDevice = (0x00 << KUsbRequestType_DestShift); |
|
46 const TUint8 KUsbRequestType_DestIfc = (0x01 << KUsbRequestType_DestShift); |
|
47 const TUint8 KUsbRequestType_DestEp = (0x02 << KUsbRequestType_DestShift); |
|
48 const TUint8 KUsbRequestType_DestOther = (0x03 << KUsbRequestType_DestShift); |
|
49 |
|
50 // |
|
51 // 'Chapter 9' Endpoint Zero Requests (bRequest) |
|
52 // |
|
53 const TUint8 KUsbRequest_GetStatus = 0; |
|
54 const TUint8 KUsbRequest_ClearFeature = 1; |
|
55 const TUint8 KUsbRequest_SetFeature = 3; |
|
56 const TUint8 KUsbRequest_SetAddress = 5; |
|
57 const TUint8 KUsbRequest_GetDescriptor = 6; |
|
58 const TUint8 KUsbRequest_SetDescriptor = 7; |
|
59 const TUint8 KUsbRequest_GetConfig = 8; |
|
60 const TUint8 KUsbRequest_SetConfig = 9; |
|
61 const TUint8 KUsbRequest_GetInterface = 10; |
|
62 const TUint8 KUsbRequest_SetInterface = 11; |
|
63 const TUint8 KUsbRequest_SynchFrame = 12; |
|
64 |
|
65 // |
|
66 // Descriptor Types |
|
67 // |
|
68 const TUint8 KUsbDescType_Device = 1; |
|
69 const TUint8 KUsbDescType_Config = 2; |
|
70 const TUint8 KUsbDescType_String = 3; |
|
71 const TUint8 KUsbDescType_Interface = 4; |
|
72 const TUint8 KUsbDescType_Endpoint = 5; |
|
73 const TUint8 KUsbDescType_DeviceQualifier = 6; |
|
74 const TUint8 KUsbDescType_OtherSpeedConfig = 7; |
|
75 const TUint8 KUsbDescType_InterfacePower = 8; |
|
76 const TUint8 KUsbDescType_Otg = 9; |
|
77 const TUint8 KUsbDescType_Debug = 10; |
|
78 const TUint8 KUsbDescType_InterfaceAssociation = 11; |
|
79 |
|
80 // |
|
81 // Descriptor Sizes |
|
82 // |
|
83 const TUint KUsbDescSize_Device = 18; |
|
84 const TUint KUsbDescSize_Config = 9; |
|
85 const TUint KUsbDescSize_Interface = 9; |
|
86 const TUint KUsbDescSize_Endpoint = 7; |
|
87 const TUint KUsbDescSize_Otg = 3; |
|
88 const TUint KUsbDescSize_DeviceQualifier = 10; |
|
89 const TUint KUsbDescSize_OtherSpeedConfig = 9; |
|
90 const TUint KUsbDescSize_InterfaceAssociation = 8; |
|
91 const TUint KUsbDescMaxSize_String = 255; |
|
92 const TUint KUsbStringDescStringMaxSize = 252; // it's actually 253, but that's awkward |
|
93 |
|
94 // |
|
95 // Configuration Characteristics (Configuration Descriptor) |
|
96 // |
|
97 const TUint8 KUsbDevAttr_SelfPowered = (0x01 << 6); |
|
98 const TUint8 KUsbDevAttr_RemoteWakeup = (0x01 << 5); |
|
99 |
|
100 // |
|
101 // Descriptor Indices for String Descriptors |
|
102 // |
|
103 const TUint KUsbDescStringIndex_Manufact = 14; |
|
104 const TUint KUsbDescStringIndex_Product = 15; |
|
105 const TUint KUsbDescStringIndex_Serial = 16; |
|
106 const TUint KUsbDescStringIndex_Config = 6; |
|
107 |
|
108 // |
|
109 // Endpoint Attributes |
|
110 // |
|
111 const TUint8 KUsbEpAttr_TransferTypeShift = 0; |
|
112 const TUint8 KUsbEpAttr_TransferTypeMask = (0x03 << KUsbEpAttr_TransferTypeShift); |
|
113 const TUint8 KUsbEpAttr_TransferTypeControl = (0x00 << KUsbEpAttr_TransferTypeShift); |
|
114 const TUint8 KUsbEpAttr_TransferTypeIsochronous = (0x01 << KUsbEpAttr_TransferTypeShift); |
|
115 const TUint8 KUsbEpAttr_TransferTypeBulk = (0x02 << KUsbEpAttr_TransferTypeShift); |
|
116 const TUint8 KUsbEpAttr_TransferTypeInterrupt = (0x03 << KUsbEpAttr_TransferTypeShift); |
|
117 |
|
118 const TUint8 KUsbEpAttr_SyncTypeShift = 2; |
|
119 const TUint8 KUsbEpAttr_SyncTypeMask = (0x03 << KUsbEpAttr_SyncTypeShift); |
|
120 const TUint8 KUsbEpAttr_SyncTypeNoSync = (0x00 << KUsbEpAttr_SyncTypeShift); |
|
121 const TUint8 KUsbEpAttr_SyncTypeAsync = (0x01 << KUsbEpAttr_SyncTypeShift); |
|
122 const TUint8 KUsbEpAttr_SyncTypeAdaptive = (0x02 << KUsbEpAttr_SyncTypeShift); |
|
123 const TUint8 KUsbEpAttr_SyncTypeSync = (0x03 << KUsbEpAttr_SyncTypeShift); |
|
124 |
|
125 const TUint8 KUsbEpAttr_UsageTypeShift = 4; |
|
126 const TUint8 KUsbEpAttr_UsageTypeMask = (0x03 << KUsbEpAttr_UsageTypeShift); |
|
127 const TUint8 KUsbEpAttr_UsageTypeDataEp = (0x00 << KUsbEpAttr_UsageTypeShift); |
|
128 const TUint8 KUsbEpAttr_UsageTypeFeedbackEp = (0x01 << KUsbEpAttr_UsageTypeShift); |
|
129 const TUint8 KUsbEpAttr_UsageTypeImplFbDataEp = (0x02 << KUsbEpAttr_UsageTypeShift); |
|
130 const TUint8 KUsbEpAttr_UsageTypeReserved = (0x03 << KUsbEpAttr_UsageTypeShift); |
|
131 |
|
132 // |
|
133 // OTG Feature Indicators |
|
134 // |
|
135 const TUint8 KUsbOtgAttr_SrpSupp = 0x01; |
|
136 const TUint8 KUsbOtgAttr_HnpSupp = 0x02; |
|
137 const TUint8 KUsbOtgAttr_B_HnpEnable = 0x04; |
|
138 const TUint8 KUsbOtgAttr_A_HnpSupport = 0x08; |
|
139 const TUint8 KUsbOtgAttr_A_AltHnpSupport = 0x10; |
|
140 |
|
141 // |
|
142 // Feature Settings |
|
143 // |
|
144 const TUint KUsbFeature_EndpointHalt = 0; |
|
145 const TUint KUsbFeature_RemoteWakeup = 1; |
|
146 const TUint KUsbFeature_TestMode = 2; |
|
147 const TUint KUsbFeature_B_HnpEnable = 3; |
|
148 const TUint KUsbFeature_A_HnpSupport = 4; |
|
149 const TUint KUsbFeature_A_AltHnpSupport = 5; |
|
150 |
|
151 // |
|
152 // Test Mode Selectors (Set/ClearFeature) |
|
153 // |
|
154 const TUint KUsbTestSelector_Test_J = 0x01; |
|
155 const TUint KUsbTestSelector_Test_K = 0x02; |
|
156 const TUint KUsbTestSelector_Test_SE0_NAK = 0x03; |
|
157 const TUint KUsbTestSelector_Test_Packet = 0x04; |
|
158 const TUint KUsbTestSelector_Test_Force_Enable = 0x05; |
|
159 |
|
160 // |
|
161 // Address Masks |
|
162 // |
|
163 const TUint8 KUsbEpAddress_In = 0x80; |
|
164 const TUint8 KUsbEpAddress_Portmask = 0x0f; |
|
165 |
|
166 // |
|
167 // Device Status Values (GET_STATUS) |
|
168 // |
|
169 const TUint16 KUsbDevStat_SelfPowered = (1 << 0); |
|
170 const TUint16 KUsbDevStat_RemoteWakeup = (1 << 1); |
|
171 |
|
172 // |
|
173 // Endpoint Status Values (GET_STATUS) |
|
174 // |
|
175 const TUint16 KUsbEpStat_Halt = (1 << 0); |
|
176 |
|
177 |
|
178 // |
|
179 // USB Descriptor Handling |
|
180 // |
|
181 /*------------------------------------------------ |
|
182 USB transfers data in little-endian fashion. |
|
183 The following macros swap the byte order in |
|
184 words (16 bit) and longwords (32 bit), such that |
|
185 they are in little-endian order afterwards. |
|
186 ------------------------------------------------*/ |
|
187 #if defined(__BIG_ENDIAN__) // Hitachi SuperH, Motorola 68k |
|
188 #define SWAP_BYTES_16(x) \ |
|
189 ((((x) >> 8) & 0x00ff) | \ |
|
190 (((x) << 8) & 0xff00)) |
|
191 #define SWAP_BYTES_32(x) \ |
|
192 ((((x) >> 24) & 0x000000ff) | \ |
|
193 (((x) >> 8) & 0x0000ff00) | \ |
|
194 (((x) << 24) & 0xff000000) | \ |
|
195 (((x) << 8) & 0x00ff0000)) |
|
196 #else // ARM, Intel |
|
197 #define SWAP_BYTES_16(x) (x) |
|
198 #define SWAP_BYTES_32(x) (x) |
|
199 #endif // defined(__BIG_ENDIAN__) |
|
200 |
|
201 |
|
202 static inline TUint8 LowByte(TUint16 aWord) |
|
203 { |
|
204 return static_cast<TUint8>(aWord & 0x00ff); |
|
205 } |
|
206 |
|
207 static inline TUint8 HighByte(TUint16 aWord) |
|
208 { |
|
209 return static_cast<TUint8>((aWord >> 8) & 0x00ff); |
|
210 } |
|
211 |
|
212 |
|
213 // |
|
214 // Class-specific Values |
|
215 // |
|
216 |
|
217 // These are from the CDC (valid also for Audio Class) |
|
218 const TUint8 KUsbDescType_CS_Interface = 0x24; |
|
219 const TUint8 KUsbDescType_CS_Endpoint = 0x25; |
|
220 |
|
221 // Audio Device Class |
|
222 const TUint KUsbDescSize_AudioEndpoint = KUsbDescSize_Endpoint + 2; |
|
223 const TUint KUsbAudioInterfaceClassCode = 0x01; |
|
224 const TUint KUsbAudioInterfaceSubclassCode_Subclass_Undefined = 0x00; |
|
225 const TUint KUsbAudioInterfaceSubclassCode_Audiocontrol = 0x01; |
|
226 const TUint KUsbAudioInterfaceSubclassCode_Audiostreaming = 0x02; |
|
227 const TUint KUsbAudioInterfaceSubclassCode_Midistreaming = 0x03; |
|
228 const TUint KUsbAudioInterfaceProtocolCode_Pr_Protocol_Undefined = 0x00; |
|
229 |
|
230 |
|
231 // |
|
232 // These are defined just for convenience: |
|
233 // |
|
234 const TUint8 KEp0_Out = 0; |
|
235 const TUint8 KEp0_In = 1; |
|
236 const TUint8 KEp0_Rx = KEp0_Out; |
|
237 const TUint8 KEp0_Tx = KEp0_In; |
|
238 |
|
239 |
|
240 // |
|
241 // USB Implementers Forum, Inc (USB-IF) assigned Vendor IDs: |
|
242 // |
|
243 const TUint16 KUsbVendorId_Symbian = 0x0E22; // Symbian Ltd. (dec. 3618) |
|
244 |
|
245 |
|
246 #endif // __USB_H__ |