greatscottgadgets / luna

Amaranth HDL framework for monitoring, hacking, and developing USB devices
https://greatscottgadgets.com/cynthion/
BSD 3-Clause "New" or "Revised" License
991 stars 171 forks source link

gateware.usb.request.windows: add MicrosoftOS10RequestHandler #251

Closed mndza closed 6 months ago

mndza commented 6 months ago

This PR adds a request handler for Microsoft OS 1.0 descriptors.

https://github.com/greatscottgadgets/python-usb-protocol/pull/41

Usage for a single interface:

Add OS string descriptor to the DeviceDescriptorCollection. The byte after MSFT100 defines the request value (bMS_VendorCode) for retrieving the OS descriptors:

descriptors.add_descriptor(get_string_descriptor("MSFT100\xee"), index=0xee)

Then add the request handler to the control endpoint:

msft_descriptors = MicrosoftOS10DescriptorCollection()

with msft_descriptors.ExtendedCompatIDDescriptor() as c:
    with c.Function() as f:
        f.bFirstInterfaceNumber = 0
        f.compatibleID          = 'WINUSB'

control_ep.add_request_handler(MicrosoftOS10RequestHandler(msft_descriptors, request_code=0xee))

NOTE: If LUNA complains about non-contiguous descriptors, you can pass avoid_blockram=True to the standard request handler as a temporary fix:

control_ep = usb.add_standard_control_endpoint(descriptors, avoid_blockram=True)