os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/camerasc/camerasc_plat.h
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/camerasc/camerasc_plat.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,342 @@
1.4 +// Copyright (c) 2006-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 +// template\template_variant\camerasc\camerasc_plat.h
1.18 +// Implementation of the Template shared chunk camera physical device driver (PDD).
1.19 +// This file is part of the Template Base port
1.20 +//
1.21 +//
1.22 +
1.23 +#ifndef __CAMERASC_PLAT_H__
1.24 +#define __CAMERASC_PLAT_H__
1.25 +
1.26 +#include <drivers/camerasc.h>
1.27 +#include <pixelformats.h>
1.28 +
1.29 +// Comment out the first #define, and uncomment the second #define in order to have debug
1.30 +// output for the shared chunk camera driver
1.31 +#define __KTRACE_CAM(s)
1.32 +//#define __KTRACE_CAM(s) s
1.33 +
1.34 +/** Total number of image capture requests that can be handled by the sensor at one time */
1.35 +const TInt KTotalCameraRequests = 2;
1.36 +
1.37 +/** NaviEngine specific panics that can be thrown by the shared chunk camera driver */
1.38 +enum TTemplateCameraScPddPanic
1.39 + {
1.40 + /** Start() has been called before SetConfig() */
1.41 + ENotConfigured,
1.42 + /** Unable to power down the camera hardware */
1.43 + ECannotPowerDown,
1.44 + /** Buffer passed to DSensorIf::FrameSizeCaps() by LDD is too small */
1.45 + ECapsBufferTooSmall
1.46 + };
1.47 +
1.48 +/**
1.49 +The physical device (factory class) for the NaviEngine shared chunk camera driver.
1.50 +
1.51 +This class is used by the device driver framework to instantiate one or more shared chunk camera driver
1.52 +PDDs. An instance of one PDD is allowed for each physical sensor on the device.
1.53 +*/
1.54 +class DTemplateCameraScPddFactory : public DPhysicalDevice
1.55 + {
1.56 +public:
1.57 +
1.58 + DTemplateCameraScPddFactory();
1.59 + ~DTemplateCameraScPddFactory();
1.60 + virtual TInt Install();
1.61 + virtual void GetCaps(TDes8 &aDes) const;
1.62 + virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
1.63 + virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
1.64 + TBool IsUnitOpen(TInt aUnit);
1.65 + TInt SetUnitOpen(TInt aUnit, TBool aIsOpen);
1.66 +
1.67 +private:
1.68 +
1.69 + /** The DFC queue to be used by both the LDD and the PDD to serialise access to the PDD. */
1.70 + TDynamicDfcQue* iDfcQ;
1.71 + /** Mask to keep track of which units have a channel open on them. */
1.72 + TUint iUnitsOpenMask;
1.73 + /** A mutex to protect access to the unit information mask. */
1.74 + NFastMutex iUnitInfoMutex;
1.75 +
1.76 + friend class DTemplateCameraScPdd;
1.77 + };
1.78 +
1.79 +/**
1.80 +Defines the interface for notification of an image being captured.
1.81 +
1.82 +Used by concrete instances of the DSensorIf abstract base class in order to notify an observer class
1.83 +(typically an DCameraScPdd derived class) that an image has been captured for processing.
1.84 +*/
1.85 +class MSensorObserver
1.86 + {
1.87 +public:
1.88 +
1.89 + virtual TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr) = 0;
1.90 + };
1.91 +
1.92 +/**
1.93 +Defines an abstract base class for implementing concrete classes for camera sensors.
1.94 +
1.95 +This class provides an abstract interface to the sensor; one class is derived from this and implemented
1.96 +for each sensor available to the camera driver.
1.97 +*/
1.98 +class DSensorIf : public DBase
1.99 + {
1.100 +public:
1.101 +
1.102 + /**
1.103 + Second phase constructor for the sensor interface. Acquires any resources required for communication with the sensor.
1.104 + When this returns, the sensor is ready for use.
1.105 + */
1.106 + virtual TInt DoCreate() = 0;
1.107 +
1.108 + /**
1.109 + Obtains information regarding the frame sizes and frame rates supported for a given combination of capture mode and pixel format.
1.110 + @param aCaptureMode The capture mode for which to obtain the information.
1.111 + @param aUidPixelFormat The pixel format for which to obtain the information.
1.112 + @param aFrameSizeCapsBuf A referenced to an array of packaged SDevCamFrameSize structures into which to place the information.
1.113 + @return KErrNone if successful, else one of the other system wide error codes.
1.114 + */
1.115 + virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf) = 0;
1.116 +
1.117 + /**
1.118 + Obtains the capabilities of the sensor. This either interrogates the sensor to find out its capabilities, or hard codes
1.119 + them into aCameraCaps, or a combination of the two.
1.120 + @param aCameraCaps A reference to a ptr to the structure into which to place the capabilities of the sensor.
1.121 + This structure is of a variable size and contains the fixed part, followed by an array of
1.122 + SDevCamPixelFormat structures.
1.123 + @return The size of the variable length structure pointed to by aCameraCaps if successful, else one of the other
1.124 + system wide error codes.
1.125 + */
1.126 + virtual TInt GetCaps(TCameraCapsV02*& aCameraCaps) = 0;
1.127 +
1.128 + /**
1.129 + Powers up the sensor.
1.130 + */
1.131 + virtual TInt RequestPower() = 0;
1.132 +
1.133 + /**
1.134 + Powers down the sensor.
1.135 + */
1.136 + virtual TInt RelinquishPower() = 0;
1.137 +
1.138 + /**
1.139 + Configures the sensor for capture in the configuration previously set by SetConfig(), and begins capture into the
1.140 + address pointed to by aLinAddr and aPhysAddr. Both of these addresses point to the same buffer; The address used
1.141 + by the sensor is hardware dependent.
1.142 + @param aCaptureMode Whether to capture in video, viewfinder or single image mode.
1.143 + @param aLinAddr The virtual address of the buffer into which to capture the image.
1.144 + @param aPhysAddr The physical address of the buffer into which to capture the image.
1.145 + @return KErrNone if successful, otherwise one of the other system wide error codes.
1.146 + @pre SetConfig() must first have been called.
1.147 + */
1.148 + virtual TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0;
1.149 +
1.150 + /**
1.151 + 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
1.152 + well as by the class that owns the sensor interface.
1.153 + @param aLinAddr The virtual address of the buffer into which to capture the image.
1.154 + @param aPhysAddr The physical address of the buffer into which to capture the image.
1.155 + @return KErrNone if successful, otherwise one of the other system wide error codes.
1.156 + @pre Start() must first have been called.
1.157 + */
1.158 + virtual TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0;
1.159 +
1.160 + /**
1.161 + Stops any image capturing that is currently underway. It is safe to call this without having called Start().
1.162 + @return KErrNone if successful, otherwise one of the other system wide error codes.
1.163 + */
1.164 + virtual TInt Stop() = 0;
1.165 +
1.166 + /**
1.167 + Saves a configuration specifying such details as dimensions and pixel format in which the sensor should
1.168 + capture images. The shared implementation of this contains generic code, but this can be overridden by
1.169 + derived classes if desired.
1.170 + @param aConfig A TCameraConfigV02 structure containing the settings to be used.
1.171 + @return KErrNone if successful, otherwise one of the other system wide error codes.
1.172 + */
1.173 + virtual TInt SetConfig(const TCameraConfigV02& aConfig);
1.174 +
1.175 +protected:
1.176 +
1.177 + /** Pointer to the observer to call when a frame of data is available */
1.178 + MSensorObserver* iObserver;
1.179 + /** ETrue if capture is under way, else EFalse*/
1.180 + TBool iEnabled;
1.181 + /** Width of the frames to be captured in pixels */
1.182 + TInt iWidth;
1.183 + /** Height of the frames to be captured in pixels */
1.184 + TInt iHeight;
1.185 + /** Number of bytes from the start of one line to the start of the next */
1.186 + TInt iLineOffset;
1.187 + /** The number of requests setup ready for transfer */
1.188 + TInt iPendingRequests;
1.189 + /** The next request to be setup ready for transfer */
1.190 + TUint iNextRequest;
1.191 + /** The configuration in which to capture images */
1.192 + TCameraConfigV02 iConfig;
1.193 + };
1.194 +
1.195 +/**
1.196 +This class provides an abstract interface to the Template sensor.
1.197 +*/
1.198 +class DTemplateSensorIf : public DSensorIf
1.199 + {
1.200 +public:
1.201 +
1.202 + DTemplateSensorIf(MSensorObserver& aObserver, TDfcQue* aDFCQueue);
1.203 + TInt DoCreate();
1.204 + ~DTemplateSensorIf();
1.205 + TInt BufferDoneCallback(TInt aResult);
1.206 + void FillBuffer(TLinAddr aBuffer);
1.207 + TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf);
1.208 + TInt GetCaps(TCameraCapsV02*& aCameraCaps);
1.209 + TInt RequestPower();
1.210 + TInt RelinquishPower();
1.211 + TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr);
1.212 + TInt Stop();
1.213 + TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr);
1.214 +
1.215 + // Static callbacks for various sensor related asynchronous functions
1.216 + static TInt HostPowerCallback(TAny* aPtr, TAny* aPoweredUp);
1.217 + static TInt SensorClkReqCallback(TAny* aPtr);
1.218 +
1.219 +private:
1.220 +
1.221 + /** X position at which to display the logo */
1.222 + TInt iX;
1.223 + /** Y position at which to display the logo */
1.224 + TInt iY;
1.225 + /** Current X direction and speed at which the logo is moving */
1.226 + TInt iXDirection;
1.227 + /** Current Y direction and speed at which the logo is moving */
1.228 + TInt iYDirection;
1.229 + /** Number of nanokernel ticks that represent the time to capture one frame */
1.230 + TInt iImageTimerTicks;
1.231 + /** Timers used for emulating images being captured */
1.232 + NTimer iImageTimers[KTotalCameraRequests];
1.233 + /** DFC queue used for completing image capture requests */
1.234 + TDfcQue* iDFCQueue;
1.235 + /** DFCs used for image capture timer callbacks happeing in our DFC thread */
1.236 + TDfc *iImageTimerDFCs[KTotalCameraRequests];
1.237 +
1.238 + /* Used for cheesy animation effect */
1.239 + TUint8 iCounter;
1.240 + TBool iFlipSwitch;
1.241 + };
1.242 +
1.243 +/**
1.244 +The physical device driver for the NaviEngine shared chunk camera driver.
1.245 +
1.246 +This is the concrete implementation of the abstract DCameraScPdd base class. One instance of this
1.247 +class will be created by the factory class per physical sensor on the device. Only one instance
1.248 +per sensor can be instantiated at any given time. Access to the sensor itself is achieved via the
1.249 +appropriate DSensorIf derived class.
1.250 +*/
1.251 +class DTemplateCameraScPdd : public DCameraScPdd, public MSensorObserver
1.252 + {
1.253 +private:
1.254 +
1.255 + /** States in which the channel can be */
1.256 + enum TState
1.257 + {
1.258 + /** Channel created but not yet configured */
1.259 + EUnconfigured,
1.260 + /** Channel configured but idle and not capturing images */
1.261 + EConfigured,
1.262 + /** Channel capturing images */
1.263 + ECapturing
1.264 + };
1.265 +
1.266 +public:
1.267 +
1.268 + DTemplateCameraScPdd();
1.269 + TInt DoCreate(DTemplateCameraScPddFactory* aPhysicalDevice, TInt aUnit);
1.270 + ~DTemplateCameraScPdd();
1.271 + TDfcQue* DfcQ(TInt aUnit);
1.272 + void Caps(TDes8& aCapsBuf) const;
1.273 + void GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo);
1.274 + TInt SetConfig(const TDesC8& aConfigBuf);
1.275 + TInt Start(TDevCamCaptureMode aCaptureMode,TLinAddr aLinAddr, TPhysAddr aPhysAddr);
1.276 + TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr);
1.277 + TInt Stop();
1.278 + void PowerDown();
1.279 + TInt CapsSize();
1.280 + TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf);
1.281 +
1.282 + /**
1.283 + Sets the sensor brightness to the desired setting.
1.284 +
1.285 + @param aValue A verified brightness setting.
1.286 + @return KErrNone if successful, KErrNotSupported if not supported.
1.287 + */
1.288 + TInt SetBrightness(TUint aBrightness);
1.289 +
1.290 + /**
1.291 + Sets the sensor contrast to the desired setting.
1.292 +
1.293 + @param aValue A verified contrast setting.
1.294 + @return KErrNone if successful, KErrNotSupported if not supported.
1.295 + */
1.296 + TInt SetContrast(TUint aContrast);
1.297 +
1.298 + /**
1.299 + Sets the sensor color effect to the desired setting.
1.300 +
1.301 + @param aValue A verified color effect setting.
1.302 + @return KErrNone if successful, KErrNotSupported if not supported.
1.303 + */
1.304 + TInt SetColorEffect(TUint aColorEffect);
1.305 +
1.306 +private:
1.307 +
1.308 + TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr);
1.309 +
1.310 +private:
1.311 +
1.312 + /** The unit number of this channel. The unit number determines the sensor used. */
1.313 + TInt iUnit;
1.314 + /** A pointer to the PDD factory that created this device. */
1.315 + DTemplateCameraScPddFactory* iPhysicalDevice;
1.316 + /** Ptr to a buffer large enough to hold the variable sized capabilities structure. */
1.317 + TUint8* iCapsBuffer;
1.318 + /** The size of the variable sized capabilities structure. */
1.319 + TUint iCapsSize;
1.320 + /** The capabilities of this device. */
1.321 + TCameraCapsV02* iCaps;
1.322 + /** The current configuration of this device. */
1.323 + TCameraConfigV02 iConfig;
1.324 + /** The current capture mode of the camera. */
1.325 + TDevCamCaptureMode iCaptureMode;
1.326 + /** Abstracted interface to the sensor */
1.327 + DSensorIf* iSensor;
1.328 + /** Current state of the channel (configured, capturing etc) */
1.329 + TState iState;
1.330 + };
1.331 +
1.332 +/**
1.333 +XXX - This structure holds information pertaining to the logo to be rendered in
1.334 +"photos" returned by the template camera driver. This structure is temporary and
1.335 +should be removed when changing this template into a "real" camera driver.
1.336 +*/
1.337 +struct SLogo
1.338 + {
1.339 + TUint iWidth;
1.340 + TUint iHeight;
1.341 + TUint8 iPixelData[80 * 61 * 3 + 1];
1.342 + TUint8 iPixelData2[80 * 61 * 3 + 1];
1.343 + };
1.344 +
1.345 +#endif /* __CAMERASC_PLAT_H__ */