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