Skip to content

Commit b51c517

Browse files
authored
implement retrieving the USB reportDescriptor & it's size (#95)
1 parent 1f75f7a commit b51c517

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

gc/ogc/usb.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#define USB_FAILED 1
1313

1414
#define USB_CLASS_HID 0x03
15+
#define USB_SUBCLASS_NONE 0x00
1516
#define USB_SUBCLASS_BOOT 0x01
17+
#define USB_PROTOCOL_NONE 0x00
1618
#define USB_PROTOCOL_KEYBOARD 0x01
1719
#define USB_PROTOCOL_MOUSE 0x02
1820

@@ -66,6 +68,7 @@
6668
#define USB_DT_ENDPOINT_SIZE 7
6769
#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
6870
#define USB_DT_HID_SIZE 9
71+
#define USB_DT_MINREPORT_SIZE 8
6972
#define USB_DT_HUB_NONVAR_SIZE 7
7073

7174
/* control message request type bitmask */
@@ -190,6 +193,8 @@ void USB_FreeDescriptors(usb_devdesc *udd);
190193

191194
s32 USB_GetGenericDescriptor(s32 fd,u8 type,u8 index,u8 interface,void *data,u32 size);
192195
s32 USB_GetHIDDescriptor(s32 fd,u8 interface,usb_hiddesc *uhd,u32 size);
196+
s32 USB_GetReportDescriptorSize(s32 fd, u8 interface);
197+
s32 USB_GetReportDescriptor(s32 fd, u8 interface, void* data, u16 size);
193198

194199
s32 USB_GetDeviceDescription(s32 fd,usb_devdesc *devdesc);
195200
s32 USB_DeviceRemovalNotifyAsync(s32 fd,usbcallback cb,void *userdata);

libogc/usb.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,41 @@ s32 USB_GetHIDDescriptor(s32 fd,u8 interface,usb_hiddesc *uhd,u32 size)
10851085
return retval;
10861086
}
10871087

1088+
s32 USB_GetReportDescriptorSize(s32 fd, u8 interface)
1089+
{
1090+
//Retrieve complete HID descriptor
1091+
//in testing it was always 9 bytes, but in the HID specifications it says it can be more (if the device has more than 1 descriptor).
1092+
//currently we only support 1 thou
1093+
usb_hiddesc hiddesc;
1094+
s32 retval = USB_GetHIDDescriptor(fd, interface, &hiddesc, USB_DT_HID_SIZE);
1095+
1096+
if(retval < 0)
1097+
return retval;
1098+
1099+
if(hiddesc.bLength > USB_DT_HID_SIZE)
1100+
return -1;
1101+
1102+
retval = -2;
1103+
for(int i = 0; i < hiddesc.bNumDescriptors; i++)
1104+
{
1105+
if(hiddesc.descr[i].bDescriptorType == USB_DT_REPORT)
1106+
{
1107+
retval = hiddesc.descr[i].wDescriptorLength;
1108+
break;
1109+
}
1110+
}
1111+
1112+
return retval;
1113+
}
1114+
1115+
s32 USB_GetReportDescriptor(s32 fd, u8 interface, void* data, u16 size)
1116+
{
1117+
if (data == NULL || size < USB_DT_MINREPORT_SIZE)
1118+
return IPC_EINVAL;
1119+
1120+
return USB_GetGenericDescriptor(fd, USB_DT_REPORT, 0, interface, data, size);
1121+
}
1122+
10881123
void USB_FreeDescriptors(usb_devdesc *udd)
10891124
{
10901125
int iConf, iInterface;

0 commit comments

Comments
 (0)