sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#ifndef D32USBDI_H
|
sl@0
|
17 |
#define D32USBDI_H
|
sl@0
|
18 |
|
sl@0
|
19 |
#ifdef __KERNEL_MODE__
|
sl@0
|
20 |
#include <kernel/klib.h>
|
sl@0
|
21 |
#else
|
sl@0
|
22 |
#include <e32base.h>
|
sl@0
|
23 |
#include <d32usbdescriptors.h>
|
sl@0
|
24 |
#endif
|
sl@0
|
25 |
#include <e32ver.h>
|
sl@0
|
26 |
#include <d32usbdi_errors.h>
|
sl@0
|
27 |
|
sl@0
|
28 |
/**
|
sl@0
|
29 |
@file
|
sl@0
|
30 |
@publishedPartner
|
sl@0
|
31 |
@prototype
|
sl@0
|
32 |
Intended to be available to 3rd parties later
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
class RUsbPipe;
|
sl@0
|
37 |
class RUsbTransferDescriptor;
|
sl@0
|
38 |
class RUsbTransferStrategy;
|
sl@0
|
39 |
|
sl@0
|
40 |
typedef TUint32 TUsbBusId;
|
sl@0
|
41 |
typedef void* TUsbBus; // handle for an os_bus
|
sl@0
|
42 |
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
Functions which act on a specific interface on a remote device.
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
class RUsbInterface : public RBusLogicalChannel
|
sl@0
|
47 |
{
|
sl@0
|
48 |
public:
|
sl@0
|
49 |
NONSHARABLE_CLASS(TUsbTransferRequestDetails)
|
sl@0
|
50 |
{
|
sl@0
|
51 |
public:
|
sl@0
|
52 |
enum TEp0TransferFlags
|
sl@0
|
53 |
{
|
sl@0
|
54 |
EShortTransferOk = 0x04,
|
sl@0
|
55 |
};
|
sl@0
|
56 |
|
sl@0
|
57 |
public:
|
sl@0
|
58 |
TUint8 iRequestType;
|
sl@0
|
59 |
TUint8 iRequest;
|
sl@0
|
60 |
TUint16 iValue;
|
sl@0
|
61 |
TUint16 iIndex;
|
sl@0
|
62 |
TInt iFlags;
|
sl@0
|
63 |
|
sl@0
|
64 |
// Internal: these should not be set or used, however making them private
|
sl@0
|
65 |
// would require the internal DUsbChannel class be exposed as a friend in
|
sl@0
|
66 |
// userside
|
sl@0
|
67 |
const TDesC8* iSend;
|
sl@0
|
68 |
TDes8* iRecv;
|
sl@0
|
69 |
};
|
sl@0
|
70 |
|
sl@0
|
71 |
NONSHARABLE_CLASS(TChunkRequestDetails)
|
sl@0
|
72 |
{
|
sl@0
|
73 |
public:
|
sl@0
|
74 |
// In
|
sl@0
|
75 |
TInt iRequestSize;
|
sl@0
|
76 |
//Out
|
sl@0
|
77 |
TInt* iChunkHandle;
|
sl@0
|
78 |
TInt* iOffset;
|
sl@0
|
79 |
};
|
sl@0
|
80 |
|
sl@0
|
81 |
NONSHARABLE_CLASS(TTransferMemoryDetails)
|
sl@0
|
82 |
{
|
sl@0
|
83 |
public:
|
sl@0
|
84 |
TInt iType;
|
sl@0
|
85 |
TUint iAlignment;
|
sl@0
|
86 |
TInt iSize;
|
sl@0
|
87 |
TInt iMaxPackets;
|
sl@0
|
88 |
};
|
sl@0
|
89 |
|
sl@0
|
90 |
enum TDeviceSpeed
|
sl@0
|
91 |
{
|
sl@0
|
92 |
ELowSpeed,
|
sl@0
|
93 |
EFullSpeed,
|
sl@0
|
94 |
EHighSpeed
|
sl@0
|
95 |
};
|
sl@0
|
96 |
enum TUsbInterfaceRequest
|
sl@0
|
97 |
{
|
sl@0
|
98 |
ESuspend,
|
sl@0
|
99 |
EEp0Transfer,
|
sl@0
|
100 |
};
|
sl@0
|
101 |
enum TUsbInterfaceControl
|
sl@0
|
102 |
{
|
sl@0
|
103 |
EOpenPipe,
|
sl@0
|
104 |
EPermitRemoteWakeup,
|
sl@0
|
105 |
EGetInterfaceDescriptorSize,
|
sl@0
|
106 |
EGetInterfaceDescriptor,
|
sl@0
|
107 |
EGetStringDescriptor,
|
sl@0
|
108 |
ESelectAlternateInterface,
|
sl@0
|
109 |
EAllocChunk,
|
sl@0
|
110 |
EGetDeviceSpeed,
|
sl@0
|
111 |
EGetBusId,
|
sl@0
|
112 |
EHcdPageSize,
|
sl@0
|
113 |
EGetSizeAndAlignment,
|
sl@0
|
114 |
};
|
sl@0
|
115 |
enum TUsbInterfaceCancel
|
sl@0
|
116 |
{
|
sl@0
|
117 |
ECancelSuspend = 0x00000001,
|
sl@0
|
118 |
ECancelWaitForResume = 0x00000002,
|
sl@0
|
119 |
ECancelEp0Transfer = 0x00000004
|
sl@0
|
120 |
};
|
sl@0
|
121 |
|
sl@0
|
122 |
public:
|
sl@0
|
123 |
inline static const TDesC& Name();
|
sl@0
|
124 |
inline static TVersion VersionRequired();
|
sl@0
|
125 |
|
sl@0
|
126 |
#ifndef __KERNEL_MODE__
|
sl@0
|
127 |
friend class RUsbPipe;
|
sl@0
|
128 |
friend class RUsbZeroCopyTransferStrategy;
|
sl@0
|
129 |
|
sl@0
|
130 |
public:
|
sl@0
|
131 |
inline RUsbInterface();
|
sl@0
|
132 |
|
sl@0
|
133 |
//
|
sl@0
|
134 |
// Standard R-class lifetime controls
|
sl@0
|
135 |
//
|
sl@0
|
136 |
IMPORT_C TInt Open(TUint32 aToken, TOwnerType aType = EOwnerProcess);
|
sl@0
|
137 |
IMPORT_C void Close();
|
sl@0
|
138 |
|
sl@0
|
139 |
//
|
sl@0
|
140 |
// Transfer allocation/initialisation functions
|
sl@0
|
141 |
//
|
sl@0
|
142 |
IMPORT_C TInt RegisterTransferDescriptor(RUsbTransferDescriptor& aTransfer);
|
sl@0
|
143 |
IMPORT_C void ResetTransferDescriptors();
|
sl@0
|
144 |
IMPORT_C TInt InitialiseTransferDescriptors();
|
sl@0
|
145 |
|
sl@0
|
146 |
//
|
sl@0
|
147 |
// Endpoint Zero transfer utilities
|
sl@0
|
148 |
//
|
sl@0
|
149 |
inline void Ep0Transfer(TUsbTransferRequestDetails& aDetails, const TDesC8& aSend, TDes8& aRecv, TRequestStatus& aRequest);
|
sl@0
|
150 |
inline void CancelEP0Transfer();
|
sl@0
|
151 |
inline TInt GetStringDescriptor(TDes8& aStringDescriptor, TUint8 aIndex, TUint16 aLangId);
|
sl@0
|
152 |
|
sl@0
|
153 |
//
|
sl@0
|
154 |
// Suspend/Resume functionality
|
sl@0
|
155 |
//
|
sl@0
|
156 |
inline void PermitSuspendAndWaitForResume(TRequestStatus& aResumeSignal);
|
sl@0
|
157 |
inline void CancelPermitSuspend();
|
sl@0
|
158 |
inline void CancelWaitForResume();
|
sl@0
|
159 |
inline TInt PermitRemoteWakeup(TBool aPermitted);
|
sl@0
|
160 |
|
sl@0
|
161 |
|
sl@0
|
162 |
//
|
sl@0
|
163 |
// Descriptor access functions
|
sl@0
|
164 |
//
|
sl@0
|
165 |
inline TInt GetInterfaceDescriptor(TUsbInterfaceDescriptor& aDescriptor);
|
sl@0
|
166 |
inline TInt GetAlternateInterfaceDescriptor(TInt aAlternateInterface, TUsbInterfaceDescriptor& aDescriptor);
|
sl@0
|
167 |
inline TInt GetEndpointDescriptor(TInt aAlternateInterface, TInt aEndpoint, TUsbEndpointDescriptor& aDescriptor);
|
sl@0
|
168 |
|
sl@0
|
169 |
// Utility functions to avoid having to parse the entire descriptor tree in simple cases.
|
sl@0
|
170 |
inline TInt GetAlternateInterfaceCount();
|
sl@0
|
171 |
inline TInt EnumerateEndpointsOnInterface(TInt aAlternateInterface);
|
sl@0
|
172 |
|
sl@0
|
173 |
//
|
sl@0
|
174 |
// Interface configuration functions
|
sl@0
|
175 |
//
|
sl@0
|
176 |
inline TInt SelectAlternateInterface(TInt aAlternateInterface);
|
sl@0
|
177 |
inline TInt OpenPipeForEndpoint(RUsbPipe& aPipe, TInt aEndpoint, TBool aUseDMA);
|
sl@0
|
178 |
|
sl@0
|
179 |
//
|
sl@0
|
180 |
// Some utility functions
|
sl@0
|
181 |
//
|
sl@0
|
182 |
inline TInt GetBusId(TUsbBusId& aBusId);
|
sl@0
|
183 |
inline TInt HcdPageSize();
|
sl@0
|
184 |
inline TInt GetDeviceSpeed(TDeviceSpeed& aDeviceSpeed);
|
sl@0
|
185 |
|
sl@0
|
186 |
private:
|
sl@0
|
187 |
inline TInt AllocateSharedChunk(RChunk& aChunk, TInt aSize, TInt& aOffset);
|
sl@0
|
188 |
TInt RegisterTransferDescriptor(RUsbTransferDescriptor& aTransfer, TUsbBusId aBusId);
|
sl@0
|
189 |
inline TInt GetEndpointDescriptor(TInt aAlternateInterface, TInt aEndpoint, TUsbEndpointDescriptor*& aDescriptor);
|
sl@0
|
190 |
|
sl@0
|
191 |
private:
|
sl@0
|
192 |
TUsbInterfaceDescriptor* iHeadInterfaceDescriptor;
|
sl@0
|
193 |
HBufC8* iInterfaceDescriptorData;
|
sl@0
|
194 |
|
sl@0
|
195 |
RUsbTransferStrategy* iTransferStrategy;
|
sl@0
|
196 |
|
sl@0
|
197 |
TInt iAlternateSetting;
|
sl@0
|
198 |
#endif
|
sl@0
|
199 |
};
|
sl@0
|
200 |
|
sl@0
|
201 |
typedef TUint64 TUsbEndpointId;
|
sl@0
|
202 |
|
sl@0
|
203 |
/**
|
sl@0
|
204 |
Functions which act on an individual pipe established between the local host and a remote device.
|
sl@0
|
205 |
*/
|
sl@0
|
206 |
class RUsbPipe
|
sl@0
|
207 |
{
|
sl@0
|
208 |
public:
|
sl@0
|
209 |
enum TUsbPipeRequest
|
sl@0
|
210 |
{
|
sl@0
|
211 |
EIssueTransfer = 0x4000000, // Start from a different value compared to interfaces
|
sl@0
|
212 |
// to allow them to be distinguished while debugging
|
sl@0
|
213 |
};
|
sl@0
|
214 |
enum TUsbPipeControl
|
sl@0
|
215 |
{
|
sl@0
|
216 |
EClose = 0x4000000, // Start from a different value compared to interfaces
|
sl@0
|
217 |
// to allow them to be distinguished while debugging
|
sl@0
|
218 |
EAbort,
|
sl@0
|
219 |
EClearRemoteStall,
|
sl@0
|
220 |
EGetEndpointId,
|
sl@0
|
221 |
};
|
sl@0
|
222 |
|
sl@0
|
223 |
#ifndef __KERNEL_MODE__
|
sl@0
|
224 |
friend class RUsbInterface;
|
sl@0
|
225 |
friend class RUsbTransferStrategy;
|
sl@0
|
226 |
friend class RUsbZeroCopyTransferStrategy;
|
sl@0
|
227 |
public:
|
sl@0
|
228 |
inline RUsbPipe();
|
sl@0
|
229 |
|
sl@0
|
230 |
inline void Close();
|
sl@0
|
231 |
inline TUint32 Handle() const;
|
sl@0
|
232 |
|
sl@0
|
233 |
inline TInt GetEndpointId(TUsbEndpointId& aEndpointId);
|
sl@0
|
234 |
inline TInt GetBusId(TUsbBusId& aBusId);
|
sl@0
|
235 |
|
sl@0
|
236 |
inline TInt GetEndpointDescriptor(TUsbEndpointDescriptor& aDescriptor);
|
sl@0
|
237 |
|
sl@0
|
238 |
IMPORT_C void Transfer(RUsbTransferDescriptor& aTransfer, TRequestStatus& aRequest);
|
sl@0
|
239 |
inline void CancelAllTransfers();
|
sl@0
|
240 |
|
sl@0
|
241 |
inline TInt ClearRemoteStall();
|
sl@0
|
242 |
|
sl@0
|
243 |
private:
|
sl@0
|
244 |
inline void IssueTransfer(TInt aTransferHandle, TRequestStatus& aRequest);
|
sl@0
|
245 |
|
sl@0
|
246 |
private:
|
sl@0
|
247 |
TUint32 iHandle;
|
sl@0
|
248 |
RUsbInterface* iInterface;
|
sl@0
|
249 |
TUsbEndpointDescriptor* iHeadEndpointDescriptor;
|
sl@0
|
250 |
#endif
|
sl@0
|
251 |
};
|
sl@0
|
252 |
|
sl@0
|
253 |
|
sl@0
|
254 |
#include <d32usbdi.inl>
|
sl@0
|
255 |
|
sl@0
|
256 |
#endif // D32USBDI_H
|