Reverted GX FIFO breakage.
[libogc.git] / gc / ogc / usb.h
blob75278e14876d28991c3a4517a1df7526888d9d6f
1 #ifndef __USB_H__
2 #define __USB_H__
4 #if defined(HW_RVL)
6 #include <gcutil.h>
7 #include <gctypes.h>
9 #define USB_MAXPATH IPC_MAXPATH_LEN
11 #define USB_OK 0
12 #define USB_FAILED 1
14 /* Descriptor types */
15 #define USB_DT_DEVICE 0x01
16 #define USB_DT_CONFIG 0x02
17 #define USB_DT_STRING 0x03
18 #define USB_DT_INTERFACE 0x04
19 #define USB_DT_ENDPOINT 0x05
20 #define USB_DT_HID 0x21
21 #define USB_DT_REPORT 0x22
23 /* Standard requests */
24 #define USB_REQ_GETSTATUS 0x00
25 #define USB_REQ_CLEARFEATURE 0x01
26 #define USB_REQ_SETFEATURE 0x03
27 #define USB_REQ_SETADDRESS 0x05
28 #define USB_REQ_GETDESCRIPTOR 0x06
29 #define USB_REQ_SETDESCRIPTOR 0x07
30 #define USB_REQ_GETCONFIG 0x08
31 #define USB_REQ_SETCONFIG 0x09
32 #define USB_REQ_GETINTERFACE 0x0a
33 #define USB_REQ_SETINTERFACE 0x0b
34 #define USB_REQ_SYNCFRAME 0x0c
36 /* Descriptor sizes per descriptor type */
37 #define USB_DT_DEVICE_SIZE 18
38 #define USB_DT_CONFIG_SIZE 9
39 #define USB_DT_INTERFACE_SIZE 9
40 #define USB_DT_ENDPOINT_SIZE 7
41 #define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
42 #define USB_DT_HID_SIZE 9
43 #define USB_DT_HUB_NONVAR_SIZE 7
45 /* control message request type bitmask */
46 #define USB_CTRLTYPE_DIR_HOST2DEVICE (0<<7)
47 #define USB_CTRLTYPE_DIR_DEVICE2HOST (1<<7)
48 #define USB_CTRLTYPE_TYPE_STANDARD (0<<5)
49 #define USB_CTRLTYPE_TYPE_CLASS (1<<5)
50 #define USB_CTRLTYPE_TYPE_VENDOR (2<<5)
51 #define USB_CTRLTYPE_TYPE_RESERVED (3<<5)
52 #define USB_CTRLTYPE_REC_DEVICE 0
53 #define USB_CTRLTYPE_REC_INTERFACE 1
54 #define USB_CTRLTYPE_REC_ENDPOINT 2
55 #define USB_CTRLTYPE_REC_OTHER 3
57 #define USB_FEATURE_ENDPOINT_HALT 0
59 #define USB_ENPOINT_INTERRUPT 0x03
60 #define USB_ENDPOINT_IN 0x80
61 #define USB_ENDPOINT_OUT 0x00
64 #ifdef __cplusplus
65 extern "C" {
66 #endif /* __cplusplus */
68 typedef struct _usbendpointdesc
70 u8 bLength;
71 u8 bDescriptorType;
72 u8 bEndpointAddress;
73 u8 bmAttributes;
74 u16 wMaxPacketSize;
75 u8 bInterval;
76 } ATTRIBUTE_PACKED usb_endpointdesc;
78 typedef struct _usbinterfacedesc
80 u8 bLength;
81 u8 bDescriptorType;
82 u8 bInterfaceNumber;
83 u8 bAlternateSetting;
84 u8 bNumEndpoints;
85 u8 bInterfaceClass;
86 u8 bInterfaceSubClass;
87 u8 bInterfaceProtocol;
88 u8 iInterface;
89 u8 *extra;
90 u8 extra_size;
91 struct _usbendpointdesc *endpoints;
92 } ATTRIBUTE_PACKED usb_interfacedesc;
94 typedef struct _usbconfdesc
96 u8 bLength;
97 u8 bDescriptorType;
98 u16 wTotalLength;
99 u8 bNumInterfaces;
100 u8 bConfigurationValue;
101 u8 iConfiguration;
102 u8 bmAttributes;
103 u8 bMaxPower;
104 struct _usbinterfacedesc *interfaces;
105 } ATTRIBUTE_PACKED usb_configurationdesc;
107 typedef struct _usbdevdesc
109 u8 bLength;
110 u8 bDescriptorType;
111 u16 bcdUSB;
112 u8 bDeviceClass;
113 u8 bDeviceSubClass;
114 u8 bDeviceProtocol;
115 u8 bMaxPacketSize0;
116 u16 idVendor;
117 u16 idProduct;
118 u16 bcdDevice;
119 u8 iManufacturer;
120 u8 iProduct;
121 u8 iSerialNumber;
122 u8 bNumConfigurations;
123 struct _usbconfdesc *configurations;
124 } ATTRIBUTE_PACKED usb_devdesc;
126 typedef struct _usbhiddesc
128 u8 bLength;
129 u8 bDescriptorType;
130 u16 bcdHID;
131 u8 bCountryCode;
132 u8 bNumDescriptors;
133 struct {
134 u8 bDescriptorType;
135 u16 wDescriptorLength;
136 } descrs[1];
137 } ATTRIBUTE_PACKED usb_hiddesc;
139 typedef s32 (*usbcallback)(s32 result,void *usrdata);
141 s32 USB_Initialize();
142 s32 USB_Deinitialize();
144 s32 USB_OpenDevice(const char *device,u16 vid,u16 pid,s32 *fd);
145 s32 USB_CloseDevice(s32 *fd);
146 s32 USB_CloseDeviceAsync(s32 *fd,usbcallback cb,void *usrdata);
148 s32 USB_GetDescriptors(s32 fd, usb_devdesc *udd);
149 void USB_FreeDescriptors(usb_devdesc *udd);
151 s32 USB_GetHIDDescriptor(s32 fd, usb_hiddesc *uhd);
153 s32 USB_GetDeviceDescription(s32 fd,usb_devdesc *devdesc);
154 s32 USB_DeviceRemovalNotifyAsync(s32 fd,usbcallback cb,void *userdata);
156 void USB_SuspendDevice(s32 fd);
157 void USB_ResumeDevice(s32 fd);
159 s32 USB_ReadIntrMsg(s32 fd,u8 bEndpoint,u16 wLength,void *rpData);
160 s32 USB_ReadIntrMsgAsync(s32 fd,u8 bEndpoint,u16 wLength,void *rpData,usbcallback cb,void *usrdata);
162 s32 USB_ReadBlkMsg(s32 fd,u8 bEndpoint,u16 wLength,void *rpData);
163 s32 USB_ReadBlkMsgAsync(s32 fd,u8 bEndpoint,u16 wLength,void *rpData,usbcallback cb,void *usrdata);
165 s32 USB_ReadCtrlMsg(s32 fd,u8 bmRequestType,u8 bmRequest,u16 wValue,u16 wIndex,u16 wLength,void *rpData);
166 s32 USB_ReadCtrlMsgAsync(s32 fd,u8 bmRequestType,u8 bmRequest,u16 wValue,u16 wIndex,u16 wLength,void *rpData,usbcallback cb,void *usrdata);
168 s32 USB_WriteIntrMsg(s32 fd,u8 bEndpoint,u16 wLength,void *rpData);
169 s32 USB_WriteIntrMsgAsync(s32 fd,u8 bEndpoint,u16 wLength,void *rpData,usbcallback cb,void *usrdata);
171 s32 USB_WriteBlkMsg(s32 fd,u8 bEndpoint,u16 wLength,void *rpData);
172 s32 USB_WriteBlkMsgAsync(s32 fd,u8 bEndpoint,u16 wLength,void *rpData,usbcallback cb,void *usrdata);
174 s32 USB_WriteCtrlMsg(s32 fd,u8 bmRequestType,u8 bmRequest,u16 wValue,u16 wIndex,u16 wLength,void *rpData);
175 s32 USB_WriteCtrlMsgAsync(s32 fd,u8 bmRequestType,u8 bmRequest,u16 wValue,u16 wIndex,u16 wLength,void *rpData,usbcallback cb,void *usrdata);
177 s32 USB_GetConfiguration(s32 fd, u8 *configuration);
178 s32 USB_SetConfiguration(s32 fd, u8 configuration);
179 s32 USB_SetAlternativeInterface(s32 fd, u8 interface, u8 alternateSetting);
180 s32 USB_ClearHalt(s32 fd, u8 endpointAddress);
181 s32 USB_GetDeviceList(const char *devpath,void *descr_buffer,u8 num_descr,u8 b0,u8 *cnt_descr);
183 #ifdef __cplusplus
185 #endif /* __cplusplus */
187 #endif /* defined(HW_RVL) */
189 #endif