add a couple more classic controller IDs
[libogc.git] / wiiuse / wiiuse_internal.h
blob2bcfa34261f459511f206bd1e8ca8f5b9fdb4ff6
1 /*
2 * wiiuse
4 * Written By:
5 * Michael Laforest < para >
6 * Email: < thepara (--AT--) g m a i l [--DOT--] com >
8 * Copyright 2006-2007
10 * This file is part of wiiuse.
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.
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.
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/>.
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 $
29 /**
30 * @file
31 * @brief General internal wiiuse stuff.
33 * Since Wiiuse is a library, wiiuse.h is a duplicate
34 * of the API header.
36 * The code that would normally go in that file, but
37 * which is not needed by third party developers,
38 * is put here.
40 * So wiiuse_internal.h is included by other files
41 * internally, wiiuse.h is included only here.
44 #ifndef WIIUSE_INTERNAL_H_INCLUDED
45 #define WIIUSE_INTERNAL_H_INCLUDED
47 #if defined(__linux__)
48 #include <arpa/inet.h> /* htons() */
49 #include <bluetooth/bluetooth.h>
50 #endif
52 #include "definitions.h"
54 /* wiiuse version */
55 #define WIIUSE_VERSION "0.12"
57 /********************
59 * Wiimote internal codes
61 ********************/
63 /* Communication channels */
64 #define WM_OUTPUT_CHANNEL 0x11
65 #define WM_INPUT_CHANNEL 0x13
67 #define WM_SET_REPORT 0x50
69 /* commands */
70 #define WM_CMD_RUMBLE 0x10
71 #define WM_CMD_LED 0x11
72 #define WM_CMD_REPORT_TYPE 0x12
73 #define WM_CMD_IR 0x13
74 #define WM_CMD_SPEAKER_ENABLE 0x14
75 #define WM_CMD_CTRL_STATUS 0x15
76 #define WM_CMD_WRITE_DATA 0x16
77 #define WM_CMD_READ_DATA 0x17
78 #define WM_CMD_STREAM_DATA 0x18
79 #define WM_CMD_SPEAKER_MUTE 0x19
80 #define WM_CMD_IR_2 0x1A
82 /* input report ids */
83 #define WM_RPT_CTRL_STATUS 0x20
84 #define WM_RPT_READ 0x21
85 #define WM_RPT_WRITE 0x22
86 #define WM_RPT_BTN 0x30
87 #define WM_RPT_BTN_ACC 0x31
88 #define WM_RPT_BTN_ACC_IR 0x33
89 #define WM_RPT_BTN_EXP 0x34
90 #define WM_RPT_BTN_ACC_EXP 0x35
91 #define WM_RPT_BTN_IR_EXP 0x36
92 #define WM_RPT_BTN_ACC_IR_EXP 0x37
94 #define WM_BT_INPUT 0x01
95 #define WM_BT_OUTPUT 0x02
97 /* Identify the wiimote device by its class */
98 #define WM_DEV_CLASS_0 0x04
99 #define WM_DEV_CLASS_1 0x25
100 #define WM_DEV_CLASS_2 0x00
101 #define WM_VENDOR_ID 0x057E
102 #define WM_PRODUCT_ID 0x0306
104 /* controller status stuff */
105 #define WM_MAX_BATTERY_CODE 0xC8
107 /* offsets in wiimote memory */
108 #define WM_MEM_OFFSET_CALIBRATION 0x16
109 #define WM_EXP_MEM_BASE 0x04A40000
110 #define WM_EXP_MEM_ENABLE1 0x04A400F0
111 #define WM_EXP_MEM_ENABLE2 0x04A400FB
112 #define WM_EXP_MEM_KEY 0x04A40040
113 #define WM_EXP_MEM_CALIBR 0x04A40020
114 #define WM_EXP_MOTION_PLUS_ENABLE 0x04A600FE
115 #define WM_EXP_ID 0x04A400FA
117 #define WM_REG_IR 0x04B00030
118 #define WM_REG_IR_BLOCK1 0x04B00000
119 #define WM_REG_IR_BLOCK2 0x04B0001A
120 #define WM_REG_IR_MODENUM 0x04B00033
122 #define WM_REG_SPEAKER_REG1 0x04A20001
123 #define WM_REG_SPEAKER_REG2 0x04A20008
124 #define WM_REG_SPEAKER_REG3 0x04A20009
125 #define WM_REG_SPEAKER_BLOCK 0x04A20001
127 /* ir block data */
128 #define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
129 #define WM_IR_BLOCK2_LEVEL1 "\xfd\x05"
130 #define WM_IR_BLOCK1_LEVEL2 "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
131 #define WM_IR_BLOCK2_LEVEL2 "\xb3\x04"
132 #define WM_IR_BLOCK1_LEVEL3 "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
133 #define WM_IR_BLOCK2_LEVEL3 "\x63\x03"
134 #define WM_IR_BLOCK1_LEVEL4 "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
135 #define WM_IR_BLOCK2_LEVEL4 "\x35\x03"
136 #define WM_IR_BLOCK1_LEVEL5 "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
137 #define WM_IR_BLOCK2_LEVEL5 "\x1f\x03"
139 #define WM_IR_TYPE_BASIC 0x01
140 #define WM_IR_TYPE_EXTENDED 0x03
141 #define WM_IR_TYPE_FULL 0x05
143 /* controller status flags for the first message byte */
144 /* bit 1 is unknown */
145 #define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02
146 #define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04
147 #define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08
148 #define WM_CTRL_STATUS_BYTE1_LED_1 0x10
149 #define WM_CTRL_STATUS_BYTE1_LED_2 0x20
150 #define WM_CTRL_STATUS_BYTE1_LED_3 0x40
151 #define WM_CTRL_STATUS_BYTE1_LED_4 0x80
153 /* aspect ratio */
154 #define WM_ASPECT_16_9_X 660
155 #define WM_ASPECT_16_9_Y 370
156 #define WM_ASPECT_4_3_X 560
157 #define WM_ASPECT_4_3_Y 420
161 * Expansion stuff
164 /* encrypted expansion id codes (located at 0x04A400FC) */
165 #define EXP_ID_CODE_NUNCHUK 0xa4200000
166 #define EXP_ID_CODE_CLASSIC_CONTROLLER 0xa4200101
167 #define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING 0x90908f00
168 #define EXP_ID_CODE_CLASSIC_CONTROLLER_NYKOWING2 0x9e9f9c00
169 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC 0xa5a2a300
170 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC2 0x98999900
171 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC3 0xa0a1a000
172 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC4 0x8d8d8e00
173 #define EXP_ID_CODE_CLASSIC_CONTROLLER_GENERIC5 0x93949400
174 #define EXP_ID_CODE_GUITAR 0xa4200103
175 #define EXP_ID_CODE_WIIBOARD 0xa4200402
176 #define EXP_ID_CODE_MOTION_PLUS 0xa4200405
178 #define EXP_HANDSHAKE_LEN 224
180 /********************
182 * End Wiimote internal codes
184 ********************/
186 /* wiimote state flags - (some duplicated in wiiuse.h)*/
187 #define WIIMOTE_STATE_DEV_FOUND 0x00001
188 //#define WIIMOTE_STATE_DEV_REGISTER 0x00002
189 #define WIIMOTE_STATE_HANDSHAKE 0x00004 /* actual connection exists but no handshake yet */
190 #define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x00008 /* actual connection exists but no handshake yet */
191 #define WIIMOTE_STATE_CONNECTED 0x00010
192 #define WIIMOTE_STATE_EXP_HANDSHAKE 0x00020 /* actual connection exists but no handshake yet */
193 #define WIIMOTE_STATE_EXP_FAILED 0x00040 /* actual connection exists but no handshake yet */
194 #define WIIMOTE_STATE_RUMBLE 0x00080
195 #define WIIMOTE_STATE_ACC 0x00100
196 #define WIIMOTE_STATE_EXP 0x00200
197 #define WIIMOTE_STATE_IR 0x00400
198 #define WIIMOTE_STATE_SPEAKER 0x00800
199 #define WIIMOTE_STATE_IR_SENS_LVL1 0x01000
200 #define WIIMOTE_STATE_IR_SENS_LVL2 0x02000
201 #define WIIMOTE_STATE_IR_SENS_LVL3 0x04000
202 #define WIIMOTE_STATE_IR_SENS_LVL4 0x08000
203 #define WIIMOTE_STATE_IR_SENS_LVL5 0x10000
204 #define WIIMOTE_STATE_IR_INIT 0x20000
205 #define WIIMOTE_STATE_SPEAKER_INIT 0x40000
207 #define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)
209 /* macro to manage states */
210 #define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
211 #define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
212 #define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
213 #define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
215 #define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
216 #define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s))
217 #define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s))
218 #define WIIMOTE_TOGGLE_FLAG(wm, s) ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
220 #define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s))
222 /* misc macros */
223 #define WIIMOTE_ID(wm) (wm->unid)
224 #define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
227 * Smooth tilt calculations are computed with the
228 * exponential moving average formula:
229 * St = St_last + (alpha * (tilt - St_last))
230 * alpha is between 0 and 1
232 #define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.3f
234 #define SMOOTH_ROLL 0x01
235 #define SMOOTH_PITCH 0x02
237 #include <wiiuse/wiiuse.h>
239 #ifdef __cplusplus
240 extern "C" {
241 #endif
243 struct op_t
245 ubyte cmd;
246 union {
247 struct {
248 uint addr;
249 uword size;
250 } readdata;
251 struct {
252 uint addr;
253 ubyte size;
254 ubyte data[16];
255 } writedata;
256 ubyte __data[MAX_PAYLOAD];
259 void *buffer;
260 int wait;
261 } __attribute__((packed));
263 /* not part of the api */
264 void wiiuse_init_cmd_queue(struct wiimote_t *wm);
265 void wiiuse_send_next_command(struct wiimote_t *wm);
266 int wiiuse_set_report_type(struct wiimote_t* wm,cmd_blk_cb cb);
267 int wiiuse_sendcmd(struct wiimote_t *wm,ubyte report_type,ubyte *msg,int len,cmd_blk_cb cb);
269 #ifdef __cplusplus
271 #endif
273 #endif /* WIIUSE_INTERNAL_H_INCLUDED */