31#define PAD_BIND_RPC_ID1 0x80000100
32#define PAD_BIND_RPC_ID2 0x80000101
34#define PAD_RPCCMD_OPEN 0x01
35#define PAD_RPCCMD_SET_MMODE 0x06
36#define PAD_RPCCMD_SET_ACTDIR 0x07
37#define PAD_RPCCMD_SET_ACTALIGN 0x08
38#define PAD_RPCCMD_GET_BTNMASK 0x09
39#define PAD_RPCCMD_SET_BTNINFO 0x0A
40#define PAD_RPCCMD_SET_VREF 0x0B
41#define PAD_RPCCMD_GET_PORTMAX 0x0C
42#define PAD_RPCCMD_GET_SLOTMAX 0x0D
43#define PAD_RPCCMD_CLOSE 0x0E
44#define PAD_RPCCMD_END 0x0F
45#define PAD_RPCCMD_INIT 0x10
46#define PAD_RPCCMD_GET_MODVER 0x12
48#define PAD_BIND_RPC_ID1 0x8000010f
49#define PAD_BIND_RPC_ID2 0x8000011f
51#define PAD_RPCCMD_OPEN 0x80000100
52#define PAD_RPCCMD_INFO_ACT 0x80000102
53#define PAD_RPCCMD_INFO_COMB 0x80000103
54#define PAD_RPCCMD_INFO_MODE 0x80000104
55#define PAD_RPCCMD_SET_MMODE 0x80000105
56#define PAD_RPCCMD_SET_ACTDIR 0x80000106
57#define PAD_RPCCMD_SET_ACTALIGN 0x80000107
58#define PAD_RPCCMD_GET_BTNMASK 0x80000108
59#define PAD_RPCCMD_SET_BTNINFO 0x80000109
60#define PAD_RPCCMD_SET_VREF 0x8000010a
61#define PAD_RPCCMD_GET_PORTMAX 0x8000010b
62#define PAD_RPCCMD_GET_SLOTMAX 0x8000010c
63#define PAD_RPCCMD_CLOSE 0x8000010d
64#define PAD_RPCCMD_END 0x8000010e
65#define PAD_RPCCMD_INIT 0x00000100
78 unsigned char *padBuf;
124 unsigned char reqState;
127 unsigned char data[32];
136 unsigned char errorCount;
137 unsigned char unk49[15];
141extern int _iop_reboot_count;
146static const char padStateString[8][16] = {
"DISCONNECT",
"FINDPAD",
147 "FINDCTP1",
"",
"",
"EXECCMD",
149static const char padReqStateString[3][16] = {
"COMPLETE",
"FAILED",
"BUSY"};
151static int padInitialised = 0;
201 } padSetMainModeArgs;
209 } padGetButtonMaskArgs;
214 } padSetButtonInfoArgs;
218 } padSetButtonInfoResult;
231 } padActDirAlignArgs;
257 pdata =
PadState[port][slot].padData;
258 SyncDCache(pdata, (u8 *)pdata + 256);
260 if(pdata[0].frame < pdata[1].frame) {
273static struct open_slot*
274padGetConnDmaStr(
void)
276 SyncDCache(openSlot, (u8*)openSlot +
sizeof(openSlot));
278 if(openSlot[0].frame < openSlot[1].frame)
301 static int _rb_count = 0;
303 if (_rb_count != _iop_reboot_count)
305 _rb_count = _iop_reboot_count;
314 padsif[0].server = NULL;
315 padsif[1].server = NULL;
318 if (SifBindRpc(&padsif[0], PAD_BIND_RPC_ID1, 0) < 0) {
322 }
while(!padsif[0].server);
325 if (SifBindRpc(&padsif[1], PAD_BIND_RPC_ID2, 0) < 0) {
329 }
while(!padsif[1].server);
360 buffer.padInitArgs.command = PAD_RPCCMD_INIT;
361 buffer.padInitArgs.statBuf = openSlot;
363 buffer.command = PAD_RPCCMD_INIT;
365 ret = SifCallRpc( &padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL);
367 return(ret >= 0 ? buffer.padResult.result : 0);
380 buffer.command=PAD_RPCCMD_END;
382 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
385 ret = buffer.padResult.result;
402 if((u32)padArea & 0xf) {
403 printf(
"Address is not 16-byte aligned.\n");
408 if((u32)padArea & 0x3f) {
409 printf(
"Address is not 16-byte aligned.\n");
414 for (i=0; i<2; i++) {
415 memset(dma_buf[i].data, 0xff, 32);
416 dma_buf[i].frame = 0;
417 dma_buf[i].length = 0;
418 dma_buf[i].state = PAD_STATE_EXECCMD;
419 dma_buf[i].reqState = PAD_RSTAT_BUSY;
424 dma_buf[i].currentTask = 0;
426 dma_buf[i].length = 0;
428 dma_buf[i].buttonDataReady = 0;
433 buffer.padOpenArgs.command = PAD_RPCCMD_OPEN;
434 buffer.padOpenArgs.port = port;
435 buffer.padOpenArgs.slot = slot;
436 buffer.padOpenArgs.padArea = padArea;
438 if(SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
444 PadState[port][slot].padData = padArea;
445 PadState[port][slot].padBuf = buffer.padOpenResult.padBuf;
447 return buffer.padOpenResult.result;
456 buffer.padCloseArgs.command = PAD_RPCCMD_CLOSE;
457 buffer.padCloseArgs.port = port;
458 buffer.padCloseArgs.slot = slot;
459 buffer.padCloseArgs.mode = 1;
461 ret = SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL);
467 return buffer.padResult.result;
479 memcpy(data, pdata->data, pdata->length);
480 return pdata->length;
492 state = pdata->state;
495 if (state == PAD_STATE_ERROR)
497 if (pdata->findPadRetries)
499 return PAD_STATE_FINDPAD;
504 if (state == PAD_STATE_STABLE) {
506 return PAD_STATE_EXECCMD;
519 return pdata->reqState;
529 pdata->reqState = state;
534padStateInt2String(
int state,
char buf[16])
538 strcpy(buf, padStateString[state]);
543padReqStateInt2String(
int state,
char buf[16])
546 strcpy(buf, padReqStateString[state]);
553 buffer.command = PAD_RPCCMD_GET_PORTMAX;
555 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
558 return buffer.padResult.result;
565 buffer.padSlotMaxArgs.command = PAD_RPCCMD_GET_SLOTMAX;
566 buffer.padSlotMaxArgs.port = port;
568 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
571 return buffer.padResult.result;
578 buffer.command = PAD_RPCCMD_GET_MODVER;
580 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
583 return buffer.padResult.result;
597 if (pdata->currentTask != 1)
599 if (pdata->reqState == PAD_RSTAT_BUSY)
604 if (pdata->modeCurId == 0xF3)
607 return (pdata->modeCurId >> 4);
610 case PAD_MODECUREXID:
611 if (pdata->modeConfig == pdata->currentTask)
613 return pdata->modeTable[pdata->modeCurOffs];
616 case PAD_MODECUROFFS:
617 if (pdata->modeConfig != 0)
618 return pdata->modeCurOffs;
624 if (pdata->modeConfig != 0) {
626 return pdata->nrOfModes;
628 else if (index < pdata->nrOfModes) {
629 return pdata->modeTable[index];
641 buffer.padInfoModeArgs.command = PAD_RPCCMD_INFO_MODE;
642 buffer.padInfoModeArgs.port = port;
643 buffer.padInfoModeArgs.slot = slot;
644 buffer.padInfoModeArgs.infoMode = infoMode;
645 buffer.padInfoModeArgs.index = index;
647 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
650 if (buffer.padModeResult.result == 1) {
653 return buffer.padModeResult.result;
661 buffer.padSetMainModeArgs.command = PAD_RPCCMD_SET_MMODE;
662 buffer.padSetMainModeArgs.port = port;
663 buffer.padSetMainModeArgs.slot = slot;
664 buffer.padSetMainModeArgs.mode = mode;
665 buffer.padSetMainModeArgs.lock = lock;
667 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
670 if (buffer.padModeResult.result == 1) {
673 return buffer.padModeResult.result;
681 mask = padGetButtonMask(port, slot);
694 return padSetButtonInfo(port, slot, 0xFFF);
700 return padSetButtonInfo(port, slot, 0);
705padGetButtonMask(
int port,
int slot)
708 buffer.padGetButtonMaskArgs.command = PAD_RPCCMD_GET_BTNMASK;
709 buffer.padGetButtonMaskArgs.port = port;
710 buffer.padGetButtonMaskArgs.slot = slot;
712 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
715 return buffer.padResult.result;
719padSetButtonInfo(
int port,
int slot,
int buttonInfo)
723 buffer.padSetButtonInfoArgs.command = PAD_RPCCMD_SET_BTNINFO;
724 buffer.padSetButtonInfoArgs.port = port;
725 buffer.padSetButtonInfoArgs.slot = slot;
726 buffer.padSetButtonInfoArgs.buttonInfo = buttonInfo;
728 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
731 val = buffer.padSetButtonInfoResult.result;
736 return buffer.padSetButtonInfoResult.result;
747 if (pdata->currentTask != 1)
749 if (pdata->modeConfig < 2)
751 if (actuator >= pdata->nrOfActuators)
755 return pdata->nrOfActuators;
760 return pdata->actData[actuator*4+cmd];
762 buffer.padInfoActArgs.command = PAD_RPCCMD_INFO_ACT;
763 buffer.padInfoActArgs.port = port;
764 buffer.padInfoActArgs.slot = slot;
765 buffer.padInfoActArgs.actuator = actuator;
766 buffer.padInfoActArgs.act_cmd = cmd;
768 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
771 if (buffer.padModeResult.result == 1) {
774 return buffer.padModeResult.result;
784 buffer.padActDirAlignArgs.command = PAD_RPCCMD_SET_ACTALIGN;
785 buffer.padActDirAlignArgs.port = port;
786 buffer.padActDirAlignArgs.slot = slot;
788 ptr = buffer.padActDirAlignArgs.align;
792 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
795 if (buffer.padModeResult.result == 1) {
798 return buffer.padModeResult.result;
807 buffer.padActDirAlignArgs.command = PAD_RPCCMD_SET_ACTDIR;
808 buffer.padActDirAlignArgs.port = port;
809 buffer.padActDirAlignArgs.slot = slot;
811 ptr = buffer.padActDirAlignArgs.align;
815 if (SifCallRpc(&padsif[0], 1, 0, &buffer, 128, &buffer, 128, NULL, NULL) < 0)
818 return buffer.padModeResult.result;
828 struct open_slot *oslot;
830 oslot = padGetConnDmaStr();
832 return ((oslot->openSlots[port] >> slot) & 0x1);
int padPortOpen(int port, int slot, void *padArea)
int padPortInit(int mode)
unsigned char padRead(int port, int slot, struct padButtonStatus *data)
int padInfoMode(int port, int slot, int infoMode, int index)
unsigned char padInfoAct(int port, int slot, int actuator, int cmd)
int padExitPressMode(int port, int slot)
static struct pad_data * padGetDmaStr(int port, int slot)
int padGetConnection(int port, int slot)
int padSetActDirect(int port, int slot, char actAlign[6])
int padSetReqState(int port, int slot, int state)
int padPortClose(int port, int slot)
int padGetState(int port, int slot)
unsigned char padGetReqState(int port, int slot)
static struct pad_state PadState[2][8]
int padInfoPressMode(int port, int slot)
int padSetMainMode(int port, int slot, int mode, int lock)
int padEnterPressMode(int port, int slot)
int padGetSlotMax(int port)
int padSetActAlign(int port, int slot, const char actAlign[6])