kernel/eka/drivers/usbho/usbdescriptors/usbdescutils.h
changeset 102 ef2a444a7410
equal deleted inserted replaced
90:947f0dc9f7a8 102:ef2a444a7410
       
     1 // Copyright (c) 2007-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 // Description:
       
    12 //
       
    13 
       
    14 /**
       
    15  @file
       
    16  @internalComponent
       
    17 */
       
    18 
       
    19 #ifndef USBDESCUTILS_H
       
    20 #define USBDESCUTILS_H
       
    21 
       
    22 #include <d32usbdescriptors.h>
       
    23 #include <d32usbdi_errors.h>
       
    24 
       
    25 inline void UsbDescFault(UsbdiFaults::TUsbDescFaults aFault)
       
    26 	{
       
    27 	User::Panic(UsbdiFaults::KUsbDescFaultCat, aFault);
       
    28 	}
       
    29 
       
    30 inline void UsbDescPanic(UsbdiPanics::TUsbDescPanics aPanic)
       
    31 	{
       
    32 	User::Panic(UsbdiPanics::KUsbDescPanicCat, aPanic);
       
    33 	}
       
    34 
       
    35 /**
       
    36 Utility function for retrieving a TUint8 from a Little Endian USB descriptor.
       
    37 @param aDes The descriptor to parse.
       
    38 @param aOffset The offset in the descriptor where to parse.
       
    39 @return The TUint8 value parsed.
       
    40 */
       
    41 inline TUint8 ParseTUint8(TPtrC8 aDes, TInt aOffset)
       
    42 	{
       
    43 	return aDes[aOffset];
       
    44 	}
       
    45 
       
    46 /**
       
    47 Utility function for retrieving a TUint16 from a Little Endian USB descriptor.
       
    48 @param aDes The descriptor to parse.
       
    49 @param aOffset The offset in the descriptor where to parse.
       
    50 @return The TUint16 value parsed.
       
    51 */
       
    52 inline TUint16 ParseTUint16(TPtrC8 aDes, TInt aOffset)
       
    53 	{
       
    54 	return ((TUint16)aDes[aOffset]) | ( ((TUint16)aDes[aOffset+1]) << 8 );
       
    55 	}
       
    56 	
       
    57 /**
       
    58 Utility function for retrieving a TUint32 from a Little Endian USB descriptor.
       
    59 @param aDes The descriptor to parse.
       
    60 @param aOffset The offset in the descriptor where to parse.
       
    61 @return The TUint32 value parsed.
       
    62 */
       
    63 inline TUint32 ParseTUint32(TPtrC8 aDes, TInt aOffset)
       
    64 	{
       
    65 	// Put enough brackets to ensure that all casting is correct
       
    66 	// and the expression looks symmetrical
       
    67 	return 	( ((TUint32)(aDes[aOffset])) ) | 
       
    68 			( ((TUint32)(aDes[aOffset + 1])) << 8 ) | 
       
    69 			( ((TUint32)(aDes[aOffset + 2])) << 16 ) | 
       
    70 			( ((TUint32)(aDes[aOffset + 3])) << 24 );
       
    71 	}
       
    72 
       
    73 /**
       
    74 A utility class to store the custom descriptor parsers.
       
    75 The USBDI descriptor parsing framework creates and stores an instance
       
    76 of this class in TLS when a custom parse is registered.
       
    77 */
       
    78 NONSHARABLE_CLASS(CUsbCustomDescriptorParserList) : public CBase
       
    79 	{
       
    80 public:
       
    81 	static CUsbCustomDescriptorParserList* NewL();
       
    82 	~CUsbCustomDescriptorParserList();
       
    83 
       
    84 	void RegisterParserL(UsbDescriptorParser::TUsbDescriptorParserL aParserFunc);
       
    85 	void UnregisterParser(UsbDescriptorParser::TUsbDescriptorParserL aParserFunc);
       
    86 	TInt NumOfRegisteredParsers() const;
       
    87 	UsbDescriptorParser::TUsbDescriptorParserL RegisteredParser(TInt aIndex) const;
       
    88 
       
    89 private:
       
    90 	RArray<UsbDescriptorParser::TUsbDescriptorParserL> iParserList;
       
    91 	};
       
    92 
       
    93 
       
    94 #endif // USBDESCUTILS_H