1 /*---------------------------------------------------------------------------*
2 Project: TwlSDK - camera - include
3 File: camera.h
4
5 Copyright 2007-2008 Nintendo. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Date:: 2008-09-17#$
14 $Rev: 8556 $
15 $Author: okubata_ryoma $
16 *---------------------------------------------------------------------------*/
17 #ifndef TWL_CAMERA_CAMERA_H_
18 #define TWL_CAMERA_CAMERA_H_
19
20 #include <twl/misc.h>
21 #include <twl/types.h>
22 #include <twl/hw/ARM9/ioreg.h>
23
24 #include <twl/camera/ARM9/camera_api.h>
25
26 #include <nitro/math.h>
27
28 #define CAMERA_GET_MAX_LINES(width) MATH_MIN((1024 / (width)), 16)
29 #define CAMERA_GET_LINE_BYTES(width) ((width) << 1)
30 #define CAMERA_GET_FRAME_BYTES(width, height) (CAMERA_GET_LINE_BYTES(width) * (height))
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 typedef enum {
37 CAMERA_OUTPUT_YUV,
38 CAMERA_OUTPUT_RGB
39 } CAMERAOutput;
40
41 typedef enum {
42 CAMERA_INTR_VSYNC_NONE = (0 << REG_CAM_CNT_IREQVS_SHIFT),
43 CAMERA_INTR_VSYNC_NEGATIVE_EDGE = (2 << REG_CAM_CNT_IREQVS_SHIFT),
44 CAMERA_INTR_VSYNC_POSITIVE_EDGE = (3 << REG_CAM_CNT_IREQVS_SHIFT)
45 } CAMERAIntrVsync;
46
47 /*---------------------------------------------------------------------------*
48 Name: CAMERA_Reset
49
50 Description: Hardware reset before I2C access.
51
52 Arguments: None.
53
54 Returns: None.
55 *---------------------------------------------------------------------------*/
56 void CAMERA_ResetCore( void );
CAMERA_Reset(void)57 SDK_INLINE void CAMERA_Reset( void )
58 {
59 if (OS_IsRunOnTwl() == TRUE)
60 {
61 CAMERA_ResetCore();
62 }
63 }
64
65 /*---------------------------------------------------------------------------*
66 Name: CAMERA_IsBusy
67
68 Description: Whether the camera is busy.
69
70 Arguments: None.
71
72 Returns: TRUE if the camera is busy.
73 *---------------------------------------------------------------------------*/
74 BOOL CAMERA_IsBusyCore( void );
CAMERA_IsBusy(void)75 SDK_INLINE BOOL CAMERA_IsBusy( void )
76 {
77 if (OS_IsRunOnTwl() == TRUE)
78 {
79 return CAMERA_IsBusyCore();
80 }
81 return FALSE;
82 }
83
84 /*---------------------------------------------------------------------------*
85 Name: CAMERA_Start
86
87 Description: Starts to receive camera data.
88
89 Arguments: None.
90
91 Returns: None.
92 *---------------------------------------------------------------------------*/
93 void CAMERA_StartCaptureCore( void );
CAMERA_StartCapture(void)94 SDK_INLINE void CAMERA_StartCapture( void )
95 {
96 if (OS_IsRunOnTwl() == TRUE)
97 {
98 CAMERA_StartCaptureCore();
99 }
100 }
101
102 /*---------------------------------------------------------------------------*
103 Name: CAMERA_Stop
104
105 Description: Stops receiving camera data.
106
107 Arguments: None.
108
109 Returns: None.
110 *---------------------------------------------------------------------------*/
111 void CAMERA_StopCaptureCore( void );
CAMERA_StopCapture(void)112 SDK_INLINE void CAMERA_StopCapture( void )
113 {
114 if (OS_IsRunOnTwl() == TRUE)
115 {
116 CAMERA_StopCaptureCore();
117 }
118 }
119
120 /*---------------------------------------------------------------------------*
121 Name: CAMERA_SetTrimmingParamsCenter
122
123 Description: Sets the camera trimming parameters by centering.
124 NOTE: You should call CAMERA_SetTrimming to enable trimming.
125
126 Arguments: destWidth: Width of the image to output
127 destHeight: Height of the image to output
128 srcWidth: Original image width
129 srcHeight: Original image height
130
131 Returns: None.
132 *---------------------------------------------------------------------------*/
133 void CAMERA_SetTrimmingParamsCenterCore(u16 destWidth, u16 destHeight, u16 srcWidth, u16 srcHeight);
CAMERA_SetTrimmingParamsCenter(u16 destWidth,u16 destHeight,u16 srcWidth,u16 srcHeight)134 SDK_INLINE void CAMERA_SetTrimmingParamsCenter(u16 destWidth, u16 destHeight, u16 srcWidth, u16 srcHeight)
135 {
136 if (OS_IsRunOnTwl() == TRUE)
137 {
138 CAMERA_SetTrimmingParamsCenterCore(destWidth, destHeight, srcWidth, srcHeight);
139 }
140 }
141
142 /*---------------------------------------------------------------------------*
143 Name: CAMERA_SetTrimmingParams
144
145 Description: Sets camera trimming parameters.
146 NOTE: width = x2 - x1; height = y2 - y1;
147 NOTE: You should call CAMERA_SetTrimming to enable trimming.
148
149 Arguments: x1: x-coordinate of the upper-left trimming point (multiple of 2)
150 y1: y-coordinate of the upper-left trimming point
151 x2: x-coordinate of the lower-right trimming point (multiple of 2)
152 y2: y-coordinate of the lower-right trimming point
153
154 Returns: None.
155 *---------------------------------------------------------------------------*/
156 void CAMERA_SetTrimmingParamsCore(u16 x1, u16 y1, u16 x2, u16 y2);
CAMERA_SetTrimmingParams(u16 x1,u16 y1,u16 x2,u16 y2)157 SDK_INLINE void CAMERA_SetTrimmingParams(u16 x1, u16 y1, u16 x2, u16 y2)
158 {
159 if (OS_IsRunOnTwl() == TRUE)
160 {
161 CAMERA_SetTrimmingParamsCore(x1, y1, x2, y2);
162 }
163 }
164
165 /*---------------------------------------------------------------------------*
166 Name: CAMERA_GetTrimmingParams
167
168 Description: Gets camera trimming parameters.
169 NOTE: width = x2 - x1; height = y2 - y1;
170 NOTE: You should call CAMERA_SetTrimming to enable trimming.
171
172 Arguments: x1: x-coordinate of the upper-left trimming point (multiple of 2)
173 y1: y-coordinate of the upper-left trimming point
174 x2: x-coordinate of the lower-right trimming point (multiple of 2)
175 y2: y-coordinate of the lower-right trimming point
176
177 Returns: None.
178 *---------------------------------------------------------------------------*/
179 void CAMERA_GetTrimmingParamsCore(u16* x1, u16* y1, u16* x2, u16* y2);
CAMERA_GetTrimmingParams(u16 * x1,u16 * y1,u16 * x2,u16 * y2)180 SDK_INLINE void CAMERA_GetTrimmingParams(u16* x1, u16* y1, u16* x2, u16* y2)
181 {
182 if (OS_IsRunOnTwl() == TRUE)
183 {
184 CAMERA_GetTrimmingParamsCore(x1, y1, x2, y2);
185 }
186 }
187
188 /*---------------------------------------------------------------------------*
189 Name: CAMERA_SetTrimming
190
191 Description: Enables or disables trimming.
192
193 Arguments: enabled: If set to TRUE, trimming will be enabled
194
195 Returns: None.
196 *---------------------------------------------------------------------------*/
197 void CAMERA_SetTrimmingCore( BOOL enabled );
CAMERA_SetTrimming(BOOL enabled)198 SDK_INLINE void CAMERA_SetTrimming( BOOL enabled )
199 {
200 if (OS_IsRunOnTwl() == TRUE)
201 {
202 CAMERA_SetTrimmingCore(enabled);
203 }
204 }
205
206 /*---------------------------------------------------------------------------*
207 Name: CAMERA_IsTrimming
208
209 Description: Determines whether trimming is enabled.
210
211 Arguments: None.
212
213 Returns: TRUE if trimming is enabled.
214 *---------------------------------------------------------------------------*/
215 BOOL CAMERA_IsTrimmingCore( void );
CAMERA_IsTrimming(void)216 SDK_INLINE BOOL CAMERA_IsTrimming( void )
217 {
218 if (OS_IsRunOnTwl() == TRUE)
219 {
220 return CAMERA_IsTrimmingCore();
221 }
222 return FALSE;
223 }
224
225 /*---------------------------------------------------------------------------*
226 Name: CAMERA_SetOutputFormat
227
228 Description: Sets the camera output format.
229
230 Arguments: output: One of the CAMERAOutput values to set
231
232 Returns: None.
233 *---------------------------------------------------------------------------*/
234 void CAMERA_SetOutputFormatCore( CAMERAOutput output );
CAMERA_SetOutputFormat(CAMERAOutput output)235 SDK_INLINE void CAMERA_SetOutputFormat( CAMERAOutput output )
236 {
237 if (OS_IsRunOnTwl() == TRUE)
238 {
239 CAMERA_SetOutputFormatCore(output);
240 }
241 }
242
243 /*---------------------------------------------------------------------------*
244 Name: CAMERA_GetOutputFormat
245
246 Description: Gets the camera output format.
247
248 Arguments: None.
249
250 Returns: One of the CAMERAOutput values.
251 *---------------------------------------------------------------------------*/
252 CAMERAOutput CAMERA_GetOutputFormatCore( void );
CAMERA_GetOutputFormat(void)253 SDK_INLINE CAMERAOutput CAMERA_GetOutputFormat( void )
254 {
255 if (OS_IsRunOnTwl() == TRUE)
256 {
257 return CAMERA_GetOutputFormatCore();
258 }
259 return CAMERA_OUTPUT_YUV;
260 }
261
262 /*---------------------------------------------------------------------------*
263 Name: CAMERA_GetErrorStatus
264
265 Description: Whether some line buffer errors have occurred.
266
267 Arguments: None.
268
269 Returns: TRUE if an error has occurred.
270 *---------------------------------------------------------------------------*/
271 BOOL CAMERA_GetErrorStatusCore( void );
CAMERA_GetErrorStatus(void)272 SDK_INLINE BOOL CAMERA_GetErrorStatus( void )
273 {
274 if (OS_IsRunOnTwl() == TRUE)
275 {
276 return CAMERA_GetErrorStatusCore();
277 }
278 return FALSE;
279 }
280
281 /*---------------------------------------------------------------------------*
282 Name: CAMERA_ClearBuffer
283
284 Description: Clears the line buffer and error status.
285
286 Arguments: None.
287
288 Returns: None.
289 *---------------------------------------------------------------------------*/
290 void CAMERA_ClearBufferCore( void );
CAMERA_ClearBuffer(void)291 SDK_INLINE void CAMERA_ClearBuffer( void )
292 {
293 if (OS_IsRunOnTwl() == TRUE)
294 {
295 CAMERA_ClearBufferCore();
296 }
297 }
298
299 /*---------------------------------------------------------------------------*
300 Name: CAMERA_SetTransferLines
301
302 Description: Sets the number of lines to store the buffer at once.
303
304 Arguments: lines: Number of lines
305
306 Returns: None.
307 *---------------------------------------------------------------------------*/
308 void CAMERA_SetTransferLinesCore( int lines );
CAMERA_SetTransferLines(int lines)309 SDK_INLINE void CAMERA_SetTransferLines( int lines )
310 {
311 if (OS_IsRunOnTwl() == TRUE)
312 {
313 CAMERA_SetTransferLinesCore(lines);
314 }
315 }
316
317 /*---------------------------------------------------------------------------*
318 Name: CAMERA_GetTransferLines
319
320 Description: Gets the number of lines to load the buffer at once.
321
322 Arguments: None.
323
324 Returns: The number of lines.
325 *---------------------------------------------------------------------------*/
326 int CAMERA_GetTransferLinesCore( void );
CAMERA_GetTransferLines(void)327 SDK_INLINE int CAMERA_GetTransferLines( void )
328 {
329 if (OS_IsRunOnTwl() == TRUE)
330 {
331 return CAMERA_GetTransferLinesCore();
332 }
333 return 0;
334 }
335
336 /*---------------------------------------------------------------------------*
337 Name: CAMERA_GetMaxLinesRound
338
339 Description: Rounds CAMERA_GET_MAX_LINES.
340
341 Arguments: width: Image width
342 height: Image height
343
344 Returns: Maximum lines.
345 *---------------------------------------------------------------------------*/
346 int CAMERA_GetMaxLinesRoundCore(u16 width, u16 height);
CAMERA_GetMaxLinesRound(u16 width,u16 height)347 SDK_INLINE int CAMERA_GetMaxLinesRound(u16 width, u16 height)
348 {
349 if (OS_IsRunOnTwl() == TRUE)
350 {
351 return CAMERA_GetMaxLinesRoundCore(width, height);
352 }
353 return 0;
354 }
355
356 /*---------------------------------------------------------------------------*
357 Name: CAMERA_GetBytesAtOnce
358
359 Description: Finds the one-time transfer size when receiving frame data from the camera buffer.
360
361 Arguments: width: Image width
362
363 Returns: Units.
364 *---------------------------------------------------------------------------*/
365 u32 CAMERA_GetBytesAtOnceCore(u16 width);
CAMERA_GetBytesAtOnce(u16 width)366 SDK_INLINE u32 CAMERA_GetBytesAtOnce(u16 width)
367 {
368 if (OS_IsRunOnTwl() == TRUE)
369 {
370 return CAMERA_GetBytesAtOnceCore(width);
371 }
372 return 0;
373 }
374
375
376 #ifdef __cplusplus
377 } /* extern "C" */
378 #endif
379
380 /* TWL_CAMERA_CAMERA_H_ */
381 #endif
382