Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gc/ogc/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#define USB_FAILED 1

#define USB_CLASS_HID 0x03
#define USB_SUBCLASS_NONE 0x00
#define USB_SUBCLASS_BOOT 0x01
#define USB_PROTOCOL_NONE 0x00
#define USB_PROTOCOL_KEYBOARD 0x01
#define USB_PROTOCOL_MOUSE 0x02

Expand Down Expand Up @@ -66,6 +68,7 @@
#define USB_DT_ENDPOINT_SIZE 7
#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
#define USB_DT_HID_SIZE 9
#define USB_DT_MINREPORT_SIZE 8
#define USB_DT_HUB_NONVAR_SIZE 7

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

s32 USB_GetGenericDescriptor(s32 fd,u8 type,u8 index,u8 interface,void *data,u32 size);
s32 USB_GetHIDDescriptor(s32 fd,u8 interface,usb_hiddesc *uhd,u32 size);
s32 USB_GetReportDescriptorSize(s32 fd, u8 interface);
s32 USB_GetReportDescriptor(s32 fd, u8 interface, void* data, u16 size);

s32 USB_GetDeviceDescription(s32 fd,usb_devdesc *devdesc);
s32 USB_DeviceRemovalNotifyAsync(s32 fd,usbcallback cb,void *userdata);
Expand Down
35 changes: 35 additions & 0 deletions libogc/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,41 @@ s32 USB_GetHIDDescriptor(s32 fd,u8 interface,usb_hiddesc *uhd,u32 size)
return retval;
}

s32 USB_GetReportDescriptorSize(s32 fd, u8 interface)
{
//Retrieve complete HID descriptor
//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).
//currently we only support 1 thou
usb_hiddesc hiddesc;
s32 retval = USB_GetHIDDescriptor(fd, interface, &hiddesc, USB_DT_HID_SIZE);

if(retval < 0)
return retval;

if(hiddesc.bLength > USB_DT_HID_SIZE)
return -1;

retval = -2;
for(int i = 0; i < hiddesc.bNumDescriptors; i++)
{
if(hiddesc.descr[i].bDescriptorType == USB_DT_REPORT)
{
retval = hiddesc.descr[i].wDescriptorLength;
break;
}
}

return retval;
}

s32 USB_GetReportDescriptor(s32 fd, u8 interface, void* data, u16 size)
{
if (data == NULL || size < USB_DT_MINREPORT_SIZE)
return IPC_EINVAL;

return USB_GetGenericDescriptor(fd, USB_DT_REPORT, 0, interface, data, size);
}

void USB_FreeDescriptors(usb_devdesc *udd)
{
int iConf, iInterface;
Expand Down