os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/camerasc/camerasc_plat.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// template\template_variant\camerasc\camerasc_plat.h
sl@0
    15
// Implementation of the Template shared chunk camera physical device driver (PDD).
sl@0
    16
// This file is part of the Template Base port
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#ifndef __CAMERASC_PLAT_H__
sl@0
    21
#define __CAMERASC_PLAT_H__
sl@0
    22
sl@0
    23
#include <drivers/camerasc.h>
sl@0
    24
#include <pixelformats.h>
sl@0
    25
sl@0
    26
// Comment out the first #define, and uncomment the second #define in order to have debug
sl@0
    27
// output for the shared chunk camera driver
sl@0
    28
#define __KTRACE_CAM(s)
sl@0
    29
//#define __KTRACE_CAM(s) s
sl@0
    30
sl@0
    31
/** Total number of image capture requests that can be handled by the sensor at one time */
sl@0
    32
const TInt KTotalCameraRequests = 2;
sl@0
    33
sl@0
    34
/** NaviEngine specific panics that can be thrown by the shared chunk camera driver */
sl@0
    35
enum TTemplateCameraScPddPanic
sl@0
    36
	{
sl@0
    37
	/** Start() has been called before SetConfig() */
sl@0
    38
	ENotConfigured,
sl@0
    39
	/** Unable to power down the camera hardware */
sl@0
    40
	ECannotPowerDown,
sl@0
    41
	/** Buffer passed to DSensorIf::FrameSizeCaps() by LDD is too small */
sl@0
    42
	ECapsBufferTooSmall
sl@0
    43
	};
sl@0
    44
sl@0
    45
/**
sl@0
    46
The physical device (factory class) for the NaviEngine shared chunk camera driver.
sl@0
    47
sl@0
    48
This class is used by the device driver framework to instantiate one or more shared chunk camera driver
sl@0
    49
PDDs.  An instance of one PDD is allowed for each physical sensor on the device.
sl@0
    50
*/
sl@0
    51
class DTemplateCameraScPddFactory : public DPhysicalDevice
sl@0
    52
	{
sl@0
    53
public:
sl@0
    54
sl@0
    55
	DTemplateCameraScPddFactory();
sl@0
    56
	~DTemplateCameraScPddFactory();
sl@0
    57
	virtual TInt Install();
sl@0
    58
	virtual void GetCaps(TDes8 &aDes) const;
sl@0
    59
	virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
sl@0
    60
	virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
sl@0
    61
	TBool IsUnitOpen(TInt aUnit);
sl@0
    62
	TInt SetUnitOpen(TInt aUnit, TBool aIsOpen);
sl@0
    63
sl@0
    64
private:
sl@0
    65
sl@0
    66
	/** The DFC queue to be used by both the LDD and the PDD to serialise access to the PDD. */
sl@0
    67
	TDynamicDfcQue*	iDfcQ;
sl@0
    68
	/** Mask to keep track of which units have a channel open on them. */
sl@0
    69
	TUint			iUnitsOpenMask;
sl@0
    70
	/** A mutex to protect access to the unit information mask. */
sl@0
    71
	NFastMutex		iUnitInfoMutex;
sl@0
    72
sl@0
    73
	friend class DTemplateCameraScPdd;
sl@0
    74
	};
sl@0
    75
sl@0
    76
/**
sl@0
    77
Defines the interface for notification of an image being captured.
sl@0
    78
sl@0
    79
Used by concrete instances of the DSensorIf abstract base class in order to notify an observer class
sl@0
    80
(typically an DCameraScPdd derived class) that an image has been captured for processing.
sl@0
    81
*/
sl@0
    82
class MSensorObserver
sl@0
    83
	{
sl@0
    84
public:
sl@0
    85
sl@0
    86
	virtual TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr) = 0;
sl@0
    87
	};
sl@0
    88
sl@0
    89
/**
sl@0
    90
Defines an abstract base class for implementing concrete classes for camera sensors.
sl@0
    91
sl@0
    92
This class provides an abstract interface to the sensor;  one class is derived from this and implemented
sl@0
    93
for each sensor available to the camera driver.
sl@0
    94
*/
sl@0
    95
class DSensorIf : public DBase
sl@0
    96
	{
sl@0
    97
public:
sl@0
    98
sl@0
    99
	/**
sl@0
   100
	Second phase constructor for the sensor interface.  Acquires any resources required for communication with the sensor.
sl@0
   101
	When this returns, the sensor is ready for use.
sl@0
   102
	*/
sl@0
   103
	virtual TInt DoCreate() = 0;
sl@0
   104
sl@0
   105
	/**
sl@0
   106
	Obtains information regarding the frame sizes and frame rates supported for a given combination of capture mode and pixel format.
sl@0
   107
	@param	aCaptureMode		The capture mode for which to obtain the information.
sl@0
   108
	@param	aUidPixelFormat		The pixel format for which to obtain the information.
sl@0
   109
	@param	aFrameSizeCapsBuf	A referenced to an array of packaged SDevCamFrameSize structures into which to place the information.
sl@0
   110
	@return	KErrNone if successful, else one of the other system wide error codes.
sl@0
   111
	*/
sl@0
   112
	virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf) = 0;
sl@0
   113
sl@0
   114
	/**
sl@0
   115
	Obtains the capabilities of the sensor.  This either interrogates the sensor to find out its capabilities, or hard codes
sl@0
   116
	them into aCameraCaps, or a combination of the two.
sl@0
   117
	@param	aCameraCaps		A reference to a ptr to the structure into which to place the capabilities of the sensor.
sl@0
   118
							This structure is of a variable size and contains the fixed part, followed by an array of
sl@0
   119
							SDevCamPixelFormat structures.
sl@0
   120
	@return	The size of the variable length structure pointed to by aCameraCaps if successful, else one of the other
sl@0
   121
			system wide error codes.
sl@0
   122
	*/
sl@0
   123
	virtual TInt GetCaps(TCameraCapsV02*& aCameraCaps) = 0;
sl@0
   124
sl@0
   125
	/**
sl@0
   126
	Powers up the sensor.
sl@0
   127
	*/
sl@0
   128
	virtual TInt RequestPower() = 0;
sl@0
   129
sl@0
   130
	/**
sl@0
   131
	Powers down the sensor.
sl@0
   132
	*/
sl@0
   133
	virtual TInt RelinquishPower() = 0;
sl@0
   134
sl@0
   135
	/**
sl@0
   136
	Configures the sensor for capture in the configuration previously set by SetConfig(), and begins capture into the
sl@0
   137
	address pointed to by aLinAddr and aPhysAddr.  Both of these addresses point to the same buffer;  The address used
sl@0
   138
	by the sensor is hardware dependent.
sl@0
   139
	@param	aCaptureMode	Whether to capture in video, viewfinder or single image mode.
sl@0
   140
	@param	aLinAddr		The virtual address of the buffer into which to capture the image.
sl@0
   141
	@param	aPhysAddr		The physical address of the buffer into which to capture the image.
sl@0
   142
	@return	KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   143
	@pre	SetConfig() must first have been called.
sl@0
   144
	*/
sl@0
   145
	virtual TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0;
sl@0
   146
sl@0
   147
	/**
sl@0
   148
	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
   149
	well as by the class that owns the sensor interface.
sl@0
   150
	@param	aLinAddr		The virtual address of the buffer into which to capture the image.
sl@0
   151
	@param	aPhysAddr		The physical address of the buffer into which to capture the image.
sl@0
   152
	@return	KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   153
	@pre	Start() must first have been called.
sl@0
   154
	*/
sl@0
   155
	virtual TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0;
sl@0
   156
sl@0
   157
	/**
sl@0
   158
	Stops any image capturing that is currently underway.  It is safe to call this without having called Start().
sl@0
   159
	@return	KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   160
	*/
sl@0
   161
	virtual TInt Stop() = 0;
sl@0
   162
sl@0
   163
	/**
sl@0
   164
	Saves a configuration specifying such details as dimensions and pixel format in which the sensor should
sl@0
   165
	capture images.  The shared implementation of this contains generic code, but this can be overridden by
sl@0
   166
	derived classes if desired.
sl@0
   167
	@param	aConfig	A TCameraConfigV02 structure containing the settings to be used.
sl@0
   168
	@return	KErrNone if successful, otherwise one of the other system wide error codes.
sl@0
   169
	*/
sl@0
   170
	virtual TInt SetConfig(const TCameraConfigV02& aConfig);
sl@0
   171
sl@0
   172
protected:
sl@0
   173
sl@0
   174
	/** Pointer to the observer to call when a frame of data is available */
sl@0
   175
	MSensorObserver*	iObserver;
sl@0
   176
	/** ETrue if capture is under way, else EFalse*/
sl@0
   177
	TBool				iEnabled;
sl@0
   178
	/** Width of the frames to be captured in pixels */
sl@0
   179
	TInt				iWidth;
sl@0
   180
	/** Height of the frames to be captured in pixels */
sl@0
   181
	TInt				iHeight;
sl@0
   182
	/** Number of bytes from the start of one line to the start of the next */
sl@0
   183
	TInt				iLineOffset;
sl@0
   184
	/** The number of requests setup ready for transfer */
sl@0
   185
	TInt				iPendingRequests;
sl@0
   186
	/** The next request to be setup ready for transfer */
sl@0
   187
	TUint				iNextRequest;
sl@0
   188
	/** The configuration in which to capture images */
sl@0
   189
	TCameraConfigV02	iConfig;
sl@0
   190
	};
sl@0
   191
sl@0
   192
/**
sl@0
   193
This class provides an abstract interface to the Template sensor.
sl@0
   194
*/
sl@0
   195
class DTemplateSensorIf : public DSensorIf
sl@0
   196
	{
sl@0
   197
public:
sl@0
   198
sl@0
   199
	DTemplateSensorIf(MSensorObserver& aObserver, TDfcQue* aDFCQueue);
sl@0
   200
	TInt DoCreate();
sl@0
   201
	~DTemplateSensorIf();
sl@0
   202
	TInt BufferDoneCallback(TInt aResult);
sl@0
   203
	void FillBuffer(TLinAddr aBuffer);
sl@0
   204
	TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf);
sl@0
   205
	TInt GetCaps(TCameraCapsV02*& aCameraCaps);
sl@0
   206
	TInt RequestPower();
sl@0
   207
	TInt RelinquishPower();
sl@0
   208
	TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr);
sl@0
   209
	TInt Stop();
sl@0
   210
	TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr);
sl@0
   211
sl@0
   212
	// Static callbacks for various sensor related asynchronous functions
sl@0
   213
	static TInt HostPowerCallback(TAny* aPtr, TAny* aPoweredUp);
sl@0
   214
	static TInt SensorClkReqCallback(TAny* aPtr);
sl@0
   215
sl@0
   216
private:
sl@0
   217
sl@0
   218
	/** X position at which to display the logo */
sl@0
   219
	TInt		iX;
sl@0
   220
	/** Y position at which to display the logo */
sl@0
   221
	TInt		iY;
sl@0
   222
	/** Current X direction and speed at which the logo is moving */
sl@0
   223
	TInt		iXDirection;
sl@0
   224
	/** Current Y direction and speed at which the logo is moving */
sl@0
   225
	TInt		iYDirection;
sl@0
   226
	/** Number of nanokernel ticks that represent the time to capture one frame */
sl@0
   227
	TInt		iImageTimerTicks;
sl@0
   228
	/** Timers used for emulating images being captured */
sl@0
   229
	NTimer		iImageTimers[KTotalCameraRequests];
sl@0
   230
	/** DFC queue used for completing image capture requests */
sl@0
   231
	TDfcQue*	iDFCQueue;
sl@0
   232
	/** DFCs used for image capture timer callbacks happeing in our DFC thread */
sl@0
   233
	TDfc		*iImageTimerDFCs[KTotalCameraRequests];
sl@0
   234
    
sl@0
   235
    /* Used for cheesy animation effect */
sl@0
   236
    TUint8 iCounter;
sl@0
   237
    TBool iFlipSwitch;
sl@0
   238
	};
sl@0
   239
sl@0
   240
/**
sl@0
   241
The physical device driver for the NaviEngine shared chunk camera driver.
sl@0
   242
sl@0
   243
This is the concrete implementation of the abstract DCameraScPdd base class.  One instance of this
sl@0
   244
class will be created by the factory class per physical sensor on the device.  Only one instance
sl@0
   245
per sensor can be instantiated at any given time.  Access to the sensor itself is achieved via the
sl@0
   246
appropriate DSensorIf derived class.
sl@0
   247
*/
sl@0
   248
class DTemplateCameraScPdd : public DCameraScPdd, public MSensorObserver
sl@0
   249
	{
sl@0
   250
private:
sl@0
   251
sl@0
   252
	/** States in which the channel can be */
sl@0
   253
	enum TState
sl@0
   254
		{
sl@0
   255
		/** Channel created but not yet configured */
sl@0
   256
		EUnconfigured,
sl@0
   257
		/** Channel configured but idle and not capturing images */
sl@0
   258
		EConfigured,
sl@0
   259
		/** Channel capturing images */
sl@0
   260
		ECapturing
sl@0
   261
		};
sl@0
   262
sl@0
   263
public:
sl@0
   264
sl@0
   265
	DTemplateCameraScPdd();
sl@0
   266
	TInt DoCreate(DTemplateCameraScPddFactory* aPhysicalDevice, TInt aUnit);
sl@0
   267
	~DTemplateCameraScPdd();
sl@0
   268
	TDfcQue* DfcQ(TInt aUnit);
sl@0
   269
	void Caps(TDes8& aCapsBuf) const;
sl@0
   270
	void GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo);
sl@0
   271
	TInt SetConfig(const TDesC8& aConfigBuf);
sl@0
   272
	TInt Start(TDevCamCaptureMode aCaptureMode,TLinAddr aLinAddr, TPhysAddr aPhysAddr);
sl@0
   273
	TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr);
sl@0
   274
	TInt Stop();
sl@0
   275
	void PowerDown();
sl@0
   276
	TInt CapsSize();
sl@0
   277
	TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf);
sl@0
   278
sl@0
   279
	/**
sl@0
   280
	Sets the sensor brightness to the desired setting.
sl@0
   281
sl@0
   282
	@param aValue A verified brightness setting.
sl@0
   283
	@return KErrNone if successful, KErrNotSupported if not supported.
sl@0
   284
	*/
sl@0
   285
	TInt SetBrightness(TUint aBrightness);
sl@0
   286
sl@0
   287
	/**
sl@0
   288
	Sets the sensor contrast to the desired setting.
sl@0
   289
sl@0
   290
	@param aValue A verified contrast setting.
sl@0
   291
	@return KErrNone if successful, KErrNotSupported if not supported.
sl@0
   292
	*/
sl@0
   293
	TInt SetContrast(TUint aContrast);
sl@0
   294
sl@0
   295
	/**
sl@0
   296
	Sets the sensor color effect to the desired setting.
sl@0
   297
sl@0
   298
	@param aValue A verified color effect setting.
sl@0
   299
	@return KErrNone if successful, KErrNotSupported if not supported.
sl@0
   300
	*/
sl@0
   301
	TInt SetColorEffect(TUint aColorEffect);
sl@0
   302
sl@0
   303
private:
sl@0
   304
sl@0
   305
	TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr);
sl@0
   306
sl@0
   307
private:
sl@0
   308
sl@0
   309
	/** The unit number of this channel.  The unit number determines the sensor used. */
sl@0
   310
	TInt						iUnit;
sl@0
   311
	/** A pointer to the PDD factory that created this device. */
sl@0
   312
	DTemplateCameraScPddFactory* iPhysicalDevice;
sl@0
   313
	/** Ptr to a buffer large enough to hold the variable sized capabilities structure. */
sl@0
   314
	TUint8*						iCapsBuffer;
sl@0
   315
	/** The size of the variable sized capabilities structure. */
sl@0
   316
	TUint						iCapsSize;
sl@0
   317
	/** The capabilities of this device. */
sl@0
   318
	TCameraCapsV02*				iCaps;
sl@0
   319
	/** The current configuration of this device. */
sl@0
   320
	TCameraConfigV02			iConfig;
sl@0
   321
	/** The current capture mode of the camera. */
sl@0
   322
	TDevCamCaptureMode			iCaptureMode;
sl@0
   323
	/** Abstracted interface to the sensor */
sl@0
   324
	DSensorIf*					iSensor;
sl@0
   325
	/** Current state of the channel (configured, capturing etc) */
sl@0
   326
	TState						iState;
sl@0
   327
	};
sl@0
   328
sl@0
   329
/**
sl@0
   330
XXX - This structure holds information pertaining to the logo to be rendered in
sl@0
   331
"photos" returned by the template camera driver.  This structure is temporary and
sl@0
   332
should be removed when changing this template into a "real" camera driver.
sl@0
   333
*/
sl@0
   334
struct SLogo
sl@0
   335
	{
sl@0
   336
	TUint	iWidth;
sl@0
   337
	TUint	iHeight;
sl@0
   338
	TUint8	iPixelData[80 * 61 * 3 + 1];
sl@0
   339
    TUint8  iPixelData2[80 * 61 * 3 + 1];
sl@0
   340
	};
sl@0
   341
sl@0
   342
#endif /* __CAMERASC_PLAT_H__ */