sl@0: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\include\usb.h sl@0: // Definitions of USB-specific constants and macros. sl@0: // sl@0: // sl@0: sl@0: /** sl@0: @file usb.h sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __USB_H__ sl@0: #define __USB_H__ sl@0: sl@0: // sl@0: // 'Chapter 9' Request Types (bmRequestType) sl@0: // sl@0: const TUint8 KUsbRequestType_DirShift = 7; sl@0: const TUint8 KUsbRequestType_DirMask = (1 << KUsbRequestType_DirShift); sl@0: sl@0: const TUint8 KUsbRequestType_DirToDev = (0 << KUsbRequestType_DirShift); sl@0: const TUint8 KUsbRequestType_DirToHost = (1 << KUsbRequestType_DirShift); sl@0: sl@0: const TUint8 KUsbRequestType_TypeShift = 5; sl@0: const TUint8 KUsbRequestType_TypeMask = (3 << KUsbRequestType_TypeShift); sl@0: const TUint8 KUsbRequestType_TypeStd = (0 << KUsbRequestType_TypeShift); sl@0: const TUint8 KUsbRequestType_TypeClass = (1 << KUsbRequestType_TypeShift); sl@0: const TUint8 KUsbRequestType_TypeVendor = (2 << KUsbRequestType_TypeShift); sl@0: sl@0: const TUint8 KUsbRequestType_DestShift = 0; sl@0: const TUint8 KUsbRequestType_DestMask = (0x1f << KUsbRequestType_DestShift); sl@0: const TUint8 KUsbRequestType_DestDevice = (0x00 << KUsbRequestType_DestShift); sl@0: const TUint8 KUsbRequestType_DestIfc = (0x01 << KUsbRequestType_DestShift); sl@0: const TUint8 KUsbRequestType_DestEp = (0x02 << KUsbRequestType_DestShift); sl@0: const TUint8 KUsbRequestType_DestOther = (0x03 << KUsbRequestType_DestShift); sl@0: sl@0: // sl@0: // 'Chapter 9' Endpoint Zero Requests (bRequest) sl@0: // sl@0: const TUint8 KUsbRequest_GetStatus = 0; sl@0: const TUint8 KUsbRequest_ClearFeature = 1; sl@0: const TUint8 KUsbRequest_SetFeature = 3; sl@0: const TUint8 KUsbRequest_SetAddress = 5; sl@0: const TUint8 KUsbRequest_GetDescriptor = 6; sl@0: const TUint8 KUsbRequest_SetDescriptor = 7; sl@0: const TUint8 KUsbRequest_GetConfig = 8; sl@0: const TUint8 KUsbRequest_SetConfig = 9; sl@0: const TUint8 KUsbRequest_GetInterface = 10; sl@0: const TUint8 KUsbRequest_SetInterface = 11; sl@0: const TUint8 KUsbRequest_SynchFrame = 12; sl@0: sl@0: // sl@0: // Descriptor Types sl@0: // sl@0: const TUint8 KUsbDescType_Device = 1; sl@0: const TUint8 KUsbDescType_Config = 2; sl@0: const TUint8 KUsbDescType_String = 3; sl@0: const TUint8 KUsbDescType_Interface = 4; sl@0: const TUint8 KUsbDescType_Endpoint = 5; sl@0: const TUint8 KUsbDescType_DeviceQualifier = 6; sl@0: const TUint8 KUsbDescType_OtherSpeedConfig = 7; sl@0: const TUint8 KUsbDescType_InterfacePower = 8; sl@0: const TUint8 KUsbDescType_Otg = 9; sl@0: const TUint8 KUsbDescType_Debug = 10; sl@0: const TUint8 KUsbDescType_InterfaceAssociation = 11; sl@0: sl@0: // sl@0: // Descriptor Sizes sl@0: // sl@0: const TUint KUsbDescSize_Device = 18; sl@0: const TUint KUsbDescSize_Config = 9; sl@0: const TUint KUsbDescSize_Interface = 9; sl@0: const TUint KUsbDescSize_Endpoint = 7; sl@0: const TUint KUsbDescSize_Otg = 3; sl@0: const TUint KUsbDescSize_DeviceQualifier = 10; sl@0: const TUint KUsbDescSize_OtherSpeedConfig = 9; sl@0: const TUint KUsbDescSize_InterfaceAssociation = 8; sl@0: const TUint KUsbDescMaxSize_String = 255; sl@0: const TUint KUsbStringDescStringMaxSize = 252; // it's actually 253, but that's awkward sl@0: sl@0: // sl@0: // Configuration Characteristics (Configuration Descriptor) sl@0: // sl@0: const TUint8 KUsbDevAttr_SelfPowered = (0x01 << 6); sl@0: const TUint8 KUsbDevAttr_RemoteWakeup = (0x01 << 5); sl@0: sl@0: // sl@0: // Descriptor Indices for String Descriptors sl@0: // sl@0: const TUint KUsbDescStringIndex_Manufact = 14; sl@0: const TUint KUsbDescStringIndex_Product = 15; sl@0: const TUint KUsbDescStringIndex_Serial = 16; sl@0: const TUint KUsbDescStringIndex_Config = 6; sl@0: sl@0: // sl@0: // Endpoint Attributes sl@0: // sl@0: const TUint8 KUsbEpAttr_TransferTypeShift = 0; sl@0: const TUint8 KUsbEpAttr_TransferTypeMask = (0x03 << KUsbEpAttr_TransferTypeShift); sl@0: const TUint8 KUsbEpAttr_TransferTypeControl = (0x00 << KUsbEpAttr_TransferTypeShift); sl@0: const TUint8 KUsbEpAttr_TransferTypeIsochronous = (0x01 << KUsbEpAttr_TransferTypeShift); sl@0: const TUint8 KUsbEpAttr_TransferTypeBulk = (0x02 << KUsbEpAttr_TransferTypeShift); sl@0: const TUint8 KUsbEpAttr_TransferTypeInterrupt = (0x03 << KUsbEpAttr_TransferTypeShift); sl@0: sl@0: const TUint8 KUsbEpAttr_SyncTypeShift = 2; sl@0: const TUint8 KUsbEpAttr_SyncTypeMask = (0x03 << KUsbEpAttr_SyncTypeShift); sl@0: const TUint8 KUsbEpAttr_SyncTypeNoSync = (0x00 << KUsbEpAttr_SyncTypeShift); sl@0: const TUint8 KUsbEpAttr_SyncTypeAsync = (0x01 << KUsbEpAttr_SyncTypeShift); sl@0: const TUint8 KUsbEpAttr_SyncTypeAdaptive = (0x02 << KUsbEpAttr_SyncTypeShift); sl@0: const TUint8 KUsbEpAttr_SyncTypeSync = (0x03 << KUsbEpAttr_SyncTypeShift); sl@0: sl@0: const TUint8 KUsbEpAttr_UsageTypeShift = 4; sl@0: const TUint8 KUsbEpAttr_UsageTypeMask = (0x03 << KUsbEpAttr_UsageTypeShift); sl@0: const TUint8 KUsbEpAttr_UsageTypeDataEp = (0x00 << KUsbEpAttr_UsageTypeShift); sl@0: const TUint8 KUsbEpAttr_UsageTypeFeedbackEp = (0x01 << KUsbEpAttr_UsageTypeShift); sl@0: const TUint8 KUsbEpAttr_UsageTypeImplFbDataEp = (0x02 << KUsbEpAttr_UsageTypeShift); sl@0: const TUint8 KUsbEpAttr_UsageTypeReserved = (0x03 << KUsbEpAttr_UsageTypeShift); sl@0: sl@0: // sl@0: // OTG Feature Indicators sl@0: // sl@0: const TUint8 KUsbOtgAttr_SrpSupp = 0x01; sl@0: const TUint8 KUsbOtgAttr_HnpSupp = 0x02; sl@0: const TUint8 KUsbOtgAttr_B_HnpEnable = 0x04; sl@0: const TUint8 KUsbOtgAttr_A_HnpSupport = 0x08; sl@0: const TUint8 KUsbOtgAttr_A_AltHnpSupport = 0x10; sl@0: sl@0: // sl@0: // Feature Settings sl@0: // sl@0: const TUint KUsbFeature_EndpointHalt = 0; sl@0: const TUint KUsbFeature_RemoteWakeup = 1; sl@0: const TUint KUsbFeature_TestMode = 2; sl@0: const TUint KUsbFeature_B_HnpEnable = 3; sl@0: const TUint KUsbFeature_A_HnpSupport = 4; sl@0: const TUint KUsbFeature_A_AltHnpSupport = 5; sl@0: sl@0: // sl@0: // Test Mode Selectors (Set/ClearFeature) sl@0: // sl@0: const TUint KUsbTestSelector_Test_J = 0x01; sl@0: const TUint KUsbTestSelector_Test_K = 0x02; sl@0: const TUint KUsbTestSelector_Test_SE0_NAK = 0x03; sl@0: const TUint KUsbTestSelector_Test_Packet = 0x04; sl@0: const TUint KUsbTestSelector_Test_Force_Enable = 0x05; sl@0: sl@0: // sl@0: // Address Masks sl@0: // sl@0: const TUint8 KUsbEpAddress_In = 0x80; sl@0: const TUint8 KUsbEpAddress_Portmask = 0x0f; sl@0: sl@0: // sl@0: // Device Status Values (GET_STATUS) sl@0: // sl@0: const TUint16 KUsbDevStat_SelfPowered = (1 << 0); sl@0: const TUint16 KUsbDevStat_RemoteWakeup = (1 << 1); sl@0: sl@0: // sl@0: // Endpoint Status Values (GET_STATUS) sl@0: // sl@0: const TUint16 KUsbEpStat_Halt = (1 << 0); sl@0: sl@0: sl@0: // sl@0: // USB Descriptor Handling sl@0: // sl@0: /*------------------------------------------------ sl@0: USB transfers data in little-endian fashion. sl@0: The following macros swap the byte order in sl@0: words (16 bit) and longwords (32 bit), such that sl@0: they are in little-endian order afterwards. sl@0: ------------------------------------------------*/ sl@0: #if defined(__BIG_ENDIAN__) // Hitachi SuperH, Motorola 68k sl@0: #define SWAP_BYTES_16(x) \ sl@0: ((((x) >> 8) & 0x00ff) | \ sl@0: (((x) << 8) & 0xff00)) sl@0: #define SWAP_BYTES_32(x) \ sl@0: ((((x) >> 24) & 0x000000ff) | \ sl@0: (((x) >> 8) & 0x0000ff00) | \ sl@0: (((x) << 24) & 0xff000000) | \ sl@0: (((x) << 8) & 0x00ff0000)) sl@0: #else // ARM, Intel sl@0: #define SWAP_BYTES_16(x) (x) sl@0: #define SWAP_BYTES_32(x) (x) sl@0: #endif // defined(__BIG_ENDIAN__) sl@0: sl@0: sl@0: static inline TUint8 LowByte(TUint16 aWord) sl@0: { sl@0: return static_cast(aWord & 0x00ff); sl@0: } sl@0: sl@0: static inline TUint8 HighByte(TUint16 aWord) sl@0: { sl@0: return static_cast((aWord >> 8) & 0x00ff); sl@0: } sl@0: sl@0: sl@0: // sl@0: // Class-specific Values sl@0: // sl@0: sl@0: // These are from the CDC (valid also for Audio Class) sl@0: const TUint8 KUsbDescType_CS_Interface = 0x24; sl@0: const TUint8 KUsbDescType_CS_Endpoint = 0x25; sl@0: sl@0: // Audio Device Class sl@0: const TUint KUsbDescSize_AudioEndpoint = KUsbDescSize_Endpoint + 2; sl@0: const TUint KUsbAudioInterfaceClassCode = 0x01; sl@0: const TUint KUsbAudioInterfaceSubclassCode_Subclass_Undefined = 0x00; sl@0: const TUint KUsbAudioInterfaceSubclassCode_Audiocontrol = 0x01; sl@0: const TUint KUsbAudioInterfaceSubclassCode_Audiostreaming = 0x02; sl@0: const TUint KUsbAudioInterfaceSubclassCode_Midistreaming = 0x03; sl@0: const TUint KUsbAudioInterfaceProtocolCode_Pr_Protocol_Undefined = 0x00; sl@0: sl@0: sl@0: // sl@0: // These are defined just for convenience: sl@0: // sl@0: const TUint8 KEp0_Out = 0; sl@0: const TUint8 KEp0_In = 1; sl@0: const TUint8 KEp0_Rx = KEp0_Out; sl@0: const TUint8 KEp0_Tx = KEp0_In; sl@0: sl@0: sl@0: // sl@0: // USB Implementers Forum, Inc (USB-IF) assigned Vendor IDs: sl@0: // sl@0: const TUint16 KUsbVendorId_Symbian = 0x0E22; // Symbian Ltd. (dec. 3618) sl@0: sl@0: sl@0: #endif // __USB_H__