Merge pull request #2189 from kamtom480/circuitpython-number-endpoint

Add an alternative way to number the USB endpoints
This commit is contained in:
Dan Halbert 2019-10-08 08:18:36 -04:00 committed by GitHub
commit cc3e0a0d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 119 additions and 35 deletions

View File

@ -22,7 +22,7 @@ CIRCUITPY_FREQUENCYIO = 0
CIRCUITPY_TOUCHIO_USE_NATIVE = 1
# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic.
USB_MSC_NUM_ENDPOINT_PAIRS = 2
USB_MSC_EP_NUM_OUT = 1
endif
# Put samd51-only choices here.

View File

@ -94,15 +94,71 @@ ifndef USB_HID_DEVICES
USB_HID_DEVICES = "KEYBOARD,MOUSE,CONSUMER,GAMEPAD"
endif
# SAMD21 needs separate endpoint pairs for MSC BULK IN and BULK OUT, otherwise it's erratic.
ifndef USB_MSC_NUM_ENDPOINT_PAIRS
USB_MSC_NUM_ENDPOINT_PAIRS = 1
endif
ifndef USB_MSC_MAX_PACKET_SIZE
USB_MSC_MAX_PACKET_SIZE = 64
endif
ifndef USB_CDC_EP_NUM_NOTIFICATION
USB_CDC_EP_NUM_NOTIFICATION = 0
endif
ifndef USB_CDC_EP_NUM_DATA_OUT
USB_CDC_EP_NUM_DATA_OUT = 0
endif
ifndef USB_CDC_EP_NUM_DATA_IN
USB_CDC_EP_NUM_DATA_IN = 0
endif
ifndef USB_MSC_EP_NUM_OUT
USB_MSC_EP_NUM_OUT = 0
endif
ifndef USB_MSC_EP_NUM_IN
USB_MSC_EP_NUM_IN = 0
endif
ifndef USB_HID_EP_NUM_OUT
USB_HID_EP_NUM_OUT = 0
endif
ifndef USB_HID_EP_NUM_IN
USB_HID_EP_NUM_IN = 0
endif
ifndef USB_MIDI_EP_NUM_OUT
USB_MIDI_EP_NUM_OUT = 0
endif
ifndef USB_MIDI_EP_NUM_IN
USB_MIDI_EP_NUM_IN = 0
endif
USB_DESCRIPTOR_ARGS = \
--manufacturer $(USB_MANUFACTURER)\
--product $(USB_PRODUCT)\
--vid $(USB_VID)\
--pid $(USB_PID)\
--serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\
--devices $(USB_DEVICES)\
--hid_devices $(USB_HID_DEVICES)\
--msc_max_packet_size $(USB_MSC_MAX_PACKET_SIZE)\
--cdc_ep_num_notification $(USB_CDC_EP_NUM_NOTIFICATION)\
--cdc_ep_num_data_out $(USB_CDC_EP_NUM_DATA_OUT)\
--cdc_ep_num_data_in $(USB_CDC_EP_NUM_DATA_IN)\
--msc_ep_num_out $(USB_MSC_EP_NUM_OUT)\
--msc_ep_num_in $(USB_MSC_EP_NUM_IN)\
--hid_ep_num_out $(USB_HID_EP_NUM_OUT)\
--hid_ep_num_in $(USB_HID_EP_NUM_IN)\
--midi_ep_num_out $(USB_MIDI_EP_NUM_OUT)\
--midi_ep_num_in $(USB_MIDI_EP_NUM_IN)\
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
ifeq ($(USB_RENUMBER_ENDPOINTS), 0)
USB_DESCRIPTOR_ARGS += --no-renumber_endpoints
endif
SUPERVISOR_O = $(addprefix $(BUILD)/, $(SRC_SUPERVISOR:.c=.o)) $(BUILD)/autogen_display_resources.o
$(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h
@ -114,18 +170,7 @@ $(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: auto
autogen_usb_descriptor.intermediate: ../../tools/gen_usb_descriptor.py Makefile | $(HEADER_BUILD)
$(STEPECHO) "GEN $@"
$(Q)install -d $(BUILD)/genhdr
$(Q)$(PYTHON3) ../../tools/gen_usb_descriptor.py \
--manufacturer $(USB_MANUFACTURER)\
--product $(USB_PRODUCT)\
--vid $(USB_VID)\
--pid $(USB_PID)\
--serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\
--devices $(USB_DEVICES)\
--hid_devices $(USB_HID_DEVICES)\
--msc_num_endpoint_pairs $(USB_MSC_NUM_ENDPOINT_PAIRS)\
--msc_max_packet_size $(USB_MSC_MAX_PACKET_SIZE)\
--output_c_file $(BUILD)/autogen_usb_descriptor.c\
--output_h_file $(BUILD)/genhdr/autogen_usb_descriptor.h
$(Q)$(PYTHON3) ../../tools/gen_usb_descriptor.py $(USB_DESCRIPTOR_ARGS)
CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf"

View File

@ -32,10 +32,28 @@ parser.add_argument('--devices', type=lambda l: tuple(l.split(',')), default=DEF
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('--msc_num_endpoint_pairs', type=int, default=1,
help='Use 1 or 2 endpoint pairs for MSC (1 bidirectional, or 1 input + 1 output (required by SAMD21))')
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',
help='use to not renumber endpoint')
parser.add_argument('--cdc_ep_num_notification', type=int, default=0,
help='endpoint number of CDC NOTIFICATION')
parser.add_argument('--cdc_ep_num_data_out', type=int, default=0,
help='endpoint number of CDC DATA OUT')
parser.add_argument('--cdc_ep_num_data_in', type=int, default=0,
help='endpoint number of CDC DATA IN')
parser.add_argument('--msc_ep_num_out', type=int, default=0,
help='endpoint number of MSC OUT')
parser.add_argument('--msc_ep_num_in', type=int, default=0,
help='endpoint number of MSC IN')
parser.add_argument('--hid_ep_num_out', type=int, default=0,
help='endpoint number of HID OUT')
parser.add_argument('--hid_ep_num_in', type=int, default=0,
help='endpoint number of HID IN')
parser.add_argument('--midi_ep_num_out', type=int, default=0,
help='endpoint number of MIDI OUT')
parser.add_argument('--midi_ep_num_in', type=int, default=0,
help='endpoint number of MIDI IN')
parser.add_argument('--output_c_file', type=argparse.FileType('w'), required=True)
parser.add_argument('--output_h_file', type=argparse.FileType('w'), required=True)
@ -49,9 +67,32 @@ unknown_hid_devices = list(frozenset(args.hid_devices) - ALL_HID_DEVICES_SET)
if unknown_hid_devices:
raise ValueError("Unknown HID devices(s)", unknown_hid_devices)
if args.msc_num_endpoint_pairs not in (1, 2):
raise ValueError("--msc_num_endpoint_pairs must be 1 or 2")
if not args.renumber_endpoints:
if 'CDC' in args.devices:
if args.cdc_ep_num_notification == 0:
raise ValueError("CDC notification endpoint number must not be 0")
elif args.cdc_ep_num_data_out == 0:
raise ValueError("CDC data OUT endpoint number must not be 0")
elif args.cdc_ep_num_data_in == 0:
raise ValueError("CDC data IN endpoint number must not be 0")
if 'MSC' in args.devices:
if args.msc_ep_num_out == 0:
raise ValueError("MSC endpoint OUT number must not be 0")
elif args.msc_ep_num_in == 0:
raise ValueError("MSC endpoint IN number must not be 0")
if 'HID' in args.devices:
if args.args.hid_ep_num_out == 0:
raise ValueError("HID endpoint OUT number must not be 0")
elif args.hid_ep_num_in == 0:
raise ValueError("HID endpoint IN number must not be 0")
if 'AUDIO' in args.devices:
if args.args.midi_ep_num_out == 0:
raise ValueError("MIDI endpoint OUT number must not be 0")
elif args.midi_ep_num_in == 0:
raise ValueError("MIDI endpoint IN number must not be 0")
class StringIndex:
"""Assign a monotonically increasing index to each unique string. Start with 0."""
@ -122,7 +163,7 @@ cdc_comm_interface = standard.InterfaceDescriptor(
cdc_union,
standard.EndpointDescriptor(
description="CDC comm in",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN,
bEndpointAddress=args.cdc_ep_num_notification | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT,
wMaxPacketSize=0x0040,
bInterval=0x10)
@ -135,11 +176,11 @@ cdc_data_interface = standard.InterfaceDescriptor(
subdescriptors=[
standard.EndpointDescriptor(
description="CDC data out",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_OUT,
bEndpointAddress=args.cdc_ep_num_data_out | standard.EndpointDescriptor.DIRECTION_OUT,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
standard.EndpointDescriptor(
description="CDC data in",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN,
bEndpointAddress=args.cdc_ep_num_data_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK),
])
@ -155,15 +196,13 @@ msc_interfaces = [
subdescriptors=[
standard.EndpointDescriptor(
description="MSC in",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN,
bEndpointAddress=args.msc_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval=0,
wMaxPacketSize=args.msc_max_packet_size),
standard.EndpointDescriptor(
description="MSC out",
# SAMD21 needs to use a separate pair of endpoints for MSC.
bEndpointAddress=((0x1 if args.msc_num_endpoint_pairs == 2 else 0x0) |
standard.EndpointDescriptor.DIRECTION_OUT),
bEndpointAddress=(args.msc_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT),
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval=0,
wMaxPacketSize=args.msc_max_packet_size)
@ -201,13 +240,13 @@ else:
# and will fail (possibly silently) if both are not supplied.
hid_endpoint_in_descriptor = standard.EndpointDescriptor(
description="HID in",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN,
bEndpointAddress=args.hid_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT,
bInterval=8)
hid_endpoint_out_descriptor = standard.EndpointDescriptor(
description="HID out",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_OUT,
bEndpointAddress=args.hid_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT,
bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT,
bInterval=8)
@ -271,12 +310,12 @@ audio_midi_interface = standard.InterfaceDescriptor(
),
standard.EndpointDescriptor(
description="MIDI data out to CircuitPython",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_OUT,
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",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN,
bEndpointAddress=args.midi_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN,
bmAttributes=standard.EndpointDescriptor.TYPE_BULK,
bInterval = 0x0),
midi.DataEndpointDescriptor(baAssocJack=[midi_out_jack_emb]),
@ -320,7 +359,7 @@ if 'AUDIO' in args.devices:
# util.join_interfaces() will renumber the endpoints to make them unique across descriptors,
# and renumber the interfaces in order. But we still need to fix up certain
# interface cross-references.
interfaces = util.join_interfaces(*interfaces_to_join)
interfaces = util.join_interfaces(interfaces_to_join, renumber_endpoints=args.renumber_endpoints)
# Now adjust the CDC interface cross-references.

@ -1 +1 @@
Subproject commit dac9689e274844294bbe4fd1b78defff9ff27533
Subproject commit 701cafc50e2e574dccaf7a340eedbd64a0b41a42