PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
usbd.h
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16#ifndef __USBD_H__
17#define __USBD_H__
18
19#include <types.h>
20#include <irx.h>
21
22typedef struct
23{
24 u8 requesttype;
25 u8 request;
26 u16 value;
27 u16 index;
28 u16 length;
30
31typedef void (*sceUsbdDoneCallback)(int result, int count, void *arg);
32
33typedef struct
34{
35 u8 bLength;
36 u8 bDescriptorType;
37 u8 bNbrPorts;
38 u8 wHubCharacteristicsLb;
39 u8 wHubCharacteristicsHb;
40 u8 bPwrOn2PwrGood;
41 u8 bHubContrCurrent;
42 u8 deviceRemovable[32]; // arbitrary number, depends on number of ports
44
45
47typedef struct _UsbDriver
48{
49 struct _UsbDriver *next, *prev;
51 char *name;
52 int (*probe)(int devID);
53 int (*connect)(int devID);
54 int (*disconnect)(int devID);
55 u32 reserved1;
56 u32 reserved2;
57 u32 reserved3;
58 u32 reserved4;
59 u32 reserved5;
60 void *gp;
62
63typedef struct
64{
65 u8 bLength;
66 u8 bDescriptorType;
67 u16 bcdUSB;
68 u8 bDeviceClass;
69 u8 bDeviceSubClass;
70 u8 bDeviceProtocol;
71 u8 bMaxPacketSize0;
72 u16 idVendor;
73 u16 idProduct;
74 u16 bcdDevice;
75 u8 iManufacturer;
76 u8 iProduct;
77 u8 iSerialNumber;
78 u8 bNumConfigurations;
80
81typedef struct
82{
83 u8 bLength;
84 u8 bDescriptorType;
85 // u8 wTotalLengthLb;
86 // u8 wTotalLengthHb;
87 u16 wTotalLength; // apparently we can expect this to be aligned, for some reason
88 u8 bNumInterfaces;
89 u8 bConfigurationValue;
90 u8 iConfiguration;
91 u8 bmAttributes;
92 u8 maxPower;
94
95typedef struct
96{
97 u8 bLength;
98 u8 bDescriptorType;
99 u8 bInterfaceNumber;
100 u8 bAlternateSetting;
101 u8 bNumEndpoints;
102 u8 bInterfaceClass;
103 u8 bInterfaceSubClass;
104 u8 bInterfaceProtocol;
105 u8 iInterface;
107
108typedef struct
109{
110 u8 bLength;
111 u8 bDescritorLength;
112 u8 bEndpointAddress;
113 u8 bmAttributes;
114 u8 wMaxPacketSizeLB;
115 u8 wMaxPacketSizeHB;
116 u8 bInterval;
118
119typedef struct
120{
121 u8 bLength;
122 u8 bDescriptorType;
123 u16 wData[1];
125
127{
128 u8 bDescriptorType;
129 u8 wDescriptorLengthLb;
130 u8 wDescriptorLengthHb;
132
133typedef struct _usbHidDescriptor
134{
135 u8 bLength;
136 u8 bDescriptorType;
137 u16 bcdHID;
138 u8 bCountryCode;
139 u8 bNumDescriptors;
140 UsbHidDescriptorItem items[];
142
143typedef struct
144{
145 u16 bLength : 11;
146 u16 reserved : 1;
147 u16 PSW : 4;
149
150#define USB_MAX_ISOCH_PACKETS 8
151
152typedef struct
153{
154 void *bBufStart;
155 u32 bRelStartFrame;
156 u32 bNumPackets;
157 sceUsbdIsochronousPswLen Packets[USB_MAX_ISOCH_PACKETS];
159
160typedef void (*sceUsbdMultiIsochronousDoneCallback)(int result, sceUsbdMultiIsochronousRequest *req, void *arg);
161
162/*
163 * Device and/or Interface Class codes
164 */
165#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
166#define USB_CLASS_AUDIO 1
167#define USB_CLASS_COMM 2
168#define USB_CLASS_HID 3
169#define USB_CLASS_PHYSICAL 5
170#define USB_CLASS_PRINTER 7
171#define USB_CLASS_MASS_STORAGE 8
172#define USB_CLASS_HUB 9
173#define USB_CLASS_DATA 10
174#define USB_CLASS_APP_SPEC 0xfe
175#define USB_CLASS_VENDOR_SPEC 0xff
176
177/*
178 * USB types
179 */
180#define USB_TYPE_STANDARD (0x00 << 5)
181#define USB_TYPE_CLASS (0x01 << 5)
182#define USB_TYPE_VENDOR (0x02 << 5)
183#define USB_TYPE_RESERVED (0x03 << 5)
184
185/*
186 * USB recipients
187 */
188#define USB_RECIP_DEVICE 0x00
189#define USB_RECIP_INTERFACE 0x01
190#define USB_RECIP_ENDPOINT 0x02
191#define USB_RECIP_OTHER 0x03
192
193#define USB_ENDPOINT_XFER_CONTROL 0
194#define USB_ENDPOINT_XFER_ISOC 1
195#define USB_ENDPOINT_XFER_BULK 2
196#define USB_ENDPOINT_XFER_INT 3
197#define USB_ENDPOINT_XFERTYPE_MASK 3
198
199#define USB_REQ_GET_REPORT 0x01
200#define USB_REQ_GET_IDLE 0x02
201#define USB_REQ_GET_PROTOCOL 0x03
202#define USB_REQ_SET_REPORT 0x09
203#define USB_REQ_SET_IDLE 0x0A
204#define USB_REQ_SET_PROTOCOL 0x0B
205
206/*
207 * USB directions
208 */
209#define USB_DIR_OUT 0
210#define USB_DIR_IN 0x80
211#define USB_ENDPOINT_DIR_MASK 0x80
212
213#define USB_DT_DEVICE 1
214#define USB_DT_CONFIG 2
215#define USB_DT_STRING 3
216#define USB_DT_INTERFACE 4
217#define USB_DT_ENDPOINT 5
218#define USB_DT_HUB 0x29
219
220#define USB_CLASS_HUB 9
221
222#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE)
223#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER)
224
225#define USB_REQ_GET_STATUS 0x00
226#define USB_REQ_CLEAR_FEATURE 0x01
227#define USB_REQ_SET_FEATURE 0x03
228#define USB_REQ_SET_ADDRESS 0x05
229#define USB_REQ_GET_DESCRIPTOR 0x06
230#define USB_REQ_SET_DESCRIPTOR 0x07
231#define USB_REQ_GET_CONFIGURATION 0x08
232#define USB_REQ_SET_CONFIGURATION 0x09
233#define USB_REQ_GET_INTERFACE 0x0A
234#define USB_REQ_SET_INTERFACE 0x0B
235#define USB_REQ_SYNCH_FRAME 0x0C
236
238#define USB_RC_OK 0x000
240#define USB_RC_CRC 0x001
242#define USB_RC_BITSTUFF 0x002
244#define USB_RC_TOGGLE 0x003
246#define USB_RC_STALL 0x004
248#define USB_RC_NORESPONSE 0x005
250#define USB_RC_BADPID 0x006
252#define USB_RC_WRONGPID 0x007
254#define USB_RC_DATAOVER 0x008
256#define USB_RC_DATAUNDER 0x009
258#define USB_RC_BUFFOVER 0x00C
260#define USB_RC_BUFFUNDER 0x00D
262#define USB_RC_NOTACCESSED 0x00E
264#define USB_RC_NOTACCESSED2 0x00F
265
267#define USB_RC_BADDEV 0x101
269#define USB_RC_BADPIPE 0x102
271#define USB_RC_BADLENGTH 0x103
273#define USB_RC_BADDRIVER 0x104
275#define USB_RC_BADCONTEXT 0x105
276#define USB_RC_BADALIGN 0x106
277#define USB_RC_BADHUBDEPTH 0x107
278
280#define USB_RC_ED 0x111
282#define USB_RC_IOREQ 0x112
284#define USB_RC_BADOPTION 0x113
285
287#define USB_RC_BUSY 0x121
289#define USB_RC_ABORTED 0x122
290
292#define USB_RC_NOSUPPORT 0x131
294#define USB_RC_UNKNOWN 0x132
295
296int sceUsbdRegisterLdd(sceUsbdLddOps *driver);
297int sceUsbdUnregisterLdd(sceUsbdLddOps *driver);
298void *sceUsbdScanStaticDescriptor(int devId, void *data, u8 type);
299int sceUsbdGetDeviceLocation(int devId, u8 *path);
300int sceUsbdSetPrivateData(int devId, void *data);
301void *sceUsbdGetPrivateData(int devId);
302int sceUsbdOpenPipe(int devId, UsbEndpointDescriptor *desc);
303int sceUsbdOpenPipeAligned(int devId, UsbEndpointDescriptor *desc);
304int sceUsbdClosePipe(int id);
305int sceUsbdTransferPipe(int id, void *data, u32 len, void *option, sceUsbdDoneCallback callback, void *cbArg);
306
307int sceUsbdRegisterAutoloader(sceUsbdLddOps *drv); // Arbitrarily named
308int sceUsbdUnregisterAutoloader(void); // Arbitrarily named
309int sceUsbdChangeThreadPriority(int prio1, int prio2);
310
311// These have been added in 1.2 export version
312int sceUsbdGetReportDescriptor(int devId, int cfgNum, int ifNum, void **desc, u32 *len);
313int sceUsbdMultiIsochronousTransfer(int pipeId, sceUsbdMultiIsochronousRequest *request, sceUsbdMultiIsochronousDoneCallback callback, void *cbArg);
314
315// For backwards compatibility:
316#define UsbCallbackProc sceUsbdDoneCallback
317#define UsbDriver sceUsbdLddOps
318#define UsbIsochronousPswLen sceUsbdIsochronousPswLen
319#define UsbMultiIsochronousRequest sceUsbdMultiIsochronousRequest
320#define UsbMultiIsochronousDoneCallback sceUsbdMultiIsochronousDoneCallback
321#define UsbRegisterDriver sceUsbdRegisterLdd
322#define UsbUnregisterDriver sceUsbdUnregisterLdd
323#define UsbGetDeviceStaticDescriptor sceUsbdScanStaticDescriptor
324#define UsbGetDeviceLocation sceUsbdGetDeviceLocation
325#define UsbSetDevicePrivateData sceUsbdSetPrivateData
326#define UsbGetDevicePrivateData sceUsbdGetPrivateData
327#define UsbOpenEndpoint sceUsbdOpenPipe
328#define UsbOpenEndpointAligned sceUsbdOpenPipeAligned
329#define UsbCloseEndpoint sceUsbdClosePipe
330#define UsbTransfer sceUsbdTransferPipe
331#define UsbRegisterAutoloader sceUsbdRegisterAutoloader
332#define UsbUnregisterAutoloader sceUsbdUnregisterAutoloader
333#define UsbChangeThreadPriority sceUsbdChangeThreadPriority
334#define UsbGetReportDescriptor sceUsbdGetReportDescriptor
335#define UsbMultiIsochronousTransfer sceUsbdMultiIsochronousTransfer
336
337#define usbd_IMPORTS_start DECLARE_IMPORT_TABLE(usbd, 1, 2)
338#define usbd_IMPORTS_end END_IMPORT_TABLE
339
340#define I_sceUsbdRegisterLdd DECLARE_IMPORT(4, sceUsbdRegisterLdd)
341#define I_sceUsbdUnregisterLdd DECLARE_IMPORT(5, sceUsbdUnregisterLdd)
342#define I_sceUsbdScanStaticDescriptor DECLARE_IMPORT(6, sceUsbdScanStaticDescriptor)
343#define I_sceUsbdSetPrivateData DECLARE_IMPORT(7, sceUsbdSetPrivateData)
344#define I_sceUsbdGetPrivateData DECLARE_IMPORT(8, sceUsbdGetPrivateData)
345#define I_sceUsbdOpenPipe DECLARE_IMPORT(9, sceUsbdOpenPipe)
346#define I_sceUsbdClosePipe DECLARE_IMPORT(10, sceUsbdClosePipe)
347#define I_sceUsbdTransferPipe DECLARE_IMPORT(11, sceUsbdTransferPipe)
348#define I_sceUsbdOpenPipeAligned DECLARE_IMPORT(12, sceUsbdOpenPipeAligned)
349#define I_sceUsbdGetDeviceLocation DECLARE_IMPORT(13, sceUsbdGetDeviceLocation)
350#define I_sceUsbdRegisterAutoloader DECLARE_IMPORT(14, sceUsbRegisterAutoloader)
351#define I_sceUsbdUnregisterAutoloader DECLARE_IMPORT(15, sceUsbUnregisterAutoloader)
352#define I_sceUsbdChangeThreadPriority DECLARE_IMPORT(16, sceUsbdChangeThreadPriority)
353#define I_sceUsbdGetReportDescriptor DECLARE_IMPORT(17, sceUsbdGetReportDescriptor)
354#define I_sceUsbdMultiIsochronousTransfer DECLARE_IMPORT(18, sceUsbdMultiIsochronousTransfer)
355
356// For backwards compatibility:
357#define I_UsbCallbackProc I_sceUsbdDoneCallback
358#define I_UsbDriver I_sceUsbdLddOps
359#define I_UsbIsochronousPswLen I_sceUsbdIsochronousPswLen
360#define I_UsbMultiIsochronousRequest I_sceUsbdMultiIsochronousRequest
361#define I_UsbMultiIsochronousDoneCallback I_sceUsbdMultiIsochronousDoneCallback
362#define I_UsbRegisterDriver I_sceUsbdRegisterLdd
363#define I_UsbUnregisterDriver I_sceUsbdUnregisterLdd
364#define I_UsbGetDeviceStaticDescriptor I_sceUsbdScanStaticDescriptor
365#define I_UsbGetDeviceLocation I_sceUsbdGetDeviceLocation
366#define I_UsbSetDevicePrivateData I_sceUsbdSetPrivateData
367#define I_UsbGetDevicePrivateData I_sceUsbdGetPrivateData
368#define I_UsbOpenEndpoint I_sceUsbdOpenPipe
369#define I_UsbOpenEndpointAligned I_sceUsbdOpenPipeAligned
370#define I_UsbCloseEndpoint I_sceUsbdClosePipe
371#define I_UsbTransfer I_sceUsbdTransferPipe
372#define I_UsbRegisterAutoloader I_sceUsbdRegisterAutoloader
373#define I_UsbUnregisterAutoloader I_sceUsbdUnregisterAutoloader
374#define I_UsbChangeThreadPriority I_sceUsbdChangeThreadPriority
375#define I_UsbGetReportDescriptor I_sceUsbdGetReportDescriptor
376#define I_UsbMultiIsochronousTransfer I_sceUsbdMultiIsochronousTransfer
377
378#endif /* __USBD_H__ */
char * name
Definition usbd.h:51
struct _UsbDriver sceUsbdLddOps
u32 count
start sector of fragmented bd/file