1 /*---------------------------------------------------------------------------*
2   Project:     WPAD library
3   File:        wpad.h
4   Programmers: TOKUNAGA, Yasuhiro
5                HIRATSU Daisuke
6                FUKUDA Takahiro
7                TOJO Haruki
8 
9   Copyright (C) 2005-2006 Nintendo.  All rights reserved.
10 
11   These coded instructions, statements, and computer programs contain
12   proprietary information of Nintendo of America Inc. and/or Nintendo
13   Company Ltd., and are protected by Federal copyright law.  They may
14   not be disclosed to third parties or copied or duplicated in any form,
15   in whole or in part, without the prior written consent of Nintendo.
16 
17   $Log: wpad.h,v $
18   Revision 1.43  08/15/2006 01:00:08  tojo
19   (none)
20 
21   Revision 1.42  08/14/2006 17:45:02  tojo
22   (none)
23 
24   Revision 1.41  08/14/2006 16:58:05  tojo
25   Modified WPADMEM API.
26 
27   Revision 1.40  08/14/2006 07:49:11  tojo
28   (none)
29 
30   Revision 1.39  2006/08/11 10:19:23  yasumoto_yoshitaka
31   suppress padding warning
32 
33   Revision 1.38  08/11/2006 07:53:55  tojo
34   Added embedded memory APIs.
35 
36   Revision 1.37  08/10/2006 01:18:42  tojo
37   Added dpd full mode.
38   Changed system config APIs.
39 
40   Revision 1.36  08/07/2006 00:18:16  tojo
41   (none)
42 
43   Revision 1.35  08/03/2006 13:09:34  tojo
44   Moved some config api to private APIs.
45 
46   Revision 1.34  08/03/2006 11:54:45  tojo
47   Changed clamp APIs.
48 
49   Revision 1.33  08/01/2006 06:03:18  tojo
50   (none)
51 
52   Revision 1.32  07/20/2006 01:18:12  tojo
53   Added WPADIsMotorEnabled.
54 
55   Revision 1.31  07/19/2006 08:14:43  tojo
56   Changed argument type u8 to u16 at WPADSetDisableChannel
57 
58   Revision 1.30  07/18/2006 10:04:49  tojo
59   Added WPAD_STRM_INTERVAL
60   Changed WPAD_DISABLED_WIFI_*
61 
62   Revision 1.29  07/04/2006 08:16:52  tojo
63   Added speaker/config/motor functions
64 
65   Revision 1.28  06/30/2006 08:59:19  tojo
66   Added WPADGetWorkMemorySize().
67 
68   Revision 1.27  06/17/2006 07:00:55  tojo
69   (none)
70 
71   Revision 1.26  06/17/2006 05:19:13  tojo
72   Added WPAD_ADD_LEN
73   Removed WPAD_ACC_1G_VALUE, WPAD_FS_ACC_1G_VALUE
74 
75   Revision 1.25  06/16/2006 04:30:50  tojo
76   Added WPAD_CLEAR_EVT_BUSY.
77   Changed WPAD_CL_STICK_RESO.
78 
79   Revision 1.24  06/15/2006 07:04:03  tojo
80   Changed API of WPADGetAccGravityUnit.
81 
82   Revision 1.22  06/15/2006 05:46:05  tojo
83   (none)
84 
85   Revision 1.21  06/15/2006 05:20:33  tojo
86   Added WPADGetAccGravityUnit.
87   Removed WPADGetOrigin.
88   Resumed WPADRecalibrate for backward compatibility.
89 
90   Revision 1.20  06/14/2006 11:31:14  tojo
91   Added WPADGetRegisteredDevNum().
92 
93   Revision 1.19  06/14/2006 10:49:05  tojo
94   Fixed typo : Extention -> Extension.
95   Removed WPADIsEmulator, WPADRecalibrate.
96   Added WPADIsSpeakerEnabled.
97 
98   Revision 1.18  06/13/2006 14:21:54  tojo
99   Added some macros.
100 
101   Revision 1.17  06/13/2006 11:45:14  tojo
102   Added delete all link keys handler.
103 
104   Revision 1.16  06/13/2006 06:29:55  tojo
105   (none)
106 
107   Revision 1.15  06/13/2006 06:05:34  tojo
108   Added
109    WPADSetExtentionCallback
110    WPADSetConnectCallback
111    WPADIsEmulator
112 
113   Revision 1.14  06/12/2006 11:42:18  ekwon
114   New API to query enable/disable state of DPD.
115 
116   Revision 1.13  06/12/2006 06:05:44  tojo
117   (none)
118 
119   Revision 1.12  06/12/2006 00:07:39  tojo
120   Changed some API
121   Defined classic controller button mappings
122 
123   Revision 1.11  2006/06/05 11:47:43  tojo
124   Defined WPADOrigin.
125   Added WPADGetOrigin.
126 
127   Revision 1.10  06/03/2006 10:00:50  tojo
128   Switched WPAD_BUTTON_C and WPAD_BUTTON_Z
129 
130   Revision 1.9  06/01/2006 08:53:36  tojo
131   Changed the declaration of WPADSyncCallback
132 
133   Revision 1.8  05/25/2006 13:00:33  tojo
134   wrapped wud api
135 
136   Revision 1.7  05/25/2006 12:21:04  tojo
137   added WPADRegisterAllocator(),
138 
139   Revision 1.6  05/23/2006 05:48:26  tojo
140   added WPAD_DPD_* and WPAD_SPEAKER_*
141 
142   Revision 1.5  05/17/2006 12:37:30  ekwon
143   Added NearEmpty field to WPADInfo.
144 
145   Revision 1.4  05/17/2006 04:59:33  kawaset
146   Added definitions for production version controllers. Use preprocessor macro WPADEMU for backwards compatibility.
147 
148   Revision 1.3  02/07/2006 11:44:09  yasuh-to
149   Deleted structure for Classic Controller. CL is not release at SDK1.0.
150 
151  *---------------------------------------------------------------------------*/
152 
153 #ifndef __WPAD_H__
154 #define __WPAD_H__
155 
156 #include <revolution/types.h>
157 #include <revolution/os.h>
158 
159 #ifdef __cplusplus
160 extern "C" {
161 #endif
162 
163 #define WPAD_CHAN0                    0
164 #define WPAD_CHAN1                    1
165 #define WPAD_CHAN2                    2
166 #define WPAD_CHAN3                    3
167 
168 #define WPAD_MAX_CONTROLLERS          4
169 
170 #define WPAD_MOTOR_STOP               0
171 #define WPAD_MOTOR_RUMBLE             1
172 
173 #ifndef WPADEMU
174 // Under construction. These definitions are subject to change.
175 
176 #define WPAD_BUTTON_LEFT              0x0001
177 #define WPAD_BUTTON_RIGHT             0x0002
178 #define WPAD_BUTTON_DOWN              0x0004
179 #define WPAD_BUTTON_UP                0x0008
180 #define WPAD_BUTTON_PLUS              0x0010
181 #define WPAD_BUTTON_2                 0x0100
182 #define WPAD_BUTTON_1                 0x0200
183 #define WPAD_BUTTON_B                 0x0400
184 #define WPAD_BUTTON_A                 0x0800
185 #define WPAD_BUTTON_MINUS             0x1000
186 #define WPAD_BUTTON_HOME              0x8000
187 
188 #define WPAD_BUTTON_Z                 0x2000
189 #define WPAD_BUTTON_C                 0x4000
190 
191 // backwards compatibility
192 #define WPAD_BUTTON_START             WPAD_BUTTON_PLUS
193 #define WPAD_BUTTON_SELECT            WPAD_BUTTON_MINUS
194 #define WPAD_BUTTON_SMALL_A           WPAD_BUTTON_1
195 #define WPAD_BUTTON_SMALL_B           WPAD_BUTTON_2
196 
197 // for classic controller extension
198 #define WPAD_CL_BUTTON_UP             0x0001
199 #define WPAD_CL_BUTTON_LEFT           0x0002
200 #define WPAD_CL_TRIGGER_ZR            0x0004
201 #define WPAD_CL_BUTTON_X              0x0008
202 #define WPAD_CL_BUTTON_A              0x0010
203 #define WPAD_CL_BUTTON_Y              0x0020
204 #define WPAD_CL_BUTTON_B              0x0040
205 #define WPAD_CL_TRIGGER_ZL            0x0080
206 #define WPAD_CL_RESERVED              0x0100
207 #define WPAD_CL_TRIGGER_R             0x0200
208 #define WPAD_CL_BUTTON_PLUS           0x0400
209 #define WPAD_CL_BUTTON_HOME           0x0800
210 #define WPAD_CL_BUTTON_MINUS          0x1000
211 #define WPAD_CL_TRIGGER_L             0x2000
212 #define WPAD_CL_BUTTON_DOWN           0x4000
213 #define WPAD_CL_BUTTON_RIGHT          0x8000
214 
215 
216 #define WPAD_DPD_OFF                  0
217 #define WPAD_DPD_STD                  1
218 #define WPAD_DPD_EXP                  3
219 #define WPAD_DPD_FULL                 5
220 
221 #define WPAD_DPD_MAX_OBJECTS          4
222 #define WPAD_DPD_ANGLE               42.0f  // viewing angle
223 #define WPAD_DPD_IMG_RESO_WX       1024     // DPD image resolution
224 #define WPAD_DPD_IMG_RESO_WY        768
225 
226 #define WPAD_SPEAKER_OFF              0
227 #define WPAD_SPEAKER_ON               1
228 #define WPAD_SPEAKER_MUTE             2
229 #define WPAD_SPEAKER_MUTE_OFF         3
230 #define WPAD_SPEAKER_PLAY             4
231 
232 #define WPAD_ACC_RESO              1024     // accelerometer resolution
233 #define WPAD_ACC_MAX                  3.4f  // valid gravity = 3.4G
234 
235 #define WPAD_FS_STICK_RESO          256     // stick resolution of FreeStyle unit
236 #define WPAD_FS_ACC_RESO           1024     // accelerometer resolution of FreeStyle unit
237 #define WPAD_FS_ACC_MAX               2.1f  // valid gravity = 2.1G
238 
239 #define WPAD_CL_STICK_RESO         1024
240 #define WPAD_CL_TRIGGER_RESO        256
241 
242 // device type
243 #define WPAD_DEV_CORE                 0
244 #define WPAD_DEV_FREESTYLE            1
245 #define WPAD_DEV_CLASSIC              2
246 #define WPAD_DEV_UNKNOWN            255
247 #define WPAD_DEV_NOT_FOUND          253     // For backwards compatibility. Don't use.
248 
249 // data format of Core
250 #define WPAD_FMT_CORE                 0     // only buttons
251 #define WPAD_FMT_CORE_ACC             1     // buttons, motion sensor
252 #define WPAD_FMT_CORE_ACC_DPD         2     // buttons, motion sensor, pointing
253 // data format of Core + Nunchaku
254 #define WPAD_FMT_FREESTYLE            3     // buttons, nunchaku
255 #define WPAD_FMT_FREESTYLE_ACC        4     // buttons, motion sensor, nunchaku
256 #define WPAD_FMT_FREESTYLE_ACC_DPD    5     // buttons, motion sensor, pointing, nunchaku
257 // data format of Core + Classic Controller
258 #define WPAD_FMT_CLASSIC              6     // buttons, classic
259 #define WPAD_FMT_CLASSIC_ACC          7     // buttons, motion sensor, classic
260 #define WPAD_FMT_CLASSIC_ACC_DPD      8     // buttons, motion sensor, pointing, classic
261 // data format of Core + DPD full mode
262 #define WPAD_FMT_CORE_ACC_DPD_FULL    9     // buttons, motion sensor, pointing
263 
264 
265 #define WPAD_STATE_DISABLED           0
266 #define WPAD_STATE_ENABLING           1
267 #define WPAD_STATE_ENABLED            2
268 #define WPAD_STATE_SETUP              3
269 #define WPAD_STATE_DISABLING          4
270 
271 // disable channel to avoid WiFi interference.
272 #define WPAD_DISABLE_CLEAR            0x0000    // enable all range
273 #define WPAD_DISABLE_WIFI_CHAN_1      0x0001
274 #define WPAD_DISABLE_WIFI_CHAN_2      0x0002
275 #define WPAD_DISABLE_WIFI_CHAN_3      0x0004
276 #define WPAD_DISABLE_WIFI_CHAN_4      0x0008
277 #define WPAD_DISABLE_WIFI_CHAN_5      0x0010
278 #define WPAD_DISABLE_WIFI_CHAN_6      0x0020
279 #define WPAD_DISABLE_WIFI_CHAN_7      0x0040
280 #define WPAD_DISABLE_WIFI_CHAN_8      0x0080
281 #define WPAD_DISABLE_WIFI_CHAN_9      0x0100
282 #define WPAD_DISABLE_WIFI_CHAN_10     0x0200
283 #define WPAD_DISABLE_WIFI_CHAN_11     0x0400
284 #define WPAD_DISABLE_WIFI_CHAN_12     0x0800
285 #define WPAD_DISABLE_WIFI_CHAN_13     0x1000
286 #define WPAD_DISABLE_WIFI_CHAN_14     0x2000
287 
288 // battery level
289 #define WPAD_BATTERY_LEVEL_LOW        1
290 #define WPAD_BATTERY_LEVEL_MEDIUM     2
291 #define WPAD_BATTERY_LEVEL_HIGH       3
292 #define WPAD_BATTERY_LEVEL_MAX        4
293 
294 #define WPAD_LED_CHAN_1             0x1
295 #define WPAD_LED_CHAN_2             0x2
296 #define WPAD_LED_CHAN_3             0x4
297 #define WPAD_LED_CHAN_4             0x8
298 
299 #define WPAD_SYNC_EVT_BUSY           -1
300 #define WPAD_SYNC_EVT_START           0
301 #define WPAD_SYNC_EVT_DONE            1
302 
303 #define WPAD_CLEAR_EVT_BUSY          -1
304 #define WPAD_CLEAR_EVT_START          0
305 #define WPAD_CLEAR_EVT_DONE           1
306 
307 #define WPAD_ADDR_LEN                 6
308 
309 #define WPAD_STRM_INTERVAL            OSNanosecondsToTicks(6666667)
310 
311 // clamp algorithm for stick
312 #define WPAD_STICK_CLAMP_OCTA_WITH_PLAY         0
313 #define WPAD_STICK_CLAMP_OCTA_WITHOUT_PLAY      1
314 #define WPAD_STICK_CLAMP_CIRCLE_WITH_PLAY       2
315 #define WPAD_STICK_CLAMP_CIRCLE_WITHOUT_PLAY    3
316 // clamp algorithm for trigger
317 #define WPAD_TRIGGER_FIXED_BASE                 0
318 #define WPAD_TRIGGER_INDIVIDUAL_BASE            1
319 // clamp algorithm for accelerometer
320 #define WPAD_ACC_CLAMP_CUBE                     0
321 #define WPAD_ACC_CLAMP_SPHERE                   1
322 
323 #define WPAD_SENSOR_BAR_POS_BOTTOM              0
324 #define WPAD_SENSOR_BAR_POS_TOP                 1
325 
326 #define WPAD_MEM_GAMEDATA_LEN         3888
327 #define WPAD_MEM_FACEDATA_LEN         1800
328 
329 #else
330 // SI-based WPAD
331 
332 #define WPAD_BUTTON_HOME              0x0001
333 #define WPAD_BUTTON_SELECT            0x0002
334 #define WPAD_BUTTON_A                 0x0004
335 #define WPAD_BUTTON_B                 0x0008
336 #define WPAD_BUTTON_SMALL_A           0x0010
337 #define WPAD_BUTTON_SMALL_B           0x0020
338 #define WPAD_BUTTON_START             0x0100
339 #define WPAD_BUTTON_UP                0x0200
340 #define WPAD_BUTTON_DOWN              0x0400
341 #define WPAD_BUTTON_RIGHT             0x0800
342 #define WPAD_BUTTON_LEFT              0x1000
343 #define WPAD_BUTTON_Z1                0x2000
344 #define WPAD_BUTTON_Z2                0x4000
345 #define WPAD_BUTTON_X                 WPAD_BUTTON_SMALL_A
346 #define WPAD_BUTTON_Y                 WPAD_BUTTON_SMALL_B
347 #define WPAD_TRIGGER_Z                WPAD_BUTTON_Z1
348 #define WPAD_TRIGGER_R                WPAD_BUTTON_Z2
349 #define WPAD_TRIGGER_L                0x8000
350 
351 #define WPAD_DPD_MAX_OBJECTS          4
352 #define WPAD_DPD_ANGLE               42.0f  // viewing angle
353 #define WPAD_DPD_IMG_RESO_WX       1024     // DPD image resolution
354 #define WPAD_DPD_IMG_RESO_WY        768
355 
356 #define WPAD_ACC_RESO              1024     // accelerometer resolution
357 #define WPAD_ACC_1G_VALUE           205     // gravity value
358 
359 #define WPAD_FS_STICK_RESO          256     // stick resolution of FreeStyle unit
360 #define WPAD_FS_ACC_RESO           1024     // accelerometer resolution of FreeStyle unit
361 #define WPAD_FS_ACC_1G_VALUE        205     // gravity value of FreeStyle unit
362 
363 #define WPAD_DEV_CORE                 0
364 #define WPAD_DEV_FREESTYLE            1
365 #define WPAD_DEV_DOLPHIN            254
366 #define WPAD_DEV_UNKNOWN            255
367 #define WPAD_DEV_NOT_FOUND          253     // For backwards compatibility. Don't use.
368 
369 #define WPAD_FMT_CORE                 0     // data format of Core controller
370 #define WPAD_FMT_FREESTYLE            1     // data format of FreeStyle controller
371 #define WPAD_FMT_DOLPHIN            255     // data format of Dolphin controller(for debug)
372 
373 #endif
374 
375 #define WPAD_ERR_NONE                 0
376 #define WPAD_ERR_NO_CONTROLLER       -1
377 #define WPAD_ERR_BUSY                -2
378 #define WPAD_ERR_TRANSFER            -3
379 #define WPAD_ERR_INVALID             -4
380 
381 #ifdef  __MWERKS__
382 #pragma warn_padding off
383 #endif
384 typedef struct DPDObject
385 {
386     s16       x;                    // 0 <=  x   < WPAD_DPD_IMG_RESO_WX
387     s16       y;                    // 0 <=  y   < WPAD_DPD_IMG_RESO_WY
388     u16       size;
389     u8        traceId;
390     // 1 byte padding
391 } DPDObject;
392 #ifdef  __MWERKS__
393 #pragma warn_padding reset
394 #endif
395 
396 #ifdef  __MWERKS__
397 #pragma warn_padding off
398 #endif
399 typedef struct DPDObjEx
400 {
401     s16       range_x1;
402     s16       range_y1;
403     s16       range_x2;
404     s16       range_y2;
405     u16       pixel;
406     s8        radius;
407     // 1 byte padding
408 } DPDObjEx;
409 #ifdef  __MWERKS__
410 #pragma warn_padding reset
411 #endif
412 
413 typedef struct WPADStatus
414 {
415     u16       button;               // Or-ed WPAD_BUTTON_* bits
416     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
417     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
418     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
419     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
420 
421     u8        dev;                  // one of WPAD_DEV_* number
422     s8        err;                  // one of WPAD_ERR_* number
423 } WPADStatus;
424 
425 typedef struct WPADFSStatus
426 {
427     u16       button;               // Or-ed WPAD_BUTTON_* bits
428     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
429     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
430     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
431     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
432 
433     u8        dev;                  // one of WPAD_DEV_* number
434     s8        err;                  // one of WPAD_ERR_* number
435 
436     s16       fsAccX;               // -WPAD_FS_ACC_RESO/2 <= fsAccX < WPAD_ACC_RESO/2
437     s16       fsAccY;               // -WPAD_FS_ACC_RESO/2 <= fsAccY < WPAD_ACC_RESO/2
438     s16       fsAccZ;               // -WPAD_FS_ACC_RESO/2 <= fsAccZ < WPAD_ACC_RESO/2
439     s8        fsStickX;             // -WPAD_FS_STICK_RESO/2 <= fsStickX < WPAD_FS_STICK_RESO/2
440     s8        fsStickY;             // -WPAD_FS_STICK_RESO/2 <= fsStickY < WPAD_FS_STICK_RESO/2
441 } WPADFSStatus;
442 
443 typedef struct WPADCLStatus
444 {
445     u16       button;               // Or-ed WPAD_BUTTON_* bits
446     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
447     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
448     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
449     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
450 
451     u8        dev;                  // one of WPAD_DEV_* number
452     s8        err;                  // one of WPAD_ERR_* number
453 
454     u16       clButton;             // Or-ed WPAD_CL_BUTTON * bits
455     s16       clLStickX;            // -WPAD_CL_STICK_RESO/2 <= clLStickX < WPAD_CL_STICK_RESO/2
456     s16       clLStickY;            // -WPAD_CL_STICK_RESO/2 <= clLStickY < WPAD_CL_STICK_RESO/2
457     s16       clRStickX;            // -WPAD_CL_STICK_RESO/2 <= clRStickX < WPAD_CL_STICK_RESO/2
458     s16       clRStickY;            // -WPAD_CL_STICK_RESO/2 <= clRStickY < WPAD_CL_STICK_RESO/2
459     u8        clTriggerL;           // 0 <= clTriggerL < WPAD_CL_TRIGGER_RESO
460     u8        clTriggerR;           // 0 <= clTriggerR < WPAD_CL_TRIGGER_RESO
461 } WPADCLStatus;
462 
463 typedef struct WPADStatusEx
464 {
465     u16       button;               // Or-ed WPAD_BUTTON_* bits
466     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
467     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
468     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
469     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
470 
471     u8        dev;                  // one of WPAD_DEV_* number
472     s8        err;                  // one of WPAD_ERR_* number
473 
474     DPDObjEx  exp[WPAD_DPD_MAX_OBJECTS];
475 
476 } WPADStatusEx;
477 
478 typedef struct WPADInfo
479 {
480     BOOL dpd;                       // the active status of pointer unit
481     BOOL speaker;                   // the active status of speaker unit
482     BOOL attach;                    // whether an attachment is installed (=1) or not (=0)
483     BOOL lowBat;                    // whether the current battery level is lower than a threshold (0x20)
484     BOOL nearempty;                 // sound buffer is nearly empty
485     u8 battery;                     // the current battery level (WPAD_BATTERY_LEVEL_*)
486     u8 led;                         // the current pattern of 4 LEDs
487     u8 protocol;                    // not used
488     u8 firmware;                    // not used
489 } WPADInfo;
490 
491 typedef struct WPADAcc
492 {
493     s16 x;
494     s16 y;
495     s16 z;
496 } WPADAcc;
497 
498 
499 typedef void   ( *WPADExtensionCallback         )( s32  chan, s32 result );
500 typedef void   ( *WPADSamplingCallback          )( s32  chan );
501 typedef void   ( *WPADConnectCallback           )( s32  chan, s32 reason );
502 typedef void   ( *WPADCallback                  )( s32  chan, s32 result );
503 typedef void * ( *WPADAlloc                     )( u32  size );
504 typedef u8     ( *WPADFree                      )( void *ptr );
505 typedef void   ( *WPADSyncDeviceCallback        )( s32  result, s32 num );
506 typedef void   ( *WPADClearDeviceCallback       )( s32  result );
507 typedef void   ( *WPADFlushCallback             )( u32  result );
508 
509 #define WPADButtonDown( buttonLast, button )   \
510     ( (u16) (((buttonLast) ^ (button)) & (button)) )
511 
512 #define WPADButtonUp( buttonLast, button )   \
513     ( (u16) (((buttonLast) ^ (button)) & (buttonLast)) )
514 
515 #define WPADStartMotor( chan )  WPADControlMotor( ( chan ), WPAD_MOTOR_RUMBLE )
516 #define WPADStopMotor( chan )   WPADControlMotor( ( chan ), WPAD_MOTOR_STOP   )
517 
518 
519 #ifdef WPADEMU
520 // only for WPADEmu
521 BOOL WPADAttach                 ( s32 chan );
522 BOOL WPADRecalibrate            ( s32 chan );
523 
524 #endif
525 
526 
527 void WPADInit                   ( void );
528 void WPADShutdown               ( void );
529 void WPADRegisterAllocator      ( WPADAlloc alloc, WPADFree free );
530 u32  WPADGetWorkMemorySize      ( void );
531 s32  WPADProbe                  ( s32 chan, u32 *type );
532 s32  WPADGetStatus              ( void );
533 u32  WPADGetDataFormat          ( s32 chan );
534 s32  WPADSetDataFormat          ( s32 chan, u32 fmt );
535 void WPADRead                   ( s32 chan, void *status );
536 void WPADSetAutoSamplingBuf     ( s32 chan, void *buf, u32 length);
537 u32  WPADGetLatestIndexInBuf    ( s32 chan );
538 void WPADGetAccGravityUnit      ( s32 chan, u32 type, WPADAcc *acc );
539 void WPADGetCLTriggerThreshold  ( s32 chan, u8 *left, u8 *right );
540 
541 #ifdef WPADEMU
542 void WPADClampStick             ( u32 fmt, void *status );
543 #else
544 void WPADClampStick             ( s32 chan, void *status, u32 type );
545 void WPADClampTrigger           ( s32 chan, void *status, u32 type );
546 void WPADClampAcc               ( s32 chan, void *status, u32 type );
547 #endif
548 
549 BOOL WPADIsDpdEnabled           ( s32 chan );
550 s32  WPADControlDpd             ( s32 chan, u32 command, WPADCallback callback );
551 void WPADDisconnect             ( s32 chan );
552 s32  WPADGetInfo                ( s32 chan, WPADInfo *info );
553 s32  WPADGetInfoAsync           ( s32 chan, WPADInfo *info, WPADCallback callback );
554 void WPADGetAddress             ( s32 chan, u8 *addr );
555 u8   WPADGetRegisteredDevNum    ( void );
556 u8   WPADGetRadioSensitivity    ( s32 chan );
557 
558 BOOL WPADIsSpeakerEnabled       ( s32 chan );
559 s32  WPADControlSpeaker         ( s32 chan, u32 command, WPADCallback callback );
560 u8   WPADGetSpeakerVolume       ( void );
561 void WPADSetSpeakerVolume       ( u8 volume );
562 s32  WPADSendStreamData         ( s32 chan, void *buf, u16 len );
563 
564 void WPADControlMotor           ( s32 chan, u32 command );
565 BOOL WPADIsMotorEnabled         ( void );
566 void WPADEnableMotor            ( BOOL enable );
567 
568 void WPADSetAutoSleepTime       ( u8 minute );
569 u8   WPADGetSensorBarPosition   ( void );
570 
571 BOOL WPADSaveConfig             ( WPADFlushCallback callback );
572 
573 s32  WPADReadGameData           ( s32 chan, void *p_buf, u16 len, u16 offset, WPADCallback callback );
574 s32  WPADWriteGameData          ( s32 chan, void *p_buf, u16 len, u16 offset, WPADCallback callback );
575 s32  WPADReadFaceData           ( s32 chan, void *p_buf, u16 len, u16 offset, WPADCallback callback );
576 s32  WPADWriteFaceData          ( s32 chan, void *p_buf, u16 len, u16 offset, WPADCallback callback );
577 void WPADSetGameTitle           ( const char *title );
578 void WPADSetGameTitleWChar      ( const u16  *title );
579 s32  WPADGetGameTitle           ( s32 chan, const char **title );
580 s32  WPADGetGameDataTimeStamp   ( s32 chan, OSTime *time );
581 
582 BOOL WPADSetDisableChannel      ( u16 disable );
583 BOOL WPADStartSyncDevice        ( void );
584 BOOL WPADStartClearDevice       ( void );
585 BOOL WPADStartSimpleSync        ( void );
586 BOOL WPADStopSimpleSync         ( void );
587 
588 
589 WPADSamplingCallback            WPADSetSamplingCallback     ( s32 chan, WPADSamplingCallback  callback );
590 WPADExtensionCallback           WPADSetExtensionCallback    ( s32 chan, WPADExtensionCallback callback );
591 WPADConnectCallback             WPADSetConnectCallback      ( s32 chan, WPADConnectCallback   callback );
592 WPADSyncDeviceCallback          WPADSetSyncDeviceCallback   ( WPADSyncDeviceCallback  callback );
593 WPADSyncDeviceCallback          WPADSetSimpleSyncCallback   ( WPADSyncDeviceCallback  callback );
594 WPADClearDeviceCallback         WPADSetClearDeviceCallback  ( WPADClearDeviceCallback callback );
595 
596 
597 #ifdef __cplusplus
598 }
599 #endif
600 
601 
602 #endif // __WPAD_H__
603