1 /*---------------------------------------------------------------------------* 2 Project: Gamecube controller(PAD) library 3 File: pad.h 4 5 Copyright (C) 1998-2006 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 $Log: pad.h,v $ 14 Revision 1.7 2008/05/08 01:39:34 yasuh-to 15 Deleted PADIsBarrel info. 16 17 Revision 1.6 2006/09/06 14:53:27 yasuh-to 18 (none) 19 20 Revision 1.5 2006/09/06 14:34:08 yasuh-to 21 Modified Clamp2 APIs. 22 Clamp2 uses new paramaters these are more widly than GC's. 23 24 Revision 1.4 2006/08/25 11:28:58 yasuh-to 25 Added new clamp API. 26 27 Revision 1.3 2006/02/06 01:06:15 yasuh-to 28 Restored the APIs 29 30 31 33 1/09/04 10:52 Shiki 32 Added PADIsBarrel(). 33 34 32 7/22/03 13:22 Shiki 35 Declared __PADDisableRumble(). 36 37 30 8/22/02 11:58 Shiki 38 Clean up. 39 40 29 8/20/02 10:28 Shiki 41 Added PADClampCircle(). 42 43 28 8/19/02 21:42 Shiki 44 Set #pragma warn_padding off around the PADStatus{} definition. 45 46 27 8/12/02 15:27 Shiki 47 Added __padding field to PADStatus{}. 48 49 26 8/05/02 18:11 Shiki 50 Added const keyword to the PADControlAllMotors() function prototype. 51 52 25 10/29/01 11:57 Shiki 53 Modified __PADDisableRecalibration() to make it return the previous 54 state. 55 56 24 10/12/01 16:29 Shiki 57 Modified PADSetSamplingCallback() to make it return the previous 58 callback pointer. 59 60 23 9/05/01 16:25 Shiki 61 Added __PADDisableRecalibration() and __PADDisableXPatch(). 62 63 22 9/03/01 14:46 Shiki 64 Added PADSetSamplingCallback(). 65 66 21 7/30/01 11:01 Shiki 67 Modified PADRead() to return OR-ed bit mask of controllers that support 68 rumble motors. 69 70 20 01/03/21 18:55 Shiki 71 Fixed not to define PAD_USESPEC for EMU builds. 72 73 19 01/03/21 18:32 Shiki 74 Added PADGetSpec(). 75 76 18 01/03/21 17:22 Shiki 77 Added PADSetAnalogMode(). 78 79 17 01/01/30 14:17 Shiki 80 Removed __PADWirelessIDCheck(). 81 82 16 11/20/00 6:03p Shiki 83 Added more PAD_SPEC_*. 84 85 15 10/17/00 10:14a Hashida 86 From IRD: Added PADRecalibrate and PADSync 87 88 14 10/02/00 10:18a Hashida 89 From Shiki: Added PAD_WIRELESS_FIX_ID define name. 90 91 13 9/05/00 9:12p Shiki 92 Added PAD_TYPE_* define names. 93 94 12 9/05/00 9:04p Shiki 95 Added PADGetType(). 96 97 11 8/29/00 10:18p Shiki 98 Added __PADWirelessIDCheck(). 99 100 10 8/24/00 7:32p Shiki 101 Revised PAD_BUTTON/TRIGGER_* define names for the final controller. 102 103 9 3/23/00 4:34p Shiki 104 Clean up. 105 106 8 3/23/00 4:31p Shiki 107 Added PADSetSpec(). 108 109 7 3/22/00 8:11p Shiki 110 Revised PAD_TRIGGER_* defines for the final controller IC. 111 112 6 3/10/00 2:56p Shiki 113 Revised motor control functions. 114 115 5 3/09/00 8:28p Shiki 116 Added PADControlMotor(). 117 118 4 2/24/00 7:48p Shiki 119 Added PAD_TRIGGER_*. 120 121 3 2/24/00 5:49p Shiki 122 Updated to the final spec. 123 124 2 12/15/99 8:25p Shiki 125 Added substickX/Y into PADStatus. 126 127 10 9/23/99 4:55p Shiki 128 Renamed 'errno' of PADStatus to 'err'. 129 130 9 9/13/99 6:26p Shiki 131 Inserted (u16) casts in PADButtonUp/Down macros. 132 133 7 5/11/99 4:42p Shiki 134 Refreshed include tree. 135 136 5 5/06/99 8:18p Shiki 137 Renamed PADNormalize() to PADClamp() 138 139 4 5/06/99 6:12p Shiki 140 Added PADNormalize(). 141 142 3 5/05/99 5:42p Shiki 143 Added PADButtonDown and PADButtonUp macros. 144 145 2 5/04/99 8:46p Shiki 146 Fixed comment. 147 148 1 5/04/99 8:32p Shiki 149 150 $NoKeywords: $ 151 *---------------------------------------------------------------------------*/ 152 153 #ifndef __PAD_H__ 154 #define __PAD_H__ 155 156 #include <revolution/types.h> 157 #include <revolution/os.h> 158 159 #ifdef __cplusplus 160 extern "C" { 161 #endif 162 163 // CAUTION: Define PAD_USESPEC as long as bread boards or prototype 164 // controllers (including DS4) are in use. 165 #define PAD_USESPEC 166 167 #ifdef __MWERKS__ 168 #pragma warn_padding off 169 #endif 170 171 typedef struct PADStatus 172 { 173 u16 button; // Or-ed PAD_BUTTON_* bits 174 s8 stickX; // -128 <= stickX <= 127 175 s8 stickY; // -128 <= stickY <= 127 176 s8 substickX; // -128 <= substickX <= 127 177 s8 substickY; // -128 <= substickY <= 127 178 u8 triggerLeft; // 0 <= triggerLeft <= 255 179 u8 triggerRight; // 0 <= triggerRight <= 255 180 u8 analogA; // 0 <= analogA <= 255 181 u8 analogB; // 0 <= analogB <= 255 182 s8 err; // one of PAD_ERR_* number 183 } PADStatus; 184 185 #ifdef __MWERKS__ 186 #pragma warn_padding reset 187 #endif 188 189 #define PAD_MAX_CONTROLLERS 4 190 191 #define PAD_BUTTON_LEFT 0x0001 192 #define PAD_BUTTON_RIGHT 0x0002 193 #define PAD_BUTTON_DOWN 0x0004 194 #define PAD_BUTTON_UP 0x0008 195 #define PAD_TRIGGER_Z 0x0010 196 #define PAD_TRIGGER_R 0x0020 197 #define PAD_TRIGGER_L 0x0040 198 #define PAD_BUTTON_A 0x0100 199 #define PAD_BUTTON_B 0x0200 200 #define PAD_BUTTON_X 0x0400 201 #define PAD_BUTTON_Y 0x0800 202 #define PAD_BUTTON_MENU 0x1000 203 #define PAD_BUTTON_START 0x1000 204 205 #define PAD_CHAN0 0 206 #define PAD_CHAN1 1 207 #define PAD_CHAN2 2 208 #define PAD_CHAN3 3 209 210 #define PAD_CHAN0_BIT 0x80000000 211 #define PAD_CHAN1_BIT 0x40000000 212 #define PAD_CHAN2_BIT 0x20000000 213 #define PAD_CHAN3_BIT 0x10000000 214 215 #define PAD_ERR_NONE 0 216 #define PAD_ERR_NO_CONTROLLER -1 217 #define PAD_ERR_NOT_READY -2 218 #define PAD_ERR_TRANSFER -3 219 220 #define PAD_MOTOR_STOP 0 221 #define PAD_MOTOR_RUMBLE 1 222 #define PAD_MOTOR_STOP_HARD 2 223 224 #ifdef PAD_USESPEC 225 #define PAD_SPEC_0 0 // bread board (ver 0.x) 226 #define PAD_SPEC_1 1 // 1st prototypes (ver 1.0) 227 #define PAD_SPEC_2 2 // 2nd prototypes (ver 3.0 FPGA) 228 #define PAD_SPEC_3 3 // DS3 229 #define PAD_SPEC_4 4 // DS4 230 #define PAD_SPEC_5 5 // DS5 (production version) 231 #endif // PAD_USESPEC 232 233 // PADSetAnalogMode() param 234 #define PAD_MODE_0 0 235 #define PAD_MODE_1 1 236 #define PAD_MODE_2 2 237 #define PAD_MODE_3 3 238 #define PAD_MODE_4 4 239 #define PAD_MODE_5 5 240 #define PAD_MODE_6 6 241 #define PAD_MODE_7 7 242 243 #define PADButtonDown(buttonLast, button) \ 244 ((u16) (((buttonLast) ^ (button)) & (button))) 245 246 #define PADButtonUp(buttonLast, button) \ 247 ((u16) (((buttonLast) ^ (button)) & (buttonLast))) 248 249 #define PADStartMotor(chan) PADControlMotor((chan), PAD_MOTOR_RUMBLE) 250 #define PADStopMotorHard(chan) PADControlMotor((chan), PAD_MOTOR_STOP_HARD) 251 #define PADStopMotor(chan) PADControlMotor((chan), PAD_MOTOR_STOP) 252 253 // clamp algorithm for stick 254 #define PAD_STICK_CLAMP_OCTA_WITH_MARGIN 0 255 #define PAD_STICK_CLAMP_OCTA_WITHOUT_MARGIN 1 256 #define PAD_STICK_CLAMP_CIRCLE_WITH_MARGIN 2 257 #define PAD_STICK_CLAMP_CIRCLE_WITHOUT_MARGIN 3 258 // clamp algorithm for trigger 259 #define PAD_TRIGGER_FIXED_BASE 0 260 #define PAD_TRIGGER_INDIVIDUAL_BASE 1 261 262 263 BOOL PADInit ( void ); 264 BOOL PADReset ( u32 mask ); 265 u32 PADRead ( PADStatus* status ); 266 void PADSetSamplingRate ( u32 msec ); 267 void PADClamp ( PADStatus* status ); 268 void PADClampCircle ( PADStatus* status ); 269 void PADClamp2 ( PADStatus* status, u32 type ); 270 void PADClampCircle2 ( PADStatus* status, u32 type ); 271 void PADClampTrigger ( PADStatus* status, u32 type ); 272 void PADControlAllMotors ( const u32* command ); 273 void PADControlMotor ( int chan, u32 command ); 274 BOOL PADRecalibrate ( u32 mask ); 275 BOOL PADSync ( void ); 276 void PADSetAnalogMode ( u32 mode ); 277 278 typedef void (* PADSamplingCallback )(void); 279 280 PADSamplingCallback PADSetSamplingCallback( PADSamplingCallback callback ); 281 282 // obsolete. Use SIProbe() instead. 283 BOOL PADGetType ( s32 chan, u32* type ); 284 285 #ifdef PAD_USESPEC 286 void PADSetSpec ( u32 model ); 287 u32 PADGetSpec ( void ); 288 #endif // PAD_USESPEC 289 290 #ifdef _DEBUG 291 void __PADTestSamplingRate( u32 tvmode ); 292 #endif // _DEBUG 293 294 // 295 // System internal use only (do not use/touch) 296 // 297 298 BOOL __PADDisableRecalibration( BOOL disable ); 299 BOOL __PADDisableRumble ( BOOL disable ); 300 void __PADDisableXPatch ( void ); 301 302 extern u32 __PADFixBits; 303 304 // 305 // 306 // 307 308 #ifdef __cplusplus 309 } 310 #endif 311 312 #endif // __PAD_H__ 313