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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
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 |
|
17 // |
|
18 // |
|
19 |
|
20 #ifndef __CAMERASC_PLAT_H__ |
|
21 #define __CAMERASC_PLAT_H__ |
|
22 |
|
23 #include <drivers/camerasc.h> |
|
24 #include <pixelformats.h> |
|
25 |
|
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 |
|
30 |
|
31 /** Total number of image capture requests that can be handled by the sensor at one time */ |
|
32 const TInt KTotalCameraRequests = 2; |
|
33 |
|
34 /** NaviEngine specific panics that can be thrown by the shared chunk camera driver */ |
|
35 enum TTemplateCameraScPddPanic |
|
36 { |
|
37 /** Start() has been called before SetConfig() */ |
|
38 ENotConfigured, |
|
39 /** Unable to power down the camera hardware */ |
|
40 ECannotPowerDown, |
|
41 /** Buffer passed to DSensorIf::FrameSizeCaps() by LDD is too small */ |
|
42 ECapsBufferTooSmall |
|
43 }; |
|
44 |
|
45 /** |
|
46 The physical device (factory class) for the NaviEngine shared chunk camera driver. |
|
47 |
|
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. |
|
50 */ |
|
51 class DTemplateCameraScPddFactory : public DPhysicalDevice |
|
52 { |
|
53 public: |
|
54 |
|
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); |
|
63 |
|
64 private: |
|
65 |
|
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. */ |
|
69 TUint iUnitsOpenMask; |
|
70 /** A mutex to protect access to the unit information mask. */ |
|
71 NFastMutex iUnitInfoMutex; |
|
72 |
|
73 friend class DTemplateCameraScPdd; |
|
74 }; |
|
75 |
|
76 /** |
|
77 Defines the interface for notification of an image being captured. |
|
78 |
|
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. |
|
81 */ |
|
82 class MSensorObserver |
|
83 { |
|
84 public: |
|
85 |
|
86 virtual TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr) = 0; |
|
87 }; |
|
88 |
|
89 /** |
|
90 Defines an abstract base class for implementing concrete classes for camera sensors. |
|
91 |
|
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. |
|
94 */ |
|
95 class DSensorIf : public DBase |
|
96 { |
|
97 public: |
|
98 |
|
99 /** |
|
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. |
|
102 */ |
|
103 virtual TInt DoCreate() = 0; |
|
104 |
|
105 /** |
|
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. |
|
111 */ |
|
112 virtual TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf) = 0; |
|
113 |
|
114 /** |
|
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. |
|
122 */ |
|
123 virtual TInt GetCaps(TCameraCapsV02*& aCameraCaps) = 0; |
|
124 |
|
125 /** |
|
126 Powers up the sensor. |
|
127 */ |
|
128 virtual TInt RequestPower() = 0; |
|
129 |
|
130 /** |
|
131 Powers down the sensor. |
|
132 */ |
|
133 virtual TInt RelinquishPower() = 0; |
|
134 |
|
135 /** |
|
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. |
|
144 */ |
|
145 virtual TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0; |
|
146 |
|
147 /** |
|
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. |
|
154 */ |
|
155 virtual TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr) = 0; |
|
156 |
|
157 /** |
|
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. |
|
160 */ |
|
161 virtual TInt Stop() = 0; |
|
162 |
|
163 /** |
|
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. |
|
169 */ |
|
170 virtual TInt SetConfig(const TCameraConfigV02& aConfig); |
|
171 |
|
172 protected: |
|
173 |
|
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*/ |
|
177 TBool iEnabled; |
|
178 /** Width of the frames to be captured in pixels */ |
|
179 TInt iWidth; |
|
180 /** Height of the frames to be captured in pixels */ |
|
181 TInt iHeight; |
|
182 /** Number of bytes from the start of one line to the start of the next */ |
|
183 TInt iLineOffset; |
|
184 /** The number of requests setup ready for transfer */ |
|
185 TInt iPendingRequests; |
|
186 /** The next request to be setup ready for transfer */ |
|
187 TUint iNextRequest; |
|
188 /** The configuration in which to capture images */ |
|
189 TCameraConfigV02 iConfig; |
|
190 }; |
|
191 |
|
192 /** |
|
193 This class provides an abstract interface to the Template sensor. |
|
194 */ |
|
195 class DTemplateSensorIf : public DSensorIf |
|
196 { |
|
197 public: |
|
198 |
|
199 DTemplateSensorIf(MSensorObserver& aObserver, TDfcQue* aDFCQueue); |
|
200 TInt DoCreate(); |
|
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); |
|
206 TInt RequestPower(); |
|
207 TInt RelinquishPower(); |
|
208 TInt Start(TDevCamCaptureMode aCaptureMode, TLinAddr aLinAddr, TPhysAddr aPhysAddr); |
|
209 TInt Stop(); |
|
210 TInt CaptureNextImage(TLinAddr aLinAddr, TPhysAddr aPhysAddr); |
|
211 |
|
212 // Static callbacks for various sensor related asynchronous functions |
|
213 static TInt HostPowerCallback(TAny* aPtr, TAny* aPoweredUp); |
|
214 static TInt SensorClkReqCallback(TAny* aPtr); |
|
215 |
|
216 private: |
|
217 |
|
218 /** X position at which to display the logo */ |
|
219 TInt iX; |
|
220 /** Y position at which to display the logo */ |
|
221 TInt iY; |
|
222 /** Current X direction and speed at which the logo is moving */ |
|
223 TInt iXDirection; |
|
224 /** Current Y direction and speed at which the logo is moving */ |
|
225 TInt iYDirection; |
|
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 */ |
|
231 TDfcQue* iDFCQueue; |
|
232 /** DFCs used for image capture timer callbacks happeing in our DFC thread */ |
|
233 TDfc *iImageTimerDFCs[KTotalCameraRequests]; |
|
234 |
|
235 /* Used for cheesy animation effect */ |
|
236 TUint8 iCounter; |
|
237 TBool iFlipSwitch; |
|
238 }; |
|
239 |
|
240 /** |
|
241 The physical device driver for the NaviEngine shared chunk camera driver. |
|
242 |
|
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. |
|
247 */ |
|
248 class DTemplateCameraScPdd : public DCameraScPdd, public MSensorObserver |
|
249 { |
|
250 private: |
|
251 |
|
252 /** States in which the channel can be */ |
|
253 enum TState |
|
254 { |
|
255 /** Channel created but not yet configured */ |
|
256 EUnconfigured, |
|
257 /** Channel configured but idle and not capturing images */ |
|
258 EConfigured, |
|
259 /** Channel capturing images */ |
|
260 ECapturing |
|
261 }; |
|
262 |
|
263 public: |
|
264 |
|
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); |
|
274 TInt Stop(); |
|
275 void PowerDown(); |
|
276 TInt CapsSize(); |
|
277 TInt FrameSizeCaps(TDevCamCaptureMode aCaptureMode, TUidPixelFormat aUidPixelFormat, TDes8& aFrameSizeCapsBuf); |
|
278 |
|
279 /** |
|
280 Sets the sensor brightness to the desired setting. |
|
281 |
|
282 @param aValue A verified brightness setting. |
|
283 @return KErrNone if successful, KErrNotSupported if not supported. |
|
284 */ |
|
285 TInt SetBrightness(TUint aBrightness); |
|
286 |
|
287 /** |
|
288 Sets the sensor contrast to the desired setting. |
|
289 |
|
290 @param aValue A verified contrast setting. |
|
291 @return KErrNone if successful, KErrNotSupported if not supported. |
|
292 */ |
|
293 TInt SetContrast(TUint aContrast); |
|
294 |
|
295 /** |
|
296 Sets the sensor color effect to the desired setting. |
|
297 |
|
298 @param aValue A verified color effect setting. |
|
299 @return KErrNone if successful, KErrNotSupported if not supported. |
|
300 */ |
|
301 TInt SetColorEffect(TUint aColorEffect); |
|
302 |
|
303 private: |
|
304 |
|
305 TInt NotifyImageCaptureEvent(TInt aResult, TLinAddr& aLinAddr, TPhysAddr& aPhysAddr); |
|
306 |
|
307 private: |
|
308 |
|
309 /** The unit number of this channel. The unit number determines the sensor used. */ |
|
310 TInt iUnit; |
|
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. */ |
|
314 TUint8* iCapsBuffer; |
|
315 /** The size of the variable sized capabilities structure. */ |
|
316 TUint iCapsSize; |
|
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 */ |
|
324 DSensorIf* iSensor; |
|
325 /** Current state of the channel (configured, capturing etc) */ |
|
326 TState iState; |
|
327 }; |
|
328 |
|
329 /** |
|
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. |
|
333 */ |
|
334 struct SLogo |
|
335 { |
|
336 TUint iWidth; |
|
337 TUint iHeight; |
|
338 TUint8 iPixelData[80 * 61 * 3 + 1]; |
|
339 TUint8 iPixelData2[80 * 61 * 3 + 1]; |
|
340 }; |
|
341 |
|
342 #endif /* __CAMERASC_PLAT_H__ */ |
|