os/kernelhwsrv/bsptemplate/asspandvariant/template_variant/camerasc/camerasc_plat.h
Update contrib.
1 // Copyright (c) 2006-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // template\template_variant\camerasc\camerasc_plat.h
15 // Implementation of the Template shared chunk camera physical device driver (PDD).
16 // This file is part of the Template Base port
20 #ifndef __CAMERASC_PLAT_H__
21 #define __CAMERASC_PLAT_H__
23 #include <drivers/camerasc.h>
24 #include <pixelformats.h>
26 // Comment out the first #define, and uncomment the second #define in order to have debug
27 // output for the shared chunk camera driver
28 #define __KTRACE_CAM(s)
29 //#define __KTRACE_CAM(s) s
31 /** Total number of image capture requests that can be handled by the sensor at one time */
32 const TInt KTotalCameraRequests = 2;
34 /** NaviEngine specific panics that can be thrown by the shared chunk camera driver */
35 enum TTemplateCameraScPddPanic
37 /** Start() has been called before SetConfig() */
39 /** Unable to power down the camera hardware */
41 /** Buffer passed to DSensorIf::FrameSizeCaps() by LDD is too small */
46 The physical device (factory class) for the NaviEngine shared chunk camera driver.
48 This class is used by the device driver framework to instantiate one or more shared chunk camera driver
49 PDDs. An instance of one PDD is allowed for each physical sensor on the device.
51 class DTemplateCameraScPddFactory : public DPhysicalDevice
55 DTemplateCameraScPddFactory();
56 ~DTemplateCameraScPddFactory();
57 virtual TInt Install();
58 virtual void GetCaps(TDes8 &aDes) const;
59 virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
60 virtual TInt Validate(TInt aUnit, const TDesC8* anInfo, const TVersion &aVer);
61 TBool IsUnitOpen(TInt aUnit);
62 TInt SetUnitOpen(TInt aUnit, TBool aIsOpen);
66 /** The DFC queue to be used by both the LDD and the PDD to serialise access to the PDD. */
67 TDynamicDfcQue* iDfcQ;
68 /** Mask to keep track of which units have a channel open on them. */
70 /** A mutex to protect access to the unit information mask. */
71 NFastMutex iUnitInfoMutex;
73 friend class DTemplateCameraScPdd;
77 Defines the interface for notification of an image being captured.
79 Used by concrete instances of the DSensorIf abstract base class in order to notify an observer class
80 (typically an DCameraScPdd derived class) that an image has been captured for processing.
86 virtual TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr) = 0;
90 Defines an abstract base class for implementing concrete classes for camera sensors.
92 This class provides an abstract interface to the sensor; one class is derived from this and implemented
93 for each sensor available to the camera driver.
95 class DSensorIf : public DBase
100 Second phase constructor for the sensor interface. Acquires any resources required for communication with the sensor.
101 When this returns, the sensor is ready for use.
103 virtual TInt DoCreate() = 0;
106 Obtains information regarding the frame sizes and frame rates supported for a given combination of capture mode and pixel format.
107 @param aCaptureMode The capture mode for which to obtain the information.
108 @param aUidPixelFormat The pixel format for which to obtain the information.
109 @param aFrameSizeCapsBuf A referenced to an array of packaged SDevCamFrameSize structures into which to place the information.
110 @return KErrNone if successful, else one of the other system wide error codes.
112 virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf) = 0;
115 Obtains the capabilities of the sensor. This either interrogates the sensor to find out its capabilities, or hard codes
116 them into aCameraCaps, or a combination of the two.
117 @param aCameraCaps A reference to a ptr to the structure into which to place the capabilities of the sensor.
118 This structure is of a variable size and contains the fixed part, followed by an array of
119 SDevCamPixelFormat structures.
120 @return The size of the variable length structure pointed to by aCameraCaps if successful, else one of the other
121 system wide error codes.
123 virtual TInt GetCaps(TCameraCapsV02*& aCameraCaps) = 0;
126 Powers up the sensor.
128 virtual TInt RequestPower() = 0;
131 Powers down the sensor.
133 virtual TInt RelinquishPower() = 0;
136 Configures the sensor for capture in the configuration previously set by SetConfig(), and begins capture into the
137 address pointed to by aLinAddr and aPhysAddr. Both of these addresses point to the same buffer; The address used
138 by the sensor is hardware dependent.
139 @param aCaptureMode Whether to capture in video, viewfinder or single image mode.
140 @param aLinAddr The virtual address of the buffer into which to capture the image.
141 @param aPhysAddr The physical address of the buffer into which to capture the image.
142 @return KErrNone if successful, otherwise one of the other system wide error codes.
143 @pre SetConfig() must first have been called.
145 virtual TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 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
149 well as by the class that owns the sensor interface.
150 @param aLinAddr The virtual address of the buffer into which to capture the image.
151 @param aPhysAddr The physical address of the buffer into which to capture the image.
152 @return KErrNone if successful, otherwise one of the other system wide error codes.
153 @pre Start() must first have been called.
155 virtual TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0;
158 Stops any image capturing that is currently underway. It is safe to call this without having called Start().
159 @return KErrNone if successful, otherwise one of the other system wide error codes.
161 virtual TInt Stop() = 0;
164 Saves a configuration specifying such details as dimensions and pixel format in which the sensor should
165 capture images. The shared implementation of this contains generic code, but this can be overridden by
166 derived classes if desired.
167 @param aConfig A TCameraConfigV02 structure containing the settings to be used.
168 @return KErrNone if successful, otherwise one of the other system wide error codes.
170 virtual TInt SetConfig(const TCameraConfigV02& aConfig);
174 /** Pointer to the observer to call when a frame of data is available */
175 MSensorObserver* iObserver;
176 /** ETrue if capture is under way, else EFalse*/
178 /** Width of the frames to be captured in pixels */
180 /** Height of the frames to be captured in pixels */
182 /** Number of bytes from the start of one line to the start of the next */
184 /** The number of requests setup ready for transfer */
185 TInt iPendingRequests;
186 /** The next request to be setup ready for transfer */
188 /** The configuration in which to capture images */
189 TCameraConfigV02 iConfig;
193 This class provides an abstract interface to the Template sensor.
195 class DTemplateSensorIf : public DSensorIf
199 DTemplateSensorIf(MSensorObserver& aObserver, TDfcQue* aDFCQueue);
201 ~DTemplateSensorIf();
202 TInt BufferDoneCallback(TInt aResult);
203 void FillBuffer(TLinAddr aBuffer);
204 TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf);
205 TInt GetCaps(TCameraCapsV02*& aCameraCaps);
207 TInt RelinquishPower();
208 TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr);
210 TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr);
212 // Static callbacks for various sensor related asynchronous functions
213 static TInt HostPowerCallback(TAny* aPtr, TAny* aPoweredUp);
214 static TInt SensorClkReqCallback(TAny* aPtr);
218 /** X position at which to display the logo */
220 /** Y position at which to display the logo */
222 /** Current X direction and speed at which the logo is moving */
224 /** Current Y direction and speed at which the logo is moving */
226 /** Number of nanokernel ticks that represent the time to capture one frame */
227 TInt iImageTimerTicks;
228 /** Timers used for emulating images being captured */
229 NTimer iImageTimers[KTotalCameraRequests];
230 /** DFC queue used for completing image capture requests */
232 /** DFCs used for image capture timer callbacks happeing in our DFC thread */
233 TDfc *iImageTimerDFCs[KTotalCameraRequests];
235 /* Used for cheesy animation effect */
241 The physical device driver for the NaviEngine shared chunk camera driver.
243 This is the concrete implementation of the abstract DCameraScPdd base class. One instance of this
244 class will be created by the factory class per physical sensor on the device. Only one instance
245 per sensor can be instantiated at any given time. Access to the sensor itself is achieved via the
246 appropriate DSensorIf derived class.
248 class DTemplateCameraScPdd : public DCameraScPdd, public MSensorObserver
252 /** States in which the channel can be */
255 /** Channel created but not yet configured */
257 /** Channel configured but idle and not capturing images */
259 /** Channel capturing images */
265 DTemplateCameraScPdd();
266 TInt DoCreate(DTemplateCameraScPddFactory* aPhysicalDevice, TInt aUnit);
267 ~DTemplateCameraScPdd();
268 TDfcQue* DfcQ(TInt aUnit);
269 void Caps(TDes8& aCapsBuf) const;
270 void GetChunkCreateInfo(TChunkCreateInfo& aChunkCreateInfo);
271 TInt SetConfig(const TDesC8& aConfigBuf);
272 TInt Start(TDevCamCaptureMode aCaptureMode,TLinAddr aLinAddr, TPhysAddr aPhysAddr);
273 TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr);
277 TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf);
280 Sets the sensor brightness to the desired setting.
282 @param aValue A verified brightness setting.
283 @return KErrNone if successful, KErrNotSupported if not supported.
285 TInt SetBrightness(TUint aBrightness);
288 Sets the sensor contrast to the desired setting.
290 @param aValue A verified contrast setting.
291 @return KErrNone if successful, KErrNotSupported if not supported.
293 TInt SetContrast(TUint aContrast);
296 Sets the sensor color effect to the desired setting.
298 @param aValue A verified color effect setting.
299 @return KErrNone if successful, KErrNotSupported if not supported.
301 TInt SetColorEffect(TUint aColorEffect);
305 TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr);
309 /** The unit number of this channel. The unit number determines the sensor used. */
311 /** A pointer to the PDD factory that created this device. */
312 DTemplateCameraScPddFactory* iPhysicalDevice;
313 /** Ptr to a buffer large enough to hold the variable sized capabilities structure. */
315 /** The size of the variable sized capabilities structure. */
317 /** The capabilities of this device. */
318 TCameraCapsV02* iCaps;
319 /** The current configuration of this device. */
320 TCameraConfigV02 iConfig;
321 /** The current capture mode of the camera. */
322 TDevCamCaptureMode iCaptureMode;
323 /** Abstracted interface to the sensor */
325 /** Current state of the channel (configured, capturing etc) */
330 XXX - This structure holds information pertaining to the logo to be rendered in
331 "photos" returned by the template camera driver. This structure is temporary and
332 should be removed when changing this template into a "real" camera driver.
338 TUint8 iPixelData[80 * 61 * 3 + 1];
339 TUint8 iPixelData2[80 * 61 * 3 + 1];
342 #endif /* __CAMERASC_PLAT_H__ */