From 67ff1c92f0d1d6a93c5f1fdf6d5e07c66d39df0a Mon Sep 17 00:00:00 2001 From: Thea Flowers <me@thea.codes> Date: Tue, 12 Nov 2019 13:29:35 -0800 Subject: [PATCH] Allow boards to change the "CircuitPython" text in their USB interface description. In cases where more than one board is connected to a single computer it can become pretty hard to figure out which board you're actually talking to. For example, if you have several MIDI-compatible boards they all show up as "CircuitPython MIDI". This change allows boards to replace the "CircuitPython" part of their USB descriptors with more specific text, for example, "CircuitPython Feather" or just "Feather". This will let folks more easily tell boards apart. The new option is named `USB_INTERFACE_NAME` and is available in `mkconfigboard.mk`. For example: ``` USB_INTERFACE_NAME = "Feather" ``` --- supervisor/supervisor.mk | 5 +++++ tools/gen_usb_descriptor.py | 28 ++++++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index ad0f716fbf78..b2e4eb1dcf45 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -91,6 +91,10 @@ else CFLAGS += -DUSB_AVAILABLE endif +ifndef USB_INTERFACE_NAME +USB_INTERFACE_NAME = "CircuitPython" +endif + ifndef USB_DEVICES USB_DEVICES = "CDC,MSC,AUDIO,HID" endif @@ -145,6 +149,7 @@ USB_DESCRIPTOR_ARGS = \ --vid $(USB_VID)\ --pid $(USB_PID)\ --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ + --interface_name $(USB_INTERFACE_NAME)\ --devices $(USB_DEVICES)\ --hid_devices $(USB_HID_DEVICES)\ --msc_max_packet_size $(USB_MSC_MAX_PACKET_SIZE)\ diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index 21a480f99ee2..5e25528f90a4 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -8,6 +8,7 @@ from adafruit_usb_descriptor import audio, audio10, cdc, hid, midi, msc, standard, util import hid_report_descriptors +DEFAULT_INTERFACE_NAME = 'CircuitPython' ALL_DEVICES='CDC,MSC,AUDIO,HID' ALL_DEVICES_SET=frozenset(ALL_DEVICES.split(',')) DEFAULT_DEVICES='CDC,MSC,AUDIO,HID' @@ -32,6 +33,9 @@ help='devices to include in descriptor (AUDIO includes MIDI support)') parser.add_argument('--hid_devices', type=lambda l: tuple(l.split(',')), default=DEFAULT_HID_DEVICES, help='HID devices to include in HID report descriptor') +parser.add_argument('--interface_name', type=str, + help='The name/prefix to use in the interface descriptions', + default=DEFAULT_INTERFACE_NAME) parser.add_argument('--msc_max_packet_size', type=int, default=64, help='Max packet size for MSC') parser.add_argument('--no-renumber_endpoints', dest='renumber_endpoints', action='store_false', @@ -151,7 +155,7 @@ def strings_in_order(cls): bInterfaceClass=cdc.CDC_CLASS_COMM, # Communications Device Class bInterfaceSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model bInterfaceProtocol=cdc.CDC_PROTOCOL_NONE, - iInterface=StringIndex.index("CircuitPython CDC control"), + iInterface=StringIndex.index("{} CDC control".format(args.interface_name)), subdescriptors=[ cdc.Header( description="CDC comm", @@ -172,7 +176,7 @@ def strings_in_order(cls): cdc_data_interface = standard.InterfaceDescriptor( description="CDC data", bInterfaceClass=cdc.CDC_CLASS_DATA, - iInterface=StringIndex.index("CircuitPython CDC data"), + iInterface=StringIndex.index("{} CDC data".format(args.interface_name)), subdescriptors=[ standard.EndpointDescriptor( description="CDC data out", @@ -192,7 +196,7 @@ def strings_in_order(cls): bInterfaceClass=msc.MSC_CLASS, bInterfaceSubClass=msc.MSC_SUBCLASS_TRANSPARENT, bInterfaceProtocol=msc.MSC_PROTOCOL_BULK, - iInterface=StringIndex.index("CircuitPython Mass Storage"), + iInterface=StringIndex.index("{} Mass Storage".format(args.interface_name)), subdescriptors=[ standard.EndpointDescriptor( description="MSC in", @@ -256,7 +260,7 @@ def strings_in_order(cls): bInterfaceClass=hid.HID_CLASS, bInterfaceSubClass=hid.HID_SUBCLASS_NOBOOT, bInterfaceProtocol=hid.HID_PROTOCOL_NONE, - iInterface=StringIndex.index("CircuitPython HID"), + iInterface=StringIndex.index("{} HID".format(args.interface_name)), subdescriptors=[ hid.HIDDescriptor( description="HID", @@ -272,9 +276,9 @@ def strings_in_order(cls): # USB OUT -> midi_in_jack_emb -> midi_out_jack_ext -> CircuitPython midi_in_jack_emb = midi.InJackDescriptor( - description="MIDI PC -> CircuitPython", + description="MIDI PC -> {}".format(args.interface_name), bJackType=midi.JACK_TYPE_EMBEDDED, - iJack=StringIndex.index("CircuitPython usb_midi.ports[0]")) + iJack=StringIndex.index("{} usb_midi.ports[0]".format(args.interface_name))) midi_out_jack_ext = midi.OutJackDescriptor( description="MIDI data out to user code.", bJackType=midi.JACK_TYPE_EXTERNAL, @@ -287,10 +291,10 @@ def strings_in_order(cls): bJackType=midi.JACK_TYPE_EXTERNAL, iJack=0) midi_out_jack_emb = midi.OutJackDescriptor( - description="MIDI PC <- CircuitPython", + description="MIDI PC <- {}".format(args.interface_name), bJackType=midi.JACK_TYPE_EMBEDDED, input_pins=[(midi_in_jack_ext, 1)], - iJack=StringIndex.index("CircuitPython usb_midi.ports[1]")) + iJack=StringIndex.index("{} usb_midi.ports[1]".format(args.interface_name))) audio_midi_interface = standard.InterfaceDescriptor( @@ -298,7 +302,7 @@ def strings_in_order(cls): bInterfaceClass=audio.AUDIO_CLASS_DEVICE, bInterfaceSubClass=audio.AUDIO_SUBCLASS_MIDI_STREAMING, bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, - iInterface=StringIndex.index("CircuitPython MIDI"), + iInterface=StringIndex.index("{} MIDI".format(args.interface_name)), subdescriptors=[ midi.Header( jacks_and_elements=[ @@ -309,12 +313,12 @@ def strings_in_order(cls): ], ), standard.EndpointDescriptor( - description="MIDI data out to CircuitPython", + description="MIDI data out to {}".format(args.interface_name), bEndpointAddress=args.midi_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, bmAttributes=standard.EndpointDescriptor.TYPE_BULK), midi.DataEndpointDescriptor(baAssocJack=[midi_in_jack_emb]), standard.EndpointDescriptor( - description="MIDI data in from CircuitPython", + description="MIDI data in from {}".format(args.interface_name), bEndpointAddress=args.midi_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN, bmAttributes=standard.EndpointDescriptor.TYPE_BULK, bInterval = 0x0), @@ -334,7 +338,7 @@ def strings_in_order(cls): bInterfaceClass=audio.AUDIO_CLASS_DEVICE, bInterfaceSubClass=audio.AUDIO_SUBCLASS_CONTROL, bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, - iInterface=StringIndex.index("CircuitPython Audio"), + iInterface=StringIndex.index("{} Audio".format(args.interface_name)), subdescriptors=[ cs_ac_interface, ])