Skip to content

usb_hid.set_interface_name - #8989

Merged
dhalbert merged 3 commits into
adafruit:mainfrom
MariuszCwikla:hid_interface_name
Mar 3, 2024
Merged

dhalbert merged 3 commits into
adafruit:mainfrom
MariuszCwikla:hid_interface_name

Conversation

@MariuszCwikla

@MariuszCwikla MariuszCwikla commented Feb 28, 2024 •

Copy link
Copy Markdown

By default on Windows HID device is seen as CircuitPython HID, see also #5445

This PR adds new method usb_hid.set_interface_name that provides means to change the name of USB HID interface.

Example:

usb_hid.set_interface_name("My HID device")
$ sudo lsusb -vd 239A:80F4 | grep iInterface
      iInterface              4 CircuitPython CDC control
      iInterface              5 CircuitPython CDC data
      iInterface              6 CircuitPython Mass Storage
      iInterface              7 My HID device
      iInterface              9 CircuitPython Audio
      iInterface              8 CircuitPython MIDI

On Windows the device is now seen as:

circuitpython-hid

I have tested it with Raspberry Pico.

@MariuszCwikla MariuszCwikla mentioned this pull request Feb 28, 2024

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! It's been asked for several times.

I've added some comments, especially about storage management.

Comment thread shared-bindings/usb_hid/__init__.c Outdated
Comment thread shared-module/usb_hid/Device.c Outdated
Comment thread shared-module/usb_hid/Device.h Outdated
@dhalbert

Copy link
Copy Markdown
Collaborator

Note the pre-commit failure. If you install pre-commit locally, it will catch these before you commit: https://learn.adafruit.com/building-circuitpython/build-circuitpython#install-pre-commit-3096511

@MariuszCwikla

Copy link
Copy Markdown
Author

Hi @dhalbert,
thank you for your comments.
I just pushed requested changes.

@dhalbert dhalbert linked an issue Mar 3, 2024 that may be closed by this pull request

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! It's been requested a number of times.

Tested on Trinket M0

@vospascal

Copy link
Copy Markdown

this wouldnt allow to have multiple deviced having different names right ?
from my understanding thats where the VID (vendor )and PID (product) parts come in
if i would like 4 devices with different names i would need 4 unique PID's

@vospascal

Copy link
Copy Markdown

image
still under same vid/pid so its for all the devices then

@vospascal

vospascal commented Jun 15, 2024 •

Copy link
Copy Markdown

@MariuszCwikla you think we could do something with the pid and vid some how to make devices unique for local machine
cause now just as well edit the regex right? same result since its cached by windows

@vospascal

Copy link
Copy Markdown

@dhalbert

dhalbert commented Jun 15, 2024 •

Copy link
Copy Markdown
Collaborator

No, there is only one VID/PID, becuase there is only one (composite) device presented.

@vospascal

vospascal commented Jun 15, 2024 •

Copy link
Copy Markdown

No, there is only one VID/PID, becuase there is only one (composite) device presented.

i found it in mpconfigboard.mk of my board thank you
does mean i need to build circuitpython

@dhalbert

Copy link
Copy Markdown
Collaborator

@vospascal

Copy link
Copy Markdown

thanks a lot Dan i was already almost done making custom builds in github ci..
how can i not have seen that ...

my solution

from hid_gamepad.simple.boot import gamepad_descriptor
import usb_hid
import supervisor

# Define custom VID, PID, product name, and manufacturer
CUSTOM_VID = 0xDDFD  # Non-registered VID
CUSTOM_PID = 0x5050  # Non-registered PID
PRODUCT_NAME = "SUNSHINE"
MANUFACTURER_NAME = "Good mood"

# Set USB identification
supervisor.set_usb_identification(vid=CUSTOM_VID, pid=CUSTOM_PID, manufacturer=MANUFACTURER_NAME, product=PRODUCT_NAME)


# Enable HID devices including the custom gamepad descriptor
usb_hid.enable(
    (usb_hid.Device.KEYBOARD,
     usb_hid.Device.MOUSE,
     usb_hid.Device.CONSUMER_CONTROL,
     gamepad_descriptor)
)

# Set interface name for the gamepad
usb_hid.set_interface_name("Good mood")

# Only use the gamepad
usb_hid.enable((gamepad_descriptor,))

this solved it for me now i got unique pid and vid and name in my regex editor

@MariuszCwikla

Copy link
Copy Markdown
Author

Yes, you should assign your VID/PID like in above example.
Windows caches name of VID/PID in the registry, so you might not see the change unless you clean registry or assign your own VID/PID. See also #9130 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rename HID device

3 participants