1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/include/usb.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,246 @@
1.4 +// Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\include\usb.h
1.18 +// Definitions of USB-specific constants and macros.
1.19 +//
1.20 +//
1.21 +
1.22 +/**
1.23 + @file usb.h
1.24 + @publishedPartner
1.25 + @released
1.26 +*/
1.27 +
1.28 +#ifndef __USB_H__
1.29 +#define __USB_H__
1.30 +
1.31 +//
1.32 +// 'Chapter 9' Request Types (bmRequestType)
1.33 +//
1.34 +const TUint8 KUsbRequestType_DirShift = 7;
1.35 +const TUint8 KUsbRequestType_DirMask = (1 << KUsbRequestType_DirShift);
1.36 +
1.37 +const TUint8 KUsbRequestType_DirToDev = (0 << KUsbRequestType_DirShift);
1.38 +const TUint8 KUsbRequestType_DirToHost = (1 << KUsbRequestType_DirShift);
1.39 +
1.40 +const TUint8 KUsbRequestType_TypeShift = 5;
1.41 +const TUint8 KUsbRequestType_TypeMask = (3 << KUsbRequestType_TypeShift);
1.42 +const TUint8 KUsbRequestType_TypeStd = (0 << KUsbRequestType_TypeShift);
1.43 +const TUint8 KUsbRequestType_TypeClass = (1 << KUsbRequestType_TypeShift);
1.44 +const TUint8 KUsbRequestType_TypeVendor = (2 << KUsbRequestType_TypeShift);
1.45 +
1.46 +const TUint8 KUsbRequestType_DestShift = 0;
1.47 +const TUint8 KUsbRequestType_DestMask = (0x1f << KUsbRequestType_DestShift);
1.48 +const TUint8 KUsbRequestType_DestDevice = (0x00 << KUsbRequestType_DestShift);
1.49 +const TUint8 KUsbRequestType_DestIfc = (0x01 << KUsbRequestType_DestShift);
1.50 +const TUint8 KUsbRequestType_DestEp = (0x02 << KUsbRequestType_DestShift);
1.51 +const TUint8 KUsbRequestType_DestOther = (0x03 << KUsbRequestType_DestShift);
1.52 +
1.53 +//
1.54 +// 'Chapter 9' Endpoint Zero Requests (bRequest)
1.55 +//
1.56 +const TUint8 KUsbRequest_GetStatus = 0;
1.57 +const TUint8 KUsbRequest_ClearFeature = 1;
1.58 +const TUint8 KUsbRequest_SetFeature = 3;
1.59 +const TUint8 KUsbRequest_SetAddress = 5;
1.60 +const TUint8 KUsbRequest_GetDescriptor = 6;
1.61 +const TUint8 KUsbRequest_SetDescriptor = 7;
1.62 +const TUint8 KUsbRequest_GetConfig = 8;
1.63 +const TUint8 KUsbRequest_SetConfig = 9;
1.64 +const TUint8 KUsbRequest_GetInterface = 10;
1.65 +const TUint8 KUsbRequest_SetInterface = 11;
1.66 +const TUint8 KUsbRequest_SynchFrame = 12;
1.67 +
1.68 +//
1.69 +// Descriptor Types
1.70 +//
1.71 +const TUint8 KUsbDescType_Device = 1;
1.72 +const TUint8 KUsbDescType_Config = 2;
1.73 +const TUint8 KUsbDescType_String = 3;
1.74 +const TUint8 KUsbDescType_Interface = 4;
1.75 +const TUint8 KUsbDescType_Endpoint = 5;
1.76 +const TUint8 KUsbDescType_DeviceQualifier = 6;
1.77 +const TUint8 KUsbDescType_OtherSpeedConfig = 7;
1.78 +const TUint8 KUsbDescType_InterfacePower = 8;
1.79 +const TUint8 KUsbDescType_Otg = 9;
1.80 +const TUint8 KUsbDescType_Debug = 10;
1.81 +const TUint8 KUsbDescType_InterfaceAssociation = 11;
1.82 +
1.83 +//
1.84 +// Descriptor Sizes
1.85 +//
1.86 +const TUint KUsbDescSize_Device = 18;
1.87 +const TUint KUsbDescSize_Config = 9;
1.88 +const TUint KUsbDescSize_Interface = 9;
1.89 +const TUint KUsbDescSize_Endpoint = 7;
1.90 +const TUint KUsbDescSize_Otg = 3;
1.91 +const TUint KUsbDescSize_DeviceQualifier = 10;
1.92 +const TUint KUsbDescSize_OtherSpeedConfig = 9;
1.93 +const TUint KUsbDescSize_InterfaceAssociation = 8;
1.94 +const TUint KUsbDescMaxSize_String = 255;
1.95 +const TUint KUsbStringDescStringMaxSize = 252; // it's actually 253, but that's awkward
1.96 +
1.97 +//
1.98 +// Configuration Characteristics (Configuration Descriptor)
1.99 +//
1.100 +const TUint8 KUsbDevAttr_SelfPowered = (0x01 << 6);
1.101 +const TUint8 KUsbDevAttr_RemoteWakeup = (0x01 << 5);
1.102 +
1.103 +//
1.104 +// Descriptor Indices for String Descriptors
1.105 +//
1.106 +const TUint KUsbDescStringIndex_Manufact = 14;
1.107 +const TUint KUsbDescStringIndex_Product = 15;
1.108 +const TUint KUsbDescStringIndex_Serial = 16;
1.109 +const TUint KUsbDescStringIndex_Config = 6;
1.110 +
1.111 +//
1.112 +// Endpoint Attributes
1.113 +//
1.114 +const TUint8 KUsbEpAttr_TransferTypeShift = 0;
1.115 +const TUint8 KUsbEpAttr_TransferTypeMask = (0x03 << KUsbEpAttr_TransferTypeShift);
1.116 +const TUint8 KUsbEpAttr_TransferTypeControl = (0x00 << KUsbEpAttr_TransferTypeShift);
1.117 +const TUint8 KUsbEpAttr_TransferTypeIsochronous = (0x01 << KUsbEpAttr_TransferTypeShift);
1.118 +const TUint8 KUsbEpAttr_TransferTypeBulk = (0x02 << KUsbEpAttr_TransferTypeShift);
1.119 +const TUint8 KUsbEpAttr_TransferTypeInterrupt = (0x03 << KUsbEpAttr_TransferTypeShift);
1.120 +
1.121 +const TUint8 KUsbEpAttr_SyncTypeShift = 2;
1.122 +const TUint8 KUsbEpAttr_SyncTypeMask = (0x03 << KUsbEpAttr_SyncTypeShift);
1.123 +const TUint8 KUsbEpAttr_SyncTypeNoSync = (0x00 << KUsbEpAttr_SyncTypeShift);
1.124 +const TUint8 KUsbEpAttr_SyncTypeAsync = (0x01 << KUsbEpAttr_SyncTypeShift);
1.125 +const TUint8 KUsbEpAttr_SyncTypeAdaptive = (0x02 << KUsbEpAttr_SyncTypeShift);
1.126 +const TUint8 KUsbEpAttr_SyncTypeSync = (0x03 << KUsbEpAttr_SyncTypeShift);
1.127 +
1.128 +const TUint8 KUsbEpAttr_UsageTypeShift = 4;
1.129 +const TUint8 KUsbEpAttr_UsageTypeMask = (0x03 << KUsbEpAttr_UsageTypeShift);
1.130 +const TUint8 KUsbEpAttr_UsageTypeDataEp = (0x00 << KUsbEpAttr_UsageTypeShift);
1.131 +const TUint8 KUsbEpAttr_UsageTypeFeedbackEp = (0x01 << KUsbEpAttr_UsageTypeShift);
1.132 +const TUint8 KUsbEpAttr_UsageTypeImplFbDataEp = (0x02 << KUsbEpAttr_UsageTypeShift);
1.133 +const TUint8 KUsbEpAttr_UsageTypeReserved = (0x03 << KUsbEpAttr_UsageTypeShift);
1.134 +
1.135 +//
1.136 +// OTG Feature Indicators
1.137 +//
1.138 +const TUint8 KUsbOtgAttr_SrpSupp = 0x01;
1.139 +const TUint8 KUsbOtgAttr_HnpSupp = 0x02;
1.140 +const TUint8 KUsbOtgAttr_B_HnpEnable = 0x04;
1.141 +const TUint8 KUsbOtgAttr_A_HnpSupport = 0x08;
1.142 +const TUint8 KUsbOtgAttr_A_AltHnpSupport = 0x10;
1.143 +
1.144 +//
1.145 +// Feature Settings
1.146 +//
1.147 +const TUint KUsbFeature_EndpointHalt = 0;
1.148 +const TUint KUsbFeature_RemoteWakeup = 1;
1.149 +const TUint KUsbFeature_TestMode = 2;
1.150 +const TUint KUsbFeature_B_HnpEnable = 3;
1.151 +const TUint KUsbFeature_A_HnpSupport = 4;
1.152 +const TUint KUsbFeature_A_AltHnpSupport = 5;
1.153 +
1.154 +//
1.155 +// Test Mode Selectors (Set/ClearFeature)
1.156 +//
1.157 +const TUint KUsbTestSelector_Test_J = 0x01;
1.158 +const TUint KUsbTestSelector_Test_K = 0x02;
1.159 +const TUint KUsbTestSelector_Test_SE0_NAK = 0x03;
1.160 +const TUint KUsbTestSelector_Test_Packet = 0x04;
1.161 +const TUint KUsbTestSelector_Test_Force_Enable = 0x05;
1.162 +
1.163 +//
1.164 +// Address Masks
1.165 +//
1.166 +const TUint8 KUsbEpAddress_In = 0x80;
1.167 +const TUint8 KUsbEpAddress_Portmask = 0x0f;
1.168 +
1.169 +//
1.170 +// Device Status Values (GET_STATUS)
1.171 +//
1.172 +const TUint16 KUsbDevStat_SelfPowered = (1 << 0);
1.173 +const TUint16 KUsbDevStat_RemoteWakeup = (1 << 1);
1.174 +
1.175 +//
1.176 +// Endpoint Status Values (GET_STATUS)
1.177 +//
1.178 +const TUint16 KUsbEpStat_Halt = (1 << 0);
1.179 +
1.180 +
1.181 +//
1.182 +// USB Descriptor Handling
1.183 +//
1.184 +/*------------------------------------------------
1.185 + USB transfers data in little-endian fashion.
1.186 + The following macros swap the byte order in
1.187 + words (16 bit) and longwords (32 bit), such that
1.188 + they are in little-endian order afterwards.
1.189 + ------------------------------------------------*/
1.190 +#if defined(__BIG_ENDIAN__) // Hitachi SuperH, Motorola 68k
1.191 +#define SWAP_BYTES_16(x) \
1.192 + ((((x) >> 8) & 0x00ff) | \
1.193 + (((x) << 8) & 0xff00))
1.194 +#define SWAP_BYTES_32(x) \
1.195 + ((((x) >> 24) & 0x000000ff) | \
1.196 + (((x) >> 8) & 0x0000ff00) | \
1.197 + (((x) << 24) & 0xff000000) | \
1.198 + (((x) << 8) & 0x00ff0000))
1.199 +#else // ARM, Intel
1.200 +#define SWAP_BYTES_16(x) (x)
1.201 +#define SWAP_BYTES_32(x) (x)
1.202 +#endif // defined(__BIG_ENDIAN__)
1.203 +
1.204 +
1.205 +static inline TUint8 LowByte(TUint16 aWord)
1.206 + {
1.207 + return static_cast<TUint8>(aWord & 0x00ff);
1.208 + }
1.209 +
1.210 +static inline TUint8 HighByte(TUint16 aWord)
1.211 + {
1.212 + return static_cast<TUint8>((aWord >> 8) & 0x00ff);
1.213 + }
1.214 +
1.215 +
1.216 +//
1.217 +// Class-specific Values
1.218 +//
1.219 +
1.220 +// These are from the CDC (valid also for Audio Class)
1.221 +const TUint8 KUsbDescType_CS_Interface = 0x24;
1.222 +const TUint8 KUsbDescType_CS_Endpoint = 0x25;
1.223 +
1.224 +// Audio Device Class
1.225 +const TUint KUsbDescSize_AudioEndpoint = KUsbDescSize_Endpoint + 2;
1.226 +const TUint KUsbAudioInterfaceClassCode = 0x01;
1.227 +const TUint KUsbAudioInterfaceSubclassCode_Subclass_Undefined = 0x00;
1.228 +const TUint KUsbAudioInterfaceSubclassCode_Audiocontrol = 0x01;
1.229 +const TUint KUsbAudioInterfaceSubclassCode_Audiostreaming = 0x02;
1.230 +const TUint KUsbAudioInterfaceSubclassCode_Midistreaming = 0x03;
1.231 +const TUint KUsbAudioInterfaceProtocolCode_Pr_Protocol_Undefined = 0x00;
1.232 +
1.233 +
1.234 +//
1.235 +// These are defined just for convenience:
1.236 +//
1.237 +const TUint8 KEp0_Out = 0;
1.238 +const TUint8 KEp0_In = 1;
1.239 +const TUint8 KEp0_Rx = KEp0_Out;
1.240 +const TUint8 KEp0_Tx = KEp0_In;
1.241 +
1.242 +
1.243 +//
1.244 +// USB Implementers Forum, Inc (USB-IF) assigned Vendor IDs:
1.245 +//
1.246 +const TUint16 KUsbVendorId_Symbian = 0x0E22; // Symbian Ltd. (dec. 3618)
1.247 +
1.248 +
1.249 +#endif // __USB_H__