sl@0: // Copyright (c) 2006-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: // template\template_variant\camerasc\camerasc_plat.h sl@0: // Implementation of the Template shared chunk camera physical device driver (PDD). sl@0: // This file is part of the Template Base port sl@0: // sl@0: // sl@0: sl@0: #ifndef __CAMERASC_PLAT_H__ sl@0: #define __CAMERASC_PLAT_H__ sl@0: sl@0: #include sl@0: #include sl@0: sl@0: // Comment out the first #define, and uncomment the second #define in order to have debug sl@0: // output for the shared chunk camera driver sl@0: #define __KTRACE_CAM(s) sl@0: //#define __KTRACE_CAM(s) s sl@0: sl@0: /** Total number of image capture requests that can be handled by the sensor at one time */ sl@0: const TInt KTotalCameraRequests = 2; sl@0: sl@0: /** NaviEngine specific panics that can be thrown by the shared chunk camera driver */ sl@0: enum TTemplateCameraScPddPanic sl@0: { sl@0: /** Start() has been called before SetConfig() */ sl@0: ENotConfigured, sl@0: /** Unable to power down the camera hardware */ sl@0: ECannotPowerDown, sl@0: /** Buffer passed to DSensorIf::FrameSizeCaps() by LDD is too small */ sl@0: ECapsBufferTooSmall sl@0: }; sl@0: sl@0: /** sl@0: The physical device (factory class) for the NaviEngine shared chunk camera driver. sl@0: sl@0: This class is used by the device driver framework to instantiate one or more shared chunk camera driver sl@0: PDDs. An instance of one PDD is allowed for each physical sensor on the device. sl@0: */ sl@0: class DTemplateCameraScPddFactory : public DPhysicalDevice sl@0: { sl@0: public: sl@0: sl@0: DTemplateCameraScPddFactory(); sl@0: ~DTemplateCameraScPddFactory(); sl@0: virtual TInt Install(); sl@0: virtual void GetCaps(TDes8 &aDes) const; sl@0: virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion &aVer); sl@0: virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer); sl@0: TBool IsUnitOpen(TInt aUnit); sl@0: TInt SetUnitOpen(TInt aUnit, TBool aIsOpen); sl@0: sl@0: private: sl@0: sl@0: /** The DFC queue to be used by both the LDD and the PDD to serialise access to the PDD. */ sl@0: TDynamicDfcQue* iDfcQ; sl@0: /** Mask to keep track of which units have a channel open on them. */ sl@0: TUint iUnitsOpenMask; sl@0: /** A mutex to protect access to the unit information mask. */ sl@0: NFastMutex iUnitInfoMutex; sl@0: sl@0: friend class DTemplateCameraScPdd; sl@0: }; sl@0: sl@0: /** sl@0: Defines the interface for notification of an image being captured. sl@0: sl@0: Used by concrete instances of the DSensorIf abstract base class in order to notify an observer class sl@0: (typically an DCameraScPdd derived class) that an image has been captured for processing. sl@0: */ sl@0: class MSensorObserver sl@0: { sl@0: public: sl@0: sl@0: virtual TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr) = 0; sl@0: }; sl@0: sl@0: /** sl@0: Defines an abstract base class for implementing concrete classes for camera sensors. sl@0: sl@0: This class provides an abstract interface to the sensor; one class is derived from this and implemented sl@0: for each sensor available to the camera driver. sl@0: */ sl@0: class DSensorIf : public DBase sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: Second phase constructor for the sensor interface. Acquires any resources required for communication with the sensor. sl@0: When this returns, the sensor is ready for use. sl@0: */ sl@0: virtual TInt DoCreate() = 0; sl@0: sl@0: /** sl@0: Obtains information regarding the frame sizes and frame rates supported for a given combination of capture mode and pixel format. sl@0: @param aCaptureMode The capture mode for which to obtain the information. sl@0: @param aUidPixelFormat The pixel format for which to obtain the information. sl@0: @param aFrameSizeCapsBuf A referenced to an array of packaged SDevCamFrameSize structures into which to place the information. sl@0: @return KErrNone if successful, else one of the other system wide error codes. sl@0: */ sl@0: virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf) = 0; sl@0: sl@0: /** sl@0: Obtains the capabilities of the sensor. This either interrogates the sensor to find out its capabilities, or hard codes sl@0: them into aCameraCaps, or a combination of the two. sl@0: @param aCameraCaps A reference to a ptr to the structure into which to place the capabilities of the sensor. sl@0: This structure is of a variable size and contains the fixed part, followed by an array of sl@0: SDevCamPixelFormat structures. sl@0: @return The size of the variable length structure pointed to by aCameraCaps if successful, else one of the other sl@0: system wide error codes. sl@0: */ sl@0: virtual TInt GetCaps(TCameraCapsV02*& aCameraCaps) = 0; sl@0: sl@0: /** sl@0: Powers up the sensor. sl@0: */ sl@0: virtual TInt RequestPower() = 0; sl@0: sl@0: /** sl@0: Powers down the sensor. sl@0: */ sl@0: virtual TInt RelinquishPower() = 0; sl@0: sl@0: /** sl@0: Configures the sensor for capture in the configuration previously set by SetConfig(), and begins capture into the sl@0: address pointed to by aLinAddr and aPhysAddr. Both of these addresses point to the same buffer; The address used sl@0: by the sensor is hardware dependent. sl@0: @param aCaptureMode Whether to capture in video, viewfinder or single image mode. sl@0: @param aLinAddr The virtual address of the buffer into which to capture the image. sl@0: @param aPhysAddr The physical address of the buffer into which to capture the image. sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: @pre SetConfig() must first have been called. sl@0: */ sl@0: virtual TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0; sl@0: sl@0: /** sl@0: Sets the address of the buffer into which the next image will be captured. If is common for this to be called by Start() as sl@0: well as by the class that owns the sensor interface. sl@0: @param aLinAddr The virtual address of the buffer into which to capture the image. sl@0: @param aPhysAddr The physical address of the buffer into which to capture the image. sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: @pre Start() must first have been called. sl@0: */ sl@0: virtual TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0; sl@0: sl@0: /** sl@0: Stops any image capturing that is currently underway. It is safe to call this without having called Start(). sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: */ sl@0: virtual TInt Stop() = 0; sl@0: sl@0: /** sl@0: Saves a configuration specifying such details as dimensions and pixel format in which the sensor should sl@0: capture images. The shared implementation of this contains generic code, but this can be overridden by sl@0: derived classes if desired. sl@0: @param aConfig A TCameraConfigV02 structure containing the settings to be used. sl@0: @return KErrNone if successful, otherwise one of the other system wide error codes. sl@0: */ sl@0: virtual TInt SetConfig(const TCameraConfigV02& aConfig); sl@0: sl@0: protected: sl@0: sl@0: /** Pointer to the observer to call when a frame of data is available */ sl@0: MSensorObserver* iObserver; sl@0: /** ETrue if capture is under way, else EFalse*/ sl@0: TBool iEnabled; sl@0: /** Width of the frames to be captured in pixels */ sl@0: TInt iWidth; sl@0: /** Height of the frames to be captured in pixels */ sl@0: TInt iHeight; sl@0: /** Number of bytes from the start of one line to the start of the next */ sl@0: TInt iLineOffset; sl@0: /** The number of requests setup ready for transfer */ sl@0: TInt iPendingRequests; sl@0: /** The next request to be setup ready for transfer */ sl@0: TUint iNextRequest; sl@0: /** The configuration in which to capture images */ sl@0: TCameraConfigV02 iConfig; sl@0: }; sl@0: sl@0: /** sl@0: This class provides an abstract interface to the Template sensor. sl@0: */ sl@0: class DTemplateSensorIf : public DSensorIf sl@0: { sl@0: public: sl@0: sl@0: DTemplateSensorIf(MSensorObserver& aObserver, TDfcQue* aDFCQueue); sl@0: TInt DoCreate(); sl@0: ~DTemplateSensorIf(); sl@0: TInt BufferDoneCallback(TInt aResult); sl@0: void FillBuffer(TLinAddr aBuffer); sl@0: TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf); sl@0: TInt GetCaps(TCameraCapsV02*& aCameraCaps); sl@0: TInt RequestPower(); sl@0: TInt RelinquishPower(); sl@0: TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr); sl@0: TInt Stop(); sl@0: TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr); sl@0: sl@0: // Static callbacks for various sensor related asynchronous functions sl@0: static TInt HostPowerCallback(TAny* aPtr, TAny* aPoweredUp); sl@0: static TInt SensorClkReqCallback(TAny* aPtr); sl@0: sl@0: private: sl@0: sl@0: /** X position at which to display the logo */ sl@0: TInt iX; sl@0: /** Y position at which to display the logo */ sl@0: TInt iY; sl@0: /** Current X direction and speed at which the logo is moving */ sl@0: TInt iXDirection; sl@0: /** Current Y direction and speed at which the logo is moving */ sl@0: TInt iYDirection; sl@0: /** Number of nanokernel ticks that represent the time to capture one frame */ sl@0: TInt iImageTimerTicks; sl@0: /** Timers used for emulating images being captured */ sl@0: NTimer iImageTimers[KTotalCameraRequests]; sl@0: /** DFC queue used for completing image capture requests */ sl@0: TDfcQue* iDFCQueue; sl@0: /** DFCs used for image capture timer callbacks happeing in our DFC thread */ sl@0: TDfc *iImageTimerDFCs[KTotalCameraRequests]; sl@0: sl@0: /* Used for cheesy animation effect */ sl@0: TUint8 iCounter; sl@0: TBool iFlipSwitch; sl@0: }; sl@0: sl@0: /** sl@0: The physical device driver for the NaviEngine shared chunk camera driver. sl@0: sl@0: This is the concrete implementation of the abstract DCameraScPdd base class. One instance of this sl@0: class will be created by the factory class per physical sensor on the device. Only one instance sl@0: per sensor can be instantiated at any given time. Access to the sensor itself is achieved via the sl@0: appropriate DSensorIf derived class. sl@0: */ sl@0: class DTemplateCameraScPdd : public DCameraScPdd, public MSensorObserver sl@0: { sl@0: private: sl@0: sl@0: /** States in which the channel can be */ sl@0: enum TState sl@0: { sl@0: /** Channel created but not yet configured */ sl@0: EUnconfigured, sl@0: /** Channel configured but idle and not capturing images */ sl@0: EConfigured, sl@0: /** Channel capturing images */ sl@0: ECapturing sl@0: }; sl@0: sl@0: public: sl@0: sl@0: DTemplateCameraScPdd(); sl@0: TInt DoCreate(DTemplateCameraScPddFactory* aPhysicalDevice, TInt aUnit); sl@0: ~DTemplateCameraScPdd(); sl@0: TDfcQue* DfcQ(TInt aUnit); sl@0: void Caps(TDes8& aCapsBuf) const; sl@0: void GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo); sl@0: TInt SetConfig(const TDesC8& aConfigBuf); sl@0: TInt Start(TDevCamCaptureMode aCaptureMode,TLinAddr aLinAddr, TPhysAddr aPhysAddr); sl@0: TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr); sl@0: TInt Stop(); sl@0: void PowerDown(); sl@0: TInt CapsSize(); sl@0: TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf); sl@0: sl@0: /** sl@0: Sets the sensor brightness to the desired setting. sl@0: sl@0: @param aValue A verified brightness setting. sl@0: @return KErrNone if successful, KErrNotSupported if not supported. sl@0: */ sl@0: TInt SetBrightness(TUint aBrightness); sl@0: sl@0: /** sl@0: Sets the sensor contrast to the desired setting. sl@0: sl@0: @param aValue A verified contrast setting. sl@0: @return KErrNone if successful, KErrNotSupported if not supported. sl@0: */ sl@0: TInt SetContrast(TUint aContrast); sl@0: sl@0: /** sl@0: Sets the sensor color effect to the desired setting. sl@0: sl@0: @param aValue A verified color effect setting. sl@0: @return KErrNone if successful, KErrNotSupported if not supported. sl@0: */ sl@0: TInt SetColorEffect(TUint aColorEffect); sl@0: sl@0: private: sl@0: sl@0: TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr); sl@0: sl@0: private: sl@0: sl@0: /** The unit number of this channel. The unit number determines the sensor used. */ sl@0: TInt iUnit; sl@0: /** A pointer to the PDD factory that created this device. */ sl@0: DTemplateCameraScPddFactory* iPhysicalDevice; sl@0: /** Ptr to a buffer large enough to hold the variable sized capabilities structure. */ sl@0: TUint8* iCapsBuffer; sl@0: /** The size of the variable sized capabilities structure. */ sl@0: TUint iCapsSize; sl@0: /** The capabilities of this device. */ sl@0: TCameraCapsV02* iCaps; sl@0: /** The current configuration of this device. */ sl@0: TCameraConfigV02 iConfig; sl@0: /** The current capture mode of the camera. */ sl@0: TDevCamCaptureMode iCaptureMode; sl@0: /** Abstracted interface to the sensor */ sl@0: DSensorIf* iSensor; sl@0: /** Current state of the channel (configured, capturing etc) */ sl@0: TState iState; sl@0: }; sl@0: sl@0: /** sl@0: XXX - This structure holds information pertaining to the logo to be rendered in sl@0: "photos" returned by the template camera driver. This structure is temporary and sl@0: should be removed when changing this template into a "real" camera driver. sl@0: */ sl@0: struct SLogo sl@0: { sl@0: TUint iWidth; sl@0: TUint iHeight; sl@0: TUint8 iPixelData[80 * 61 * 3 + 1]; sl@0: TUint8 iPixelData2[80 * 61 * 3 + 1]; sl@0: }; sl@0: sl@0: #endif /* __CAMERASC_PLAT_H__ */