PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
freepad.h
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#ifndef __FREEPAD_H__
13#define __FREEPAD_H__
14
15#include "irx.h"
16#include "types.h"
17
18#define MODNAME "freepad"
19#define M_PRINTF(format, args...) printf(MODNAME ": " format, ## args)
20#define M_KPRINTF(format, args...) Kprintf(MODNAME ": " format, ## args)
21
22#ifdef DEBUG
23#define D_PRINTF(format, args...) printf(MODNAME ": " format, ## args)
24#else
25#define D_PRINTF(a...) (void)0
26#endif
27
28#define PADMAN_THPRI_LO 46
29#define PADMAN_THPRI_HI 20
30
31#define SB_STAT *((volatile unsigned int*)0xBD000040)
32
33/*
34 * Pad states
35 */
36#define PAD_STATE_DISCONN 0x00
37#define PAD_STATE_FINDPAD 0x01
38#define PAD_STATE_FINDCTP1 0x02
39#define PAD_STATE_EXECCMD 0x05
40#define PAD_STATE_STABLE 0x06
41#define PAD_STATE_ERROR 0x07
42
43/*
44 * Pad request states
45 */
46#define PAD_RSTAT_COMPLETE 0x00
47#define PAD_RSTAT_FAILED 0x01
48#define PAD_RSTAT_BUSY 0x02
49
50/*
51 * Connected pad type
52 */
53#define PAD_TYPE_NEJICON 0x2
54#define PAD_TYPE_KONAMIGUN 0x3
55#define PAD_TYPE_DIGITAL 0x4
56#define PAD_TYPE_ANALOG 0x5
57#define PAD_TYPE_NAMCOGUN 0x6
58#define PAD_TYPE_DUALSHOCK 0x7
59
60#define PAD_MODEL_DUALSHOCK 0x1
61#define PAD_MODEL_DUALSHOCK2 0x3
62
63#define MODE_CONFIG_NO_PAD 0x0
64#define MODE_CONFIG_QUERY_PAD 0x1
65#define MODE_CONFIG_READY 0x2
66
67// PAD Tasks
68#define TASK_NONE 0
69#define TASK_UPDATE_PAD 1
70#define TASK_QUERY_PAD 2
71#define TASK_PORT_CLOSE 3
72#define TASK_SET_MAIN_MODE 4
73#define TASK_SET_ACT_ALIGN 5
74#define TASK_SET_BUTTON_INFO 6
75#define TASK_SET_VREF_PARAM 7
76
77// Main event flags
78#define EF_UPDATE_PAD 0x0001
79#define EF_QUERY_PAD 0x0002
80
81#define EF_SET_MAIN_MODE 0x0008
82#define EF_SET_ACT_ALIGN 0x0010
83#define EF_SET_SET_BUTTON_INFO 0x0020
84#define EF_SET_VREF_PARAM 0x0040
85#define EF_PAD_TRANSFER_START 0x0080
86#define EF_PAD_TRANSFER_DONE 0x0100
87#define EF_TASK_DONE 0x0200
88#define EF_PORT_CLOSE 0x0400
89#define EF_EXIT_THREAD 0x1000
90
91// Vblank event flags
92#define EF_VB_TRANSFER 0x0001
93#define EF_VB_TRANSFER_DONE 0x0004
94#define EF_VB_WAIT_THREAD_EXIT 0x0008
95
96// Global Types
97typedef struct
98{
99 int padEnd;
100 int eventflag;
101 int init;
102 int stopTransfer;
103 int tid_1;
104 int tid_2;
106
107typedef struct
108{
109 u8 data[32];
110 u32 actDirData[2];
111 u32 actAlignData[2];
112 u32 actData[4];
113 u32 combData[4];
114 u32 modeTable[2];
115 u32 frame;
116 u32 findPadRetries;
117 u32 length;
118 u8 modeConfig;
119 u8 modeCurId;
120 u8 model;
121 u8 buttonDataReady;
122 u8 nrOfModes;
123 u8 modeCurOffs;
124 u8 nrOfActuators;
125 u8 numActComb;
126 u8 val_c6;
127 u8 mode;
128 u8 lock;
129 u8 actDirSize;
130 u8 state;
131 u8 reqState;
132 u8 currentTask;
133 u8 runTask;
134 u8 stat70bit;
135 u8 padding[11];
137
138typedef struct
139{
140 u32 frame;
141 u8 state;
142 u8 reqState;
143 u8 ok;
144 u8 unkn7;
145 u8 data[32];
146 u32 length;
147 u8 request;
149 u8 CTP;
154 u8 errorCount;
155 u8 unk49[15];
157
158typedef struct
159{
160 ee_paddata_t ee_pdata __attribute__((aligned(4)));
161 ee_old_paddata_t ee_old_pdata __attribute__((aligned(4)));
162 u8 modeConfig;
163 u8 modeCurId;
164 u8 model;
165 u8 numModes;
166 u8 modeCurOffs;
167 u8 numActuators;
168 u8 numActComb;
169 u8 disconnected;
170 union {
171 u8 data[4][4];
172 u32 data32[4];
173 } actData;
174 union {
175 u8 data[4][4];
176 u32 data32[4];
177 } combData;
178 union {
179 u16 data[4];
180 u32 data32[2];
181 } modeTable;
182 u8 buttonInfo[4];
183 u8 buttonMask[4];
184 u8 modeParam[12];
185 u16 val_c4; // unused
186 u16 val_c6;
187 u8 inbuffer[32];
188 u8 outbuffer[32];
189 u8 buttonStatus[32];
190 u32 buttonDataReady;
191 u8 mode;
192 u8 lock;
193 union {
194 u8 data[8];
195 u32 data32[8 / sizeof(u32)];
196 } ee_actDirectData;
197 s16 ee_actDirectSize;
198 union {
199 u8 data[8];
200 u32 data32[8 / sizeof(u32)];
201 } ee_actAlignData;
202 u16 state;
203 u16 reqState;
204 u32 frame;
205 u32 padarea_ee_addr;
206 u32 findPadRetries;
207 s32 updatepadTid;
208 s32 querypadTid;
209 s32 unused158; // probably unused thread id
210 s32 setmainmodeTid;
211 s32 setactalignTid;
212 s32 setbuttoninfoTid;
213 s32 setvrefparamTid;
214 int eventflag;
215 u16 port;
216 u16 slot;
217 u32 currentTask;
218 u32 runTask;
219 u32 taskTid;
220 u32 stat70bit;
221 u32 val_184; // Set, but unused
222} padState_t;
223
224// Internal functions
225void WaitClearEvent(int eventflag, u32 bits, int mode, u32 *resbits_out);
226int VblankStart(void *arg);
227int VblankEnd(void *arg);
228
229// Exported/RPC functions
230s32 padInit(void * ee_addr);
231s32 padEnd(void);
232s32 padPortClose(s32 port, s32 slot, s32 wait);
233s32 padPortOpen(s32 port, s32 slot, s32 pad_area_ee_addr, u32 *buf);
234u32 padSetMainMode(u32 port, u32 slot, u32 mode, u32 lock);
235u32 padSetActDirect(u32 port, u32 slot, u8 *actData);
236u32 padSetActAlign(u32 port, u32 slot, const u8 *actData);
237u32 padGetButtonMask(u32 port, u32 slot);
238u32 padSetButtonInfo(u32 port, u32 slot, u32 info);
239u32 padSetVrefParam(u32 port, u32 slot, const u8 *vparam);
240s32 padInfoAct(u32 port, u32 slot, s32 act, u32 val);
241s32 padInfoComb(u32 port, u32 slot, s32 listno, u32 offs);
242s32 padInfoMode(u32 port, u32 slot, s32 term, u32 offs);
243u32 padGetPortMax(void);
244u32 padGetSlotMax(u32 port);
245u32 padGetModVersion(void);
246
247#endif
u32 padGetModVersion(void)
Definition libpad.c:575
s32 padEnd(void)
Definition libpad.c:374
u32 padGetPortMax(void)
Definition libpad.c:550
int padPortOpen(int port, int slot, void *padArea)
Definition libpad.c:394
int padSetActAlign(int port, int slot, const char act_align[6])
Definition libpad.c:779
int padInfoMode(int port, int slot, int infoMode, int index)
Definition libpad.c:590
int padSetActDirect(int port, int slot, char act_align[6])
Definition libpad.c:802
int padInit(int mode)
Definition libpad.c:297
int padPortClose(int port, int slot)
Definition libpad.c:451
unsigned char padInfoAct(int port, int slot, int word, int byte)
Definition libpad.c:740
int padSetMainMode(int port, int slot, int mode, int lock)
Definition libpad.c:658
int padGetSlotMax(int port)
Definition libpad.c:562