1 /*---------------------------------------------------------------------------*
2   Project: WPAD library
3   File:    wpad.h
4 
5   Copyright (C) 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  *---------------------------------------------------------------------------*/
14 
15 #ifndef __WPAD_H__
16 #define __WPAD_H__
17 
18 #include <types.h>
19 #include <cafe/os.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define SENSOR_BAR_OFF				  0
26 #define SENSOR_BAR_ON				  1
27 
28 
29 #define WPAD_CHAN0                    0
30 #define WPAD_CHAN1                    1
31 #define WPAD_CHAN2                    2
32 #define WPAD_CHAN3                    3
33 #define WPAD_CHAN_INVALID            -1
34 
35 #define WPAD_MAX_CONTROLLERS          4
36 
37 #define WPAD_MOTOR_STOP               0
38 #define WPAD_MOTOR_RUMBLE             1
39 
40 #ifndef WPADEMU
41 // Under construction. These definitions are subject to change.
42 
43 #define WPAD_BUTTON_LEFT              0x0001
44 #define WPAD_BUTTON_RIGHT             0x0002
45 #define WPAD_BUTTON_DOWN              0x0004
46 #define WPAD_BUTTON_UP                0x0008
47 #define WPAD_BUTTON_PLUS              0x0010
48 #define WPAD_BUTTON_2                 0x0100
49 #define WPAD_BUTTON_1                 0x0200
50 #define WPAD_BUTTON_B                 0x0400
51 #define WPAD_BUTTON_A                 0x0800
52 #define WPAD_BUTTON_MINUS             0x1000
53 #define WPAD_BUTTON_HOME              0x8000
54 
55 #define WPAD_BUTTON_Z                 0x2000
56 #define WPAD_BUTTON_C                 0x4000
57 
58 // for backward compatibility
59 #define WPAD_BUTTON_START             WPAD_BUTTON_PLUS
60 #define WPAD_BUTTON_SELECT            WPAD_BUTTON_MINUS
61 #define WPAD_BUTTON_SMALL_A           WPAD_BUTTON_1
62 #define WPAD_BUTTON_SMALL_B           WPAD_BUTTON_2
63 
64 // for Classic Controller accessory extension
65 #define WPAD_CL_BUTTON_UP             0x0001
66 #define WPAD_CL_BUTTON_LEFT           0x0002
67 #define WPAD_CL_TRIGGER_ZR            0x0004
68 #define WPAD_CL_BUTTON_ZR             WPAD_CL_TRIGGER_ZR
69 #define WPAD_CL_BUTTON_X              0x0008
70 #define WPAD_CL_BUTTON_A              0x0010
71 #define WPAD_CL_BUTTON_Y              0x0020
72 #define WPAD_CL_BUTTON_B              0x0040
73 #define WPAD_CL_TRIGGER_ZL            0x0080
74 #define WPAD_CL_BUTTON_ZL             WPAD_CL_TRIGGER_ZL
75 #define WPAD_CL_RESERVED              0x0100
76 #define WPAD_CL_TRIGGER_R             0x0200
77 #define WPAD_CL_BUTTON_R              WPAD_CL_TRIGGER_R
78 #define WPAD_CL_BUTTON_PLUS           0x0400
79 #define WPAD_CL_BUTTON_HOME           0x0800
80 #define WPAD_CL_BUTTON_MINUS          0x1000
81 #define WPAD_CL_TRIGGER_L             0x2000
82 #define WPAD_CL_BUTTON_L              WPAD_CL_TRIGGER_L
83 #define WPAD_CL_BUTTON_DOWN           0x4000
84 #define WPAD_CL_BUTTON_RIGHT          0x8000
85 
86 // for URCC extension
87 #define WPAD_UC_BUTTON_UP             0x00000001
88 #define WPAD_UC_BUTTON_LEFT           0x00000002
89 #define WPAD_UC_TRIGGER_ZR            0x00000004
90 #define WPAD_UC_BUTTON_X              0x00000008
91 #define WPAD_UC_BUTTON_A              0x00000010
92 #define WPAD_UC_BUTTON_Y              0x00000020
93 #define WPAD_UC_BUTTON_B              0x00000040
94 #define WPAD_UC_TRIGGER_ZL            0x00000080
95 #define WPAD_UC_RESERVED              0x00000100
96 #define WPAD_UC_TRIGGER_R             0x00000200
97 #define WPAD_UC_BUTTON_PLUS           0x00000400
98 #define WPAD_UC_BUTTON_HOME           0x00000800
99 #define WPAD_UC_BUTTON_MINUS          0x00001000
100 #define WPAD_UC_TRIGGER_L             0x00002000
101 #define WPAD_UC_BUTTON_DOWN           0x00004000
102 #define WPAD_UC_BUTTON_RIGHT          0x00008000
103 #define WPAD_UC_BUTTON_STICK_R        0x00010000
104 #define WPAD_UC_BUTTON_STICK_L        0x00020000
105 
106 #define WPAD_UC_BUTTON_ZL             WPAD_UC_TRIGGER_ZL
107 #define WPAD_UC_BUTTON_ZR             WPAD_UC_TRIGGER_ZR
108 #define WPAD_UC_BUTTON_L              WPAD_UC_TRIGGER_L
109 #define WPAD_UC_BUTTON_R              WPAD_UC_TRIGGER_R
110 
111 #define WPAD_MAX_CUSTOM_BUFS          20
112 
113 #define WPAD_DPD_OFF                  0
114 #define WPAD_DPD_STD                  1
115 #define WPAD_DPD_EXP                  3
116 #define WPAD_DPD_FULL                 5
117 
118 #define WPAD_DPD_MAX_OBJECTS          4
119 #define WPAD_DPD_ANGLE               42.0f  // viewing angle
120 #define WPAD_DPD_IMG_RESO_WX       1024     // DPD image resolution
121 #define WPAD_DPD_IMG_RESO_WY        768
122 
123 #define WPAD_SPEAKER_OFF              0
124 #define WPAD_SPEAKER_ON               1
125 #define WPAD_SPEAKER_MUTE             2
126 #define WPAD_SPEAKER_MUTE_OFF         3
127 #define WPAD_SPEAKER_PLAY             4
128 #define WPAD_SPEAKER_RESET            5
129 
130 #define WPAD_MPLS_OFF                 0
131 #define WPAD_MPLS_STD                 4
132 #define WPAD_MPLS_EXP                 5    // for compatible
133 #define WPAD_MPLS_FS                  5
134 #define WPAD_MPLS_CL                  7
135 #define WPAD_MPLS_ZRST                128
136 
137 #define WPAD_MPLS_STAT_PLSVLD         0x80
138 #define WPAD_MPLS_STAT_EXTVLD         0x40
139 #define WPAD_MPLS_STAT_YAWSEL         0x08
140 #define WPAD_MPLS_STAT_PITSEL         0x04
141 #define WPAD_MPLS_STAT_ROLSEL         0x02
142 #define WPAD_MPLS_STAT_ATTACH         0x01
143 
144 #define WPAD_EXTGMK_OFF               0
145 #define WPAD_EXTGMK_ON                1
146 
147 #define WPAD_ACC_RESO              1024     // accelerometer resolution
148 #define WPAD_ACC_MAX                  3.4f  // valid gravity = 3.4G
149 
150 #define WPAD_FS_STICK_RESO          256     // stick resolution of FreeStyle unit
151 #define WPAD_FS_ACC_RESO           1024     // accelerometer resolution of FreeStyle unit
152 #define WPAD_FS_ACC_MAX               2.1f  // valid gravity = 2.1G
153 
154 #define WPAD_CL_STICK_RESO         1024
155 #define WPAD_CL_TRIGGER_RESO        256
156 
157 #define WPAD_UC_STICK_RESO         4096
158 
159 // device type
160 #define WPAD_DEV_CORE                 0
161 #define WPAD_DEV_FREESTYLE            1
162 #define WPAD_DEV_CLASSIC              2
163 #define WPAD_DEV_MPLS                 5
164 #define WPAD_DEV_MPLS_FREESTYLE       6
165 #define WPAD_DEV_MPLS_CLASSIC         7
166 #define WPAD_DEV_URCC                31
167 #define WPAD_DEV_MPLS_FUTURE        250
168 #define WPAD_DEV_FUTURE             251
169 #define WPAD_DEV_NOT_SUPPORTED      252
170 #define WPAD_DEV_NOT_FOUND          253
171 #define WPAD_DEV_UNKNOWN            255
172 
173 // data format of Core
174 #define WPAD_FMT_CORE                 0     // only buttons
175 #define WPAD_FMT_CORE_ACC             1     // buttons, motion sensor
176 #define WPAD_FMT_CORE_ACC_DPD         2     // buttons, motion sensor, pointing
177 // data format of Core + Nunchuk
178 #define WPAD_FMT_FREESTYLE            3     // buttons, Nunchuk
179 #define WPAD_FMT_FREESTYLE_ACC        4     // buttons, motion sensor, Nunchuk
180 #define WPAD_FMT_FREESTYLE_ACC_DPD    5     // buttons, motion sensor, pointing, Nunchuk
181 // data format of Core + Classic Controller accessory
182 #define WPAD_FMT_CLASSIC              6     // buttons, classic
183 #define WPAD_FMT_CLASSIC_ACC          7     // buttons, motion sensor, classic
184 #define WPAD_FMT_CLASSIC_ACC_DPD      8     // buttons, motion sensor, pointing, classic
185 // data format of Core + DPD full mode
186 #define WPAD_FMT_CORE_ACC_DPD_FULL    9     // buttons, motion sensor, pointing
187 #define WPAD_FMT_MPLS                16     // buttons, motion sensor, pointing, Wii MotionPlus
188 #define WPAD_FMT_URCC                22     // buttons, URCC
189 
190 #define WPAD_STATE_DISABLED           0
191 #define WPAD_STATE_ENABLED            1
192 
193 // disable channel to avoid WiFi interference.
194 #define WPAD_DISABLE_CLEAR            0x0000    // enable all range
195 #define WPAD_DISABLE_WIFI_CHAN_1      0x0001
196 #define WPAD_DISABLE_WIFI_CHAN_2      0x0002
197 #define WPAD_DISABLE_WIFI_CHAN_3      0x0004
198 #define WPAD_DISABLE_WIFI_CHAN_4      0x0008
199 #define WPAD_DISABLE_WIFI_CHAN_5      0x0010
200 #define WPAD_DISABLE_WIFI_CHAN_6      0x0020
201 #define WPAD_DISABLE_WIFI_CHAN_7      0x0040
202 #define WPAD_DISABLE_WIFI_CHAN_8      0x0080
203 #define WPAD_DISABLE_WIFI_CHAN_9      0x0100
204 #define WPAD_DISABLE_WIFI_CHAN_10     0x0200
205 #define WPAD_DISABLE_WIFI_CHAN_11     0x0400
206 #define WPAD_DISABLE_WIFI_CHAN_12     0x0800
207 #define WPAD_DISABLE_WIFI_CHAN_13     0x1000
208 #define WPAD_DISABLE_WIFI_CHAN_14     0x2000
209 
210 // battery level
211 #define WPAD_BATTERY_LEVEL_CRITICAL   0
212 #define WPAD_BATTERY_LEVEL_LOW        1
213 #define WPAD_BATTERY_LEVEL_MEDIUM     2
214 #define WPAD_BATTERY_LEVEL_HIGH       3
215 #define WPAD_BATTERY_LEVEL_MAX        4
216 
217 #define WPAD_LED_CHAN_1             0x1
218 #define WPAD_LED_CHAN_2             0x2
219 #define WPAD_LED_CHAN_3             0x4
220 #define WPAD_LED_CHAN_4             0x8
221 
222 #define WPAD_SYNC_EVT_START           0
223 #define WPAD_SYNC_EVT_DONE            1
224 
225 #define WPAD_CLEAR_EVT_BUSY          -1
226 #define WPAD_CLEAR_EVT_START          0
227 #define WPAD_CLEAR_EVT_DONE           1
228 
229 #define WPAD_ADDR_LEN                 6
230 
231 #define WPAD_STRM_INTERVAL            OSNanosecondsToTicks(6666667)
232 
233 // clamp algorithm for stick
234 #define WPAD_STICK_CLAMP_OCTA_WITH_PLAY         0
235 #define WPAD_STICK_CLAMP_OCTA_WITHOUT_PLAY      1
236 #define WPAD_STICK_CLAMP_CIRCLE_WITH_PLAY       2
237 #define WPAD_STICK_CLAMP_CIRCLE_WITHOUT_PLAY    3
238 // clamp algorithm for trigger
239 #define WPAD_TRIGGER_FIXED_BASE       0
240 #define WPAD_TRIGGER_INDIVIDUAL_BASE  1
241 // clamp algorithm for accelerometer
242 #define WPAD_ACC_CLAMP_CUBE           0
243 #define WPAD_ACC_CLAMP_SPHERE         1
244 
245 #define WPAD_SENSOR_BAR_POS_BOTTOM    0
246 #define WPAD_SENSOR_BAR_POS_TOP       1
247 
248 #define WPAD_MEM_GAMEDATA_LEN         3888
249 
250 #define WPAD_SYNC_TYPE_STD            0
251 #define WPAD_SYNC_TYPE_SMP            1
252 
253 #define WPAD_MPLS_TYPE_INTEGRATED     1
254 #define WPAD_MPLS_TYPE_STANDARD       0
255 #define WPAD_MPLS_TYPE_READING        -1
256 
257 #else
258 // SI-based WPAD
259 
260 #define WPAD_BUTTON_HOME              0x0001
261 #define WPAD_BUTTON_SELECT            0x0002
262 #define WPAD_BUTTON_A                 0x0004
263 #define WPAD_BUTTON_B                 0x0008
264 #define WPAD_BUTTON_SMALL_A           0x0010
265 #define WPAD_BUTTON_SMALL_B           0x0020
266 #define WPAD_BUTTON_START             0x0100
267 #define WPAD_BUTTON_UP                0x0200
268 #define WPAD_BUTTON_DOWN              0x0400
269 #define WPAD_BUTTON_RIGHT             0x0800
270 #define WPAD_BUTTON_LEFT              0x1000
271 #define WPAD_BUTTON_Z1                0x2000
272 #define WPAD_BUTTON_Z2                0x4000
273 #define WPAD_BUTTON_X                 WPAD_BUTTON_SMALL_A
274 #define WPAD_BUTTON_Y                 WPAD_BUTTON_SMALL_B
275 
276 #define WPAD_TRIGGER_Z                WPAD_BUTTON_Z1
277 #define WPAD_BUTTON_Z                 WPAD_TRIGGER_Z
278 
279 #define WPAD_TRIGGER_R                WPAD_BUTTON_Z2
280 #define WPAD_BUTTON_R                 WPAD_TRIGGER_R
281 
282 #define WPAD_TRIGGER_L                0x8000
283 #define WPAD_BUTTON_L                 WPAD_TRIGGER_L
284 
285 #define WPAD_DPD_MAX_OBJECTS          4
286 #define WPAD_DPD_ANGLE               42.0f  // viewing angle
287 #define WPAD_DPD_IMG_RESO_WX       1024     // DPD image resolution
288 #define WPAD_DPD_IMG_RESO_WY        768
289 
290 #define WPAD_ACC_RESO              1024     // accelerometer resolution
291 #define WPAD_ACC_1G_VALUE           205     // gravity value
292 
293 #define WPAD_FS_STICK_RESO          256     // stick resolution of FreeStyle unit
294 #define WPAD_FS_ACC_RESO           1024     // accelerometer resolution of FreeStyle unit
295 #define WPAD_FS_ACC_1G_VALUE        205     // gravity value of FreeStyle unit
296 
297 #define WPAD_DEV_CORE                 0
298 #define WPAD_DEV_FREESTYLE            1
299 #define WPAD_DEV_DOLPHIN            254
300 #define WPAD_DEV_UNKNOWN            255
301 #define WPAD_DEV_NOT_FOUND          253     // For backward compatibility. do not use.
302 
303 #define WPAD_FMT_CORE                 0     // data format of Core controller
304 #define WPAD_FMT_FREESTYLE            1     // data format of FreeStyle controller
305 #define WPAD_FMT_DOLPHIN            255     // data format of Dolphin controller(for debug)
306 
307 #endif
308 
309 #define WPAD_ERR_NONE                 0
310 #define WPAD_ERR_NO_CONTROLLER       -1
311 #define WPAD_ERR_BUSY                -2
312 #define WPAD_ERR_TRANSFER            -3
313 #define WPAD_ERR_INVALID             -4
314 #define WPAD_ERR_NOPERM              -5
315 #define WPAD_ERR_BROKEN              -6
316 #define WPAD_ERR_CORRUPTED           -7
317 
318 #define WPAD_UPTO7_ERR_NONE           0
319 #define WPAD_UPTO7_ERR_FAIL          -1
320 
321 #ifdef  __MWERKS__
322 #pragma warn_padding off
323 #endif
324 typedef struct DPDObject
325 {
326     s16       x;                    // 0 <=  x   < WPAD_DPD_IMG_RESO_WX
327     s16       y;                    // 0 <=  y   < WPAD_DPD_IMG_RESO_WY
328     u16       size;
329     u8        traceId;
330     // 1 byte padding
331 } DPDObject;
332 #ifdef  __MWERKS__
333 #pragma warn_padding reset
334 #endif
335 
336 #ifdef  __MWERKS__
337 #pragma warn_padding off
338 #endif
339 typedef struct DPDObjEx
340 {
341     s16       range_x1;
342     s16       range_y1;
343     s16       range_x2;
344     s16       range_y2;
345     u16       pixel;
346     s8        radius;
347     // 1 byte padding
348 } DPDObjEx;
349 #ifdef  __MWERKS__
350 #pragma warn_padding reset
351 #endif
352 
353 typedef struct WPADStatus
354 {
355     u16       button;               // Or-ed WPAD_BUTTON_* bits
356     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
357     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
358     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
359     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
360 
361     u8        dev;                  // one of WPAD_DEV_* number
362     s8        err;                  // one of WPAD_ERR_* number
363 } WPADStatus;
364 
365 typedef struct WPADFSStatus
366 {
367     u16       button;               // Or-ed WPAD_BUTTON_* bits
368     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
369     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
370     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
371     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
372 
373     u8        dev;                  // one of WPAD_DEV_* number
374     s8        err;                  // one of WPAD_ERR_* number
375 
376     s16       fsAccX;               // -WPAD_FS_ACC_RESO/2 <= fsAccX < WPAD_ACC_RESO/2
377     s16       fsAccY;               // -WPAD_FS_ACC_RESO/2 <= fsAccY < WPAD_ACC_RESO/2
378     s16       fsAccZ;               // -WPAD_FS_ACC_RESO/2 <= fsAccZ < WPAD_ACC_RESO/2
379     s8        fsStickX;             // -WPAD_FS_STICK_RESO/2 <= fsStickX < WPAD_FS_STICK_RESO/2
380     s8        fsStickY;             // -WPAD_FS_STICK_RESO/2 <= fsStickY < WPAD_FS_STICK_RESO/2
381 } WPADFSStatus;
382 
383 typedef struct WPADCLStatus
384 {
385     u16       button;               // Or-ed WPAD_BUTTON_* bits
386     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
387     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
388     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
389     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
390 
391     u8        dev;                  // one of WPAD_DEV_* number
392     s8        err;                  // one of WPAD_ERR_* number
393 
394     u16       clButton;             // Or-ed WPAD_CL_BUTTON * bits
395     s16       clLStickX;            // -WPAD_CL_STICK_RESO/2 <= clLStickX < WPAD_CL_STICK_RESO/2
396     s16       clLStickY;            // -WPAD_CL_STICK_RESO/2 <= clLStickY < WPAD_CL_STICK_RESO/2
397     s16       clRStickX;            // -WPAD_CL_STICK_RESO/2 <= clRStickX < WPAD_CL_STICK_RESO/2
398     s16       clRStickY;            // -WPAD_CL_STICK_RESO/2 <= clRStickY < WPAD_CL_STICK_RESO/2
399     u8        clTriggerL;           // legacy: will read as 0
400     u8        clTriggerR;           // legacy: will read as 0
401 } WPADCLStatus;
402 
403 typedef struct WPADUCStatus
404 {
405     u16       button;               // Or-ed WPAD_BUTTON_* bits
406     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
407     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
408     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
409     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
410 
411     u8        dev;                  // one of WPAD_DEV_* number
412     s8        err;                  // one of WPAD_ERR_* number
413 
414     u32       ucButton;             // Or-ed WPAD_UC_BUTTON * bits
415     s16       ucLStickX;            // -WPAD_UC_STICK_RESO/2 <= ucLStickX < WPAD_UC_STICK_RESO/2
416     s16       ucLStickY;            // -WPAD_UC_STICK_RESO/2 <= ucLStickY < WPAD_UC_STICK_RESO/2
417     s16       ucRStickX;            // -WPAD_UC_STICK_RESO/2 <= ucRStickX < WPAD_UC_STICK_RESO/2
418     s16       ucRStickY;            // -WPAD_UC_STICK_RESO/2 <= ucRStickY < WPAD_UC_STICK_RESO/2
419 
420     BOOL      charge;               // URCC is charging or not
421     BOOL      cable;                // URCC's charger cable is plugged or not
422 } WPADUCStatus;
423 
424 typedef struct WPADCMStatus
425 {
426     u16       button;               // Or-ed WPAD_BUTTON_* bits
427     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
428     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
429     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
430     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
431 
432     u8        dev;                  // one of WPAD_DEV_* number
433     s8        err;                  // one of WPAD_ERR_* number
434 
435     u16       cmButton;             // Or-ed WPAD_CM_BUTTON * bits
436     u8        custom[WPAD_MAX_CUSTOM_BUFS];// buffer for additional data
437 
438 } WPADCMStatus;
439 
440 
441 typedef struct WPADStatusEx
442 {
443     u16       button;               // Or-ed WPAD_BUTTON_* bits
444     s16       accX;                 // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
445     s16       accY;                 // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
446     s16       accZ;                 // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
447     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
448 
449     u8        dev;                  // one of WPAD_DEV_* number
450     s8        err;                  // one of WPAD_ERR_* number
451 
452     DPDObjEx  exp[WPAD_DPD_MAX_OBJECTS];
453 
454 } WPADStatusEx;
455 
456 typedef struct WPADMpls
457 {
458     f32 pitch_zero;
459     f32 pitch_scale;
460     f32 yaw_zero;
461     f32 yaw_scale;
462     f32 roll_zero;
463     f32 roll_scale;
464     s32 degrees;
465 } WPADMpls;
466 
467 typedef struct WPADMPStatus
468 {
469     u16       button;                       // Or-ed WPAD_BUTTON_* bits
470     s16       accX;                         // -WPAD_ACC_RESO/2 <= accX < WPAD_ACC_RESO/2
471     s16       accY;                         // -WPAD_ACC_RESO/2 <= accY < WPAD_ACC_RESO/2
472     s16       accZ;                         // -WPAD_ACC_RESO/2 <= accZ < WPAD_ACC_RESO/2
473     DPDObject obj[WPAD_DPD_MAX_OBJECTS];
474 
475     u8        dev;                          // one of WPAD_DEV_* number
476     s8        err;                          // one of WPAD_ERR_* number
477 
478     union
479     {
480         // for Nunchuk
481         struct
482         {
483             s16 fsAccX;
484             s16 fsAccY;
485             s16 fsAccZ;
486             s8  fsStickX;
487             s8  fsStickY;
488         } fs;
489 
490         // for classic
491         struct
492         {
493             u16 clButton;
494             s16 clLStickX;
495             s16 clLStickY;
496             s16 clRStickX;
497             s16 clRStickY;
498             u8  clTriggerL;
499             u8  clTriggerR;
500         } cl;
501     } ext;
502 
503     u8        stat;                         // yaw_sel, pitch_sel, roll_sel, attach2
504     u8        reserved;
505 
506     s16       pitch;                        // for Wii MotionPlus
507     s16       yaw;
508     s16       roll;
509 
510 } WPADMPStatus;
511 
512 typedef struct WPADInfo
513 {
514     BOOL dpd;                       // the active status of pointer unit
515     BOOL speaker;                   // the active status of speaker unit
516     BOOL attach;                    // whether an attachment is installed (=1) or not (=0)
517     BOOL lowBat;                    // whether the current battery level is lower than a threshold (0x20)
518     BOOL nearempty;                 // sound buffer is nearly empty
519     u8 battery;                     // the current battery level (WPAD_BATTERY_LEVEL_*)
520     u8 led;                         // the current pattern of 4 LEDs
521     u8 protocol;                    // not used
522     u8 firmware;                    // not used
523 } WPADInfo;
524 
525 typedef struct WPADAcc
526 {
527     s16 x;
528     s16 y;
529     s16 z;
530 } WPADAcc;
531 
532 
533 typedef void   ( *WPADExtensionCallback         )( s32  chan, s32 result );
534 typedef void   ( *WPADSamplingCallback          )( s32  chan );
535 typedef void   ( *WPADConnectCallback           )( s32  chan, s32 reason );
536 typedef void   ( *WPADCallback                  )( s32  chan, s32 result );
537 typedef void * ( *WPADAlloc                     )( u32  size );
538 typedef u8     ( *WPADFree                      )( void *ptr );
539 typedef void   ( *WPADSyncDeviceCallback        )( s32  result, s32 num );
540 typedef void   ( *WPADClearDeviceCallback       )( s32  result );
541 typedef void   ( *WPADFlushCallback             )( u32  result );
542 
543 #define WPADButtonDown( buttonLast, button )   \
544     ( (u16) (((buttonLast) ^ (button)) & (button)) )
545 
546 #define WPADButtonUp( buttonLast, button )   \
547     ( (u16) (((buttonLast) ^ (button)) & (buttonLast)) )
548 
549 #define WPADURCCButtonDown( buttonLast, button )   \
550     ( (u32) (((buttonLast) ^ (button)) & (button)) )
551 
552 #define WPADURCCButtonUp( buttonLast, button )   \
553     ( (u32) (((buttonLast) ^ (button)) & (buttonLast)) )
554 
555 #define WPADStartMotor( chan )  WPADControlMotor( ( chan ), WPAD_MOTOR_RUMBLE )
556 #define WPADStopMotor( chan )   WPADControlMotor( ( chan ), WPAD_MOTOR_STOP   )
557 
558 
559 
560 void WPADInit                   ( void );
561 void WPADShutdown               ( void );                             // DEPRECATED
562 void WPADRegisterAllocator      ( WPADAlloc alloc, WPADFree free );   // DEPRECATED
563 u32  WPADGetWorkMemorySize      ( void );                             // DEPRECATED
564 s32  WPADProbe                  ( s32 chan, u32 *type );
565 s32  WPADGetStatus              ( void );
566 u32  WPADGetDataFormat          ( s32 chan );
567 s32  WPADSetDataFormat          ( s32 chan, u32 fmt );
568 void WPADRead                   ( s32 chan, void *status );
569 void WPADSetAutoSamplingBuf     ( s32 chan, void *buf, u32 length);
570 u32  WPADGetLatestIndexInBuf    ( s32 chan );
571 void WPADGetAccGravityUnit      ( s32 chan, u32 type, WPADAcc *acc );
572 void WPADGetCLTriggerThreshold  ( s32 chan, u8 *left, u8 *right );    // DEPRECATED
573 
574 
575 #ifdef WPADEMU
576 void WPADClampStick             ( u32 fmt, void *status );
577 #else
578 void WPADClampStick             ( s32 chan, void *status, u32 type );
579 void WPADClampTrigger           ( s32 chan, void *status, u32 type );  // DEPRECATED
580 void WPADClampAcc               ( s32 chan, void *status, u32 type );
581 #endif
582 
583 BOOL WPADIsDpdEnabled           ( s32 chan );
584 u8   WPADGetDpdFormat           ( s32 chan );
585 s32  WPADControlDpd             ( s32 chan, u32 command, WPADCallback callback );
586 u8   WPADGetDpdSensitivity      ( void );
587 
588 s32  WPADControlExtGimmick      ( s32 chan, u32 command, WPADCallback callback );
589 
590 void WPADDisconnect             ( s32 chan );
591 s32  WPADGetInfo                ( s32 chan, WPADInfo *info );
592 s32  WPADGetInfoAsync           ( s32 chan, WPADInfo *info, WPADCallback callback );
593 void WPADGetAddress             ( s32 chan, u8 *addr );
594 u8   WPADGetRegisteredDevNum    ( void );
595 u8   WPADGetRadioSensitivity    ( s32 chan );
596 u8   WPADGetBatteryLevel        ( s32 chan );
597 
598 BOOL WPADIsSpeakerEnabled       ( s32 chan );
599 s32  WPADControlSpeaker         ( s32 chan, u32 command, WPADCallback callback );
600 u8   WPADGetSpeakerVolume       ( void );
601 s32  WPADSendStreamData         ( s32 chan, void *buf, u16 len );
602 BOOL WPADCanSendStreamData      ( s32 chan );
603 
604 void WPADControlMotor           ( s32 chan, u32 command );
605 BOOL WPADIsMotorEnabled         ( void );
606 
607 void WPADSetAutoSleepTime       ( u8 minute );
608 u32  WPADGetAutoSleepTimeCount  ( s32 chan );
609 void WPADResetAutoSleepTimeCount( s32 chan );
610 u8   WPADGetSensorBarPosition   ( void );
611 void WPADEnableSensorBar        ( u8 sensorBar );                 // DEPRECATED
612 void WPADSetSensorBar           ( BOOL on );
613 
614 
615 void WPADSetGameTitleUtf16      ( const u16  *title );            // DEPRECATED
616 s32  WPADGetGameTitleUtf16      ( s32 chan, const u16 **title );  // DEPRECATED
617 s32  WPADGetGameDataTimeStamp   ( s32 chan, OSTime *time );       // DEPRECATED
618 
619 BOOL WPADSetAcceptConnection    ( BOOL accept );                  // DEPRECATED - use WPADDisableBluetooth instead
620 BOOL WPADGetAcceptConnection    ( void );                         // DEPRECATED
621 
622 BOOL WPADStartSyncDevice        ( void );
623 BOOL WPADPurgeBtDb              ( void );                         // DEPRECATED
624 BOOL WPADCancelSyncDevice       ( void );
625 BOOL WPADIsBusyForSync          ( void );
626 
627 s32  WPADGetSyncType            ( s32 chan, u8 *type );           // DEPRECATED
628 
629 WPADSamplingCallback            WPADSetSamplingCallback     ( s32 chan, WPADSamplingCallback  callback );
630 WPADExtensionCallback           WPADSetExtensionCallback    ( s32 chan, WPADExtensionCallback callback );
631 WPADConnectCallback             WPADSetConnectCallback      ( s32 chan, WPADConnectCallback   callback );
632 WPADSyncDeviceCallback          WPADSetSyncDeviceCallback   ( WPADSyncDeviceCallback  callback );
633 WPADClearDeviceCallback         WPADSetClearDeviceCallback  ( WPADClearDeviceCallback callback );
634 
635 // These can be used in only debug build so that application can debug extension handling
636 BOOL WPADAttachDummyExtension( s32 chan, u32 type );
637 BOOL WPADDetachDummyExtension( s32 chan );
638 
639 
640 // for motion plus
641 s8   WPADIsMplsAttached         ( s32 chan, BOOL *attached, WPADCallback callback );
642 s8   WPADIsMplsIntegrated       ( s32 chan );
643 BOOL WPADGetCalibrationStatus   ( s32 chan );
644 
645 // for URCC
646 void WPADEnableURCC             ( BOOL enable );
647 
648 // for other controllers
649 void WPADEnableWiiRemote        ( BOOL enable );
650 
651 
652 // for Applications that do not support WPAD
653 void WPADDisableBluetooth      ( void );
654 
655 #ifdef __cplusplus
656 }
657 #endif
658 
659 
660 #endif // __WPAD_H__
661