RetroArch
wiiuse_internal.h
Go to the documentation of this file.
1 /*
2  * wiiuse
3  *
4  * Written By:
5  * Michael Laforest < para >
6  * Email: < thepara (--AT--) g m a i l [--DOT--] com >
7  *
8  * Copyright 2006-2007
9  *
10  * This file is part of wiiuse.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  *
25  * $Header: /lvm/shared/ds/ds/cvs/devkitpro-cvsbackup/libogc/wiiuse/wiiuse_internal.h,v 1.8 2008-12-10 16:16:40 shagkur Exp $
26  *
27  */
28 
44 /* This source as presented is a modified version of original wiiuse for use
45  * with RetroArch, and must not be confused with the original software. */
46 
47 #ifndef WIIUSE_INTERNAL_H_INCLUDED
48 #define WIIUSE_INTERNAL_H_INCLUDED
49 
50 #if defined(__linux__)
51  #include <arpa/inet.h> /* htons() */
52  #include <bluetooth/bluetooth.h>
53 #endif
54 
55 #include "definitions.h"
56 
57 /* wiiuse version */
58 #define WIIUSE_VERSION "0.12"
59 
60 /********************
61  *
62  * Wiimote internal codes
63  *
64  ********************/
65 
66 /* Communication channels */
67 #define WM_OUTPUT_CHANNEL 0x11
68 #define WM_INPUT_CHANNEL 0x13
69 
70 #define WM_SET_REPORT 0x50
71 #define WM_DATA 0xA0
72 
73 /* commands */
74 #define WM_CMD_RUMBLE 0x10
75 #define WM_CMD_LED 0x11
76 #define WM_CMD_REPORT_TYPE 0x12
77 #define WM_CMD_IR 0x13
78 #define WM_CMD_SPEAKER_ENABLE 0x14
79 #define WM_CMD_CTRL_STATUS 0x15
80 #define WM_CMD_WRITE_DATA 0x16
81 #define WM_CMD_READ_DATA 0x17
82 #define WM_CMD_STREAM_DATA 0x18
83 #define WM_CMD_SPEAKER_MUTE 0x19
84 #define WM_CMD_IR_2 0x1A
85 
86 /* input report ids */
87 #define WM_RPT_CTRL_STATUS 0x20
88 #define WM_RPT_READ 0x21
89 #define WM_RPT_ACK 0x22
90 #define WM_RPT_BTN 0x30
91 #define WM_RPT_BTN_ACC 0x31
92 #define WM_RPT_BTN_ACC_IR 0x33
93 #define WM_RPT_BTN_EXP 0x34
94 #define WM_RPT_BTN_ACC_EXP 0x35
95 #define WM_RPT_BTN_IR_EXP 0x36
96 #define WM_RPT_BTN_ACC_IR_EXP 0x37
97 
98 #define WM_BT_INPUT 0x01
99 #define WM_BT_OUTPUT 0x02
100 
101 /* Identify the wiimote device by its class */
102 #define WM_DEV_CLASS_0 0x04
103 #define WM_DEV_CLASS_1 0x25
104 #define WM_DEV_CLASS_2 0x00
105 #define WM_VENDOR_ID 0x057E
106 #define WM_PRODUCT_ID 0x0306
107 
108 /* controller status stuff */
109 #define WM_MAX_BATTERY_CODE 0xC8
110 
111 /* offsets in wiimote memory */
112 #define WM_MEM_OFFSET_CALIBRATION 0x16
113 #define WM_EXP_MEM_BASE 0x04A40000
114 #define WM_EXP_MEM_ENABLE1 0x04A400F0
115 #define WM_EXP_MEM_ENABLE2 0x04A400FB
116 #define WM_EXP_MEM_KEY 0x04A40040
117 #define WM_EXP_MEM_CALIBR 0x04A40020
118 #define WM_EXP_MOTION_PLUS_ENABLE 0x04A600FE
119 #define WM_EXP_ID 0x04A400FA
120 
121 #define WM_REG_IR 0x04B00030
122 #define WM_REG_IR_BLOCK1 0x04B00000
123 #define WM_REG_IR_BLOCK2 0x04B0001A
124 #define WM_REG_IR_MODENUM 0x04B00033
125 
126 #define WM_REG_SPEAKER_REG1 0x04A20001
127 #define WM_REG_SPEAKER_REG2 0x04A20008
128 #define WM_REG_SPEAKER_REG3 0x04A20009
129 #define WM_REG_SPEAKER_BLOCK 0x04A20001
130 
131 /* ir block data */
132 #define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
133 #define WM_IR_BLOCK2_LEVEL1 "\xfd\x05"
134 #define WM_IR_BLOCK1_LEVEL2 "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
135 #define WM_IR_BLOCK2_LEVEL2 "\xb3\x04"
136 #define WM_IR_BLOCK1_LEVEL3 "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
137 #define WM_IR_BLOCK2_LEVEL3 "\x63\x03"
138 #define WM_IR_BLOCK1_LEVEL4 "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
139 #define WM_IR_BLOCK2_LEVEL4 "\x35\x03"
140 #define WM_IR_BLOCK1_LEVEL5 "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
141 #define WM_IR_BLOCK2_LEVEL5 "\x1f\x03"
142 
143 #define WM_IR_TYPE_BASIC 0x01
144 #define WM_IR_TYPE_EXTENDED 0x03
145 #define WM_IR_TYPE_FULL 0x05
146 
147 /* controller status flags for the first message byte */
148 /* bit 1 is unknown */
149 #define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02
150 #define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04
151 #define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08
152 #define WM_CTRL_STATUS_BYTE1_LED_1 0x10
153 #define WM_CTRL_STATUS_BYTE1_LED_2 0x20
154 #define WM_CTRL_STATUS_BYTE1_LED_3 0x40
155 #define WM_CTRL_STATUS_BYTE1_LED_4 0x80
156 
157 /* aspect ratio */
158 #define WM_ASPECT_16_9_X 660
159 #define WM_ASPECT_16_9_Y 370
160 #define WM_ASPECT_4_3_X 560
161 #define WM_ASPECT_4_3_Y 420
162 
163 
168 /* encrypted expansion id codes (located at 0x04A400FC) */
169 #define EXP_ID_CODE_NUNCHUK 0xa4200000
170 #define EXP_ID_CODE_CLASSIC_CONTROLLER 0xa4200101
171 #define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING 0x90908f00
172 #define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING2 0x9e9f9c00
173 #define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING3 0x908f8f00
174 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC 0xa5a2a300
175 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC2 0x98999900
176 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC3 0xa0a1a000
177 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC4 0x8d8d8e00
178 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC5 0x93949400
179 #define EXP_ID_CODE_CLASSIC_WIIU_PRO 0xa4200120
180 //#define EXP_ID_CODE_GUITAR 0xa4200103
181 //#define EXP_ID_CODE_WIIBOARD 0xa4200402
182 #define EXP_ID_CODE_MOTION_PLUS 0xa4200405
183 
184 #define EXP_HANDSHAKE_LEN 224
185 
186 /********************
187  *
188  * End Wiimote internal codes
189  *
190  ********************/
191 
192 /* wiimote state flags - (some duplicated in wiiuse.h)*/
193 #define WIIMOTE_STATE_DEV_FOUND 0x00001
194 //#define WIIMOTE_STATE_DEV_REGISTER 0x00002
195 #define WIIMOTE_STATE_HANDSHAKE 0x00004 /* actual connection exists but no handshake yet */
196 #define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x00008 /* actual connection exists but no handshake yet */
197 #define WIIMOTE_STATE_CONNECTED 0x00010
198 #define WIIMOTE_STATE_EXP_HANDSHAKE 0x00020 /* actual connection exists but no handshake yet */
199 #define WIIMOTE_STATE_EXP_FAILED 0x00040 /* actual connection exists but no handshake yet */
200 #define WIIMOTE_STATE_RUMBLE 0x00080
201 #define WIIMOTE_STATE_ACC 0x00100
202 #define WIIMOTE_STATE_EXP 0x00200
203 #define WIIMOTE_STATE_IR 0x00400
204 #define WIIMOTE_STATE_SPEAKER 0x00800
205 #define WIIMOTE_STATE_IR_SENS_LVL1 0x01000
206 #define WIIMOTE_STATE_IR_SENS_LVL2 0x02000
207 #define WIIMOTE_STATE_IR_SENS_LVL3 0x04000
208 #define WIIMOTE_STATE_IR_SENS_LVL4 0x08000
209 #define WIIMOTE_STATE_IR_SENS_LVL5 0x10000
210 #define WIIMOTE_STATE_IR_INIT 0x20000
211 #define WIIMOTE_STATE_SPEAKER_INIT 0x40000
212 #define WIIMOTE_STATE_WIIU_PRO 0x80000
213 
214 #define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)
215 
216 /* macro to manage states */
217 #define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
218 #define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
219 #define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
220 #define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
221 
222 #define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
223 #define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s))
224 #define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s))
225 #define WIIMOTE_TOGGLE_FLAG(wm, s) ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
226 
227 #define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s))
228 
229 /* misc macros */
230 #define WIIMOTE_ID(wm) (wm->unid)
231 #define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
232 
233 /*
234  * Smooth tilt calculations are computed with the
235  * exponential moving average formula:
236  * St = St_last + (alpha * (tilt - St_last))
237  * alpha is between 0 and 1
238  */
239 #define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.3f
240 
241 #define SMOOTH_ROLL 0x01
242 #define SMOOTH_PITCH 0x02
243 
244 #include <wiiuse/wiiuse.h>
245 
246 #ifdef __cplusplus
247 extern "C" {
248 #endif
249 
250 struct op_t
251 {
253  union {
254  struct {
257  } readdata;
258  struct {
259  uint addr;
261  ubyte data[16];
262  } writedata;
264  };
265 
266  void *buffer;
267  int wait;
268 } __attribute__((packed));
269 
270 /* not part of the api */
271 void wiiuse_init_cmd_queue(struct wiimote_t *wm);
272 void wiiuse_send_next_command(struct wiimote_t *wm);
273 int wiiuse_set_report_type(struct wiimote_t* wm,cmd_blk_cb cb);
274 int wiiuse_sendcmd(struct wiimote_t *wm,ubyte report_type,ubyte *msg,int len,cmd_blk_cb cb);
275 
276 #ifdef __cplusplus
277 }
278 #endif
279 
280 #endif /* WIIUSE_INTERNAL_H_INCLUDED */
Definition: wiiuse_internal.h:250
uint addr
Definition: wiiuse_internal.h:255
Wiimote structure.
Definition: wiiuse.h:594
GLenum GLsizei len
Definition: glext.h:7389
uword size
Definition: wiiuse_internal.h:256
Definition: ibxm.h:9
void * buffer
Definition: wiiuse_internal.h:266
struct op_t::@877::@879 writedata
unsigned int uint
Definition: wiiuse.h:191
void wiiuse_init_cmd_queue(struct wiimote_t *wm)
ubyte size
Definition: wiiuse_internal.h:260
static const unsigned char msg[]
Definition: ccm.c:375
struct op_t __attribute__((packed))
Definition: psp1_gfx.c:71
ubyte cmd
Definition: wiiuse_internal.h:252
unsigned char ubyte
Definition: wiiuse.h:187
int wiiuse_sendcmd(struct wiimote_t *wm, ubyte report_type, ubyte *msg, int len, cmd_blk_cb cb)
Definition: wiiuse.c:318
unsigned short uword
Definition: wiiuse.h:189
GLuint GLenum GLsizei GLsizei GLint GLint GLboolean packed
Definition: glext.h:10178
ubyte __data[MAX_PAYLOAD]
Definition: wiiuse_internal.h:263
int wait
Definition: wiiuse_internal.h:267
struct op_t::@877::@878 readdata
#define MAX_PAYLOAD
Definition: wiiuse.h:176
void(* cmd_blk_cb)(struct wiimote_t *wm, ubyte *data, uword len)
Definition: wiiuse.h:239
int wiiuse_set_report_type(struct wiimote_t *wm, cmd_blk_cb cb)
Definition: wiiuse.c:207
void wiiuse_send_next_command(struct wiimote_t *wm)
Definition: wiiuse.c:20