adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
MIT License
3.95k stars 1.16k forks source link

How to set USB HID name to a composite HID device #9319

Open aroidzap opened 3 weeks ago

aroidzap commented 3 weeks ago

CircuitPython version

Adafruit CircuitPython 9.0.5 on 2024-05-22; Waveshare RP2040-Zero with rp2040

Code/REPL

gamepad_a = usb_hid.Device(
    report_descriptor=GAMEPAD_REPORT_DESCRIPTOR_A,
    usage_page=0x01,           # Generic Desktop Control
    usage=0x05,                # Gamepad
    report_ids=(4,),           # Descriptor uses report ID 4.
    # in_report_lengths=(6,),    # This gamepad sends 6 bytes in its report.
    in_report_lengths=(3,),    # This gamepad sends 6 bytes in its report.
    out_report_lengths=(0,),   # It does not receive any reports.
)
gamepad_b = usb_hid.Device(
    report_descriptor=GAMEPAD_REPORT_DESCRIPTOR_B,
    usage_page=0x01,           # Generic Desktop Control
    usage=0x05,                # Gamepad
    report_ids=(5,),           # Descriptor uses report ID 5.
    # in_report_lengths=(6,),    # This gamepad sends 6 bytes in its report.
    in_report_lengths=(3,),    # This gamepad sends 6 bytes in its report.
    out_report_lengths=(0,),   # It does not receive any reports.
)

usb_hid.set_interface_name("Joystick")
usb_hid.enable((
    # usb_hid.Device.KEYBOARD,
    # usb_hid.Device.MOUSE,
    # usb_hid.Device.CONSUMER_CONTROL,
    gamepad_a,
    gamepad_b,
))

# usb_hid.set_interface_name("Joystick 1")
# usb_hid.enable((gamepad_a,))
# usb_hid.set_interface_name("Joystick 2")
# usb_hid.enable((gamepad_b,))

Behavior

I'm trying to set a name for each USB HID composite device, but I'm not sure how or if it is even supported. Also when only trying to set name for USB HID composite device as whole, I'm getting USB HID name RP2040-Zero instead (in Windows Game Controllers settings). I also tried to remove registry keys as described in https://github.com/adafruit/circuitpython/issues/9130.

Description

No response

Additional information

No response

todbot commented 3 weeks ago

I believe that in order to do this, you would need to create multiple UBS HID interfaces, as the interface name is part of the USB Config Descriptor, and not part of the HID Descriptor. I think you could do this in C with TinyUSB as a composite device, but CircuitPython creates only one HID interface that all HID devices go into (keyboard, mouse, any custom ones you create like gamepads, etc)