usbdrv/peripheral/public/d32usbcshared.h
branchRCL_3
changeset 15 f92a4f87e424
equal deleted inserted replaced
14:d3e8e7d462dd 15:f92a4f87e424
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32/include/d32usbcshared.h
       
    15 // User side class definitions for USB Device support.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file d32usbcshared.h
       
    21  @publishedPartner
       
    22  @released
       
    23 */
       
    24 
       
    25 #ifndef __D32USBCSHARED_H__
       
    26 #define __D32USBCSHARED_H__
       
    27 
       
    28 #include <usb/usb_peripheral_shai_shared.h>
       
    29 
       
    30 // FIXME: for dummy dcd compitible, move this line to usbcshared.h
       
    31 // used by shared chunk version LDD's user app interface
       
    32 typedef TInt TUsbcDeviceState;
       
    33 
       
    34 // USB driver error codes
       
    35 
       
    36 /** USB driver specific error codes start from here
       
    37 */
       
    38 const TInt KErrUsbDriverBase = -6701;
       
    39 
       
    40 /**	Attempt at data transfer, or something interface related,
       
    41 	when neither an Interface has been set up nor Device Control is owned by
       
    42 	the channel
       
    43 */
       
    44 const TInt KErrUsbInterfaceNotReady = -6702;
       
    45 
       
    46 /**	Attempt at data transfer on an endpoint that does not belong to the active interface
       
    47 */
       
    48 const TInt KErrUsbEpNotInInterface = -6703;
       
    49 
       
    50 /**	Attempt at data transfer in a direction not supported by the endpoint
       
    51 */
       
    52 const TInt KErrUsbEpBadDirection = -6704;
       
    53 
       
    54 /**	The data transfer size specified exceeds that of the source or
       
    55 	destination buffer descriptor
       
    56 */
       
    57 const TInt KErrUsbTransferSize = -6705;
       
    58 
       
    59 /**	This has multiple uses:
       
    60 	1) User request completed because device is no longer in configured state
       
    61 	2) Something endpoint related, stall, unstall, status enquiry etc,
       
    62 	   that requires the device to be configured
       
    63 */
       
    64 const TInt KErrUsbDeviceNotConfigured = -6706;
       
    65 
       
    66 /**	Requested endpoint properties inconsistent during Interface setup
       
    67 */
       
    68 const TInt KErrUsbBadEndpoint = -6707;
       
    69 
       
    70 /**	User data request completed because channel is closing (channel destructor called)
       
    71 */
       
    72 const TInt KErrUsbDeviceClosing = -6708;
       
    73 
       
    74 /**	User data request completed because current endpoint set is being
       
    75 	replaced since alternate setting is changing
       
    76 */
       
    77 const TInt KErrUsbInterfaceChange = -6709;
       
    78 
       
    79 /**	User data request completed because cable has been detached (or equivalent)
       
    80 */
       
    81 const TInt KErrUsbCableDetached = -6710;
       
    82 
       
    83 /**	User data request completed because cable has been detached (or equivalent)
       
    84 */
       
    85 const TInt KErrUsbDeviceBusReset = -6711;
       
    86 
       
    87 /**	This means that read data is still available when a write request is made.
       
    88 	Relates to bidirectional eps only (ep0).
       
    89 	A bidirectional ep must consume all of its read data before attempting to write.
       
    90 */
       
    91 const TInt KErrUsbEpNotReady = -6712;
       
    92 
       
    93 // FIXME: REMOVE THIS GUY, ONCE DUMMY DCD is modified according to new SHAI.
       
    94 const TInt EUsbcDeviceStateUndefined = UsbShai::EUsbPeripheralStateUndefined; // 0
       
    95 const TInt EUsbcDeviceStateAttached = UsbShai::EUsbPeripheralStateAttached; // 1
       
    96 const TInt EUsbcDeviceStatePowered = UsbShai::EUsbPeripheralStatePowered;// 2
       
    97 const TInt EUsbcDeviceStateDefault = UsbShai::EUsbPeripheralStateDefault;// 3
       
    98 const TInt EUsbcDeviceStateAddress = UsbShai::EUsbPeripheralStateAddress; // 4
       
    99 const TInt EUsbcDeviceStateConfigured = UsbShai::EUsbPeripheralStateConfigured;// 5
       
   100 const TInt EUsbcDeviceStateSuspended = UsbShai::EUsbPeripheralStateSuspended;// 6
       
   101 const TInt EUsbcNoState = UsbShai::EUsbPeripheralNoState; // 255 (used as a place holder)
       
   102 
       
   103 /** The endpoint states.
       
   104 
       
   105 	@see RDevUsbcClient::EndpointStatus()
       
   106 	@see RDevUsbcClient::EndpointStatusNotify()
       
   107 */
       
   108 enum TEndpointState
       
   109 	{
       
   110 	EEndpointStateNotStalled,
       
   111 	EEndpointStateStalled,
       
   112 	EEndpointStateUnknown
       
   113 	};
       
   114 
       
   115 class TUsbcEndpointCaps : public UsbShai::TUsbPeripheralEndpointCaps
       
   116     {
       
   117     public:
       
   118 	/** Returns the greatest available packet size for this endpoint. */
       
   119 	TInt MaxPacketSize() const;
       
   120 	/** Returns the smallest available packet size for this endpoint. */
       
   121 	TInt MinPacketSize() const;    
       
   122     };
       
   123 
       
   124 /** Endpoint resources/behaviours.
       
   125 
       
   126 	@see AllocateEndpointResource()
       
   127 	@see DeAllocateEndpointResource()
       
   128 	@see QueryEndpointResourceUse()
       
   129 */
       
   130 enum TUsbcEndpointResource
       
   131 	{
       
   132 	/** Requests the use of DMA. */
       
   133 	EUsbcEndpointResourceDMA = 0,
       
   134 	/** Requests the use of double FIFO buffering. */
       
   135 	EUsbcEndpointResourceDoubleBuffering = 1
       
   136 	};
       
   137 
       
   138 const TUint KUsbcEndpointInfoFeatureWord1_DMA = UsbShai::KUsbEndpointInfoFeatureWord1_DMA;
       
   139 const TUint KUsbcEndpointInfoFeatureWord1_DoubleBuffering = UsbShai::KUsbEndpointInfoFeatureWord1_DoubleBuffering;
       
   140     
       
   141 /** The USB client device capability class.
       
   142 */
       
   143 class TCapsDevUsbc
       
   144 	{
       
   145     public:
       
   146 	/** The device version. */
       
   147 	TVersion version;
       
   148 	};
       
   149 
       
   150 /** The maximum number of endpoints supported by the device, excluding ep0.
       
   151 */
       
   152 const TInt KUsbcMaxEndpoints = 30;
       
   153 
       
   154 /** The maximum number of endpoints per interface, excluding ep0.
       
   155 */
       
   156 const TInt KMaxEndpointsPerClient = 5;
       
   157 
       
   158 /** @internalComponent
       
   159 */
       
   160 const TInt KInvalidEndpointNumber = 31;
       
   161 
       
   162 /** The alternate setting flag; when this bit is set the state change notified by
       
   163 	RDevUsbcClient::AlternateDeviceStatusNotify() is an alternate setting number.
       
   164 */
       
   165 const TUint KUsbAlternateSetting = 0x80000000;
       
   166 
       
   167 /** The USB cable detection feature flag; used by TUsbDeviceCapsV01::iFeatureWord1.
       
   168 	When this bit is set then the USB controller hardware (UDC) supports detection
       
   169 	of a plugged-in USB cable even when not powered.
       
   170 
       
   171 	@see TUsbDeviceCapsV01
       
   172 */
       
   173 const TUint KUsbDevCapsFeatureWord1_CableDetectWithoutPower = 0x00000001;
       
   174 
       
   175 /** If this flag is set then the driver supports the new endpoint resource
       
   176 	allocation scheme for DMA and Double-buffering via
       
   177 	TUsbcEndpointInfo::iFeatureWord1.
       
   178 
       
   179 	@see TUsbDeviceCapsV01
       
   180 */
       
   181 const TUint KUsbDevCapsFeatureWord1_EndpointResourceAllocV2 = 0x00000002;
       
   182 
       
   183 
       
   184 /** Device USB capabilities.
       
   185 */
       
   186 class TUsbDeviceCapsV01
       
   187 	{
       
   188 public:
       
   189 	/** The total number of endpoints on the device. */
       
   190 	TInt iTotalEndpoints;
       
   191 	/** Indicates whether the device supports software connect/disconnect. */
       
   192 	TBool iConnect;
       
   193 	/** Indicates whether the device is self powered. */
       
   194 	TBool iSelfPowered;
       
   195 	/** Indicates whether the device can send Remote Wakeup. */
       
   196 	TBool iRemoteWakeup;
       
   197 	/** Indicates whether the device supports High-speed mode. */
       
   198 	TBool iHighSpeed;
       
   199 	/** 32 flag bits indicating miscellaneous UDC/device features.
       
   200 		Currently defined are:
       
   201 		- KUsbDevCapsFeatureWord1_CableDetectWithoutPower = 0x00000001
       
   202 		- KUsbDevCapsFeatureWord1_EndpointResourceAllocV2 = 0x00000002
       
   203 	*/
       
   204 	TUint32 iFeatureWord1;
       
   205 	/** Reserved for future use. */
       
   206 	TUint32 iReserved;
       
   207 	};
       
   208 
       
   209 /** Package buffer for a TUsbDeviceCapsV01 object.
       
   210 
       
   211 	@see TUsbDeviceCapsV01
       
   212 */
       
   213 typedef TPckgBuf<TUsbDeviceCapsV01> TUsbDeviceCaps;
       
   214 
       
   215 /** Bitmaps for TUsbcEndpointCaps.iSizes.
       
   216 
       
   217 	This endpoint is not available (= no size).
       
   218 */
       
   219 const TUint KUsbEpNotAvailable = 0x00000000;
       
   220 /**	Max packet size is continuously variable up to some size specified.
       
   221 	(Interrupt and Isochronous endpoints only.)
       
   222 */
       
   223 const TUint KUsbEpSizeCont     = 0x00000001;
       
   224 /** Max packet size 8 bytes is supported
       
   225 */
       
   226 const TUint KUsbEpSize8        = 0x00000008;
       
   227 /** Max packet size 16 bytes is supported
       
   228 */
       
   229 const TUint KUsbEpSize16       = 0x00000010;
       
   230 /** Max packet size 32 bytes is supported
       
   231 */
       
   232 const TUint KUsbEpSize32       = 0x00000020;
       
   233 /** Max packet size 64 bytes is supported
       
   234 */
       
   235 const TUint KUsbEpSize64       = 0x00000040;
       
   236 /** Max packet size 128 bytes is supported
       
   237 */
       
   238 const TUint KUsbEpSize128      = 0x00000080;
       
   239 /** Max packet size 256 bytes is supported
       
   240 */
       
   241 const TUint KUsbEpSize256      = 0x00000100;
       
   242 /** Max packet size 512 bytes is supported
       
   243 */
       
   244 const TUint KUsbEpSize512      = 0x00000200;
       
   245 /** Max packet size 1023 bytes is supported
       
   246 */
       
   247 const TUint KUsbEpSize1023     = 0x00000400;
       
   248 /** Max packet size 1024 bytes is supported
       
   249 */
       
   250 const TUint KUsbEpSize1024     = 0x00000800;
       
   251 
       
   252 /** Bitmaps for TUsbcEndpointCaps.iSupportedTypesAndDir.
       
   253 
       
   254 	Endpoint supports Control transfer type.
       
   255 */
       
   256 const TUint KUsbEpTypeControl     = UsbShai::KUsbEpTypeControl;
       
   257 /** Endpoint supports Isochronous transfer type.
       
   258 */
       
   259 const TUint KUsbEpTypeIsochronous = UsbShai::KUsbEpTypeIsochronous;
       
   260 /** Endpoint supports Bulk transfer type.
       
   261 */
       
   262 const TUint KUsbEpTypeBulk        = UsbShai::KUsbEpTypeBulk;
       
   263 /** Endpoint supports Interrupt transfer type.
       
   264 */
       
   265 const TUint KUsbEpTypeInterrupt   = UsbShai::KUsbEpTypeInterrupt;
       
   266 /** Endpoint supports IN transfers.
       
   267 */
       
   268 const TUint KUsbEpDirIn           = UsbShai::KUsbEpDirIn;
       
   269 /** Endpoint supports OUT transfers.
       
   270 */
       
   271 const TUint KUsbEpDirOut          = UsbShai::KUsbEpDirOut;
       
   272 /** Endpoint supports bidirectional (Control) transfers only.
       
   273 */
       
   274 const TUint KUsbEpDirBidirect     = UsbShai::KUsbEpDirBidirect;
       
   275 
       
   276 
       
   277 /** Converts an absolute size value into a KUsbEpSize... mask.
       
   278 */
       
   279 static inline TUint PacketSize2Mask(TInt aSize);
       
   280 
       
   281 /** Converts an endpoint type mask KUsbEpType...  into an endpoint attribute
       
   282 	value KUsbEpAttr_....
       
   283 */
       
   284 static inline TUint EpTypeMask2Value(TInt aType);
       
   285 
       
   286 
       
   287 /** Endpoint capabilities as returned by RDevUsbcClient::EndpointCaps().
       
   288 */
       
   289 class TUsbcEndpointData
       
   290 	{
       
   291 public:
       
   292 	/** Detail of endpoint capabilities. */
       
   293 	TUsbcEndpointCaps iCaps;
       
   294 	/** Indicates whether this endpoint is already claimed. */
       
   295 	TBool iInUse;
       
   296 	};
       
   297 
       
   298 class TUsbcEndpointInfo : public UsbShai::TUsbPeripheralEndpointInfo 
       
   299     {
       
   300     public:
       
   301 	TUsbcEndpointInfo(TUint aType=UsbShai::KUsbEpTypeBulk, TUint aDir=UsbShai::KUsbEpDirOut,
       
   302 					  TInt aSize=0, TInt aInterval=0, TInt aExtra=0);
       
   303 	
       
   304 	TInt AdjustEpSizes(TInt& aEpSize_Fs, TInt& aEpSize_Hs) const;
       
   305 	
       
   306     TInt AdjustPollInterval();
       
   307     };
       
   308     
       
   309 /** USB Class information used in RDevUsbcClient::SetInterface().
       
   310 */
       
   311 class TUsbcClassInfo
       
   312 	{
       
   313 public:
       
   314 	TUsbcClassInfo(TInt aClass=0, TInt aSubClass=0, TInt aProtocol=0);
       
   315 public:
       
   316 	/** The class type number. */
       
   317 	TInt iClassNum;
       
   318 	/** The sub-class type number. */
       
   319 	TInt iSubClassNum;
       
   320 	/** The protocol number. */
       
   321 	TInt iProtocolNum;
       
   322 	/** Reserved for future use. */
       
   323 	TUint32 iReserved;
       
   324 	};
       
   325 
       
   326 
       
   327 /** The Ep0 Setup request 'unsubscribe' flag; used by
       
   328 	TUsbcInterfaceInfo::iFeatureWord. When this bit is set then valid vendor-
       
   329 	or class-specific Ep0 requests addressed to this interface or any of its
       
   330 	endpoints will be stalled by the USB PDD PIL.
       
   331 
       
   332 	@see TUsbcInterfaceInfo
       
   333 */
       
   334 const TUint KUsbcInterfaceInfo_NoEp0RequestsPlease = 0x00000001;
       
   335 
       
   336 #include <usb/d32usbcshared.inl>
       
   337 
       
   338 #endif