epoc32/include/drivers/usbcshared.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
williamr@4
     1
// Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
williamr@4
     2
// All rights reserved.
williamr@4
     3
// This component and the accompanying materials are made available
williamr@4
     4
// under the terms of the License "Eclipse Public License v1.0"
williamr@4
     5
// which accompanies this distribution, and is available
williamr@4
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
williamr@4
     7
//
williamr@4
     8
// Initial Contributors:
williamr@4
     9
// Nokia Corporation - initial contribution.
williamr@4
    10
//
williamr@4
    11
// Contributors:
williamr@4
    12
//
williamr@4
    13
// Description:
williamr@4
    14
// e32\include\drivers\usbcshared.h
williamr@4
    15
// Kernel side definitions for the USB Device driver stack (PIL + LDD).
williamr@4
    16
// 
williamr@4
    17
//
williamr@4
    18
williamr@4
    19
/**
williamr@4
    20
 @file usbcshared.h
williamr@4
    21
 @internalTechnology
williamr@4
    22
*/
williamr@4
    23
williamr@4
    24
#ifndef __USBCSHARED_H__
williamr@4
    25
#define __USBCSHARED_H__
williamr@4
    26
williamr@4
    27
#include <drivers/usbcque.h>
williamr@4
    28
williamr@4
    29
// Define here what options are required:
williamr@4
    30
// (USB_SUPPORTS_CONTROLENDPOINTS and USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
williamr@4
    31
//  have never been tested though...)
williamr@4
    32
//#define USB_SUPPORTS_CONTROLENDPOINTS
williamr@4
    33
//#define USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
williamr@4
    34
williamr@4
    35
#include <drivers/usbcdesc.h>
williamr@4
    36
williamr@4
    37
// Debug Support
williamr@4
    38
williamr@4
    39
// Use for debugging purposes only (commented out for normal operation):
williamr@4
    40
//#define USBC_LDD_BUFFER_TRACE
williamr@4
    41
williamr@4
    42
static const char KUsbPILPanicCat[] = "USB PIL FAULT"; // kernel fault category
williamr@4
    43
_LIT(KUsbPILKillCat, "USB PIL KILL");					// thread kill category
williamr@4
    44
_LIT(KUsbLDDKillCat, "USB LDD KILL");					// thread kill category
williamr@4
    45
williamr@4
    46
/** Error code for stalled endpoint.
williamr@4
    47
*/
williamr@4
    48
const TInt KErrEndpointStall = KErrLocked;
williamr@4
    49
williamr@4
    50
/** Error code for Ep0 write prematurely ended by a host OUT token.
williamr@4
    51
*/
williamr@4
    52
const TInt KErrPrematureEnd = KErrDiskFull;
williamr@4
    53
williamr@4
    54
/** The following constants control the buffer arrangement for OUT transfers (IN transfers have only 1
williamr@4
    55
	buffer). The total size of buffering for an OUT endpoint will be number of buffers * buffersize,
williamr@4
    56
	so that, for example, a Bulk OUT endpoint will have KUsbcDmaBufNumBulk * KUsbcDmaBufSzBulk bytes of
williamr@4
    57
	buffering.
williamr@4
    58
	These buffers will be physically contiguous, so that DMA may be used.
williamr@4
    59
	The number of buffers MUST be >=2 - otherwise the buffering scheme won't work.
williamr@4
    60
	The buffer sizes should be an exact fraction of 4kB and the number of buffers such that the
williamr@4
    61
	buffersize * number of buffers is an exact multiple of 4kB, otherwise memory will be wasted.
williamr@4
    62
*/
williamr@4
    63
/** Size of a Control ep buffer.
williamr@4
    64
*/
williamr@4
    65
const TInt KUsbcDmaBufSzControl = 1024;
williamr@4
    66
williamr@4
    67
/** Size of a Bulk ep buffer.
williamr@4
    68
*/
williamr@4
    69
const TInt KUsbcDmaBufSzBulk = 4096;
williamr@4
    70
williamr@4
    71
/** Size of an Interrupt ep buffer.
williamr@4
    72
*/
williamr@4
    73
const TInt KUsbcDmaBufSzInterrupt = 4096;
williamr@4
    74
williamr@4
    75
/** Size of an Isochronous ep buffer.
williamr@4
    76
*/
williamr@4
    77
const TInt KUsbcDmaBufSzIsochronous = 4096;
williamr@4
    78
williamr@4
    79
/** Number of buffers for Control OUT endpoints.
williamr@4
    80
*/
williamr@4
    81
const TInt KUsbcDmaBufNumControl = 2;
williamr@4
    82
williamr@4
    83
/** Number of buffers for Isochronous OUT endpoints.
williamr@4
    84
*/
williamr@4
    85
const TInt KUsbcDmaBufNumIsochronous = 2;
williamr@4
    86
williamr@4
    87
/** Number of buffers for Bulk OUT endpoints.
williamr@4
    88
*/
williamr@4
    89
const TInt KUsbcDmaBufNumBulk = 2;
williamr@4
    90
williamr@4
    91
/** Number of buffers for Interrupt OUT endpoints.
williamr@4
    92
*/
williamr@4
    93
const TInt KUsbcDmaBufNumInterrupt = 2;
williamr@4
    94
williamr@4
    95
/** Maximum buffer number.
williamr@4
    96
*/
williamr@4
    97
const TInt KUsbcDmaBufNumMax = MAX4(KUsbcDmaBufNumControl, KUsbcDmaBufNumIsochronous,
williamr@4
    98
									KUsbcDmaBufNumBulk, KUsbcDmaBufNumInterrupt);
williamr@4
    99
williamr@4
   100
/** Maximum number of recorded packets possible.
williamr@4
   101
*/
williamr@4
   102
const TUint KUsbcDmaBufMaxPkts = 2;
williamr@4
   103
williamr@4
   104
/** Number of arrays.
williamr@4
   105
*/
williamr@4
   106
const TInt KUsbcDmaBufNumArrays = 2;
williamr@4
   107
williamr@4
   108
/** Max size that Ep0 packets might have.
williamr@4
   109
*/
williamr@4
   110
const TInt KUsbcBufSzControl = 64;
williamr@4
   111
williamr@4
   112
/** The Ep0 RX data collection buffer area.
williamr@4
   113
	(Arbitrary size, judged to be sufficient for SET_DESCRIPTOR requests)
williamr@4
   114
*/
williamr@4
   115
const TInt KUsbcBufSz_Ep0Rx = 1024;
williamr@4
   116
williamr@4
   117
/** The Ep0 TX buffer area.
williamr@4
   118
	(Size sufficient to hold as much data as can be requested via GET_DESCRIPTOR)
williamr@4
   119
*/
williamr@4
   120
const TInt KUsbcBufSz_Ep0Tx = 1024 * 64; 
williamr@4
   121
williamr@4
   122
williamr@4
   123
/** The USB version the stack is compliant with: 2.0 (BCD).
williamr@4
   124
*/
williamr@4
   125
const TUint16 KUsbcUsbVersion = 0x0200;
williamr@4
   126
williamr@4
   127
/** Maximum number of endpoints an interface (i.e. LDD) may have.
williamr@4
   128
*/
williamr@4
   129
const TInt KUsbcMaxEpNumber = 5;
williamr@4
   130
williamr@4
   131
/** Status FIFO depth; enough for 2 complete configs.
williamr@4
   132
*/
williamr@4
   133
const TInt KUsbDeviceStatusQueueDepth = 15;
williamr@4
   134
williamr@4
   135
/** = 'no status info'.
williamr@4
   136
*/
williamr@4
   137
const TUint32 KUsbDeviceStatusNull = 0xffffffffu;
williamr@4
   138
williamr@4
   139
/** = 'no buffer available'.
williamr@4
   140
*/
williamr@4
   141
const TInt KUsbcInvalidBufferIndex = -1;
williamr@4
   142
williamr@4
   143
/** = 'no packet available'.
williamr@4
   144
*/
williamr@4
   145
const TUint KUsbcInvalidPacketIndex = (TUint)(-1);
williamr@4
   146
williamr@4
   147
/** = 'no drainable buffers'.
williamr@4
   148
*/
williamr@4
   149
const TInt KUsbcInvalidDrainQueueIndex = -1;
williamr@4
   150
williamr@4
   151
/** Number of possible bandwidth priorities.
williamr@4
   152
*/
williamr@4
   153
const TInt KUsbcDmaBufMaxPriorities = 4;
williamr@4
   154
williamr@4
   155
// The following buffer sizes are used within the LDD for the different
williamr@4
   156
// user-selectable endpoint bandwidth priorities
williamr@4
   157
// (EUsbcBandwidthOUTDefault/Plus1/Plus2/Maximum + the same for 'IN').
williamr@4
   158
// These values, in particular those for the Maximum setting, were obtained
williamr@4
   159
// empirically.
williamr@4
   160
williamr@4
   161
/** Bulk IN buffer sizes for different priorities (4K, 16K, 64K, 512K).
williamr@4
   162
*/
williamr@4
   163
const TInt KUsbcDmaBufSizesBulkIN[KUsbcDmaBufMaxPriorities] =
williamr@4
   164
	{KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
williamr@4
   165
williamr@4
   166
/** Bulk OUT buffer sizes for different priorities (4K, 16K, 64K, 512K).
williamr@4
   167
*/
williamr@4
   168
const TInt KUsbcDmaBufSizesBulkOUT[KUsbcDmaBufMaxPriorities] =
williamr@4
   169
	{KUsbcDmaBufSzBulk, 0x4000, 0x10000, 0x80000};
williamr@4
   170
williamr@4
   171
/** Number of UDCs supported in the system.
williamr@4
   172
	(Support for more than one UDC is preliminary.)
williamr@4
   173
*/
williamr@4
   174
const TInt KUsbcMaxUdcs = 2;
williamr@4
   175
williamr@4
   176
/** Number of endpoints a USB device can have.
williamr@4
   177
	(30 regular endpoints + 2 x Ep0)
williamr@4
   178
*/
williamr@4
   179
const TInt KUsbcEpArraySize = KUsbcMaxEndpoints + 2;
williamr@4
   180
williamr@4
   181
/** Number of notification requests of the same kind that can be registered at
williamr@4
   182
	a time. As normally not more than one request per kind per LDD is
williamr@4
   183
	permitted, this number is roughly equivalent to the maximum number of LDDs
williamr@4
   184
	that can be operating at the same time.
williamr@4
   185
	This constant is used by the PIL while maintaining its request lists
williamr@4
   186
	(iClientCallbacks, iStatusCallbacks, iEpStatusCallbacks, iOtgCallbacks) to
williamr@4
   187
	ensure that the lists are of a finite length and thus the list traverse
williamr@4
   188
	time is bounded.
williamr@4
   189
	This value is chosen with the maximum number of USB interfaces (not
williamr@4
   190
	settings) allowed by the spec for a single device in mind.
williamr@4
   191
*/
williamr@4
   192
const TInt KUsbcMaxListLength = 256;
williamr@4
   193
williamr@4
   194
/** Used by the LDD.
williamr@4
   195
*/
williamr@4
   196
typedef TUint32 TUsbcPacketArray;
williamr@4
   197
williamr@4
   198
williamr@4
   199
/** Used as a return value from DUsbClientController::EnquireEp0NextState(),
williamr@4
   200
	the purpose of which is to enable the PSL to find out what the next stage
williamr@4
   201
	will be for a newly received Setup packet.
williamr@4
   202
williamr@4
   203
	The enum values are self-explanatory.
williamr@4
   204
williamr@4
   205
	@publishedPartner
williamr@4
   206
	@released
williamr@4
   207
*/
williamr@4
   208
enum TUsbcEp0State
williamr@4
   209
	{
williamr@4
   210
	EEp0StateDataIn,
williamr@4
   211
	EEp0StateDataOut,
williamr@4
   212
	EEp0StateStatusIn
williamr@4
   213
	};
williamr@4
   214
williamr@4
   215
williamr@4
   216
/** Used to show the direction of a transfer request to the Controller.
williamr@4
   217
williamr@4
   218
	@see TUsbcRequestCallback
williamr@4
   219
*/
williamr@4
   220
enum TTransferDirection {EControllerNone, EControllerRead, EControllerWrite};
williamr@4
   221
williamr@4
   222
williamr@4
   223
/** These event codes are used by the PSL to tell the PIL what has happened.
williamr@4
   224
williamr@4
   225
	@publishedPartner
williamr@4
   226
	@released
williamr@4
   227
*/
williamr@4
   228
enum TUsbcDeviceEvent
williamr@4
   229
	{
williamr@4
   230
	/** The USB Suspend bus state has been detected. */
williamr@4
   231
	EUsbEventSuspend,
williamr@4
   232
	/** USB Resume signalling has been detected. */
williamr@4
   233
	EUsbEventResume,
williamr@4
   234
	/** A USB Reset condition has been detected. */
williamr@4
   235
	EUsbEventReset,
williamr@4
   236
	/** Physical removal of the USB cable has been detected. */
williamr@4
   237
	EUsbEventCableRemoved,
williamr@4
   238
	/** Physical insertion of the USB cable has been detected. */
williamr@4
   239
	EUsbEventCableInserted
williamr@4
   240
	};
williamr@4
   241
williamr@4
   242
williamr@4
   243
/** USB LDD client callback.
williamr@4
   244
*/
williamr@4
   245
class TUsbcClientCallback
williamr@4
   246
    {
williamr@4
   247
public:
williamr@4
   248
	inline TUsbcClientCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
williamr@4
   249
	inline DBase* Owner() const;
williamr@4
   250
	inline TInt DoCallback();
williamr@4
   251
	inline void Cancel();
williamr@4
   252
	inline void SetDfcQ(TDfcQue* aDfcQ);
williamr@4
   253
public:
williamr@4
   254
	/** Used by the PIL to queue callback objects into a TSglQue. */
williamr@4
   255
	TSglQueLink iLink;
williamr@4
   256
private:
williamr@4
   257
	DBase* iOwner;
williamr@4
   258
	TDfc iDfc;
williamr@4
   259
    };
williamr@4
   260
williamr@4
   261
williamr@4
   262
/** The endpoint halt/clear_halt status.
williamr@4
   263
*/
williamr@4
   264
class TUsbcEndpointStatusCallback
williamr@4
   265
	{
williamr@4
   266
public:
williamr@4
   267
	inline TUsbcEndpointStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
williamr@4
   268
	inline void SetState(TUint aState);
williamr@4
   269
	inline TUint State() const;
williamr@4
   270
	inline DBase* Owner() const;
williamr@4
   271
	inline TInt DoCallback();
williamr@4
   272
	inline void Cancel();
williamr@4
   273
	inline void SetDfcQ(TDfcQue* aDfcQ);
williamr@4
   274
public:
williamr@4
   275
	/** Used by the PIL to queue callback objects into a TSglQue. */
williamr@4
   276
	TSglQueLink iLink;
williamr@4
   277
private:
williamr@4
   278
	DBase* iOwner;
williamr@4
   279
	TDfc iDfc;
williamr@4
   280
	TUint iState;
williamr@4
   281
	};
williamr@4
   282
williamr@4
   283
williamr@4
   284
/** Maximum number of device status requests that can be queued at a time.
williamr@4
   285
	The value chosen is thought to be sufficient in all situations.
williamr@4
   286
*/
williamr@4
   287
const TInt KUsbcDeviceStateRequests = 8;
williamr@4
   288
williamr@4
   289
williamr@4
   290
/** The USB device status.
williamr@4
   291
*/
williamr@4
   292
class TUsbcStatusCallback
williamr@4
   293
	{
williamr@4
   294
public:
williamr@4
   295
	inline TUsbcStatusCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
williamr@4
   296
	inline void SetState(TUsbcDeviceState aState);
williamr@4
   297
	inline TUsbcDeviceState State(TInt aIndex) const;
williamr@4
   298
	inline void ResetState();
williamr@4
   299
	inline DBase* Owner() const;
williamr@4
   300
	inline TInt DoCallback();
williamr@4
   301
	inline void Cancel();
williamr@4
   302
	inline void SetDfcQ(TDfcQue* aDfcQ);
williamr@4
   303
public:
williamr@4
   304
	/** Used by the PIL to queue callback objects into a TSglQue. */
williamr@4
   305
	TSglQueLink iLink;
williamr@4
   306
private:
williamr@4
   307
	DBase* iOwner;
williamr@4
   308
	TDfc iDfc;
williamr@4
   309
	TUsbcDeviceState iState[KUsbcDeviceStateRequests];
williamr@4
   310
	};
williamr@4
   311
williamr@4
   312
williamr@4
   313
/** A USB transfer request.
williamr@4
   314
williamr@4
   315
	@publishedPartner
williamr@4
   316
	@released
williamr@4
   317
*/
williamr@4
   318
class TUsbcRequestCallback
williamr@4
   319
	{
williamr@4
   320
public:
williamr@4
   321
	/** @internalTechnology */
williamr@4
   322
	inline TUsbcRequestCallback(const DBase* aOwner, TInt aEndpointNum, TDfcFn aDfcFunc,
williamr@4
   323
						 TAny* aEndpoint, TDfcQue* aDfcQ, TInt aPriority);
williamr@4
   324
	/** @internalTechnology	*/
williamr@4
   325
	inline ~TUsbcRequestCallback();
williamr@4
   326
	/** @internalTechnology	*/
williamr@4
   327
	inline void SetRxBufferInfo(TUint8* aBufferStart, TPhysAddr aBufferAddr,
williamr@4
   328
								TUsbcPacketArray* aPacketIndex, TUsbcPacketArray* aPacketSize,
williamr@4
   329
								TInt aLength);
williamr@4
   330
	/** @internalTechnology	*/
williamr@4
   331
	inline void SetTxBufferInfo(TUint8* aBufferStart, TPhysAddr aBufferAddr, TInt aLength);
williamr@4
   332
	/** @internalTechnology	*/
williamr@4
   333
	inline void SetTransferDirection(TTransferDirection aTransferDir);
williamr@4
   334
	/** @internalTechnology	*/
williamr@4
   335
	inline const DBase* Owner() const;
williamr@4
   336
	/** @internalTechnology	*/
williamr@4
   337
	inline TInt DoCallback();
williamr@4
   338
	/** @internalTechnology	*/
williamr@4
   339
	inline void Cancel();
williamr@4
   340
public:
williamr@4
   341
	/** Used by the PIL to queue callback objects into a TSglQue.
williamr@4
   342
		@internalTechnology
williamr@4
   343
	*/
williamr@4
   344
	TSglQueLink iLink;
williamr@4
   345
public:
williamr@4
   346
	/** The endpoint number. */
williamr@4
   347
	const TInt iEndpointNum;
williamr@4
   348
	/** The 'real' endpoint number, as used by the PDD. */
williamr@4
   349
	TInt iRealEpNum;
williamr@4
   350
	/** Indicates the LDD client for this transfer. */
williamr@4
   351
	const DBase* const iOwner;
williamr@4
   352
	/** DFC, used by PIL to call back the LDD when transfer completes to the LDD. */
williamr@4
   353
	TDfc iDfc;
williamr@4
   354
	/** Direction of transfer request. */
williamr@4
   355
	TTransferDirection iTransferDir;
williamr@4
   356
	/** Start address of this buffer. */
williamr@4
   357
	TUint8* iBufferStart;
williamr@4
   358
	/** Physical address of buffer start (used for DMA). */
williamr@4
   359
	TPhysAddr iBufferAddr;
williamr@4
   360
	/** Array of pointers into iBufferStart (actually TUsbcPacketArray (*)[]). */
williamr@4
   361
	TUsbcPacketArray* iPacketIndex;
williamr@4
   362
	/** Array of packet sizes (actually TUsbcPacketArray (*)[]). */
williamr@4
   363
	TUsbcPacketArray* iPacketSize;
williamr@4
   364
	/** Length in bytes of buffer (iBufferStart). */
williamr@4
   365
	TInt iLength;
williamr@4
   366
	/** For IN transfers, if a zlp might be required at the end of this transfer. */
williamr@4
   367
	TBool iZlpReqd;
williamr@4
   368
	/** Number of bytes transmitted; changed by the PSL. */
williamr@4
   369
	TUint iTxBytes;
williamr@4
   370
	/** Number of packets received (if it is a read); changed by the PSL. */
williamr@4
   371
	TUint iRxPackets;
williamr@4
   372
	/** The error code upon completion of the request; changed by the PSL. */
williamr@4
   373
	TInt iError;
williamr@4
   374
	};
williamr@4
   375
williamr@4
   376
/** USB On-The-Go feature change callback.
williamr@4
   377
*/
williamr@4
   378
class TUsbcOtgFeatureCallback
williamr@4
   379
    {
williamr@4
   380
public:
williamr@4
   381
	inline TUsbcOtgFeatureCallback(DBase* aOwner, TDfcFn aCallback, TInt aPriority);
williamr@4
   382
	inline void SetFeatures(TUint8 aFeatures);
williamr@4
   383
	inline TUint8 Features() const;
williamr@4
   384
	inline DBase* Owner() const;
williamr@4
   385
	inline TInt DoCallback();
williamr@4
   386
	inline void Cancel();
williamr@4
   387
	inline void SetDfcQ(TDfcQue* aDfcQ);
williamr@4
   388
public:
williamr@4
   389
	/** Used by the PIL to queue callback objects into a TSglQue. */
williamr@4
   390
	TSglQueLink iLink;
williamr@4
   391
private:
williamr@4
   392
	DBase* iOwner;
williamr@4
   393
	TDfc iDfc;
williamr@4
   394
	TUint8 iValue;
williamr@4
   395
    };
williamr@4
   396
williamr@4
   397
//
williamr@4
   398
//########################### Physical Device Driver (PIL + PSL) ######################
williamr@4
   399
//
williamr@4
   400
williamr@4
   401
class TUsbcLogicalEndpoint;
williamr@4
   402
williamr@4
   403
/** This models a physical (real) endpoint of the UDC.
williamr@4
   404
*/
williamr@4
   405
class TUsbcPhysicalEndpoint
williamr@4
   406
	{
williamr@4
   407
public:
williamr@4
   408
	TUsbcPhysicalEndpoint();
williamr@4
   409
	~TUsbcPhysicalEndpoint();
williamr@4
   410
	TBool EndpointSuitable(const TUsbcEndpointInfo* aEpInfo, TInt aIfcNumber) const; // Check Todo, SC will pass pointer to derived class
williamr@4
   411
	TInt TypeAvailable(TUint aType) const;
williamr@4
   412
	TInt DirAvailable(TUint aDir) const;
williamr@4
   413
public:
williamr@4
   414
	/** This endpoint's capabilities. */
williamr@4
   415
	TUsbcEndpointCaps iCaps;
williamr@4
   416
	/** USB address: 0x00, 0x80, 0x01, 0x81, etc. */
williamr@4
   417
	TUint8 iEndpointAddr;
williamr@4
   418
	/** Pointer to interface # this endpoint has been assigned to. */
williamr@4
   419
	const TUint8* iIfcNumber;
williamr@4
   420
	/** Pointer to corresponding logical endpoint or NULL. */
williamr@4
   421
	const TUsbcLogicalEndpoint* iLEndpoint;
williamr@4
   422
	/** Only used when searching for available endpoints. */
williamr@4
   423
	TBool iSettingReserve;
williamr@4
   424
	/** True if endpoint is halted (i.e. issues STALL handshakes), false otherwise. */
williamr@4
   425
	TBool iHalt;
williamr@4
   426
	};
williamr@4
   427
williamr@4
   428
williamr@4
   429
class DUsbClientController;
williamr@4
   430
class TUsbcInterface;
williamr@4
   431
williamr@4
   432
/** This is a 'logical' endpoint, as used by our device configuration model.
williamr@4
   433
*/
williamr@4
   434
class TUsbcLogicalEndpoint
williamr@4
   435
	{
williamr@4
   436
public:
williamr@4
   437
	TUsbcLogicalEndpoint(DUsbClientController* aController, TUint aEndpointNum,
williamr@4
   438
						 const TUsbcEndpointInfo& aEpInfo, TUsbcInterface* aInterface,
williamr@4
   439
						 TUsbcPhysicalEndpoint* aPEndpoint);		// Check Todo, SC will pass pointer to derived class
williamr@4
   440
	~TUsbcLogicalEndpoint();
williamr@4
   441
public:
williamr@4
   442
	/** Pointer to controller object. */
williamr@4
   443
	DUsbClientController* iController;
williamr@4
   444
	/** The virtual (logical) endpoint number. */
williamr@4
   445
	const TInt iLEndpointNum;
williamr@4
   446
	/** This endpoint's info structure. */
williamr@4
   447
	TUsbcEndpointInfo iInfo;										// Check Todo, SC will pass pointer to derived class
williamr@4
   448
	/** Stores the endpoint size to be used for FS. */
williamr@4
   449
	TInt iEpSize_Fs;
williamr@4
   450
	/** Stores the endpoint size to be used for HS. */
williamr@4
   451
	TInt iEpSize_Hs;
williamr@4
   452
	/** 'Back' pointer. */
williamr@4
   453
	const TUsbcInterface* iInterface;
williamr@4
   454
	/** Pointer to corresponding physical endpoint, never NULL. */
williamr@4
   455
	TUsbcPhysicalEndpoint* const iPEndpoint;
williamr@4
   456
	};
williamr@4
   457
williamr@4
   458
williamr@4
   459
class TUsbcInterfaceSet;
williamr@4
   460
williamr@4
   461
/** This is an 'alternate setting' of an interface.
williamr@4
   462
*/
williamr@4
   463
class TUsbcInterface
williamr@4
   464
	{
williamr@4
   465
public:
williamr@4
   466
	TUsbcInterface(TUsbcInterfaceSet* aIfcSet, TUint8 aSetting, TBool aNoEp0Requests);
williamr@4
   467
	~TUsbcInterface();
williamr@4
   468
public:
williamr@4
   469
	/** Array of endpoints making up (belonging to) this setting. */
williamr@4
   470
	RPointerArray<TUsbcLogicalEndpoint> iEndpoints;
williamr@4
   471
	/** 'Back' pointer. */
williamr@4
   472
	TUsbcInterfaceSet* const iInterfaceSet;
williamr@4
   473
	/** bAlternateSetting (zero-based). */
williamr@4
   474
	const TUint8 iSettingCode;
williamr@4
   475
	/** KUsbcInterfaceInfo_NoEp0RequestsPlease: stall non-std Setup requests. */
williamr@4
   476
	const TBool iNoEp0Requests;
williamr@4
   477
	};
williamr@4
   478
williamr@4
   479
williamr@4
   480
/** This is an 'interface' (owning 1 or more alternate settings).
williamr@4
   481
williamr@4
   482
	@see TUsbcInterface
williamr@4
   483
*/
williamr@4
   484
class TUsbcInterfaceSet
williamr@4
   485
	{
williamr@4
   486
public:
williamr@4
   487
	TUsbcInterfaceSet(const DBase* aClientId, TUint8 aIfcNum);
williamr@4
   488
	~TUsbcInterfaceSet();
williamr@4
   489
	inline const TUsbcInterface* CurrentInterface() const;
williamr@4
   490
	inline TUsbcInterface* CurrentInterface();
williamr@4
   491
public:
williamr@4
   492
	/** Array of alternate settings provided by (belonging to) this interface. */
williamr@4
   493
	RPointerArray<TUsbcInterface> iInterfaces;
williamr@4
   494
	/** Pointer to the LDD which created and owns this interface. */
williamr@4
   495
	const DBase* const iClientId;
williamr@4
   496
	/** bInterfaceNumber (zero-based). */
williamr@4
   497
	TUint8 iInterfaceNumber;
williamr@4
   498
	/** bAlternateSetting (zero-based). */
williamr@4
   499
	TUint8 iCurrentInterface;
williamr@4
   500
	};
williamr@4
   501
williamr@4
   502
williamr@4
   503
/** This is a 'configuration' of the USB device.
williamr@4
   504
	Currently we support only one configuration.
williamr@4
   505
*/
williamr@4
   506
class TUsbcConfiguration
williamr@4
   507
	{
williamr@4
   508
public:
williamr@4
   509
	TUsbcConfiguration(TUint8 aConfigVal);
williamr@4
   510
	~TUsbcConfiguration();
williamr@4
   511
public:
williamr@4
   512
	/** Array of interfaces making up (belonging to) this configuration. */
williamr@4
   513
	RPointerArray<TUsbcInterfaceSet> iInterfaceSets;
williamr@4
   514
	/** bConfigurationValue (one-based). */
williamr@4
   515
	const TUint8 iConfigValue;
williamr@4
   516
	};
williamr@4
   517
williamr@4
   518
williamr@4
   519
/** A USB Setup packet.
williamr@4
   520
williamr@4
   521
	Used mainly internally by the PIL but also by
williamr@4
   522
	DUsbClientController::ProcessSetConfiguration(const TUsbcSetup&),
williamr@4
   523
	which is classified as publishedPartner.
williamr@4
   524
williamr@4
   525
	@publishedPartner @released
williamr@4
   526
*/
williamr@4
   527
struct TUsbcSetup
williamr@4
   528
	{
williamr@4
   529
	/** bmRequestType */
williamr@4
   530
	TUint8 iRequestType;
williamr@4
   531
	/** bRequest */
williamr@4
   532
	TUint8 iRequest;
williamr@4
   533
	/** wValue */
williamr@4
   534
	TUint16 iValue;
williamr@4
   535
	/** wIndex */
williamr@4
   536
	TUint16 iIndex;
williamr@4
   537
	/** wLength */
williamr@4
   538
	TUint16 iLength;
williamr@4
   539
	};
williamr@4
   540
williamr@4
   541
williamr@4
   542
/** The USB controller's power handler class.
williamr@4
   543
*/
williamr@4
   544
class DUsbcPowerHandler : public DPowerHandler
williamr@4
   545
	{
williamr@4
   546
public:
williamr@4
   547
	void PowerUp();
williamr@4
   548
	void PowerDown(TPowerState);
williamr@4
   549
public:
williamr@4
   550
	DUsbcPowerHandler(DUsbClientController* aController);
williamr@4
   551
private:
williamr@4
   552
	DUsbClientController* iController;
williamr@4
   553
	};
williamr@4
   554
williamr@4
   555
williamr@4
   556
/*
williamr@4
   557
This is the EndpointInfo class used by the usb shared chunk client driver. 
williamr@4
   558
*/
williamr@4
   559
williamr@4
   560
class TUsbcScEndpointInfo;
williamr@4
   561
williamr@4
   562
williamr@4
   563
/**
williamr@4
   564
Used to represent an array of (or inheriting from) TUsbcEndpointInfo objects.
williamr@4
   565
williamr@4
   566
@see DUsbClientController::SetInterface
williamr@4
   567
*/
williamr@4
   568
williamr@4
   569
class TUsbcEndpointInfoArray
williamr@4
   570
	{
williamr@4
   571
public:
williamr@4
   572
	typedef enum {EUsbcEndpointInfo, EUsbcScEndpointInfo} TArrayType;
williamr@4
   573
williamr@4
   574
	TUsbcEndpointInfoArray(const TUsbcEndpointInfo* aData, TInt aDataSize=0);
williamr@4
   575
	TUsbcEndpointInfoArray(const TUsbcScEndpointInfo* aData, TInt aDataSize=0);
williamr@4
   576
	inline TUsbcEndpointInfo& operator[](TInt aIndex) const; 
williamr@4
   577
williamr@4
   578
	TArrayType iType;
williamr@4
   579
private:
williamr@4
   580
	TUint8* iData;
williamr@4
   581
	TInt iDataSize;
williamr@4
   582
	};
williamr@4
   583
williamr@4
   584
class TUsbcRequestCallback; // todo?? required only for class below
williamr@4
   585
williamr@4
   586
/** The USB Device software controller class.
williamr@4
   587
williamr@4
   588
	Implements the platform-independent layer (PIL), and defines the interface to the
williamr@4
   589
	platform-specific layer PSL).
williamr@4
   590
williamr@4
   591
	The implementation of the platform-specific layer interfaces with the hardware.
williamr@4
   592
*/
williamr@4
   593
class DUsbClientController : public DBase
williamr@4
   594
	{
williamr@4
   595
friend class DUsbcPowerHandler;
williamr@4
   596
friend TUsbcLogicalEndpoint::~TUsbcLogicalEndpoint();
williamr@4
   597
	//
williamr@4
   598
	// --- Platform Independent Layer (PIL) ---
williamr@4
   599
	//
williamr@4
   600
williamr@4
   601
public:
williamr@4
   602
williamr@4
   603
	//
williamr@4
   604
	// --- The following functions constitute the PIL interface to the LDD ---
williamr@4
   605
	//
williamr@4
   606
williamr@4
   607
	virtual ~DUsbClientController();
williamr@4
   608
	IMPORT_C void DisableClientStack();
williamr@4
   609
	IMPORT_C void EnableClientStack();
williamr@4
   610
	IMPORT_C TBool IsActive();
williamr@4
   611
	IMPORT_C TInt RegisterClientCallback(TUsbcClientCallback& aCallback);
williamr@4
   612
	IMPORT_C static DUsbClientController* UsbcControllerPointer(TInt aUdc=0);
williamr@4
   613
	IMPORT_C void EndpointCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
williamr@4
   614
	IMPORT_C void DeviceCaps(const DBase* aClientId, TDes8 &aCapsBuf) const;
williamr@4
   615
	IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread, TInt aInterfaceNum,
williamr@4
   616
							   TUsbcClassInfo& aClass, TDesC8* aString, TInt aTotalEndpointsUsed,
williamr@4
   617
							   const TUsbcEndpointInfo aEndpointData[], TInt (*aRealEpNumbers)[6],
williamr@4
   618
							   TUint32 aFeatureWord);
williamr@4
   619
	IMPORT_C TInt SetInterface(const DBase* aClientId, DThread* aThread,
williamr@4
   620
												 TInt aInterfaceNum, TUsbcClassInfo& aClass,
williamr@4
   621
												 TDesC8* aString, TInt aTotalEndpointsUsed,
williamr@4
   622
												 const TUsbcEndpointInfoArray aEndpointData,
williamr@4
   623
												 TInt aRealEpNumbers[], TUint32 aFeatureWord);
williamr@4
   624
	IMPORT_C TInt ReleaseInterface(const DBase* aClientId, TInt aInterfaceNum);
williamr@4
   625
	IMPORT_C TInt ReEnumerate();
williamr@4
   626
	IMPORT_C TInt PowerUpUdc();
williamr@4
   627
	IMPORT_C TInt UsbConnect();
williamr@4
   628
	IMPORT_C TInt UsbDisconnect();
williamr@4
   629
	IMPORT_C TInt RegisterForStatusChange(TUsbcStatusCallback& aCallback);
williamr@4
   630
	IMPORT_C TInt DeRegisterForStatusChange(const DBase* aClientId);
williamr@4
   631
	IMPORT_C TInt RegisterForEndpointStatusChange(TUsbcEndpointStatusCallback& aCallback);
williamr@4
   632
	IMPORT_C TInt DeRegisterForEndpointStatusChange(const DBase* aClientId);
williamr@4
   633
	IMPORT_C TInt GetInterfaceNumber(const DBase* aClientId, TInt& aInterfaceNum) const;
williamr@4
   634
	IMPORT_C TInt DeRegisterClient(const DBase* aClientId);
williamr@4
   635
	IMPORT_C TInt Ep0PacketSize() const;
williamr@4
   636
	IMPORT_C TInt Ep0Stall(const DBase* aClientId);
williamr@4
   637
	IMPORT_C void SendEp0StatusPacket(const DBase* aClientId);
williamr@4
   638
	IMPORT_C TUsbcDeviceState GetDeviceStatus() const;
williamr@4
   639
	IMPORT_C TEndpointState GetEndpointStatus(const DBase* aClientId, TInt aEndpointNum) const;
williamr@4
   640
	IMPORT_C TInt SetupReadBuffer(TUsbcRequestCallback& aCallback);
williamr@4
   641
	IMPORT_C TInt SetupWriteBuffer(TUsbcRequestCallback& aCallback);
williamr@4
   642
	IMPORT_C void CancelReadBuffer(const DBase* aClientId, TInt aRealEndpoint);
williamr@4
   643
	IMPORT_C void CancelWriteBuffer(const DBase* aClientId, TInt aRealEndpoint);
williamr@4
   644
	IMPORT_C TInt HaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
williamr@4
   645
	IMPORT_C TInt ClearHaltEndpoint(const DBase* aClientId, TInt aEndpointNum);
williamr@4
   646
	IMPORT_C TInt SetDeviceControl(const DBase* aClientId);
williamr@4
   647
	IMPORT_C TInt ReleaseDeviceControl(const DBase* aClientId);
williamr@4
   648
	IMPORT_C TUint EndpointZeroMaxPacketSizes() const;
williamr@4
   649
	IMPORT_C TInt SetEndpointZeroMaxPacketSize(TInt aMaxPacketSize);
williamr@4
   650
	IMPORT_C TInt GetDeviceDescriptor(DThread* aThread, TDes8& aDeviceDescriptor);
williamr@4
   651
	IMPORT_C TInt SetDeviceDescriptor(DThread* aThread, const TDes8& aDeviceDescriptor);
williamr@4
   652
	IMPORT_C TInt GetDeviceDescriptorSize(DThread* aThread, TDes8& aSize);
williamr@4
   653
	IMPORT_C TInt GetConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
williamr@4
   654
	IMPORT_C TInt SetConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
williamr@4
   655
	IMPORT_C TInt GetConfigurationDescriptorSize(DThread* aThread, TDes8& aSize);
williamr@4
   656
	IMPORT_C TInt SetOtgDescriptor(DThread* aThread, const TDesC8& aOtgDesc);
williamr@4
   657
	IMPORT_C TInt GetOtgDescriptor(DThread* aThread, TDes8& aOtgDesc) const;
williamr@4
   658
	IMPORT_C TInt GetOtgFeatures(DThread* aThread, TDes8& aFeatures) const;
williamr@4
   659
	IMPORT_C TInt GetCurrentOtgFeatures(TUint8& aFeatures) const;
williamr@4
   660
	IMPORT_C TInt RegisterForOtgFeatureChange(TUsbcOtgFeatureCallback& aCallback);
williamr@4
   661
	IMPORT_C TInt DeRegisterForOtgFeatureChange(const DBase* aClientId);
williamr@4
   662
	IMPORT_C TInt GetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   663
										 TDes8& aInterfaceDescriptor);
williamr@4
   664
	IMPORT_C TInt SetInterfaceDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   665
										 const TDes8& aInterfaceDescriptor);
williamr@4
   666
	IMPORT_C TInt GetInterfaceDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   667
											 TDes8& aSize);
williamr@4
   668
	IMPORT_C TInt GetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   669
										TInt aEndpointNum, TDes8& aEndpointDescriptor);
williamr@4
   670
	IMPORT_C TInt SetEndpointDescriptor(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   671
										TInt aEndpointNum, const TDes8& aEndpointDescriptor);
williamr@4
   672
	IMPORT_C TInt GetEndpointDescriptorSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   673
											TInt aEndpointNum, TDes8& aSize);
williamr@4
   674
	IMPORT_C TInt GetDeviceQualifierDescriptor(DThread* aThread, TDes8& aDeviceQualifierDescriptor);
williamr@4
   675
	IMPORT_C TInt SetDeviceQualifierDescriptor(DThread* aThread, const TDes8& aDeviceQualifierDescriptor);
williamr@4
   676
	IMPORT_C TInt GetOtherSpeedConfigurationDescriptor(DThread* aThread, TDes8& aConfigurationDescriptor);
williamr@4
   677
	IMPORT_C TInt SetOtherSpeedConfigurationDescriptor(DThread* aThread, const TDes8& aConfigurationDescriptor);
williamr@4
   678
	IMPORT_C TInt GetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   679
												TDes8& aInterfaceDescriptor);
williamr@4
   680
	IMPORT_C TInt SetCSInterfaceDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   681
												const TDes8& aInterfaceDescriptor, TInt aSize);
williamr@4
   682
	IMPORT_C TInt GetCSInterfaceDescriptorBlockSize(DThread* aThread, const DBase* aClientId,
williamr@4
   683
													TInt aSettingNum, TDes8& aSize);
williamr@4
   684
	IMPORT_C TInt GetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   685
											   TInt aEndpointNum, TDes8& aEndpointDescriptor);
williamr@4
   686
	IMPORT_C TInt SetCSEndpointDescriptorBlock(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   687
											   TInt aEndpointNum, const TDes8& aEndpointDescriptor,
williamr@4
   688
											   TInt aSize);
williamr@4
   689
	IMPORT_C TInt GetCSEndpointDescriptorBlockSize(DThread* aThread, const DBase* aClientId, TInt aSettingNum,
williamr@4
   690
												   TInt aEndpointNum, TDes8& aSize);
williamr@4
   691
	IMPORT_C TInt GetStringDescriptorLangId(DThread* aThread, TDes8& aLangId);
williamr@4
   692
	IMPORT_C TInt SetStringDescriptorLangId(TUint16 aLangId);
williamr@4
   693
	IMPORT_C TInt GetManufacturerStringDescriptor(DThread* aThread, TDes8& aString);
williamr@4
   694
	IMPORT_C TInt SetManufacturerStringDescriptor(DThread* aThread, const TDes8& aString);
williamr@4
   695
	IMPORT_C TInt RemoveManufacturerStringDescriptor();
williamr@4
   696
	IMPORT_C TInt GetProductStringDescriptor(DThread* aThread, TDes8& aString);
williamr@4
   697
	IMPORT_C TInt SetProductStringDescriptor(DThread* aThread, const TDes8& aString);
williamr@4
   698
	IMPORT_C TInt RemoveProductStringDescriptor();
williamr@4
   699
	IMPORT_C TInt GetSerialNumberStringDescriptor(DThread* aThread, TDes8& aString);
williamr@4
   700
	IMPORT_C TInt SetSerialNumberStringDescriptor(DThread* aThread, const TDes8& aString);
williamr@4
   701
	IMPORT_C TInt RemoveSerialNumberStringDescriptor();
williamr@4
   702
	IMPORT_C TInt GetConfigurationStringDescriptor(DThread* aThread, TDes8& aString);
williamr@4
   703
	IMPORT_C TInt SetConfigurationStringDescriptor(DThread* aThread, const TDes8& aString);
williamr@4
   704
	IMPORT_C TInt RemoveConfigurationStringDescriptor();
williamr@4
   705
	IMPORT_C TInt GetStringDescriptor(DThread* aThread, TUint8 aIndex, TDes8& aString);
williamr@4
   706
	IMPORT_C TInt SetStringDescriptor(DThread* aThread, TUint8 aIndex, const TDes8& aString);
williamr@4
   707
	IMPORT_C TInt RemoveStringDescriptor(TUint8 aIndex);
williamr@4
   708
	IMPORT_C TInt AllocateEndpointResource(const DBase* aClientId, TInt aEndpointNum,
williamr@4
   709
										   TUsbcEndpointResource aResource);
williamr@4
   710
	IMPORT_C TInt DeAllocateEndpointResource(const DBase* aClientId, TInt aEndpointNum,
williamr@4
   711
											 TUsbcEndpointResource aResource);
williamr@4
   712
	IMPORT_C TBool QueryEndpointResource(const DBase* aClientId, TInt aEndpointNum,
williamr@4
   713
										 TUsbcEndpointResource aResource);
williamr@4
   714
	IMPORT_C TInt EndpointPacketSize(const DBase* aClientId, TInt aEndpointNum);
williamr@4
   715
williamr@4
   716
	//
williamr@4
   717
	// --- Public (pure) virtual (implemented by PSL, used by LDD) ---
williamr@4
   718
	//
williamr@4
   719
williamr@4
   720
	/** Forces the UDC into a non-idle state to perform a USB remote wakeup operation.
williamr@4
   721
williamr@4
   722
		The PSL should first check the current value of iRmWakeupStatus_Enabled
williamr@4
   723
		to determine whether or not to actually send a Remote Wakeup.
williamr@4
   724
williamr@4
   725
		@see iRmWakeupStatus_Enabled
williamr@4
   726
williamr@4
   727
		@return KErrGeneral if Remote Wakeup feature is not enabled or an error is encountered,
williamr@4
   728
		KErrNone otherwise.
williamr@4
   729
williamr@4
   730
		@publishedPartner @released
williamr@4
   731
	*/
williamr@4
   732
	IMPORT_C virtual TInt SignalRemoteWakeup() =0;
williamr@4
   733
williamr@4
   734
	/** Dumps the contents of (all or part of) the UDC registers to the serial console.
williamr@4
   735
		This is for debugging purposes only.
williamr@4
   736
williamr@4
   737
		@publishedPartner @released
williamr@4
   738
	*/
williamr@4
   739
	IMPORT_C virtual void DumpRegisters() =0;
williamr@4
   740
williamr@4
   741
	/** Returns a pointer to the DFC queue that should be used by the USB LDD.
williamr@4
   742
williamr@4
   743
		@return A pointer to the DFC queue that should be used by the USB LDD.
williamr@4
   744
williamr@4
   745
		@publishedPartner @released
williamr@4
   746
	*/
williamr@4
   747
	IMPORT_C virtual TDfcQue* DfcQ(TInt aUnit) =0;
williamr@4
   748
williamr@4
   749
	/** Returns information about the current operating speed of the UDC.
williamr@4
   750
williamr@4
   751
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
williamr@4
   752
		 The default implementation in the PIL returns EFalse.)
williamr@4
   753
williamr@4
   754
		@return ETrue if the UDC is currently operating at High speed, EFalse
williamr@4
   755
		otherwise (i.e. controller is operating at Full speed).
williamr@4
   756
williamr@4
   757
		@publishedPartner @released
williamr@4
   758
	*/
williamr@4
   759
	IMPORT_C virtual TBool CurrentlyUsingHighSpeed();
williamr@4
   760
williamr@4
   761
	//
williamr@4
   762
	// --- Public PIL functions ---
williamr@4
   763
	//
williamr@4
   764
williamr@4
   765
	DUsbClientController* RegisterUdc(TInt aUdc);
williamr@4
   766
williamr@4
   767
protected:
williamr@4
   768
williamr@4
   769
	//
williamr@4
   770
	// --- Functions and data members provided by PIL, called by PSL ---
williamr@4
   771
	//
williamr@4
   772
williamr@4
   773
	TBool InitialiseBaseClass(TUsbcDeviceDescriptor* aDeviceDesc,
williamr@4
   774
							  TUsbcConfigDescriptor* aConfigDesc,
williamr@4
   775
							  TUsbcLangIdDescriptor* aLangId,
williamr@4
   776
							  TUsbcStringDescriptor* aManufacturer =0,
williamr@4
   777
							  TUsbcStringDescriptor* aProduct =0,
williamr@4
   778
							  TUsbcStringDescriptor* aSerialNum =0,
williamr@4
   779
							  TUsbcStringDescriptor* aConfig =0,
williamr@4
   780
							  TUsbcOtgDescriptor* aOtgDesc =0);
williamr@4
   781
	DUsbClientController();
williamr@4
   782
	TInt DeviceEventNotification(TUsbcDeviceEvent aEvent);
williamr@4
   783
	void EndpointRequestComplete(TUsbcRequestCallback* aCallback);
williamr@4
   784
	TInt Ep0RequestComplete(TInt aRealEndpoint, TInt aCount, TInt aError);
williamr@4
   785
	void MoveToAddressState();
williamr@4
   786
	void SetCurrent(TInt aCurrent);
williamr@4
   787
	TUsbcEp0State EnquireEp0NextState(const TUint8* aSetupBuf) const;
williamr@4
   788
	TInt ProcessSetConfiguration(const TUsbcSetup& aPacket);
williamr@4
   789
	void HandleHnpRequest(TInt aHnpState);
williamr@4
   790
williamr@4
   791
	/** This info can be used by the PSL before sending ZLPs.
williamr@4
   792
williamr@4
   793
		@publishedPartner @released
williamr@4
   794
	*/
williamr@4
   795
	TBool iEp0ReceivedNonStdRequest;
williamr@4
   796
williamr@4
   797
	/** True if RMW is currently enabled (set by either PIL or PSL).
williamr@4
   798
williamr@4
   799
		@publishedPartner @released
williamr@4
   800
	*/
williamr@4
   801
	TBool iRmWakeupStatus_Enabled;
williamr@4
   802
williamr@4
   803
	/** Ep0 incoming (rx) data is placed here (one packet).
williamr@4
   804
williamr@4
   805
		@publishedPartner @released
williamr@4
   806
	*/
williamr@4
   807
	TUint8 iEp0_RxBuf[KUsbcBufSzControl];
williamr@4
   808
williamr@4
   809
private:
williamr@4
   810
williamr@4
   811
	//
williamr@4
   812
	// --- Platform Specific Layer (PSL) ---
williamr@4
   813
	//
williamr@4
   814
williamr@4
   815
	/** This function will be called by the PIL upon decoding a SET_ADDRESS request.
williamr@4
   816
williamr@4
   817
		UDCs which require a manual setting of the USB device address should do that in this function.
williamr@4
   818
williamr@4
   819
		@param aAddress A valid USB device address that was received with the SET_ADDRESS request.
williamr@4
   820
williamr@4
   821
		@return KErrNone if address was set successfully or if this UDC's address cannot be set manually,
williamr@4
   822
		KErrGeneral otherwise.
williamr@4
   823
williamr@4
   824
		@publishedPartner @released
williamr@4
   825
	*/
williamr@4
   826
	virtual TInt SetDeviceAddress(TInt aAddress) =0;
williamr@4
   827
williamr@4
   828
	/** Configures (enables) an endpoint (incl. Ep0) for data transmission or reception.
williamr@4
   829
williamr@4
   830
		@param aRealEndpoint The number of the endpoint to be enabled.
williamr@4
   831
		@param aEndpointInfo A reference to a properly filled-in endpoint info structure.
williamr@4
   832
williamr@4
   833
		@return KErrArgument if endpoint number or endpoint info invalid, KErrNone if endpoint
williamr@4
   834
		successfully configured, KErrGeneral otherwise.
williamr@4
   835
williamr@4
   836
		@publishedPartner @released
williamr@4
   837
	*/
williamr@4
   838
	virtual TInt ConfigureEndpoint(TInt aRealEndpoint, const TUsbcEndpointInfo& aEndpointInfo) =0;
williamr@4
   839
williamr@4
   840
	/** De-configures (disables) an endpoint (incl. Ep0).
williamr@4
   841
williamr@4
   842
		@param aRealEndpoint The number of the endpoint to be disabled.
williamr@4
   843
williamr@4
   844
		@return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully de-configured,
williamr@4
   845
		KErrGeneral otherwise.
williamr@4
   846
williamr@4
   847
		@publishedPartner @released
williamr@4
   848
	*/
williamr@4
   849
	virtual TInt DeConfigureEndpoint(TInt aRealEndpoint) =0;
williamr@4
   850
williamr@4
   851
	/** Allocates an endpoint resource.
williamr@4
   852
williamr@4
   853
		If the resource gets successfully allocated, it will be used from when the current bus transfer
williamr@4
   854
		has been completed.
williamr@4
   855
williamr@4
   856
		@param aRealEndpoint The number of the endpoint.
williamr@4
   857
		@param aResource The endpoint resource to be allocated.
williamr@4
   858
williamr@4
   859
		@return KErrNone if the resource has been successfully allocated, KErrNotSupported if the endpoint
williamr@4
   860
		does not support the resource requested, and KErrInUse if the resource is already consumed and
williamr@4
   861
		cannot be allocated.
williamr@4
   862
williamr@4
   863
		@publishedPartner @deprecated
williamr@4
   864
	*/
williamr@4
   865
	virtual TInt AllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) =0;
williamr@4
   866
williamr@4
   867
	/** Deallocates (frees) an endpoint resource.
williamr@4
   868
williamr@4
   869
		The resource will be removed from when the current bus transfer has been completed.
williamr@4
   870
williamr@4
   871
		@param aRealEndpoint The number of the endpoint.
williamr@4
   872
		@param aResource The endpoint resource to be deallocated.
williamr@4
   873
williamr@4
   874
		@return KErrNone if the resource has been successfully deallocated, KErrNotSupported if the endpoint
williamr@4
   875
		does not support the resource requested.
williamr@4
   876
williamr@4
   877
		@publishedPartner @deprecated
williamr@4
   878
	*/
williamr@4
   879
	virtual TInt DeAllocateEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) =0;
williamr@4
   880
williamr@4
   881
	/** Queries the use of and endpoint resource.
williamr@4
   882
williamr@4
   883
		@param aRealEndpoint The number of the endpoint.
williamr@4
   884
		@param aResource The endpoint resource to be queried.
williamr@4
   885
williamr@4
   886
		@return ETrue if the specified resource is in use at the endpoint, EFalse if not.
williamr@4
   887
williamr@4
   888
		@publishedPartner @released
williamr@4
   889
	*/
williamr@4
   890
	virtual TBool QueryEndpointResource(TInt aRealEndpoint, TUsbcEndpointResource aResource) const =0;
williamr@4
   891
williamr@4
   892
	/** Opens a DMA channel (if possible).
williamr@4
   893
williamr@4
   894
		@param aRealEndpoint The number of the endpoint for which to open the DMA channel.
williamr@4
   895
williamr@4
   896
		@return KErrArgument if endpoint number invalid, KErrNone if channel successfully opened or if
williamr@4
   897
		endpoint not DMA-capable, KErrGeneral otherwise.
williamr@4
   898
williamr@4
   899
		@publishedPartner @released
williamr@4
   900
	*/
williamr@4
   901
	virtual TInt OpenDmaChannel(TInt aRealEndpoint);
williamr@4
   902
williamr@4
   903
	/** Closes a DMA channel (if possible).
williamr@4
   904
williamr@4
   905
		@param aRealEndpoint The number of the endpoint for which to close the DMA channel.
williamr@4
   906
williamr@4
   907
		@publishedPartner @released
williamr@4
   908
	*/
williamr@4
   909
	virtual void CloseDmaChannel(TInt aRealEndpoint);
williamr@4
   910
williamr@4
   911
	/** Sets up a read request on an endpoint (excl. Ep0) for data reception.
williamr@4
   912
williamr@4
   913
		For endpoint 0 read requests, SetupEndpointZeroRead() is used instead.
williamr@4
   914
williamr@4
   915
		@param aRealEndpoint The number of the endpoint to be used.
williamr@4
   916
		@param aCallback A reference to a properly filled-in request callback structure.
williamr@4
   917
williamr@4
   918
		@return KErrArgument if endpoint number invalid, KErrNone if read successfully set up,
williamr@4
   919
		KErrGeneral otherwise.
williamr@4
   920
williamr@4
   921
		@publishedPartner @released
williamr@4
   922
	*/
williamr@4
   923
	virtual TInt SetupEndpointRead(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) =0;
williamr@4
   924
williamr@4
   925
	/** Sets up a write request on an endpoint (excl. Ep0) for data transmission.
williamr@4
   926
williamr@4
   927
		For endpoint 0 write requests, SetupEndpointZeroWrite() is used instead.
williamr@4
   928
williamr@4
   929
		@param aRealEndpoint The number of the endpoint to be used.
williamr@4
   930
		@param aCallback A reference to a properly filled-in request callback structure.
williamr@4
   931
williamr@4
   932
		@return KErrArgument if endpoint number invalid, KErrNone if write successfully set up,
williamr@4
   933
		KErrGeneral otherwise.
williamr@4
   934
williamr@4
   935
		@publishedPartner @released
williamr@4
   936
	*/
williamr@4
   937
	virtual TInt SetupEndpointWrite(TInt aRealEndpoint, TUsbcRequestCallback& aCallback) =0;
williamr@4
   938
williamr@4
   939
	/** Cancels a read request on an endpoint (excl. Ep0).
williamr@4
   940
williamr@4
   941
		Note that endpoint 0 read requests are never cancelled by the PIL, so
williamr@4
   942
		there is also no CancelEndpointZeroRead() function.
williamr@4
   943
williamr@4
   944
		@param aRealEndpoint The number of the endpoint to be used.
williamr@4
   945
williamr@4
   946
		@return KErrArgument if endpoint number invalid, KErrNone if read successfully cancelled,
williamr@4
   947
		KErrGeneral otherwise.
williamr@4
   948
williamr@4
   949
		@publishedPartner @released
williamr@4
   950
	*/
williamr@4
   951
	virtual TInt CancelEndpointRead(TInt aRealEndpoint) =0;
williamr@4
   952
williamr@4
   953
	/** Cancels a write request on an endpoint (incl. Ep0).
williamr@4
   954
williamr@4
   955
		The PIL calls this function also to cancel endpoint zero write requests.
williamr@4
   956
williamr@4
   957
		@param aRealEndpoint The number of the endpoint to be used.
williamr@4
   958
williamr@4
   959
		@return KErrArgument if endpoint number invalid, KErrNone if write successfully cancelled,
williamr@4
   960
		KErrGeneral otherwise.
williamr@4
   961
williamr@4
   962
		@publishedPartner @released
williamr@4
   963
	*/
williamr@4
   964
	virtual TInt CancelEndpointWrite(TInt aRealEndpoint) =0;
williamr@4
   965
williamr@4
   966
	/** Same as SetupEndpointRead(), but for endpoint zero only.
williamr@4
   967
williamr@4
   968
		No callback is used here as this function is only used internally by the PIL and no user side request
williamr@4
   969
		exists for it. The data buffer to be used (filled) is iEp0_RxBuf.
williamr@4
   970
williamr@4
   971
		@return KErrGeneral if (&iEndpoints[KEp0_Out]->iRxBuf != NULL) or some other error occurs,
williamr@4
   972
		KErrNone if read successfully set up.
williamr@4
   973
williamr@4
   974
		@publishedPartner @released
williamr@4
   975
	*/
williamr@4
   976
	virtual TInt SetupEndpointZeroRead() =0;
williamr@4
   977
williamr@4
   978
	/** Same as SetupEndpointWrite(), but for endpoint zero only.
williamr@4
   979
williamr@4
   980
		No callback is used here as this function is only used internally by the PIL and no user side request
williamr@4
   981
		exists for it.
williamr@4
   982
williamr@4
   983
		@param aBuffer This points to the beginning of the data to be sent.
williamr@4
   984
		@param aLength The number of bytes to be sent.
williamr@4
   985
		@param aZlpReqd ETrue if a zero-length packet (ZLP) is to be sent after the data.
williamr@4
   986
williamr@4
   987
		@return KErrGeneral if (&iEndpoints[KEp0_In]->iTxBuf != NULL) or some other error occurs,
williamr@4
   988
		KErrNone if write successfully set up.
williamr@4
   989
williamr@4
   990
		@publishedPartner @released
williamr@4
   991
	*/
williamr@4
   992
	virtual TInt SetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd=EFalse) =0;
williamr@4
   993
williamr@4
   994
	/** Sets up on Ep0 the transmission of a single zero-length packet (ZLP).
williamr@4
   995
williamr@4
   996
		@return KErrNone if ZLP successfully set up, KErrGeneral otherwise..
williamr@4
   997
williamr@4
   998
		@publishedPartner @released
williamr@4
   999
	*/
williamr@4
  1000
	virtual TInt SendEp0ZeroByteStatusPacket() =0;
williamr@4
  1001
williamr@4
  1002
	/** Stalls an endpoint (incl. Ep0).
williamr@4
  1003
williamr@4
  1004
		Isochronous endpoints cannot be stalled.
williamr@4
  1005
williamr@4
  1006
		@param aRealEndpoint The number of the endpoint to be stalled.
williamr@4
  1007
williamr@4
  1008
		@return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully stalled,
williamr@4
  1009
		KErrGeneral otherwise.
williamr@4
  1010
williamr@4
  1011
		@publishedPartner @released
williamr@4
  1012
	*/
williamr@4
  1013
	virtual TInt StallEndpoint(TInt aRealEndpoint) =0;
williamr@4
  1014
williamr@4
  1015
	/** Clears the stall condition on an endpoint (incl. Ep0).
williamr@4
  1016
williamr@4
  1017
		Isochronous endpoints cannot be stalled.
williamr@4
  1018
williamr@4
  1019
		@param aRealEndpoint The number of the endpoint to be stalled.
williamr@4
  1020
williamr@4
  1021
		@return KErrArgument if endpoint number invalid, KErrNone if endpoint successfully de-stalled,
williamr@4
  1022
		KErrGeneral otherwise.
williamr@4
  1023
williamr@4
  1024
		@publishedPartner @released
williamr@4
  1025
	*/
williamr@4
  1026
	virtual TInt ClearStallEndpoint(TInt aRealEndpoint) =0;
williamr@4
  1027
williamr@4
  1028
	/** Returns the stall status of an endpoint (incl. Ep0).
williamr@4
  1029
williamr@4
  1030
		Isochronous endpoints cannot be stalled.
williamr@4
  1031
williamr@4
  1032
		@param aRealEndpoint The number of the endpoint to be used.
williamr@4
  1033
williamr@4
  1034
		@return KErrArgument if endpoint number invalid, 1 if endpoint is currently stalled, 0 if not.
williamr@4
  1035
williamr@4
  1036
		@publishedPartner @released
williamr@4
  1037
	*/
williamr@4
  1038
	virtual TInt EndpointStallStatus(TInt aRealEndpoint) const =0;
williamr@4
  1039
williamr@4
  1040
	/** Returns the error status of an endpoint (incl. Ep0).
williamr@4
  1041
williamr@4
  1042
		@param aRealEndpoint The number of the endpoint to be used.
williamr@4
  1043
williamr@4
  1044
		@return KErrArgument if endpoint number invalid, KErrNone if no error at this endpoint,
williamr@4
  1045
		KErrGeneral if there is an error.
williamr@4
  1046
williamr@4
  1047
		@publishedPartner @released
williamr@4
  1048
	*/
williamr@4
  1049
	virtual TInt EndpointErrorStatus(TInt aRealEndpoint) const =0;
williamr@4
  1050
williamr@4
  1051
	/** Resets the data toggle bit for an endpoint (incl. Ep0).
williamr@4
  1052
williamr@4
  1053
		Isochronous endpoints don't use data toggles.
williamr@4
  1054
williamr@4
  1055
		@param aRealEndpoint The number of the endpoint to be used.
williamr@4
  1056
williamr@4
  1057
		@return KErrArgument if endpoint number invalid, KErrNone if data toggle successfully reset,
williamr@4
  1058
		KErrGeneral otherwise.
williamr@4
  1059
williamr@4
  1060
		@publishedPartner @released
williamr@4
  1061
	*/
williamr@4
  1062
	virtual TInt ResetDataToggle(TInt aRealEndpoint) =0;
williamr@4
  1063
williamr@4
  1064
	/** Returns the (11-bit) frame number contained in the last received SOF packet.
williamr@4
  1065
williamr@4
  1066
		This information is used for isochronous transfers.
williamr@4
  1067
williamr@4
  1068
		@return The (11-bit) frame number contained in the last received SOF packet.
williamr@4
  1069
williamr@4
  1070
		@publishedPartner @released
williamr@4
  1071
	*/
williamr@4
  1072
	virtual TInt SynchFrameNumber() const =0;
williamr@4
  1073
williamr@4
  1074
	/** Stores the (11-bit) frame number that should be sent in response to the next SYNCH_FRAME request(s).
williamr@4
  1075
williamr@4
  1076
		@publishedPartner @released
williamr@4
  1077
	 */
williamr@4
  1078
	virtual void SetSynchFrameNumber(TInt aFrameNumber) =0;
williamr@4
  1079
williamr@4
  1080
	/** Starts the UDC.
williamr@4
  1081
williamr@4
  1082
		This initializes the device controller hardware before any other operation can be
williamr@4
  1083
		performed. Tasks to be carried out here might include
williamr@4
  1084
		- resetting the whole UDC design
williamr@4
  1085
		- enabling the UDC's clock
williamr@4
  1086
		- binding & enabling the UDC (primary) interrupt
williamr@4
  1087
		- write meaningful values to some general UDC registers
williamr@4
  1088
		- enabling the USB Reset interrupt
williamr@4
  1089
		- enabling the UDC proper (for instance by setting an Enable bit)
williamr@4
  1090
williamr@4
  1091
		@return KErrNone if UDC successfully started, KErrGeneral if there was an error.
williamr@4
  1092
williamr@4
  1093
		@publishedPartner @released
williamr@4
  1094
	*/
williamr@4
  1095
	virtual TInt StartUdc() =0;
williamr@4
  1096
williamr@4
  1097
	/** Stops the UDC.
williamr@4
  1098
williamr@4
  1099
		This basically makes undone what happened in StartUdc(). Tasks to be carried out
williamr@4
  1100
		here might include:
williamr@4
  1101
		- disabling the UDC proper (for instance by clearing an Enable bit)
williamr@4
  1102
		- disabling the USB Reset interrupt
williamr@4
  1103
		- disabling & unbinding the UDC (primary) interrupt
williamr@4
  1104
		- disabling the UDC's clock
williamr@4
  1105
williamr@4
  1106
		@return KErrNone if UDC successfully stopped, KErrGeneral if there was an error.
williamr@4
  1107
williamr@4
  1108
		@publishedPartner @released
williamr@4
  1109
	*/
williamr@4
  1110
	virtual TInt StopUdc() =0;
williamr@4
  1111
williamr@4
  1112
	/** Connects the UDC  - and thus the USB device - physically to the bus.
williamr@4
  1113
williamr@4
  1114
		This might involve a call into the Variant DLL, as the mechanism to achieve the connection can be
williamr@4
  1115
		specific to the platform (rather than UDC specific). Since this functionality is not part of the USB
williamr@4
  1116
		specification it has to be explicitly supported, either by the UDC itself or by the hardware
williamr@4
  1117
		platform. If it is supported, then the member function SoftConnectCaps should be implemented to return
williamr@4
  1118
		ETrue.
williamr@4
  1119
williamr@4
  1120
		@see SoftConnectCaps()
williamr@4
  1121
williamr@4
  1122
		@return KErrNone if UDC successfully connected, KErrGeneral if there was an error.
williamr@4
  1123
williamr@4
  1124
		@publishedPartner @released
williamr@4
  1125
	*/
williamr@4
  1126
	virtual TInt UdcConnect() =0;
williamr@4
  1127
williamr@4
  1128
	/** Disconnects the UDC	 - and thus the USB device - physically from the bus.
williamr@4
  1129
williamr@4
  1130
		This might involve a call into the Variant DLL, as the mechanism to achieve the disconnection can be
williamr@4
  1131
		specific to the platform (rather than UDC specific). Since this functionality is not part of the USB
williamr@4
  1132
		specification it has to be explicitly supported, either by the UDC itself or by the hardware
williamr@4
  1133
		platform. If it is supported, then the member function SoftConnectCaps should be implemented to return
williamr@4
  1134
		ETrue.
williamr@4
  1135
williamr@4
  1136
		@see SoftConnectCaps()
williamr@4
  1137
williamr@4
  1138
		@return KErrNone if UDC successfully disconnected, KErrGeneral if there was an error.
williamr@4
  1139
williamr@4
  1140
		@publishedPartner @released
williamr@4
  1141
	*/
williamr@4
  1142
	virtual TInt UdcDisconnect() =0;
williamr@4
  1143
williamr@4
  1144
	/** Returns the USB cable connection status.
williamr@4
  1145
williamr@4
  1146
		@return ETrue if the device is connected (via the USB cable) to a USB host, EFalse if not.
williamr@4
  1147
williamr@4
  1148
		@publishedPartner @released
williamr@4
  1149
	*/
williamr@4
  1150
	virtual TBool UsbConnectionStatus() const  =0;
williamr@4
  1151
williamr@4
  1152
	/** Returns a truth value showing if the VBUS line is powered or not.
williamr@4
  1153
williamr@4
  1154
		Lack of power may indicate an unpowered host or upstream hub, or a disconnected cable.
williamr@4
  1155
williamr@4
  1156
		@return ETrue if VBUS is powered, EFalse otherwise.
williamr@4
  1157
williamr@4
  1158
		@publishedPartner @released
williamr@4
  1159
	*/
williamr@4
  1160
	virtual TBool UsbPowerStatus() const =0;
williamr@4
  1161
williamr@4
  1162
	/** Returns the current power status of the USB device.
williamr@4
  1163
williamr@4
  1164
		@return ETrue if the device is currently self-powered, EFalse if not.
williamr@4
  1165
williamr@4
  1166
		@publishedPartner @released
williamr@4
  1167
	*/
williamr@4
  1168
	virtual TBool DeviceSelfPowered() const =0;
williamr@4
  1169
williamr@4
  1170
	/** Returns a pointer to an array of TUsbcEndpointCaps structures, which describe the endpoint
williamr@4
  1171
		capabilities of this UDC.
williamr@4
  1172
williamr@4
  1173
		The dimension of the array can be obtained by calling the member function DeviceTotalEndpoints().
williamr@4
  1174
		Note that there might be gaps in the array, as the endpoints are numbered using the 'real endpoint'
williamr@4
  1175
		numbering scheme. Here is how an array could look like:
williamr@4
  1176
williamr@4
  1177
		@code
williamr@4
  1178
		static const TInt KUsbTotalEndpoints = 5;
williamr@4
  1179
		static const TUsbcEndpointCaps DeviceEndpoints[KUsbTotalEndpoints] =
williamr@4
  1180
		{
williamr@4
  1181
		//															 UDC #	  iEndpoints index
williamr@4
  1182
		{KEp0MaxPktSzMask,	(KUsbEpTypeControl	   | KUsbEpDirOut)}, //	 0 -  0
williamr@4
  1183
		{KEp0MaxPktSzMask,	(KUsbEpTypeControl	   | KUsbEpDirIn )}, //	 0 -  1
williamr@4
  1184
		{KUsbEpNotAvailable, KUsbEpNotAvailable},					 // --- Not present
williamr@4
  1185
		{KBlkMaxPktSzMask,	(KUsbEpTypeBulk		   | KUsbEpDirIn )}, //	 1 -  3
williamr@4
  1186
		{KBlkMaxPktSzMask,	(KUsbEpTypeBulk		   | KUsbEpDirOut)}	 //	 2 -  4
williamr@4
  1187
		};
williamr@4
  1188
		@endcode
williamr@4
  1189
williamr@4
  1190
		For the endpoint max packet sizes on a USB 2.0 High-speed UDC, the PSL should provide
williamr@4
  1191
		the overlaid values for both FS and HS, as the PIL can deduce the appropriate values
williamr@4
  1192
		for either speed.
williamr@4
  1193
williamr@4
  1194
		@see TUsbcEndpointCaps
williamr@4
  1195
		@see DeviceTotalEndpoints()
williamr@4
  1196
williamr@4
  1197
		@return A pointer to an array of TUsbcEndpointCaps structures, which describe the endpoint
williamr@4
  1198
		capabilities of this UDC.
williamr@4
  1199
williamr@4
  1200
		@publishedPartner @released
williamr@4
  1201
	*/
williamr@4
  1202
	virtual const TUsbcEndpointCaps* DeviceEndpointCaps() const =0;
williamr@4
  1203
williamr@4
  1204
	/** Returns the number of elements in the array pointed to by the return value of DeviceEndpointCaps().
williamr@4
  1205
williamr@4
  1206
		Note that this is not necessarily equal to the number of usable endpoints. In the example to the
williamr@4
  1207
		DeviceEndpointCaps() function, this value would be 5 even though there are only 4 endpoints.
williamr@4
  1208
williamr@4
  1209
		@see DeviceEndpointCaps()
williamr@4
  1210
williamr@4
  1211
		@return The number of elements in the array pointed to by the return value of DeviceEndpointCaps().
williamr@4
  1212
williamr@4
  1213
		@publishedPartner @released
williamr@4
  1214
	*/
williamr@4
  1215
	virtual TInt DeviceTotalEndpoints() const =0;
williamr@4
  1216
williamr@4
  1217
	/** Returns a truth value indicating whether or not this UDC or platform has the capability to disconnect
williamr@4
  1218
		and re-connect the USB D+ line under software control.
williamr@4
  1219
williamr@4
  1220
		@see UdcConnect()
williamr@4
  1221
		@see UdcDisconnect()
williamr@4
  1222
williamr@4
  1223
		@return ETrue if software connect/disconnect is supported, EFalse otherwise.
williamr@4
  1224
williamr@4
  1225
		@publishedPartner @released
williamr@4
  1226
	*/
williamr@4
  1227
	virtual TBool SoftConnectCaps() const =0;
williamr@4
  1228
williamr@4
  1229
	/** Returns a truth value indicating whether or not this UDC allows the accurate tracking of the USB
williamr@4
  1230
		device state.
williamr@4
  1231
williamr@4
  1232
		This capability affects how device state change notifications to the LDD/user are being handled.
williamr@4
  1233
williamr@4
  1234
		@return ETrue if this UDC allows the tracking of the USB device state, EFalse otherwise.
williamr@4
  1235
williamr@4
  1236
		@publishedPartner @released
williamr@4
  1237
	*/
williamr@4
  1238
	virtual TBool DeviceStateChangeCaps() const =0;
williamr@4
  1239
williamr@4
  1240
	/** Returns a truth value indicating whether the USB device controller (UDC) hardware supports
williamr@4
  1241
		detection of a plugged-in USB cable even when not powered.
williamr@4
  1242
williamr@4
  1243
		This capability affects the power management strategy used by the USB Manager.
williamr@4
  1244
williamr@4
  1245
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
williamr@4
  1246
		 The default implementation in the PIL returns EFalse.)
williamr@4
  1247
williamr@4
  1248
		@return ETrue if this UDC supports USB cable detection when not powered, EFalse otherwise.
williamr@4
  1249
williamr@4
  1250
		@publishedPartner @released
williamr@4
  1251
	*/
williamr@4
  1252
	virtual TBool CableDetectWithoutPowerCaps() const;
williamr@4
  1253
williamr@4
  1254
	/** Returns a truth value indicating whether the USB device controller (UDC) hardware supports
williamr@4
  1255
		USB High-speed operation.
williamr@4
  1256
williamr@4
  1257
		This capability affects driver functionality and behaviour throughout the implementation.
williamr@4
  1258
williamr@4
  1259
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
williamr@4
  1260
		 The default implementation in the PIL returns EFalse.)
williamr@4
  1261
williamr@4
  1262
		@return ETrue if this UDC supports USB High-speed operation, EFalse otherwise.
williamr@4
  1263
williamr@4
  1264
		@publishedPartner @released
williamr@4
  1265
	*/
williamr@4
  1266
	virtual TBool DeviceHighSpeedCaps() const;
williamr@4
  1267
williamr@4
  1268
	/** Returns a truth value indicating whether this PSL supports the new
williamr@4
  1269
		('V2') endpoint resource request scheme.
williamr@4
  1270
williamr@4
  1271
		This capability can be queried from the user-side and may determine the
williamr@4
  1272
		way the USB application issues resource allocation requests.
williamr@4
  1273
williamr@4
  1274
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
williamr@4
  1275
		 The default implementation in the PIL returns EFalse.)
williamr@4
  1276
williamr@4
  1277
		@return ETrue if PSL supports the new endpoint resource request scheme,
williamr@4
  1278
		EFalse otherwise.
williamr@4
  1279
williamr@4
  1280
		@publishedPartner @released
williamr@4
  1281
	*/
williamr@4
  1282
	virtual TBool DeviceResourceAllocV2Caps() const;
williamr@4
  1283
williamr@4
  1284
	/** Returns a truth value indicating whether this UDC handles OTG HNP bus
williamr@4
  1285
		connects/disconnects automatically in hardware.
williamr@4
  1286
williamr@4
  1287
		This capability will be queried by the PIL and determines the way the
williamr@4
  1288
		PIL calls the functions behind the
williamr@4
  1289
		iEnablePullUpOnDPlus / iDisablePullUpOnDPlus pointers.
williamr@4
  1290
williamr@4
  1291
		If HNP is handled by hardware (TBool = ETrue) then the PIL will (in
williamr@4
  1292
		that order)
williamr@4
  1293
williamr@4
  1294
		1) make calls to those function pointers dependent only on the
williamr@4
  1295
		readiness or otherwise of user-side USB Client support (i.e. the Client
williamr@4
  1296
		LDD calls DeviceConnectToHost() / DeviceDisconnectFromHost()), as
williamr@4
  1297
		opposed to also evaluating Client PDD EnableClientStack() /
williamr@4
  1298
		DisableClientStack() calls from the OTG driver.
williamr@4
  1299
williamr@4
  1300
		2) delay its USB Reset processing incl. the notification of upper
williamr@4
  1301
		layers (LDD + user-side), plus the initial setting up of an Ep0 read
williamr@4
  1302
		until user-side USB Client support readiness has been signalled
williamr@4
  1303
		(i.e. until after a call to DeviceConnectToHost()).
williamr@4
  1304
williamr@4
  1305
		(Function is not 'pure virtual' for backwards compatibility with
williamr@4
  1306
		 existing USB PSLs. The default implementation in the PIL returns EFalse.)
williamr@4
  1307
williamr@4
  1308
		@return ETrue if UDC/PSL handles HNP connects/disconnects in hardware,
williamr@4
  1309
		EFalse otherwise.
williamr@4
  1310
williamr@4
  1311
		@publishedPartner @released
williamr@4
  1312
	*/
williamr@4
  1313
	virtual TBool DeviceHnpHandledByHardwareCaps() const;
williamr@4
  1314
williamr@4
  1315
	/** Implements anything the UDC (PSL) might require following bus Suspend signalling.
williamr@4
  1316
williamr@4
  1317
		This function gets called by the PIL after it has been notified (by the PSL) about the Suspend
williamr@4
  1318
		condition.
williamr@4
  1319
williamr@4
  1320
		@publishedPartner @released
williamr@4
  1321
	*/
williamr@4
  1322
	virtual void Suspend() =0;
williamr@4
  1323
williamr@4
  1324
	/** Implements anything the UDC (PSL) might require following bus Resume signalling.
williamr@4
  1325
williamr@4
  1326
		This function gets called by the PIL after it has been notified (by the PSL) about the Resume event.
williamr@4
  1327
williamr@4
  1328
		@publishedPartner @released
williamr@4
  1329
	*/
williamr@4
  1330
	virtual void Resume() =0;
williamr@4
  1331
williamr@4
  1332
	/** Implements anything the UDC (PSL) might require following bus Reset signalling.
williamr@4
  1333
williamr@4
  1334
		This function gets called by the PIL after it has been notified (by the PSL) about the Reset event.
williamr@4
  1335
williamr@4
  1336
		@publishedPartner @released
williamr@4
  1337
	*/
williamr@4
  1338
	virtual void Reset() =0;
williamr@4
  1339
williamr@4
  1340
	/** Called by the PIL to signal to the PSL that it has finished processing a received Setup packet (on
williamr@4
  1341
		Ep0) and that the PSL can now prepare itself for the next Ep0 reception (for instance by re-enabling
williamr@4
  1342
		the Ep0 interrupt).
williamr@4
  1343
williamr@4
  1344
		The reason for having this function is the situation where no Ep0 read has been set up by the user and
williamr@4
  1345
		thus a received Setup packet cannot immediately be delivered to the user. Once the user however sets
williamr@4
  1346
		up an Ep0 read, the PIL completes the request and eventually calls this function. This way we can
williamr@4
  1347
		implement some sort of flow-control.
williamr@4
  1348
williamr@4
  1349
		@publishedPartner @released
williamr@4
  1350
	*/
williamr@4
  1351
	virtual void Ep0ReadSetupPktProceed() =0;
williamr@4
  1352
williamr@4
  1353
	/** Called by the PIL to signal to the PSL that it has finished processing a received Ep0 data packet and
williamr@4
  1354
		that the PSL can now prepare itself for the next Ep0 reception (for instance by re-enabling the Ep0
williamr@4
  1355
		interrupt).
williamr@4
  1356
williamr@4
  1357
		The reason for having this function is the situation where no Ep0 read has been set up by the user and
williamr@4
  1358
		thus a received packet cannot immediately be delivered to the user. Once the user however sets up an
williamr@4
  1359
		Ep0 read, the PIL completes the request and eventually calls this function. This way we can implement
williamr@4
  1360
		some sort of flow-control.
williamr@4
  1361
williamr@4
  1362
		@publishedPartner @released
williamr@4
  1363
	*/
williamr@4
  1364
	virtual void Ep0ReceiveProceed() =0;
williamr@4
  1365
williamr@4
  1366
	/** Returns a truth value indicating whether the USB controller hardware (UDC) supports being powered
williamr@4
  1367
		down while (a configuration is) active.
williamr@4
  1368
williamr@4
  1369
		This capability affects the power management strategy used by the USB Manager.
williamr@4
  1370
williamr@4
  1371
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
williamr@4
  1372
		implementation in the PIL - to be on the safe side - returns EFalse.)
williamr@4
  1373
williamr@4
  1374
		@return ETrue if this UDC supports power-down while active, EFalse otherwise.
williamr@4
  1375
williamr@4
  1376
		@publishedPartner @released
williamr@4
  1377
	*/
williamr@4
  1378
	virtual TBool PowerDownWhenActive() const;
williamr@4
  1379
williamr@4
  1380
	/** Powers the UDC down, i.e. puts it into a (hardware-dependent) power-saving mode. Note that this
williamr@4
  1381
		function is not the same as StopUdc(). The difference is that while StopUdc() effectively turns the
williamr@4
  1382
		UDC off and so may invalidate all its settings, after a call to PowerDown() the UDC is expected to
williamr@4
  1383
		return to its previous state when PowerUp() is called. This function is also not the same as
williamr@4
  1384
		Suspend() which gets called by the PIL in response to a Suspend event on the bus, and only then
williamr@4
  1385
		(but apart from that the two functions are very similar).
williamr@4
  1386
williamr@4
  1387
		This function won't be called by the PIL once the UDC is active if PowerDownWhenActive() returns
williamr@4
  1388
		EFalse (which it by default does).
williamr@4
  1389
williamr@4
  1390
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
williamr@4
  1391
		implementation in the PIL does nothing.)
williamr@4
  1392
williamr@4
  1393
		@see PowerUp()
williamr@4
  1394
		@see PowerDownWhenActive()
williamr@4
  1395
williamr@4
  1396
		@return KErrNone if UDC was successfully powered down, KErrGeneral otherwise.
williamr@4
  1397
williamr@4
  1398
		@publishedPartner @released
williamr@4
  1399
	*/
williamr@4
  1400
	virtual TInt PowerDown();
williamr@4
  1401
williamr@4
  1402
	/** Powers the UDC up by exiting a (hardware-dependent) power-saving mode. Note that this function is not
williamr@4
  1403
		the same as StartUdc(). The difference is that while StartUdc() starts the UDC from zero and merely
williamr@4
  1404
		leads to the default state (i.e. not an active configuration), after a call to PowerUp() the UDC is
williamr@4
  1405
		expected to have returned to the state it was in before PowerDown() was called.
williamr@4
  1406
williamr@4
  1407
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs. The default
williamr@4
  1408
		implementation in the PIL does nothing.)
williamr@4
  1409
williamr@4
  1410
		@see PowerDown()
williamr@4
  1411
williamr@4
  1412
		@return KErrNone if UDC was successfully powered up, KErrGeneral otherwise.
williamr@4
  1413
williamr@4
  1414
		@publishedPartner @released
williamr@4
  1415
	*/
williamr@4
  1416
	virtual TInt PowerUp();
williamr@4
  1417
williamr@4
  1418
	/** Puts the controller into a specific test mode (during HS operation only).
williamr@4
  1419
williamr@4
  1420
		9.4.9 Set Feature: "The transition to test mode must be complete no later than 3 ms after the
williamr@4
  1421
		completion of the status stage of the request." (The status stage will have been completed
williamr@4
  1422
		immediately before this function gets called.)
williamr@4
  1423
williamr@4
  1424
		(Function is not 'pure virtual' for backwards compatibility with existing USB PSLs.
williamr@4
  1425
		 The default implementation in the PIL returns KErrNotSupported.)
williamr@4
  1426
williamr@4
  1427
		@param aTestSelector The specific test mode selector (@see usb.h).
williamr@4
  1428
williamr@4
  1429
		@return KErrNone if the specified test mode was entered successfully,
williamr@4
  1430
		KErrGeneral otherwise.
williamr@4
  1431
williamr@4
  1432
		@publishedPartner @released
williamr@4
  1433
	*/
williamr@4
  1434
	virtual TInt EnterTestMode(TInt aTestSelector);
williamr@4
  1435
williamr@4
  1436
	/** Turn on USB client functionality in an OTG/Host setup.
williamr@4
  1437
williamr@4
  1438
		This PSL function is called by the PIL when the OTG stack calls the PIL
williamr@4
  1439
		function EnableClientStack(). Immediately afterwards the PIL may
williamr@4
  1440
		connect the B-device to the bus (via the OTG stack). OtgEnableUdc() is
williamr@4
  1441
		called always after StartUdc().
williamr@4
  1442
williamr@4
  1443
		There is no equivalent to this function in the non-OTG version of the
williamr@4
  1444
		USB PDD.
williamr@4
  1445
williamr@4
  1446
		@return KErrNone if UDC successfully enabled, KErrGeneral otherwise.
williamr@4
  1447
williamr@4
  1448
		@publishedPartner @released
williamr@4
  1449
	*/
williamr@4
  1450
	virtual TInt OtgEnableUdc();
williamr@4
  1451
williamr@4
  1452
	/** Turn off USB client functionality in an OTG/Host setup.
williamr@4
  1453
williamr@4
  1454
		This function is called by the PIL when the OTG stack calls the PIL
williamr@4
  1455
		function DisableClientStack(); the PIL will do this immediately after
williamr@4
  1456
		it has disconnected the B-device from the bus (via the OTG stack) and
williamr@4
  1457
		before calling StopUdc().
williamr@4
  1458
williamr@4
  1459
		There is no equivalent to this function in the non-OTG version of the
williamr@4
  1460
		USB PDD.
williamr@4
  1461
williamr@4
  1462
		@return KErrNone if UDC successfully disabled, KErrGeneral otherwise.
williamr@4
  1463
williamr@4
  1464
		@publishedPartner @released
williamr@4
  1465
	*/
williamr@4
  1466
	virtual TInt OtgDisableUdc();
williamr@4
  1467
williamr@4
  1468
private:
williamr@4
  1469
williamr@4
  1470
	//
williamr@4
  1471
	// --- Private member functions (used by PIL) ---
williamr@4
  1472
	//
williamr@4
  1473
williamr@4
  1474
	TInt DeRegisterClientCallback(const DBase* aClientId);
williamr@4
  1475
	TBool CheckEpAvailability(TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData, TInt aIfcNumber)
williamr@4
  1476
		const;
williamr@4
  1477
	TUsbcInterface* CreateInterface(const DBase* aClientId, TInt aIfc, TUint32 aFeatureWord);
williamr@4
  1478
	TInt CreateEndpoints(TUsbcInterface* aIfc, TInt aEndpointsUsed, const TUsbcEndpointInfoArray& aEndpointData,
williamr@4
  1479
						 TInt *aRealEpNumbers);
williamr@4
  1480
	TInt SetupIfcDescriptor(TUsbcInterface* aIfc, TUsbcClassInfo& aClass, DThread* aThread, TDesC8* aString,
williamr@4
  1481
							const TUsbcEndpointInfoArray& aEndpointData);
williamr@4
  1482
	TInt ClientId2InterfaceNumber(const DBase* aClientId) const;
williamr@4
  1483
	TUsbcInterfaceSet* ClientId2InterfacePointer(const DBase* aClientId) const;
williamr@4
  1484
	const DBase* InterfaceNumber2ClientId(TInt aIfcSet) const;
williamr@4
  1485
	TUsbcInterfaceSet* InterfaceNumber2InterfacePointer(TInt aIfcSet) const;
williamr@4
  1486
	inline const DBase* PEndpoint2ClientId(TInt aRealEndpoint) const;
williamr@4
  1487
	inline TInt PEndpoint2LEndpoint(TInt aRealEndpoint) const;
williamr@4
  1488
	TInt ActivateHardwareController();
williamr@4
  1489
	void DeActivateHardwareController();
williamr@4
  1490
	void DeleteInterfaceSet(TInt aIfcSet);
williamr@4
  1491
	void DeleteInterface(TInt aIfcSet, TInt aIfc);
williamr@4
  1492
	void CancelTransferRequests(TInt aRealEndpoint);
williamr@4
  1493
	void DeleteRequestCallback(const DBase* aClientId, TInt aEndpointNum, TTransferDirection aTransferDir);
williamr@4
  1494
	void DeleteRequestCallbacks(const DBase* aClientId);
williamr@4
  1495
	void StatusNotify(TUsbcDeviceState aState, const DBase* aClientId=NULL);
williamr@4
  1496
	void EpStatusNotify(TInt aRealEndpoint);
williamr@4
  1497
	void OtgFeaturesNotify();
williamr@4
  1498
	void RunClientCallbacks();
williamr@4
  1499
	void ProcessDataTransferDone(TUsbcRequestCallback& aRcb);
williamr@4
  1500
	void NextDeviceState(TUsbcDeviceState aNextState);
williamr@4
  1501
	TInt ProcessSuspendEvent();
williamr@4
  1502
	TInt ProcessSuspendEventProceed();
williamr@4
  1503
	TInt ProcessResumeEvent();
williamr@4
  1504
	TInt ProcessResetEvent(TBool aPslUpcall=ETrue);
williamr@4
  1505
	TInt ProcessCableInsertEvent();
williamr@4
  1506
	TInt ProcessCableRemoveEvent();
williamr@4
  1507
	TInt ProcessEp0ReceiveDone(TInt aCount);
williamr@4
  1508
	TInt ProcessEp0TransmitDone(TInt aCount, TInt aError);
williamr@4
  1509
	TInt ProcessEp0SetupReceived(TInt aCount);
williamr@4
  1510
	TInt ProcessEp0DataReceived(TInt aCount);
williamr@4
  1511
	TInt ProcessGetDeviceStatus(const TUsbcSetup& aPacket);
williamr@4
  1512
	TInt ProcessGetInterfaceStatus(const TUsbcSetup& aPacket);
williamr@4
  1513
	TInt ProcessGetEndpointStatus(const TUsbcSetup& aPacket);
williamr@4
  1514
	TInt ProcessSetClearDevFeature(const TUsbcSetup& aPacket);
williamr@4
  1515
	TInt ProcessSetClearIfcFeature(const TUsbcSetup& aPacket);
williamr@4
  1516
	TInt ProcessSetClearEpFeature(const TUsbcSetup& aPacket);
williamr@4
  1517
	TInt ProcessSetAddress(const TUsbcSetup& aPacket);
williamr@4
  1518
	TInt ProcessGetDescriptor(const TUsbcSetup& aPacket);
williamr@4
  1519
	TInt ProcessSetDescriptor(const TUsbcSetup& aPacket);
williamr@4
  1520
	TInt ProcessGetConfiguration(const TUsbcSetup& aPacket);
williamr@4
  1521
	TInt ProcessGetInterface(const TUsbcSetup& aPacket);
williamr@4
  1522
	TInt ProcessSetInterface(const TUsbcSetup& aPacket);
williamr@4
  1523
	TInt ProcessSynchFrame(const TUsbcSetup& aPacket);
williamr@4
  1524
	void ProceedSetDescriptor();
williamr@4
  1525
	void SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest);
williamr@4
  1526
	TInt ClearHaltFeature(TInt aRealEndpoint);
williamr@4
  1527
	void ChangeConfiguration(TUint16 aValue);
williamr@4
  1528
	void InterfaceSetup(TUsbcInterface* aIfc);
williamr@4
  1529
	void InterfaceSetTeardown(TUsbcInterfaceSet* aIfc);
williamr@4
  1530
	void ChangeInterface(TUsbcInterface* aIfc);
williamr@4
  1531
	TInt DoForEveryEndpointInUse(TInt (DUsbClientController::*aFunction)(TInt), TInt& aCount);
williamr@4
  1532
	void EnterFullSpeed();
williamr@4
  1533
	void EnterHighSpeed();
williamr@4
  1534
	TInt EvaluateOtgConnectFlags();
williamr@4
  1535
	inline const TUsbcConfiguration* CurrentConfig() const;
williamr@4
  1536
	inline TUsbcConfiguration* CurrentConfig();
williamr@4
  1537
	inline TBool InterfaceExists(TInt aNumber) const;
williamr@4
  1538
	inline TBool EndpointExists(TUint aAddress) const;
williamr@4
  1539
	inline void Buffer2Setup(const TAny* aBuf, TUsbcSetup& aSetup) const;
williamr@4
  1540
	inline TUint EpIdx2Addr(TUint aRealEndpoint) const;
williamr@4
  1541
	inline TUint EpAddr2Idx(TUint aAddress) const;
williamr@4
  1542
	inline void SetEp0DataOutVars(const TUsbcSetup& aPacket, const DBase* aClientId = NULL);
williamr@4
  1543
	inline void ResetEp0DataOutVars();
williamr@4
  1544
	inline TBool IsInTheStatusList(const TUsbcStatusCallback& aCallback);
williamr@4
  1545
	inline TBool IsInTheEpStatusList(const TUsbcEndpointStatusCallback& aCallback);
williamr@4
  1546
	inline TBool IsInTheOtgFeatureList(const TUsbcOtgFeatureCallback& aCallback);
williamr@4
  1547
	inline TBool IsInTheRequestList(const TUsbcRequestCallback& aCallback);
williamr@4
  1548
	static void ReconnectTimerCallback(TAny* aPtr);
williamr@4
  1549
	static void CableStatusTimerCallback(TAny* aPtr);
williamr@4
  1550
	static void PowerUpDfc(TAny* aPtr);
williamr@4
  1551
	static void PowerDownDfc(TAny* aPtr);
williamr@4
  1552
williamr@4
  1553
private:
williamr@4
  1554
williamr@4
  1555
	//
williamr@4
  1556
	// --- Private data members ---
williamr@4
  1557
	//
williamr@4
  1558
williamr@4
  1559
	static DUsbClientController* UsbClientController[KUsbcMaxUdcs];
williamr@4
  1560
williamr@4
  1561
	TInt iDeviceTotalEndpoints;								// number of endpoints reported by PSL
williamr@4
  1562
	TInt iDeviceUsableEndpoints;							// number of endpoints reported to LDD
williamr@4
  1563
	TUsbcDeviceState iDeviceState;							// states as of USB spec chapter 9.1
williamr@4
  1564
	TUsbcDeviceState iDeviceStateB4Suspend;					// state before entering suspend state
williamr@4
  1565
	TBool iSelfPowered;										// true if device is capable of beeing self-powered
williamr@4
  1566
	TBool iRemoteWakeup;									// true if device is capable of signalling rmwakeup
williamr@4
  1567
	TBool iTrackDeviceState;								// true if we should track the device state in s/w
williamr@4
  1568
	TBool iHardwareActivated;								// true if controller silicon is in operating state
williamr@4
  1569
	TBool iOtgSupport;										// true if OTG is supported by this device
williamr@4
  1570
	TBool iOtgHnpHandledByHw;								// true if HNP dis/connect is handled by hardware
williamr@4
  1571
	TUint8 iOtgFuncMap;										// bitmap indicating OTG extension features
williamr@4
  1572
	TBool iHighSpeed;										// true if currently operating at high-speed
williamr@4
  1573
	TUsbcSetup iSetup;										// storage for a setup packet during its DATA_OUT
williamr@4
  1574
	TInt iEp0MaxPacketSize;									// currently configured max packet size for Ep0
williamr@4
  1575
	const DBase* iEp0ClientId;								// see comment at the begin of ps_usbc.cpp
williamr@4
  1576
	TUint16 iEp0DataReceived;								// indicates how many bytes have already been received
williamr@4
  1577
	TBool iEp0DataReceiving;								// true if ep0's in DATA_OUT stage
williamr@4
  1578
	TBool iEp0WritePending;									// true if a write on ep0 has been set up
williamr@4
  1579
	TBool iEp0ClientDataTransmitting;						// true if ep0's in DATA_IN on behalf of a client
williamr@4
  1580
	const DBase* iEp0DeviceControl;							// Device Ep0 requests are delivered to this LDD
williamr@4
  1581
	TUsbcDescriptorPool iDescriptors;						// the descriptors as of USB spec chapter 9.5
williamr@4
  1582
	TUint8 iCurrentConfig;									// bConfigurationValue of current Config (1-based!)
williamr@4
  1583
	RPointerArray<TUsbcConfiguration> iConfigs;				// the root of the modelled USB device
williamr@4
  1584
	TUsbcPhysicalEndpoint iRealEndpoints[KUsbcEpArraySize]; // array will be filled once at startup
williamr@4
  1585
	TUint8 iEp0_TxBuf[KUsbcBufSz_Ep0Tx];					// ep0 outgoing (tx) data is placed here
williamr@4
  1586
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
williamr@4
  1587
	TUint8 iEp0_RxCollectionBuf[KUsbcBufSz_Ep0Rx];			// used for (optional) SET_DESCRIPTOR request
williamr@4
  1588
#endif
williamr@4
  1589
	TInt iEp0_RxExtraCount;									// number of bytes received but not yet delivered
williamr@4
  1590
	TBool iEp0_RxExtraData;									// true if iEp0_RxExtraCount is valid
williamr@4
  1591
	TInt iEp0_TxNonStdCount;								// number of bytes requested by non-std Ep0 request
williamr@4
  1592
	TUsbcRequestCallback* iRequestCallbacks[KUsbcEpArraySize]; // xfer requests; indexed by real ep number
williamr@4
  1593
	TSglQue<TUsbcRequestCallback> iEp0ReadRequestCallbacks;	// list of ep0 read requests
williamr@4
  1594
	TSglQue<TUsbcClientCallback> iClientCallbacks;          // registered LDD clients and their callback functions
williamr@4
  1595
	TSglQue<TUsbcStatusCallback> iStatusCallbacks;			// list of device state notification requests
williamr@4
  1596
	TSglQue<TUsbcEndpointStatusCallback> iEpStatusCallbacks; // list of endpoint state notification requests
williamr@4
  1597
	TSglQue<TUsbcOtgFeatureCallback> iOtgCallbacks;		    // list of OTG feature change requests
williamr@4
  1598
	NTimer iReconnectTimer;									// implements USB re-enumeration delay
williamr@4
  1599
	NTimer iCableStatusTimer;								// implements USB cable status detection delay
williamr@4
  1600
	DUsbcPowerHandler* iPowerHandler;						// pointer to USB power handler object
williamr@4
  1601
	TSpinLock iUsbLock;                                     // implement SMP for USB PDD and LDD
williamr@4
  1602
williamr@4
  1603
protected:
williamr@4
  1604
	TDfc iPowerUpDfc;										// queued by power handler upon power-up
williamr@4
  1605
	TDfc iPowerDownDfc;										// queued by power handler upon power-down
williamr@4
  1606
williamr@4
  1607
private:
williamr@4
  1608
	TBool iStandby;											// toggled by power handler as appropriate
williamr@4
  1609
	TBool iStackIsActive;									// client stack's function is usable
williamr@4
  1610
	TBool iOtgClientConnect;								// OTG stack wishes to connect to the host
williamr@4
  1611
	TBool iClientSupportReady;								// user-side USB Client support is loaded & active
williamr@4
  1612
	TBool iDPlusEnabled;									// set if both sides agree and DPLUS is asserted
williamr@4
  1613
	TBool iUsbResetDeferred;								// set when user-side wasn't ready yet
williamr@4
  1614
williamr@4
  1615
public:
williamr@4
  1616
	TInt (*iEnablePullUpOnDPlus)(TAny* aOtgContext);		// these are to be filled in by the Host component
williamr@4
  1617
	TInt (*iDisablePullUpOnDPlus)(TAny* aOtgContext);		// in an OTG setup (otherwise unused)
williamr@4
  1618
	TAny* iOtgContext;										// to be passed into the above 2 functions
williamr@4
  1619
	};
williamr@4
  1620
williamr@4
  1621
williamr@4
  1622
/** Simple queue of status changes to be recorded.
williamr@4
  1623
	Items are fetched by userside when able.
williamr@4
  1624
*/
williamr@4
  1625
class TUsbcDeviceStatusQueue
williamr@4
  1626
	{
williamr@4
  1627
public:
williamr@4
  1628
	TUsbcDeviceStatusQueue();
williamr@4
  1629
	void AddStatusToQueue(TUint32 aDeviceStatus);
williamr@4
  1630
	TInt GetDeviceQueuedStatus(TUint32& aDeviceStatus);
williamr@4
  1631
	void FlushQueue();
williamr@4
  1632
williamr@4
  1633
private:
williamr@4
  1634
	TUint32 iDeviceStatusQueue[KUsbDeviceStatusQueueDepth];
williamr@4
  1635
	TInt iStatusQueueHead;
williamr@4
  1636
	};
williamr@4
  1637
williamr@4
  1638
#include <drivers/usbcshared.inl>
williamr@4
  1639
williamr@4
  1640
#endif	// __USBCSHARED_H__
williamr@4
  1641
williamr@4
  1642
williamr@4
  1643
williamr@4
  1644
williamr@4
  1645
williamr@4
  1646
williamr@4
  1647
williamr@4
  1648
williamr@4
  1649
williamr@4
  1650
williamr@4
  1651
williamr@4
  1652
williamr@4
  1653
williamr@4
  1654
williamr@4
  1655
williamr@4
  1656
williamr@4
  1657
williamr@4
  1658