libnx icon indicating copy to clipboard operation
libnx copied to clipboard

Emulating HID with usbds

Open yjun123 opened this issue 2 months ago • 2 comments

I want to emulate a HID device using usbds.

The key requirements are:

  • Add the HID descriptor to the configuration descriptor. (Done. ✔)
  • Implement the GetDescriptor request to return the HID report descriptor.
  • Handle SetIdle and other class-specific request.

I’m unable to find how to handle standard control requests(EP0). Could anyone provide guidance or examples on achieving this? Thanks!

yjun123 avatar Nov 08 '25 09:11 yjun123

https://github.com/switchbrew/libnx/blob/master/nx/include/switch/services/usbds.h#L137-L140

yellows8 avatar Nov 08 '25 14:11 yellows8

Thanks, but I still don’t really get how to call the interface. Here’s what I’m thinking:

usbDsInterface_CtrlOutPostBufferAsync ==>
waiterForEvent(interface ->CtrlOutCompletionEvent) ==>
usbDsInterface_GetCtrlOutReportData ==>
usbDsParseReportData 

If I call it this way, can I get the requests during the enumeration process? Then use the CtrlIn API to reply (like Get Descriptor HID Report – I need to reply with the content of the HID Report Descriptor)?

yjun123 avatar Nov 11 '25 14:11 yjun123