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.
10 # $Id: usbd_macro.h 1600 2009-08-11 02:42:17Z jim $
11 # USB Driver function prototypes and constants.
14 #if !defined(_USBD_MACRO_H)
17 // !!! usbd exports functions pointers !!!
18 extern int (*pUsbRegisterDriver
)(UsbDriver
*driver
); // #4
19 extern void *(*pUsbGetDeviceStaticDescriptor
)(int devId
, void *data
, u8 type
); // #6
20 extern int (*pUsbSetDevicePrivateData
)(int devId
, void *data
); // #7
21 extern int (*pUsbOpenEndpoint
)(int devId
, UsbEndpointDescriptor
*desc
); // #9
22 extern int (*pUsbCloseEndpoint
)(int id
); // #10
23 extern int (*pUsbTransfer
)(int id
, void *data
, u32 len
, void *option
, UsbCallbackProc callback
, void *cbArg
); // #11
24 extern int (*pUsbOpenEndpointAligned
)(int devId
, UsbEndpointDescriptor
*desc
); // #12
26 static int UsbControlTransfer(int epID
, int reqtyp
, int req
, int val
, int index
, int leng
, void *dataptr
, void *doneCB
, void* arg
)
29 UsbDeviceRequest devreq
;
30 devreq
.requesttype
= reqtyp
;
36 return pUsbTransfer(epID
, dataptr
, devreq
.length
, &devreq
, doneCB
, arg
);
42 #define UsbControlTransfer(epID, reqtyp, req, val, index, len, dataptr, doneCB, arg) \
44 UsbDeviceRequest devreq; \
45 devreq.requesttype = (reqtyp); \
46 devreq.request = (req); \
47 devreq.value = (val); \
48 devreq.index = (index); \
49 devreq.length = (len); \
50 UsbTransfer((epID), (dataptr), devreq.length, &devreq, (doneCB), (arg)); \
54 #define UsbIsochronousTransfer(epID, dataptr, len, delta, doneCB, arg) \
55 pUsbTransfer((epID), (dataptr), (len), (void *)(delta), (doneCB), (arg))
57 #define UsbBulkTransfer(epID, dataptr, len, doneCB, arg) \
58 pUsbTransfer((epID), (dataptr), (len), NULL, (doneCB), (arg))
60 #define UsbInterruptTransfer(epID, dataptr, len, doneCB, arg) \
61 pUsbTransfer((epID), (dataptr), (len), NULL, (doneCB), (arg))
63 /* standard control transfers */
65 #define UsbClearDeviceFeature(epID, feature, doneCB, arg) \
66 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_DEVICE, USB_REQ_CLEAR_FEATURE, \
67 (feature), 0, 0, NULL, (doneCB), (arg))
69 #define UsbSetDeviceFeature(epID, feature, doneCB, arg) \
70 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_DEVICE, USB_REQ_SET_FEATURE, \
71 (feature), 0, 0, NULL, (doneCB), (arg))
73 #define UsbGetDeviceConfiguration(epID, dataptr, doneCB, arg) \
74 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_DEVICE, USB_REQ_GET_CONFIGURATION, \
75 0, 0, 1, (dataptr), (doneCB), (arg))
77 #define UsbSetDeviceConfiguration(epID, config, doneCB, arg) \
78 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_DEVICE, USB_REQ_SET_CONFIGURATION, (config), 0, 0, NULL, (doneCB), (arg))
80 #define UsbGetDeviceDescriptor(epID, type, index, language, dataptr, len, doneCB, arg) \
81 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_DEVICE, USB_REQ_GET_DESCRIPTOR, \
82 ((type) << 8) | (index), (language), (len), (dataptr), (doneCB), (arg))
84 #define UsbSetDeviceDescriptor(epID, type, index, language, dataptr, len, doneCB, arg) \
85 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_DEVICE, USB_REQ_SET_DESCRIPTOR, \
86 ((type) << 8) | (index), (language), (len), (dataptr), (doneCB), (arg))
88 #define UsbGetDeviceStatus(epID, dataptr, doneCB, arg) \
89 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_DEVICE, USB_REQ_GET_STATUS, \
90 0, 0, 2, (dataptr), (doneCB), (arg))
92 #define UsbSetDeviceAddress(epID, address, doneCB, arg) \
93 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_DEVICE, USB_REQ_SET_ADDRESS, \
94 (address), 0, 0, NULL, (doneCB), (arg))
96 #define UsbClearInterfaceFeature(epID, feature, interface, doneCB, arg) \
97 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_INTERFACE, USB_REQ_CLEAR_FEATURE, \
98 (feature), (interface), 0, NULL, (doneCB), (arg))
100 #define UsbSetInterfaceFeature(epID, feature, interface, doneCB, arg) \
101 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_INTERFACE, USB_REQ_SET_FEATURE, \
102 (feature), (interface), 0, NULL, (doneCB), (arg))
104 #define UsbGetInterface(epID, interface, dataptr, doneCB, arg) \
105 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_INTERFACE, USB_REQ_GET_INTERFACE, \
106 0, (interface), 1, (dataptr), (doneCB), (arg))
108 #define UsbSetInterface(epID, interface, alt_setting, doneCB, arg) \
109 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_INTERFACE, USB_REQ_SET_INTERFACE, \
110 (alt_setting), (interface), 0, NULL, (doneCB), (arg))
112 #define UsbGetInterfaceDescriptor(epID, type, index, language, dataptr, len, doneCB, arg) \
113 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_INTERFACE, USB_REQ_GET_DESCRIPTOR, \
114 ((type) << 8) | (index), (language), (len), (dataptr), (doneCB), (arg))
116 #define UsbSetInterfaceDescriptor(epID, type, index, language, dataptr, len, doneCB, arg) \
117 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_INTERFACE, USB_REQ_SET_DESCRIPTOR, \
118 ((type) << 8) | (index), (language), (len), (dataptr), (doneCB), (arg))
120 #define UsbGetInterfaceStatus(epID, interface, dataptr, doneCB, arg) \
121 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_INTERFACE, USB_REQ_GET_STATUS, \
122 0, (interface), 2, (dataptr), (doneCB), (arg))
124 #define UsbClearEndpointFeature(epID, feature, endpoint, doneCB, arg) \
125 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_ENDPOINT, USB_REQ_CLEAR_FEATURE, \
126 (feature), (endpoint), 0, NULL, (doneCB), (arg))
128 #define UsbSetEndpointFeature(epID, feature, endpoint, doneCB, arg) \
129 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_ENDPOINT, USB_REQ_SET_FEATURE, \
130 (feature), (endpoint), 0, NULL, (doneCB), (arg))
132 #define UsbGetEndpointStatus(epID, endpoint, dataptr, doneCB, arg) \
133 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_ENDPOINT, USB_REQ_GET_STATUS, \
134 0, (endpoint), 2, (dataptr), (doneCB), (arg))
136 #define UsbGetEndpointDescriptor(epID, type, index, language, dataptr, len, doneCB, arg) \
137 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_ENDPOINT, USB_REQ_GET_DESCRIPTOR, \
138 ((type) << 8) | (index), (language), (len), (dataptr), (doneCB), (arg))
140 #define UsbSetEndpointDescriptor(epID, type, index, language, dataptr, len, doneCB, arg) \
141 UsbControlTransfer((epID), USB_DIR_OUT | USB_RECIP_ENDPOINT, USB_REQ_SET_DESCRIPTOR, \
142 ((type) << 8) | (index), (language), (len), (dataptr), (doneCB), (arg))
144 #define UsbSynchEndpointFrame(epID, endpoint, pfn, doneCB, arg) \
145 UsbControlTransfer((epID), USB_DIR_IN | USB_RECIP_ENDPOINT, USB_REQ_SYNCH_FRAME, \
146 0, (endpoint), 2, (pfn), (doneCB), (arg))