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