PS2SDK
PS2 Homebrew Libraries
padCmds.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Lukasz Bruun <mail@lukasz.dk>
3  *
4  * See the file LICENSE included with this distribution for licensing terms.
5  */
6 
12 #include "types.h"
13 #include "thevent.h"
14 #include "freepad.h"
15 #include "sio2Cmds.h"
16 #include "padData.h"
17 
18 static void shiftarray(u8 *buf)
19 {
20  u8 temp[32];
21  u32 i;
22 
23  for(i=0; i < 32; i++)
24  temp[i] = buf[i];
25 
26  buf[0] = 0xFF;
27 
28  for(i=0; i < 31; i++)
29  buf[i+1] = temp[i];
30 }
31 
32 u32 PadIsSupported(padState_t *pstate)
33 {
34  u32 res;
35  u32 ret = 0;
36 
37  res = sio2CmdGetPortCtrl1(0, pstate->stat70bit, pstate->model);
38 
39  pdSetCtrl1(pstate->port, pstate->slot, res);
40 
41  res = sio2CmdGetPortCtrl2(0, pstate->stat70bit);
42 
43  pdSetCtrl2(pstate->port, pstate->slot, res);
44 
45  res = pdGetRegData(0);
46 
47  pdSetRegData(pstate->port, pstate->slot, res);
48 
49  res = pdGetInSize(0);
50 
51  pdSetInSize(pstate->port, pstate->slot, res);
52 
53  res = pdGetOutSize(0);
54 
55  pdSetOutSize(pstate->port, pstate->slot, res);
56 
57  sio2CmdSetReadData(0, pstate->inbuffer);
58 
59  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
60 
61  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
62 
63  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
64 
65  res = pdGetError(pstate->port, pstate->slot);
66 
67  if(res == 0)
68  {
69  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
70 
71  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
72 
73  if((pstate->outbuffer[1] != 0)
74  && (sio2cmdCheckId(pstate->outbuffer[1]) == 1))
75  { //Twice? Okay...
76  if((pstate->outbuffer[1] != 0)
77  && (sio2cmdCheckId(pstate->outbuffer[1]) == 1))
78  {
79  pstate->modeCurId = pstate->outbuffer[1];
80  ret = 1;
81  }
82  }
83  }
84 
85  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
86 
87  return ret;
88 }
89 
90 u32 VrefParam(u32 val, padState_t *pstate)
91 {
92  u32 res;
93  u32 ret = 0;
94 
95  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
96 
97  pdSetCtrl1(pstate->port, pstate->slot, res);
98 
99  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
100 
101  pdSetCtrl2(pstate->port, pstate->slot, res),
102 
103  res = pdGetRegData(PAD_ID_CONFIG);
104 
105  pdSetRegData(pstate->port, pstate->slot, res);
106 
107  res = pdGetInSize(PAD_ID_CONFIG);
108 
109  pdSetInSize(pstate->port, pstate->slot, res);
110 
111  res = pdGetOutSize(PAD_ID_CONFIG);
112 
113  pdSetOutSize(pstate->port, pstate->slot, res);
114 
115  sio2CmdSetSetVrefParam(PAD_ID_CONFIG, pstate->inbuffer);
116 
117  pstate->inbuffer[3] = val;
118  pstate->inbuffer[4] = pstate->modeParam[val];
119 
120  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
121 
122  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
123 
124  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
125 
126  if( pdGetError(pstate->port, pstate->slot) == 0)
127  {
128  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
129 
130  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
131 
132  if(pstate->outbuffer[1] == PAD_ID_CONFIG) ret = 1;
133  }
134 
135  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
136 
137  return ret;
138 }
139 
140 u32 ReadData(padState_t *pstate)
141 {
142  u32 res, i;
143  u32 ret = 0;
144 
145  res = sio2CmdGetPortCtrl1(pstate->modeCurId, pstate->stat70bit, pstate->model);
146 
147  pdSetCtrl1(pstate->port, pstate->slot, res);
148 
149  res = sio2CmdGetPortCtrl2(pstate->modeCurId, pstate->stat70bit);
150 
151  pdSetCtrl2(pstate->port, pstate->slot, res);
152 
153  res = pdGetRegData( pstate->modeCurId );
154 
155  pdSetRegData( pstate->port, pstate->slot, res);
156 
157  res = pdGetInSize( pstate->modeCurId );
158 
159  pdSetInSize( pstate->port, pstate->slot, res);
160 
161  res = pdGetOutSize( pstate->modeCurId );
162 
163  pdSetOutSize(pstate->port, pstate->slot, res);
164 
165  for(i=0; i < 32; i++)
166  {
167  pstate->inbuffer[i] = 0;
168  pstate->outbuffer[i] = 0;
169  }
170 
171  sio2CmdSetReadData(pstate->modeCurId, pstate->inbuffer);
172 
173  for(i=0; i < (u32)(pstate->ee_actDirectSize); i++)
174  {
175  if(pstate->ee_actAlignData.data[i] == 0xFF)
176  pstate->inbuffer[i+3] = pstate->ee_actAlignData.data[i];
177  else
178  pstate->inbuffer[i+3] = pstate->ee_actDirectData.data[i];
179  }
180 
181  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
182 
183  SetEventFlag( pstate->eventflag, EF_PAD_TRANSFER_START);
184 
185  WaitClearEvent( pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
186 
187  res = pdGetError(pstate->port, pstate->slot);
188 
189  if(res == 0)
190  {
191  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
192 
193  ret = 1;
194 
195  if(pstate->stat70bit == 1) shiftarray( pstate->outbuffer );
196  }
197 
198  SetEventFlag( pstate->eventflag, EF_TASK_DONE);
199 
200  return ret;
201 }
202 
203 u32 EnterConfigMode(u8 val, padState_t *pstate)
204 {
205  u32 res;
206  u32 ret = 0;
207 
208  res = sio2CmdGetPortCtrl1(val, pstate->stat70bit, pstate->model);
209 
210  pdSetCtrl1(pstate->port, pstate->slot, res);
211 
212  res = sio2CmdGetPortCtrl2(val, pstate->stat70bit);
213 
214  pdSetCtrl2(pstate->port, pstate->slot, res);
215 
216  res = pdGetRegData(val);
217 
218  pdSetRegData(pstate->port, pstate->slot, res);
219 
220  res = pdGetInSize(val);
221 
222  pdSetInSize(pstate->port, pstate->slot, res);
223 
224  res = pdGetOutSize(val);
225 
226  pdSetOutSize(pstate->port, pstate->slot, res);
227 
228  sio2CmdSetEnterConfigMode(val, pstate->inbuffer);
229 
230  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
231 
232  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
233 
234  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
235 
236  if( pdGetError(pstate->port, pstate->slot) == 0)
237  {
238  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
239 
240  if( pstate->stat70bit == 1)
241  {
242  shiftarray(pstate->outbuffer);
243  }
244 
245  ret = 1;
246  }
247 
248  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
249 
250 
251  return ret;
252 }
253 
254 u32 QueryModel(padState_t *pstate)
255 {
256  u32 res;
257  u32 ret = 0;
258 
259  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
260 
261  pdSetCtrl1(pstate->port, pstate->slot, res);
262 
263  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
264 
265  pdSetCtrl2(pstate->port, pstate->slot, res);
266 
267  res = pdGetRegData(PAD_ID_CONFIG);
268 
269  pdSetRegData(pstate->port, pstate->slot, res);
270 
271  res = pdGetInSize(PAD_ID_CONFIG);
272 
273  pdSetInSize(pstate->port, pstate->slot, res);
274 
275  res = pdGetOutSize(PAD_ID_CONFIG);
276 
277  pdSetOutSize(pstate->port, pstate->slot, res);
278 
279  sio2CmdSetQueryModel(PAD_ID_CONFIG, pstate->inbuffer);
280 
281  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
282 
283  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
284 
285  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
286 
287  if( pdGetError(pstate->port, pstate->slot) == 0)
288  {
289  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
290 
291  if( pstate->stat70bit == 1) shiftarray( pstate->outbuffer );
292 
293  if( pstate->outbuffer[1] == PAD_ID_CONFIG)
294  {
295  pstate->numActuators = pstate->outbuffer[6];
296  pstate->model = pstate->outbuffer[3];
297  pstate->numModes = pstate->outbuffer[4];
298  pstate->modeCurOffs = pstate->outbuffer[5];
299  pstate->numActComb = pstate->outbuffer[7];
300 
301  if( pstate->numActuators > 4) pstate->numActuators = 4;
302  if( pstate->numActComb > 4 ) pstate->numActComb = 4;
303  if( pstate->numModes > 4) pstate->numModes = 4;
304 
305  ret = 1;
306  }
307  }
308 
309  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
310 
311  return ret;
312 }
313 
314 u32 SetMainMode(padState_t *pstate)
315 {
316  u32 ret = 0;
317  u32 res;
318 
319  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
320 
321  pdSetCtrl1(pstate->port, pstate->slot, res);
322 
323  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
324 
325  pdSetCtrl2(pstate->port, pstate->slot, res);
326 
327  res = pdGetRegData(PAD_ID_CONFIG);
328 
329  pdSetRegData(pstate->port, pstate->slot, res);
330 
331  res = pdGetInSize(PAD_ID_CONFIG);
332 
333  pdSetInSize(pstate->port, pstate->slot, res);
334 
335  res = pdGetOutSize(PAD_ID_CONFIG);
336 
337  pdSetOutSize(pstate->port, pstate->slot, res);
338 
339  sio2CmdSetSetMainMode(PAD_ID_CONFIG, pstate->inbuffer);
340 
341  pstate->inbuffer[3] = pstate->mode;
342  pstate->inbuffer[4] = pstate->lock;
343 
344  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
345 
346  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
347 
348  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
349 
350  if( pdGetError(pstate->port, pstate->slot) == 0)
351  {
352  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
353 
354  if(pstate->stat70bit == 1) shiftarray( pstate->outbuffer);
355 
356  if(pstate->outbuffer[1] == PAD_ID_CONFIG) ret = 1;
357 
358  }
359 
360  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
361 
362  return ret;
363 }
364 
365 u32 QueryAct(u32 actuator, padState_t *pstate)
366 {
367  u32 ret = 0;
368  u32 res;
369 
370  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
371 
372  pdSetCtrl1(pstate->port, pstate->slot, res);
373 
374  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
375 
376  pdSetCtrl2(pstate->port, pstate->slot, res);
377 
378  res = pdGetRegData(PAD_ID_CONFIG);
379 
380  pdSetRegData(pstate->port, pstate->slot, res);
381 
382  res = pdGetInSize(PAD_ID_CONFIG);
383 
384  pdSetInSize(pstate->port, pstate->slot, res);
385 
386  res = pdGetOutSize(PAD_ID_CONFIG);
387 
388  pdSetOutSize(pstate->port, pstate->slot, res);
389 
390  sio2CmdSetQueryAct(PAD_ID_CONFIG, pstate->inbuffer);
391 
392  pstate->inbuffer[3] = actuator;
393 
394  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
395 
396  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
397 
398  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
399 
400  if( pdGetError(pstate->port, pstate->slot) == 0)
401  {
402  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
403 
404  if(pstate->stat70bit == 1) shiftarray( pstate->outbuffer );
405 
406  if(pstate->outbuffer[1] == PAD_ID_CONFIG)
407  {
408  u8 *actData = pstate->actData.data[actuator];
409 
410  actData[0] = pstate->outbuffer[5];
411  actData[1] = pstate->outbuffer[6];
412  actData[2] = pstate->outbuffer[7];
413  actData[3] = pstate->outbuffer[8];
414 
415  ret = 1;
416  }
417  }
418 
419  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
420 
421  return ret;
422 }
423 
424 u32 QueryComb(u32 val, padState_t *pstate)
425 {
426  u32 ret = 0;
427  u32 res;
428 
429  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
430 
431  pdSetCtrl1(pstate->port, pstate->slot, res);
432 
433  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
434 
435  pdSetCtrl2(pstate->port, pstate->slot, res),
436 
437  res = pdGetRegData(PAD_ID_CONFIG);
438 
439  pdSetRegData(pstate->port, pstate->slot, res);
440 
441  res = pdGetInSize(PAD_ID_CONFIG);
442 
443  pdSetInSize(pstate->port, pstate->slot, res);
444 
445  res = pdGetOutSize(PAD_ID_CONFIG);
446 
447  pdSetOutSize(pstate->port, pstate->slot, res);
448 
449  sio2CmdSetQueryComb(PAD_ID_CONFIG, pstate->inbuffer);
450 
451  pstate->inbuffer[3] = val;
452 
453  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
454 
455  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
456 
457  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
458 
459  if( pdGetError(pstate->port, pstate->slot) == 0)
460  {
461  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
462 
463  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
464 
465  if(pstate->outbuffer[1] == PAD_ID_CONFIG)
466  {
467  u8 *data = pstate->combData.data[val];
468 
469  data[0] = pstate->outbuffer[5];
470  data[1] = pstate->outbuffer[6];
471  data[2] = pstate->outbuffer[7];
472  data[3] = pstate->outbuffer[8];
473 
474  ret = 1;
475  }
476  }
477 
478  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
479 
480 
481  return ret;
482 }
483 
484 u32 QueryMode(u32 val, padState_t *pstate)
485 {
486  u32 res;
487  u32 ret = 0;
488 
489  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
490 
491  pdSetCtrl1(pstate->port, pstate->slot, res);
492 
493  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
494 
495  pdSetCtrl2(pstate->port, pstate->slot, res),
496 
497  res = pdGetRegData(PAD_ID_CONFIG);
498 
499  pdSetRegData(pstate->port, pstate->slot, res);
500 
501  res = pdGetInSize(PAD_ID_CONFIG);
502 
503  pdSetInSize(pstate->port, pstate->slot, res);
504 
505  res = pdGetOutSize(PAD_ID_CONFIG);
506 
507  pdSetOutSize(pstate->port, pstate->slot, res);
508 
509  sio2CmdSetQueryMode(PAD_ID_CONFIG, pstate->inbuffer);
510 
511  pstate->inbuffer[3] = val;
512 
513  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
514 
515  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
516 
517  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
518 
519  if( pdGetError(pstate->port, pstate->slot) == 0)
520  {
521  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
522 
523  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
524 
525  if(pstate->outbuffer[1] == PAD_ID_CONFIG)
526  {
527  u16 *modeTable = pstate->modeTable.data;
528 
529  modeTable[val] = (pstate->outbuffer[5] << 8) | pstate->outbuffer[6];
530 
531  ret = 1;
532  }
533  }
534 
535  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
536 
537  return ret;
538 }
539 
540 u32 ExitConfigMode(padState_t *pstate)
541 {
542  u32 res;
543  u32 ret = 0;
544 
545  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
546 
547  pdSetCtrl1(pstate->port, pstate->slot, res);
548 
549  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
550 
551  pdSetCtrl2(pstate->port, pstate->slot, res),
552 
553  res = pdGetRegData(PAD_ID_CONFIG);
554 
555  pdSetRegData(pstate->port, pstate->slot, res);
556 
557  res = pdGetInSize(PAD_ID_CONFIG);
558 
559  pdSetInSize(pstate->port, pstate->slot, res);
560 
561  res = pdGetOutSize(PAD_ID_CONFIG);
562 
563  pdSetOutSize(pstate->port, pstate->slot, res);
564 
565  sio2CmdSetExitConfigMode(PAD_ID_CONFIG, pstate->inbuffer);
566 
567  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
568 
569  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
570 
571  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
572 
573  if( pdGetError(pstate->port, pstate->slot) == 0)
574  {
575  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
576 
577  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
578 
579  ret = 1;
580  }
581 
582  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
583 
584  return ret;
585 }
586 
587 u32 SetActAlign(padState_t *pstate)
588 {
589  u32 res, i;
590  u32 ret = 0;
591 
592  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
593 
594  pdSetCtrl1(pstate->port, pstate->slot, res);
595 
596  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
597 
598  pdSetCtrl2(pstate->port, pstate->slot, res),
599 
600  res = pdGetRegData(PAD_ID_CONFIG);
601 
602  pdSetRegData(pstate->port, pstate->slot, res);
603 
604  res = pdGetInSize(PAD_ID_CONFIG);
605 
606  pdSetInSize(pstate->port, pstate->slot, res);
607 
608  res = pdGetOutSize(PAD_ID_CONFIG);
609 
610  pdSetOutSize(pstate->port, pstate->slot, res);
611 
612  sio2CmdSetSetActAlign(PAD_ID_CONFIG, pstate->inbuffer);
613 
614  for(i=0; i < 6; i++)
615  pstate->inbuffer[3+i] = pstate->ee_actAlignData.data[i];
616 
617  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
618 
619  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
620 
621  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
622 
623  if( pdGetError(pstate->port, pstate->slot) == 0)
624  {
625  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
626 
627  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
628 
629  if(pstate->outbuffer[1] == PAD_ID_CONFIG) ret = 1;
630  }
631 
632 
633  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
634 
635  return ret;
636 }
637 
638 u32 QueryButtonMask(padState_t *pstate)
639 {
640  u32 res;
641  u32 ret = 0;
642 
643  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
644 
645  pdSetCtrl1(pstate->port, pstate->slot, res);
646 
647  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
648 
649  pdSetCtrl2(pstate->port, pstate->slot, res),
650 
651  res = pdGetRegData(PAD_ID_CONFIG);
652 
653  pdSetRegData(pstate->port, pstate->slot, res);
654 
655  res = pdGetInSize(PAD_ID_CONFIG);
656 
657  pdSetInSize(pstate->port, pstate->slot, res);
658 
659  res = pdGetOutSize(PAD_ID_CONFIG);
660 
661  pdSetOutSize(pstate->port, pstate->slot, res);
662 
663  sio2CmdSetQueryButtonMask(PAD_ID_CONFIG, pstate->inbuffer);
664 
665  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
666 
667  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
668 
669  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
670 
671  if( pdGetError(pstate->port, pstate->slot) == 0)
672  {
673  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
674 
675  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
676 
677  if(pstate->outbuffer[8] == 0x5A)
678  {
679  pstate->buttonMask[0] = pstate->outbuffer[3];
680  pstate->buttonMask[1] = pstate->outbuffer[4];
681  pstate->buttonMask[2] = pstate->outbuffer[5];
682  pstate->buttonMask[3] = pstate->outbuffer[6];
683  }
684  else
685  {
686  pstate->buttonMask[0] = 0;
687  pstate->buttonMask[1] = 0;
688  pstate->buttonMask[2] = 0;
689  pstate->buttonMask[3] = 0;
690  }
691 
692  ret = 1;
693  }
694 
695  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
696 
697  return ret;
698 }
699 
700 u32 SetButtonInfo(padState_t *pstate)
701 {
702  u32 res, i;
703  u32 ret = 0;
704 
705  res = sio2CmdGetPortCtrl1(PAD_ID_CONFIG, pstate->stat70bit, pstate->model);
706 
707  pdSetCtrl1(pstate->port, pstate->slot, res);
708 
709  res = sio2CmdGetPortCtrl2(PAD_ID_CONFIG, pstate->stat70bit);
710 
711  pdSetCtrl2(pstate->port, pstate->slot, res),
712 
713  res = pdGetRegData(PAD_ID_CONFIG);
714 
715  pdSetRegData(pstate->port, pstate->slot, res);
716 
717  res = pdGetInSize(PAD_ID_CONFIG);
718 
719  pdSetInSize(pstate->port, pstate->slot, res);
720 
721  res = pdGetOutSize(PAD_ID_CONFIG);
722 
723  pdSetOutSize(pstate->port, pstate->slot, res);
724 
725  sio2CmdSetSetButtonInfo(PAD_ID_CONFIG, pstate->inbuffer);
726 
727  for(i=0; i < 4; i++)
728  pstate->inbuffer[3+i] = pstate->buttonInfo[i];
729 
730  pdSetInBuffer(pstate->port, pstate->slot, 0, pstate->inbuffer);
731 
732  SetEventFlag(pstate->eventflag, EF_PAD_TRANSFER_START);
733 
734  WaitClearEvent(pstate->eventflag, EF_PAD_TRANSFER_DONE, WEF_AND|WEF_CLEAR, NULL);
735 
736  if( pdGetError(pstate->port, pstate->slot) == 0)
737  {
738  pdGetOutBuffer(pstate->port, pstate->slot, 0, pstate->outbuffer);
739 
740  if(pstate->stat70bit == 1) shiftarray(pstate->outbuffer);
741 
742  if(pstate->outbuffer[1] == PAD_ID_CONFIG) ret = 1;
743  }
744 
745  SetEventFlag(pstate->eventflag, EF_TASK_DONE);
746 
747  return ret;
748 }
padState_t
Definition: freepad.h:158
freepad.h
padData.h
thevent.h
sio2Cmds.h