-
-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathwpad.h
More file actions
1489 lines (1373 loc) · 41.6 KB
/
wpad.h
File metadata and controls
1489 lines (1373 loc) · 41.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include <wut.h>
#include <coreinit/time.h>
/**
* \defgroup padscore_wpad WPAD
* \ingroup padscore
*
* WPAD is a low-level library under KPAD.
*
* @{
*/
#ifdef __cplusplus
extern "C" {
#endif
#define WPAD_MAX_IR_DOTS 4
#define WPAD_MAX_PRESSURE_SENSORS 4
typedef struct WPADStatusProController WPADStatusProController;
typedef struct WPADVec2D WPADVec2D;
typedef struct WPADVec3D WPADVec3D;
typedef struct WPADInfo WPADInfo;
typedef struct WPADAddress WPADAddress;
typedef struct WPADiQueueElement WPADiQueueElement;
typedef struct WPADiQueue WPADiQueue;
typedef struct WPADIRDot WPADIRDot;
typedef struct WPADIRDotEx WPADIRDotEx;
typedef struct WPADStatus WPADStatus;
typedef struct WPADStatusEx WPADStatusEx;
typedef struct WPADStatusNunchuk WPADStatusNunchuk;
typedef struct WPADStatusClassic WPADStatusClassic;
typedef struct WPADStatusMotionPlus WPADStatusMotionPlus;
typedef struct WPADStatusBalanceBoard WPADStatusBalanceBoard;
typedef struct WPADStatusTrain WPADStatusTrain;
typedef WPADStatusProController WPADStatusPro;
typedef struct WENCParams WENCParams;
typedef enum WPADError
{
WPAD_ERROR_NONE = 0,
WPAD_ERROR_NO_CONTROLLER = -1,
WPAD_ERROR_NOT_READY = -2,
WPAD_ERROR_TRANSFER = -3,
WPAD_ERROR_INVALID = -4,
WPAD_ERROR_PERMISSION = -5,
WPAD_ERROR_BROKEN = -6,
WPAD_ERROR_QUEUE_EMPTY = -7,
WPAD_ERROR_BAD_VALUE = -8,
WPAD_ERROR_BAD_CONF = -9,
} WPADError;
//! Wii Remote channel.
typedef enum WPADChan
{
//! Channel 0.
WPAD_CHAN_0 = 0,
//! Channel 1.
WPAD_CHAN_1 = 1,
//! Channel 2.
WPAD_CHAN_2 = 2,
//! Channel 3.
WPAD_CHAN_3 = 3,
//! Channel 4.
WPAD_CHAN_4 = 4,
//! Channel 5.
WPAD_CHAN_5 = 5,
//! Channel 6.
WPAD_CHAN_6 = 6,
} WPADChan;
//! Data format.
typedef enum WPADDataFormat
{
//! Wii Remote buttons
WPAD_FMT_CORE = 0x00,
//! Wii Remote buttons and accelerometer
WPAD_FMT_CORE_ACC = 0x01,
//! Wii Remote buttons, accelerometer and IR pos
WPAD_FMT_CORE_ACC_DPD = 0x02,
//! Wii Remote buttons, Nunchuk
WPAD_FMT_NUNCHUK = 0x03,
//! Wii Remote buttons, accelerometer, Nunchuk
WPAD_FMT_NUNCHUK_ACC = 0x04,
//! Wii Remote buttons, accelerometer, IR pos, Nunchuk
WPAD_FMT_NUNCHUK_ACC_DPD = 0x05,
//! Wii Remote buttons, Classic Controller
WPAD_FMT_CLASSIC = 0x06,
//! Wii Remote buttons, accelerometer, Classic Controller
WPAD_FMT_CLASSIC_ACC = 0x07,
//! Wii Remote buttons, accelerometer, IR pos, Classic Controller
WPAD_FMT_CLASSIC_ACC_DPD = 0x08,
//! Wii Remote buttons, accelerometer and IR pos with bounds
WPAD_FMT_CORE_ACC_DPD_FULL = 0x09,
//! Wii Remote, Densha De GO! Shinkansen Controller
WPAD_FMT_TRAIN = 0x0A,
//! Guitar Hero Guitar
WPAD_FMT_GUITAR = 0x0B,
//! Wii Balance Board
WPAD_FMT_BALANCE_BOARD = 0x0C,
//! Guitar Hero World Tour Drums
WPAD_FMT_DRUM = 0x0F,
//! Wii Remote buttons, accelerometer, IR pos, Motion Plus gyroscope
WPAD_FMT_MPLUS = 0x10,
//! Wii Remote, Taiko no Tatsujin TaTaCon
WPAD_FMT_TAIKO = 0x11,
//! Wii U Pro Controller
WPAD_FMT_PRO_CONTROLLER = 0x16,
} WPADDataFormat;
//! Extension type.
typedef enum WPADExtensionType
{
//! Wii Remote with no extension.
WPAD_EXT_CORE = 0x00,
//! Nunchuk.
WPAD_EXT_NUNCHUK = 0x01,
//! Classic Controller.
WPAD_EXT_CLASSIC = 0x02,
//! Balance Board.
WPAD_EXT_BALANCE_BOARD = 0x03,
//! Motion Plus.
WPAD_EXT_MPLUS = 0x05,
//! Motion Plus with Nunchuk.
WPAD_EXT_MPLUS_NUNCHUK = 0x06,
//! Motion Plus with Classic Controller.
WPAD_EXT_MPLUS_CLASSIC = 0x07,
//! Train controller.
WPAD_EXT_TRAIN = 0x10,
//! Guitar controller.
WPAD_EXT_GUITAR = 0x11,
//! Drum controller.
WPAD_EXT_DRUM = 0x12,
//! Taiko no Tatsujin controller.
WPAD_EXT_TAIKO = 0x13,
//! Pro Controller.
WPAD_EXT_PRO_CONTROLLER = 0x1f,
//! No controller found.
WPAD_EXT_DEV_NOT_FOUND = 0xfd,
//! Extension unknown.
WPAD_EXT_UNKNOWN = 0xff,
} WPADExtensionType;
//! Wii Remote buttons.
typedef enum WPADButton
{
//! The left button of the D-pad.
WPAD_BUTTON_LEFT = 0x0001,
//! The right button of the D-pad.
WPAD_BUTTON_RIGHT = 0x0002,
//! The down button of the D-pad.
WPAD_BUTTON_DOWN = 0x0004,
//! The up button of the D-pad.
WPAD_BUTTON_UP = 0x0008,
//! The + button.
WPAD_BUTTON_PLUS = 0x0010,
//! The 2 button.
WPAD_BUTTON_2 = 0x0100,
//! The 1 button.
WPAD_BUTTON_1 = 0x0200,
//! The B button.
WPAD_BUTTON_B = 0x0400,
//! The A button.
WPAD_BUTTON_A = 0x0800,
//! The - button.
WPAD_BUTTON_MINUS = 0x1000,
//! The Z button on the Nunchuk extension.
WPAD_BUTTON_Z = 0x2000,
//! The C button on the Nunchuk extension.
WPAD_BUTTON_C = 0x4000,
//! The HOME button.
WPAD_BUTTON_HOME = 0x8000,
} WPADButton;
//! Nunchuk buttons.
typedef enum WPADNunchukButton
{
//! The emulated left button on the Nunchuk stick or the left button of the D-pad on the Wii Remote.
WPAD_NUNCHUK_STICK_EMULATION_LEFT = 0x0001,
//! The emulated right button on the Nunchuk stick or the right button of the D-pad on the Wii Remote.
WPAD_NUNCHUK_STICK_EMULATION_RIGHT = 0x0002,
//! The emulated down button on the Nunchuk stick or the down button of the D-pad on the Wii Remote.
WPAD_NUNCHUK_STICK_EMULATION_DOWN = 0x0004,
//! The emulated up button on the Nunchuk stick or the up button of the D-pad on the Wii Remote.
WPAD_NUNCHUK_STICK_EMULATION_UP = 0x0008,
//! The Z button.
WPAD_NUNCHUK_BUTTON_Z = 0x2000,
//! The C button.
WPAD_NUNCHUK_BUTTON_C = 0x4000,
} WPADNunchukButton;
//! Classic Controller buttons.
typedef enum WPADClassicButton
{
//! The up button of the D-pad.
WPAD_CLASSIC_BUTTON_UP = 0x00000001,
//! The left button of the D-pad.
WPAD_CLASSIC_BUTTON_LEFT = 0x00000002,
//! The ZR button.
WPAD_CLASSIC_BUTTON_ZR = 0x00000004,
//! The X button.
WPAD_CLASSIC_BUTTON_X = 0x00000008,
//! The A button.
WPAD_CLASSIC_BUTTON_A = 0x00000010,
//! The Y button.
WPAD_CLASSIC_BUTTON_Y = 0x00000020,
//! The B button.
WPAD_CLASSIC_BUTTON_B = 0x00000040,
//! The ZL button.
WPAD_CLASSIC_BUTTON_ZL = 0x00000080,
//! The R button.
WPAD_CLASSIC_BUTTON_R = 0x00000200,
//! The + button.
WPAD_CLASSIC_BUTTON_PLUS = 0x00000400,
//! The HOME button.
WPAD_CLASSIC_BUTTON_HOME = 0x00000800,
//! The - button.
WPAD_CLASSIC_BUTTON_MINUS = 0x00001000,
//! The L button.
WPAD_CLASSIC_BUTTON_L = 0x00002000,
//! The down button of the D-pad.
WPAD_CLASSIC_BUTTON_DOWN = 0x00004000,
//! The right button of the D-pad.
WPAD_CLASSIC_BUTTON_RIGHT = 0x00008000,
//! The emulated left button on the left stick.
WPAD_CLASSIC_STICK_L_EMULATION_LEFT = 0x00010000,
//! The emulated right button on the left stick.
WPAD_CLASSIC_STICK_L_EMULATION_RIGHT = 0x00020000,
//! The emulated down button on the left stick.
WPAD_CLASSIC_STICK_L_EMULATION_DOWN = 0x00040000,
//! The emulated up button on the left stick.
WPAD_CLASSIC_STICK_L_EMULATION_UP = 0x00080000,
//! The emulated left button on the right stick.
WPAD_CLASSIC_STICK_R_EMULATION_LEFT = 0x00100000,
//! The emulated right button on the right stick.
WPAD_CLASSIC_STICK_R_EMULATION_RIGHT = 0x00200000,
//! The emulated down button on the right stick.
WPAD_CLASSIC_STICK_R_EMULATION_DOWN = 0x00400000,
//! The emulated up button on the right stick.
WPAD_CLASSIC_STICK_R_EMULATION_UP = 0x00800000,
} WPADClassicButton;
//! Pro Controller buttons.
typedef enum WPADProButton
{
//! The up button of the D-pad.
WPAD_PRO_BUTTON_UP = 0x00000001,
//! The left button of the D-pad.
WPAD_PRO_BUTTON_LEFT = 0x00000002,
//! The ZR button.
WPAD_PRO_BUTTON_ZR = 0x00000004,
//! Another name for the ZR button.
WPAD_PRO_TRIGGER_ZR = WPAD_PRO_BUTTON_ZR,
//! The X button.
WPAD_PRO_BUTTON_X = 0x00000008,
//! The A button.
WPAD_PRO_BUTTON_A = 0x00000010,
//! The Y button.
WPAD_PRO_BUTTON_Y = 0x00000020,
//! The B button.
WPAD_PRO_BUTTON_B = 0x00000040,
//! The ZL button.
WPAD_PRO_BUTTON_ZL = 0x00000080,
//! Another name for the ZL button.
WPAD_PRO_TRIGGER_ZL = WPAD_PRO_BUTTON_ZL,
//! Reserved.
WPAD_PRO_RESERVED = 0x00000100,
//! The R button.
WPAD_PRO_BUTTON_R = 0x00000200,
//! Another name for the R button.
WPAD_PRO_TRIGGER_R = WPAD_PRO_BUTTON_R,
//! The + button.
WPAD_PRO_BUTTON_PLUS = 0x00000400,
//! The HOME button.
WPAD_PRO_BUTTON_HOME = 0x00000800,
//! The - button.
WPAD_PRO_BUTTON_MINUS = 0x00001000,
//! The L button.
WPAD_PRO_BUTTON_L = 0x00002000,
//! Another name for the L button.
WPAD_PRO_TRIGGER_L = WPAD_PRO_BUTTON_L,
//! The down button of the D-pad.
WPAD_PRO_BUTTON_DOWN = 0x00004000,
//! The right button of the D-pad.
WPAD_PRO_BUTTON_RIGHT = 0x00008000,
//! The right stick button.
WPAD_PRO_BUTTON_STICK_R = 0x00010000,
//! The left stick button.
WPAD_PRO_BUTTON_STICK_L = 0x00020000,
//! The emulated up button on the left stick.
WPAD_PRO_STICK_L_EMULATION_UP = 0x00200000,
//! The emulated down button on the left stick.
WPAD_PRO_STICK_L_EMULATION_DOWN = 0x00100000,
//! The emulated left button on the left stick.
WPAD_PRO_STICK_L_EMULATION_LEFT = 0x00040000,
//! The emulated right button on the left stick.
WPAD_PRO_STICK_L_EMULATION_RIGHT = 0x00080000,
//! The emulated up button on the right stick.
WPAD_PRO_STICK_R_EMULATION_UP = 0x02000000,
//! The emulated down button on the right stick.
WPAD_PRO_STICK_R_EMULATION_DOWN = 0x01000000,
//! The emulated left button on the right stick.
WPAD_PRO_STICK_R_EMULATION_LEFT = 0x00400000,
//! The emulated right button on the right stick.
WPAD_PRO_STICK_R_EMULATION_RIGHT = 0x00800000,
} WPADProButton;
//! WPAD Led flags
typedef enum WPADLed
{
WPAD_LED_ONE = 0x01,
WPAD_LED_TWO = 0x02,
WPAD_LED_THREE = 0x04,
WPAD_LED_FOUR = 0x08,
} WPADLed;
WUT_ENUM_BITMASK_TYPE(WPADLed);
//! WPAD Infrared Format. For more information see <a href="https://wiibrew.org/wiki/Wiimote#Data_Formats">IR Data Formats</a>
typedef enum WPADDpdFormat
{
//! Disable IR
WPAD_DPD_FMT_NONE = 0,
WPAD_DPD_FMT_BASIC = 1,
WPAD_DPD_FMT_EXTENDED = 3,
WPAD_DPD_FMT_FULL = 5,
} WPADDpdFormat;
//! WPAD Speaker Command.
typedef enum WPADSpeakerCmd
{
//! Deinitializes and turns off speaker
WPAD_SPEAKER_CMD_OFF = 0,
//! Turns on and initializes speaker to use 4-bit Yamaha ADPCM data format at 3000 Hz
WPAD_SPEAKER_CMD_ON = 1,
//! Mutes speaker
WPAD_SPEAKER_CMD_MUTE = 2,
//! Unmutes speaker
WPAD_SPEAKER_CMD_UNMUTE = 3,
//! Allows sound to play
WPAD_SPEAKER_CMD_PLAY = 4,
//! Does the same as WPAD_SPEAKER_CMD_ON
WPAD_SPEAKER_CMD_ON_ALT = 5,
} WPADSpeakerCmd;
//! MotionPlus Mode.
typedef enum WPADMplsMode
{
WPAD_MPLS_MODE_DISABLE = 0,
//! MotionPlus exclusive mode
WPAD_MPLS_MODE_MPLS_ONLY = 4,
//! Nunchuk passthrough mode
WPAD_MPLS_MODE_MPLS_NUNCHUK = 5,
//! Classic passthrough mode
WPAD_MPLS_MODE_MPLS_CLASSIC = 7,
} WPADMplsMode;
//! MotionPlus status flags.
typedef enum WPADMplsStatus
{
//! When something is attached to the MotionPlus
WPAD_MPLS_STATUS_ATTACHED = 0x01,
//! When the roll is in low-velocity mode.
WPAD_MPLS_STATUS_ROLL_CONV = 0x02,
//! When the pitch is in low-velocity mode.
WPAD_MPLS_STATUS_PITCH_CONV = 0x04,
//! When the yaw is in low-velocity mode.
WPAD_MPLS_STATUS_YAW_CONV = 0x08,
//! When extension data is valid.
WPAD_MPLS_STATUS_EXT_VALID = 0x40,
//! When MotionPlus data is valid.
WPAD_MPLS_STATUS_VALID = 0x80,
} WPADMplsStatus;
//! WPAD Peripheral Memory Space Prefixes
typedef enum WPADPeripheralSpace
{
WPAD_PERIPHERAL_SPACE_SPEAKER = 0xA2,
//! Any extension other than Motion Plus.
WPAD_PERIPHERAL_SPACE_EXTENSION = 0xA4,
WPAD_PERIPHERAL_SPACE_MOTIONPLUS = 0xA6,
//! Infrared.
WPAD_PERIPHERAL_SPACE_DPD = 0xB0,
} WPADPeripheralSpace;
//! Balance Board commands.
typedef enum WPADBalanceBoardCmd
{
//! Update temperature data.
WPAD_BALANCE_BOARD_CMD_UPDATE_TEMP = 0x00,
//! Turn Balance Board off.
WPAD_BALANCE_BOARD_CMD_OFF = 0x55,
//! Turn Balance Board on.
WPAD_BALANCE_BOARD_CMD_ON = 0xAA,
} WPADBalanceBoardCmd;
//! Encoding mode
typedef enum WENCMode
{
//! Start encoding with new parameters
WENC_MODE_NEW = 0,
//! Use prior encoding parameters
WENC_MODE_CONTINUE = 1
} WENCMode;
//! 2D vector.
struct WPADVec2D
{
//! x.
int16_t x;
//! y.
int16_t y;
};
WUT_CHECK_OFFSET(WPADVec2D, 0x00, x);
WUT_CHECK_OFFSET(WPADVec2D, 0x02, y);
WUT_CHECK_SIZE(WPADVec2D, 0x04);
//! 3D vector.
struct WPADVec3D
{
//! x.
int16_t x;
//! y.
int16_t y;
//! z.
int16_t z;
};
WUT_CHECK_OFFSET(WPADVec3D, 0x00, x);
WUT_CHECK_OFFSET(WPADVec3D, 0x02, y);
WUT_CHECK_OFFSET(WPADVec3D, 0x04, z);
WUT_CHECK_SIZE(WPADVec3D, 0x06);
//! A single IR dot tracked by the camera.
struct WPADIRDot
{
//! Position (in a 1024x768 grid).
WPADVec2D pos;
//! Pixel area (in a 128x96 grid).
uint16_t pixels;
//! Identifier.
uint8_t id;
WUT_PADDING_BYTES(1);
};
WUT_CHECK_OFFSET(WPADIRDot, 0x0, pos);
WUT_CHECK_OFFSET(WPADIRDot, 0x4, pixels);
WUT_CHECK_OFFSET(WPADIRDot, 0x6, id);
WUT_CHECK_SIZE(WPADIRDot, 0x8);
//! A single IR dot tracked by the camera, extra info.
struct WPADIRDotEx
{
//! Top-right coordinate (in a 1024x768 grid).
WPADVec2D topRight;
//! Bottom-left coordinate (in a 1024x768 grid).
WPADVec2D bottomLeft;
//! Pixel area (in a 128x96 grid).
uint16_t pixels;
//! Calculated size (from 0 to 15).
uint8_t size;
WUT_PADDING_BYTES(1);
};
WUT_CHECK_OFFSET(WPADIRDotEx, 0x00, topRight);
WUT_CHECK_OFFSET(WPADIRDotEx, 0x04, bottomLeft);
WUT_CHECK_OFFSET(WPADIRDotEx, 0x08, pixels);
WUT_CHECK_OFFSET(WPADIRDotEx, 0x0A, size);
WUT_CHECK_SIZE(WPADIRDotEx, 0x0C);
/**
* Core Wii Remote status.
*
* Valid buffer for formats:
* - `WPAD_FMT_CORE`
* - `WPAD_FMT_CORE_ACC`
* - `WPAD_FMT_CORE_ACC_DPD`
*/
struct WPADStatus
{
//! Bitset from `WPADButton`.
uint16_t buttons;
//! Accelerometer data.
WPADVec3D acc;
//! IR dots tracked.
WPADIRDot ir[WPAD_MAX_IR_DOTS];
//! One of `WPADExtensionType`.
uint8_t extensionType;
//! Error of the last `WPADRead()`.
int8_t error;
};
WUT_CHECK_OFFSET(WPADStatus, 0x00, buttons);
WUT_CHECK_OFFSET(WPADStatus, 0x02, acc);
WUT_CHECK_OFFSET(WPADStatus, 0x08, ir);
WUT_CHECK_OFFSET(WPADStatus, 0x28, extensionType);
WUT_CHECK_OFFSET(WPADStatus, 0x29, error);
WUT_CHECK_SIZE(WPADStatus, 0x2a);
/**
* Extended core Wii Remote status, with more IR details.
*
* Valid buffer for formats:
* - `WPAD_FMT_CORE_ACC_DPD_FULL`
*/
struct WPADStatusEx
{
WPADStatus core;
WPADIRDotEx irEx[WPAD_MAX_IR_DOTS];
};
WUT_CHECK_OFFSET(WPADStatusEx, 0x00, core);
WUT_CHECK_OFFSET(WPADStatusEx, 0x2A, irEx);
WUT_CHECK_SIZE(WPADStatusEx, 0x5a);
/**
* Wii Remote + Nunchuk status.
*
* Note that nunchuk buttons (Z and C) are reported in `core.buttons`.
*
* Valid buffer for formats:
* - `WPAD_FMT_NUNCHUK`
* - `WPAD_FMT_NUNCHUK_ACC`
* - `WPAD_FMT_NUNCHUK_ACC_DPD`
*/
struct WPADStatusNunchuk
{
//! Wii Remote core state + nunchuk buttons.
WPADStatus core;
//! Accelerometer data.
WPADVec3D acc;
struct
{
//! x, in the range [-128, 127].
int8_t x;
//! y, in the range [-128, 127].
int8_t y;
} stick;
};
WUT_CHECK_OFFSET(WPADStatusNunchuk, 0x00, core);
WUT_CHECK_OFFSET(WPADStatusNunchuk, 0x2a, acc);
WUT_CHECK_OFFSET(WPADStatusNunchuk, 0x30, stick.x);
WUT_CHECK_OFFSET(WPADStatusNunchuk, 0x31, stick.y);
WUT_CHECK_SIZE(WPADStatusNunchuk, 0x32);
/**
* Classic Controller and Classic Controller Pro status.
*
* Valid buffer for formats:
* - `WPAD_FMT_CLASSIC`
* - `WPAD_FMT_CLASSIC_ACC`
* - `WPAD_FMT_CLASSIC_ACC_DPD`
* - `WPAD_FMT_GUITAR`
* - `WPAD_FMT_DRUM`
* - `WPAD_FMT_TAIKO`
*/
struct WPADStatusClassic
{
WPADStatus core;
//! Bitset from `WPADClassicButton`.
uint16_t buttons;
//! Left stick: [-512, 511] x [-512, 511]
WPADVec2D leftStick;
//! Right stick: [-512, 511] x [-512, 511]
WPADVec2D rightStick;
uint8_t leftTrigger;
uint8_t rightTrigger;
};
WUT_CHECK_OFFSET(WPADStatusClassic, 0x00, core);
WUT_CHECK_OFFSET(WPADStatusClassic, 0x2a, buttons);
WUT_CHECK_OFFSET(WPADStatusClassic, 0x2c, leftStick);
WUT_CHECK_OFFSET(WPADStatusClassic, 0x30, rightStick);
WUT_CHECK_OFFSET(WPADStatusClassic, 0x34, leftTrigger);
WUT_CHECK_OFFSET(WPADStatusClassic, 0x35, rightTrigger);
WUT_CHECK_SIZE(WPADStatusClassic, 0x36);
/**
* Pro Controller status.
*
* Valid buffer for formats:
* - `WPAD_FMT_PRO_CONTROLLER`
*/
struct WPADStatusProController
{
WPADStatus core;
WUT_PADDING_BYTES(2);
//! Bitset from `WPADProButton`.
uint32_t buttons;
//! Left stick: [-2048, 2047] x [-2048 x 2047]
WPADVec2D leftStick;
//! Right stick: [-2048, 2047] x [-2048 x 2047]
WPADVec2D rightStick;
BOOL charging;
BOOL wired;
};
WUT_CHECK_OFFSET(WPADStatusProController, 0x00, core);
WUT_CHECK_OFFSET(WPADStatusProController, 0x2C, buttons);
WUT_CHECK_OFFSET(WPADStatusProController, 0x30, leftStick);
WUT_CHECK_OFFSET(WPADStatusProController, 0x34, rightStick);
WUT_CHECK_OFFSET(WPADStatusProController, 0x38, charging);
WUT_CHECK_OFFSET(WPADStatusProController, 0x3c, wired);
WUT_CHECK_SIZE(WPADStatusProController, 0x40);
/**
* MotionPlus status.
*
* Use `core.extensionType` to determine if `nunchuk` or `classic` are valid.
*
* Valid for formats:
* - `WPAD_FMT_MPLUS`
*
* Note that the extension fields line up with `WPADStatusNunchuk` and `WPADStatusClassic`.
*/
struct WPADStatusMotionPlus
{
WPADStatus core;
union
{
struct
{
//! Accelerometer data.
WPADVec3D acc;
struct
{
//! x: [-128, 127]
int8_t x;
//! y: [-128, 127]
int8_t y;
} stick;
} nunchuk;
struct
{
//! Bitset from `WPADClassicButton`.
uint16_t buttons;
//! Left stick: [-512, 511] x [-512, 511]
WPADVec2D leftStick;
//! Right stick: [-512, 511] x [-512, 511]
WPADVec2D rightStick;
uint8_t leftTrigger;
uint8_t rightTrigger;
} classic;
};
//! Bitset from WPADMplsStatus
uint8_t status;
WUT_PADDING_BYTES(1);
WPADVec3D angle;
};
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x00, core);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x2a, nunchuk.acc);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x30, nunchuk.stick);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x2a, classic.buttons);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x2c, classic.leftStick);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x30, classic.rightStick);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x34, classic.leftTrigger);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x35, classic.rightTrigger);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x36, status);
WUT_CHECK_OFFSET(WPADStatusMotionPlus, 0x38, angle);
WUT_CHECK_SIZE(WPADStatusMotionPlus, 0x3e);
/**
* Balance Board status.
*
* Valid for formats:
* - `WPAD_FMT_BALANCE_BOARD`
*/
struct WPADStatusBalanceBoard
{
WPADStatus core;
//! Raw pressure data. \sa `WBCRead()`.
uint16_t pressure[WPAD_MAX_PRESSURE_SENSORS];
//! Raw temperature data. \sa `WBCSetupCalibration()`.
int8_t temperature;
//! Raw battery charge. \sa `WBCGetBatteryLevel()`.
uint8_t battery;
};
WUT_CHECK_OFFSET(WPADStatusBalanceBoard, 0x00, core);
WUT_CHECK_OFFSET(WPADStatusBalanceBoard, 0x2a, pressure);
WUT_CHECK_OFFSET(WPADStatusBalanceBoard, 0x32, temperature);
WUT_CHECK_OFFSET(WPADStatusBalanceBoard, 0x33, battery);
WUT_CHECK_SIZE(WPADStatusBalanceBoard, 0x34);
/**
* Bullet Train controller status.
*
* Valid for formats:
* - `WPAD_FMT_TRAIN`
*/
struct WPADStatusTrain
{
WPADStatus core;
//! Bitset from `WPADClassicButton`.
uint16_t buttons;
//! Brake (left) lever.
uint8_t brake;
//! Throttle (right) lever.
uint8_t throttle;
};
WUT_CHECK_OFFSET(WPADStatusTrain, 0x00, core);
WUT_CHECK_OFFSET(WPADStatusTrain, 0x2a, buttons);
WUT_CHECK_OFFSET(WPADStatusTrain, 0x2c, brake);
WUT_CHECK_OFFSET(WPADStatusTrain, 0x2d, throttle);
WUT_CHECK_SIZE(WPADStatusTrain, 0x2e);
//! Controller status info
struct WPADInfo
{
BOOL irEnabled;
BOOL speakerEnabled;
BOOL extensionAttached;
BOOL batteryLow;
BOOL speakerBufNearEmpty;
uint8_t batteryLevel;
uint8_t led;
uint8_t protocol;
uint8_t firmware;
};
WUT_CHECK_OFFSET(WPADInfo, 0x00, irEnabled);
WUT_CHECK_OFFSET(WPADInfo, 0x04, speakerEnabled);
WUT_CHECK_OFFSET(WPADInfo, 0x08, extensionAttached);
WUT_CHECK_OFFSET(WPADInfo, 0x0c, batteryLow);
WUT_CHECK_OFFSET(WPADInfo, 0x10, speakerBufNearEmpty);
WUT_CHECK_OFFSET(WPADInfo, 0x14, batteryLevel);
WUT_CHECK_OFFSET(WPADInfo, 0x15, led);
WUT_CHECK_OFFSET(WPADInfo, 0x16, protocol);
WUT_CHECK_OFFSET(WPADInfo, 0x17, firmware);
WUT_CHECK_SIZE(WPADInfo, 0x18);
struct WPADiQueueElement
{
uint8_t data[0x30];
};
WUT_CHECK_OFFSET(WPADiQueueElement, 0x00, data);
WUT_CHECK_SIZE(WPADiQueueElement, 0x30);
struct WPADiQueue
{
uint8_t frontIndex;
uint8_t backIndex;
WUT_PADDING_BYTES(2);
WPADiQueueElement *elements;
uint32_t capacity;
};
WUT_CHECK_OFFSET(WPADiQueue, 0x00, frontIndex);
WUT_CHECK_OFFSET(WPADiQueue, 0x01, backIndex);
WUT_CHECK_OFFSET(WPADiQueue, 0x04, elements);
WUT_CHECK_OFFSET(WPADiQueue, 0x08, capacity);
WUT_CHECK_SIZE(WPADiQueue, 0xc);
//! Bluetooth device address
struct WPADAddress
{
uint8_t btDeviceAddress[6];
};
WUT_CHECK_OFFSET(WPADAddress, 0x00, btDeviceAddress);
WUT_CHECK_SIZE(WPADAddress, 0x6);
//! Continuation parameters for \link WENCGetEncodeData
struct WENCParams
{
WUT_UNKNOWN_BYTES(32);
};
WUT_CHECK_SIZE(WENCParams, 32);
typedef void (*WPADCallback)(WPADChan channel, WPADError status);
typedef WPADCallback WPADControlLedCallback;
typedef WPADCallback WPADControlDpdCallback;
typedef WPADCallback WPADControlSpeakerCallback;
typedef WPADCallback WPADIsMplsAttachedCallback;
typedef WPADCallback WPADGetInfoCallback;
typedef WPADCallback WPADReadMemoryCallback;
typedef WPADCallback WPADWriteMemoryCallback;
typedef WPADCallback WPADConnectCallback;
typedef WPADCallback WPADiSendCallback;
typedef WPADCallback WPADiWriteGameDataCallback;
typedef void (*WPADSamplingCallback)(WPADChan channel);
/**
* Callback called when the active extension changes
*/
typedef void (*WPADExtensionCallback)(WPADChan channel, WPADExtensionType ext);
/**
* Initialises the WPAD library for use.
*/
void
WPADInit(void);
/**
* Cleans up and frees the WPAD library.
*/
void
WPADShutdown(void);
/**
* Get the status of the WPAD library.
*
* \return `TRUE` if the library is initialized.
*/
BOOL
WPADGetStatus(void);
/**
* Immediately disconnects the associated controller
*/
void
WPADDisconnect(WPADChan channel);
/**
* Identifies the extension connected to the associated controller
* \return `WPAD_ERROR_NO_CONTROLLER` if controller is not connected,
* \return `WPAD_ERROR_NOT_READY` if busy
*/
WPADError
WPADProbe(WPADChan channel,
WPADExtensionType *outExtensionType);
/**
* Sets the data format of the controller,
* can be used to reduce or increase the amount of data received
* \param channel
* \param format data format
* \return `WPAD_ERROR_NONE` on success
* \return `WPAD_ERROR_NOT_READY` if busy or data
* \return `WPAD_ERROR_INVALID` if format is for a disabled device type
*/
WPADError
WPADSetDataFormat(WPADChan channel,
WPADDataFormat format);
/**
* Gets the data format in use by the controller
* \return the current data format
*/
WPADDataFormat
WPADGetDataFormat(WPADChan channel);
/**
* Reads data for a given Wii Remote.
*
* \param channel
* \param status Where to store the data; must have be the correct type for the data format.
* \sa
* - `WPADDataFormat`
* - `WPADSetDataFormat()`
* - `WPADGetDataFormat()`
*/
void
WPADRead(WPADChan channel,
WPADStatus *status);
/**
* Controls the associated Wii Remote's LEDs
*/
WPADError
WPADControlLed(WPADChan channel,
WPADLed led,
WPADCallback callback);
/**
* Controls the Wii Remote's IR sensor
*/
WPADError
WPADControlDpd(WPADChan channel,
WPADDpdFormat mode,
WPADCallback callback);
/**
* Returns the associated Wii Remote's IR mode
*/
WPADDpdFormat
WPADGetDpdFormat(WPADChan channel);
/**
* Controls the associated WPADChan's rumble motor.
*/
void
WPADControlMotor(WPADChan channel,
BOOL motorEnabled);
/**
* Sets the Wii Remote speaker mode
*/
int32_t
WPADControlSpeaker(WPADChan channel,
WPADSpeakerCmd mode,
WPADCallback callback);
/**
* Returns whether the Wii Remote's speaker is enabled
*/
BOOL
WPADIsSpeakerEnabled(WPADChan channel);
/**
* Returns whether it is possible to send data to the Wii Remote's speaker at this moment
* May return false if device type is unknown, or the device is too busy
*/
BOOL
WPADCanSendStreamData(WPADChan channel);
/**
* Sends data to be played by Wii Remote speaker
* make sure the data is in the format the speaker was initialized for,
* (4-bit Yamaha ADPCM by default)
* \param data audio encoded in initialized format
* \param size number of bytes to send, up to 20 bytes may be sent per call
* \return `WPAD_ERROR_NOT_READY`, if not possible to send data at this moment
* \return `WPAD_ERROR_NO_CONTROLLER`, if channel is invalid, data is NULL or size is more than 20
*
* \sa WPADControlSpeaker
* \sa WPADCanSendStreamData
* \sa WENCGetEncodeData
*/
WPADError
WPADSendStreamData(WPADChan channel,
const void *data,
uint32_t size);
/**
* Encode 16-bit LPCM as 4-bit Yamaha ADPCM
* \param params encoding continuation params, written on first call, and read and updated on each subsequent call
* \param mode should be WENC_MODE_CONTINUE if continuing encoding stream with the params produced via a prior call
* \param [in] samples 16-bit LPCM sample buffer
* \param sampleCount number of 16-bit LPCM samples
* \param [out] outEncodedData buffer for the returned ADPCM samples, size should be {(sampleCount + 1) / 2}
* \return Number of LPCM-16 samples
*
* \sa AXRmtGetSamples
* \sa WPADSendStreamData
*/
uint32_t
WENCGetEncodeData(WENCParams *params,
WENCMode mode,
const int16_t *samples,
uint32_t sampleCount,
uint8_t *outEncodedData);
/**
* Returns the global Wii Remote speaker volume
*/
uint8_t
WPADGetSpeakerVolume(void);
/**
* Sets the global Wii Remote speaker volume.
* Only applies to Wii Remotes whose speakers are initialized after this call.
*/
void
WPADSetSpeakerVolume(uint8_t volume);
/**
* Gets whether MotionPlus is enabled for the WPAD
* \param outEnabled is set to true if MotionPlus is enabled
*/
int32_t
WPADIsMplsAttached(WPADChan channel,
BOOL *outEnabled,
WPADCallback callback);
/**
* Returns whether the WPADChan has MotionPlus integrated
* \return -1 if controller is not connected, 1 if MotionPlus integrated, 0 if not
*/
int32_t
WPADIsMplsIntegrated(WPADChan channel);
/**
* Retrieves status info from the controller
* \return WPAD_ERROR_NO_CONTROLLER if info request fails
* \return WPAD_ERROR_NOT_READY if controller is not connected
*/
WPADError
WPADGetInfo(WPADChan channel,
WPADInfo *outInfo);
/**
* Retrieves status info from the controller asynchronously
* \param callback pointer to function called when info is obtained
* \return WPAD_ERROR_NO_CONTROLLER if info request fails
* \return WPAD_ERROR_NOT_READY if controller is not connected
*/
WPADError
WPADGetInfoAsync(WPADChan channel,
WPADInfo *outInfo,
WPADCallback callback);
/**
* Reads from the device's memory
* \param destination where the received data will be stored
* \param size number of bytes to read
* \param address device memory address, see
* <a href="https://wiibrew.org/wiki/Wiimote#EEPROM_Memory">EEPROM Memory</a> and
* <a href="https://wiibrew.org/wiki/Wiimote#Control_Registers">Control Registers</a>
* \param callback function to be called upon completion
* \sa
* - WPADWriteMemoryAsync()
* - WPADReadExtReg()
*/
WPADError
WPADReadMemoryAsync(WPADChan channel,
void *destination,
uint16_t size,