From 9f30f870fa5865e94e33a43d31c83ec9ea28de42 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 6 Apr 2021 19:15:31 -0400 Subject: [PATCH 01/66] Add some minimum versions to requirements-dev.txt --- requirements-dev.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 1c956f0f98..4b0e36d617 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,7 +8,7 @@ typer requests sh -click +click>=7.1.2 setuptools cpp-coveralls @@ -20,14 +20,14 @@ sphinx-autoapi sphinxcontrib-svg2pdfconverter # For translate check -polib +polib>=1.1.0 # For pre-commit pyyaml -astroid -isort -black -mypy +astroid>=2.5.1 +isort>=5.7.0 +black>=20.8b1 +mypy>=0.812 # For uploading artifacts awscli From 3e5bc5a05d6fe6ca93735e0bcbb490772f8d02c8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 8 Apr 2021 23:19:55 -0400 Subject: [PATCH 02/66] wip --- tools/gen_separated_usb_descriptors.py | 1064 ++++++++++++++++++++++++ tools/usb_descriptor | 2 +- 2 files changed, 1065 insertions(+), 1 deletion(-) create mode 100644 tools/gen_separated_usb_descriptors.py diff --git a/tools/gen_separated_usb_descriptors.py b/tools/gen_separated_usb_descriptors.py new file mode 100644 index 0000000000..1fad2fbeb3 --- /dev/null +++ b/tools/gen_separated_usb_descriptors.py @@ -0,0 +1,1064 @@ +# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) +# +# SPDX-License-Identifier: MIT + +import argparse + +import os +import sys + +sys.path.append("../../tools/usb_descriptor") + +from adafruit_usb_descriptor import audio, audio10, cdc, hid, midi, msc, standard, util +import hid_report_descriptors + +DEFAULT_INTERFACE_NAME = "CircuitPython" +ALL_DEVICES = "CDC CDC2 MSC AUDIO HID VENDOR" +ALL_DEVICES_SET = frozenset(ALL_DEVICES.split()) +DEFAULT_DEVICES = "CDC MSC AUDIO HID" + +# This list is in preferred order. MacOS does not like GAMEPAD coming before MOUSE. +ALL_HID_DEVICES = ( + "KEYBOARD MOUSE CONSUMER SYS_CONTROL GAMEPAD DIGITIZER XAC_COMPATIBLE_GAMEPAD RAW" +) +ALL_HID_DEVICES_ORDER = dict((name, idx) for (idx, name) in enumerate(ALL_HID_DEVICES.split())) +ALL_HID_DEVICES_SET = frozenset(ALL_HID_DEVICES.split()) +# Digitizer works on Linux but conflicts with mouse, so omit it. +DEFAULT_HID_DEVICES = "KEYBOARD MOUSE CONSUMER GAMEPAD" + +# In the following URL, don't include the https:// because that prefix gets added automatically +DEFAULT_WEBUSB_URL = "circuitpython.org" # In the future, this may become a specific landing page + +parser = argparse.ArgumentParser(description="Generate USB descriptors.") +parser.add_argument( + "--highspeed", default=False, action="store_true", help="descriptor for highspeed device" +) +parser.add_argument("--manufacturer", type=str, help="manufacturer of the device") +parser.add_argument("--product", type=str, help="product name of the device") +parser.add_argument("--vid", type=lambda x: int(x, 16), help="vendor id") +parser.add_argument("--pid", type=lambda x: int(x, 16), help="product id") +parser.add_argument( + "--serial_number_length", + type=int, + default=32, + help="length needed for the serial number in digits", +) +parser.add_argument( + "--devices", + type=lambda l: tuple(l.split()), + default=DEFAULT_DEVICES, + 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( + "--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( + "--cdc2_ep_num_notification", type=int, default=0, help="endpoint number of CDC2 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( + "--cdc2_ep_num_data_out", type=int, default=0, help="endpoint number of CDC2 DATA OUT" +) +parser.add_argument( + "--cdc2_ep_num_data_in", type=int, default=0, help="endpoint number of CDC2 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("--max_ep", type=int, default=0, help="total number of endpoints available") +parser.add_argument( + "--webusb_url", + type=str, + help="The URL to include in the WebUSB URL Descriptor", + default=DEFAULT_WEBUSB_URL, +) +parser.add_argument( + "--vendor_ep_num_out", type=int, default=0, help="endpoint number of VENDOR OUT" +) +parser.add_argument("--vendor_ep_num_in", type=int, default=0, help="endpoint number of VENDOR IN") +parser.add_argument( + "--output_c_file", type=argparse.FileType("w", encoding="UTF-8"), required=True +) +parser.add_argument( + "--output_h_file", type=argparse.FileType("w", encoding="UTF-8"), required=True +) + +args = parser.parse_args() + +unknown_devices = list(frozenset(args.devices) - ALL_DEVICES_SET) +if unknown_devices: + raise ValueError("Unknown device(s)", unknown_devices) + +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) + +include_cdc = "CDC" in args.devices +include_cdc2 = "CDC2" in args.devices +include_msc = "MSC" in args.devices +include_hid = "HID" in args.devices +include_audio = "AUDIO" in args.devices +include_vendor = "VENDOR" in args.devices + +if not include_cdc and include_cdc2: + raise ValueError("CDC2 requested without CDC") + +if not args.renumber_endpoints: + if include_cdc: + if args.cdc_ep_num_notification == 0: + raise ValueError("CDC notification endpoint number must not be 0") + if args.cdc_ep_num_data_out == 0: + raise ValueError("CDC data OUT endpoint number must not be 0") + if args.cdc_ep_num_data_in == 0: + raise ValueError("CDC data IN endpoint number must not be 0") + + if include_cdc2: + if args.cdc2_ep_num_notification == 0: + raise ValueError("CDC2 notification endpoint number must not be 0") + if args.cdc2_ep_num_data_out == 0: + raise ValueError("CDC2 data OUT endpoint number must not be 0") + if args.cdc2_ep_num_data_in == 0: + raise ValueError("CDC2 data IN endpoint number must not be 0") + + if include_msc: + if args.msc_ep_num_out == 0: + raise ValueError("MSC endpoint OUT number must not be 0") + if args.msc_ep_num_in == 0: + raise ValueError("MSC endpoint IN number must not be 0") + + if include_hid: + if args.args.hid_ep_num_out == 0: + raise ValueError("HID endpoint OUT number must not be 0") + if args.hid_ep_num_in == 0: + raise ValueError("HID endpoint IN number must not be 0") + + if include_audio: + if args.args.midi_ep_num_out == 0: + raise ValueError("MIDI endpoint OUT number must not be 0") + if args.midi_ep_num_in == 0: + raise ValueError("MIDI endpoint IN number must not be 0") + + if include_vendor: + if args.vendor_ep_num_out == 0: + raise ValueError("VENDOR endpoint OUT number must not be 0") + if args.vendor_ep_num_in == 0: + raise ValueError("VENDOR endpoint IN number must not be 0") + + +class StringIndex: + """Assign a monotonically increasing index to each unique string. Start with 0.""" + + string_to_index = {} + index_to_variable = {} + strings = [] + + @classmethod + def index(cls, string, *, variable_name=None): + if string in cls.string_to_index: + idx = cls.string_to_index[string] + if not cls.index_to_variable[idx]: + cls.index_to_variable[idx] = variable_name + return idx + else: + idx = len(cls.strings) + cls.string_to_index[string] = idx + cls.strings.append(string) + cls.index_to_variable[idx] = variable_name + return idx + + @classmethod + def strings_in_order(cls): + return cls.strings + + +# langid must be the 0th string descriptor +LANGID_INDEX = StringIndex.index("\u0409", variable_name="language_id") +assert LANGID_INDEX == 0 +SERIAL_NUMBER_INDEX = StringIndex.index( + "S" * args.serial_number_length, variable_name="usb_serial_number" +) + +device = standard.DeviceDescriptor( + description="top", + idVendor=args.vid, + idProduct=args.pid, + iManufacturer=StringIndex.index(args.manufacturer), + iProduct=StringIndex.index(args.product), + iSerialNumber=SERIAL_NUMBER_INDEX, +) + +# Interface numbers are interface-set local and endpoints are interface local +# until util.join_interfaces renumbers them. + + +def make_cdc_union(name): + return cdc.Union( + description="{} comm".format(name), + # Set bMasterInterface and bSlaveInterface_list to proper values after interfaces are renumbered. + bMasterInterface=0x00, + bSlaveInterface_list=[0x01], + ) + + +def make_cdc_call_management(name): + # Set bDataInterface to proper value after interfaces are renumbered. + return cdc.CallManagement( + description="{} comm".format(name), bmCapabilities=0x01, bDataInterface=0x01 + ) + + +def make_cdc_comm_interface(name, cdc_union, cdc_call_management, cdc_ep_num_notification): + return standard.InterfaceDescriptor( + description="{} comm".format(name), + bInterfaceClass=cdc.CDC_CLASS_COMM, # Communications Device Class + bInterfaceSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model + bInterfaceProtocol=cdc.CDC_PROTOCOL_NONE, + iInterface=StringIndex.index("{} {} control".format(args.interface_name, name)), + subdescriptors=[ + cdc.Header(description="{} comm".format(name), bcdCDC=0x0110), + cdc_call_management, + cdc.AbstractControlManagement(description="{} comm".format(name), bmCapabilities=0x02), + cdc_union, + standard.EndpointDescriptor( + description="{} comm in".format(name), + bEndpointAddress=cdc_ep_num_notification + | standard.EndpointDescriptor.DIRECTION_IN, + bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT, + wMaxPacketSize=0x0040, + bInterval=0x10, + ), + ], + ) + + +def make_cdc_data_interface(name, cdc_ep_num_data_in, cdc_ep_num_data_out): + return standard.InterfaceDescriptor( + description="{} data".format(name), + bInterfaceClass=cdc.CDC_CLASS_DATA, + iInterface=StringIndex.index("{} {} data".format(args.interface_name, name)), + subdescriptors=[ + standard.EndpointDescriptor( + description="{} data out".format(name), + bEndpointAddress=cdc_ep_num_data_out | standard.EndpointDescriptor.DIRECTION_OUT, + bmAttributes=standard.EndpointDescriptor.TYPE_BULK, + bInterval=0, + wMaxPacketSize=512 if args.highspeed else 64, + ), + standard.EndpointDescriptor( + description="{} data in".format(name), + bEndpointAddress=cdc_ep_num_data_in | standard.EndpointDescriptor.DIRECTION_IN, + bmAttributes=standard.EndpointDescriptor.TYPE_BULK, + bInterval=0, + wMaxPacketSize=512 if args.highspeed else 64, + ), + ], + ) + + +if include_cdc: + cdc_union = make_cdc_union("CDC") + cdc_call_management = make_cdc_call_management("CDC") + cdc_comm_interface = make_cdc_comm_interface( + "CDC", cdc_union, cdc_call_management, args.cdc_ep_num_notification + ) + cdc_data_interface = make_cdc_data_interface( + "CDC", args.cdc_ep_num_data_in, args.cdc_ep_num_data_out + ) + + cdc_interfaces = [cdc_comm_interface, cdc_data_interface] + +if include_cdc2: + cdc2_union = make_cdc_union("CDC2") + cdc2_call_management = make_cdc_call_management("CDC2") + cdc2_comm_interface = make_cdc_comm_interface( + "CDC2", cdc2_union, cdc2_call_management, args.cdc2_ep_num_notification + ) + cdc2_data_interface = make_cdc_data_interface( + "CDC2", args.cdc2_ep_num_data_in, args.cdc2_ep_num_data_out + ) + + cdc2_interfaces = [cdc2_comm_interface, cdc2_data_interface] + +if include_msc: + msc_interfaces = [ + standard.InterfaceDescriptor( + description="MSC", + bInterfaceClass=msc.MSC_CLASS, + bInterfaceSubClass=msc.MSC_SUBCLASS_TRANSPARENT, + bInterfaceProtocol=msc.MSC_PROTOCOL_BULK, + iInterface=StringIndex.index("{} Mass Storage".format(args.interface_name)), + subdescriptors=[ + standard.EndpointDescriptor( + description="MSC in", + bEndpointAddress=args.msc_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN, + bmAttributes=standard.EndpointDescriptor.TYPE_BULK, + bInterval=0, + wMaxPacketSize=512 if args.highspeed else 64, + ), + standard.EndpointDescriptor( + description="MSC out", + bEndpointAddress=( + args.msc_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT + ), + bmAttributes=standard.EndpointDescriptor.TYPE_BULK, + bInterval=0, + wMaxPacketSize=512 if args.highspeed else 64, + ), + ], + ) + ] + + +if include_hid: + # When there's only one hid_device, it shouldn't have a report id. + # Otherwise, report ids are assigned sequentially: + # args.hid_devices[0] has report_id 1 + # args.hid_devices[1] has report_id 2 + # etc. + + report_ids = {} + + if len(args.hid_devices) == 1: + name = args.hid_devices[0] + combined_hid_report_descriptor = hid.ReportDescriptor( + description=name, + report_descriptor=bytes(hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](0)), + ) + report_ids[name] = 0 + else: + report_id = 1 + concatenated_descriptors = bytearray() + # Sort HID devices by preferred order. + for name in sorted(args.hid_devices, key=ALL_HID_DEVICES_ORDER.get): + concatenated_descriptors.extend( + bytes(hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](report_id)) + ) + report_ids[name] = report_id + report_id += 1 + combined_hid_report_descriptor = hid.ReportDescriptor( + description="MULTIDEVICE", report_descriptor=bytes(concatenated_descriptors) + ) + + # ASF4 expects keyboard and generic devices to have both in and out endpoints, + # and will fail (possibly silently) if both are not supplied. + hid_endpoint_in_descriptor = standard.EndpointDescriptor( + description="HID 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=args.hid_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, + bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT, + bInterval=8, + ) + + hid_interfaces = [ + standard.InterfaceDescriptor( + description="HID Multiple Devices", + bInterfaceClass=hid.HID_CLASS, + bInterfaceSubClass=hid.HID_SUBCLASS_NOBOOT, + bInterfaceProtocol=hid.HID_PROTOCOL_NONE, + iInterface=StringIndex.index("{} HID".format(args.interface_name)), + subdescriptors=[ + hid.HIDDescriptor( + description="HID", wDescriptorLength=len(bytes(combined_hid_report_descriptor)) + ), + hid_endpoint_in_descriptor, + hid_endpoint_out_descriptor, + ], + ) + ] + +if include_audio: + # Audio! + # In and out here are relative to CircuitPython + + # USB OUT -> midi_in_jack_emb -> midi_out_jack_ext -> CircuitPython + midi_in_jack_emb = midi.InJackDescriptor( + description="MIDI PC -> {}".format(args.interface_name), + bJackType=midi.JACK_TYPE_EMBEDDED, + 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, + input_pins=[(midi_in_jack_emb, 1)], + iJack=0, + ) + + # USB IN <- midi_out_jack_emb <- midi_in_jack_ext <- CircuitPython + midi_in_jack_ext = midi.InJackDescriptor( + description="MIDI data in from user code.", bJackType=midi.JACK_TYPE_EXTERNAL, iJack=0 + ) + midi_out_jack_emb = midi.OutJackDescriptor( + description="MIDI PC <- {}".format(args.interface_name), + bJackType=midi.JACK_TYPE_EMBEDDED, + input_pins=[(midi_in_jack_ext, 1)], + iJack=StringIndex.index("{} usb_midi.ports[1]".format(args.interface_name)), + ) + + audio_midi_interface = standard.InterfaceDescriptor( + description="Midi goodness", + bInterfaceClass=audio.AUDIO_CLASS_DEVICE, + bInterfaceSubClass=audio.AUDIO_SUBCLASS_MIDI_STREAMING, + bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, + iInterface=StringIndex.index("{} MIDI".format(args.interface_name)), + subdescriptors=[ + midi.Header( + jacks_and_elements=[ + midi_in_jack_emb, + midi_in_jack_ext, + midi_out_jack_emb, + midi_out_jack_ext, + ] + ), + standard.EndpointDescriptor( + description="MIDI data out to {}".format(args.interface_name), + bEndpointAddress=args.midi_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, + bmAttributes=standard.EndpointDescriptor.TYPE_BULK, + bInterval=0, + wMaxPacketSize=512 if args.highspeed else 64, + ), + midi.DataEndpointDescriptor(baAssocJack=[midi_in_jack_emb]), + standard.EndpointDescriptor( + 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, + wMaxPacketSize=512 if args.highspeed else 64, + ), + midi.DataEndpointDescriptor(baAssocJack=[midi_out_jack_emb]), + ], + ) + + cs_ac_interface = audio10.AudioControlInterface( + description="Empty audio control", + audio_streaming_interfaces=[], + midi_streaming_interfaces=[audio_midi_interface], + ) + + audio_control_interface = standard.InterfaceDescriptor( + description="All the audio", + bInterfaceClass=audio.AUDIO_CLASS_DEVICE, + bInterfaceSubClass=audio.AUDIO_SUBCLASS_CONTROL, + bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, + iInterface=StringIndex.index("{} Audio".format(args.interface_name)), + subdescriptors=[cs_ac_interface], + ) + + # Audio streaming interfaces must occur before MIDI ones. + audio_interfaces = ( + [audio_control_interface] + + cs_ac_interface.audio_streaming_interfaces + + cs_ac_interface.midi_streaming_interfaces + ) + +if include_vendor: + # Vendor-specific interface, for example WebUSB + vendor_endpoint_in_descriptor = standard.EndpointDescriptor( + description="VENDOR in", + bEndpointAddress=args.vendor_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN, + bmAttributes=standard.EndpointDescriptor.TYPE_BULK, + bInterval=16, + ) + + vendor_endpoint_out_descriptor = standard.EndpointDescriptor( + description="VENDOR out", + bEndpointAddress=args.vendor_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, + bmAttributes=standard.EndpointDescriptor.TYPE_BULK, + bInterval=16, + ) + + vendor_interface = standard.InterfaceDescriptor( + description="VENDOR", + bInterfaceClass=0xFF, # Vendor-specific + bInterfaceSubClass=0x00, + bInterfaceProtocol=0x00, + iInterface=StringIndex.index("{} VENDOR".format(args.interface_name)), + subdescriptors=[vendor_endpoint_in_descriptor, vendor_endpoint_out_descriptor], + ) + + vendor_interfaces = [vendor_interface] + +interfaces_to_join = [] + +if include_cdc: + interfaces_to_join.append(cdc_interfaces) + +if include_cdc2: + interfaces_to_join.append(cdc2_interfaces) + +if include_msc: + interfaces_to_join.append(msc_interfaces) + +if include_hid: + interfaces_to_join.append(hid_interfaces) + +if include_audio: + interfaces_to_join.append(audio_interfaces) + +if include_vendor: + interfaces_to_join.append(vendor_interfaces) + +# 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, renumber_endpoints=args.renumber_endpoints) + +if args.max_ep != 0: + for interface in interfaces: + for subdescriptor in interface.subdescriptors: + endpoint_address = getattr(subdescriptor, "bEndpointAddress", 0) & 0x7F + if endpoint_address >= args.max_ep: + raise ValueError( + "Endpoint address %d of '%s' must be less than %d; you have probably run out of endpoints" + % (endpoint_address & 0x7F, interface.description, args.max_ep) + ) +else: + print("Unable to check whether maximum number of endpoints is respected", file=sys.stderr) + +# Now adjust the CDC interface cross-references. + +if include_cdc: + cdc_union.bMasterInterface = cdc_comm_interface.bInterfaceNumber + cdc_union.bSlaveInterface_list = [cdc_data_interface.bInterfaceNumber] + + cdc_call_management.bDataInterface = cdc_data_interface.bInterfaceNumber + +if include_cdc2: + cdc2_union.bMasterInterface = cdc2_comm_interface.bInterfaceNumber + cdc2_union.bSlaveInterface_list = [cdc2_data_interface.bInterfaceNumber] + + cdc2_call_management.bDataInterface = cdc2_data_interface.bInterfaceNumber + + +def make_cdc_iad(cdc_comm_interface, name): + return standard.InterfaceAssociationDescriptor( + description="{} IAD".format(name), + bFirstInterface=cdc_comm_interface.bInterfaceNumber, + bInterfaceCount=len(cdc_interfaces), + bFunctionClass=cdc.CDC_CLASS_COMM, # Communications Device Class + bFunctionSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model + bFunctionProtocol=cdc.CDC_PROTOCOL_NONE, + ) + + +if include_cdc: + cdc_iad = make_cdc_iad(cdc_comm_interface, "CDC") +if include_cdc2: + cdc2_iad = make_cdc_iad(cdc2_comm_interface, "CDC2") + +descriptor_list = [] + +if include_cdc: + # Put the CDC IAD just before the CDC interfaces. + # There appears to be a bug in the Windows composite USB driver that requests the + # HID report descriptor with the wrong interface number if the HID interface is not given + # first. However, it still fetches the descriptor anyway. We could reorder the interfaces but + # the Windows 7 Adafruit_usbser.inf file thinks CDC is at Interface 0, so we'll leave it + # there for backwards compatibility. + descriptor_list.append(cdc_iad) + descriptor_list.extend(cdc_interfaces) + +if include_cdc2: + descriptor_list.append(cdc2_iad) + descriptor_list.extend(cdc2_interfaces) + +if include_msc: + descriptor_list.extend(msc_interfaces) + +if include_hid: + descriptor_list.extend(hid_interfaces) + +if include_audio: + # Only add the control interface because other audio interfaces are managed by it to ensure the + # correct ordering. + descriptor_list.append(audio_control_interface) + +if include_vendor: + descriptor_list.extend(vendor_interfaces) + +# Finally, build the composite descriptor. + +configuration = standard.ConfigurationDescriptor( + description="Composite configuration", + wTotalLength=( + standard.ConfigurationDescriptor.bLength + sum([len(bytes(x)) for x in descriptor_list]) + ), + bNumInterfaces=len(interfaces), + # bus powered (bit 6), remote wakeup (bit 5), + # bit 7 is always 1 and 0-4 are always 0 + # Turn off remote wakeup until we handle it in CircuitPython. + bmAttributes=0x80, + +) +descriptor_list.insert(0, configuration) + +string_descriptors = [ + standard.StringDescriptor(string) for string in StringIndex.strings_in_order() +] +serial_number_descriptor = string_descriptors[SERIAL_NUMBER_INDEX] + +c_file = args.output_c_file +h_file = args.output_h_file + + +c_file.write( + """\ +#include + +#include "tusb.h" +#include "py/objtuple.h" +#include "shared-bindings/usb_hid/Device.h" +#include "{H_FILE_NAME}" + +""".format( + H_FILE_NAME=h_file.name + ) +) + +c_file.write( + """\ +// {DESCRIPTION} : {CLASS} +""".format( + DESCRIPTION=device.description, CLASS=device.__class__ + ) +) + +c_file.write( + """\ +const uint8_t usb_desc_dev[] = { +""" +) +for b in bytes(device): + c_file.write("0x{:02x}, ".format(b)) + +c_file.write( + """\ +}; +""" +) + +c_file.write( + """\ +const uint8_t usb_desc_cfg[] = { +""" +) + +# Write out all the regular descriptors as one long array (that's how ASF4 does it). +descriptor_length = 0 +for descriptor in descriptor_list: + c_file.write( + """\ +// {DESCRIPTION} : {CLASS} +""".format( + DESCRIPTION=descriptor.description, CLASS=descriptor.__class__ + ) + ) + + b = bytes(descriptor) + notes = descriptor.notes() + i = 0 + + # This prints each subdescriptor on a separate line. + n = 0 + while i < len(b): + length = b[i] + for j in range(length): + c_file.write("0x{:02x}, ".format(b[i + j])) + c_file.write("// " + notes[n]) + n += 1 + c_file.write("\n") + i += length + descriptor_length += len(b) + +c_file.write( + """\ +}; +""" +) + +pointers_to_strings = [] + +for idx, descriptor in enumerate(string_descriptors): + c_file.write( + """\ +// {DESCRIPTION} : {CLASS} +""".format( + DESCRIPTION=descriptor.description, CLASS=descriptor.__class__ + ) + ) + + b = bytes(descriptor) + notes = descriptor.notes() + i = 0 + + # This prints each subdescriptor on a separate line. + variable_name = StringIndex.index_to_variable[idx] + if not variable_name: + variable_name = "string_descriptor{}".format(idx) + pointers_to_strings.append("{name}".format(name=variable_name)) + + const = "const " + if variable_name == "usb_serial_number": + length = len(b) + c_file.write( + " uint16_t {NAME}[{length}];\n".format(NAME=variable_name, length=length // 2) + ) + else: + c_file.write( + """\ + const uint16_t {NAME}[] = {{ + """.format( + const=const, NAME=variable_name + ) + ) + n = 0 + while i < len(b): + length = b[i] + for j in range(length // 2): + c_file.write("0x{:04x}, ".format(b[i + 2 * j + 1] << 8 | b[i + 2 * j])) + n += 1 + c_file.write("\n") + i += length + c_file.write( + """\ + }; + """ + ) + +c_file.write( + """\ +// array of pointer to string descriptors +uint16_t const * const string_desc_arr [] = +{ +""" +) +c_file.write( + """,\ + +""".join( + pointers_to_strings + ) +) + +c_file.write( + """ +}; +""" +) + +c_file.write("\n") + +if include_hid: + hid_descriptor_length = len(bytes(combined_hid_report_descriptor)) +else: + hid_descriptor_length = 0 + +# Now the values we need for the .h file. +h_file.write( + """\ +#ifndef MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H +#define MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H + +#include + +extern const uint8_t usb_desc_dev[{device_length}]; +extern const uint8_t usb_desc_cfg[{configuration_length}]; +extern uint16_t usb_serial_number[{serial_number_length}]; +extern uint16_t const * const string_desc_arr [{string_descriptor_length}]; + +#define CFG_TUSB_RHPORT0_MODE ({rhport0_mode}) + +// Vendor name included in Inquiry response, max 8 bytes +#define CFG_TUD_MSC_VENDOR "{msc_vendor}" + +// Product name included in Inquiry response, max 16 bytes +#define CFG_TUD_MSC_PRODUCT "{msc_product}" + +""".format( + serial_number_length=len(bytes(serial_number_descriptor)) // 2, + device_length=len(bytes(device)), + configuration_length=descriptor_length, + max_configuration_length=max(hid_descriptor_length, descriptor_length), + string_descriptor_length=len(pointers_to_strings), + rhport0_mode="OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED" + if args.highspeed + else "OPT_MODE_DEVICE", + msc_vendor=args.manufacturer[:8], + msc_product=args.product[:16], + ) +) + +if include_hid: + h_file.write( + """\ +extern const uint8_t hid_report_descriptor[{hid_report_descriptor_length}]; + +#define USB_HID_NUM_DEVICES {hid_num_devices} +""".format( + hid_report_descriptor_length=len(bytes(combined_hid_report_descriptor)), + hid_num_devices=len(args.hid_devices), + ) + ) + +if include_vendor: + h_file.write( + """\ +enum +{ + VENDOR_REQUEST_WEBUSB = 1, + VENDOR_REQUEST_MICROSOFT = 2 +}; + +extern uint8_t const desc_ms_os_20[]; + +// Currently getting compile-time errors in files like tusb_fifo.c +// if we try do define this here (TODO figure this out!) +//extern const tusb_desc_webusb_url_t desc_webusb_url; + +""" + ) + +h_file.write( + """\ +#endif // MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H +""" +) + +if include_hid: + # Write out the report descriptor and info + c_file.write( + """\ +const uint8_t hid_report_descriptor[{HID_DESCRIPTOR_LENGTH}] = {{ +""".format( + HID_DESCRIPTOR_LENGTH=hid_descriptor_length + ) + ) + + for b in bytes(combined_hid_report_descriptor): + c_file.write("0x{:02x}, ".format(b)) + + c_file.write( + """\ +}; + +""" + ) + + # Write out USB HID report buffer definitions. + for name in args.hid_devices: + c_file.write( + """\ +static uint8_t {name}_report_buffer[{report_length}]; +""".format( + name=name.lower(), + report_length=hid_report_descriptors.HID_DEVICE_DATA[name].report_length, + ) + ) + + if hid_report_descriptors.HID_DEVICE_DATA[name].out_report_length > 0: + c_file.write( + """\ +static uint8_t {name}_out_report_buffer[{report_length}]; +""".format( + name=name.lower(), + report_length=hid_report_descriptors.HID_DEVICE_DATA[name].out_report_length, + ) + ) + + # Write out table of device objects. + c_file.write( + """\ +usb_hid_device_obj_t usb_hid_devices[] = { +""" + ) + for name in args.hid_devices: + device_data = hid_report_descriptors.HID_DEVICE_DATA[name] + out_report_buffer = ( + "{}_out_report_buffer".format(name.lower()) + if device_data.out_report_length > 0 + else "NULL" + ) + c_file.write( + """\ + {{ + .base = {{ .type = &usb_hid_device_type }}, + .report_buffer = {name}_report_buffer, + .report_id = {report_id}, + .report_length = {report_length}, + .usage_page = {usage_page:#04x}, + .usage = {usage:#04x}, + .out_report_buffer = {out_report_buffer}, + .out_report_length = {out_report_length}, + }}, +""".format( + name=name.lower(), + report_id=report_ids[name], + report_length=device_data.report_length, + usage_page=device_data.usage_page, + usage=device_data.usage, + out_report_buffer=out_report_buffer, + out_report_length=device_data.out_report_length, + ) + ) + c_file.write( + """\ +}; +""" + ) + + # Write out tuple of device objects. + c_file.write( + """ +mp_obj_tuple_t common_hal_usb_hid_devices = {{ + .base = {{ + .type = &mp_type_tuple, + }}, + .len = {num_devices}, + .items = {{ +""".format( + num_devices=len(args.hid_devices) + ) + ) + for idx in range(len(args.hid_devices)): + c_file.write( + """\ + (mp_obj_t) &usb_hid_devices[{idx}], +""".format( + idx=idx + ) + ) + c_file.write( + """\ + }, +}; +""" + ) + +if include_vendor: + # Mimic what the tinyusb webusb demo does in its main.c file + c_file.write( + """ +#define URL "{webusb_url}" + +const tusb_desc_webusb_url_t desc_webusb_url = +{{ + .bLength = 3 + sizeof(URL) - 1, + .bDescriptorType = 3, // WEBUSB URL type + .bScheme = 1, // 0: http, 1: https, 255: "" + .url = URL +}}; + +// These next two hardcoded descriptors were pulled from the usb_descriptor.c file +// of the tinyusb webusb_serial demo. TODO - this is probably something else to +// integrate into the adafruit_usb_descriptors project... + +//--------------------------------------------------------------------+ +// BOS Descriptor +//--------------------------------------------------------------------+ + +/* Microsoft OS 2.0 registry property descriptor +Per MS requirements https://msdn.microsoft.com/en-us/library/windows/hardware/hh450799(v=vs.85).aspx +device should create DeviceInterfaceGUIDs. It can be done by driver and +in case of real PnP solution device should expose MS "Microsoft OS 2.0 +registry property descriptor". Such descriptor can insert any record +into Windows registry per device/configuration/interface. In our case it +will insert "DeviceInterfaceGUIDs" multistring property. + +GUID is freshly generated and should be OK to use. + +https://developers.google.com/web/fundamentals/native-hardware/build-for-webusb/ +(Section Microsoft OS compatibility descriptors) +*/ + +#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) + +#define MS_OS_20_DESC_LEN 0xB2 + +// BOS Descriptor is required for webUSB +uint8_t const desc_bos[] = +{{ + // total length, number of device caps + TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2), + + // Vendor Code, iLandingPage + TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1), + + // Microsoft OS 2.0 descriptor + TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) +}}; + +uint8_t const * tud_descriptor_bos_cb(void) +{{ + return desc_bos; +}} + + +#define ITF_NUM_VENDOR {webusb_interface} // used in this next descriptor + +uint8_t const desc_ms_os_20[] = +{{ + // Set header: length, type, windows version, total length + U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN), + + // Configuration subset header: length, type, configuration index, reserved, configuration total length + U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A), + + // Function Subset header: length, type, first interface, reserved, subset length + U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_VENDOR, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08), + + // MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID + U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible + + // MS OS 2.0 Registry property descriptor: length, type + U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), + U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16 + 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, + 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00, + U16_TO_U8S_LE(0x0050), // wPropertyDataLength + //bPropertyData: “{{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}}”. + '{{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00, + '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, + '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00, + '8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}}', 0x00, 0x00, 0x00, 0x00, 0x00 +}}; + +TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size"); + +// End of section about desc_ms_os_20 + +""".format( + webusb_url=args.webusb_url, webusb_interface=vendor_interface.bInterfaceNumber + ) + ) diff --git a/tools/usb_descriptor b/tools/usb_descriptor index 2eaa6114b2..7ca9377687 160000 --- a/tools/usb_descriptor +++ b/tools/usb_descriptor @@ -1 +1 @@ -Subproject commit 2eaa6114b209fe7f0a795eda8d6a7b3b93d76d2e +Subproject commit 7ca9377687cc8bd367bd6401dcc4361a71a9d6cf From 2a58b667aaeef02396e9b58a07df06559dd0b6b2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 12 Apr 2021 23:42:48 -0400 Subject: [PATCH 03/66] wip: incorporate new hid descriptor building --- tools/gen_usb_descriptor.py | 35 +-- tools/hid_report_descriptors.py | 476 +------------------------------- tools/usb_descriptor | 2 +- 3 files changed, 24 insertions(+), 489 deletions(-) diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index 1fad2fbeb3..b873e75cc7 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -337,7 +337,7 @@ if include_msc: if include_hid: # When there's only one hid_device, it shouldn't have a report id. - # Otherwise, report ids are assigned sequentially: + # Otherwise, report ids are assigned sequentially, starting at 1. # args.hid_devices[0] has report_id 1 # args.hid_devices[1] has report_id 2 # etc. @@ -346,24 +346,19 @@ if include_hid: if len(args.hid_devices) == 1: name = args.hid_devices[0] - combined_hid_report_descriptor = hid.ReportDescriptor( - description=name, - report_descriptor=bytes(hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](0)), - ) + hid_descriptor = hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](None) + concatenated_hid_report_descriptors = bytes( + hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](report_id=0)) report_ids[name] = 0 else: report_id = 1 - concatenated_descriptors = bytearray() + concatenated_hid_report_descriptors = bytearray() # Sort HID devices by preferred order. for name in sorted(args.hid_devices, key=ALL_HID_DEVICES_ORDER.get): - concatenated_descriptors.extend( - bytes(hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](report_id)) - ) + hid_report_descriptor = hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](report_id) + concatenated_hid_report_descriptors.extend(bytes(hid_report_descriptor)) report_ids[name] = report_id report_id += 1 - combined_hid_report_descriptor = hid.ReportDescriptor( - description="MULTIDEVICE", report_descriptor=bytes(concatenated_descriptors) - ) # ASF4 expects keyboard and generic devices to have both in and out endpoints, # and will fail (possibly silently) if both are not supplied. @@ -390,7 +385,7 @@ if include_hid: iInterface=StringIndex.index("{} HID".format(args.interface_name)), subdescriptors=[ hid.HIDDescriptor( - description="HID", wDescriptorLength=len(bytes(combined_hid_report_descriptor)) + description="HID", wDescriptorLength=len(concatenated_hid_report_descriptors) ), hid_endpoint_in_descriptor, hid_endpoint_out_descriptor, @@ -780,9 +775,9 @@ c_file.write( c_file.write("\n") if include_hid: - hid_descriptor_length = len(bytes(combined_hid_report_descriptor)) + hid_report_descriptors_length = len(concatenated_hid_report_descriptors) else: - hid_descriptor_length = 0 + hid_report_descriptors_length = 0 # Now the values we need for the .h file. h_file.write( @@ -809,7 +804,7 @@ extern uint16_t const * const string_desc_arr [{string_descriptor_length}]; serial_number_length=len(bytes(serial_number_descriptor)) // 2, device_length=len(bytes(device)), configuration_length=descriptor_length, - max_configuration_length=max(hid_descriptor_length, descriptor_length), + max_configuration_length=max(hid_report_descriptors_length, descriptor_length), string_descriptor_length=len(pointers_to_strings), rhport0_mode="OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED" if args.highspeed @@ -826,7 +821,7 @@ extern const uint8_t hid_report_descriptor[{hid_report_descriptor_length}]; #define USB_HID_NUM_DEVICES {hid_num_devices} """.format( - hid_report_descriptor_length=len(bytes(combined_hid_report_descriptor)), + hid_report_descriptor_length=len(concatenated_hid_report_descriptors), hid_num_devices=len(args.hid_devices), ) ) @@ -859,13 +854,13 @@ if include_hid: # Write out the report descriptor and info c_file.write( """\ -const uint8_t hid_report_descriptor[{HID_DESCRIPTOR_LENGTH}] = {{ +const uint8_t hid_report_descriptor[{HID_REPORT_DESCRIPTORS_LENGTH}] = {{ """.format( - HID_DESCRIPTOR_LENGTH=hid_descriptor_length + HID_REPORT_DESCRIPTORS_LENGTH=hid_report_descriptors_length ) ) - for b in bytes(combined_hid_report_descriptor): + for b in bytes(concatenated_hid_report_descriptors): c_file.write("0x{:02x}, ".format(b)) c_file.write( diff --git a/tools/hid_report_descriptors.py b/tools/hid_report_descriptors.py index 827af3a3f0..c8dd5238ca 100644 --- a/tools/hid_report_descriptors.py +++ b/tools/hid_report_descriptors.py @@ -48,474 +48,14 @@ HID_DEVICE_DATA = { ), # Vendor 0xFFAF "Adafruit", 0xAF } - -def keyboard_hid_descriptor(report_id): - data = HID_DEVICE_DATA["KEYBOARD"] - return hid.ReportDescriptor( - description="KEYBOARD", - report_descriptor=bytes( - # Regular keyboard - ( - 0x05, - data.usage_page, # Usage Page (Generic Desktop) - 0x09, - data.usage, # Usage (Keyboard) - 0xA1, - 0x01, # Collection (Application) - ) - + ((0x85, report_id) if report_id != 0 else ()) - + ( - 0x05, - 0x07, # Usage Page (Keyboard) - 0x19, - 224, # Usage Minimum (224) - 0x29, - 231, # Usage Maximum (231) - 0x15, - 0x00, # Logical Minimum (0) - 0x25, - 0x01, # Logical Maximum (1) - 0x75, - 0x01, # Report Size (1) - 0x95, - 0x08, # Report Count (8) - 0x81, - 0x02, # Input (Data, Variable, Absolute) - 0x81, - 0x01, # Input (Constant) - 0x19, - 0x00, # Usage Minimum (0) - 0x29, - 0xDD, # Usage Maximum (221) - 0x15, - 0x00, # Logical Minimum (0) - 0x25, - 0xDD, # Logical Maximum (221) - 0x75, - 0x08, # Report Size (8) - 0x95, - 0x06, # Report Count (6) - 0x81, - 0x00, # Input (Data, Array) - 0x05, - 0x08, # Usage Page (LED) - 0x19, - 0x01, # Usage Minimum (1) - 0x29, - 0x05, # Usage Maximum (5) - 0x15, - 0x00, # Logical Minimum (0) - 0x25, - 0x01, # Logical Maximum (1) - 0x75, - 0x01, # Report Size (1) - 0x95, - 0x05, # Report Count (5) - 0x91, - 0x02, # Output (Data, Variable, Absolute) - 0x95, - 0x03, # Report Count (3) - 0x91, - 0x01, # Output (Constant) - 0xC0, # End Collection - ) - ), - ) - - -def mouse_hid_descriptor(report_id): - data = HID_DEVICE_DATA["MOUSE"] - return hid.ReportDescriptor( - description="MOUSE", - report_descriptor=bytes( - # Regular mouse - ( - 0x05, - data.usage_page, # Usage Page (Generic Desktop) - 0x09, - data.usage, # Usage (Mouse) - 0xA1, - 0x01, # Collection (Application) - 0x09, - 0x01, # Usage (Pointer) - 0xA1, - 0x00, # Collection (Physical) - ) - + ((0x85, report_id) if report_id != 0 else ()) - + ( - 0x05, - 0x09, # Usage Page (Button) - 0x19, - 0x01, # Usage Minimum (0x01) - 0x29, - 0x05, # Usage Maximum (0x05) - 0x15, - 0x00, # Logical Minimum (0) - 0x25, - 0x01, # Logical Maximum (1) - 0x95, - 0x05, # Report Count (5) - 0x75, - 0x01, # Report Size (1) - 0x81, - 0x02, # Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x95, - 0x01, # Report Count (1) - 0x75, - 0x03, # Report Size (3) - 0x81, - 0x01, # Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x05, - 0x01, # Usage Page (Generic Desktop Ctrls) - 0x09, - 0x30, # Usage (X) - 0x09, - 0x31, # Usage (Y) - 0x15, - 0x81, # Logical Minimum (-127) - 0x25, - 0x7F, # Logical Maximum (127) - 0x75, - 0x08, # Report Size (8) - 0x95, - 0x02, # Report Count (2) - 0x81, - 0x06, # Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position) - 0x09, - 0x38, # Usage (Wheel) - 0x15, - 0x81, # Logical Minimum (-127) - 0x25, - 0x7F, # Logical Maximum (127) - 0x75, - 0x08, # Report Size (8) - 0x95, - 0x01, # Report Count (1) - 0x81, - 0x06, # Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position) - 0xC0, # End Collection - 0xC0, # End Collection - ) - ), - ) - - -def consumer_hid_descriptor(report_id): - data = HID_DEVICE_DATA["CONSUMER"] - return hid.ReportDescriptor( - description="CONSUMER", - report_descriptor=bytes( - # Consumer ("multimedia") keys - ( - 0x05, - data.usage_page, # Usage Page (Consumer) - 0x09, - data.usage, # Usage (Consumer Control) - 0xA1, - 0x01, # Collection (Application) - ) - + ((0x85, report_id) if report_id != 0 else ()) - + ( - 0x75, - 0x10, # Report Size (16) - 0x95, - 0x01, # Report Count (1) - 0x15, - 0x01, # Logical Minimum (1) - 0x26, - 0x8C, - 0x02, # Logical Maximum (652) - 0x19, - 0x01, # Usage Minimum (Consumer Control) - 0x2A, - 0x8C, - 0x02, # Usage Maximum (AC Send) - 0x81, - 0x00, # Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0xC0, # End Collection - ) - ), - ) - - -def sys_control_hid_descriptor(report_id): - data = HID_DEVICE_DATA["SYS_CONTROL"] - return hid.ReportDescriptor( - description="SYS_CONTROL", - report_descriptor=bytes( - # Power controls - ( - 0x05, - data.usage_page, # Usage Page (Generic Desktop Ctrls) - 0x09, - data.usage, # Usage (Sys Control) - 0xA1, - 0x01, # Collection (Application) - ) - + ((0x85, report_id) if report_id != 0 else ()) - + ( - 0x75, - 0x02, # Report Size (2) - 0x95, - 0x01, # Report Count (1) - 0x15, - 0x01, # Logical Minimum (1) - 0x25, - 0x03, # Logical Maximum (3) - 0x09, - 0x82, # Usage (Sys Sleep) - 0x09, - 0x81, # Usage (Sys Power Down) - 0x09, - 0x83, # Usage (Sys Wake Up) - 0x81, - 0x60, # Input (Data,Array,Abs,No Wrap,Linear,No Preferred State,Null State) - 0x75, - 0x06, # Report Size (6) - 0x81, - 0x03, # Input (Const,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0xC0, # End Collection - ) - ), - ) - - -def gamepad_hid_descriptor(report_id): - data = HID_DEVICE_DATA["GAMEPAD"] - return hid.ReportDescriptor( - description="GAMEPAD", - report_descriptor=bytes( - # Gamepad with 16 buttons and two joysticks - ( - 0x05, - data.usage_page, # Usage Page (Generic Desktop Ctrls) - 0x09, - data.usage, # Usage (Game Pad) - 0xA1, - 0x01, # Collection (Application) - ) - + ((0x85, report_id) if report_id != 0 else ()) - + ( - 0x05, - 0x09, # Usage Page (Button) - 0x19, - 0x01, # Usage Minimum (Button 1) - 0x29, - 0x10, # Usage Maximum (Button 16) - 0x15, - 0x00, # Logical Minimum (0) - 0x25, - 0x01, # Logical Maximum (1) - 0x75, - 0x01, # Report Size (1) - 0x95, - 0x10, # Report Count (16) - 0x81, - 0x02, # Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x05, - 0x01, # Usage Page (Generic Desktop Ctrls) - 0x15, - 0x81, # Logical Minimum (-127) - 0x25, - 0x7F, # Logical Maximum (127) - 0x09, - 0x30, # Usage (X) - 0x09, - 0x31, # Usage (Y) - 0x09, - 0x32, # Usage (Z) - 0x09, - 0x35, # Usage (Rz) - 0x75, - 0x08, # Report Size (8) - 0x95, - 0x04, # Report Count (4) - 0x81, - 0x02, # Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0xC0, # End Collection - ) - ), - ) - - -def digitizer_hid_descriptor(report_id): - data = HID_DEVICE_DATA["DIGITIZER"] - return hid.ReportDescriptor( - description="DIGITIZER", - report_descriptor=bytes( - # Digitizer (used as an absolute pointer) - ( - 0x05, - data.usage_page, # Usage Page (Digitizers) - 0x09, - data.usage, # Usage (Pen) - 0xA1, - 0x01, # Collection (Application) - ) - + ((0x85, report_id) if report_id != 0 else ()) - + ( - 0x09, - 0x01, # Usage (Stylus) - 0xA1, - 0x00, # Collection (Physical) - 0x09, - 0x32, # Usage (In-Range) - 0x09, - 0x42, # Usage (Tip Switch) - 0x09, - 0x44, # Usage (Barrel Switch) - 0x09, - 0x45, # Usage (Eraser Switch) - 0x15, - 0x00, # Logical Minimum (0) - 0x25, - 0x01, # Logical Maximum (1) - 0x75, - 0x01, # Report Size (1) - 0x95, - 0x04, # Report Count (4) - 0x81, - 0x02, # Input (Data,Var,Abs) - 0x75, - 0x04, # Report Size (4) -- Filler - 0x95, - 0x01, # Report Count (1) -- Filler - 0x81, - 0x01, # Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x05, - 0x01, # Usage Page (Generic Desktop Ctrls) - 0x15, - 0x00, # Logical Minimum (0) - 0x26, - 0xFF, - 0x7F, # Logical Maximum (32767) - 0x09, - 0x30, # Usage (X) - 0x09, - 0x31, # Usage (Y) - 0x75, - 0x10, # Report Size (16) - 0x95, - 0x02, # Report Count (2) - 0x81, - 0x02, # Input (Data,Var,Abs) - 0xC0, # End Collection - 0xC0, # End Collection - ) - ), - ) - - -def xac_compatible_gamepad_hid_descriptor(report_id): - data = HID_DEVICE_DATA["XAC_COMPATIBLE_GAMEPAD"] - return hid.ReportDescriptor( - description="XAC", - report_descriptor=bytes( - # This descriptor mimics the simple joystick from PDP that the XBox likes - ( - 0x05, - data.usage_page, # Usage Page (Desktop), - 0x09, - data.usage, # Usage (Gamepad), - 0xA1, - 0x01, # Collection (Application), - ) - + ((0x85, report_id) if report_id != 0 else ()) - + ( - 0x15, - 0x00, # Logical Minimum (0), - 0x25, - 0x01, # Logical Maximum (1), - 0x35, - 0x00, # Physical Minimum (0), - 0x45, - 0x01, # Physical Maximum (1), - 0x75, - 0x01, # Report Size (1), - 0x95, - 0x08, # Report Count (8), - 0x05, - 0x09, # Usage Page (Button), - 0x19, - 0x01, # Usage Minimum (01h), - 0x29, - 0x08, # Usage Maximum (08h), - 0x81, - 0x02, # Input (Variable), - 0x05, - 0x01, # Usage Page (Desktop), - 0x26, - 0xFF, - 0x00, # Logical Maximum (255), - 0x46, - 0xFF, - 0x00, # Physical Maximum (255), - 0x09, - 0x30, # Usage (X), - 0x09, - 0x31, # Usage (Y), - 0x75, - 0x08, # Report Size (8), - 0x95, - 0x02, # Report Count (2), - 0x81, - 0x02, # Input (Variable), - 0xC0, # End Collection - ) - ), - ) - - -def raw_hid_descriptor(report_id): - if report_id != 0: - raise ValueError("raw hid must not have a report id") - data = HID_DEVICE_DATA["RAW"] - return hid.ReportDescriptor( - description="RAW", - report_descriptor=bytes( - # Provide vendor-defined - # This is a two-byte page value. - ( - 0x06, - data.usage_page & 0xFF, - (data.usage_page >> 8) & 0xFF, # Usage Page (Vendor 0xFFAF "Adafruit"), - 0x09, - data.usage, # Usage (AF), - 0xA1, - 0x01, # Collection (Application), - 0x75, - 0x08, # Report Size (8), - 0x15, - 0x00, # Logical Minimum (0), - 0x26, - 0xFF, - 0x00, # Logical Maximum (255), - 0x95, - 0x08, # Report Count (8), - 0x09, - 0x01, # Usage(xxx) - 0x81, - 0x02, # Input (Variable) - 0x95, - 0x08, # Report Count (8), - 0x09, - 0x02, # Usage(xxx) - 0x91, - 0x02, # Input (Variable) - 0xC0, # End Collection - ) - ), - ) - - # Function to call for each kind of HID descriptor. REPORT_DESCRIPTOR_FUNCTIONS = { - "KEYBOARD": keyboard_hid_descriptor, - "MOUSE": mouse_hid_descriptor, - "CONSUMER": consumer_hid_descriptor, - "SYS_CONTROL": sys_control_hid_descriptor, - "GAMEPAD": gamepad_hid_descriptor, - "DIGITIZER": digitizer_hid_descriptor, - "XAC_COMPATIBLE_GAMEPAD": xac_compatible_gamepad_hid_descriptor, - "RAW": raw_hid_descriptor, + "KEYBOARD": hid.ReportDescriptor.keyboard, + "MOUSE": hid.ReportDescriptor.mouse, + "CONSUMER": hid.ReportDescriptor.consumer_control, + "SYS_CONTROL": hid.ReportDescriptor.sys_control, + "GAMEPAD": hid.ReportDescriptor.gamepad, + "DIGITIZER": hid.ReportDescriptor.digitizer, + "XAC_COMPATIBLE_GAMEPAD": hid.ReportDescriptor.xac_compatible_gamepad, + "RAW": hid.ReportDescriptor.raw, } diff --git a/tools/usb_descriptor b/tools/usb_descriptor index 7ca9377687..7275306928 160000 --- a/tools/usb_descriptor +++ b/tools/usb_descriptor @@ -1 +1 @@ -Subproject commit 7ca9377687cc8bd367bd6401dcc4361a71a9d6cf +Subproject commit 727530692805bb1c9d9d20d7477804a1799e358d From 4a7e1292872e4d910bd51acfa2e8ca16985240b2 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 13 Apr 2021 23:33:44 -0400 Subject: [PATCH 04/66] wip: latent usb device enabling/disabling --- locale/circuitpython.pot | 25 ++++------ main.c | 22 +++++++++ py/circuitpy_mpconfig.mk | 4 +- shared-bindings/storage/__init__.c | 16 +++++++ shared-bindings/storage/__init__.h | 1 + shared-bindings/usb_cdc/__init__.c | 71 +++++++++++++++++++++++++---- shared-bindings/usb_cdc/__init__.h | 3 ++ shared-bindings/usb_midi/__init__.c | 18 +++++++- shared-bindings/usb_midi/__init__.h | 2 + shared-module/storage/__init__.c | 17 +++++++ shared-module/storage/__init__.h | 32 +++++++++++++ shared-module/usb_cdc/__init__.c | 57 ++++++++++++++++------- shared-module/usb_cdc/__init__.h | 2 + shared-module/usb_midi/__init__.c | 52 +++++++++++++++------ shared-module/usb_midi/__init__.h | 1 + supervisor/shared/usb/usb.c | 2 +- 16 files changed, 261 insertions(+), 64 deletions(-) create mode 100644 shared-module/storage/__init__.h diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 811de13645..858152b52b 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -600,6 +600,14 @@ msgstr "" msgid "Can't set CCCD on local Characteristic" msgstr "" +#: shared-bindings/usb_cdc/__init__.c shared-bindings/usb_midi/__init__.c +msgid "Cannot change USB devices now" +msgstr "" + +#: shared-bindings/storage/__init__.c +msgid "Cannot change usb devices now" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Cannot create a new Adapter; use _bleio.adapter;" msgstr "" @@ -1080,10 +1088,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -3249,10 +3253,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3712,6 +3712,7 @@ msgstr "" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -4010,10 +4011,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "" @@ -4148,10 +4145,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" diff --git a/main.c b/main.c index 1e828a1aa7..9f83bb370c 100755 --- a/main.c +++ b/main.c @@ -94,10 +94,18 @@ #include "shared-module/network/__init__.h" #endif +#if CIRCUITPY_STORAGE +#include "shared-module/storage/__init__.h" +#endif + #if CIRCUITPY_USB_CDC #include "shared-module/usb_cdc/__init__.h" #endif +#if CIRCUITPY_USB_MIDI +#include "shared-module/usb_midi/__init__.h" +#endif + #if CIRCUITPY_WIFI #include "shared-bindings/wifi/__init__.h" #endif @@ -169,6 +177,20 @@ STATIC void start_mp(supervisor_allocation* heap) { #if CIRCUITPY_NETWORK network_module_init(); #endif + + // Do before boot.py. + + #if CIRCUITPY_STORAGE + storage_init(); + #endif + + #if CIRCUITPY_USB_CDC + usb_cdc_init(); + #endif + + #if CIRCUITPY_USB_MIDI + usb_midi_init(); + #endif } STATIC void stop_mp(void) { diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 2a4467d493..4538016a39 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -325,10 +325,8 @@ CFLAGS += -DCIRCUITPY_TOUCHIO=$(CIRCUITPY_TOUCHIO) CIRCUITPY_UHEAP ?= 0 CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP) -# Disable by default for now, until we have dynamic enabling. -CIRCUITPY_USB_CDC ?= 0 # Secondary CDC is usually available if there are at least 8 endpoints. -#CIRCUITPY_USB_CDC ?= $(shell expr $(USB_NUM_EP) '>=' 8) +CIRCUITPY_USB_CDC ?= $(shell expr $(USB_NUM_EP) '>=' 8) CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC) CIRCUITPY_USB_HID ?= 1 diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 7b436a4df1..526d2c7e1a 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -158,6 +158,21 @@ mp_obj_t storage_erase_filesystem(void) { } MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem); +//| def enable_usb(enabled: True) -> None: +//| """Enable or disable presenting ``CIRCUITPY`` as a USB mass storage device. +//| By default, ``CIRCUITPY`` is visible. +//| Use ``storage.enable_usb(False)`` to hide CIRCUITPY from the host computer. +//| Can be changed in ``boot.py``, before USB is connected.""" +//| ... +//| +STATIC mp_obj_t storage_enable_usb(mp_obj_t enabled) { + if (!common_hal_storage_enable_usb(mp_obj_is_true(enabled))) { + mp_raise_RuntimeError(translate("Cannot change usb devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(storage_enable_usb_obj, storage_enable_usb); + STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) }, @@ -166,6 +181,7 @@ STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) }, { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, { MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) }, + { MP_ROM_QSTR(MP_QSTR_enable_usb), MP_ROM_PTR(&storage_enable_usb_obj) }, //| class VfsFat: //| def __init__(self, block_device: str) -> None: diff --git a/shared-bindings/storage/__init__.h b/shared-bindings/storage/__init__.h index eeb0d3a73b..4b578ccd7e 100644 --- a/shared-bindings/storage/__init__.h +++ b/shared-bindings/storage/__init__.h @@ -36,5 +36,6 @@ void common_hal_storage_umount_object(mp_obj_t vfs_obj); void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection); mp_obj_t common_hal_storage_getmount(const char *path); void common_hal_storage_erase_filesystem(void); +bool common_hal_storage_enable_usb(bool enabled); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H diff --git a/shared-bindings/usb_cdc/__init__.c b/shared-bindings/usb_cdc/__init__.c index 9e9ccb898d..2ef9a2dc02 100644 --- a/shared-bindings/usb_cdc/__init__.c +++ b/shared-bindings/usb_cdc/__init__.c @@ -36,22 +36,73 @@ //| """USB CDC Serial streams //| -//| The `usb_cdc` module allows access to USB CDC (serial) communications.""" +//| The `usb_cdc` module allows access to USB CDC (serial) communications. //| -//| serials: Tuple[Serial, ...] -//| """Tuple of all CDC streams. Each item is a `Serial`. -//| ``serials[0]`` is the USB REPL connection. -//| ``serials[1]`` is a second USB serial connection, unconnected to the REPL. +//| On Windows, each `Serial` is visible as a separate COM port. The ports will often +//| be assigned consecutively, REPL first, but this is not always true. +//| +//| On Linux, the ports are typically ``/dev/ttyACM0`` and ``/dev/ttyACM1``. The REPL +//| is usually first. +//| +//| On MacOS, the ports are typically ``/dev/cu.usbmodem``. The something +//| varies based on the USB bus and port used. The REPL is usually first. //| """ //| +//| repl: Optional[Serial] +//| """The `Serial` object that can be used to communicate over the REPL serial +//| channel. ``None`` if disabled. +//| +//| Note that`sys.stdin` and `sys.stdout` are also connected to the REPL, though +//| they are text-based streams, and the `repl` object is a binary stream.""" +//| +//| data: Optional[Serial] +//| """A `Serial` object that can be used to send and receive binary data to and from +//| the host. +//| Note that `data` is *disabled* by default.""" -static const mp_map_elem_t usb_cdc_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) }, - { MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) }, - { MP_ROM_QSTR(MP_QSTR_serials), MP_OBJ_FROM_PTR(&usb_cdc_serials_tuple) }, + + + +//| def enable_repl(enabled:bool) -> None: +//| """Enable or disable the `repl` USB serial connection. The REPL +//| is enabled by default. +//| Can be changed in ``boot.py``, before USB is connected.""" +//| ... +//| +STATIC mp_obj_t usb_cdc_enable_repl(mp_obj_t enabled) { + if (!common_hal_usb_cdc_enable_repl(mp_obj_is_true(enabled))) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(usb_cdc_enable_repl_obj, usb_cdc_enable_repl); + +//| def enable_data(enabled: bool) -> None: +//| """Enable or disable the `data` USB serial connection;n +//| *disabled* by default. +//| Can be changed in ``boot.py``, before USB is connected.""" +//| ... +//| +STATIC mp_obj_t usb_cdc_enable_data(mp_obj_t enabled) { + if (!common_hal_usb_cdc_enable_data(mp_obj_is_true(enabled))) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(usb_cdc_enable_data_obj, usb_cdc_enable_data); + +// The usb_cdc module dict is mutable so that .repl and .data may +// be set to a Serial or to None depending on whether they are enabled or not. +static mp_map_elem_t usb_cdc_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) }, + { MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) }, + { MP_ROM_QSTR(MP_QSTR_repl), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_data), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_enable_repl), MP_OBJ_FROM_PTR(&usb_cdc_enable_repl_obj) }, + { MP_ROM_QSTR(MP_QSTR_enable_data), MP_OBJ_FROM_PTR(&usb_cdc_enable_data_obj) }, }; -static MP_DEFINE_CONST_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table); +static MP_DEFINE_MUTABLE_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table); const mp_obj_module_t usb_cdc_module = { .base = { &mp_type_module }, diff --git a/shared-bindings/usb_cdc/__init__.h b/shared-bindings/usb_cdc/__init__.h index e81d243e6c..528288af25 100644 --- a/shared-bindings/usb_cdc/__init__.h +++ b/shared-bindings/usb_cdc/__init__.h @@ -29,4 +29,7 @@ #include "shared-module/usb_cdc/__init__.h" +bool common_hal_usb_cdc_enable_repl(bool enabled); +bool common_hal_usb_cdc_enable_data(bool enabled); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H diff --git a/shared-bindings/usb_midi/__init__.c b/shared-bindings/usb_midi/__init__.c index 4bbe46fda5..851160c23b 100644 --- a/shared-bindings/usb_midi/__init__.c +++ b/shared-bindings/usb_midi/__init__.c @@ -43,11 +43,25 @@ //| """Tuple of all MIDI ports. Each item is ether `PortIn` or `PortOut`.""" //| +//| def enable(enabled: bool) -> None: +//| """Enable or disable USB MIDI device. By default, MIDI is enabled. +//| Can be changed in ``boot.py``, before USB is connected.""" +//| ... +//| +STATIC mp_obj_t usb_midi_enable(mp_obj_t enabled) { + if (!common_hal_usb_midi_enable(mp_obj_is_true(enabled))) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(usb_midi_enable_obj, usb_midi_enable); + mp_map_elem_t usb_midi_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) }, - { MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple }, + { MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_midi_enable_obj) }, + { MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple }, { MP_ROM_QSTR(MP_QSTR_PortIn), MP_OBJ_FROM_PTR(&usb_midi_portin_type) }, - { MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) }, + { MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) }, }; // This isn't const so we can set ports dynamically. diff --git a/shared-bindings/usb_midi/__init__.h b/shared-bindings/usb_midi/__init__.h index e81818e04c..ae53b92f97 100644 --- a/shared-bindings/usb_midi/__init__.h +++ b/shared-bindings/usb_midi/__init__.h @@ -31,4 +31,6 @@ extern mp_obj_dict_t usb_midi_module_globals; +bool common_hal_usb_midi_enable(bool enabled); + #endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_MIDI___INIT___H diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 5c743377df..efd2a9c112 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -39,6 +39,10 @@ #include "supervisor/filesystem.h" #include "supervisor/flash.h" #include "supervisor/usb.h" +#include "tusb.h" + +// Is the MSC device enabled? +static bool usb_storage_enabled; STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { if (vfs == MP_VFS_NONE) { @@ -57,6 +61,10 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_ return mp_call_method_n_kw(n_args, 0, meth); } +void storage_init(void) { + usb_storage_enabled = true; +} + void common_hal_storage_mount(mp_obj_t vfs_obj, const char *mount_path, bool readonly) { // create new object mp_vfs_mount_t *vfs = m_new_obj(mp_vfs_mount_t); @@ -166,3 +174,12 @@ void common_hal_storage_erase_filesystem(void) { common_hal_mcu_reset(); // We won't actually get here, since we're resetting. } + +bool common_hal_storage_enable_usb(bool enabled) { + // We can't change the descriptors once we're connected. + if (!tud_connected()) { + return false; + } + usb_storage_enabled = enabled; + return true; +} diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h new file mode 100644 index 0000000000..69e2a2da1c --- /dev/null +++ b/shared-module/storage/__init__.h @@ -0,0 +1,32 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Dan Halbert for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef SHARED_MODULE_STORAGE___INIT___H +#define SHARED_MODULE_STORAGE___INIT___H + +void storage_init(void); + +#endif // SHARED_MODULE_STORAGE___INIT___H diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 3cf80a8b5c..9c3b6bfbe4 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -38,23 +38,46 @@ #error CFG_TUD_CDC must be exactly 2 #endif -static usb_cdc_serial_obj_t serial_objs[CFG_TUD_CDC] = { - { .base.type = &usb_cdc_serial_type, - .timeout = -1.0f, - .write_timeout = -1.0f, - .idx = 0,}, { - .base.type = &usb_cdc_serial_type, - .timeout = -1.0f, - .write_timeout = -1.0f, - .idx = 1, - } +static bool usb_cdc_repl_enabled; +static bool usb_cdc_data_enabled; + +static usb_cdc_serial_obj_t usb_cdc_repl_obj = { + .base.type = &usb_cdc_serial_type, + .timeout = -1.0f, + .write_timeout = -1.0f, + .idx = 0, }; -const mp_rom_obj_tuple_t usb_cdc_serials_tuple = { - .base.type = &mp_type_tuple, - .len = CFG_TUD_CDC, - .items = { - &serial_objs[0], - &serial_objs[1], - }, +static usb_cdc_serial_obj_t usb_cdc_data_obj = { + .base.type = &usb_cdc_serial_type, + .timeout = -1.0f, + .write_timeout = -1.0f, + .idx = 1, }; + +void usb_cdc_init(void) { + usb_cdc_repl_enabled = true; + usb_cdc_data_enabled = false; +} + +bool common_hal_usb_cdc_enable_repl(bool enabled) { + // We can't change the descriptors once we're connected. + if (!tud_connected()) { + // TODO set entry in dict + return false; + } + usb_cdc_repl_enabled = enabled; + // TODO set entry in dict + return true; +} + +bool common_hal_usb_cdc_enable_data(bool enabled) { + // We can't change the descriptors once we're connected. + if (!tud_connected()) { + // TODO set entry in dict + return false; + } + usb_cdc_data_enabled = enabled; + // TODO set entry in dict + return true; +} diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 9de3eb2faa..6e4e3b7001 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -31,4 +31,6 @@ extern const mp_rom_obj_tuple_t usb_cdc_serials_tuple; +void usb_cdc_init(void); + #endif /* SHARED_MODULE_USB_CDC___INIT___H */ diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 0684112b72..3871a934f6 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -38,26 +38,48 @@ supervisor_allocation *usb_midi_allocation; +// Is the USB MIDI device enabled? +static bool usb_midi_enabled; + void usb_midi_init(void) { - // TODO(tannewt): Make this dynamic. - size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t *) * 2); - size_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t)); - size_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t)); + usb_midi_enabled = true; +} - // For each embedded MIDI Jack in the descriptor we create a Port - usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false, false); +void usb_midi_usb_init(void) { + mp_obj_tuple_t *ports; - mp_obj_tuple_t *ports = (mp_obj_tuple_t *)usb_midi_allocation->ptr; - ports->base.type = &mp_type_tuple; - ports->len = 2; + if (usb_midi_enabled) { + // TODO(tannewt): Make this dynamic. + size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t *) * 2); + size_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t)); + size_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t)); - usb_midi_portin_obj_t *in = (usb_midi_portin_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4); - in->base.type = &usb_midi_portin_type; - ports->items[0] = MP_OBJ_FROM_PTR(in); + // For each embedded MIDI Jack in the descriptor we create a Port + usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false, false); - usb_midi_portout_obj_t *out = (usb_midi_portout_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4 + portin_size / 4); - out->base.type = &usb_midi_portout_type; - ports->items[1] = MP_OBJ_FROM_PTR(out); + ports = (mp_obj_tuple_t *)usb_midi_allocation->ptr; + ports->base.type = &mp_type_tuple; + ports->len = 2; + + usb_midi_portin_obj_t *in = (usb_midi_portin_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4); + in->base.type = &usb_midi_portin_type; + ports->items[0] = MP_OBJ_FROM_PTR(in); + + usb_midi_portout_obj_t *out = (usb_midi_portout_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4 + portin_size / 4); + out->base.type = &usb_midi_portout_type; + ports->items[1] = MP_OBJ_FROM_PTR(out); + } else { + ports = mp_const_empty_tuple; + } mp_map_lookup(&usb_midi_module_globals.map, MP_ROM_QSTR(MP_QSTR_ports), MP_MAP_LOOKUP)->value = MP_OBJ_FROM_PTR(ports); } + +bool common_hal_usb_midi_enable(bool enabled) { + // We can't change the descriptors once we're connected. + if (!tud_connected()) { + return false; + } + usb_midi_enabled = enabled; + return true; +} diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index e1ad1fbafb..9cba7fe6c4 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -28,5 +28,6 @@ #define SHARED_MODULE_USB_MIDI___INIT___H void usb_midi_init(void); +void usb_midi_usb_init(void); #endif /* SHARED_MODULE_USB_MIDI___INIT___H */ diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index ea5faaf06b..9d48a512bd 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -94,7 +94,7 @@ void usb_init(void) { #endif #if CIRCUITPY_USB_MIDI - usb_midi_init(); + usb_midi_usb_init(); #endif } From 6cb751ab065967014b92a84f222d2cc9c2cd3b85 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 14 Apr 2021 22:10:09 -0400 Subject: [PATCH 05/66] wip: revamp API names --- shared-bindings/storage/__init__.c | 29 ++++++++------ shared-bindings/storage/__init__.h | 2 +- shared-bindings/usb_cdc/__init__.c | 62 +++++++++++++++-------------- shared-bindings/usb_cdc/__init__.h | 7 +++- shared-bindings/usb_midi/__init__.c | 25 +++++++----- shared-bindings/usb_midi/__init__.h | 2 +- shared-module/storage/__init__.c | 4 +- shared-module/usb_cdc/__init__.c | 23 ++++------- shared-module/usb_cdc/__init__.h | 2 - shared-module/usb_midi/__init__.c | 4 +- 10 files changed, 81 insertions(+), 79 deletions(-) diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 526d2c7e1a..f4dba61867 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -158,30 +158,33 @@ mp_obj_t storage_erase_filesystem(void) { } MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem); -//| def enable_usb(enabled: True) -> None: -//| """Enable or disable presenting ``CIRCUITPY`` as a USB mass storage device. -//| By default, ``CIRCUITPY`` is visible. -//| Use ``storage.enable_usb(False)`` to hide CIRCUITPY from the host computer. -//| Can be changed in ``boot.py``, before USB is connected.""" +//| def configure_usb(enabled: True) -> None: +//| """Configure the USB mass storage device. +//| Enable or disable presenting ``CIRCUITPY`` as a USB mass storage device. +//| By default, the device is enabled and ``CIRCUITPY`` is visible. +//| Can be called in ``boot.py``, before USB is connected. +//| +//| :param enabled bool: Enable or disable the USB mass storage device. +//| True to enable; False to disable. Enabled by default.""" //| ... //| -STATIC mp_obj_t storage_enable_usb(mp_obj_t enabled) { - if (!common_hal_storage_enable_usb(mp_obj_is_true(enabled))) { +STATIC mp_obj_t storage_configure_usb(mp_obj_t enabled) { + if (!common_hal_storage_configure_usb(mp_obj_is_true(enabled))) { mp_raise_RuntimeError(translate("Cannot change usb devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(storage_enable_usb_obj, storage_enable_usb); +MP_DEFINE_CONST_FUN_OBJ_1(storage_configure_usb_obj, storage_configure_usb); STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) }, - { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) }, - { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) }, - { MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) }, - { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, + { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) }, + { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) }, + { MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) }, + { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, { MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) }, - { MP_ROM_QSTR(MP_QSTR_enable_usb), MP_ROM_PTR(&storage_enable_usb_obj) }, + { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_ROM_PTR(&storage_configure_usb_obj) }, //| class VfsFat: //| def __init__(self, block_device: str) -> None: diff --git a/shared-bindings/storage/__init__.h b/shared-bindings/storage/__init__.h index 4b578ccd7e..cd9366c1bc 100644 --- a/shared-bindings/storage/__init__.h +++ b/shared-bindings/storage/__init__.h @@ -36,6 +36,6 @@ void common_hal_storage_umount_object(mp_obj_t vfs_obj); void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection); mp_obj_t common_hal_storage_getmount(const char *path); void common_hal_storage_erase_filesystem(void); -bool common_hal_storage_enable_usb(bool enabled); +bool common_hal_storage_configure_usb(bool enabled); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H diff --git a/shared-bindings/usb_cdc/__init__.c b/shared-bindings/usb_cdc/__init__.c index 2ef9a2dc02..24728366a6 100644 --- a/shared-bindings/usb_cdc/__init__.c +++ b/shared-bindings/usb_cdc/__init__.c @@ -60,46 +60,33 @@ //| the host. //| Note that `data` is *disabled* by default.""" - - - -//| def enable_repl(enabled:bool) -> None: -//| """Enable or disable the `repl` USB serial connection. The REPL -//| is enabled by default. -//| Can be changed in ``boot.py``, before USB is connected.""" +//| def configure_usb(repl_enabled: bool, data_enabled: bool) -> None: +//| """Configure the USB CDC devices. Can be called in ``boot.py``, before USB is connected. +//| +//| :param repl_enabled bool: Enable or disable the `repl` USB serial device. +//| True to enable; False to disable. Enabled by default. +//| :param data_enabled bool: Enable or disable the `data` USB serial device. +//| True to enable; False to disable. *Disabled* by default.""" //| ... //| -STATIC mp_obj_t usb_cdc_enable_repl(mp_obj_t enabled) { - if (!common_hal_usb_cdc_enable_repl(mp_obj_is_true(enabled))) { +STATIC mp_obj_t usb_cdc_configure_usb(mp_obj_t repl_enabled, mp_obj_t data_enabled) { + if (!common_hal_usb_cdc_configure_usb( + mp_obj_is_true(repl_enabled), + mp_obj_is_true(data_enabled))) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(usb_cdc_enable_repl_obj, usb_cdc_enable_repl); - -//| def enable_data(enabled: bool) -> None: -//| """Enable or disable the `data` USB serial connection;n -//| *disabled* by default. -//| Can be changed in ``boot.py``, before USB is connected.""" -//| ... -//| -STATIC mp_obj_t usb_cdc_enable_data(mp_obj_t enabled) { - if (!common_hal_usb_cdc_enable_data(mp_obj_is_true(enabled))) { - mp_raise_RuntimeError(translate("Cannot change USB devices now")); - } - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(usb_cdc_enable_data_obj, usb_cdc_enable_data); +MP_DEFINE_CONST_FUN_OBJ_2(usb_cdc_configure_usb_obj, usb_cdc_configure_usb); // The usb_cdc module dict is mutable so that .repl and .data may // be set to a Serial or to None depending on whether they are enabled or not. static mp_map_elem_t usb_cdc_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) }, - { MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) }, - { MP_ROM_QSTR(MP_QSTR_repl), mp_const_none }, - { MP_ROM_QSTR(MP_QSTR_data), mp_const_none }, - { MP_ROM_QSTR(MP_QSTR_enable_repl), MP_OBJ_FROM_PTR(&usb_cdc_enable_repl_obj) }, - { MP_ROM_QSTR(MP_QSTR_enable_data), MP_OBJ_FROM_PTR(&usb_cdc_enable_data_obj) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) }, + { MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) }, + { MP_ROM_QSTR(MP_QSTR_repl), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_data), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_cdc_configure_usb_obj) }, }; static MP_DEFINE_MUTABLE_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table); @@ -108,3 +95,18 @@ const mp_obj_module_t usb_cdc_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&usb_cdc_module_globals, }; + +static void set_module_dict_entry(mp_obj_t key_qstr, mp_obj_t serial_obj) { + mp_map_elem_t *elem = mp_map_lookup(&usb_cdc_module_globals.map, key_qstr, MP_MAP_LOOKUP); + if (elem) { + elem->value = serial_obj; + } +} + +void usb_cdc_set_repl(mp_obj_t serial_obj) { + set_module_dict_entry(MP_ROM_QSTR(MP_QSTR_repl), serial_obj); +} + +void usb_cdc_set_data(mp_obj_t serial_obj) { + set_module_dict_entry(MP_ROM_QSTR(MP_QSTR_data), serial_obj); +} diff --git a/shared-bindings/usb_cdc/__init__.h b/shared-bindings/usb_cdc/__init__.h index 528288af25..abf148e9f6 100644 --- a/shared-bindings/usb_cdc/__init__.h +++ b/shared-bindings/usb_cdc/__init__.h @@ -29,7 +29,10 @@ #include "shared-module/usb_cdc/__init__.h" -bool common_hal_usb_cdc_enable_repl(bool enabled); -bool common_hal_usb_cdc_enable_data(bool enabled); +// Set the module dict entries. +void usb_cdc_set_repl(mp_obj_t serial_obj); +void usb_cdc_set_data(mp_obj_t serial_obj); + +extern bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H diff --git a/shared-bindings/usb_midi/__init__.c b/shared-bindings/usb_midi/__init__.c index 851160c23b..6aaa60aa48 100644 --- a/shared-bindings/usb_midi/__init__.c +++ b/shared-bindings/usb_midi/__init__.c @@ -43,25 +43,28 @@ //| """Tuple of all MIDI ports. Each item is ether `PortIn` or `PortOut`.""" //| -//| def enable(enabled: bool) -> None: -//| """Enable or disable USB MIDI device. By default, MIDI is enabled. -//| Can be changed in ``boot.py``, before USB is connected.""" +//| def configure_usb(enabled: True) -> None: +//| """Configure the USB MIDI device. +//| Can be called in ``boot.py``, before USB is connected. +//| +//| :param enabled bool: Enable or disable the USB MIDI Device. +//| True to enable; False to disable. Enabled by default.""" //| ... //| -STATIC mp_obj_t usb_midi_enable(mp_obj_t enabled) { - if (!common_hal_usb_midi_enable(mp_obj_is_true(enabled))) { +STATIC mp_obj_t usb_midi_configure_usb(mp_obj_t enabled) { + if (!common_hal_usb_midi_configure_usb(mp_obj_is_true(enabled))) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(usb_midi_enable_obj, usb_midi_enable); +MP_DEFINE_CONST_FUN_OBJ_1(usb_midi_configure_usb_obj, usb_midi_configure_usb); mp_map_elem_t usb_midi_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) }, - { MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_midi_enable_obj) }, - { MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple }, - { MP_ROM_QSTR(MP_QSTR_PortIn), MP_OBJ_FROM_PTR(&usb_midi_portin_type) }, - { MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) }, + { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_midi_configure_usb_obj) }, + { MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple }, + { MP_ROM_QSTR(MP_QSTR_PortIn), MP_OBJ_FROM_PTR(&usb_midi_portin_type) }, + { MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) }, }; // This isn't const so we can set ports dynamically. diff --git a/shared-bindings/usb_midi/__init__.h b/shared-bindings/usb_midi/__init__.h index ae53b92f97..25e0fbfcbf 100644 --- a/shared-bindings/usb_midi/__init__.h +++ b/shared-bindings/usb_midi/__init__.h @@ -31,6 +31,6 @@ extern mp_obj_dict_t usb_midi_module_globals; -bool common_hal_usb_midi_enable(bool enabled); +bool common_hal_usb_midi_configure_usb(bool enabled); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_MIDI___INIT___H diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index efd2a9c112..04f64fda65 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -175,9 +175,9 @@ void common_hal_storage_erase_filesystem(void) { // We won't actually get here, since we're resetting. } -bool common_hal_storage_enable_usb(bool enabled) { +bool common_hal_storage_configure_usb(bool enabled) { // We can't change the descriptors once we're connected. - if (!tud_connected()) { + if (tud_connected()) { return false; } usb_storage_enabled = enabled; diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 9c3b6bfbe4..afd71feda5 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -60,24 +60,17 @@ void usb_cdc_init(void) { usb_cdc_data_enabled = false; } -bool common_hal_usb_cdc_enable_repl(bool enabled) { +bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) { // We can't change the descriptors once we're connected. - if (!tud_connected()) { - // TODO set entry in dict + if (tud_connected()) { return false; } - usb_cdc_repl_enabled = enabled; - // TODO set entry in dict - return true; -} -bool common_hal_usb_cdc_enable_data(bool enabled) { - // We can't change the descriptors once we're connected. - if (!tud_connected()) { - // TODO set entry in dict - return false; - } - usb_cdc_data_enabled = enabled; - // TODO set entry in dict + usb_cdc_repl_enabled = repl_enabled; + usb_cdc_set_repl(repl_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_repl_obj) : mp_const_none); + + usb_cdc_data_enabled = data_enabled; + usb_cdc_set_data(data_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_data_obj) : mp_const_none); + return true; } diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 6e4e3b7001..321ee253bd 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -29,8 +29,6 @@ #include "py/objtuple.h" -extern const mp_rom_obj_tuple_t usb_cdc_serials_tuple; - void usb_cdc_init(void); #endif /* SHARED_MODULE_USB_CDC___INIT___H */ diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 3871a934f6..7956fe2f0c 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -75,9 +75,9 @@ void usb_midi_usb_init(void) { mp_map_lookup(&usb_midi_module_globals.map, MP_ROM_QSTR(MP_QSTR_ports), MP_MAP_LOOKUP)->value = MP_OBJ_FROM_PTR(ports); } -bool common_hal_usb_midi_enable(bool enabled) { +bool common_hal_usb_midi_configure_usb(bool enabled) { // We can't change the descriptors once we're connected. - if (!tud_connected()) { + if (tud_connected()) { return false; } usb_midi_enabled = enabled; From 51ccf8dc302ec0fcfbdeb50aae616405897110b5 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 19 Apr 2021 23:24:18 -0400 Subject: [PATCH 06/66] wip: revert usb_descriptor changes; use raw descriptors instead --- py/circuitpy_mpconfig.mk | 3 - shared-module/storage/__init__.c | 54 +++++++++++++- shared-module/storage/__init__.h | 6 ++ shared-module/usb_cdc/__init__.c | 4 +- shared-module/usb_cdc/__init__.h | 3 + shared-module/usb_midi/__init__.c | 107 +++++++++++++++++++++++++++- shared-module/usb_midi/__init__.h | 11 +++ supervisor/shared/usb/usb_desc.c | 114 +++++++++++++++++++++++++++++- supervisor/supervisor.mk | 50 +------------ tools/usb_descriptor | 2 +- 10 files changed, 294 insertions(+), 60 deletions(-) diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 4538016a39..5dc59cc73b 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -251,9 +251,6 @@ CFLAGS += -DCIRCUITPY_REPL_BLE=$(CIRCUITPY_REPL_BLE) CIRCUITPY_REPL_UART ?= 0 CFLAGS += -DCIRCUITPY_REPL_UART=$(CIRCUITPY_REPL_UART) -CIRCUITPY_REPL_USB ?= 1 -CFLAGS += -DCIRCUITPY_REPL_USB=$(CIRCUITPY_REPL_USB) - # Should busio.I2C() check for pullups? # Some boards in combination with certain peripherals may not want this. CIRCUITPY_REQUIRE_I2C_PULLUPS ?= 1 diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 04f64fda65..6c8e2a738b 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -41,8 +41,56 @@ #include "supervisor/usb.h" #include "tusb.h" +static uint8_t[] storage_usb_msc_descriptor[] = { + 0x09, // 0 bLength + 0x04, // 1 bDescriptorType (Interface) + 0xFF, // 2 bInterfaceNumber [SET AT RUNTIME] + 0x00, // 3 bAlternateSetting + 0x02, // 4 bNumEndpoints 2 + 0x08, // 5 bInterfaceClass: MSC + 0x06, // 6 bInterfaceSubClass: TRANSPARENT + 0x50, // 7 bInterfaceProtocol: BULK + 0x00, // 8 iInterface (String Index) [SET AT RUNTIME] + + 0x07, // 9 bLength + 0x05, // 10 bDescriptorType (Endpoint) + 0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] + 0x02, // 12 bmAttributes (Bulk) + 0x40, 0x00, // 13,14 wMaxPacketSize 64 + 0x00, // 15 bInterval 0 (unit depends on device speed) + + 0x07, // 16 bLength + 0x05, // 17 bDescriptorType (Endpoint) + 0xFF, // 18 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] + 0x02, // 19 bmAttributes (Bulk) + 0x40, 0x00, // 20 wMaxPacketSize 64 + 0x00, // 21 bInterval 0 (unit depends on device speed) +}; + +// Indices into usb_msc_descriptor for values that must be set at runtime. + +#define MSC_INTERFACE_NUMBER_INDEX 2 +#define MSC_INTERFACE_STRING_INDEX 8 +#define MSC_IN_ENDPOINT_INDEX 11 +#define MSC_OUT_ENDPOINT_INDEX 118 + // Is the MSC device enabled? -static bool usb_storage_enabled; +bool storage_usb_enabled; + +size_t storage_usb_desc_length(void) { + return sizeof(usb_msc_descriptor); +} + +size_t storage_usb_add_desc(uint8_t *desc_buf, uint8_t interface_number, uint8_t in_endpoint_address, + uint8_t out_endpoint_address, uint8_t interface_string_index) { + memcpy(descriptor_buf, storage_usb_msc_descriptor, sizeof(storage_usb_msc_descriptor)); + desc_buf[MSC_INTERFACE_NUMBER_INDEX] = interface_number; + desc_buf[MSC_INTERFACE_STRING_INDEX] = interface_string_index; + desc_buf[MSC_IN_ENDPOINT_INDEX] = in_endpoint_address; + desc_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | out_endpoint_address; + return sizeof(usb_msc_descriptor); +} + STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { if (vfs == MP_VFS_NONE) { @@ -62,7 +110,7 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_ } void storage_init(void) { - usb_storage_enabled = true; + storage_usb_enabled = true; } void common_hal_storage_mount(mp_obj_t vfs_obj, const char *mount_path, bool readonly) { @@ -180,6 +228,6 @@ bool common_hal_storage_configure_usb(bool enabled) { if (tud_connected()) { return false; } - usb_storage_enabled = enabled; + storage_usb_enabled = enabled; return true; } diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index 69e2a2da1c..e3cae1481a 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -27,6 +27,12 @@ #ifndef SHARED_MODULE_STORAGE___INIT___H #define SHARED_MODULE_STORAGE___INIT___H +extern bool storage_usb_enabled; + void storage_init(void); +size_t storage_usb_desc_length(void); +size_t storage_usb_add_desc(uint8_t *desc_buf, uint8_t interface_number, + uint8_t in_endpoint_address, uint8_t out_endpoint_address, + uint8_t interface_string_index); #endif // SHARED_MODULE_STORAGE___INIT___H diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index afd71feda5..d0930956cb 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -38,8 +38,8 @@ #error CFG_TUD_CDC must be exactly 2 #endif -static bool usb_cdc_repl_enabled; -static bool usb_cdc_data_enabled; +bool usb_cdc_repl_enabled; +bool usb_cdc_data_enabled; static usb_cdc_serial_obj_t usb_cdc_repl_obj = { .base.type = &usb_cdc_serial_type, diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 321ee253bd..79a2e58a92 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -29,6 +29,9 @@ #include "py/objtuple.h" +extern bool usb_cdc_repl_enabled; +extern bool usb_cdc_data_enabled; + void usb_cdc_init(void); #endif /* SHARED_MODULE_USB_CDC___INIT___H */ diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 7956fe2f0c..2869cc8b36 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -38,8 +38,113 @@ supervisor_allocation *usb_midi_allocation; +static uint8_t[] usb_midi_descriptor[] = { + 0x09, // 0 bLength + 0x04, // 1 bDescriptorType (Interface) + 0xFF, // 2 bInterfaceNumber [SET AT RUNTIME] + 0x00, // 3 bAlternateSetting + 0x00, // 4 bNumEndpoints 0 + 0x01, // 5 bInterfaceClass (Audio) + 0x01, // 6 bInterfaceSubClass (Audio Control) + 0x00, // 7 bInterfaceProtocol + 0x00, // 8 iInterface (String Index) [SET AT RUNTIME] + + 0x09, // 9 bLength + 0x24, // 10 bDescriptorType (See Next Line) + 0x01, // 11 bDescriptorSubtype (CS_INTERFACE -> HEADER) + 0x00, 0x01, // 12,13 bcdADC 1.00 + 0x09, 0x00, // 14,15 wTotalLength 9 + 0x01, // 16 binCollection 0x01 + 0xFF, // 17 baInterfaceNr [SET AT RUNTIME: one-element list: same as 20] + + 0x09, // 18 bLength + 0x04, // 19 bDescriptorType (Interface) + 0xFF, // 20 bInterfaceNumber [SET AT RUNTIME] + 0x00, // 21 bAlternateSetting + 0x02, // 22 bNumEndpoints 2 + 0x01, // 23 bInterfaceClass (Audio) + 0x03, // 24 bInterfaceSubClass (MIDI Streaming) + 0x00, // 25 bInterfaceProtocol + 0x0A, // 26 iInterface (String Index) [SET AT RUNTIME] + + 0x07, // 27 bLength + 0x24, // 28 bDescriptorType (See Next Line) + 0x01, 0x00, 0x01, 0x25, 0x00, // 29,30,31,32,33 + 0x06, // 34 bLength + 0x24, // 35 bDescriptorType (See Next Line) + 0x02, 0x01, 0x01, 0x08, // 36,37,38,39 + 0x06, // 40 bLength + 0x24, // 41 bDescriptorType (See Next Line) + 0x02, 0x02, 0x02, 0x00, // 42,43,44,45 + 0x09, // 46 bLength + 0x24, // 47 bDescriptorType (See Next Line) + 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x09, // 48,49,50,51,52,53,54 + 0x09, // 56 bLength + 0x24, // 57 bDescriptorType (See Next Line) + 0x03, 0x02, 0x04, 0x01, 0x01, 0x01, 0x00, // 58,59,60,61,62,63,64 + 0x07, // 65 bLength + 0x05, // 66 bDescriptorType (See Next Line) + 0xFF, // 67 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] + 0x02, // 68 bmAttributes (Bulk) + 0x40, 0x00, // 69,70 wMaxPacketSize 64 + 0x00, // 71 bInterval 0 (unit depends on device speed) + + 0x05, // 72 bLength + 0x25, // 73 bDescriptorType (See Next Line) + 0x01, 0x01, 0x01, // 74,75,76 + 0x07, // 77 bLength + 0x05, // 78 bDescriptorType (See Next Line) + 0xFF, // 79 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] + 0x02, // 80 bmAttributes (Bulk) + 0x40, 0x00, // 81,82 wMaxPacketSize 64 + 0x00, // 83 bInterval 0 (unit depends on device speed) + + 0x05, // 84 bLength + 0x25, // 85 bDescriptorType (See Next Line) + 0x01, 0x01, 0x03, // 86,87,88 +}; + // Is the USB MIDI device enabled? -static bool usb_midi_enabled; +bool usb_midi_enabled; + +// Indices into usb_midi_descriptor for values that must be set at runtime. + +#define MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX 2 +#define MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX 8 + +// These two get the same value. +#define MIDI_MIDI_STREAMING_INTERFACE_NUMBER_INDEX 20 +#define MIDI_MIDI_STREAMING_INTERFACE_NUMBER_XREF_INDEX 17 + +#define MIDI_MIDI_STREAMING_INTERFACE_STRING_INDEX 26 + +#define MIDI_MIDI_STREAMING_OUT_ENDPOINT_INDEX 67 +#define MIDI_MIDI_STREAMING_IN_ENDPOINT_INDEX 79 + +size_t usb_midi_desc_length(void) { + return sizeof(usb_midi_descriptor); +} + +size_t usb_midi_add_desc(uint8_t *desc_buf, + uint8_t audio_control_interface_number, + uint8_t midi_streaming_interface_number, + uint8_t midi_streaming_in_endpoint_address, + uint8_t midi_streaming_out_endpoint_address, + uint8_t audio_control_interface_string, + uint8_t midi_streaming_interface_string) { + memcpy(descriptor_buf, usb_midi_descriptor, sizeof(usb_midi_descriptor)); + desc_buf[MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX] = audio_control_interface_number; + desc_buf[MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX] = audio_control_interface_string; + + desc_buf[MIDI_MIDI_STREAMING_INTERFACE_NUMBER_INDEX] = midi_streaming_interface_number; + desc_buf[MIDI_MIDI_STREAMING_INTERFACE_NUMBER_XREF_INDEX] = midi_streaming_interface_number; + desc_buf[MIDI_MIDI_STREAMING_INTERFACE_STRING_INDEX] = midi_streaming_interface_string; + + desc_buf[MSC_IN_ENDPOINT_INDEX] = midi_streaming_in_endpoint_address; + desc_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | midi_streaming_out_endpoint_address; + return sizeof(usb_midi_descriptor); +} + void usb_midi_init(void) { usb_midi_enabled = true; diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index 9cba7fe6c4..75738515ba 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -27,7 +27,18 @@ #ifndef SHARED_MODULE_USB_MIDI___INIT___H #define SHARED_MODULE_USB_MIDI___INIT___H +extern bool usb_midi_enabled; + void usb_midi_init(void); void usb_midi_usb_init(void); +size_t usb_midi_desc_length(void); +size_t usb_midi_add_desc(uint8_t *desc_buf, + uint8_t audio_control_interface_number, + uint8_t midi_streaming_interface_number, + uint8_t midi_streaming_in_endpoint_address, + uint8_t midi_streaming_out_endpoint_address, + uint8_t audio_control_interface_string, + uint8_t midi_streaming_interface_string); + #endif /* SHARED_MODULE_USB_MIDI___INIT___H */ diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 67df4f44bf..1de9c0a7a9 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -25,10 +25,29 @@ */ #include "lib/tinyusb/src/tusb.h" + +#if CIRCUITPY_USB_CDC +#include "shared-module/storage/__init__.h" +#endif + +#if CIRCUITPY_USB_HID +#include "shared-module/usb_hid/__init__.h" +#endif + +#if CIRCUITPY_USB_MIDI +#include "shared-module/usb_midi/__init__.h" +#endif + +#if CIRCUITPY_USB_MSC +#include "shared-module/storage/__init__.h" +#endif + #include "shared-module/usb_hid/Device.h" #include "genhdr/autogen_usb_descriptor.h" +static uint8_t *config_desc; + // Invoked when received GET DEVICE DESCRIPTOR // Application return pointer to descriptor uint8_t const *tud_descriptor_device_cb(void) { @@ -40,7 +59,100 @@ uint8_t const *tud_descriptor_device_cb(void) { // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { (void)index; // for multiple configurations - return usb_desc_cfg; + + size_t total_descriptor_length = 0; + + // CDC should be first, for compatibility with Adafruit Windows 7 drivers. + // In the past, the order has been CDC, MSC, MIDI, HID, so preserve + // that order. +#if CIRCUITPY_USB_CDC + if (usb_cdc_repl_enabled) { + total_descriptor_length += usb_cdc_desc_length(); + } + if (usb_cdc_data_enabled) { + total_descriptor_length += usb_cdc_desc_length(); + } +#endif + +#if CIRCUITPY_USB_MSC + if (storage_usb_enabled) { + total_descriptor_length += storage_usb_desc_length(); + } +#endif + +#if CIRCUITPY_USB_MIDI + if (usb_midi_enabled) { + total_descriptor_length += usb_midi_desc_length(); + } +#endif + +#if CIRCUITPY_USB_HID + if (usb_hid_enabled) { + total_descriptor_length += usb_hid_desc_length(); + } +#endif + + // Now we now how big the configuration descriptor will be. + config_desc = m_malloc(total_descriptor_length, false); + + // Number interfaces and endpoints. + // Endpoint 0 is already used for USB control + uint8_t current_interface = 0; + uint8_t current_endpoint = 1; + uint16_t current_interface_string = 1; + + uint8_t *desc_buf_remaining = config_desc; + +#if CIRCUITPY_USB_CDC + if (usb_cdc_repl_enabled) { + // Concatenate and fix up the CDC REPL descriptor. + } + if (usb_cdc_data_enabled) { + // Concatenate and fix up the CDC data descriptor. + } +#endif + +#if CIRCUITPY_USB_MSC + if (storage_usb_enabled) { + // Concatenate and fix up the MSC descriptor. + desc_buf_remaining += storage_usb_add_desc( + desc_buf_remaining, current_interface, + current_endpoint, // in + current_endpoint, // out + current_interface_string_index); + current_interface++; + current_endpoint++; + current_interface_string++; + } +#endif + +#if CIRCUITPY_USB_MIDI + if (usb_midi_enabled) { + // Concatenate and fix up the MIDI descriptor. + desc_buf_remaining += usb_midi_add_desc( + desc_buf_remaining, + current_interface, // audio control + current_interface + 1, // MIDI streaming + current_endpoint, // in + current_endpoint, // out + current_interface_string, // audio control + current_interface_string + 1 // MIDI streaming + ); + current_interface += 2; + current_endpoint++; + current_interface_string += 2; + + } +#endif + +#if CIRCUITPY_USB_HID + if (usb_hid_enabled) { + // Concatenate and fix up the HID descriptor (not the report descriptors). + } +#endif + + + return config_desc; } #if CIRCUITPY_USB_HID diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 1744c4f47f..7fab262f64 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -149,57 +149,9 @@ endif # It gets added automatically. USB_WEBUSB_URL ?= "circuitpython.org" -ifeq ($(CIRCUITPY_REPL_USB),1) -USB_DEVICES += CDC -endif - -ifeq ($(CIRCUITPY_USB_HID),1) -USB_DEVICES += HID -endif -ifeq ($(CIRCUITPY_USB_MIDI),1) -USB_DEVICES += AUDIO -endif -ifeq ($(CIRCUITPY_USB_MSC),1) -USB_DEVICES += MSC -endif ifeq ($(CIRCUITPY_USB_CDC),1) # Inform TinyUSB there are two CDC devices. CFLAGS += -DCFG_TUD_CDC=2 -USB_DEVICES += CDC2 -endif -ifeq ($(CIRCUITPY_USB_VENDOR),1) -USB_DEVICES += VENDOR -endif - -USB_HID_DEVICES = -ifeq ($(CIRCUITPY_USB_HID_CONSUMER),1) -USB_HID_DEVICES += CONSUMER -endif -ifeq ($(CIRCUITPY_USB_HID_DIGITIZER),1) -USB_HID_DEVICES += DIGITIZER -endif -ifeq ($(CIRCUITPY_USB_HID_GAMEPAD),1) -USB_HID_DEVICES += GAMEPAD -endif -ifeq ($(CIRCUITPY_USB_HID_KEYBOARD),1) -USB_HID_DEVICES += KEYBOARD -endif -ifeq ($(CIRCUITPY_USB_HID_MOUSE),1) -USB_HID_DEVICES += MOUSE -endif -ifeq ($(CIRCUITPY_USB_HID_SYS_CONTROL),1) -USB_HID_DEVICES += SYS_CONTROL -endif -ifeq ($(CIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD),1) -USB_HID_DEVICES += XAC_COMPATIBLE_GAMEPAD -endif - -# RAW is not compatible with other HID devices. -ifeq ($(CIRCUITPY_USB_HID_RAW),1) - ifneq ($(CIRCUITPY_USB_HID_DEVICES,) - $(error HID RAW must not be combined with other HID devices) -endif -USB_HID_DEVICES += MOUSE endif USB_HIGHSPEED ?= 0 @@ -221,7 +173,7 @@ USB_DESCRIPTOR_ARGS = \ --vid $(USB_VID)\ --pid $(USB_PID)\ --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ - --interface_name $(USB_INTERFACE_NAME)\ + --interface_name_prefix $(USB_INTERFACE_NAME)\ --devices "$(USB_DEVICES)"\ --hid_devices "$(USB_HID_DEVICES)"\ --max_ep $(USB_NUM_EP) \ diff --git a/tools/usb_descriptor b/tools/usb_descriptor index 7275306928..2eaa6114b2 160000 --- a/tools/usb_descriptor +++ b/tools/usb_descriptor @@ -1 +1 @@ -Subproject commit 727530692805bb1c9d9d20d7477804a1799e358d +Subproject commit 2eaa6114b209fe7f0a795eda8d6a7b3b93d76d2e From 6b18a51d57eb035ea8c9ce93e18370625baa5182 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 20 Apr 2021 22:20:34 -0400 Subject: [PATCH 07/66] wip: working on descriptor templates --- shared-module/storage/__init__.c | 39 +++--- shared-module/storage/__init__.h | 6 +- shared-module/usb_cdc/__init__.c | 118 +++++++++++++++++ shared-module/usb_cdc/__init__.h | 2 + shared-module/usb_midi/__init__.c | 213 ++++++++++++++++++------------ shared-module/usb_midi/__init__.h | 10 +- supervisor/shared/usb/usb_desc.c | 127 ++++++++++++++---- 7 files changed, 366 insertions(+), 149 deletions(-) diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 6c8e2a738b..786b72574c 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -41,54 +41,53 @@ #include "supervisor/usb.h" #include "tusb.h" -static uint8_t[] storage_usb_msc_descriptor[] = { +static const uint8_t storage_usb_msc_descriptor_template[] = { + // MSC Interface Descriptor 0x09, // 0 bLength 0x04, // 1 bDescriptorType (Interface) 0xFF, // 2 bInterfaceNumber [SET AT RUNTIME] +#define MSC_INTERFACE_INDEX 2 0x00, // 3 bAlternateSetting 0x02, // 4 bNumEndpoints 2 0x08, // 5 bInterfaceClass: MSC 0x06, // 6 bInterfaceSubClass: TRANSPARENT 0x50, // 7 bInterfaceProtocol: BULK - 0x00, // 8 iInterface (String Index) [SET AT RUNTIME] + 0xFF, // 8 iInterface (String Index) [SET AT RUNTIME] +#define MSC_INTERFACE_STRING_INDEX 8 + // MSC Endpoint IN Descriptor 0x07, // 9 bLength 0x05, // 10 bDescriptorType (Endpoint) 0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] +#define MSC_IN_ENDPOINT_INDEX 11 0x02, // 12 bmAttributes (Bulk) 0x40, 0x00, // 13,14 wMaxPacketSize 64 0x00, // 15 bInterval 0 (unit depends on device speed) + // MSC Endpoint OUT Descriptor 0x07, // 16 bLength 0x05, // 17 bDescriptorType (Endpoint) 0xFF, // 18 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] +#define MSC_OUT_ENDPOINT_INDEX 18 0x02, // 19 bmAttributes (Bulk) - 0x40, 0x00, // 20 wMaxPacketSize 64 - 0x00, // 21 bInterval 0 (unit depends on device speed) + 0x40, 0x00, // 20,21 wMaxPacketSize 64 + 0x00, // 22 bInterval 0 (unit depends on device speed) }; -// Indices into usb_msc_descriptor for values that must be set at runtime. - -#define MSC_INTERFACE_NUMBER_INDEX 2 -#define MSC_INTERFACE_STRING_INDEX 8 -#define MSC_IN_ENDPOINT_INDEX 11 -#define MSC_OUT_ENDPOINT_INDEX 118 - // Is the MSC device enabled? bool storage_usb_enabled; -size_t storage_usb_desc_length(void) { +size_t storage_usb_descriptor_length(void) { return sizeof(usb_msc_descriptor); } -size_t storage_usb_add_desc(uint8_t *desc_buf, uint8_t interface_number, uint8_t in_endpoint_address, - uint8_t out_endpoint_address, uint8_t interface_string_index) { - memcpy(descriptor_buf, storage_usb_msc_descriptor, sizeof(storage_usb_msc_descriptor)); - desc_buf[MSC_INTERFACE_NUMBER_INDEX] = interface_number; - desc_buf[MSC_INTERFACE_STRING_INDEX] = interface_string_index; - desc_buf[MSC_IN_ENDPOINT_INDEX] = in_endpoint_address; - desc_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | out_endpoint_address; - return sizeof(usb_msc_descriptor); +size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t interface_number, uint8_t in_endpoint, uint8_t out_endpoint, uint8_t interface_string) { + memcpy(descriptor_buf, storage_usb_msc_descriptor_template, sizeof(storage_usb_msc_descriptor_template)); + descriptor_buf[MSC_INTERFACE_INDEX] = interface_number; + descriptor_buf[MSC_INTERFACE_STRING_INDEX] = interface_string; + descriptor_buf[MSC_IN_ENDPOINT_INDEX] = in_endpoint_address; + descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | out_endpoint_address; + return sizeof(storage_usb_msc_descriptor_template); } diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index e3cae1481a..2f38ed8b19 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -30,9 +30,7 @@ extern bool storage_usb_enabled; void storage_init(void); -size_t storage_usb_desc_length(void); -size_t storage_usb_add_desc(uint8_t *desc_buf, uint8_t interface_number, - uint8_t in_endpoint_address, uint8_t out_endpoint_address, - uint8_t interface_string_index); +size_t storage_usb_descriptor_length(void); +size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t interface, uint8_t in_endpoint, uint8_t out_endpoint, uint8_tt interface_string); #endif // SHARED_MODULE_STORAGE___INIT___H diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index d0930956cb..1a68148da6 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -41,6 +41,124 @@ bool usb_cdc_repl_enabled; bool usb_cdc_data_enabled; +static const uint8_t usb_cdc_descriptor_template[] = { + // CDC IAD Descriptor + 0x08, // 0 bLength + 0x0B, // 1 bDescriptorType: IAD Descriptor + 0xFF, // 2 bFirstInterface [SET AT RUNTIME] +#define CDC_FIRST_INTERFACE_INDEX 2 + 0x02, // 3 bInterfaceCount: 2 + 0x02, // 4 bFunctionClass: COMM + 0x02, // 5 bFunctionSubclass: ACM + 0x00, // 6 bFunctionProtocol: NONE + 0x00, // 7 iFunction + + // CDC Comm Interface Descriptor + 0x09, // 8 bLength + 0x04, // 9 bDescriptorType (Interface) + 0xFF, // 10 bInterfaceNumber [SET AT RUNTIME] +#define CDC_COMM_INTERFACE_INDEX 10 + 0x00, // 11 bAlternateSetting + 0x01, // 12 bNumEndpoints 1 + 0x02, // 13 bInterfaceClass: COMM + 0x02, // 14 bInterfaceSubClass: ACM + 0x00, // 15 bInterfaceProtocol: NONE + 0xFF, // 16 iInterface (String Index) +#define CDC_COMM_INTERFACE_STRING_INDEX 16 + + // CDC Header Descriptor + 0x05, // 17 bLength + 0x24, // 18 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x00, // 19 bDescriptorSubtype: NONE + 0x10, 0x01, // 20,21 bcdCDC: 1.10 + + // CDC Call Management Descriptor + 0x05, // 22 bLength + 0x24, // 23 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x01, // 24 bDescriptorSubtype: CALL MANAGEMENT + 0x01, // 25 bmCapabilities + 0xFF, // 26 bDataInterface [SET AT RUNTIME] +#define CDC_CALL_MANAGEMENT_DATA_INTERFACE_INDEX 26 + + // CDC Abstract Control Management Descriptor + 0x04, // 27 bLength + 0x24, // 28 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x02, // 29 bDescriptorSubtype: ABSTRACT CONTROL MANAGEMENT + 0x02, // 30 bmCapabilities + + // CDC Union Descriptor + 0x05, // 31 bLength + 0x24, // 32 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x06, // 33 bDescriptorSubtype: CDC + 0xFF, // 34 bMasterInterface [SET AT RUNTIME] +#define CDC_UNION_MASTER_INTERFACE_INDEX 34 + 0xFF, // 35 bSlaveInterface_list (1 item) +#define CDC_UNION_SLAVE_INTERFACE_INDEX 35 + + // CDC Control IN Endpoint Descriptor + 0x07, // 36 bLength + 0x05, // 37 bDescriptorType (Endpoint) + 0xFF, // 38 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] +#define CDC_CONTROL_IN_ENDPOINT_INDEX 38 + 0x03, // 39 bmAttributes (Interrupt) + 0x40, 0x00, // 40, 41 wMaxPacketSize 64 + 0x10, // 42 bInterval 16 (unit depends on device speed) + + // CDC Data Interface + 0x09, // 43 bLength + 0x04, // 44 bDescriptorType (Interface) + 0xFF, // 45 bInterfaceNumber [SET AT RUNTIME] +#define CDC_DATA_INTERFACE_INDEX 45 + 0x00, // 46 bAlternateSetting + 0x02, // 47 bNumEndpoints 2 + 0x0A, // 48 bInterfaceClass: DATA + 0x00, // 49 bInterfaceSubClass: NONE + 0x00, // 50 bInterfaceProtocol + 0x05, // 51 iInterface (String Index) +#define CDC_DATA_INTERFACE_STRING_INDEX 51 + + // CDC Data OUT Endpoint Descriptor + 0x07, // 52 bLength + 0x05, // 53 bDescriptorType (Endpoint) + 0xFF, // 54 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] +#define CDC_DATA_OUT_ENDPOINT_INDEX 54 + 0x02, // 55 bmAttributes (Bulk) + 0x40, 0x00, // 56,57 wMaxPacketSize 64 + 0x00, // 58 bInterval 0 (unit depends on device speed) + + // CDC Data IN Endpoint Descriptor + 0x07, // 59 bLength + 0x05, // 60 bDescriptorType (Endpoint) + 0xFF, // 61 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] +#define CDC_DATA_IN_ENDPOINT_INDEX 61 + 0x02, // 62 bmAttributes (Bulk) + 0x40, 0x00, // 63,64 wMaxPacketSize 64 + 0x00, // 65 bInterval 0 (unit depends on device speed) +}; + +size_t usb_cdc_descriptor_length(void) { + return sizeof(usb_cdc_descriptor_template); +} + +size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8 comm_interface, uint8_t data_interface, uint8_t control_in_endpoint, uint8_t data_in_endpoint, uint8_t data_out_endpoint, uint8_t comm_interface_string, uint8_t data_interface_string) { + memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); + descriptor_buf[CDC_FIRST_INTERFACE_INDEX] = comm_interface; + descriptor_buf[CDC_COMM_INTERFACE_INDEX] = comm_interface; + descriptor_buf[CDC_CALL_MANAGEMENT_DATA_INTERFACE_INDEX] = data_interface; + descriptor_buf[CDC_UNION_MASTER_INTERFACE_INDEX] = comm_interface; + descriptor_buf[CDC_UNION_SLAVE_INTERFACE_INDEX] = data_interface; + descriptor_buf[CDC_DATA_INTERFACE_INDEX] = data_interface; + + descriptor_buf[CDC_CONTROL_IN_ENDPOINT_INDEX] = control_in_endpoint; + descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = data_out_endpoint; + descriptor_buf[CDC_DATA_IN_ENDPOINT_INDEX] = data_in_endpoint; + + descriptor_buf[CDC_COMM_INTERFACE_STRING_INDEX] = comm_interface_string; + descriptor_buf[CDC_DATA_INTERFACE_STRING_INDEX] = data_interface_string; + + return sizeof(usb_midi_descriptor_template); +} + static usb_cdc_serial_obj_t usb_cdc_repl_obj = { .base.type = &usb_cdc_serial_type, .timeout = -1.0f, diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 79a2e58a92..b7d635f49f 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -33,5 +33,7 @@ extern bool usb_cdc_repl_enabled; extern bool usb_cdc_data_enabled; void usb_cdc_init(void); +size_t usb_cdc_descriptor_length(void); +size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8 comm_interface, uint8_t data_interface, uint8_t control_in_endpoint, uint8_t data_in_endpoint, uint8_t data_out_endpoint, uint8_t comm_interface_string, uint8_t data_interface_string); #endif /* SHARED_MODULE_USB_CDC___INIT___H */ diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 2869cc8b36..9f78856836 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -38,111 +38,148 @@ supervisor_allocation *usb_midi_allocation; -static uint8_t[] usb_midi_descriptor[] = { - 0x09, // 0 bLength - 0x04, // 1 bDescriptorType (Interface) - 0xFF, // 2 bInterfaceNumber [SET AT RUNTIME] - 0x00, // 3 bAlternateSetting - 0x00, // 4 bNumEndpoints 0 - 0x01, // 5 bInterfaceClass (Audio) - 0x01, // 6 bInterfaceSubClass (Audio Control) - 0x00, // 7 bInterfaceProtocol - 0x00, // 8 iInterface (String Index) [SET AT RUNTIME] +static const uint8_t usb_midi_descriptor_template[] = { + // Audio Interface Descriptor + 0x09, // 0 bLength + 0x04, // 1 bDescriptorType (Interface) + 0xFF, // 2 bInterfaceNumber [SET AT RUNTIME] +#define MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX 2 + 0x00, // 3 bAlternateSetting + 0x00, // 4 bNumEndpoints 0 + 0x01, // 5 bInterfaceClass (Audio) + 0x01, // 6 bInterfaceSubClass (Audio Control) + 0x00, // 7 bInterfaceProtocol + 0xFF, // 8 iInterface (String Index) [SET AT RUNTIME] +#define MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX 8 - 0x09, // 9 bLength - 0x24, // 10 bDescriptorType (See Next Line) - 0x01, // 11 bDescriptorSubtype (CS_INTERFACE -> HEADER) - 0x00, 0x01, // 12,13 bcdADC 1.00 - 0x09, 0x00, // 14,15 wTotalLength 9 - 0x01, // 16 binCollection 0x01 - 0xFF, // 17 baInterfaceNr [SET AT RUNTIME: one-element list: same as 20] + // Audio10 Control Interface Descriptor + 0x09, // 9 bLength + 0x24, // 10 bDescriptorType (See Next Line) + 0x01, // 11 bDescriptorSubtype (CS_INTERFACE -> HEADER) + 0x00, 0x01, // 12,13 bcdADC 1.00 + 0x09, 0x00, // 14,15 wTotalLength 9 + 0x01, // 16 binCollection 0x01 + 0xFF, // 17 baInterfaceNr [SET AT RUNTIME: one-element list: same as 20] +#define MIDI_STREAMING_INTERFACE_NUMBER_INDEX_2 17 - 0x09, // 18 bLength - 0x04, // 19 bDescriptorType (Interface) - 0xFF, // 20 bInterfaceNumber [SET AT RUNTIME] - 0x00, // 21 bAlternateSetting - 0x02, // 22 bNumEndpoints 2 - 0x01, // 23 bInterfaceClass (Audio) - 0x03, // 24 bInterfaceSubClass (MIDI Streaming) - 0x00, // 25 bInterfaceProtocol - 0x0A, // 26 iInterface (String Index) [SET AT RUNTIME] + // MIDI Streaming Interface Descriptor + 0x09, // 18 bLength + 0x04, // 19 bDescriptorType (Interface) + 0xFF, // 20 bInterfaceNumber [SET AT RUNTIME] +#define MIDI_STREAMING_INTERFACE_NUMBER_INDEX 20 + 0x00, // 21 bAlternateSetting + 0x02, // 22 bNumEndpoints 2 + 0x01, // 23 bInterfaceClass (Audio) + 0x03, // 24 bInterfaceSubClass (MIDI Streaming) + 0x00, // 25 bInterfaceProtocol + 0xFF, // 26 iInterface (String Index) [SET AT RUNTIME] +#define MIDI_STREAMING_INTERFACE_STRING_INDEX 26 - 0x07, // 27 bLength - 0x24, // 28 bDescriptorType (See Next Line) - 0x01, 0x00, 0x01, 0x25, 0x00, // 29,30,31,32,33 - 0x06, // 34 bLength - 0x24, // 35 bDescriptorType (See Next Line) - 0x02, 0x01, 0x01, 0x08, // 36,37,38,39 + // MIDI Header Descriptor + 0x07, // 27 bLength + 0x24, // 28 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x01, // 29 bDescriptorSubtype: MIDI STREAMING HEADER + 0x00, 0x01, // 30,31 bsdMSC (MIDI STREAMING) version 1.0 + 0x25, 0x00 // 32,33 wLength + + // MIDI Embedded In Jack Descriptor + 0x06, // 34 bLength + 0x24, // 35 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x02, // 36 bDescriptorSubtype: MIDI IN JACK + 0x01, // 37 bJackType: EMBEDDED + 0x01, // 38 id (always 1) + 0xFF, // 39 iJack (String Index) [SET AT RUNTIME] +#define MIDI_IN_JACK_STRING_INDEX 39 + + // MIDI External In Jack Descriptor 0x06, // 40 bLength - 0x24, // 41 bDescriptorType (See Next Line) - 0x02, 0x02, 0x02, 0x00, // 42,43,44,45 + 0x24, // 41 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x02, // 42 bDescriptorSubtype: MIDI IN JACK + 0x02, // 43 bJackType: EXTERNAL + 0x02, // 44 bJackId (always 2) + 0x00, // 45 iJack (String Index) + + // MIDI Embedded Out Jack Descriptor 0x09, // 46 bLength - 0x24, // 47 bDescriptorType (See Next Line) - 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x09, // 48,49,50,51,52,53,54 - 0x09, // 56 bLength - 0x24, // 57 bDescriptorType (See Next Line) - 0x03, 0x02, 0x04, 0x01, 0x01, 0x01, 0x00, // 58,59,60,61,62,63,64 - 0x07, // 65 bLength - 0x05, // 66 bDescriptorType (See Next Line) - 0xFF, // 67 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] - 0x02, // 68 bmAttributes (Bulk) - 0x40, 0x00, // 69,70 wMaxPacketSize 64 - 0x00, // 71 bInterval 0 (unit depends on device speed) + 0x24, // 47 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x03, // 48 bDescriptorSubtype: MIDI OUT JACK + 0x01, // 49 bJackType: EMBEDDED + 0x03, // 50 bJackID (always 3) + 0x01, // 51 bNrInputPins (always 1) + 0x02, // 52 BaSourceID(1) (always 2) + 0x01, // 53 BaSourcePin(1) (always 1) + 0xFF, // 54 iJack (String Index) [SET AT RUNTIME] +#define MIDI_OUT_JACK_STRING_INDEX 54 - 0x05, // 72 bLength - 0x25, // 73 bDescriptorType (See Next Line) - 0x01, 0x01, 0x01, // 74,75,76 - 0x07, // 77 bLength - 0x05, // 78 bDescriptorType (See Next Line) - 0xFF, // 79 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] - 0x02, // 80 bmAttributes (Bulk) - 0x40, 0x00, // 81,82 wMaxPacketSize 64 - 0x00, // 83 bInterval 0 (unit depends on device speed) + // MIDI External Out Jack Descriptor + 0x09, // 55 bLength + 0x24, // 56 bDescriptorType: CLASS SPECIFIC INTERFACE + 0x03, // 57 bDescriptorSubtype: MIDI OUT JACK + 0x02, // 58 bJackType: EXTERNAL + 0x04, // 59 bJackID (always 4) + 0x01, // 60 bNrInputPins (always 1) + 0x01, // 61 BaSourceID(1) (always 1) + 0x01, // 62 BaSourcePin(1) (always 1) + 0x00, // 63 iJack (String Index) - 0x05, // 84 bLength - 0x25, // 85 bDescriptorType (See Next Line) - 0x01, 0x01, 0x03, // 86,87,88 + // MIDI Streaming Endpoint OUT Descriptor + 0x07, // 64 bLength + 0x05, // 65 bDescriptorType (EndPoint) + 0xFF, // 66 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] +#define MIDI_STREAMING_OUT_ENDPOINT_INDEX 66 + 0x02, // 67 bmAttributes (Bulk) + 0x40, 0x00, // 68,69 wMaxPacketSize 64 + 0x00, // 70 bInterval 0 (unit depends on device speed) + + // MIDI Data Endpoint Descriptor + 0x05, // 71 bLength + 0x25, // 72 bDescriptorType: CLASS SPECIFIC ENDPOINT + 0x01, // 73 bDescriptorSubtype: MIDI STREAMING 1.0 + 0x01, // 74 bNumGrpTrmBlock (always 1) + 0x01, // 75 baAssoGrpTrmBlkID(1) (always 1) + + // MIDI IN Data Endpoint + 0x07, // 76 bLength + 0x05, // 77 bDescriptorType: Endpoint + 0xFF, // 78 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] +#define MIDI_STREAMING_IN_ENDPOINT_INDEX 78 + 0x02, // 79 bmAttributes (Bulk) + 0x40, 0x00, // 8081 wMaxPacketSize 64 + 0x00, // 82 bInterval 0 (unit depends on device speed) + + // MIDI Data Endpoint Descriptor + 0x05, // 83 bLength + 0x25, // 84 bDescriptorType: CLASS SPECIFIC ENDPOINT + 0x01, // 85 bDescriptorSubtype: MIDI STREAMING 1.0 + 0x01, // 86 bNumGrpTrmBlock (always 1) + 0x03, // 87 baAssoGrpTrmBlkID(1) (always 3) }; // Is the USB MIDI device enabled? bool usb_midi_enabled; -// Indices into usb_midi_descriptor for values that must be set at runtime. -#define MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX 2 -#define MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX 8 - -// These two get the same value. -#define MIDI_MIDI_STREAMING_INTERFACE_NUMBER_INDEX 20 -#define MIDI_MIDI_STREAMING_INTERFACE_NUMBER_XREF_INDEX 17 - -#define MIDI_MIDI_STREAMING_INTERFACE_STRING_INDEX 26 - -#define MIDI_MIDI_STREAMING_OUT_ENDPOINT_INDEX 67 -#define MIDI_MIDI_STREAMING_IN_ENDPOINT_INDEX 79 - -size_t usb_midi_desc_length(void) { - return sizeof(usb_midi_descriptor); +size_t usb_midi_descriptor_length(void) { + return sizeof(usb_midi_descriptor_template); } -size_t usb_midi_add_desc(uint8_t *desc_buf, - uint8_t audio_control_interface_number, - uint8_t midi_streaming_interface_number, - uint8_t midi_streaming_in_endpoint_address, - uint8_t midi_streaming_out_endpoint_address, - uint8_t audio_control_interface_string, - uint8_t midi_streaming_interface_string) { - memcpy(descriptor_buf, usb_midi_descriptor, sizeof(usb_midi_descriptor)); - desc_buf[MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX] = audio_control_interface_number; - desc_buf[MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX] = audio_control_interface_string; +size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, + uint8_t audio_control_interface, uint8_t midi_streaming_interface, uint8_t midi_streaming_in_endpoint, uint8_t midi_streaming_out_endpoint, uint8_t audio_control_interface_string, uint8_t midi_streaming_interface_string, uint8_t in_jack_string, uint8_t out_jack_string) { + memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); + descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX] = audio_control_interface_number; + descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX] = audio_control_interface_string; - desc_buf[MIDI_MIDI_STREAMING_INTERFACE_NUMBER_INDEX] = midi_streaming_interface_number; - desc_buf[MIDI_MIDI_STREAMING_INTERFACE_NUMBER_XREF_INDEX] = midi_streaming_interface_number; - desc_buf[MIDI_MIDI_STREAMING_INTERFACE_STRING_INDEX] = midi_streaming_interface_string; + descriptor_buf[MSC_IN_ENDPOINT_INDEX] = midi_streaming_in_endpoint; + descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | midi_streaming_out_endpoint; - desc_buf[MSC_IN_ENDPOINT_INDEX] = midi_streaming_in_endpoint_address; - desc_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | midi_streaming_out_endpoint_address; - return sizeof(usb_midi_descriptor); + descriptor_buf[MIDI_STREAMING_INTERFACE_NUMBER_INDEX] = midi_streaming_interface_number; + descriptor_buf[MIDI_STREAMING_INTERFACE_NUMBER_INDEX_2] = midi_streaming_interface_number; + descriptor_buf[MIDI_STREAMING_INTERFACE_STRING_INDEX] = midi_streaming_interface_string; + + descriptor_buf[MIDI_IN_JACK_STRING_INDEX] = in_jack_string; + descriptor_buf[MIDI_OUT_JACK_STRING_INDEX] = out_jack_string; + + return sizeof(usb_midi_descriptor_template); } diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index 75738515ba..a57308e8b7 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -31,14 +31,8 @@ extern bool usb_midi_enabled; void usb_midi_init(void); void usb_midi_usb_init(void); -size_t usb_midi_desc_length(void); -size_t usb_midi_add_desc(uint8_t *desc_buf, - uint8_t audio_control_interface_number, - uint8_t midi_streaming_interface_number, - uint8_t midi_streaming_in_endpoint_address, - uint8_t midi_streaming_out_endpoint_address, - uint8_t audio_control_interface_string, - uint8_t midi_streaming_interface_string); +size_t usb_midi_descriptor_length(void); +size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t audio_control_interface, uint8_t midi_streaming_interface, uint8_t midi_streaming_in_endpoint, uint8_t midi_streaming_out_endpoint, uint8_t audio_control_interface_string, uint8_t midi_streaming_interface_string, uint8_t in_jack_string, uint8_t out_jack_string); #endif /* SHARED_MODULE_USB_MIDI___INIT___H */ diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 1de9c0a7a9..c894c8ab40 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -46,62 +46,109 @@ #include "genhdr/autogen_usb_descriptor.h" -static uint8_t *config_desc; +static uint8_t *device_descriptor; +static uint8_t *config_descriptor; -// Invoked when received GET DEVICE DESCRIPTOR -// Application return pointer to descriptor -uint8_t const *tud_descriptor_device_cb(void) { - return usb_desc_dev; +static const uint8_t device_descriptor_template[] = { + 0x12, // 0 bLength + 0x01, // 1 bDescriptorType (Device) + 0x00, 0x02, // 2,3 bcdUSB 2.00 + 0x00, // 4 bDeviceClass (Use class information in the Interface Descriptors) + 0x00, // 5 bDeviceSubClass + 0x00, // 6 bDeviceProtocol + 0x40, // 7 bMaxPacketSize0 64 + 0x9A, 0x23, // 8,9 idVendor [SET AT RUNTIME: lo,hi] +#define DEVICE_VID_LO_INDEX 8 +#define DEVICE_VID_HI_INDEX 9 + 0x, 0xFF, // 10,11 idProduct [SET AT RUNTIME: lo,hi] +#define DEVICE PID_LO_INDEX 10 +#define DEVICE PID_HI_INDEX 11 + 0x00, 0x01, // 12,13 bcdDevice 2.00 + 0x02, // 14 iManufacturer (String Index) [SET AT RUNTIME] +#define DEVICE_MANUFACTURER_STRING_INDEX 14 + 0x03, // 15 iProduct (String Index) [SET AT RUNTIME] +#define DEVICE_PRODUCT_STRING_INDEX 15 + 0x01, // 16 iSerialNumber (String Index) [SET AT RUNTIME] +#define DEVICE_SERIAL_NUMBER_STRING_INDEX 16 + 0x01, // 17 bNumConfigurations 1 +}; + +static const uint8_t configuration_descriptor_template[] = { + 0x09, // 0 bLength + 0x02, // 1 bDescriptorType (Configuration) + 0xFF, 0xFF, // 2,3 wTotalLength [SET AT RUNTIME: lo, hi] +#define CONFIG_TOTAL_LENGTH_LO_INDEX 2 +#define CONFIG_TOTAL_LENGTH_HI_INDEX 3 + 0xFF, // 4 bNumInterfaces [SET AT RUNTIME] +#define CONFIG_NUM_INTERFACES_INDEX 4 + 0x01, // 5 bConfigurationValue + 0x00, // 6 iConfiguration (String Index) + 0x80, // 7 bmAttributes + 0x32, // 8 bMaxPower 100mA +}; + +void build_usb_device_descriptor(uint16_t vid, uint16_t pid, uint8_t manufacturer_string_index, uint8_t product_string_index, uint8_t serial_number_string_index) { + + device_descriptor = m_malloc(sizeof(device_descriptor_template), false); + memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); + + device_descriptor[DEVICE_VID_LO_INDEX] = vid & 0xFF; + device_descriptor[DEVICE_VID_HI_INDEX] = vid >> 8; + device_descriptor[DEVICE_PID_LO_INDEX] = pid & 0xFF; + device_descriptor[DEVICE_PID_HI_INDEX] = pid >> 8; + device_descriptor[DEVICE_MANUFACTURER_STRING_INDEX] = manufacturer_string_index; + device_descriptor[DEVICE_PRODUCT_STRING_INDEX] = product_string_index; + device_descriptor[DEVICE_SERIAL_NUMBER_STRING_INDEX] = serial_number_string_index; } -// Invoked when received GET CONFIGURATION DESCRIPTOR -// Application return pointer to descriptor -// Descriptor contents must exist long enough for transfer to complete -uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { - (void)index; // for multiple configurations - - size_t total_descriptor_length = 0; +void build_usb_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces) { + size_t total_descriptor_length = sizeof(configuration_descriptor_template); // CDC should be first, for compatibility with Adafruit Windows 7 drivers. // In the past, the order has been CDC, MSC, MIDI, HID, so preserve // that order. #if CIRCUITPY_USB_CDC if (usb_cdc_repl_enabled) { - total_descriptor_length += usb_cdc_desc_length(); + total_descriptor_length += usb_cdc_descriptor_length(); } if (usb_cdc_data_enabled) { - total_descriptor_length += usb_cdc_desc_length(); + total_descriptor_length += usb_cdc_descriptor_length(); } #endif #if CIRCUITPY_USB_MSC if (storage_usb_enabled) { - total_descriptor_length += storage_usb_desc_length(); + total_descriptor_length += storage_usb_descriptor_length(); } #endif #if CIRCUITPY_USB_MIDI if (usb_midi_enabled) { - total_descriptor_length += usb_midi_desc_length(); + total_descriptor_length += usb_midi_descriptor_length(); } #endif #if CIRCUITPY_USB_HID if (usb_hid_enabled) { - total_descriptor_length += usb_hid_desc_length(); + total_descriptor_length += usb_hid_descriptor_length(); } #endif // Now we now how big the configuration descriptor will be. - config_desc = m_malloc(total_descriptor_length, false); + configuration_descriptor = m_malloc(total_descriptor_length, false); + + // Copy the top-level template, and fix up its length. + memcpy(config_descriptor, configuration_descriptor_template, sizeof(configuration_descriptor_template)); + configuration_descriptor[CONFIG_TOTAL_LENGTH_LO_INDEX] = total_descriptor_length & 0xFF; + configuration_descriptor[CONFIG_TOTAL_LENGTH_HI_INDEX] = (total_descriptor_length >> 8) & 0xFF; // Number interfaces and endpoints. - // Endpoint 0 is already used for USB control + // Endpoint 0 is already used for USB control. uint8_t current_interface = 0; uint8_t current_endpoint = 1; uint16_t current_interface_string = 1; - uint8_t *desc_buf_remaining = config_desc; + uint8_t *descriptor_buf_remaining = configuration_descriptor + sizeof(configuration_descriptor_template); #if CIRCUITPY_USB_CDC if (usb_cdc_repl_enabled) { @@ -115,8 +162,8 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { #if CIRCUITPY_USB_MSC if (storage_usb_enabled) { // Concatenate and fix up the MSC descriptor. - desc_buf_remaining += storage_usb_add_desc( - desc_buf_remaining, current_interface, + descriptor_buf_remaining += storage_usb_add_descriptor( + descriptor_buf_remaining, current_interface, current_endpoint, // in current_endpoint, // out current_interface_string_index); @@ -129,18 +176,20 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { #if CIRCUITPY_USB_MIDI if (usb_midi_enabled) { // Concatenate and fix up the MIDI descriptor. - desc_buf_remaining += usb_midi_add_desc( - desc_buf_remaining, + descriptor_buf_remaining += usb_midi_add_descriptor( + descriptor_buf_remaining, current_interface, // audio control current_interface + 1, // MIDI streaming current_endpoint, // in current_endpoint, // out current_interface_string, // audio control current_interface_string + 1 // MIDI streaming + current_interface_string + 2 // in jack + current_interface_string + 3 // out jack ); - current_interface += 2; - current_endpoint++; - current_interface_string += 2; + current_interface += 2; // two interfaces: audio control and MIDI streaming + current_endpoint++; // MIDI streaming only (no audio data) + current_interface_string += 4; // two interface names: audio control and MIDI streaming } #endif @@ -151,7 +200,27 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { } #endif + // Now we know how many interfaces have been used. + configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface - 1; + // Did we run out of endpoints? + if (current_endpoint - 1 > USB_NUM_EP) { + mp_raise_SystemError("Not enough USB endpoints"); + } + +} + +// Invoked when received GET DEVICE DESCRIPTOR +// Application return pointer to descriptor +uint8_t const *tud_descriptor_device_cb(void) { + return usb_descriptor_dev; +} + +// Invoked when received GET CONFIGURATION DESCRIPTOR +// Application return pointer to descriptor +// Descriptor contents must exist long enough for transfer to complete +uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { + (void)index; // for multiple configurations return config_desc; } @@ -168,6 +237,6 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { // Invoked when received GET STRING DESCRIPTOR request // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { - uint8_t const max_index = sizeof(string_desc_arr) / sizeof(string_desc_arr[0]); - return (index < max_index) ? string_desc_arr[index] : NULL; + uint8_t const max_index = sizeof(string_descriptor_arr) / sizeof(string_descriptor_arr[0]); + return (index < max_index) ? string_descriptor_arr[index] : NULL; } From 64e095891635dfd5c1b797b6dc2cc485bc25e480 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 21 Apr 2021 23:25:36 -0400 Subject: [PATCH 08/66] wip: descriptor building --- .../common-hal/microcontroller/Processor.c | 2 +- ports/atmel-samd/mpconfigport.mk | 2 - ports/cxd56/mpconfigport.mk | 1 - ports/esp32s2/mpconfigport.mk | 3 - ports/litex/mpconfigport.mk | 3 - ports/mimxrt10xx/mpconfigport.mk | 1 - ports/nrf/mpconfigport.mk | 2 - ports/raspberrypi/mpconfigport.mk | 2 - ports/stm/mpconfigport.mk | 1 - shared-module/storage/__init__.c | 21 +++- shared-module/storage/__init__.h | 2 +- shared-module/usb_cdc/__init__.c | 51 ++++++-- shared-module/usb_cdc/__init__.h | 2 +- shared-module/usb_hid/__init__.c | 49 +++++++- shared-module/usb_midi/__init__.c | 42 +++++-- shared-module/usb_midi/__init__.h | 2 +- supervisor/shared/usb/usb.c | 28 +---- supervisor/shared/usb/usb_desc.c | 118 ++++++++++++------ supervisor/supervisor.mk | 54 ++------ supervisor/usb.h | 5 + 20 files changed, 239 insertions(+), 152 deletions(-) diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index 8c288a352e..44517f00c5 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -346,7 +346,7 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { for (int i=0; i<4; i++) { for (int k=0; k<4; k++) { - raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff; + raw_id[4 * i + (3 -k)] = (*(id_addresses[i]) >> k * 8) & 0xff; } } } diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 7be9e203a8..559db97ca3 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -20,8 +20,6 @@ endif INTERNAL_LIBM = 1 -USB_SERIAL_NUMBER_LENGTH = 32 - # Number of USB endpoint pairs. USB_NUM_EP = 8 diff --git a/ports/cxd56/mpconfigport.mk b/ports/cxd56/mpconfigport.mk index e767c6326f..a010f16778 100644 --- a/ports/cxd56/mpconfigport.mk +++ b/ports/cxd56/mpconfigport.mk @@ -1,4 +1,3 @@ -USB_SERIAL_NUMBER_LENGTH = 10 USB_HIGHSPEED = 1 USB_RENUMBER_ENDPOINTS = 0 USB_CDC_EP_NUM_NOTIFICATION = 3 diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index 5073d8812d..2671c30558 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -6,9 +6,6 @@ MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz # Internal math library is substantially smaller than toolchain one INTERNAL_LIBM = 1 -# Chip supplied serial number, in bytes -USB_SERIAL_NUMBER_LENGTH = 12 - # Longints can be implemented as mpz, as longlong, or not LONGINT_IMPL = MPZ diff --git a/ports/litex/mpconfigport.mk b/ports/litex/mpconfigport.mk index af6a94e64a..990b462dce 100644 --- a/ports/litex/mpconfigport.mk +++ b/ports/litex/mpconfigport.mk @@ -9,9 +9,6 @@ INTERNAL_LIBM = 1 # Number of USB endpoint pairs. USB_NUM_EP = 16 -# Chip supplied serial number, in bytes -USB_SERIAL_NUMBER_LENGTH = 30 - # Longints can be implemented as mpz, as longlong, or not LONGINT_IMPL = MPZ diff --git a/ports/mimxrt10xx/mpconfigport.mk b/ports/mimxrt10xx/mpconfigport.mk index 89c6d8c941..36d8f7deb8 100644 --- a/ports/mimxrt10xx/mpconfigport.mk +++ b/ports/mimxrt10xx/mpconfigport.mk @@ -14,7 +14,6 @@ endif INTERNAL_LIBM = 1 -USB_SERIAL_NUMBER_LENGTH = 32 USB_HIGHSPEED = 1 # Number of USB endpoint pairs. diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index 83924ff795..2bb7cca59f 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -9,8 +9,6 @@ MPY_TOOL_LONGINT_IMPL = -mlongint-impl=mpz INTERNAL_LIBM = 1 -USB_SERIAL_NUMBER_LENGTH = 16 - # Number of USB endpoint pairs. USB_NUM_EP = 8 diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index ddbd0ec63b..b8d602e146 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -47,8 +47,6 @@ CIRCUITPY_AUDIOMIXER ?= 0 INTERNAL_LIBM = 1 -USB_SERIAL_NUMBER_LENGTH = 16 - # Number of USB endpoint pairs. USB_NUM_EP = 8 diff --git a/ports/stm/mpconfigport.mk b/ports/stm/mpconfigport.mk index a3216f2678..bfaff49274 100644 --- a/ports/stm/mpconfigport.mk +++ b/ports/stm/mpconfigport.mk @@ -1,7 +1,6 @@ MPY_TOOL_LONGINT_IMPL ?= -mlongint-impl=mpz LONGINT_IMPL ?= MPZ INTERNAL_LIBM ?= 1 -USB_SERIAL_NUMBER_LENGTH ?= 24 ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32F405xx STM32F407xx)) CIRCUITPY_CANIO = 1 diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 786b72574c..368e30ac6d 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -58,7 +58,7 @@ static const uint8_t storage_usb_msc_descriptor_template[] = { // MSC Endpoint IN Descriptor 0x07, // 9 bLength 0x05, // 10 bDescriptorType (Endpoint) - 0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] + 0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | number] #define MSC_IN_ENDPOINT_INDEX 11 0x02, // 12 bmAttributes (Bulk) 0x40, 0x00, // 13,14 wMaxPacketSize 64 @@ -81,12 +81,21 @@ size_t storage_usb_descriptor_length(void) { return sizeof(usb_msc_descriptor); } -size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t interface_number, uint8_t in_endpoint, uint8_t out_endpoint, uint8_t interface_string) { +static const char[] storage_interface_name = USB_INTERFACE_NAME " Mass Storage"; + +size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { memcpy(descriptor_buf, storage_usb_msc_descriptor_template, sizeof(storage_usb_msc_descriptor_template)); - descriptor_buf[MSC_INTERFACE_INDEX] = interface_number; - descriptor_buf[MSC_INTERFACE_STRING_INDEX] = interface_string; - descriptor_buf[MSC_IN_ENDPOINT_INDEX] = in_endpoint_address; - descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | out_endpoint_address; + descriptor_buf[MSC_INTERFACE_INDEX] = *current_interface; + (*current_interface)++; + + descriptor_buf[MSC_IN_ENDPOINT_INDEX] = USB_MSC_EP_NUM_IN ? USB_MSC_EP_NUM_IN : *current_endpoint; + descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | (USB_MSC_EP_NUM_OUT ? USB_MSC_EP_NUM_OUT : *current_endpoint); + (*current_endpoint)++: + + usb_add_interface_string(*current_interface_string,); + descriptor_buf[MSC_INTERFACE_STRING_INDEX] = *current_interface_string; + (*current_interface_string)++; + return sizeof(storage_usb_msc_descriptor_template); } diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index 2f38ed8b19..58ece345d1 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -31,6 +31,6 @@ extern bool storage_usb_enabled; void storage_init(void); size_t storage_usb_descriptor_length(void); -size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t interface, uint8_t in_endpoint, uint8_t out_endpoint, uint8_tt interface_string); +size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string); #endif // SHARED_MODULE_STORAGE___INIT___H diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 1a68148da6..307f0a8e68 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -140,21 +140,48 @@ size_t usb_cdc_descriptor_length(void) { return sizeof(usb_cdc_descriptor_template); } -size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8 comm_interface, uint8_t data_interface, uint8_t control_in_endpoint, uint8_t data_in_endpoint, uint8_t data_out_endpoint, uint8_t comm_interface_string, uint8_t data_interface_string) { +static const char[] repl_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC control"; +static const char[] data_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC2 control"; +static const char[] repl_cdc_data_interface_name = USB_INTERFACE_NAME " CDC data"; +static const char[] data_cdc_data_interface_name = USB_INTERFACE_NAME " CDC2 data"; + +size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl) { memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); - descriptor_buf[CDC_FIRST_INTERFACE_INDEX] = comm_interface; - descriptor_buf[CDC_COMM_INTERFACE_INDEX] = comm_interface; - descriptor_buf[CDC_CALL_MANAGEMENT_DATA_INTERFACE_INDEX] = data_interface; - descriptor_buf[CDC_UNION_MASTER_INTERFACE_INDEX] = comm_interface; - descriptor_buf[CDC_UNION_SLAVE_INTERFACE_INDEX] = data_interface; - descriptor_buf[CDC_DATA_INTERFACE_INDEX] = data_interface; - descriptor_buf[CDC_CONTROL_IN_ENDPOINT_INDEX] = control_in_endpoint; - descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = data_out_endpoint; - descriptor_buf[CDC_DATA_IN_ENDPOINT_INDEX] = data_in_endpoint; + // Store comm interface number. + descriptor_buf[CDC_FIRST_INTERFACE_INDEX] = *current_interface; + descriptor_buf[CDC_COMM_INTERFACE_INDEX] = *current_interface; + descriptor_buf[CDC_UNION_MASTER_INTERFACE_INDEX] = *current_interface; + (*current_interface)++; - descriptor_buf[CDC_COMM_INTERFACE_STRING_INDEX] = comm_interface_string; - descriptor_buf[CDC_DATA_INTERFACE_STRING_INDEX] = data_interface_string; + // Now store data interface number. + descriptor_buf[CDC_CALL_MANAGEMENT_DATA_INTERFACE_INDEX] = *current_interface; + descriptor_buf[CDC_UNION_SLAVE_INTERFACE_INDEX] = *current_interface; + descriptor_buf[CDC_DATA_INTERFACE_INDEX] = *current_interface; + + descriptor_buf[CDC_CONTROL_IN_ENDPOINT_INDEX] = repl + ? (USB_CDC_EP_NUM_NOTIFICATION ? USB_CDC_EP_NUM_NOTIFICATION : *current_endpoint) + : (USB_CDC2_EP_NUM_NOTIFICATION ? USB_CDC2_EP_NUM_NOTIFICATION : *current_endpoint); + (*current_endpoint)++; + + descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = repl + ? (USB_CDC_EP_NUM_DATA_OUT ? USB_CDC_EP_NUM_DATA_OUT : *current_endpoint) + : (USB_CDC2_EP_NUM_DATA_OUT ? USB_CDC2_EP_NUM_DATA_OUT : *current_endpoint); + + descriptor_buf[CDC_DATA_IN_ENDPOINT_INDEX] = repl + ? (USB_CDC_EP_NUM_DATA_IN ? USB_CDC_EP_NUM_DATA_IN : *current_endpoint) + : (USB_CDC2_EP_NUM_DATA_IN ? USB_CDC2_EP_NUM_DATA_IN : *current_endpoint); + (*current_endpoint)++; + + usb_add_interface_string(*current_interface_string, + repl ? repl_cdc_comm_interface_name : data_cdc_comm_interface_name); + descriptor_buf[CDC_COMM_INTERFACE_STRING_INDEX] = *current_interface_string; + (*current_interface_string)++; + + usb_add_interface_string(*current_interface_string, + repl ? repl_cdc_data_interface_name : data_cdc_data_interface_name); + descriptor_buf[CDC_DATA_INTERFACE_STRING_INDEX] = *current_interface_string; + (*current_interface_string)++; return sizeof(usb_midi_descriptor_template); } diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index b7d635f49f..973569530f 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -34,6 +34,6 @@ extern bool usb_cdc_data_enabled; void usb_cdc_init(void); size_t usb_cdc_descriptor_length(void); -size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8 comm_interface, uint8_t data_interface, uint8_t control_in_endpoint, uint8_t data_in_endpoint, uint8_t data_out_endpoint, uint8_t comm_interface_string, uint8_t data_interface_string); +size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl); #endif /* SHARED_MODULE_USB_CDC___INIT___H */ diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index d88f9787ac..5403b7fcef 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -24,4 +24,51 @@ * THE SOFTWARE. */ -// Nothing needed here. Tables of HID devices are generated in autogen_usb_descriptor.c at compile-time. +static const uint8_t usb_hid_descriptor_template[] = { + 0x09, // 0 bLength + 0x21, // 1 bDescriptorType (HID) + 0x11, 0x01, // 2 bcdHID 1.11 + 0x00, // 3 bCountryCode + 0x01, // 4 bNumDescriptors + 0x22, // 5 bDescriptorType[0] (HID) + 0xFF, 0xFF, // 6,7 wDescriptorLength[0] [SET AT RUNTIME: lo, hi] +#define HID_DESCRIPTOR_LENGTH_INDEX 6 + + 0x07, // 8 bLength + 0x05, // 9 bDescriptorType (Endpoint) + 0xFF, // 10 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | endpoint] +#define HID_IN_ENDPOINT_INDEX 10 + 0x03, // 11 bmAttributes (Interrupt) + 0x40, 0x00, // 12,13 wMaxPacketSize 64 + 0x08, // 14 bInterval 8 (unit depends on device speed) + + 0x07, // 15 bLength + 0x05, // 16 bDescriptorType (Endpoint) + 0xFF, // 17 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] +#define HID_OUT_ENDPOINT_INDEX 17 + 0x03, // 18 bmAttributes (Interrupt) + 0x40, 0x00, // 19,20 wMaxPacketSize 64 + 0x08, // 21 bInterval 8 (unit depends on device speed) +}; + +// Is the HID device enabled? +bool usb_hid_enabled; + +size_t usb_hid_descriptor_length(void) { + return sizeof(usb_hid_descriptor); +} + +static const char[] usb_hid_interface_name = USB_INTERFACE_NAME " Mass Storage"; + +size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length) { + memcpy(descriptor_buf, usb_hid_descriptor_template, sizeof(usb_hid_descriptor_template)); + + descriptor_buf[HID_DESCRIPTOR_LENGTH_INDEX] = report_descriptor_length & 0xFF; + descriptor_buf[HID_DESCRIPTOR_LENGTH_INDEX + 1] = (report_descriptor_length >> 8); + + descriptor_buf[HID_IN_ENDPOINT_INDEX] = USB_HID_EP_NUM_IN ? USB_HID_EP_NUM_IN : *current_endpoint; + descriptor_buf[HID_OUT_ENDPOINT_INDEX] = 0x80 | (USB_HID_EP_NUM_OUT ? USB_HID_EP_NUM_OUT : *current_endpoint); + (*current_endpoint)++: + + return sizeof(usb_hid_descriptor_template); +} diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 9f78856836..9fa95dbe22 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -163,21 +163,41 @@ size_t usb_midi_descriptor_length(void) { return sizeof(usb_midi_descriptor_template); } -size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, - uint8_t audio_control_interface, uint8_t midi_streaming_interface, uint8_t midi_streaming_in_endpoint, uint8_t midi_streaming_out_endpoint, uint8_t audio_control_interface_string, uint8_t midi_streaming_interface_string, uint8_t in_jack_string, uint8_t out_jack_string) { +static const char[] midi_streaming_interface_name = USB_INTERFACE_NAME " MIDI"; +static const char[] midi_audio_control_interface_name = USB_INTERFACE_NAME " Audio"; +static const char[] midi_in_jack_name = USB_INTERFACE_NAME " usb_midi.ports[0]"; +static const char[] midi_out_jack_name = USB_INTERFACE_NAME " usb_midi.ports[0]"; + +size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); - descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX] = audio_control_interface_number; - descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX] = audio_control_interface_string; - descriptor_buf[MSC_IN_ENDPOINT_INDEX] = midi_streaming_in_endpoint; - descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | midi_streaming_out_endpoint; + descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX] = *current_interface; + (*current_interface)++; - descriptor_buf[MIDI_STREAMING_INTERFACE_NUMBER_INDEX] = midi_streaming_interface_number; - descriptor_buf[MIDI_STREAMING_INTERFACE_NUMBER_INDEX_2] = midi_streaming_interface_number; - descriptor_buf[MIDI_STREAMING_INTERFACE_STRING_INDEX] = midi_streaming_interface_string; + descriptor_buf[MSC_IN_ENDPOINT_INDEX] = USB_MIDI_EP_NUM_IN ? USB_MIDI_EP_NUM_IN : *current_endpoint; + descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = + 0x80 | (USB_MIDI_EP_NUM_OUT ? USB_MIDI_EP_NUM_OUT : *current_endpoint); + (*current_endpoint)++; - descriptor_buf[MIDI_IN_JACK_STRING_INDEX] = in_jack_string; - descriptor_buf[MIDI_OUT_JACK_STRING_INDEX] = out_jack_string; + descriptor_buf[MIDI_STREAMING_INTERFACE_NUMBER_INDEX] = *current_interface; + descriptor_buf[MIDI_STREAMING_INTERFACE_NUMBER_INDEX_2] = *current_interface; + (*current_interface)++; + + usb_add_interface_string(*current_interface, midi_streaming_interface_name); + descriptor_buf[MIDI_STREAMING_INTERFACE_STRING_INDEX] = *current_interface; + (*current_interface_string)++; + + usb_add_interface_string(*current_interface, midi_audio_control_interface_name); + descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX] = *current_interface; + (*current_interface_string)++; + + usb_add_interface_string(*current_interface, midi_in_jack_name); + descriptor_buf[MIDI_IN_JACK_STRING_INDEX] = *current_interface; + (*current_interface_string)++; + + usb_add_interface_string(*current_interface, midi_out_jack_name); + descriptor_buf[MIDI_OUT_JACK_STRING_INDEX] = *current_interface; + (*current_interface_string)++; return sizeof(usb_midi_descriptor_template); } diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index a57308e8b7..28871185cf 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -33,6 +33,6 @@ void usb_midi_init(void); void usb_midi_usb_init(void); size_t usb_midi_descriptor_length(void); -size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t audio_control_interface, uint8_t midi_streaming_interface, uint8_t midi_streaming_in_endpoint, uint8_t midi_streaming_out_endpoint, uint8_t audio_control_interface_string, uint8_t midi_streaming_interface_string, uint8_t in_jack_string, uint8_t out_jack_string); +size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string); #endif /* SHARED_MODULE_USB_MIDI___INIT___H */ diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 9d48a512bd..0605b3fc93 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -51,27 +51,6 @@ extern const tusb_desc_webusb_url_t desc_webusb_url; static bool web_serial_connected = false; #endif - - -// Serial number as hex characters. This writes directly to the USB -// descriptor. -extern uint16_t usb_serial_number[1 + COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2]; - -void load_serial_number(void) { - // create serial number based on device unique id - uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; - common_hal_mcu_processor_get_uid(raw_id); - - usb_serial_number[0] = 0x300 | sizeof(usb_serial_number); - for (int i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) { - for (int j = 0; j < 2; j++) { - uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf; - // Strings are UTF-16-LE encoded. - usb_serial_number[1 + i * 2 + j] = nibble_to_hex_upper[nibble]; - } - } -} - bool usb_enabled(void) { return tusb_inited(); } @@ -80,8 +59,13 @@ MP_WEAK void post_usb_init(void) { } void usb_init(void) { + usb_build_device_descriptor(); + usb_build_configuration_descriptor(); + usb_build_hid_descriptor(); + usb_build_string_descriptors(); + + init_usb_hardware(); - load_serial_number(); tusb_init(); diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index c894c8ab40..516c9d5e8b 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -46,9 +46,22 @@ #include "genhdr/autogen_usb_descriptor.h" +// ******* TODO PROTECT AGAINST GC. static uint8_t *device_descriptor; static uint8_t *config_descriptor; +// Table for collecting interface strings (interface names) as descriptor is built. +#define MAX_INTERFACE_STRINGS 16 +// slot 0 is not used. +static char * collected_interface_strings[]; +static uint16_t current_interface_string; + +static const char[] manufacturer_name = USB_MANUFACTURER; +static const char[] product_name = USB_PRODUCT; + +// Serial number string is UID length * 2 (2 nibbles per byte) + 1 byte for null termination. +static char serial_number_hex_string[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2 + 1]; + static const uint8_t device_descriptor_template[] = { 0x12, // 0 bLength 0x01, // 1 bDescriptorType (Device) @@ -87,8 +100,27 @@ static const uint8_t configuration_descriptor_template[] = { 0x32, // 8 bMaxPower 100mA }; -void build_usb_device_descriptor(uint16_t vid, uint16_t pid, uint8_t manufacturer_string_index, uint8_t product_string_index, uint8_t serial_number_string_index) { +void usb_desc_init(void) { + uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; + common_hal_mcu_processor_get_uid(raw_id); + for (int i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) { + for (int j = 0; j < 2; j++) { + uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf; + serial_number_hex_string[i * 2 + (1 - j)] = nibble_to_hex_upper[nibble]; + } + } + + // Null-terminate the string. + serial_number_hex_string[sizeof(serial_number_hex_string)] = '\0'; + + // Set to zero when allocated; we depend on that. + collected_interface_strings = m_malloc(MAX_INTERFACE_STRINGS + 1, false); + current_interface_string = 1; +} + + +void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string) { device_descriptor = m_malloc(sizeof(device_descriptor_template), false); memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); @@ -96,12 +128,21 @@ void build_usb_device_descriptor(uint16_t vid, uint16_t pid, uint8_t manufacture device_descriptor[DEVICE_VID_HI_INDEX] = vid >> 8; device_descriptor[DEVICE_PID_LO_INDEX] = pid & 0xFF; device_descriptor[DEVICE_PID_HI_INDEX] = pid >> 8; - device_descriptor[DEVICE_MANUFACTURER_STRING_INDEX] = manufacturer_string_index; - device_descriptor[DEVICE_PRODUCT_STRING_INDEX] = product_string_index; - device_descriptor[DEVICE_SERIAL_NUMBER_STRING_INDEX] = serial_number_string_index; + + usb_add_interface_string(*current_interface_string, manufacturer_name); + device_descriptor[DEVICE_MANUFACTURER_STRING_INDEX] = *current_interface_string; + (*current_interface_string)++; + + usb_add_interface_string(*current_interface_string, product_name); + device_descriptor[DEVICE_PRODUCT_STRING_INDEX] = *current_interface_string; + (*current_interface_string)++; + + usb_add_interface_string(*current_interface_string, serial_number_hex_string); + device_descriptor[DEVICE_SERIAL_NUMBER_STRING_INDEX] = *current_interface_string; + (*current_interface_string)++; } -void build_usb_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces) { +void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces) { size_t total_descriptor_length = sizeof(configuration_descriptor_template); // CDC should be first, for compatibility with Adafruit Windows 7 drivers. @@ -143,19 +184,22 @@ void build_usb_configuration_descriptor(uint16_t total_length, uint8_t num_inter configuration_descriptor[CONFIG_TOTAL_LENGTH_HI_INDEX] = (total_descriptor_length >> 8) & 0xFF; // Number interfaces and endpoints. - // Endpoint 0 is already used for USB control. + // Endpoint 0 is already used for USB control, so start with 1. uint8_t current_interface = 0; uint8_t current_endpoint = 1; - uint16_t current_interface_string = 1; uint8_t *descriptor_buf_remaining = configuration_descriptor + sizeof(configuration_descriptor_template); #if CIRCUITPY_USB_CDC if (usb_cdc_repl_enabled) { // Concatenate and fix up the CDC REPL descriptor. + descriptor_buf_remaining += usb_cdc_add_descriptor( + descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string, true); } if (usb_cdc_data_enabled) { // Concatenate and fix up the CDC data descriptor. + descriptor_buf_remaining += usb_cdc_add_descriptor( + descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string, false); } #endif @@ -163,13 +207,7 @@ void build_usb_configuration_descriptor(uint16_t total_length, uint8_t num_inter if (storage_usb_enabled) { // Concatenate and fix up the MSC descriptor. descriptor_buf_remaining += storage_usb_add_descriptor( - descriptor_buf_remaining, current_interface, - current_endpoint, // in - current_endpoint, // out - current_interface_string_index); - current_interface++; - current_endpoint++; - current_interface_string++; + descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string); } #endif @@ -177,26 +215,14 @@ void build_usb_configuration_descriptor(uint16_t total_length, uint8_t num_inter if (usb_midi_enabled) { // Concatenate and fix up the MIDI descriptor. descriptor_buf_remaining += usb_midi_add_descriptor( - descriptor_buf_remaining, - current_interface, // audio control - current_interface + 1, // MIDI streaming - current_endpoint, // in - current_endpoint, // out - current_interface_string, // audio control - current_interface_string + 1 // MIDI streaming - current_interface_string + 2 // in jack - current_interface_string + 3 // out jack - ); - current_interface += 2; // two interfaces: audio control and MIDI streaming - current_endpoint++; // MIDI streaming only (no audio data) - current_interface_string += 4; // two interface names: audio control and MIDI streaming - + descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string); } #endif #if CIRCUITPY_USB_HID if (usb_hid_enabled) { - // Concatenate and fix up the HID descriptor (not the report descriptors). + descriptor_buf_remaining += usb_hid_add_descriptor( + descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string); } #endif @@ -210,13 +236,33 @@ void build_usb_configuration_descriptor(uint16_t total_length, uint8_t num_inter } -// Invoked when received GET DEVICE DESCRIPTOR +void usb_add_interface_string(uint8_t interface_string_index, const char[] str) { + if (interface_string_index > MAX_INTERFACE_STRINGS) { + mp_raise_SystemError("Too many USB interface names"); + } + // 2 bytes for String Descriptor header, then 2 bytes for each character + const size_t str_len = strlen(str); + uint8_t descriptor_size = 2 + (str_len * 2); + uint16_t *string_descriptor = (uint16_t *) m_malloc(descriptor_size, false); + string_descriptor[0] = 0x0300 | descriptor_size; + // Convert to le16 + for (i = 0; i <= str_len; i++) { + string_descriptor[i + 1] = str[i]; + } + + collected_interface_strings[interface_string_index] = string_descriptor; +} + + +void usb_ + +// Invoked when GET DEVICE DESCRIPTOR is received. // Application return pointer to descriptor uint8_t const *tud_descriptor_device_cb(void) { return usb_descriptor_dev; } -// Invoked when received GET CONFIGURATION DESCRIPTOR +// Invoked when GET CONFIGURATION DESCRIPTOR is received. // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { @@ -225,7 +271,7 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { } #if CIRCUITPY_USB_HID -// Invoked when received GET HID REPORT DESCRIPTOR +// Invoked when GET HID REPORT DESCRIPTOR is received. // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { @@ -234,9 +280,11 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { } #endif -// Invoked when received GET STRING DESCRIPTOR request +// Invoked when GET STRING DESCRIPTOR request is received. // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { - uint8_t const max_index = sizeof(string_descriptor_arr) / sizeof(string_descriptor_arr[0]); - return (index < max_index) ? string_descriptor_arr[index] : NULL; + if (index > MAX_INTERFACE_STRINGS) { + return NULL; + } + return collected_interface_strings[index]; } diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 7fab262f64..1210896c7f 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -76,7 +76,6 @@ else supervisor/usb.c \ supervisor/shared/usb/usb_desc.c \ supervisor/shared/usb/usb.c \ - $(BUILD)/autogen_usb_descriptor.c \ ifeq ($(CIRCUITPY_USB_CDC), 1) SRC_SUPERVISOR += \ @@ -159,61 +158,24 @@ USB_HIGHSPEED ?= 0 USB_CDC_EP_NUM_NOTIFICATION ?= 0 USB_CDC_EP_NUM_DATA_OUT ?= 0 USB_CDC_EP_NUM_DATA_IN ?= 0 + +USB_CDC2_EP_NUM_NOTIFICATION ?= 0 +USB_CDC2_EP_NUM_DATA_OUT ?= 0 +USB_CDC2_EP_NUM_DATA_IN ?= 0 + USB_MSC_EP_NUM_OUT ?= 0 USB_MSC_EP_NUM_IN ?= 0 + USB_HID_EP_NUM_OUT ?= 0 USB_HID_EP_NUM_IN ?= 0 + USB_MIDI_EP_NUM_OUT ?= 0 USB_MIDI_EP_NUM_IN ?= 0 + USB_NUM_EP ?= 0 -USB_DESCRIPTOR_ARGS = \ - --manufacturer $(USB_MANUFACTURER)\ - --product $(USB_PRODUCT)\ - --vid $(USB_VID)\ - --pid $(USB_PID)\ - --serial_number_length $(USB_SERIAL_NUMBER_LENGTH)\ - --interface_name_prefix $(USB_INTERFACE_NAME)\ - --devices "$(USB_DEVICES)"\ - --hid_devices "$(USB_HID_DEVICES)"\ - --max_ep $(USB_NUM_EP) \ - --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 ($(CIRCUITPY_USB_VENDOR), 1) -USB_DESCRIPTOR_ARGS += \ - --vendor_ep_num_out 0 --vendor_ep_num_in 0 \ - --webusb_url $(USB_WEBUSB_URL) -endif - -ifeq ($(USB_RENUMBER_ENDPOINTS), 0) -USB_DESCRIPTOR_ARGS += --no-renumber_endpoints -endif - -ifeq ($(USB_HIGHSPEED), 1) -USB_DESCRIPTOR_ARGS += --highspeed -endif - $(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h -$(BUILD)/autogen_usb_descriptor.c $(BUILD)/genhdr/autogen_usb_descriptor.h: autogen_usb_descriptor.intermediate - -.INTERMEDIATE: autogen_usb_descriptor.intermediate - -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 $(USB_DESCRIPTOR_ARGS) - CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf" $(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD) diff --git a/supervisor/usb.h b/supervisor/usb.h index f8fd713715..c8a699065d 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -53,6 +53,11 @@ bool usb_enabled(void); void usb_init(void); void usb_disconnect(void); +void usb_add_interface_string(uint8_t interface_string_index, const char[] str); +void usb_desc_init(void); +void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string); +void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces); + // Propagate plug/unplug events to the MSC logic. #if CIRCUITPY_USB_MSC void usb_msc_mount(void); From bfc5eb1660ceb8ab55a361e199947d9ce126ddf8 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 22 Apr 2021 22:21:50 -0500 Subject: [PATCH 09/66] event_handler, init, and reset --- ports/esp32s2/common-hal/wifi/__init__.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index 3ec4ebc24d..71cebda9b4 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -50,11 +50,23 @@ static void event_handler(void *arg, esp_event_base_t event_base, ESP_LOGW(TAG, "scan"); xEventGroupSetBits(radio->event_group_handle, WIFI_SCAN_DONE_BIT); break; + case WIFI_EVENT_AP_START: + ESP_LOGW(TAG, "ap start"); + break; + case WIFI_EVENT_AP_STOP: + ESP_LOGW(TAG, "ap stop"); + break; + case WIFI_EVENT_AP_STACONNECTED: + ESP_LOGW(TAG, "ap sta connected"); + break; + case WIFI_EVENT_AP_STADISCONNECTED: + ESP_LOGW(TAG, "ap sta disconnected"); + break; case WIFI_EVENT_STA_START: - ESP_LOGW(TAG, "start"); + ESP_LOGW(TAG, "sta start"); break; case WIFI_EVENT_STA_STOP: - ESP_LOGW(TAG, "stop"); + ESP_LOGW(TAG, "sta stop"); break; case WIFI_EVENT_STA_CONNECTED: ESP_LOGW(TAG, "connected"); @@ -109,6 +121,7 @@ void common_hal_wifi_init(void) { wifi_radio_obj_t *self = &common_hal_wifi_radio_obj; self->netif = esp_netif_create_default_wifi_sta(); + self->ap_netif = esp_netif_create_default_wifi_ap(); self->started = false; // Even though we just called esp_netif_create_default_wifi_sta, @@ -155,6 +168,8 @@ void wifi_reset(void) { ESP_ERROR_CHECK(esp_wifi_deinit()); esp_netif_destroy(radio->netif); radio->netif = NULL; + esp_netif_destroy(radio->ap_netif); + radio->ap_netif = NULL; } void ipaddress_ipaddress_to_esp_idf(mp_obj_t ip_address, ip_addr_t *esp_ip_address) { From 7e95dc1261126b45dfa314637bb04908490c248c Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 22 Apr 2021 22:23:33 -0500 Subject: [PATCH 10/66] ap additions to radio object --- ports/esp32s2/common-hal/wifi/Radio.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/esp32s2/common-hal/wifi/Radio.h b/ports/esp32s2/common-hal/wifi/Radio.h index 1dac47016b..17ce3e4dca 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.h +++ b/ports/esp32s2/common-hal/wifi/Radio.h @@ -57,6 +57,9 @@ typedef struct { uint8_t retries_left; uint8_t starting_retries; uint8_t last_disconnect_reason; + + wifi_config_t ap_config; + esp_netif_t *ap_netif; } wifi_radio_obj_t; extern void common_hal_wifi_radio_gc_collect(wifi_radio_obj_t *self); From 3d60ed132228154fd0d8529afd765950a90dc2ba Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 22 Apr 2021 22:55:32 -0500 Subject: [PATCH 11/66] loc & common_hal start_ap(), + AP MAC getter --- ports/esp32s2/common-hal/wifi/Radio.c | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 9c8ccaf7f2..2082ad1383 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -57,6 +57,15 @@ static void start_station(wifi_radio_obj_t *self) { self->sta_mode = 1; } +static void start_ap(wifi_radio_obj_t *self) { + if (self->ap_mode) { + return; + } + esp_wifi_set_mode(WIFI_MODE_APSTA); + + self->ap_mode = 1; +} + bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) { return self->started; } @@ -85,6 +94,12 @@ mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self) { return mp_obj_new_bytes(mac, MAC_ADDRESS_LENGTH); } +mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) { + uint8_t mac[MAC_ADDRESS_LENGTH]; + esp_wifi_get_mac(ESP_IF_WIFI_AP, mac); + return mp_obj_new_bytes(mac, MAC_ADDRESS_LENGTH); +} + mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) { if (self->current_scan != NULL) { mp_raise_RuntimeError(translate("Already scanning for wifi networks")); @@ -127,6 +142,25 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host esp_netif_set_hostname(self->netif, hostname); } +void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len) { + if (!common_hal_wifi_radio_get_enabled(self)) { + mp_raise_RuntimeError(translate("wifi is not enabled")); + } + + start_ap(self); + + wifi_config_t *config = &self->ap_config; + memcpy(&config->ap.ssid, ssid, ssid_len); + config->ap.ssid[ssid_len] = 0; + memcpy(&config->ap.password, password, password_len); + config->ap.password[password_len] = 0; + config->ap.authmode = WIFI_AUTH_WPA2_PSK; + esp_wifi_set_config(ESP_IF_WIFI_AP, config); + + // common_hal_wifi_radio_set_enabled(self, false); + common_hal_wifi_radio_set_enabled(self, true); +} + wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) { if (!common_hal_wifi_radio_get_enabled(self)) { mp_raise_RuntimeError(translate("wifi is not enabled")); From 3544d4e221021f01931c46bdb3111a39f6d3ce0c Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 22 Apr 2021 22:57:07 -0500 Subject: [PATCH 12/66] .start_ap() & .mac_address_ap --- shared-bindings/wifi/Radio.c | 56 +++++++++++++++++++++++++++++++++++- shared-bindings/wifi/Radio.h | 3 ++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 5c7fe14924..fe691b1684 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -74,7 +74,7 @@ const mp_obj_property_t wifi_radio_enabled_obj = { }; //| mac_address: bytes -//| """MAC address of the wifi radio. (read-only)""" +//| """MAC address of the wifi radio station. (read-only)""" //| STATIC mp_obj_t wifi_radio_get_mac_address(mp_obj_t self) { return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address(self)); @@ -90,6 +90,23 @@ const mp_obj_property_t wifi_radio_mac_address_obj = { }; +//| mac_address_ap: bytes +//| """MAC address of the wifi radio access point. (read-only)""" +//| +STATIC mp_obj_t wifi_radio_get_mac_address_ap(mp_obj_t self) { + return MP_OBJ_FROM_PTR(common_hal_wifi_radio_get_mac_address_ap(self)); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_mac_address_ap_obj, wifi_radio_get_mac_address_ap); + +const mp_obj_property_t wifi_radio_mac_address_ap_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_mac_address_ap_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + + //| def start_scanning_networks(self, *, start_channel: int = 1, stop_channel: int = 11) -> Iterable[Network]: //| """Scans for available wifi networks over the given channel range. Make sure the channels are allowed in your country.""" //| ... @@ -153,6 +170,41 @@ const mp_obj_property_t wifi_radio_hostname_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| def start_ap(self, +//| ssid: ReadableBuffer, +//| password: ReadableBuffer = b"", +//| *, +//| """Starts an Access Point with the specified ssid and password.""" +//| ... +//| +STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_ssid, ARG_password, ARG_channel, ARG_bssid, ARG_timeout }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + }; + + wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_buffer_info_t ssid; + mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ); + + mp_buffer_info_t password; + password.len = 0; + if (args[ARG_password].u_obj != MP_OBJ_NULL) { + mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ); + if (password.len > 0 && (password.len < 8 || password.len > 63)) { + mp_raise_ValueError(translate("WiFi password must be between 8 and 63 characters")); + } + } + + common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); + //| def connect(self, //| ssid: ReadableBuffer, //| password: ReadableBuffer = b"", @@ -343,12 +395,14 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_ping_obj, 1, wifi_radio_ping); STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_enabled), MP_ROM_PTR(&wifi_radio_enabled_obj) }, { MP_ROM_QSTR(MP_QSTR_mac_address), MP_ROM_PTR(&wifi_radio_mac_address_obj) }, + { MP_ROM_QSTR(MP_QSTR_mac_address_ap), MP_ROM_PTR(&wifi_radio_mac_address_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_start_scanning_networks), MP_ROM_PTR(&wifi_radio_start_scanning_networks_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_scanning_networks), MP_ROM_PTR(&wifi_radio_stop_scanning_networks_obj) }, { MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&wifi_radio_hostname_obj) }, + { MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 333c82bab5..4e52e09635 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -78,10 +78,13 @@ extern mp_obj_t common_hal_wifi_radio_get_hostname(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *hostname); extern mp_obj_t common_hal_wifi_radio_get_mac_address(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len); + extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len); extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self); From 2b4c88d633eaa1f2ec1771d3547eef275d9b850c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 23 Apr 2021 00:18:05 -0400 Subject: [PATCH 13/66] wip: partial HID, still needs rework --- locale/circuitpython.pot | 23 ++++- main.c | 4 + shared-bindings/usb_hid/Device.c | 90 +++++++++++++++++- shared-bindings/usb_hid/Device.h | 1 + shared-bindings/usb_hid/__init__.c | 38 +++++++- shared-module/storage/__init__.c | 8 +- shared-module/usb_hid/Device.c | 141 ++++++++++++++++++++++++++++- shared-module/usb_hid/Device.h | 23 ++--- shared-module/usb_hid/__init__.c | 35 ++++++- shared-module/usb_hid/__init__.h | 36 ++++++++ shared-module/usb_midi/__init__.c | 20 ++-- supervisor/shared/usb/usb.c | 5 + supervisor/shared/usb/usb_desc.c | 38 +++++--- supervisor/usb.h | 2 + 14 files changed, 407 insertions(+), 57 deletions(-) create mode 100644 shared-module/usb_hid/__init__.h diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 858152b52b..b8586ff136 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -87,6 +87,14 @@ msgstr "" msgid "%q list must be a list" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be 1-255" +msgstr "" + +#: shared-bindings/usb_hid/Device.c +msgid "%q must be > 1-255" +msgstr "" + #: shared-bindings/memorymonitor/AllocationAlarm.c msgid "%q must be >= 0" msgstr "" @@ -99,6 +107,14 @@ msgstr "" msgid "%q must be >= 1" msgstr "" +#: shared-bindings/usb_hid/Device.c +msgid "%q must be None or 1-255" +msgstr "" + +#: shared-bindings/usb_hid/Device.c +msgid "%q must be None or > 1-255" +msgstr "" + #: shared-module/vectorio/Polygon.c msgid "%q must be a tuple of length 2" msgstr "" @@ -600,7 +616,8 @@ msgstr "" msgid "Can't set CCCD on local Characteristic" msgstr "" -#: shared-bindings/usb_cdc/__init__.c shared-bindings/usb_midi/__init__.c +#: shared-bindings/usb_cdc/__init__.c shared-bindings/usb_hid/__init__.c +#: shared-bindings/usb_midi/__init__.c msgid "Cannot change USB devices now" msgstr "" @@ -3470,6 +3487,10 @@ msgstr "" msgid "no such attribute" msgstr "" +#: shared-bindings/usb_hid/__init__.c +msgid "non-Device in %q" +msgstr "" + #: ports/nrf/common-hal/_bleio/Connection.c msgid "non-UUID found in service_uuids_whitelist" msgstr "" diff --git a/main.c b/main.c index 9f83bb370c..4ec6b5ccb1 100755 --- a/main.c +++ b/main.c @@ -641,6 +641,10 @@ void gc_collect(void) { background_callback_gc_collect(); + #if CIRCUITPY_USB + usb_gc_collect(); + #endif + #if CIRCUITPY_ALARM common_hal_alarm_gc_collect(); #endif diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index cd4f3dd54b..8b205934e3 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -39,10 +39,88 @@ //| mouse.send_report()""" //| -//| def __init__(self) -> None: -//| """Not currently dynamically supported.""" +//| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: Optional[int], , report_id_index: Optional[int]) -> None: +//| """Create a description of a USB HID device. To create an actual device, +//| pass a `Device` to `usb_hid.configure_usb()`. +//| +//| :param ReadableBuffer descriptor: The USB HID Report descriptor bytes. The descriptor is not +//| not verified for correctness; it is up to you to make sure it is not malformed. +//| :param int usage_page: The Usage Page value from the descriptor. Must match what is in the descriptor. +//| :param int usage: The Usage value from the descriptor. Must match what is in the descriptor. +//| :param int in_report_length: Size in bytes of the HID report sent to the host. +//| "In" is with respect to the host. +//| :param int out_report_length: Size in bytes of the HID report received from the host. +//| "Out" is with respect to the host. If no reports are expected, use ``None``. +//| :param int report_id_index: position of byte in descriptor that contains the Report ID. +//| A Report ID will be assigned when the device is created. If there is no +//| Report ID, use ``None``. //| ... //| +STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + usb_hid_device_obj_t *self = m_new_obj(usb_hid_device_obj_t); + self->base.type = &usb_hid_device_type; + enum { ARG_descriptor, ARG_usage, ARG_usage_page, ARG_in_report_length, ARG_out_report_length, ARG_report_id_index }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_descriptor, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_usage_page, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, + { MP_QSTR_usage, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, + { MP_QSTR_in_report_length, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT } , + { MP_QSTR_out_report_length, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } }, + { MP_QSTR_report_id_index, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(descriptor, &bufinfo, MP_BUFFER_READ); + + bytearray_obj_t descriptor = mp_obj_array_t new_bytearray(bufinfo.len, bufinfo.buf); + + const mp_int_t usage_page_arg = args[ARG_usage_page].u_int; + if (usage_page_arg <= 0 || usage_arg > 255) { + mp_raise_ValueError_varg(translate("%q must be 1-255"), MP_QSTR_usage_page); + } + const uint8_t usage_page = usage_page_arg; + + const mp_int_t usage_arg = args[ARG_usage].u_int; + if (usage_arg <= 0 || usage_arg > 255) { + mp_raise_ValueError_varg(translate("%q must be 1-255"), MP_QSTR_usage); + } + const uint8_t usage = usage_arg; + + const mp_int_t in_report_length_arg = args[ARG_in_report_length].u_int; + if (in_report_length_arg <= 0 || in_report_length_arg > 255) { + mp_raise_ValueError_varg(translate("%q must be > 1-255"), MP_QSTR_in_report_length); + } + const uint8_t in_report_length = in_report_length_arg; + + const mp_obj_t out_report_length_arg = args[ARG_out_report_length].u_obj; + if (out_report_length_arg == mp_const_none) { + self->out_report_length = 0; + } + else if (!MP_OBJ_IS_SMALL_INT(out_report_length_arg) || + MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) <= 0 || + MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) > 255) { + mp_raise_ValueError_varg(translate("%q must be None or > 1-255"), MP_QSTR_out_report_length); + } + uint8_t out_report_length = MP_OBJ_SMALL_INT_VALUE(out_report_length_arg); + + const mp_obj_t report_id_index_arg = args[ARG_report_id_index].u_obj; + if (report_id_index_arg == mp_const_none) { + self->report_id_index = 0; + } + else if (!MP_OBJ_IS_SMALL_INT(report_id_index_arg) || + MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) <= 0 || + MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) > 255 ) { + mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_report_id_index); + } + uint8_t report_id_index = MP_OBJ_SMALL_INT_VALUE(report_id_index_arg); + + common_hal_usb_hid_device_construct(self, descriptor, usage_page, usage, in_report_length, out_report_length, report_id_index); +} + + //| def send_report(self, buf: ReadableBuffer) -> None: //| """Send a HID report.""" //| ... @@ -116,8 +194,11 @@ const mp_obj_property_t usb_hid_device_usage_obj = { STATIC const mp_rom_map_elem_t usb_hid_device_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_send_report), MP_ROM_PTR(&usb_hid_device_send_report_obj) }, { MP_ROM_QSTR(MP_QSTR_last_received_report), MP_ROM_PTR(&usb_hid_device_last_received_report_obj) }, - { MP_ROM_QSTR(MP_QSTR_usage_page), MP_ROM_PTR(&usb_hid_device_usage_page_obj)}, - { MP_ROM_QSTR(MP_QSTR_usage), MP_ROM_PTR(&usb_hid_device_usage_obj)}, + { MP_ROM_QSTR(MP_QSTR_usage_page), MP_ROM_PTR(&usb_hid_device_usage_page_obj) }, + { MP_ROM_QSTR(MP_QSTR_usage), MP_ROM_PTR(&usb_hid_device_usage_obj) }, + { MP_ROM_QSTR(MP_QSTR_KEYBOARD), MP_ROM_PTR(&usb_hid_device_keyboard_obj) }, + { MP_ROM_QSTR(MP_QSTR_MOUSE), MP_ROM_PTR(&usb_hid_device_mouse_obj) }, + { MP_ROM_QSTR(MP_QSTR_CONSUMER_CONTROL), MP_ROM_PTR(&usb_hid_device_consumer_control_obj) }, }; STATIC MP_DEFINE_CONST_DICT(usb_hid_device_locals_dict, usb_hid_device_locals_dict_table); @@ -125,5 +206,6 @@ STATIC MP_DEFINE_CONST_DICT(usb_hid_device_locals_dict, usb_hid_device_locals_di const mp_obj_type_t usb_hid_device_type = { { &mp_type_type }, .name = MP_QSTR_Device, + .make_new = usb_hid_device_make_new, .locals_dict = (mp_obj_t)&usb_hid_device_locals_dict, }; diff --git a/shared-bindings/usb_hid/Device.h b/shared-bindings/usb_hid/Device.h index d9918d4060..c9ca3e16f0 100644 --- a/shared-bindings/usb_hid/Device.h +++ b/shared-bindings/usb_hid/Device.h @@ -31,6 +31,7 @@ extern const mp_obj_type_t usb_hid_device_type; +void common_hal_usb_hid_device_construct(usb_hid_device_obj_t *self, ***); void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *report, uint8_t len); uint8_t common_hal_usb_hid_device_get_usage_page(usb_hid_device_obj_t *self); uint8_t common_hal_usb_hid_device_get_usage(usb_hid_device_obj_t *self); diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 1a2f28d431..6558c98e64 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -39,10 +39,42 @@ //| devices: Tuple[Device, ...] //| """Tuple of all active HID device interfaces.""" //| + +//| def configure_usb(devices: Sequence[Device, ...]=) -> None: +//| """Configure the USB HID devices that will be available. +//| Can be called in ``boot.py``, before USB is connected. +//| +//| :param Sequence devices: `Device` objects. +//| If `devices` is empty, HID is disabled. The order of the ``Devices`` +//| may matter to the host. For instance, for MacOS, put the mouse device +//| before any Gamepad or Digitizer HID device. +//| ... +//| +STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { + + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(devices, &iter_buf); + mp_obj_t device; + while ((device = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { + mp_raise_ValueError_varg(translate("non-Device in %q", MP_QSTR_devices)); + } + } + + if (!common_hal_usb_hid_configure_usb(descriptors)) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + } + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_configure_usb_obj, usb_hid_configure_usb); + + STATIC const mp_rom_map_elem_t usb_hid_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, - { MP_ROM_QSTR(MP_QSTR_devices), MP_ROM_PTR(&common_hal_usb_hid_devices) }, - { MP_ROM_QSTR(MP_QSTR_Device), MP_ROM_PTR(&usb_hid_device_type) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, + { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_midi_configure_usb_obj) }, + { MP_ROM_QSTR(MP_QSTR_devices), MP_ROM_PTR(&common_hal_usb_hid_devices) }, + { MP_ROM_QSTR(MP_QSTR_Device), MP_ROM_PTR(&usb_hid_device_type) }, }; STATIC MP_DEFINE_CONST_DICT(usb_hid_module_globals, usb_hid_module_globals_table); diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 368e30ac6d..8f361cb2d1 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -46,20 +46,20 @@ static const uint8_t storage_usb_msc_descriptor_template[] = { 0x09, // 0 bLength 0x04, // 1 bDescriptorType (Interface) 0xFF, // 2 bInterfaceNumber [SET AT RUNTIME] -#define MSC_INTERFACE_INDEX 2 +#define MSC_INTERFACE_INDEX (2) 0x00, // 3 bAlternateSetting 0x02, // 4 bNumEndpoints 2 0x08, // 5 bInterfaceClass: MSC 0x06, // 6 bInterfaceSubClass: TRANSPARENT 0x50, // 7 bInterfaceProtocol: BULK 0xFF, // 8 iInterface (String Index) [SET AT RUNTIME] -#define MSC_INTERFACE_STRING_INDEX 8 +#define MSC_INTERFACE_STRING_INDEX (8) // MSC Endpoint IN Descriptor 0x07, // 9 bLength 0x05, // 10 bDescriptorType (Endpoint) 0xFF, // 11 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | number] -#define MSC_IN_ENDPOINT_INDEX 11 +#define MSC_IN_ENDPOINT_INDEX (11) 0x02, // 12 bmAttributes (Bulk) 0x40, 0x00, // 13,14 wMaxPacketSize 64 0x00, // 15 bInterval 0 (unit depends on device speed) @@ -68,7 +68,7 @@ static const uint8_t storage_usb_msc_descriptor_template[] = { 0x07, // 16 bLength 0x05, // 17 bDescriptorType (Endpoint) 0xFF, // 18 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] -#define MSC_OUT_ENDPOINT_INDEX 18 +#define MSC_OUT_ENDPOINT_INDEX (18) 0x02, // 19 bmAttributes (Bulk) 0x40, 0x00, // 20,21 wMaxPacketSize 64 0x00, // 22 bInterval 0 (unit depends on device speed) diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 4f392847ff..d87fe3dff4 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -33,6 +33,137 @@ #include "supervisor/shared/tick.h" #include "tusb.h" +static const uint8_t keyboard_descriptor[] = { + 0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls) + 0x09, 0x06, // 2,3 Usage (Keyboard) + 0xA1, 0x01, // 4,5 Collection (Application) + 0x85, 0xFF, // 6,7 Report ID [SET AT RUNTIME] +#define KEYBOARD_REPORT_ID_INDEX (7) + 0x05, 0x07, // Usage Page (Kbrd/Keypad) + 0x19, 0xE0, // Usage Minimum (0xE0) + 0x29, 0xE7, // Usage Maximum (0xE7) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x75, 0x01, // Report Size (1) + 0x95, 0x08, // Report Count (8) + 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x19, 0x00, // Usage Minimum (0x00) + 0x29, 0xDD, // Usage Maximum (0xDD) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0xDD, // Logical Maximum (-35) + 0x75, 0x08, // Report Size (8) + 0x95, 0x06, // Report Count (6) + 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x05, 0x08, // Usage Page (LEDs) + 0x19, 0x01, // Usage Minimum (Num Lock) + 0x29, 0x05, // Usage Maximum (Kana) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x75, 0x01, // Report Size (1) + 0x95, 0x05, // Report Count (5) + 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) + 0x95, 0x03, // Report Count (3) + 0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) + 0xC0, // End Collection + }, + +const usb_hid_device_obj_t usb_hid_device_keyboard_obj = { + .descriptor = keyboard_descriptor, + .descriptor_length = sizeof(keyboard_descriptor), + .usage_page = 0x01 + .usage = 0x06, + .in_report_length = 8, + .out_report_length = 1, + .report_id_index = KEYBOARD_REPORT_ID_INDEX, + +}; + +static const uint8_t mouse_descriptor[] = { + 0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls) + 0x09, 0x02, // 2,3 Usage (Mouse) + 0xA1, 0x01, // 4,5 Collection (Application) + 0x09, 0x01, // 6,7 Usage (Pointer) + 0xA1, 0x00, // 8,9 Collection (Physical) + 0x85, 0xFF, // 10, 11 Report ID [SET AT RUNTIME] +#define MOUSE_REPORT_ID_INDEX (11) + 0x05, 0x09, // Usage Page (Button) + 0x19, 0x01, // Usage Minimum (0x01) + 0x29, 0x05, // Usage Maximum (0x05) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x95, 0x05, // Report Count (5) + 0x75, 0x01, // Report Size (1) + 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x95, 0x01, // Report Count (1) + 0x75, 0x03, // Report Size (3) + 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x05, 0x01, // Usage Page (Generic Desktop Ctrls) + 0x09, 0x30, // Usage (X) + 0x09, 0x31, // Usage (Y) + 0x15, 0x81, // Logical Minimum (-127) + 0x25, 0x7F, // Logical Maximum (127) + 0x75, 0x08, // Report Size (8) + 0x95, 0x02, // Report Count (2) + 0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position) + 0x09, 0x38, // Usage (Wheel) + 0x15, 0x81, // Logical Minimum (-127) + 0x25, 0x7F, // Logical Maximum (127) + 0x75, 0x08, // Report Size (8) + 0x95, 0x01, // Report Count (1) + 0x81, 0x06, // Input (Data,Var,Rel,No Wrap,Linear,Preferred State,No Null Position) + 0xC0, // End Collection + 0xC0, // End Collection +}; + +const usb_hid_device_obj_t usb_hid_device_mouse_obj = { + .descriptor = mouse_descriptor, + .descriptor_length = sizeof(mouse_descriptor), + .usage_page = 0x01 + .usage = 0x02, + .in_report_length = 4, + .out_report_length = 0, + .descriptor = { + .report_id_index = MOUSE_REPORT_ID_INDEX, +}; + +static const uint8_t consumer_control_descriptor[] = { + 0x05, 0x0C, // 0,1 Usage Page (Consumer) + 0x09, 0x01, // 2,3 Usage (Consumer Control) + 0xA1, 0x01, // 4,5 Collection (Application) + 0x85, 0xFF, // 6,7 Report ID [SET AT RUNTIME] +#define CONSUMER_CONTROL_REPORT_ID_INDEX (7) + 0x75, 0x10, // Report Size (16) + 0x95, 0x01, // Report Count (1) + 0x15, 0x01, // Logical Minimum (1) + 0x26, 0x8C, 0x02, // Logical Maximum (652) + 0x19, 0x01, // Usage Minimum (Consumer Control) + 0x2A, 0x8C, 0x02, // Usage Maximum (AC Send) + 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0xC0, // End Collection +}; + +const usb_hid_device_obj_t usb_hid_device_consumer_control_obj = { + .descriptor = consumer_control_descriptor, + .descriptor_length = sizeof(consumer_control_descriptor), + .usage_page = 0x0C + .usage = 0x01, + .in_report_length = 2, + .out_report_length = 0, + .report_id_index = CONSUMER_CONTROL_REPORT_ID_INDEX, +}; + + +void common_hal_usb_hid_device_construct(usb_hid_dev_obj_t *self, mp_obj_array_t *descriptor, uint8_t usage_page, uint8_t usage, uint8_t in_report_length, uint8_t out_report_length, uint8_t report_id_index) { + // report buffer pointers are NULL at start, and are created on demand. + self->descriptor = descriptor; + self->usage_page = usage_page; + self->usage = usage; + self->in_report_length = in_report_length; + self->out_report_length = out_report_length; + self->report_id_index = report_id_index; +} + uint8_t common_hal_usb_hid_device_get_usage_page(usb_hid_device_obj_t *self) { return self->usage_page; } @@ -42,8 +173,8 @@ uint8_t common_hal_usb_hid_device_get_usage(usb_hid_device_obj_t *self) { } void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *report, uint8_t len) { - if (len != self->report_length) { - mp_raise_ValueError_varg(translate("Buffer incorrect size. Should be %d bytes."), self->report_length); + if (len != self->in_report_length) { + mp_raise_ValueError_varg(translate("Buffer incorrect size. Should be %d bytes."), self->in_report_length); } // Wait until interface is ready, timeout = 2 seconds @@ -56,9 +187,9 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t * mp_raise_msg(&mp_type_OSError, translate("USB Busy")); } - memcpy(self->report_buffer, report, len); + memcpy(self->in_report_buffer, report, len); - if (!tud_hid_report(self->report_id, self->report_buffer, len)) { + if (!tud_hid_report(self->in_report_id, self->in_report_buffer, len)) { mp_raise_msg(&mp_type_OSError, translate("USB Error")); } } @@ -81,7 +212,7 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t } // fill buffer with current report - memcpy(buffer, get_hid_device(report_id)->report_buffer, reqlen); + memcpy(buffer, get_hid_device(report_id)->in_report_buffer, reqlen); return reqlen; } diff --git a/shared-module/usb_hid/Device.h b/shared-module/usb_hid/Device.h index bf4e9d9adb..5b2caf369f 100644 --- a/shared-module/usb_hid/Device.h +++ b/shared-module/usb_hid/Device.h @@ -32,26 +32,21 @@ #include "py/obj.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { mp_obj_base_t base; - uint8_t *report_buffer; - uint8_t report_id; - uint8_t report_length; + uint8_t *in_report_buffer; + uint8_t *out_report_buffer; + uint8_t *descriptor; + uint16_t descriptor_length; uint8_t usage_page; uint8_t usage; - uint8_t *out_report_buffer; + uint8_t report_id; + uint8_t in_report_length; uint8_t out_report_length; } usb_hid_device_obj_t; - -extern usb_hid_device_obj_t usb_hid_devices[]; - -#ifdef __cplusplus -} -#endif +extern usb_hid_device_obj_t usb_hid_device_keyboard_obj; +extern usb_hid_device_obj_t usb_hid_device_mouse_obj; +extern usb_hid_device_mouse_obj usb_hid_device_consumer_control_obj; #endif /* SHARED_MODULE_USB_HID_DEVICE_H */ diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 5403b7fcef..f234709df6 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -32,12 +32,12 @@ static const uint8_t usb_hid_descriptor_template[] = { 0x01, // 4 bNumDescriptors 0x22, // 5 bDescriptorType[0] (HID) 0xFF, 0xFF, // 6,7 wDescriptorLength[0] [SET AT RUNTIME: lo, hi] -#define HID_DESCRIPTOR_LENGTH_INDEX 6 +#define HID_DESCRIPTOR_LENGTH_INDEX (6) 0x07, // 8 bLength 0x05, // 9 bDescriptorType (Endpoint) 0xFF, // 10 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | endpoint] -#define HID_IN_ENDPOINT_INDEX 10 +#define HID_IN_ENDPOINT_INDEX (10) 0x03, // 11 bmAttributes (Interrupt) 0x40, 0x00, // 12,13 wMaxPacketSize 64 0x08, // 14 bInterval 8 (unit depends on device speed) @@ -45,7 +45,7 @@ static const uint8_t usb_hid_descriptor_template[] = { 0x07, // 15 bLength 0x05, // 16 bDescriptorType (Endpoint) 0xFF, // 17 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] -#define HID_OUT_ENDPOINT_INDEX 17 +#define HID_OUT_ENDPOINT_INDEX (17) 0x03, // 18 bmAttributes (Interrupt) 0x40, 0x00, // 19,20 wMaxPacketSize 64 0x08, // 21 bInterval 8 (unit depends on device speed) @@ -53,6 +53,7 @@ static const uint8_t usb_hid_descriptor_template[] = { // Is the HID device enabled? bool usb_hid_enabled; +mp_obj_t usb_hid_devices; size_t usb_hid_descriptor_length(void) { return sizeof(usb_hid_descriptor); @@ -72,3 +73,31 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_hid_descriptor_template); } + +void usb_hid_build_report_descriptor() { +} + +bool common_hal_usb_hid_configure_usb(mp_obj_t devices) { + // We can't change the devices once we're connected. + if (tud_connected()) { + return false; + } + + // Assume no devices to start. + usb_hid_enabled = false; + if (devices == mp_const_none) { + return true; + } +} + +void usb_hid_build_report + +void usb_hid_gc_collect(void) { + // Once tud_mounted() is true, we're done with the constructed descriptors. + if (tud_mounted()) { + // GC will pick up the inaccessible blocks. + usb_hid_devices_to_configure = NULL; + } else { + gc_collect_ptr(usb_hid_devices); + } +} diff --git a/shared-module/usb_hid/__init__.h b/shared-module/usb_hid/__init__.h new file mode 100644 index 0000000000..6eab014459 --- /dev/null +++ b/shared-module/usb_hid/__init__.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Dan Halbert for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef SHARED_MODULE_USB_HID___INIT___H +#define SHARED_MODULE_USB_HID___INIT___H + +extern bool usb_hid_enabled; +extern usb_hid_device_obj_t usb_hid_devices[]; + +void usb_hid_gc_collect(void); + + +#endif // SHARED_MODULE_USB_HID___INIT___H diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 9fa95dbe22..d6abf7c9e5 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -43,14 +43,14 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x09, // 0 bLength 0x04, // 1 bDescriptorType (Interface) 0xFF, // 2 bInterfaceNumber [SET AT RUNTIME] -#define MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX 2 +#define MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX (2) 0x00, // 3 bAlternateSetting 0x00, // 4 bNumEndpoints 0 0x01, // 5 bInterfaceClass (Audio) 0x01, // 6 bInterfaceSubClass (Audio Control) 0x00, // 7 bInterfaceProtocol 0xFF, // 8 iInterface (String Index) [SET AT RUNTIME] -#define MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX 8 +#define MIDI_AUDIO_CONTROL_INTERFACE_STRING_INDEX (8) // Audio10 Control Interface Descriptor 0x09, // 9 bLength @@ -60,20 +60,20 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x09, 0x00, // 14,15 wTotalLength 9 0x01, // 16 binCollection 0x01 0xFF, // 17 baInterfaceNr [SET AT RUNTIME: one-element list: same as 20] -#define MIDI_STREAMING_INTERFACE_NUMBER_INDEX_2 17 +#define MIDI_STREAMING_INTERFACE_NUMBER_INDEX_2 (17) // MIDI Streaming Interface Descriptor 0x09, // 18 bLength 0x04, // 19 bDescriptorType (Interface) 0xFF, // 20 bInterfaceNumber [SET AT RUNTIME] -#define MIDI_STREAMING_INTERFACE_NUMBER_INDEX 20 +#define MIDI_STREAMING_INTERFACE_NUMBER_INDEX (20) 0x00, // 21 bAlternateSetting 0x02, // 22 bNumEndpoints 2 0x01, // 23 bInterfaceClass (Audio) 0x03, // 24 bInterfaceSubClass (MIDI Streaming) 0x00, // 25 bInterfaceProtocol 0xFF, // 26 iInterface (String Index) [SET AT RUNTIME] -#define MIDI_STREAMING_INTERFACE_STRING_INDEX 26 +#define MIDI_STREAMING_INTERFACE_STRING_INDEX (26) // MIDI Header Descriptor 0x07, // 27 bLength @@ -89,7 +89,7 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x01, // 37 bJackType: EMBEDDED 0x01, // 38 id (always 1) 0xFF, // 39 iJack (String Index) [SET AT RUNTIME] -#define MIDI_IN_JACK_STRING_INDEX 39 +#define MIDI_IN_JACK_STRING_INDEX (39) // MIDI External In Jack Descriptor 0x06, // 40 bLength @@ -109,7 +109,7 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x02, // 52 BaSourceID(1) (always 2) 0x01, // 53 BaSourcePin(1) (always 1) 0xFF, // 54 iJack (String Index) [SET AT RUNTIME] -#define MIDI_OUT_JACK_STRING_INDEX 54 +#define MIDI_OUT_JACK_STRING_INDEX (54) // MIDI External Out Jack Descriptor 0x09, // 55 bLength @@ -126,9 +126,9 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x07, // 64 bLength 0x05, // 65 bDescriptorType (EndPoint) 0xFF, // 66 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] -#define MIDI_STREAMING_OUT_ENDPOINT_INDEX 66 +#define MIDI_STREAMING_OUT_ENDPOINT_INDEX (66) 0x02, // 67 bmAttributes (Bulk) - 0x40, 0x00, // 68,69 wMaxPacketSize 64 + 0x40, 0x00, // 68,69 wMaxPacketSize (64) 0x00, // 70 bInterval 0 (unit depends on device speed) // MIDI Data Endpoint Descriptor @@ -142,7 +142,7 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x07, // 76 bLength 0x05, // 77 bDescriptorType: Endpoint 0xFF, // 78 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] -#define MIDI_STREAMING_IN_ENDPOINT_INDEX 78 +#define MIDI_STREAMING_IN_ENDPOINT_INDEX (78) 0x02, // 79 bmAttributes (Bulk) 0x40, 0x00, // 8081 wMaxPacketSize 64 0x00, // 82 bInterval 0 (unit depends on device speed) diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 0605b3fc93..5ce5083b17 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -109,6 +109,11 @@ void usb_irq_handler(void) { usb_background_schedule(); } +void usb_gc_collect(void) { + usb_desc_gc_collect(); + usb_hid_gc_collect(); +} + // --------------------------------------------------------------------+ // tinyusb callbacks // --------------------------------------------------------------------+ diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 516c9d5e8b..d77047c472 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -46,9 +46,9 @@ #include "genhdr/autogen_usb_descriptor.h" -// ******* TODO PROTECT AGAINST GC. static uint8_t *device_descriptor; static uint8_t *config_descriptor; +static uint8_t *hid_report_descriptor; // Table for collecting interface strings (interface names) as descriptor is built. #define MAX_INTERFACE_STRINGS 16 @@ -71,18 +71,18 @@ static const uint8_t device_descriptor_template[] = { 0x00, // 6 bDeviceProtocol 0x40, // 7 bMaxPacketSize0 64 0x9A, 0x23, // 8,9 idVendor [SET AT RUNTIME: lo,hi] -#define DEVICE_VID_LO_INDEX 8 -#define DEVICE_VID_HI_INDEX 9 +#define DEVICE_VID_LO_INDEX (8) +#define DEVICE_VID_HI_INDEX (9) 0x, 0xFF, // 10,11 idProduct [SET AT RUNTIME: lo,hi] -#define DEVICE PID_LO_INDEX 10 -#define DEVICE PID_HI_INDEX 11 +#define DEVICE PID_LO_INDEX (10) +#define DEVICE PID_HI_INDEX (11) 0x00, 0x01, // 12,13 bcdDevice 2.00 0x02, // 14 iManufacturer (String Index) [SET AT RUNTIME] -#define DEVICE_MANUFACTURER_STRING_INDEX 14 +#define DEVICE_MANUFACTURER_STRING_INDEX (14) 0x03, // 15 iProduct (String Index) [SET AT RUNTIME] -#define DEVICE_PRODUCT_STRING_INDEX 15 +#define DEVICE_PRODUCT_STRING_INDEX (15) 0x01, // 16 iSerialNumber (String Index) [SET AT RUNTIME] -#define DEVICE_SERIAL_NUMBER_STRING_INDEX 16 +#define DEVICE_SERIAL_NUMBER_STRING_INDEX (16) 0x01, // 17 bNumConfigurations 1 }; @@ -90,10 +90,10 @@ static const uint8_t configuration_descriptor_template[] = { 0x09, // 0 bLength 0x02, // 1 bDescriptorType (Configuration) 0xFF, 0xFF, // 2,3 wTotalLength [SET AT RUNTIME: lo, hi] -#define CONFIG_TOTAL_LENGTH_LO_INDEX 2 -#define CONFIG_TOTAL_LENGTH_HI_INDEX 3 +#define CONFIG_TOTAL_LENGTH_LO_INDEX (2) +#define CONFIG_TOTAL_LENGTH_HI_INDEX (3) 0xFF, // 4 bNumInterfaces [SET AT RUNTIME] -#define CONFIG_NUM_INTERFACES_INDEX 4 +#define CONFIG_NUM_INTERFACES_INDEX (4) 0x01, // 5 bConfigurationValue 0x00, // 6 iConfiguration (String Index) 0x80, // 7 bmAttributes @@ -254,7 +254,20 @@ void usb_add_interface_string(uint8_t interface_string_index, const char[] str) } -void usb_ +void usb_desc_gc_collect(void) { + // Once tud_mounted() is true, we're done with the constructed descriptors. + if (tud_mounted()) { + // GC will pick up the inaccessible blocks. + device_descriptor = NULL; + configuration_descriptor = NULL; + hid_report_descriptors = NULL; + } else { + gc_collect_ptr(device_descriptor); + gc_collect_ptr(configuration_descriptor); + gc_collect_ptr(hid_report_descriptors); // Collects children too. + } +} + // Invoked when GET DEVICE DESCRIPTOR is received. // Application return pointer to descriptor @@ -275,7 +288,6 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { - (void)itf; return hid_report_descriptor; } #endif diff --git a/supervisor/usb.h b/supervisor/usb.h index c8a699065d..9e3e14c2fd 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -52,8 +52,10 @@ void post_usb_init(void); bool usb_enabled(void); void usb_init(void); void usb_disconnect(void); +void usb_gc_collect(void); void usb_add_interface_string(uint8_t interface_string_index, const char[] str); +void usb_desc_gc_collect(void); void usb_desc_init(void); void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string); void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces); From 632cebafc62afd36ba7db96497e21b6f4380c3a1 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 22 Apr 2021 23:33:33 -0500 Subject: [PATCH 14/66] fix comment (stub fail) --- shared-bindings/wifi/Radio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index fe691b1684..782694a50d 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -172,8 +172,7 @@ const mp_obj_property_t wifi_radio_hostname_obj = { //| def start_ap(self, //| ssid: ReadableBuffer, -//| password: ReadableBuffer = b"", -//| *, +//| password: ReadableBuffer = b"") -> None //| """Starts an Access Point with the specified ssid and password.""" //| ... //| From 9da8978d401fa12047988f99a5aaf017f845daf3 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Thu, 22 Apr 2021 23:41:57 -0500 Subject: [PATCH 15/66] more of the same --- shared-bindings/wifi/Radio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 782694a50d..93e7af0b9d 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -172,7 +172,7 @@ const mp_obj_property_t wifi_radio_hostname_obj = { //| def start_ap(self, //| ssid: ReadableBuffer, -//| password: ReadableBuffer = b"") -> None +//| password: ReadableBuffer = b"") -> None: //| """Starts an Access Point with the specified ssid and password.""" //| ... //| From 556a126917d67dad53b7cf70da8abc5ffec42c65 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 23 Apr 2021 21:44:13 -0400 Subject: [PATCH 16/66] wip: getting closer --- shared-bindings/usb_hid/__init__.c | 15 ++++-- shared-bindings/usb_hid/__init__.h | 8 +++ shared-module/usb_hid/Device.c | 8 ++- shared-module/usb_hid/Device.h | 5 +- shared-module/usb_hid/__init__.c | 80 ++++++++++++++++++++++++++---- supervisor/shared/memory.c | 5 ++ 6 files changed, 104 insertions(+), 17 deletions(-) diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 6558c98e64..fdecba53df 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -40,14 +40,14 @@ //| """Tuple of all active HID device interfaces.""" //| -//| def configure_usb(devices: Sequence[Device, ...]=) -> None: +//| def configure_usb(devices: Optional[Sequence[Device, ...]]) -> None: //| """Configure the USB HID devices that will be available. //| Can be called in ``boot.py``, before USB is connected. //| //| :param Sequence devices: `Device` objects. //| If `devices` is empty, HID is disabled. The order of the ``Devices`` //| may matter to the host. For instance, for MacOS, put the mouse device -//| before any Gamepad or Digitizer HID device. +//| before any Gamepad or Digitizer HID device or else it will not work. //| ... //| STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { @@ -61,10 +61,15 @@ STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { } } - if (!common_hal_usb_hid_configure_usb(descriptors)) { - mp_raise_RuntimeError(translate("Cannot change USB devices now")); + switch (common_hal_usb_hid_configure_usb(descriptors)) { + case USB_CONFIG_TOO_LATE: + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + break; + case USB_CONFIG_NON_DEVICE: + mp_raise_ValueError_varg(translate("non-Device in %q", MP_QSTR_devices)); + break; + default: } - return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_configure_usb_obj, usb_hid_configure_usb); diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index 3d56fbfd02..352d1f5a9a 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -32,4 +32,12 @@ extern mp_obj_tuple_t common_hal_usb_hid_devices; +typedef enum { + USB_CONFIG_OK = 0, + USB_CONFIG_TOO_LATE = 1, + USB_CONFIG_NON_DEVICE = 2, +} usb_hid_configure_status; + +usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices); + #endif // SHARED_BINDINGS_USB_HID_H diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index d87fe3dff4..368372df89 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -156,7 +156,13 @@ const usb_hid_device_obj_t usb_hid_device_consumer_control_obj = { void common_hal_usb_hid_device_construct(usb_hid_dev_obj_t *self, mp_obj_array_t *descriptor, uint8_t usage_page, uint8_t usage, uint8_t in_report_length, uint8_t out_report_length, uint8_t report_id_index) { // report buffer pointers are NULL at start, and are created on demand. - self->descriptor = descriptor; + self->descriptor_obj = descriptor; + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(descriptor, &bufinfo, MP_BUFFER_READ); + self->descriptor = bufinfo.buf; + self->descriptor_length = bufinfo.len; + self->usage_page = usage_page; self->usage = usage; self->in_report_length = in_report_length; diff --git a/shared-module/usb_hid/Device.h b/shared-module/usb_hid/Device.h index 5b2caf369f..f15b70d79a 100644 --- a/shared-module/usb_hid/Device.h +++ b/shared-module/usb_hid/Device.h @@ -34,9 +34,12 @@ typedef struct { mp_obj_base_t base; + // If not MP_OBJ_NULL, points to Python array object whose contents are the descriptor. + mp_obj_t descriptor_obj; + // If not NULL, points to raw bytes that are the descriptor. + uint8_t *descriptor; uint8_t *in_report_buffer; uint8_t *out_report_buffer; - uint8_t *descriptor; uint16_t descriptor_length; uint8_t usage_page; uint8_t usage; diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index f234709df6..e48f882f93 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -53,14 +53,18 @@ static const uint8_t usb_hid_descriptor_template[] = { // Is the HID device enabled? bool usb_hid_enabled; -mp_obj_t usb_hid_devices; +supervisor_allocation *combined_hid_report_descriptor_allocation; +supervisor_allocation *devices_allocation; + +// This is the interface descriptor, not the report descriptor. size_t usb_hid_descriptor_length(void) { return sizeof(usb_hid_descriptor); } -static const char[] usb_hid_interface_name = USB_INTERFACE_NAME " Mass Storage"; +static const char[] usb_hid_interface_name = USB_INTERFACE_NAME " HID"; +// This is the interface descriptor, nto the report descriptor. size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length) { memcpy(descriptor_buf, usb_hid_descriptor_template, sizeof(usb_hid_descriptor_template)); @@ -74,23 +78,79 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_hid_descriptor_template); } -void usb_hid_build_report_descriptor() { -} - -bool common_hal_usb_hid_configure_usb(mp_obj_t devices) { +usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) { // We can't change the devices once we're connected. if (tud_connected()) { - return false; + return USB_CONFIG_TOO_LATE; } // Assume no devices to start. usb_hid_enabled = false; if (devices == mp_const_none) { - return true; + return USB_CONFIG_OK; } -} -void usb_hid_build_report + size_t total_report_descriptors_length = 0; + + // Build a combined report descriptor + + mp_int_t len = mp_obj_get_int(mp_obj_len(devices)); + + // First get the total size. + for (size_t i = 0; i < len; i++) { + mp_obj_t item = mp_obj_subscr(devices, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { + return USB_CONFIG_NON_DEVICE; for (size_t i = 0; i < len; i++) { + mp_obj_t item = (devices, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { + return USB_CONFIG_NON_DEVICE; + } + total_report_descriptors_length += device->report_descriptor_length; + } + + } + total_report_descriptors_length += device->report_descriptor_length; + } + if (len == 1) { + // Don't need space for a report id if there's only one device. + total_report_descriptors_length -= 2; + } + + // Allocate storage that persists across VMs to build the combined descriptor + // and to remember the device details. + + // allocate_memory(length, highaddress=false, movable=true) + combined_hid_report_descriptor_allocation = allocate_memory(total_report_descriptors_length, false, true); + + devices_allocation = allocate_memory(sizeof(usb_hid_device_obj_t) * len); + usb_hid_device_obj_t devices[] = (devices[]) device_details_allocation->ptr; + + uint8_t *descriptor_start = combined_hid_report_descriptor_allocation->ptr; + + for (size_t i = 0; i < len; i++) { + usb_hid_device_obj_t *device = MP_OBJ_TO_PTR(devices, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + + // Copy the report descriptor for this device. + if (len == 1) { + // Theres only one device, so it shouldn't have a report ID. + // Copy the descriptor, but splice out the report id indicator and value (2 bytes). + memcpy(descriptor_start, device->descriptor, device->report_id_index - 1); + descriptor_start += device->report_id_index - 1; + memcpy(descriptor_start, device->descriptor + device->report_id_index + 1, + device->report_descriptor_length - device->report_id_index - 1); + } else { + // Copy the whole descriptor and fill in the report id. + memcpy(descriptor_start, device->descriptor, device->descriptor_len); + descriptor_start[device->report_id_index] = i + 1; + descriptor_start += device->descriptor_len; + } + + // Copy the device data and discard any descriptor-bytes object pointer. + memcpy(&devices[i], device, sizeof(usb_hid_device_obj_t)); + devices[i].descriptor_obj = mp_const_none; + } + +} void usb_hid_gc_collect(void) { // Once tud_mounted() is true, we're done with the constructed descriptors. diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index 30482ea7b9..16015d1ae0 100644 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -45,6 +45,9 @@ enum { , CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT = 0 + #if CIRCUITPY_USB_HID + + 2 + #endif #if CIRCUITPY_DISPLAYIO #if CIRCUITPY_TERMINALIO + 1 @@ -308,9 +311,11 @@ void supervisor_move_memory(void) { // Notify clients that their movable allocations may have moved. old_allocations = &old_allocations_array[0]; + #if CIRCUITPY_DISPLAYIO supervisor_display_move_memory(); #endif + // Add calls to further clients here. old_allocations = NULL; } From 4d267ef6449fd999fdb6d67d65a7d3b396dc0c24 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Fri, 23 Apr 2021 21:44:34 -0500 Subject: [PATCH 17/66] add get_ipv4_address_ap --- ports/esp32s2/common-hal/wifi/Radio.c | 8 ++++++++ shared-bindings/wifi/Radio.c | 17 +++++++++++++++++ shared-bindings/wifi/Radio.h | 1 + 3 files changed, 26 insertions(+) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 2082ad1383..85deda704c 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -289,6 +289,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) { return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr); } +mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->ap_netif)) { + return mp_const_none; + } + esp_netif_get_ip_info(self->ap_netif, &self->ip_info); + return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr); +} + mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 93e7af0b9d..35cc72fd60 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -329,6 +329,22 @@ const mp_obj_property_t wifi_radio_ipv4_address_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| ipv4_address_ap: Optional[ipaddress.IPv4Address] +//| """IP v4 Address of the radio access point, when enabled. None otherwise.""" +//| +STATIC mp_obj_t wifi_radio_get_ipv4_address_ap(mp_obj_t self) { + return common_hal_wifi_radio_get_ipv4_address_ap(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_address_ap_obj, wifi_radio_get_ipv4_address_ap); + +const mp_obj_property_t wifi_radio_ipv4_address_ap_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ipv4_address_ap_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| ipv4_dns: Optional[ipaddress.IPv4Address] //| """IP v4 Address of the DNS server in use when connected to an access point. None otherwise.""" //| @@ -410,6 +426,7 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipv4_address_ap), MP_ROM_PTR(&wifi_radio_ipv4_address_ap_obj) }, // { MP_ROM_QSTR(MP_QSTR_access_point_active), MP_ROM_PTR(&wifi_radio_access_point_active_obj) }, // { MP_ROM_QSTR(MP_QSTR_start_access_point), MP_ROM_PTR(&wifi_radio_start_access_point_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 4e52e09635..61375d4532 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -92,6 +92,7 @@ extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self); extern mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, mp_float_t timeout); From 2e52c0ae62b53245b8f054808dd5b178837a6c99 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sat, 24 Apr 2021 16:41:41 -0500 Subject: [PATCH 18/66] set all wifi modes; add sta start & sta/ap stop --- ports/esp32s2/common-hal/wifi/Radio.c | 86 +++++++++++++++++------- ports/esp32s2/common-hal/wifi/__init__.c | 3 + shared-bindings/wifi/Radio.c | 34 +++++++++- shared-bindings/wifi/Radio.h | 3 + 4 files changed, 99 insertions(+), 27 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 85deda704c..76d7ce3a22 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -42,28 +42,44 @@ #define MAC_ADDRESS_LENGTH 6 -static void start_station(wifi_radio_obj_t *self) { - if (self->sta_mode) { - return; - } +static void set_mode_station(wifi_radio_obj_t *self, bool state) { wifi_mode_t next_mode; - if (self->ap_mode) { - next_mode = WIFI_MODE_APSTA; - } else { - next_mode = WIFI_MODE_STA; - } - esp_wifi_set_mode(next_mode); + if (state) { + if (self->ap_mode) { + next_mode = WIFI_MODE_APSTA; + } else { + next_mode = WIFI_MODE_STA; + } + } else { + if (self->ap_mode) { + next_mode = WIFI_MODE_AP; + } else { + next_mode = WIFI_MODE_NULL; + } + } - self->sta_mode = 1; + esp_wifi_set_mode(next_mode); + self->sta_mode = state; } -static void start_ap(wifi_radio_obj_t *self) { - if (self->ap_mode) { - return; - } - esp_wifi_set_mode(WIFI_MODE_APSTA); +static void set_mode_ap(wifi_radio_obj_t *self, bool state) { + wifi_mode_t next_mode; + if (state) { + if (self->sta_mode) { + next_mode = WIFI_MODE_APSTA; + } else { + next_mode = WIFI_MODE_AP; + } + } else { + if (self->sta_mode) { + next_mode = WIFI_MODE_STA; + } else { + next_mode = WIFI_MODE_NULL; + } + } - self->ap_mode = 1; + esp_wifi_set_mode(next_mode); + self->ap_mode = state; } bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self) { @@ -80,8 +96,6 @@ void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled) { return; } if (!self->started && enabled) { - // esp_wifi_start() would default to soft-AP, thus setting it to station - start_station(self); ESP_ERROR_CHECK(esp_wifi_start()); self->started = true; return; @@ -107,7 +121,7 @@ mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self) { if (!common_hal_wifi_radio_get_enabled(self)) { mp_raise_RuntimeError(translate("wifi is not enabled")); } - start_station(self); + set_mode_station(self, true); wifi_scannednetworks_obj_t *scan = m_new_obj(wifi_scannednetworks_obj_t); scan->base.type = &wifi_scannednetworks_type; @@ -142,12 +156,28 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host esp_netif_set_hostname(self->netif, hostname); } +void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) { + if (!common_hal_wifi_radio_get_enabled(self)) { + mp_raise_RuntimeError(translate("wifi is not enabled")); + } + + set_mode_station(self, true); +} + +void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { + if (!common_hal_wifi_radio_get_enabled(self)) { + mp_raise_RuntimeError(translate("wifi is not enabled")); + } + + set_mode_station(self, false); +} + void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len) { if (!common_hal_wifi_radio_get_enabled(self)) { mp_raise_RuntimeError(translate("wifi is not enabled")); } - start_ap(self); + set_mode_ap(self, true); wifi_config_t *config = &self->ap_config; memcpy(&config->ap.ssid, ssid, ssid_len); @@ -155,10 +185,16 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ memcpy(&config->ap.password, password, password_len); config->ap.password[password_len] = 0; config->ap.authmode = WIFI_AUTH_WPA2_PSK; - esp_wifi_set_config(ESP_IF_WIFI_AP, config); + config->ap.max_connection = 4; + esp_wifi_set_config(WIFI_IF_AP, config); +} - // common_hal_wifi_radio_set_enabled(self, false); - common_hal_wifi_radio_set_enabled(self, true); +void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) { + if (!common_hal_wifi_radio_get_enabled(self)) { + mp_raise_RuntimeError(translate("wifi is not enabled")); + } + + set_mode_ap(self, false); } wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len) { @@ -181,7 +217,7 @@ wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t // explicitly clear bits since xEventGroupWaitBits may have timed out xEventGroupClearBits(self->event_group_handle, WIFI_CONNECTED_BIT); xEventGroupClearBits(self->event_group_handle, WIFI_DISCONNECTED_BIT); - start_station(self); + set_mode_station(self, true); wifi_config_t *config = &self->sta_config; memcpy(&config->sta.ssid, ssid, ssid_len); diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index 71cebda9b4..f735d68644 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -150,6 +150,9 @@ void common_hal_wifi_init(void) { } else if (result != ESP_OK) { mp_raise_RuntimeError(translate("Failed to init wifi")); } + // set station mode to avoid the default SoftAP + esp_wifi_set_mode(WIFI_MODE_STA); + // start wifi common_hal_wifi_radio_set_enabled(self, true); } diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 35cc72fd60..9965455f76 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -170,14 +170,32 @@ const mp_obj_property_t wifi_radio_hostname_obj = { (mp_obj_t)&mp_const_none_obj}, }; +//| def start_station(self) -> None: +//| """Starts a Wi-Fi Station""" +//| ... +//| +STATIC mp_obj_t wifi_radio_start_station(mp_obj_t self) { + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_station_obj, wifi_radio_start_station); + +//| def stop_station(self) -> None: +//| """Stops the Wi-Fi Station""" +//| ... +//| +STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) { + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); + //| def start_ap(self, //| ssid: ReadableBuffer, //| password: ReadableBuffer = b"") -> None: -//| """Starts an Access Point with the specified ssid and password.""" +//| """Starts a Wi-Fi Access Point with the specified ssid and password.""" //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_ssid, ARG_password, ARG_channel, ARG_bssid, ARG_timeout }; + enum { ARG_ssid, ARG_password, ARG_channel, ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -204,6 +222,15 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); +//| def stop_ap(self) -> None: +//| """Stops the Wi-Fi Access Point""" +//| ... +//| +STATIC mp_obj_t wifi_radio_stop_ap(mp_obj_t self) { + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_ap_obj, wifi_radio_stop_ap); + //| def connect(self, //| ssid: ReadableBuffer, //| password: ReadableBuffer = b"", @@ -417,7 +444,10 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_hostname), MP_ROM_PTR(&wifi_radio_hostname_obj) }, + { MP_ROM_QSTR(MP_QSTR_start_station), MP_ROM_PTR(&wifi_radio_start_station_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop_station), MP_ROM_PTR(&wifi_radio_stop_station_obj) }, { MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop_ap), MP_ROM_PTR(&wifi_radio_stop_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 61375d4532..b84966f14b 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -83,7 +83,10 @@ extern mp_obj_t common_hal_wifi_radio_get_mac_address_ap(wifi_radio_obj_t *self) extern mp_obj_t common_hal_wifi_radio_start_scanning_networks(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self); +extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len); +extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *selfn); extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len); From 354b4428678815d25b95a2873120919d0cbea49e Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sat, 24 Apr 2021 19:36:11 -0500 Subject: [PATCH 19/66] fixes --- ports/esp32s2/common-hal/wifi/Radio.c | 4 ++-- shared-bindings/wifi/Radio.c | 14 +++++++------- shared-bindings/wifi/Radio.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 76d7ce3a22..95f464c716 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -50,7 +50,7 @@ static void set_mode_station(wifi_radio_obj_t *self, bool state) { } else { next_mode = WIFI_MODE_STA; } - } else { + } else { if (self->ap_mode) { next_mode = WIFI_MODE_AP; } else { @@ -70,7 +70,7 @@ static void set_mode_ap(wifi_radio_obj_t *self, bool state) { } else { next_mode = WIFI_MODE_AP; } - } else { + } else { if (self->sta_mode) { next_mode = WIFI_MODE_STA; } else { diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 9965455f76..51ed1b19d5 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -171,8 +171,8 @@ const mp_obj_property_t wifi_radio_hostname_obj = { }; //| def start_station(self) -> None: -//| """Starts a Wi-Fi Station""" -//| ... +//| """Starts a Station.""" +//| ... //| STATIC mp_obj_t wifi_radio_start_station(mp_obj_t self) { return mp_const_none; @@ -180,8 +180,8 @@ STATIC mp_obj_t wifi_radio_start_station(mp_obj_t self) { MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_station_obj, wifi_radio_start_station); //| def stop_station(self) -> None: -//| """Stops the Wi-Fi Station""" -//| ... +//| """Stops the Station.""" +//| ... //| STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) { return mp_const_none; @@ -191,7 +191,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| def start_ap(self, //| ssid: ReadableBuffer, //| password: ReadableBuffer = b"") -> None: -//| """Starts a Wi-Fi Access Point with the specified ssid and password.""" +//| """Starts an Access Point with the specified ssid and password.""" //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -223,8 +223,8 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); //| def stop_ap(self) -> None: -//| """Stops the Wi-Fi Access Point""" -//| ... +//| """Stops the Access Point.""" +//| ... //| STATIC mp_obj_t wifi_radio_stop_ap(mp_obj_t self) { return mp_const_none; diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index b84966f14b..77ae0da9f8 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -86,7 +86,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len); -extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *selfn); +extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self); extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len); From de01814cced3cccf01c8c51c3364894bdb7f57b5 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sat, 24 Apr 2021 20:38:04 -0500 Subject: [PATCH 20/66] call start and stop (oops) --- shared-bindings/wifi/Radio.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 51ed1b19d5..4856d4572b 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -175,6 +175,7 @@ const mp_obj_property_t wifi_radio_hostname_obj = { //| ... //| STATIC mp_obj_t wifi_radio_start_station(mp_obj_t self) { + common_hal_wifi_radio_start_station(self); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_station_obj, wifi_radio_start_station); @@ -184,6 +185,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_start_station_obj, wifi_radio_start_station //| ... //| STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) { + common_hal_wifi_radio_stop_station(self); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); @@ -227,6 +229,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_a //| ... //| STATIC mp_obj_t wifi_radio_stop_ap(mp_obj_t self) { + common_hal_wifi_radio_stop_ap(self); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_ap_obj, wifi_radio_stop_ap); From dc3c47d39681c141b311e6d38e2d79cfbcc5f762 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 25 Apr 2021 00:22:08 -0500 Subject: [PATCH 21/66] ap channel param --- ports/esp32s2/common-hal/wifi/Radio.c | 3 ++- shared-bindings/wifi/Radio.c | 5 +++-- shared-bindings/wifi/Radio.h | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 95f464c716..bc2da2e66e 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -172,7 +172,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { set_mode_station(self, false); } -void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len) { +void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel) { if (!common_hal_wifi_radio_get_enabled(self)) { mp_raise_RuntimeError(translate("wifi is not enabled")); } @@ -184,6 +184,7 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ config->ap.ssid[ssid_len] = 0; memcpy(&config->ap.password, password, password_len); config->ap.password[password_len] = 0; + config->ap.channel = channel; config->ap.authmode = WIFI_AUTH_WPA2_PSK; config->ap.max_connection = 4; esp_wifi_set_config(WIFI_IF_AP, config); diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 4856d4572b..de4deca7e7 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -197,10 +197,11 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_ssid, ARG_password, ARG_channel, ARG_timeout }; + enum { ARG_ssid, ARG_password, ARG_channel }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, + { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, }; wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); @@ -219,7 +220,7 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ } } - common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len); + common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 77ae0da9f8..318f3e05d4 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -85,7 +85,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self); -extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len); +extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel); extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self); extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len); From aea3c4d3abe288ceb0f5df7cf103bd0f46a37465 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 25 Apr 2021 10:23:59 -0400 Subject: [PATCH 22/66] wip --- shared-bindings/usb_hid/__init__.h | 4 +--- shared-module/usb_hid/__init__.c | 37 +++++++++++++++--------------- supervisor/shared/memory.c | 9 ++++++-- supervisor/shared/usb/usb_desc.c | 27 ++++++++++++---------- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index 352d1f5a9a..925b3d5e91 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -38,6 +38,4 @@ typedef enum { USB_CONFIG_NON_DEVICE = 2, } usb_hid_configure_status; -usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices); - -#endif // SHARED_BINDINGS_USB_HID_H +usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seqf // SHARED_BINDINGS_USB_HID_H diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index e48f882f93..8d8f5b2e08 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -53,8 +53,8 @@ static const uint8_t usb_hid_descriptor_template[] = { // Is the HID device enabled? bool usb_hid_enabled; -supervisor_allocation *combined_hid_report_descriptor_allocation; -supervisor_allocation *devices_allocation; +supervisor_allocation *hid_report_descriptor_allocation; +supervisor_allocation *hid_devices_allocation; // This is the interface descriptor, not the report descriptor. @@ -64,7 +64,7 @@ size_t usb_hid_descriptor_length(void) { static const char[] usb_hid_interface_name = USB_INTERFACE_NAME " HID"; -// This is the interface descriptor, nto the report descriptor. +// This is the interface descriptor, not the report descriptor. size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length) { memcpy(descriptor_buf, usb_hid_descriptor_template, sizeof(usb_hid_descriptor_template)); @@ -78,7 +78,7 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_hid_descriptor_template); } -usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) { +usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seq) { // We can't change the devices once we're connected. if (tud_connected()) { return USB_CONFIG_TOO_LATE; @@ -86,7 +86,7 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) { // Assume no devices to start. usb_hid_enabled = false; - if (devices == mp_const_none) { + if (devices_seq == mp_const_none) { return USB_CONFIG_OK; } @@ -94,11 +94,11 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) { // Build a combined report descriptor - mp_int_t len = mp_obj_get_int(mp_obj_len(devices)); + mp_int_t len = mp_obj_get_int(mp_obj_len(devices_seq)); // First get the total size. for (size_t i = 0; i < len; i++) { - mp_obj_t item = mp_obj_subscr(devices, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + mp_obj_t item = mp_obj_subscr(devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { return USB_CONFIG_NON_DEVICE; for (size_t i = 0; i < len; i++) { mp_obj_t item = (devices, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); @@ -119,16 +119,16 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) { // Allocate storage that persists across VMs to build the combined descriptor // and to remember the device details. - // allocate_memory(length, highaddress=false, movable=true) - combined_hid_report_descriptor_allocation = allocate_memory(total_report_descriptors_length, false, true); + hid_report_descriptor_allocation = + allocate_memory(total_report_descriptors_length, false /*highaddress*/, true /*movable*/); - devices_allocation = allocate_memory(sizeof(usb_hid_device_obj_t) * len); - usb_hid_device_obj_t devices[] = (devices[]) device_details_allocation->ptr; + hid_devices_allocation = allocate_memory(sizeof(usb_hid_device_obj_t) * len); + usb_hid_device_obj_t hid_devices[] = (usb_hid_device_obj_t[]) hid_devices_allocation->ptr; - uint8_t *descriptor_start = combined_hid_report_descriptor_allocation->ptr; + uint8_t *descriptor_start = (uint8_t *) hid_report_descriptor_allocation->ptr; for (size_t i = 0; i < len; i++) { - usb_hid_device_obj_t *device = MP_OBJ_TO_PTR(devices, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + usb_hid_device_obj_t *device = MP_OBJ_TO_PTR(devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); // Copy the report descriptor for this device. if (len == 1) { @@ -146,8 +146,8 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) { } // Copy the device data and discard any descriptor-bytes object pointer. - memcpy(&devices[i], device, sizeof(usb_hid_device_obj_t)); - devices[i].descriptor_obj = mp_const_none; + memcpy(&hid_devices[i], device, sizeof(usb_hid_device_obj_t)); + hid_devices[i].descriptor_obj = mp_const_none; } } @@ -155,9 +155,10 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices) { void usb_hid_gc_collect(void) { // Once tud_mounted() is true, we're done with the constructed descriptors. if (tud_mounted()) { - // GC will pick up the inaccessible blocks. - usb_hid_devices_to_configure = NULL; + free_memory(hid_report_descriptor_allocation); + free_memory(usb_hid_devices_allocation); } else { - gc_collect_ptr(usb_hid_devices); + gc_collect_ptr(hid_report_descriptor_allocation->ptr); + gc_collect_ptr(usb_hid_devices_allocation); } } diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index 16015d1ae0..7cb00006e5 100644 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -34,7 +34,7 @@ enum { CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT = - // stack + heap + // stack + heap 2 #if INTERNAL_FLASH_FILESYSTEM == 0 + 1 @@ -45,8 +45,13 @@ enum { , CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT = 0 + #if CIRCUITPY_USB + + 1 // device_descriptor_allocation + + 1 // config_descriptor_allocation + #endif #if CIRCUITPY_USB_HID - + 2 + + 1 // hid_report_descriptor_allocation + + 1 // hid_devices_allocation #endif #if CIRCUITPY_DISPLAYIO #if CIRCUITPY_TERMINALIO diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index d77047c472..ea67e3aaaf 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -46,9 +46,8 @@ #include "genhdr/autogen_usb_descriptor.h" -static uint8_t *device_descriptor; -static uint8_t *config_descriptor; -static uint8_t *hid_report_descriptor; +supervisor_allocation *device_descriptor_allocation; +supervisor_allocation *config_descriptor_allocation; // Table for collecting interface strings (interface names) as descriptor is built. #define MAX_INTERFACE_STRINGS 16 @@ -114,14 +113,17 @@ void usb_desc_init(void) { // Null-terminate the string. serial_number_hex_string[sizeof(serial_number_hex_string)] = '\0'; - // Set to zero when allocated; we depend on that. + // Memory is cleared to zero when allocated; we depend on that. collected_interface_strings = m_malloc(MAX_INTERFACE_STRINGS + 1, false); current_interface_string = 1; } void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string) { - device_descriptor = m_malloc(sizeof(device_descriptor_template), false); + device_descriptor_allocation = + allocate_memory(sizeof(device_descriptor_template), false /*highaddress*/, true /*movable*/); + uint8_t *device_descriptor = (uint8_t *) device_descriptor_allocation->ptr; + memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); device_descriptor[DEVICE_VID_LO_INDEX] = vid & 0xFF; @@ -176,7 +178,10 @@ void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_inter #endif // Now we now how big the configuration descriptor will be. - configuration_descriptor = m_malloc(total_descriptor_length, false); + + configuration_descriptor_allocation = + allocate_memory(sizeof(configuration_descriptor_template), false /*highaddress*/, true /*movable*/); + uint8_t *configuration_descriptor = (uint8_t *) device_descriptor_allocation->ptr; // Copy the top-level template, and fix up its length. memcpy(config_descriptor, configuration_descriptor_template, sizeof(configuration_descriptor_template)); @@ -258,13 +263,11 @@ void usb_desc_gc_collect(void) { // Once tud_mounted() is true, we're done with the constructed descriptors. if (tud_mounted()) { // GC will pick up the inaccessible blocks. - device_descriptor = NULL; - configuration_descriptor = NULL; - hid_report_descriptors = NULL; + free_memory(device_descriptor_allocation); + free_memory(configuration_descriptor_allocation); } else { - gc_collect_ptr(device_descriptor); - gc_collect_ptr(configuration_descriptor); - gc_collect_ptr(hid_report_descriptors); // Collects children too. + gc_collect_ptr(device_descriptor_allocation->ptr); + gc_collect_ptr(configuration_descriptor_allocation->ptr); } } From c510c4d501316ef006460308d324bb2a60131cf2 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 25 Apr 2021 09:29:15 -0500 Subject: [PATCH 23/66] allow start/stop sta/ap (changing modes) when `wifi.radio.enabled = False` --- ports/esp32s2/common-hal/wifi/Radio.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index bc2da2e66e..92338ce169 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -157,26 +157,14 @@ void common_hal_wifi_radio_set_hostname(wifi_radio_obj_t *self, const char *host } void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self) { - if (!common_hal_wifi_radio_get_enabled(self)) { - mp_raise_RuntimeError(translate("wifi is not enabled")); - } - set_mode_station(self, true); } void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { - if (!common_hal_wifi_radio_get_enabled(self)) { - mp_raise_RuntimeError(translate("wifi is not enabled")); - } - set_mode_station(self, false); } void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel) { - if (!common_hal_wifi_radio_get_enabled(self)) { - mp_raise_RuntimeError(translate("wifi is not enabled")); - } - set_mode_ap(self, true); wifi_config_t *config = &self->ap_config; @@ -191,10 +179,6 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ } void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self) { - if (!common_hal_wifi_radio_get_enabled(self)) { - mp_raise_RuntimeError(translate("wifi is not enabled")); - } - set_mode_ap(self, false); } From 6f6c0cff81d5c7f04f819b1d71963dae47a77a0b Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 25 Apr 2021 14:30:45 -0500 Subject: [PATCH 24/66] embellish rtd comments. channel _should_ default to 1 behind the scenes since 0 is out of range, but just to be sure, default channel to 1 --- shared-bindings/wifi/Radio.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index de4deca7e7..790b0b5e75 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -192,8 +192,13 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| def start_ap(self, //| ssid: ReadableBuffer, -//| password: ReadableBuffer = b"") -> None: -//| """Starts an Access Point with the specified ssid and password.""" +//| password: ReadableBuffer = b"", +//| *, +//| channel: Optional[int] = 1) -> None: +//| """Starts an Access Point with the specified ssid and password. +//| +//| If ``channel`` is given, the access point will use that channel unless +//| wifi is already operating on a different channel due to an active station.""" //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { @@ -201,7 +206,7 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, }; wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); From 747d72f5a5e082711a5f1b2b441140b720466f79 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 25 Apr 2021 18:18:45 -0500 Subject: [PATCH 25/66] redundant with system log --- ports/esp32s2/common-hal/wifi/__init__.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index f735d68644..5ba8f4cd64 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -56,12 +56,12 @@ static void event_handler(void *arg, esp_event_base_t event_base, case WIFI_EVENT_AP_STOP: ESP_LOGW(TAG, "ap stop"); break; - case WIFI_EVENT_AP_STACONNECTED: - ESP_LOGW(TAG, "ap sta connected"); + case WIFI_EVENT_AP_STACONNECTED: { break; - case WIFI_EVENT_AP_STADISCONNECTED: - ESP_LOGW(TAG, "ap sta disconnected"); + } + case WIFI_EVENT_AP_STADISCONNECTED: { break; + } case WIFI_EVENT_STA_START: ESP_LOGW(TAG, "sta start"); break; From f20a53177bb64e96d1add9c58eb9c92ae75541cf Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 25 Apr 2021 18:20:18 -0500 Subject: [PATCH 26/66] add authmode to start_ap() --- ports/esp32s2/common-hal/wifi/Radio.c | 4 ++-- shared-bindings/wifi/Radio.c | 31 +++++++++++++++++++++------ shared-bindings/wifi/Radio.h | 14 +++++++++++- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 92338ce169..953cd41e49 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -164,7 +164,7 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { set_mode_station(self, false); } -void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel) { +void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode) { set_mode_ap(self, true); wifi_config_t *config = &self->ap_config; @@ -173,7 +173,7 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ memcpy(&config->ap.password, password, password_len); config->ap.password[password_len] = 0; config->ap.channel = channel; - config->ap.authmode = WIFI_AUTH_WPA2_PSK; + config->ap.authmode = authmode; config->ap.max_connection = 4; esp_wifi_set_config(WIFI_IF_AP, config); } diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 790b0b5e75..988391e536 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -190,23 +190,34 @@ STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); +//| OPEN: int +//| WPA_PSK: int +//| WPA2_PSK: int +//| WPA_WPA2_PSK: int +//| //| def start_ap(self, //| ssid: ReadableBuffer, //| password: ReadableBuffer = b"", //| *, -//| channel: Optional[int] = 1) -> None: -//| """Starts an Access Point with the specified ssid and password. +//| channel: Optional[int] = 1, +//| authmode: Optional[int] = WPA_WPA2_PSK) -> None: +//| """Starts an Access Point with the specified ssid and password +//| If an empty. //| //| If ``channel`` is given, the access point will use that channel unless -//| wifi is already operating on a different channel due to an active station.""" +//| a station is already operating on a different channel. +//| +//| If ``authmode`` is given, the access point will use that Authentication +//| mode. If a password is given, ``authmode`` must not be ``OPEN``.""" //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_ssid, ARG_password, ARG_channel }; + enum { ARG_ssid, ARG_password, ARG_channel, ARG_authmode }; static const mp_arg_t allowed_args[] = { { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, + { MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = WIFI_RADIO_AUTH_WPA_WPA2_PSK} }, }; wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); @@ -223,9 +234,12 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ if (password.len > 0 && (password.len < 8 || password.len > 63)) { mp_raise_ValueError(translate("WiFi password must be between 8 and 63 characters")); } + if (args[ARG_authmode].u_int == WIFI_RADIO_AUTH_OPEN) { + mp_raise_ValueError(translate("WiFi password is not used with OPEN authentication")); + } } - common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int); + common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, args[ARG_authmode].u_int); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); @@ -455,8 +469,13 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_start_station), MP_ROM_PTR(&wifi_radio_start_station_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_station), MP_ROM_PTR(&wifi_radio_stop_station_obj) }, - { MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_ap), MP_ROM_PTR(&wifi_radio_stop_ap_obj) }, + { MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) }, + { MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(WIFI_RADIO_AUTH_OPEN) }, + { MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA_PSK) }, + { MP_ROM_QSTR(MP_QSTR_WPA2_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA2_PSK) }, + { MP_ROM_QSTR(MP_QSTR_WPA_WPA2_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA_WPA2_PSK) }, + { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 318f3e05d4..8bcc02063b 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -71,6 +71,18 @@ typedef enum { WIFI_RADIO_ERROR_AP_TSF_RESET = 206, } wifi_radio_error_t; +typedef enum { + WIFI_RADIO_AUTH_OPEN = 0, // OK + WIFI_RADIO_AUTH_WEP, // not supported in SoftAP + WIFI_RADIO_AUTH_WPA_PSK, // OK + WIFI_RADIO_AUTH_WPA2_PSK, // OK + WIFI_RADIO_AUTH_WPA_WPA2_PSK, // OK + WIFI_RADIO_AUTH_WPA2_ENTERPRISE, // not currently supported + WIFI_RADIO_AUTH_WPA3_PSK, // not currently supported + WIFI_RADIO_AUTH_WPA2_WPA3_PSK, // not currently supported + WIFI_RADIO_AUTH_MAX, // not currently supported +} wifi_radio_authmode_t; + extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled); @@ -85,7 +97,7 @@ extern void common_hal_wifi_radio_stop_scanning_networks(wifi_radio_obj_t *self) extern void common_hal_wifi_radio_start_station(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self); -extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel); +extern void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode); extern void common_hal_wifi_radio_stop_ap(wifi_radio_obj_t *self); extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, mp_float_t timeout, uint8_t *bssid, size_t bssid_len); From a328cff209da76cec2f9be78a597ee3a7ee75fcf Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Sun, 25 Apr 2021 18:51:00 -0500 Subject: [PATCH 27/66] translate --- locale/circuitpython.pot | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 7b019191e3..57a73d18c2 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -2343,6 +2343,10 @@ msgid "" "To list built-in modules please do `help(\"modules\")`.\n" msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "WiFi password is not used with OPEN authentication" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "WiFi password must be between 8 and 63 characters" msgstr "" From c26e49c2e609a90d45e77a6add728c8ab18e605c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Sun, 25 Apr 2021 23:17:41 -0400 Subject: [PATCH 28/66] wip: starting to try to compile --- WEBUSB_README.md | 31 +- main.c | 8 +- .../asf4_conf/samd21/hpl_usb_config.h | 35 +- .../asf4_conf/samd51/hpl_usb_config.h | 35 +- .../asf4_conf/same51/hpl_usb_config.h | 35 +- .../asf4_conf/same54/hpl_usb_config.h | 35 +- py/circuitpy_mpconfig.mk | 46 +- shared-bindings/usb_hid/__init__.c | 18 +- shared-bindings/usb_hid/__init__.h | 9 +- shared-module/usb_cdc/__init__.c | 1 - shared-module/usb_hid/__init__.c | 38 +- shared-module/usb_midi/__init__.c | 1 - supervisor/shared/usb/tusb_config.h | 2 - supervisor/shared/usb/usb.c | 20 +- supervisor/shared/usb/usb_desc.c | 95 +- tools/gen_separated_usb_descriptors.py | 1064 ----------------- tools/gen_usb_descriptor.py | 1059 ---------------- 17 files changed, 149 insertions(+), 2383 deletions(-) delete mode 100644 tools/gen_separated_usb_descriptors.py delete mode 100644 tools/gen_usb_descriptor.py diff --git a/WEBUSB_README.md b/WEBUSB_README.md index a257d5259c..8250941eb0 100644 --- a/WEBUSB_README.md +++ b/WEBUSB_README.md @@ -62,33 +62,4 @@ The tinyusb examples already include a "WebUSB serial" example. Basically, this feature was ported into CircuitPython by pulling code snippets out of the tinyusb example, and putting them where they best belonged in the CircuitPython codebase. -There was one complication: - -tinyusb uses C preprocessor macros to define things like USB descriptors. - -CircuitPython uses a Python program (tools/gen_usb_descriptor.py) to create USB descriptors (etc.) -using "helper objects" from another repo (adafruit_usb_descriptor). This means some of the example -code had to be adapted to the new programing model, and gen_usb_descriptor gained new command-line -options to control the generated code. - -The generated files go into the "build" directory, look for autogen_usb_descriptor.c and -genhdr/autogen_usb_descriptor.h. - - -Also worth pointing out - the re-use of the CDC connect/disconnect mechanism is not actually part -of the WebUSB standard, it's more of "common idiom". We make use of it here because we need to know -when we should be paying attention to the WebUSB serial interface, and when we should ignore it.. - -## Possible future work areas - -The current code uses the existing Python infrastructure to create the Interface descriptor, but -simply outputs the code snippets from the original tinyusb demo code to create the WEBUSB_URL, -BOS, and MS_OS_20 descriptors. I suppose additional work could be done to add these to the -adafruit_usb_descriptor project, and then gen_usb_descriptor.py could be modified to make use -of them. - -Program gen_usb_descriptor.py creates objects for most interface types, regardless of whether or -not they are actually enabled. This increases the size of a generated string table. I made the -new vendor-interface-related code not do this (because some of the ARM platforms would no longer -build), but I did not go back and do this for the other interface types (CDC, MIDI, HID, etc.) -Some FLASH savings are probably possible if this is done. +### TODO: This needs to be reworked for dynamic USB descriptors. diff --git a/main.c b/main.c index 00c43275fb..21e7775a9f 100755 --- a/main.c +++ b/main.c @@ -518,7 +518,6 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { } #endif - // TODO(tannewt): Allocate temporary space to hold custom usb descriptors. filesystem_flush(); supervisor_allocation* heap = allocate_remaining_memory(); start_mp(heap); @@ -535,6 +534,12 @@ STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { boot_output_file = NULL; #endif + #if CIRCUITPY_USB + // Remember USB settings done during boot.py. + // Call this before the boot.py heap is destroyed. + usb_post_boot_py(); + #endif + cleanup_after_vm(heap); } } @@ -588,6 +593,7 @@ int __attribute__((used)) main(void) { // Port-independent devices, like CIRCUITPY_BLEIO_HCI. reset_devices(); reset_board(); + reset_usb(); // This is first time we are running CircuitPython after a reset or power-up. supervisor_set_run_reason(RUN_REASON_STARTUP); diff --git a/ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h index d1bb42fe45..51c71cb823 100644 --- a/ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h +++ b/ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h @@ -2,60 +2,29 @@ #ifndef HPL_USB_CONFIG_H #define HPL_USB_CONFIG_H -// CIRCUITPY: +// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. +// So provide cache space for all of them. -// Use 64-byte USB buffers for endpoint directions that are in use. They're set to 0 below otherwise. - -#include "genhdr/autogen_usb_descriptor.h" - -#if defined(USB_ENDPOINT_1_OUT_USED) && USB_ENDPOINT_1_OUT_USED #define CONF_USB_EP1_CACHE 64 -#endif -#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED #define CONF_USB_EP1_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED #define CONF_USB_EP2_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED #define CONF_USB_EP2_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED #define CONF_USB_EP3_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED #define CONF_USB_EP3_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED #define CONF_USB_EP4_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED #define CONF_USB_EP4_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED #define CONF_USB_EP5_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED #define CONF_USB_EP5_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED #define CONF_USB_EP6_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED #define CONF_USB_EP6_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED #define CONF_USB_EP7_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED #define CONF_USB_EP7_I_CACHE 64 -#endif // <<< Use Configuration Wizard in Context Menu >>> diff --git a/ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h index d1bb42fe45..51c71cb823 100644 --- a/ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h +++ b/ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h @@ -2,60 +2,29 @@ #ifndef HPL_USB_CONFIG_H #define HPL_USB_CONFIG_H -// CIRCUITPY: +// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. +// So provide cache space for all of them. -// Use 64-byte USB buffers for endpoint directions that are in use. They're set to 0 below otherwise. - -#include "genhdr/autogen_usb_descriptor.h" - -#if defined(USB_ENDPOINT_1_OUT_USED) && USB_ENDPOINT_1_OUT_USED #define CONF_USB_EP1_CACHE 64 -#endif -#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED #define CONF_USB_EP1_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED #define CONF_USB_EP2_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED #define CONF_USB_EP2_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED #define CONF_USB_EP3_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED #define CONF_USB_EP3_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED #define CONF_USB_EP4_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED #define CONF_USB_EP4_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED #define CONF_USB_EP5_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED #define CONF_USB_EP5_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED #define CONF_USB_EP6_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED #define CONF_USB_EP6_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED #define CONF_USB_EP7_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED #define CONF_USB_EP7_I_CACHE 64 -#endif // <<< Use Configuration Wizard in Context Menu >>> diff --git a/ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h index d1bb42fe45..51c71cb823 100644 --- a/ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h +++ b/ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h @@ -2,60 +2,29 @@ #ifndef HPL_USB_CONFIG_H #define HPL_USB_CONFIG_H -// CIRCUITPY: +// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. +// So provide cache space for all of them. -// Use 64-byte USB buffers for endpoint directions that are in use. They're set to 0 below otherwise. - -#include "genhdr/autogen_usb_descriptor.h" - -#if defined(USB_ENDPOINT_1_OUT_USED) && USB_ENDPOINT_1_OUT_USED #define CONF_USB_EP1_CACHE 64 -#endif -#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED #define CONF_USB_EP1_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED #define CONF_USB_EP2_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED #define CONF_USB_EP2_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED #define CONF_USB_EP3_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED #define CONF_USB_EP3_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED #define CONF_USB_EP4_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED #define CONF_USB_EP4_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED #define CONF_USB_EP5_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED #define CONF_USB_EP5_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED #define CONF_USB_EP6_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED #define CONF_USB_EP6_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED #define CONF_USB_EP7_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED #define CONF_USB_EP7_I_CACHE 64 -#endif // <<< Use Configuration Wizard in Context Menu >>> diff --git a/ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h index d1bb42fe45..51c71cb823 100644 --- a/ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h +++ b/ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h @@ -2,60 +2,29 @@ #ifndef HPL_USB_CONFIG_H #define HPL_USB_CONFIG_H -// CIRCUITPY: +// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. +// So provide cache space for all of them. -// Use 64-byte USB buffers for endpoint directions that are in use. They're set to 0 below otherwise. - -#include "genhdr/autogen_usb_descriptor.h" - -#if defined(USB_ENDPOINT_1_OUT_USED) && USB_ENDPOINT_1_OUT_USED #define CONF_USB_EP1_CACHE 64 -#endif -#if defined(USB_ENDPOINT_1_IN_USED) && USB_ENDPOINT_1_IN_USED #define CONF_USB_EP1_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_OUT_USED) && USB_ENDPOINT_2_OUT_USED #define CONF_USB_EP2_CACHE 64 -#endif -#if defined(USB_ENDPOINT_2_IN_USED) && USB_ENDPOINT_2_IN_USED #define CONF_USB_EP2_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_OUT_USED) && USB_ENDPOINT_3_OUT_USED #define CONF_USB_EP3_CACHE 64 -#endif -#if defined(USB_ENDPOINT_3_IN_USED) && USB_ENDPOINT_3_IN_USED #define CONF_USB_EP3_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_OUT_USED) && USB_ENDPOINT_4_OUT_USED #define CONF_USB_EP4_CACHE 64 -#endif -#if defined(USB_ENDPOINT_4_IN_USED) && USB_ENDPOINT_4_IN_USED #define CONF_USB_EP4_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_OUT_USED) && USB_ENDPOINT_5_OUT_USED #define CONF_USB_EP5_CACHE 64 -#endif -#if defined(USB_ENDPOINT_5_IN_USED) && USB_ENDPOINT_5_IN_USED #define CONF_USB_EP5_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_OUT_USED) && USB_ENDPOINT_6_OUT_USED #define CONF_USB_EP6_CACHE 64 -#endif -#if defined(USB_ENDPOINT_6_IN_USED) && USB_ENDPOINT_6_IN_USED #define CONF_USB_EP6_I_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_OUT_USED) && USB_ENDPOINT_7_OUT_USED #define CONF_USB_EP7_CACHE 64 -#endif -#if defined(USB_ENDPOINT_7_IN_USED) && USB_ENDPOINT_7_IN_USED #define CONF_USB_EP7_I_CACHE 64 -#endif // <<< Use Configuration Wizard in Context Menu >>> diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 1758d8fe4c..622f991ffb 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -308,6 +308,9 @@ CFLAGS += -DCIRCUITPY_STRUCT=$(CIRCUITPY_STRUCT) CIRCUITPY_SUPERVISOR ?= 1 CFLAGS += -DCIRCUITPY_SUPERVISOR=$(CIRCUITPY_SUPERVISOR) +CIRCUITPY_SYNTHIO ?= $(CIRCUITPY_AUDIOCORE) +CFLAGS += -DCIRCUITPY_SYNTHIO=$(CIRCUITPY_SYNTHIO) + CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO) CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO) @@ -325,39 +328,34 @@ CFLAGS += -DCIRCUITPY_TOUCHIO=$(CIRCUITPY_TOUCHIO) CIRCUITPY_UHEAP ?= 0 CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP) -# Secondary CDC is usually available if there are at least 8 endpoints. -CIRCUITPY_USB_CDC ?= $(shell expr $(USB_NUM_EP) '>=' 8) +CIRCUITPY_USB ?= 1 +CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB) + +# If you need to count endpoints, do: +# $(shell expr $(USB_NUM_EP) '>=' 8) + +CIRCUITPY_USB_CDC ?= 1 CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC) +CIRCUITPY_USB_CDC_REPL_ENABLED ?= 1 +CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT) +CIRCUITPY_USB_CDC_DATA_ENABLED ?= 0 +CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT) CIRCUITPY_USB_HID ?= 1 CFLAGS += -DCIRCUITPY_USB_HID=$(CIRCUITPY_USB_HID) +CIRCUITPY_USB_HID_ENABLED_DEFAULT = $(CIRCUITPY_USB_HID) +CFLAGS += -DCIRCUITPY_USB_HID_ENABLED_DEFAULT=$(CIRCUITPY_USB_HID_ENABLED_DEFAULT) -CIRCUITPY_USB_HID_CONSUMER ?= 1 -CFLAGS += -DCIRCUITPY_USB_HID_CONSUMER=$(CIRCUITPY_USB_HID_CONSUMER) - -CIRCUITPY_USB_HID_DIGITIZER ?= 0 -CFLAGS += -DCIRCUITPY_USB_HID_DIGITIZER=$(CIRCUITPY_USB_HID_DIGITIZER) - -CIRCUITPY_USB_HID_GAMEPAD ?= 1 -CFLAGS += -DCIRCUITPY_USB_HID_GAMEPAD=$(CIRCUITPY_USB_HID_GAMEPAD) - -CIRCUITPY_USB_HID_KEYBOARD ?= 1 -CFLAGS += -DCIRCUITPY_USB_HID_KEYBOARD=$(CIRCUITPY_USB_HID_KEYBOARD) - -CIRCUITPY_USB_HID_MOUSE ?= 1 -CFLAGS += -DCIRCUITPY_USB_HID_MOUSE=$(CIRCUITPY_USB_HID_MOUSE) - -CIRCUITPY_USB_HID_SYS_CONTROL ?= 0 -CFLAGS += -DCIRCUITPY_USB_HID_SYS_CONTROL=$(CIRCUITPY_USB_HID_SYS_CONTROL) - -CIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD ?= 0 -CFLAGS += -DCIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD=$(CIRCUITPY_USB_HID_XAC_COMPATIBLE_GAMEPAD) - -CIRCUITPY_USB_MIDI ?= 1 +# MIDI is usually available if there are at least 8 endpoints. +CIRCUITPY_USB_MIDI ?= $(shell expr $(USB_NUM_EP) '>=' 8) CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI) +CIRCUITPY_USB_MIDI_ENABLED_DEFAULT = $(CIRCUITPY_USB_MIDI) +CFLAGS += -DCIRCUITPY_USB_MIDI_ENABLED_DEFAULT=$(CIRCUITPY_USB_MIDI_ENABLED_DEFAULT) CIRCUITPY_USB_MSC ?= 1 CFLAGS += -DCIRCUITPY_USB_MSC=$(CIRCUITPY_USB_MSC) +CIRCUITPY_USB_MSC_ENABLED_DEFAULT = $(CIRCUITPY_USB_MSC) +CFLAGS += -DCIRCUITPY_USB_MSC_ENABLED_DEFAULT=$(CIRCUITPY_USB_MSC_ENABLED_DEFAULT) # Defaulting this to OFF initially because it has only been tested on a # limited number of platforms, and the other platforms do not have this diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index fdecba53df..ccfaaaf96e 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -53,23 +53,19 @@ STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { mp_obj_iter_buf_t iter_buf; - mp_obj_t iterable = mp_getiter(devices, &iter_buf); - mp_obj_t device; - while ((device = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + + const mp_int_t len = mp_obj_get_int(mp_obj_len(devices_seq)); + for (size_t i = 0; i < len; i++) { + mp_obj_t item = mp_obj_subscr(devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { mp_raise_ValueError_varg(translate("non-Device in %q", MP_QSTR_devices)); } } - switch (common_hal_usb_hid_configure_usb(descriptors)) { - case USB_CONFIG_TOO_LATE: - mp_raise_RuntimeError(translate("Cannot change USB devices now")); - break; - case USB_CONFIG_NON_DEVICE: - mp_raise_ValueError_varg(translate("non-Device in %q", MP_QSTR_devices)); - break; - default: + if (!common_hal_usb_hid_configure_usb(descriptors)) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); } + return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_configure_usb_obj, usb_hid_configure_usb); diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index 925b3d5e91..89779a84a7 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -32,10 +32,7 @@ extern mp_obj_tuple_t common_hal_usb_hid_devices; -typedef enum { - USB_CONFIG_OK = 0, - USB_CONFIG_TOO_LATE = 1, - USB_CONFIG_NON_DEVICE = 2, -} usb_hid_configure_status; +void common_hal_usb_hid_configure_usb_defaults(void); +usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seq); -usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seqf // SHARED_BINDINGS_USB_HID_H +#endif // SHARED_BINDINGS_USB_HID_H diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 307f0a8e68..72eb1d8291 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -24,7 +24,6 @@ * THE SOFTWARE. */ -#include "genhdr/autogen_usb_descriptor.h" #include "py/gc.h" #include "py/obj.h" #include "py/mphal.h" diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 8d8f5b2e08..7ab6b7592b 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -51,6 +51,9 @@ static const uint8_t usb_hid_descriptor_template[] = { 0x08, // 21 bInterval 8 (unit depends on device speed) }; +// Sequence of devices to configure. +static mp_obj_t hid_devices_seq; + // Is the HID device enabled? bool usb_hid_enabled; supervisor_allocation *hid_report_descriptor_allocation; @@ -78,23 +81,35 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_hid_descriptor_template); } -usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seq) { +static mp_obj_t default_hid_devices[] = { + MP_OBJ_FROM_PTR(usb_hid_device_keyboard_obj), + MP_OBJ_FROM_PTR(usb_hid_device_mouse_obj), +}; + +// Set the default list of devices that will be included. Called before boot.py runs, in the boot.py VM. +void common_hal_usb_hid_configure_usb_defaults(void) { + common_hal_usb_hid_configure_usb(mp_obj_new_tuple(sizeof(default_hid_devices), default_hid_devices)); +} + +bool common_hal_usb_hid_configure_usb(mp_obj_t devices_seq) { // We can't change the devices once we're connected. if (tud_connected()) { - return USB_CONFIG_TOO_LATE; + return false; } - // Assume no devices to start. - usb_hid_enabled = false; - if (devices_seq == mp_const_none) { - return USB_CONFIG_OK; - } + // Remember the devices for use in usb_hid_post_boot_py. + hid_devices_seq = devices_seq; + return true; +} +// Build the combined HID report descriptor and save the chosen devices. +// Both are saved in supervisor allocations. +void usb_hid_post_boot_py(void) { size_t total_report_descriptors_length = 0; // Build a combined report descriptor - mp_int_t len = mp_obj_get_int(mp_obj_len(devices_seq)); + mp_int_t len = mp_obj_get_int(mp_obj_len(hid_devices_seq)); // First get the total size. for (size_t i = 0; i < len; i++) { @@ -128,7 +143,7 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seq) uint8_t *descriptor_start = (uint8_t *) hid_report_descriptor_allocation->ptr; for (size_t i = 0; i < len; i++) { - usb_hid_device_obj_t *device = MP_OBJ_TO_PTR(devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + usb_hid_device_obj_t *device = MP_OBJ_TO_PTR(hid_devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); // Copy the report descriptor for this device. if (len == 1) { @@ -150,6 +165,8 @@ usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seq) hid_devices[i].descriptor_obj = mp_const_none; } + // No longer keeping the Python object of devices to configure. + hid_devices_seq = MP_OBJ_NULL; } void usb_hid_gc_collect(void) { @@ -158,7 +175,8 @@ void usb_hid_gc_collect(void) { free_memory(hid_report_descriptor_allocation); free_memory(usb_hid_devices_allocation); } else { + gc_collect_ptr(hid_devices_seq); gc_collect_ptr(hid_report_descriptor_allocation->ptr); - gc_collect_ptr(usb_hid_devices_allocation); + gc_collect_ptr(usb_hid_devices_allocation_ptr); } } diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index d6abf7c9e5..14c3cfa5ae 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -26,7 +26,6 @@ #include "shared-bindings/usb_midi/__init__.h" -#include "genhdr/autogen_usb_descriptor.h" #include "py/obj.h" #include "py/mphal.h" #include "py/runtime.h" diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 0b23d56b9b..16f8d13c5f 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -38,8 +38,6 @@ #ifndef _TUSB_CONFIG_H_ #define _TUSB_CONFIG_H_ -#include "genhdr/autogen_usb_descriptor.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 5ce5083b17..983112f001 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -41,7 +41,6 @@ #include "tusb.h" #if CIRCUITPY_USB_VENDOR -#include "genhdr/autogen_usb_descriptor.h" // The WebUSB support being conditionally added to this file is based on the // tinyusb demo examples/device/webusb_serial. @@ -55,15 +54,17 @@ bool usb_enabled(void) { return tusb_inited(); } +// Initialization done only once, before boot.py is run. +void reset_usb(void) { + reset_usb_desc(); +} + + MP_WEAK void post_usb_init(void) { } void usb_init(void) { - usb_build_device_descriptor(); - usb_build_configuration_descriptor(); - usb_build_hid_descriptor(); - usb_build_string_descriptors(); - + usb_desc_init(); init_usb_hardware(); @@ -82,6 +83,13 @@ void usb_init(void) { #endif } +// Remember USB settings done during boot.py. +// The boot.py heap is still valid at this point. +void usb_post_boot_py(void) { + usb_desc_post_boot_py(); +} + + void usb_disconnect(void) { tud_disconnect(); } diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index ea67e3aaaf..b9c3e64951 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -44,10 +44,8 @@ #include "shared-module/usb_hid/Device.h" -#include "genhdr/autogen_usb_descriptor.h" - -supervisor_allocation *device_descriptor_allocation; -supervisor_allocation *config_descriptor_allocation; +uint8_t *device_descriptor; +uint8_t *config_descriptor; // Table for collecting interface strings (interface names) as descriptor is built. #define MAX_INTERFACE_STRINGS 16 @@ -99,31 +97,31 @@ static const uint8_t configuration_descriptor_template[] = { 0x32, // 8 bMaxPower 100mA }; -void usb_desc_init(void) { - uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; - common_hal_mcu_processor_get_uid(raw_id); +// Initialization done before boot.py is run. +// Turn on or off various USB devices. On devices with limited endpoints, +// some may be off by default. +void reset_usb_desc(void) { + // Set defaults for enabling/disabling of various USB devices. +#if CIRCUITPY_USB_CDC + common_hal_usb_cdc_configure_usb( + (bool) CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT, + (bool) CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT); +#endif - for (int i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) { - for (int j = 0; j < 2; j++) { - uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf; - serial_number_hex_string[i * 2 + (1 - j)] = nibble_to_hex_upper[nibble]; - } - } +#if CIRCUITPY_USB_MSC + common_hal_storage_configure_usb((bool) CIRCUITPY_USB_MSC_ENABLED_DEFAULT); +#endif - // Null-terminate the string. - serial_number_hex_string[sizeof(serial_number_hex_string)] = '\0'; +#if CIRCUITPY_USB_MIDI + common_hal_usb_midi_configure_usb((bool) CIRCUITPY_USB_MIDI_ENABLED_DEFAULT); +#endif - // Memory is cleared to zero when allocated; we depend on that. - collected_interface_strings = m_malloc(MAX_INTERFACE_STRINGS + 1, false); - current_interface_string = 1; +#if CIRCUITPY_USB_HID + common_hal_usb_hid_configure_usb_default(); +#endif } - -void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string) { - device_descriptor_allocation = - allocate_memory(sizeof(device_descriptor_template), false /*highaddress*/, true /*movable*/); - uint8_t *device_descriptor = (uint8_t *) device_descriptor_allocation->ptr; - +static void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string) { memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); device_descriptor[DEVICE_VID_LO_INDEX] = vid & 0xFF; @@ -144,7 +142,7 @@ void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_in (*current_interface_string)++; } -void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces) { +static void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces) { size_t total_descriptor_length = sizeof(configuration_descriptor_template); // CDC should be first, for compatibility with Adafruit Windows 7 drivers. @@ -178,11 +176,6 @@ void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_inter #endif // Now we now how big the configuration descriptor will be. - - configuration_descriptor_allocation = - allocate_memory(sizeof(configuration_descriptor_template), false /*highaddress*/, true /*movable*/); - uint8_t *configuration_descriptor = (uint8_t *) device_descriptor_allocation->ptr; - // Copy the top-level template, and fix up its length. memcpy(config_descriptor, configuration_descriptor_template, sizeof(configuration_descriptor_template)); configuration_descriptor[CONFIG_TOTAL_LENGTH_LO_INDEX] = total_descriptor_length & 0xFF; @@ -241,7 +234,7 @@ void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_inter } -void usb_add_interface_string(uint8_t interface_string_index, const char[] str) { +static void usb_add_interface_string(uint8_t interface_string_index, const char[] str) { if (interface_string_index > MAX_INTERFACE_STRINGS) { mp_raise_SystemError("Too many USB interface names"); } @@ -259,15 +252,45 @@ void usb_add_interface_string(uint8_t interface_string_index, const char[] str) } +// Remember USB information that must persist from the boot.py VM to the next VM. +// Some of this is already remembered in globals, for example, usb_midi_enabled and similar bools. +void usb_desc_post_boot_py(void) { + usb_hid_post_boot_py(); +} + +// Called in a the new VM created after boot.py is run. The USB devices to be used are now chosen. +static void usb_desc_init(void) { + uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; + common_hal_mcu_processor_get_uid(raw_id); + + for (int i = 0; i < COMMON_HAL_MCU_PROCESSOR_UID_LENGTH; i++) { + for (int j = 0; j < 2; j++) { + uint8_t nibble = (raw_id[i] >> (j * 4)) & 0xf; + serial_number_hex_string[i * 2 + (1 - j)] = nibble_to_hex_upper[nibble]; + } + } + + // Null-terminate the string. + serial_number_hex_string[sizeof(serial_number_hex_string)] = '\0'; + + // Memory is cleared to zero when allocated; we depend on that. + collected_interface_strings = m_malloc(MAX_INTERFACE_STRINGS + 1, false); + current_interface_string = 1; + + usb_build_device_descriptor(); + usb_build_configuration_descriptor(); + usb_build_hid_descriptor(); + usb_build_string_descriptors(); +} + void usb_desc_gc_collect(void) { // Once tud_mounted() is true, we're done with the constructed descriptors. if (tud_mounted()) { - // GC will pick up the inaccessible blocks. - free_memory(device_descriptor_allocation); - free_memory(configuration_descriptor_allocation); + gc_free(device_descriptor_allocation); + gc_free(configuration_descriptor); } else { - gc_collect_ptr(device_descriptor_allocation->ptr); - gc_collect_ptr(configuration_descriptor_allocation->ptr); + gc_collect_ptr(device_descriptor); + gc_collect_ptr(configuration_descriptor); } } diff --git a/tools/gen_separated_usb_descriptors.py b/tools/gen_separated_usb_descriptors.py deleted file mode 100644 index 1fad2fbeb3..0000000000 --- a/tools/gen_separated_usb_descriptors.py +++ /dev/null @@ -1,1064 +0,0 @@ -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -import argparse - -import os -import sys - -sys.path.append("../../tools/usb_descriptor") - -from adafruit_usb_descriptor import audio, audio10, cdc, hid, midi, msc, standard, util -import hid_report_descriptors - -DEFAULT_INTERFACE_NAME = "CircuitPython" -ALL_DEVICES = "CDC CDC2 MSC AUDIO HID VENDOR" -ALL_DEVICES_SET = frozenset(ALL_DEVICES.split()) -DEFAULT_DEVICES = "CDC MSC AUDIO HID" - -# This list is in preferred order. MacOS does not like GAMEPAD coming before MOUSE. -ALL_HID_DEVICES = ( - "KEYBOARD MOUSE CONSUMER SYS_CONTROL GAMEPAD DIGITIZER XAC_COMPATIBLE_GAMEPAD RAW" -) -ALL_HID_DEVICES_ORDER = dict((name, idx) for (idx, name) in enumerate(ALL_HID_DEVICES.split())) -ALL_HID_DEVICES_SET = frozenset(ALL_HID_DEVICES.split()) -# Digitizer works on Linux but conflicts with mouse, so omit it. -DEFAULT_HID_DEVICES = "KEYBOARD MOUSE CONSUMER GAMEPAD" - -# In the following URL, don't include the https:// because that prefix gets added automatically -DEFAULT_WEBUSB_URL = "circuitpython.org" # In the future, this may become a specific landing page - -parser = argparse.ArgumentParser(description="Generate USB descriptors.") -parser.add_argument( - "--highspeed", default=False, action="store_true", help="descriptor for highspeed device" -) -parser.add_argument("--manufacturer", type=str, help="manufacturer of the device") -parser.add_argument("--product", type=str, help="product name of the device") -parser.add_argument("--vid", type=lambda x: int(x, 16), help="vendor id") -parser.add_argument("--pid", type=lambda x: int(x, 16), help="product id") -parser.add_argument( - "--serial_number_length", - type=int, - default=32, - help="length needed for the serial number in digits", -) -parser.add_argument( - "--devices", - type=lambda l: tuple(l.split()), - default=DEFAULT_DEVICES, - 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( - "--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( - "--cdc2_ep_num_notification", type=int, default=0, help="endpoint number of CDC2 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( - "--cdc2_ep_num_data_out", type=int, default=0, help="endpoint number of CDC2 DATA OUT" -) -parser.add_argument( - "--cdc2_ep_num_data_in", type=int, default=0, help="endpoint number of CDC2 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("--max_ep", type=int, default=0, help="total number of endpoints available") -parser.add_argument( - "--webusb_url", - type=str, - help="The URL to include in the WebUSB URL Descriptor", - default=DEFAULT_WEBUSB_URL, -) -parser.add_argument( - "--vendor_ep_num_out", type=int, default=0, help="endpoint number of VENDOR OUT" -) -parser.add_argument("--vendor_ep_num_in", type=int, default=0, help="endpoint number of VENDOR IN") -parser.add_argument( - "--output_c_file", type=argparse.FileType("w", encoding="UTF-8"), required=True -) -parser.add_argument( - "--output_h_file", type=argparse.FileType("w", encoding="UTF-8"), required=True -) - -args = parser.parse_args() - -unknown_devices = list(frozenset(args.devices) - ALL_DEVICES_SET) -if unknown_devices: - raise ValueError("Unknown device(s)", unknown_devices) - -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) - -include_cdc = "CDC" in args.devices -include_cdc2 = "CDC2" in args.devices -include_msc = "MSC" in args.devices -include_hid = "HID" in args.devices -include_audio = "AUDIO" in args.devices -include_vendor = "VENDOR" in args.devices - -if not include_cdc and include_cdc2: - raise ValueError("CDC2 requested without CDC") - -if not args.renumber_endpoints: - if include_cdc: - if args.cdc_ep_num_notification == 0: - raise ValueError("CDC notification endpoint number must not be 0") - if args.cdc_ep_num_data_out == 0: - raise ValueError("CDC data OUT endpoint number must not be 0") - if args.cdc_ep_num_data_in == 0: - raise ValueError("CDC data IN endpoint number must not be 0") - - if include_cdc2: - if args.cdc2_ep_num_notification == 0: - raise ValueError("CDC2 notification endpoint number must not be 0") - if args.cdc2_ep_num_data_out == 0: - raise ValueError("CDC2 data OUT endpoint number must not be 0") - if args.cdc2_ep_num_data_in == 0: - raise ValueError("CDC2 data IN endpoint number must not be 0") - - if include_msc: - if args.msc_ep_num_out == 0: - raise ValueError("MSC endpoint OUT number must not be 0") - if args.msc_ep_num_in == 0: - raise ValueError("MSC endpoint IN number must not be 0") - - if include_hid: - if args.args.hid_ep_num_out == 0: - raise ValueError("HID endpoint OUT number must not be 0") - if args.hid_ep_num_in == 0: - raise ValueError("HID endpoint IN number must not be 0") - - if include_audio: - if args.args.midi_ep_num_out == 0: - raise ValueError("MIDI endpoint OUT number must not be 0") - if args.midi_ep_num_in == 0: - raise ValueError("MIDI endpoint IN number must not be 0") - - if include_vendor: - if args.vendor_ep_num_out == 0: - raise ValueError("VENDOR endpoint OUT number must not be 0") - if args.vendor_ep_num_in == 0: - raise ValueError("VENDOR endpoint IN number must not be 0") - - -class StringIndex: - """Assign a monotonically increasing index to each unique string. Start with 0.""" - - string_to_index = {} - index_to_variable = {} - strings = [] - - @classmethod - def index(cls, string, *, variable_name=None): - if string in cls.string_to_index: - idx = cls.string_to_index[string] - if not cls.index_to_variable[idx]: - cls.index_to_variable[idx] = variable_name - return idx - else: - idx = len(cls.strings) - cls.string_to_index[string] = idx - cls.strings.append(string) - cls.index_to_variable[idx] = variable_name - return idx - - @classmethod - def strings_in_order(cls): - return cls.strings - - -# langid must be the 0th string descriptor -LANGID_INDEX = StringIndex.index("\u0409", variable_name="language_id") -assert LANGID_INDEX == 0 -SERIAL_NUMBER_INDEX = StringIndex.index( - "S" * args.serial_number_length, variable_name="usb_serial_number" -) - -device = standard.DeviceDescriptor( - description="top", - idVendor=args.vid, - idProduct=args.pid, - iManufacturer=StringIndex.index(args.manufacturer), - iProduct=StringIndex.index(args.product), - iSerialNumber=SERIAL_NUMBER_INDEX, -) - -# Interface numbers are interface-set local and endpoints are interface local -# until util.join_interfaces renumbers them. - - -def make_cdc_union(name): - return cdc.Union( - description="{} comm".format(name), - # Set bMasterInterface and bSlaveInterface_list to proper values after interfaces are renumbered. - bMasterInterface=0x00, - bSlaveInterface_list=[0x01], - ) - - -def make_cdc_call_management(name): - # Set bDataInterface to proper value after interfaces are renumbered. - return cdc.CallManagement( - description="{} comm".format(name), bmCapabilities=0x01, bDataInterface=0x01 - ) - - -def make_cdc_comm_interface(name, cdc_union, cdc_call_management, cdc_ep_num_notification): - return standard.InterfaceDescriptor( - description="{} comm".format(name), - bInterfaceClass=cdc.CDC_CLASS_COMM, # Communications Device Class - bInterfaceSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model - bInterfaceProtocol=cdc.CDC_PROTOCOL_NONE, - iInterface=StringIndex.index("{} {} control".format(args.interface_name, name)), - subdescriptors=[ - cdc.Header(description="{} comm".format(name), bcdCDC=0x0110), - cdc_call_management, - cdc.AbstractControlManagement(description="{} comm".format(name), bmCapabilities=0x02), - cdc_union, - standard.EndpointDescriptor( - description="{} comm in".format(name), - bEndpointAddress=cdc_ep_num_notification - | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT, - wMaxPacketSize=0x0040, - bInterval=0x10, - ), - ], - ) - - -def make_cdc_data_interface(name, cdc_ep_num_data_in, cdc_ep_num_data_out): - return standard.InterfaceDescriptor( - description="{} data".format(name), - bInterfaceClass=cdc.CDC_CLASS_DATA, - iInterface=StringIndex.index("{} {} data".format(args.interface_name, name)), - subdescriptors=[ - standard.EndpointDescriptor( - description="{} data out".format(name), - bEndpointAddress=cdc_ep_num_data_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - standard.EndpointDescriptor( - description="{} data in".format(name), - bEndpointAddress=cdc_ep_num_data_in | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - ], - ) - - -if include_cdc: - cdc_union = make_cdc_union("CDC") - cdc_call_management = make_cdc_call_management("CDC") - cdc_comm_interface = make_cdc_comm_interface( - "CDC", cdc_union, cdc_call_management, args.cdc_ep_num_notification - ) - cdc_data_interface = make_cdc_data_interface( - "CDC", args.cdc_ep_num_data_in, args.cdc_ep_num_data_out - ) - - cdc_interfaces = [cdc_comm_interface, cdc_data_interface] - -if include_cdc2: - cdc2_union = make_cdc_union("CDC2") - cdc2_call_management = make_cdc_call_management("CDC2") - cdc2_comm_interface = make_cdc_comm_interface( - "CDC2", cdc2_union, cdc2_call_management, args.cdc2_ep_num_notification - ) - cdc2_data_interface = make_cdc_data_interface( - "CDC2", args.cdc2_ep_num_data_in, args.cdc2_ep_num_data_out - ) - - cdc2_interfaces = [cdc2_comm_interface, cdc2_data_interface] - -if include_msc: - msc_interfaces = [ - standard.InterfaceDescriptor( - description="MSC", - bInterfaceClass=msc.MSC_CLASS, - bInterfaceSubClass=msc.MSC_SUBCLASS_TRANSPARENT, - bInterfaceProtocol=msc.MSC_PROTOCOL_BULK, - iInterface=StringIndex.index("{} Mass Storage".format(args.interface_name)), - subdescriptors=[ - standard.EndpointDescriptor( - description="MSC in", - bEndpointAddress=args.msc_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - standard.EndpointDescriptor( - description="MSC out", - bEndpointAddress=( - args.msc_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT - ), - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - ], - ) - ] - - -if include_hid: - # When there's only one hid_device, it shouldn't have a report id. - # Otherwise, report ids are assigned sequentially: - # args.hid_devices[0] has report_id 1 - # args.hid_devices[1] has report_id 2 - # etc. - - report_ids = {} - - if len(args.hid_devices) == 1: - name = args.hid_devices[0] - combined_hid_report_descriptor = hid.ReportDescriptor( - description=name, - report_descriptor=bytes(hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](0)), - ) - report_ids[name] = 0 - else: - report_id = 1 - concatenated_descriptors = bytearray() - # Sort HID devices by preferred order. - for name in sorted(args.hid_devices, key=ALL_HID_DEVICES_ORDER.get): - concatenated_descriptors.extend( - bytes(hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](report_id)) - ) - report_ids[name] = report_id - report_id += 1 - combined_hid_report_descriptor = hid.ReportDescriptor( - description="MULTIDEVICE", report_descriptor=bytes(concatenated_descriptors) - ) - - # ASF4 expects keyboard and generic devices to have both in and out endpoints, - # and will fail (possibly silently) if both are not supplied. - hid_endpoint_in_descriptor = standard.EndpointDescriptor( - description="HID 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=args.hid_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT, - bInterval=8, - ) - - hid_interfaces = [ - standard.InterfaceDescriptor( - description="HID Multiple Devices", - bInterfaceClass=hid.HID_CLASS, - bInterfaceSubClass=hid.HID_SUBCLASS_NOBOOT, - bInterfaceProtocol=hid.HID_PROTOCOL_NONE, - iInterface=StringIndex.index("{} HID".format(args.interface_name)), - subdescriptors=[ - hid.HIDDescriptor( - description="HID", wDescriptorLength=len(bytes(combined_hid_report_descriptor)) - ), - hid_endpoint_in_descriptor, - hid_endpoint_out_descriptor, - ], - ) - ] - -if include_audio: - # Audio! - # In and out here are relative to CircuitPython - - # USB OUT -> midi_in_jack_emb -> midi_out_jack_ext -> CircuitPython - midi_in_jack_emb = midi.InJackDescriptor( - description="MIDI PC -> {}".format(args.interface_name), - bJackType=midi.JACK_TYPE_EMBEDDED, - 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, - input_pins=[(midi_in_jack_emb, 1)], - iJack=0, - ) - - # USB IN <- midi_out_jack_emb <- midi_in_jack_ext <- CircuitPython - midi_in_jack_ext = midi.InJackDescriptor( - description="MIDI data in from user code.", bJackType=midi.JACK_TYPE_EXTERNAL, iJack=0 - ) - midi_out_jack_emb = midi.OutJackDescriptor( - description="MIDI PC <- {}".format(args.interface_name), - bJackType=midi.JACK_TYPE_EMBEDDED, - input_pins=[(midi_in_jack_ext, 1)], - iJack=StringIndex.index("{} usb_midi.ports[1]".format(args.interface_name)), - ) - - audio_midi_interface = standard.InterfaceDescriptor( - description="Midi goodness", - bInterfaceClass=audio.AUDIO_CLASS_DEVICE, - bInterfaceSubClass=audio.AUDIO_SUBCLASS_MIDI_STREAMING, - bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, - iInterface=StringIndex.index("{} MIDI".format(args.interface_name)), - subdescriptors=[ - midi.Header( - jacks_and_elements=[ - midi_in_jack_emb, - midi_in_jack_ext, - midi_out_jack_emb, - midi_out_jack_ext, - ] - ), - standard.EndpointDescriptor( - description="MIDI data out to {}".format(args.interface_name), - bEndpointAddress=args.midi_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - midi.DataEndpointDescriptor(baAssocJack=[midi_in_jack_emb]), - standard.EndpointDescriptor( - 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, - wMaxPacketSize=512 if args.highspeed else 64, - ), - midi.DataEndpointDescriptor(baAssocJack=[midi_out_jack_emb]), - ], - ) - - cs_ac_interface = audio10.AudioControlInterface( - description="Empty audio control", - audio_streaming_interfaces=[], - midi_streaming_interfaces=[audio_midi_interface], - ) - - audio_control_interface = standard.InterfaceDescriptor( - description="All the audio", - bInterfaceClass=audio.AUDIO_CLASS_DEVICE, - bInterfaceSubClass=audio.AUDIO_SUBCLASS_CONTROL, - bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, - iInterface=StringIndex.index("{} Audio".format(args.interface_name)), - subdescriptors=[cs_ac_interface], - ) - - # Audio streaming interfaces must occur before MIDI ones. - audio_interfaces = ( - [audio_control_interface] - + cs_ac_interface.audio_streaming_interfaces - + cs_ac_interface.midi_streaming_interfaces - ) - -if include_vendor: - # Vendor-specific interface, for example WebUSB - vendor_endpoint_in_descriptor = standard.EndpointDescriptor( - description="VENDOR in", - bEndpointAddress=args.vendor_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=16, - ) - - vendor_endpoint_out_descriptor = standard.EndpointDescriptor( - description="VENDOR out", - bEndpointAddress=args.vendor_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=16, - ) - - vendor_interface = standard.InterfaceDescriptor( - description="VENDOR", - bInterfaceClass=0xFF, # Vendor-specific - bInterfaceSubClass=0x00, - bInterfaceProtocol=0x00, - iInterface=StringIndex.index("{} VENDOR".format(args.interface_name)), - subdescriptors=[vendor_endpoint_in_descriptor, vendor_endpoint_out_descriptor], - ) - - vendor_interfaces = [vendor_interface] - -interfaces_to_join = [] - -if include_cdc: - interfaces_to_join.append(cdc_interfaces) - -if include_cdc2: - interfaces_to_join.append(cdc2_interfaces) - -if include_msc: - interfaces_to_join.append(msc_interfaces) - -if include_hid: - interfaces_to_join.append(hid_interfaces) - -if include_audio: - interfaces_to_join.append(audio_interfaces) - -if include_vendor: - interfaces_to_join.append(vendor_interfaces) - -# 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, renumber_endpoints=args.renumber_endpoints) - -if args.max_ep != 0: - for interface in interfaces: - for subdescriptor in interface.subdescriptors: - endpoint_address = getattr(subdescriptor, "bEndpointAddress", 0) & 0x7F - if endpoint_address >= args.max_ep: - raise ValueError( - "Endpoint address %d of '%s' must be less than %d; you have probably run out of endpoints" - % (endpoint_address & 0x7F, interface.description, args.max_ep) - ) -else: - print("Unable to check whether maximum number of endpoints is respected", file=sys.stderr) - -# Now adjust the CDC interface cross-references. - -if include_cdc: - cdc_union.bMasterInterface = cdc_comm_interface.bInterfaceNumber - cdc_union.bSlaveInterface_list = [cdc_data_interface.bInterfaceNumber] - - cdc_call_management.bDataInterface = cdc_data_interface.bInterfaceNumber - -if include_cdc2: - cdc2_union.bMasterInterface = cdc2_comm_interface.bInterfaceNumber - cdc2_union.bSlaveInterface_list = [cdc2_data_interface.bInterfaceNumber] - - cdc2_call_management.bDataInterface = cdc2_data_interface.bInterfaceNumber - - -def make_cdc_iad(cdc_comm_interface, name): - return standard.InterfaceAssociationDescriptor( - description="{} IAD".format(name), - bFirstInterface=cdc_comm_interface.bInterfaceNumber, - bInterfaceCount=len(cdc_interfaces), - bFunctionClass=cdc.CDC_CLASS_COMM, # Communications Device Class - bFunctionSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model - bFunctionProtocol=cdc.CDC_PROTOCOL_NONE, - ) - - -if include_cdc: - cdc_iad = make_cdc_iad(cdc_comm_interface, "CDC") -if include_cdc2: - cdc2_iad = make_cdc_iad(cdc2_comm_interface, "CDC2") - -descriptor_list = [] - -if include_cdc: - # Put the CDC IAD just before the CDC interfaces. - # There appears to be a bug in the Windows composite USB driver that requests the - # HID report descriptor with the wrong interface number if the HID interface is not given - # first. However, it still fetches the descriptor anyway. We could reorder the interfaces but - # the Windows 7 Adafruit_usbser.inf file thinks CDC is at Interface 0, so we'll leave it - # there for backwards compatibility. - descriptor_list.append(cdc_iad) - descriptor_list.extend(cdc_interfaces) - -if include_cdc2: - descriptor_list.append(cdc2_iad) - descriptor_list.extend(cdc2_interfaces) - -if include_msc: - descriptor_list.extend(msc_interfaces) - -if include_hid: - descriptor_list.extend(hid_interfaces) - -if include_audio: - # Only add the control interface because other audio interfaces are managed by it to ensure the - # correct ordering. - descriptor_list.append(audio_control_interface) - -if include_vendor: - descriptor_list.extend(vendor_interfaces) - -# Finally, build the composite descriptor. - -configuration = standard.ConfigurationDescriptor( - description="Composite configuration", - wTotalLength=( - standard.ConfigurationDescriptor.bLength + sum([len(bytes(x)) for x in descriptor_list]) - ), - bNumInterfaces=len(interfaces), - # bus powered (bit 6), remote wakeup (bit 5), - # bit 7 is always 1 and 0-4 are always 0 - # Turn off remote wakeup until we handle it in CircuitPython. - bmAttributes=0x80, - -) -descriptor_list.insert(0, configuration) - -string_descriptors = [ - standard.StringDescriptor(string) for string in StringIndex.strings_in_order() -] -serial_number_descriptor = string_descriptors[SERIAL_NUMBER_INDEX] - -c_file = args.output_c_file -h_file = args.output_h_file - - -c_file.write( - """\ -#include - -#include "tusb.h" -#include "py/objtuple.h" -#include "shared-bindings/usb_hid/Device.h" -#include "{H_FILE_NAME}" - -""".format( - H_FILE_NAME=h_file.name - ) -) - -c_file.write( - """\ -// {DESCRIPTION} : {CLASS} -""".format( - DESCRIPTION=device.description, CLASS=device.__class__ - ) -) - -c_file.write( - """\ -const uint8_t usb_desc_dev[] = { -""" -) -for b in bytes(device): - c_file.write("0x{:02x}, ".format(b)) - -c_file.write( - """\ -}; -""" -) - -c_file.write( - """\ -const uint8_t usb_desc_cfg[] = { -""" -) - -# Write out all the regular descriptors as one long array (that's how ASF4 does it). -descriptor_length = 0 -for descriptor in descriptor_list: - c_file.write( - """\ -// {DESCRIPTION} : {CLASS} -""".format( - DESCRIPTION=descriptor.description, CLASS=descriptor.__class__ - ) - ) - - b = bytes(descriptor) - notes = descriptor.notes() - i = 0 - - # This prints each subdescriptor on a separate line. - n = 0 - while i < len(b): - length = b[i] - for j in range(length): - c_file.write("0x{:02x}, ".format(b[i + j])) - c_file.write("// " + notes[n]) - n += 1 - c_file.write("\n") - i += length - descriptor_length += len(b) - -c_file.write( - """\ -}; -""" -) - -pointers_to_strings = [] - -for idx, descriptor in enumerate(string_descriptors): - c_file.write( - """\ -// {DESCRIPTION} : {CLASS} -""".format( - DESCRIPTION=descriptor.description, CLASS=descriptor.__class__ - ) - ) - - b = bytes(descriptor) - notes = descriptor.notes() - i = 0 - - # This prints each subdescriptor on a separate line. - variable_name = StringIndex.index_to_variable[idx] - if not variable_name: - variable_name = "string_descriptor{}".format(idx) - pointers_to_strings.append("{name}".format(name=variable_name)) - - const = "const " - if variable_name == "usb_serial_number": - length = len(b) - c_file.write( - " uint16_t {NAME}[{length}];\n".format(NAME=variable_name, length=length // 2) - ) - else: - c_file.write( - """\ - const uint16_t {NAME}[] = {{ - """.format( - const=const, NAME=variable_name - ) - ) - n = 0 - while i < len(b): - length = b[i] - for j in range(length // 2): - c_file.write("0x{:04x}, ".format(b[i + 2 * j + 1] << 8 | b[i + 2 * j])) - n += 1 - c_file.write("\n") - i += length - c_file.write( - """\ - }; - """ - ) - -c_file.write( - """\ -// array of pointer to string descriptors -uint16_t const * const string_desc_arr [] = -{ -""" -) -c_file.write( - """,\ - -""".join( - pointers_to_strings - ) -) - -c_file.write( - """ -}; -""" -) - -c_file.write("\n") - -if include_hid: - hid_descriptor_length = len(bytes(combined_hid_report_descriptor)) -else: - hid_descriptor_length = 0 - -# Now the values we need for the .h file. -h_file.write( - """\ -#ifndef MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H -#define MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H - -#include - -extern const uint8_t usb_desc_dev[{device_length}]; -extern const uint8_t usb_desc_cfg[{configuration_length}]; -extern uint16_t usb_serial_number[{serial_number_length}]; -extern uint16_t const * const string_desc_arr [{string_descriptor_length}]; - -#define CFG_TUSB_RHPORT0_MODE ({rhport0_mode}) - -// Vendor name included in Inquiry response, max 8 bytes -#define CFG_TUD_MSC_VENDOR "{msc_vendor}" - -// Product name included in Inquiry response, max 16 bytes -#define CFG_TUD_MSC_PRODUCT "{msc_product}" - -""".format( - serial_number_length=len(bytes(serial_number_descriptor)) // 2, - device_length=len(bytes(device)), - configuration_length=descriptor_length, - max_configuration_length=max(hid_descriptor_length, descriptor_length), - string_descriptor_length=len(pointers_to_strings), - rhport0_mode="OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED" - if args.highspeed - else "OPT_MODE_DEVICE", - msc_vendor=args.manufacturer[:8], - msc_product=args.product[:16], - ) -) - -if include_hid: - h_file.write( - """\ -extern const uint8_t hid_report_descriptor[{hid_report_descriptor_length}]; - -#define USB_HID_NUM_DEVICES {hid_num_devices} -""".format( - hid_report_descriptor_length=len(bytes(combined_hid_report_descriptor)), - hid_num_devices=len(args.hid_devices), - ) - ) - -if include_vendor: - h_file.write( - """\ -enum -{ - VENDOR_REQUEST_WEBUSB = 1, - VENDOR_REQUEST_MICROSOFT = 2 -}; - -extern uint8_t const desc_ms_os_20[]; - -// Currently getting compile-time errors in files like tusb_fifo.c -// if we try do define this here (TODO figure this out!) -//extern const tusb_desc_webusb_url_t desc_webusb_url; - -""" - ) - -h_file.write( - """\ -#endif // MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H -""" -) - -if include_hid: - # Write out the report descriptor and info - c_file.write( - """\ -const uint8_t hid_report_descriptor[{HID_DESCRIPTOR_LENGTH}] = {{ -""".format( - HID_DESCRIPTOR_LENGTH=hid_descriptor_length - ) - ) - - for b in bytes(combined_hid_report_descriptor): - c_file.write("0x{:02x}, ".format(b)) - - c_file.write( - """\ -}; - -""" - ) - - # Write out USB HID report buffer definitions. - for name in args.hid_devices: - c_file.write( - """\ -static uint8_t {name}_report_buffer[{report_length}]; -""".format( - name=name.lower(), - report_length=hid_report_descriptors.HID_DEVICE_DATA[name].report_length, - ) - ) - - if hid_report_descriptors.HID_DEVICE_DATA[name].out_report_length > 0: - c_file.write( - """\ -static uint8_t {name}_out_report_buffer[{report_length}]; -""".format( - name=name.lower(), - report_length=hid_report_descriptors.HID_DEVICE_DATA[name].out_report_length, - ) - ) - - # Write out table of device objects. - c_file.write( - """\ -usb_hid_device_obj_t usb_hid_devices[] = { -""" - ) - for name in args.hid_devices: - device_data = hid_report_descriptors.HID_DEVICE_DATA[name] - out_report_buffer = ( - "{}_out_report_buffer".format(name.lower()) - if device_data.out_report_length > 0 - else "NULL" - ) - c_file.write( - """\ - {{ - .base = {{ .type = &usb_hid_device_type }}, - .report_buffer = {name}_report_buffer, - .report_id = {report_id}, - .report_length = {report_length}, - .usage_page = {usage_page:#04x}, - .usage = {usage:#04x}, - .out_report_buffer = {out_report_buffer}, - .out_report_length = {out_report_length}, - }}, -""".format( - name=name.lower(), - report_id=report_ids[name], - report_length=device_data.report_length, - usage_page=device_data.usage_page, - usage=device_data.usage, - out_report_buffer=out_report_buffer, - out_report_length=device_data.out_report_length, - ) - ) - c_file.write( - """\ -}; -""" - ) - - # Write out tuple of device objects. - c_file.write( - """ -mp_obj_tuple_t common_hal_usb_hid_devices = {{ - .base = {{ - .type = &mp_type_tuple, - }}, - .len = {num_devices}, - .items = {{ -""".format( - num_devices=len(args.hid_devices) - ) - ) - for idx in range(len(args.hid_devices)): - c_file.write( - """\ - (mp_obj_t) &usb_hid_devices[{idx}], -""".format( - idx=idx - ) - ) - c_file.write( - """\ - }, -}; -""" - ) - -if include_vendor: - # Mimic what the tinyusb webusb demo does in its main.c file - c_file.write( - """ -#define URL "{webusb_url}" - -const tusb_desc_webusb_url_t desc_webusb_url = -{{ - .bLength = 3 + sizeof(URL) - 1, - .bDescriptorType = 3, // WEBUSB URL type - .bScheme = 1, // 0: http, 1: https, 255: "" - .url = URL -}}; - -// These next two hardcoded descriptors were pulled from the usb_descriptor.c file -// of the tinyusb webusb_serial demo. TODO - this is probably something else to -// integrate into the adafruit_usb_descriptors project... - -//--------------------------------------------------------------------+ -// BOS Descriptor -//--------------------------------------------------------------------+ - -/* Microsoft OS 2.0 registry property descriptor -Per MS requirements https://msdn.microsoft.com/en-us/library/windows/hardware/hh450799(v=vs.85).aspx -device should create DeviceInterfaceGUIDs. It can be done by driver and -in case of real PnP solution device should expose MS "Microsoft OS 2.0 -registry property descriptor". Such descriptor can insert any record -into Windows registry per device/configuration/interface. In our case it -will insert "DeviceInterfaceGUIDs" multistring property. - -GUID is freshly generated and should be OK to use. - -https://developers.google.com/web/fundamentals/native-hardware/build-for-webusb/ -(Section Microsoft OS compatibility descriptors) -*/ - -#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) - -#define MS_OS_20_DESC_LEN 0xB2 - -// BOS Descriptor is required for webUSB -uint8_t const desc_bos[] = -{{ - // total length, number of device caps - TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2), - - // Vendor Code, iLandingPage - TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1), - - // Microsoft OS 2.0 descriptor - TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) -}}; - -uint8_t const * tud_descriptor_bos_cb(void) -{{ - return desc_bos; -}} - - -#define ITF_NUM_VENDOR {webusb_interface} // used in this next descriptor - -uint8_t const desc_ms_os_20[] = -{{ - // Set header: length, type, windows version, total length - U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN), - - // Configuration subset header: length, type, configuration index, reserved, configuration total length - U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A), - - // Function Subset header: length, type, first interface, reserved, subset length - U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_VENDOR, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08), - - // MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID - U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible - - // MS OS 2.0 Registry property descriptor: length, type - U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), - U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16 - 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, - 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00, - U16_TO_U8S_LE(0x0050), // wPropertyDataLength - //bPropertyData: “{{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}}”. - '{{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00, - '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, - '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00, - '8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}}', 0x00, 0x00, 0x00, 0x00, 0x00 -}}; - -TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size"); - -// End of section about desc_ms_os_20 - -""".format( - webusb_url=args.webusb_url, webusb_interface=vendor_interface.bInterfaceNumber - ) - ) diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py deleted file mode 100644 index b873e75cc7..0000000000 --- a/tools/gen_usb_descriptor.py +++ /dev/null @@ -1,1059 +0,0 @@ -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -import argparse - -import os -import sys - -sys.path.append("../../tools/usb_descriptor") - -from adafruit_usb_descriptor import audio, audio10, cdc, hid, midi, msc, standard, util -import hid_report_descriptors - -DEFAULT_INTERFACE_NAME = "CircuitPython" -ALL_DEVICES = "CDC CDC2 MSC AUDIO HID VENDOR" -ALL_DEVICES_SET = frozenset(ALL_DEVICES.split()) -DEFAULT_DEVICES = "CDC MSC AUDIO HID" - -# This list is in preferred order. MacOS does not like GAMEPAD coming before MOUSE. -ALL_HID_DEVICES = ( - "KEYBOARD MOUSE CONSUMER SYS_CONTROL GAMEPAD DIGITIZER XAC_COMPATIBLE_GAMEPAD RAW" -) -ALL_HID_DEVICES_ORDER = dict((name, idx) for (idx, name) in enumerate(ALL_HID_DEVICES.split())) -ALL_HID_DEVICES_SET = frozenset(ALL_HID_DEVICES.split()) -# Digitizer works on Linux but conflicts with mouse, so omit it. -DEFAULT_HID_DEVICES = "KEYBOARD MOUSE CONSUMER GAMEPAD" - -# In the following URL, don't include the https:// because that prefix gets added automatically -DEFAULT_WEBUSB_URL = "circuitpython.org" # In the future, this may become a specific landing page - -parser = argparse.ArgumentParser(description="Generate USB descriptors.") -parser.add_argument( - "--highspeed", default=False, action="store_true", help="descriptor for highspeed device" -) -parser.add_argument("--manufacturer", type=str, help="manufacturer of the device") -parser.add_argument("--product", type=str, help="product name of the device") -parser.add_argument("--vid", type=lambda x: int(x, 16), help="vendor id") -parser.add_argument("--pid", type=lambda x: int(x, 16), help="product id") -parser.add_argument( - "--serial_number_length", - type=int, - default=32, - help="length needed for the serial number in digits", -) -parser.add_argument( - "--devices", - type=lambda l: tuple(l.split()), - default=DEFAULT_DEVICES, - 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( - "--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( - "--cdc2_ep_num_notification", type=int, default=0, help="endpoint number of CDC2 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( - "--cdc2_ep_num_data_out", type=int, default=0, help="endpoint number of CDC2 DATA OUT" -) -parser.add_argument( - "--cdc2_ep_num_data_in", type=int, default=0, help="endpoint number of CDC2 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("--max_ep", type=int, default=0, help="total number of endpoints available") -parser.add_argument( - "--webusb_url", - type=str, - help="The URL to include in the WebUSB URL Descriptor", - default=DEFAULT_WEBUSB_URL, -) -parser.add_argument( - "--vendor_ep_num_out", type=int, default=0, help="endpoint number of VENDOR OUT" -) -parser.add_argument("--vendor_ep_num_in", type=int, default=0, help="endpoint number of VENDOR IN") -parser.add_argument( - "--output_c_file", type=argparse.FileType("w", encoding="UTF-8"), required=True -) -parser.add_argument( - "--output_h_file", type=argparse.FileType("w", encoding="UTF-8"), required=True -) - -args = parser.parse_args() - -unknown_devices = list(frozenset(args.devices) - ALL_DEVICES_SET) -if unknown_devices: - raise ValueError("Unknown device(s)", unknown_devices) - -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) - -include_cdc = "CDC" in args.devices -include_cdc2 = "CDC2" in args.devices -include_msc = "MSC" in args.devices -include_hid = "HID" in args.devices -include_audio = "AUDIO" in args.devices -include_vendor = "VENDOR" in args.devices - -if not include_cdc and include_cdc2: - raise ValueError("CDC2 requested without CDC") - -if not args.renumber_endpoints: - if include_cdc: - if args.cdc_ep_num_notification == 0: - raise ValueError("CDC notification endpoint number must not be 0") - if args.cdc_ep_num_data_out == 0: - raise ValueError("CDC data OUT endpoint number must not be 0") - if args.cdc_ep_num_data_in == 0: - raise ValueError("CDC data IN endpoint number must not be 0") - - if include_cdc2: - if args.cdc2_ep_num_notification == 0: - raise ValueError("CDC2 notification endpoint number must not be 0") - if args.cdc2_ep_num_data_out == 0: - raise ValueError("CDC2 data OUT endpoint number must not be 0") - if args.cdc2_ep_num_data_in == 0: - raise ValueError("CDC2 data IN endpoint number must not be 0") - - if include_msc: - if args.msc_ep_num_out == 0: - raise ValueError("MSC endpoint OUT number must not be 0") - if args.msc_ep_num_in == 0: - raise ValueError("MSC endpoint IN number must not be 0") - - if include_hid: - if args.args.hid_ep_num_out == 0: - raise ValueError("HID endpoint OUT number must not be 0") - if args.hid_ep_num_in == 0: - raise ValueError("HID endpoint IN number must not be 0") - - if include_audio: - if args.args.midi_ep_num_out == 0: - raise ValueError("MIDI endpoint OUT number must not be 0") - if args.midi_ep_num_in == 0: - raise ValueError("MIDI endpoint IN number must not be 0") - - if include_vendor: - if args.vendor_ep_num_out == 0: - raise ValueError("VENDOR endpoint OUT number must not be 0") - if args.vendor_ep_num_in == 0: - raise ValueError("VENDOR endpoint IN number must not be 0") - - -class StringIndex: - """Assign a monotonically increasing index to each unique string. Start with 0.""" - - string_to_index = {} - index_to_variable = {} - strings = [] - - @classmethod - def index(cls, string, *, variable_name=None): - if string in cls.string_to_index: - idx = cls.string_to_index[string] - if not cls.index_to_variable[idx]: - cls.index_to_variable[idx] = variable_name - return idx - else: - idx = len(cls.strings) - cls.string_to_index[string] = idx - cls.strings.append(string) - cls.index_to_variable[idx] = variable_name - return idx - - @classmethod - def strings_in_order(cls): - return cls.strings - - -# langid must be the 0th string descriptor -LANGID_INDEX = StringIndex.index("\u0409", variable_name="language_id") -assert LANGID_INDEX == 0 -SERIAL_NUMBER_INDEX = StringIndex.index( - "S" * args.serial_number_length, variable_name="usb_serial_number" -) - -device = standard.DeviceDescriptor( - description="top", - idVendor=args.vid, - idProduct=args.pid, - iManufacturer=StringIndex.index(args.manufacturer), - iProduct=StringIndex.index(args.product), - iSerialNumber=SERIAL_NUMBER_INDEX, -) - -# Interface numbers are interface-set local and endpoints are interface local -# until util.join_interfaces renumbers them. - - -def make_cdc_union(name): - return cdc.Union( - description="{} comm".format(name), - # Set bMasterInterface and bSlaveInterface_list to proper values after interfaces are renumbered. - bMasterInterface=0x00, - bSlaveInterface_list=[0x01], - ) - - -def make_cdc_call_management(name): - # Set bDataInterface to proper value after interfaces are renumbered. - return cdc.CallManagement( - description="{} comm".format(name), bmCapabilities=0x01, bDataInterface=0x01 - ) - - -def make_cdc_comm_interface(name, cdc_union, cdc_call_management, cdc_ep_num_notification): - return standard.InterfaceDescriptor( - description="{} comm".format(name), - bInterfaceClass=cdc.CDC_CLASS_COMM, # Communications Device Class - bInterfaceSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model - bInterfaceProtocol=cdc.CDC_PROTOCOL_NONE, - iInterface=StringIndex.index("{} {} control".format(args.interface_name, name)), - subdescriptors=[ - cdc.Header(description="{} comm".format(name), bcdCDC=0x0110), - cdc_call_management, - cdc.AbstractControlManagement(description="{} comm".format(name), bmCapabilities=0x02), - cdc_union, - standard.EndpointDescriptor( - description="{} comm in".format(name), - bEndpointAddress=cdc_ep_num_notification - | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT, - wMaxPacketSize=0x0040, - bInterval=0x10, - ), - ], - ) - - -def make_cdc_data_interface(name, cdc_ep_num_data_in, cdc_ep_num_data_out): - return standard.InterfaceDescriptor( - description="{} data".format(name), - bInterfaceClass=cdc.CDC_CLASS_DATA, - iInterface=StringIndex.index("{} {} data".format(args.interface_name, name)), - subdescriptors=[ - standard.EndpointDescriptor( - description="{} data out".format(name), - bEndpointAddress=cdc_ep_num_data_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - standard.EndpointDescriptor( - description="{} data in".format(name), - bEndpointAddress=cdc_ep_num_data_in | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - ], - ) - - -if include_cdc: - cdc_union = make_cdc_union("CDC") - cdc_call_management = make_cdc_call_management("CDC") - cdc_comm_interface = make_cdc_comm_interface( - "CDC", cdc_union, cdc_call_management, args.cdc_ep_num_notification - ) - cdc_data_interface = make_cdc_data_interface( - "CDC", args.cdc_ep_num_data_in, args.cdc_ep_num_data_out - ) - - cdc_interfaces = [cdc_comm_interface, cdc_data_interface] - -if include_cdc2: - cdc2_union = make_cdc_union("CDC2") - cdc2_call_management = make_cdc_call_management("CDC2") - cdc2_comm_interface = make_cdc_comm_interface( - "CDC2", cdc2_union, cdc2_call_management, args.cdc2_ep_num_notification - ) - cdc2_data_interface = make_cdc_data_interface( - "CDC2", args.cdc2_ep_num_data_in, args.cdc2_ep_num_data_out - ) - - cdc2_interfaces = [cdc2_comm_interface, cdc2_data_interface] - -if include_msc: - msc_interfaces = [ - standard.InterfaceDescriptor( - description="MSC", - bInterfaceClass=msc.MSC_CLASS, - bInterfaceSubClass=msc.MSC_SUBCLASS_TRANSPARENT, - bInterfaceProtocol=msc.MSC_PROTOCOL_BULK, - iInterface=StringIndex.index("{} Mass Storage".format(args.interface_name)), - subdescriptors=[ - standard.EndpointDescriptor( - description="MSC in", - bEndpointAddress=args.msc_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - standard.EndpointDescriptor( - description="MSC out", - bEndpointAddress=( - args.msc_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT - ), - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - ], - ) - ] - - -if include_hid: - # When there's only one hid_device, it shouldn't have a report id. - # Otherwise, report ids are assigned sequentially, starting at 1. - # args.hid_devices[0] has report_id 1 - # args.hid_devices[1] has report_id 2 - # etc. - - report_ids = {} - - if len(args.hid_devices) == 1: - name = args.hid_devices[0] - hid_descriptor = hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](None) - concatenated_hid_report_descriptors = bytes( - hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](report_id=0)) - report_ids[name] = 0 - else: - report_id = 1 - concatenated_hid_report_descriptors = bytearray() - # Sort HID devices by preferred order. - for name in sorted(args.hid_devices, key=ALL_HID_DEVICES_ORDER.get): - hid_report_descriptor = hid_report_descriptors.REPORT_DESCRIPTOR_FUNCTIONS[name](report_id) - concatenated_hid_report_descriptors.extend(bytes(hid_report_descriptor)) - report_ids[name] = report_id - report_id += 1 - - # ASF4 expects keyboard and generic devices to have both in and out endpoints, - # and will fail (possibly silently) if both are not supplied. - hid_endpoint_in_descriptor = standard.EndpointDescriptor( - description="HID 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=args.hid_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_INTERRUPT, - bInterval=8, - ) - - hid_interfaces = [ - standard.InterfaceDescriptor( - description="HID Multiple Devices", - bInterfaceClass=hid.HID_CLASS, - bInterfaceSubClass=hid.HID_SUBCLASS_NOBOOT, - bInterfaceProtocol=hid.HID_PROTOCOL_NONE, - iInterface=StringIndex.index("{} HID".format(args.interface_name)), - subdescriptors=[ - hid.HIDDescriptor( - description="HID", wDescriptorLength=len(concatenated_hid_report_descriptors) - ), - hid_endpoint_in_descriptor, - hid_endpoint_out_descriptor, - ], - ) - ] - -if include_audio: - # Audio! - # In and out here are relative to CircuitPython - - # USB OUT -> midi_in_jack_emb -> midi_out_jack_ext -> CircuitPython - midi_in_jack_emb = midi.InJackDescriptor( - description="MIDI PC -> {}".format(args.interface_name), - bJackType=midi.JACK_TYPE_EMBEDDED, - 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, - input_pins=[(midi_in_jack_emb, 1)], - iJack=0, - ) - - # USB IN <- midi_out_jack_emb <- midi_in_jack_ext <- CircuitPython - midi_in_jack_ext = midi.InJackDescriptor( - description="MIDI data in from user code.", bJackType=midi.JACK_TYPE_EXTERNAL, iJack=0 - ) - midi_out_jack_emb = midi.OutJackDescriptor( - description="MIDI PC <- {}".format(args.interface_name), - bJackType=midi.JACK_TYPE_EMBEDDED, - input_pins=[(midi_in_jack_ext, 1)], - iJack=StringIndex.index("{} usb_midi.ports[1]".format(args.interface_name)), - ) - - audio_midi_interface = standard.InterfaceDescriptor( - description="Midi goodness", - bInterfaceClass=audio.AUDIO_CLASS_DEVICE, - bInterfaceSubClass=audio.AUDIO_SUBCLASS_MIDI_STREAMING, - bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, - iInterface=StringIndex.index("{} MIDI".format(args.interface_name)), - subdescriptors=[ - midi.Header( - jacks_and_elements=[ - midi_in_jack_emb, - midi_in_jack_ext, - midi_out_jack_emb, - midi_out_jack_ext, - ] - ), - standard.EndpointDescriptor( - description="MIDI data out to {}".format(args.interface_name), - bEndpointAddress=args.midi_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=0, - wMaxPacketSize=512 if args.highspeed else 64, - ), - midi.DataEndpointDescriptor(baAssocJack=[midi_in_jack_emb]), - standard.EndpointDescriptor( - 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, - wMaxPacketSize=512 if args.highspeed else 64, - ), - midi.DataEndpointDescriptor(baAssocJack=[midi_out_jack_emb]), - ], - ) - - cs_ac_interface = audio10.AudioControlInterface( - description="Empty audio control", - audio_streaming_interfaces=[], - midi_streaming_interfaces=[audio_midi_interface], - ) - - audio_control_interface = standard.InterfaceDescriptor( - description="All the audio", - bInterfaceClass=audio.AUDIO_CLASS_DEVICE, - bInterfaceSubClass=audio.AUDIO_SUBCLASS_CONTROL, - bInterfaceProtocol=audio.AUDIO_PROTOCOL_V1, - iInterface=StringIndex.index("{} Audio".format(args.interface_name)), - subdescriptors=[cs_ac_interface], - ) - - # Audio streaming interfaces must occur before MIDI ones. - audio_interfaces = ( - [audio_control_interface] - + cs_ac_interface.audio_streaming_interfaces - + cs_ac_interface.midi_streaming_interfaces - ) - -if include_vendor: - # Vendor-specific interface, for example WebUSB - vendor_endpoint_in_descriptor = standard.EndpointDescriptor( - description="VENDOR in", - bEndpointAddress=args.vendor_ep_num_in | standard.EndpointDescriptor.DIRECTION_IN, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=16, - ) - - vendor_endpoint_out_descriptor = standard.EndpointDescriptor( - description="VENDOR out", - bEndpointAddress=args.vendor_ep_num_out | standard.EndpointDescriptor.DIRECTION_OUT, - bmAttributes=standard.EndpointDescriptor.TYPE_BULK, - bInterval=16, - ) - - vendor_interface = standard.InterfaceDescriptor( - description="VENDOR", - bInterfaceClass=0xFF, # Vendor-specific - bInterfaceSubClass=0x00, - bInterfaceProtocol=0x00, - iInterface=StringIndex.index("{} VENDOR".format(args.interface_name)), - subdescriptors=[vendor_endpoint_in_descriptor, vendor_endpoint_out_descriptor], - ) - - vendor_interfaces = [vendor_interface] - -interfaces_to_join = [] - -if include_cdc: - interfaces_to_join.append(cdc_interfaces) - -if include_cdc2: - interfaces_to_join.append(cdc2_interfaces) - -if include_msc: - interfaces_to_join.append(msc_interfaces) - -if include_hid: - interfaces_to_join.append(hid_interfaces) - -if include_audio: - interfaces_to_join.append(audio_interfaces) - -if include_vendor: - interfaces_to_join.append(vendor_interfaces) - -# 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, renumber_endpoints=args.renumber_endpoints) - -if args.max_ep != 0: - for interface in interfaces: - for subdescriptor in interface.subdescriptors: - endpoint_address = getattr(subdescriptor, "bEndpointAddress", 0) & 0x7F - if endpoint_address >= args.max_ep: - raise ValueError( - "Endpoint address %d of '%s' must be less than %d; you have probably run out of endpoints" - % (endpoint_address & 0x7F, interface.description, args.max_ep) - ) -else: - print("Unable to check whether maximum number of endpoints is respected", file=sys.stderr) - -# Now adjust the CDC interface cross-references. - -if include_cdc: - cdc_union.bMasterInterface = cdc_comm_interface.bInterfaceNumber - cdc_union.bSlaveInterface_list = [cdc_data_interface.bInterfaceNumber] - - cdc_call_management.bDataInterface = cdc_data_interface.bInterfaceNumber - -if include_cdc2: - cdc2_union.bMasterInterface = cdc2_comm_interface.bInterfaceNumber - cdc2_union.bSlaveInterface_list = [cdc2_data_interface.bInterfaceNumber] - - cdc2_call_management.bDataInterface = cdc2_data_interface.bInterfaceNumber - - -def make_cdc_iad(cdc_comm_interface, name): - return standard.InterfaceAssociationDescriptor( - description="{} IAD".format(name), - bFirstInterface=cdc_comm_interface.bInterfaceNumber, - bInterfaceCount=len(cdc_interfaces), - bFunctionClass=cdc.CDC_CLASS_COMM, # Communications Device Class - bFunctionSubClass=cdc.CDC_SUBCLASS_ACM, # Abstract control model - bFunctionProtocol=cdc.CDC_PROTOCOL_NONE, - ) - - -if include_cdc: - cdc_iad = make_cdc_iad(cdc_comm_interface, "CDC") -if include_cdc2: - cdc2_iad = make_cdc_iad(cdc2_comm_interface, "CDC2") - -descriptor_list = [] - -if include_cdc: - # Put the CDC IAD just before the CDC interfaces. - # There appears to be a bug in the Windows composite USB driver that requests the - # HID report descriptor with the wrong interface number if the HID interface is not given - # first. However, it still fetches the descriptor anyway. We could reorder the interfaces but - # the Windows 7 Adafruit_usbser.inf file thinks CDC is at Interface 0, so we'll leave it - # there for backwards compatibility. - descriptor_list.append(cdc_iad) - descriptor_list.extend(cdc_interfaces) - -if include_cdc2: - descriptor_list.append(cdc2_iad) - descriptor_list.extend(cdc2_interfaces) - -if include_msc: - descriptor_list.extend(msc_interfaces) - -if include_hid: - descriptor_list.extend(hid_interfaces) - -if include_audio: - # Only add the control interface because other audio interfaces are managed by it to ensure the - # correct ordering. - descriptor_list.append(audio_control_interface) - -if include_vendor: - descriptor_list.extend(vendor_interfaces) - -# Finally, build the composite descriptor. - -configuration = standard.ConfigurationDescriptor( - description="Composite configuration", - wTotalLength=( - standard.ConfigurationDescriptor.bLength + sum([len(bytes(x)) for x in descriptor_list]) - ), - bNumInterfaces=len(interfaces), - # bus powered (bit 6), remote wakeup (bit 5), - # bit 7 is always 1 and 0-4 are always 0 - # Turn off remote wakeup until we handle it in CircuitPython. - bmAttributes=0x80, - -) -descriptor_list.insert(0, configuration) - -string_descriptors = [ - standard.StringDescriptor(string) for string in StringIndex.strings_in_order() -] -serial_number_descriptor = string_descriptors[SERIAL_NUMBER_INDEX] - -c_file = args.output_c_file -h_file = args.output_h_file - - -c_file.write( - """\ -#include - -#include "tusb.h" -#include "py/objtuple.h" -#include "shared-bindings/usb_hid/Device.h" -#include "{H_FILE_NAME}" - -""".format( - H_FILE_NAME=h_file.name - ) -) - -c_file.write( - """\ -// {DESCRIPTION} : {CLASS} -""".format( - DESCRIPTION=device.description, CLASS=device.__class__ - ) -) - -c_file.write( - """\ -const uint8_t usb_desc_dev[] = { -""" -) -for b in bytes(device): - c_file.write("0x{:02x}, ".format(b)) - -c_file.write( - """\ -}; -""" -) - -c_file.write( - """\ -const uint8_t usb_desc_cfg[] = { -""" -) - -# Write out all the regular descriptors as one long array (that's how ASF4 does it). -descriptor_length = 0 -for descriptor in descriptor_list: - c_file.write( - """\ -// {DESCRIPTION} : {CLASS} -""".format( - DESCRIPTION=descriptor.description, CLASS=descriptor.__class__ - ) - ) - - b = bytes(descriptor) - notes = descriptor.notes() - i = 0 - - # This prints each subdescriptor on a separate line. - n = 0 - while i < len(b): - length = b[i] - for j in range(length): - c_file.write("0x{:02x}, ".format(b[i + j])) - c_file.write("// " + notes[n]) - n += 1 - c_file.write("\n") - i += length - descriptor_length += len(b) - -c_file.write( - """\ -}; -""" -) - -pointers_to_strings = [] - -for idx, descriptor in enumerate(string_descriptors): - c_file.write( - """\ -// {DESCRIPTION} : {CLASS} -""".format( - DESCRIPTION=descriptor.description, CLASS=descriptor.__class__ - ) - ) - - b = bytes(descriptor) - notes = descriptor.notes() - i = 0 - - # This prints each subdescriptor on a separate line. - variable_name = StringIndex.index_to_variable[idx] - if not variable_name: - variable_name = "string_descriptor{}".format(idx) - pointers_to_strings.append("{name}".format(name=variable_name)) - - const = "const " - if variable_name == "usb_serial_number": - length = len(b) - c_file.write( - " uint16_t {NAME}[{length}];\n".format(NAME=variable_name, length=length // 2) - ) - else: - c_file.write( - """\ - const uint16_t {NAME}[] = {{ - """.format( - const=const, NAME=variable_name - ) - ) - n = 0 - while i < len(b): - length = b[i] - for j in range(length // 2): - c_file.write("0x{:04x}, ".format(b[i + 2 * j + 1] << 8 | b[i + 2 * j])) - n += 1 - c_file.write("\n") - i += length - c_file.write( - """\ - }; - """ - ) - -c_file.write( - """\ -// array of pointer to string descriptors -uint16_t const * const string_desc_arr [] = -{ -""" -) -c_file.write( - """,\ - -""".join( - pointers_to_strings - ) -) - -c_file.write( - """ -}; -""" -) - -c_file.write("\n") - -if include_hid: - hid_report_descriptors_length = len(concatenated_hid_report_descriptors) -else: - hid_report_descriptors_length = 0 - -# Now the values we need for the .h file. -h_file.write( - """\ -#ifndef MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H -#define MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H - -#include - -extern const uint8_t usb_desc_dev[{device_length}]; -extern const uint8_t usb_desc_cfg[{configuration_length}]; -extern uint16_t usb_serial_number[{serial_number_length}]; -extern uint16_t const * const string_desc_arr [{string_descriptor_length}]; - -#define CFG_TUSB_RHPORT0_MODE ({rhport0_mode}) - -// Vendor name included in Inquiry response, max 8 bytes -#define CFG_TUD_MSC_VENDOR "{msc_vendor}" - -// Product name included in Inquiry response, max 16 bytes -#define CFG_TUD_MSC_PRODUCT "{msc_product}" - -""".format( - serial_number_length=len(bytes(serial_number_descriptor)) // 2, - device_length=len(bytes(device)), - configuration_length=descriptor_length, - max_configuration_length=max(hid_report_descriptors_length, descriptor_length), - string_descriptor_length=len(pointers_to_strings), - rhport0_mode="OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED" - if args.highspeed - else "OPT_MODE_DEVICE", - msc_vendor=args.manufacturer[:8], - msc_product=args.product[:16], - ) -) - -if include_hid: - h_file.write( - """\ -extern const uint8_t hid_report_descriptor[{hid_report_descriptor_length}]; - -#define USB_HID_NUM_DEVICES {hid_num_devices} -""".format( - hid_report_descriptor_length=len(concatenated_hid_report_descriptors), - hid_num_devices=len(args.hid_devices), - ) - ) - -if include_vendor: - h_file.write( - """\ -enum -{ - VENDOR_REQUEST_WEBUSB = 1, - VENDOR_REQUEST_MICROSOFT = 2 -}; - -extern uint8_t const desc_ms_os_20[]; - -// Currently getting compile-time errors in files like tusb_fifo.c -// if we try do define this here (TODO figure this out!) -//extern const tusb_desc_webusb_url_t desc_webusb_url; - -""" - ) - -h_file.write( - """\ -#endif // MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H -""" -) - -if include_hid: - # Write out the report descriptor and info - c_file.write( - """\ -const uint8_t hid_report_descriptor[{HID_REPORT_DESCRIPTORS_LENGTH}] = {{ -""".format( - HID_REPORT_DESCRIPTORS_LENGTH=hid_report_descriptors_length - ) - ) - - for b in bytes(concatenated_hid_report_descriptors): - c_file.write("0x{:02x}, ".format(b)) - - c_file.write( - """\ -}; - -""" - ) - - # Write out USB HID report buffer definitions. - for name in args.hid_devices: - c_file.write( - """\ -static uint8_t {name}_report_buffer[{report_length}]; -""".format( - name=name.lower(), - report_length=hid_report_descriptors.HID_DEVICE_DATA[name].report_length, - ) - ) - - if hid_report_descriptors.HID_DEVICE_DATA[name].out_report_length > 0: - c_file.write( - """\ -static uint8_t {name}_out_report_buffer[{report_length}]; -""".format( - name=name.lower(), - report_length=hid_report_descriptors.HID_DEVICE_DATA[name].out_report_length, - ) - ) - - # Write out table of device objects. - c_file.write( - """\ -usb_hid_device_obj_t usb_hid_devices[] = { -""" - ) - for name in args.hid_devices: - device_data = hid_report_descriptors.HID_DEVICE_DATA[name] - out_report_buffer = ( - "{}_out_report_buffer".format(name.lower()) - if device_data.out_report_length > 0 - else "NULL" - ) - c_file.write( - """\ - {{ - .base = {{ .type = &usb_hid_device_type }}, - .report_buffer = {name}_report_buffer, - .report_id = {report_id}, - .report_length = {report_length}, - .usage_page = {usage_page:#04x}, - .usage = {usage:#04x}, - .out_report_buffer = {out_report_buffer}, - .out_report_length = {out_report_length}, - }}, -""".format( - name=name.lower(), - report_id=report_ids[name], - report_length=device_data.report_length, - usage_page=device_data.usage_page, - usage=device_data.usage, - out_report_buffer=out_report_buffer, - out_report_length=device_data.out_report_length, - ) - ) - c_file.write( - """\ -}; -""" - ) - - # Write out tuple of device objects. - c_file.write( - """ -mp_obj_tuple_t common_hal_usb_hid_devices = {{ - .base = {{ - .type = &mp_type_tuple, - }}, - .len = {num_devices}, - .items = {{ -""".format( - num_devices=len(args.hid_devices) - ) - ) - for idx in range(len(args.hid_devices)): - c_file.write( - """\ - (mp_obj_t) &usb_hid_devices[{idx}], -""".format( - idx=idx - ) - ) - c_file.write( - """\ - }, -}; -""" - ) - -if include_vendor: - # Mimic what the tinyusb webusb demo does in its main.c file - c_file.write( - """ -#define URL "{webusb_url}" - -const tusb_desc_webusb_url_t desc_webusb_url = -{{ - .bLength = 3 + sizeof(URL) - 1, - .bDescriptorType = 3, // WEBUSB URL type - .bScheme = 1, // 0: http, 1: https, 255: "" - .url = URL -}}; - -// These next two hardcoded descriptors were pulled from the usb_descriptor.c file -// of the tinyusb webusb_serial demo. TODO - this is probably something else to -// integrate into the adafruit_usb_descriptors project... - -//--------------------------------------------------------------------+ -// BOS Descriptor -//--------------------------------------------------------------------+ - -/* Microsoft OS 2.0 registry property descriptor -Per MS requirements https://msdn.microsoft.com/en-us/library/windows/hardware/hh450799(v=vs.85).aspx -device should create DeviceInterfaceGUIDs. It can be done by driver and -in case of real PnP solution device should expose MS "Microsoft OS 2.0 -registry property descriptor". Such descriptor can insert any record -into Windows registry per device/configuration/interface. In our case it -will insert "DeviceInterfaceGUIDs" multistring property. - -GUID is freshly generated and should be OK to use. - -https://developers.google.com/web/fundamentals/native-hardware/build-for-webusb/ -(Section Microsoft OS compatibility descriptors) -*/ - -#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN) - -#define MS_OS_20_DESC_LEN 0xB2 - -// BOS Descriptor is required for webUSB -uint8_t const desc_bos[] = -{{ - // total length, number of device caps - TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 2), - - // Vendor Code, iLandingPage - TUD_BOS_WEBUSB_DESCRIPTOR(VENDOR_REQUEST_WEBUSB, 1), - - // Microsoft OS 2.0 descriptor - TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, VENDOR_REQUEST_MICROSOFT) -}}; - -uint8_t const * tud_descriptor_bos_cb(void) -{{ - return desc_bos; -}} - - -#define ITF_NUM_VENDOR {webusb_interface} // used in this next descriptor - -uint8_t const desc_ms_os_20[] = -{{ - // Set header: length, type, windows version, total length - U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN), - - // Configuration subset header: length, type, configuration index, reserved, configuration total length - U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A), - - // Function Subset header: length, type, first interface, reserved, subset length - U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_VENDOR, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08), - - // MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID - U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'U', 'S', 'B', 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible - - // MS OS 2.0 Registry property descriptor: length, type - U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY), - U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16 - 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, - 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00, - U16_TO_U8S_LE(0x0050), // wPropertyDataLength - //bPropertyData: “{{975F44D9-0D08-43FD-8B3E-127CA8AFFF9D}}”. - '{{', 0x00, '9', 0x00, '7', 0x00, '5', 0x00, 'F', 0x00, '4', 0x00, '4', 0x00, 'D', 0x00, '9', 0x00, '-', 0x00, - '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, - '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00, - '8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}}', 0x00, 0x00, 0x00, 0x00, 0x00 -}}; - -TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size"); - -// End of section about desc_ms_os_20 - -""".format( - webusb_url=args.webusb_url, webusb_interface=vendor_interface.bInterfaceNumber - ) - ) From a1e2afadcecb6c8109dcebf637a70bbb475b281c Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Mon, 26 Apr 2021 00:22:51 -0500 Subject: [PATCH 29/66] AP ip_info, gateway, & subnet --- ports/esp32s2/common-hal/wifi/Radio.c | 28 ++++++++++++---- ports/esp32s2/common-hal/wifi/Radio.h | 1 + ports/esp32s2/common-hal/wifi/__init__.c | 6 ++-- shared-bindings/wifi/Radio.c | 42 +++++++++++++++++++++--- shared-bindings/wifi/Radio.h | 2 ++ 5 files changed, 64 insertions(+), 15 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 953cd41e49..17a7421642 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -56,8 +56,7 @@ static void set_mode_station(wifi_radio_obj_t *self, bool state) { } else { next_mode = WIFI_MODE_NULL; } - } - + } esp_wifi_set_mode(next_mode); self->sta_mode = state; } @@ -76,8 +75,7 @@ static void set_mode_ap(wifi_radio_obj_t *self, bool state) { } else { next_mode = WIFI_MODE_NULL; } - } - + } esp_wifi_set_mode(next_mode); self->ap_mode = state; } @@ -174,7 +172,7 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ config->ap.password[password_len] = 0; config->ap.channel = channel; config->ap.authmode = authmode; - config->ap.max_connection = 4; + config->ap.max_connection = 4; // kwarg? esp_wifi_set_config(WIFI_IF_AP, config); } @@ -294,6 +292,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self) { return common_hal_ipaddress_new_ipv4address(self->ip_info.gw.addr); } +mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->ap_netif)) { + return mp_const_none; + } + esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info); + return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.gw.addr); +} + mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; @@ -302,6 +308,14 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self) { return common_hal_ipaddress_new_ipv4address(self->ip_info.netmask.addr); } +mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self) { + if (!esp_netif_is_netif_up(self->ap_netif)) { + return mp_const_none; + } + esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info); + return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.netmask.addr); +} + mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->netif)) { return mp_const_none; @@ -314,8 +328,8 @@ mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self) { if (!esp_netif_is_netif_up(self->ap_netif)) { return mp_const_none; } - esp_netif_get_ip_info(self->ap_netif, &self->ip_info); - return common_hal_ipaddress_new_ipv4address(self->ip_info.ip.addr); + esp_netif_get_ip_info(self->ap_netif, &self->ap_ip_info); + return common_hal_ipaddress_new_ipv4address(self->ap_ip_info.ip.addr); } mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self) { diff --git a/ports/esp32s2/common-hal/wifi/Radio.h b/ports/esp32s2/common-hal/wifi/Radio.h index 17ce3e4dca..b6cf750b4b 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.h +++ b/ports/esp32s2/common-hal/wifi/Radio.h @@ -59,6 +59,7 @@ typedef struct { uint8_t last_disconnect_reason; wifi_config_t ap_config; + esp_netif_ip_info_t ap_ip_info; esp_netif_t *ap_netif; } wifi_radio_obj_t; diff --git a/ports/esp32s2/common-hal/wifi/__init__.c b/ports/esp32s2/common-hal/wifi/__init__.c index 5ba8f4cd64..fa544ce153 100644 --- a/ports/esp32s2/common-hal/wifi/__init__.c +++ b/ports/esp32s2/common-hal/wifi/__init__.c @@ -56,12 +56,10 @@ static void event_handler(void *arg, esp_event_base_t event_base, case WIFI_EVENT_AP_STOP: ESP_LOGW(TAG, "ap stop"); break; - case WIFI_EVENT_AP_STACONNECTED: { + case WIFI_EVENT_AP_STACONNECTED: break; - } - case WIFI_EVENT_AP_STADISCONNECTED: { + case WIFI_EVENT_AP_STADISCONNECTED: break; - } case WIFI_EVENT_STA_START: ESP_LOGW(TAG, "sta start"); break; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 988391e536..09ed804d6f 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -332,7 +332,7 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_connect_obj, 1, wifi_radio_connect); //| ipv4_gateway: Optional[ipaddress.IPv4Address] -//| """IP v4 Address of the gateway when connected to an access point. None otherwise.""" +//| """IP v4 Address of the station gateway when connected to an access point. None otherwise.""" //| STATIC mp_obj_t wifi_radio_get_ipv4_gateway(mp_obj_t self) { return common_hal_wifi_radio_get_ipv4_gateway(self); @@ -347,8 +347,24 @@ const mp_obj_property_t wifi_radio_ipv4_gateway_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| ipv4_gateway_ap: Optional[ipaddress.IPv4Address] +//| """IP v4 Address of the access point gateway, when enabled. None otherwise.""" +//| +STATIC mp_obj_t wifi_radio_get_ipv4_gateway_ap(mp_obj_t self) { + return common_hal_wifi_radio_get_ipv4_gateway_ap(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_gateway_ap_obj, wifi_radio_get_ipv4_gateway_ap); + +const mp_obj_property_t wifi_radio_ipv4_gateway_ap_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ipv4_gateway_ap_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| ipv4_subnet: Optional[ipaddress.IPv4Address] -//| """IP v4 Address of the subnet when connected to an access point. None otherwise.""" +//| """IP v4 Address of the station subnet when connected to an access point. None otherwise.""" //| STATIC mp_obj_t wifi_radio_get_ipv4_subnet(mp_obj_t self) { return common_hal_wifi_radio_get_ipv4_subnet(self); @@ -363,8 +379,24 @@ const mp_obj_property_t wifi_radio_ipv4_subnet_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| ipv4_subnet_ap: Optional[ipaddress.IPv4Address] +//| """IP v4 Address of the access point subnet, when enabled. None otherwise.""" +//| +STATIC mp_obj_t wifi_radio_get_ipv4_subnet_ap(mp_obj_t self) { + return common_hal_wifi_radio_get_ipv4_subnet_ap(self); + +} +MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_get_ipv4_subnet_ap_obj, wifi_radio_get_ipv4_subnet_ap); + +const mp_obj_property_t wifi_radio_ipv4_subnet_ap_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&wifi_radio_get_ipv4_subnet_ap_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| ipv4_address: Optional[ipaddress.IPv4Address] -//| """IP v4 Address of the radio when connected to an access point. None otherwise.""" +//| """IP v4 Address of the station when connected to an access point. None otherwise.""" //| STATIC mp_obj_t wifi_radio_get_ipv4_address(mp_obj_t self) { return common_hal_wifi_radio_get_ipv4_address(self); @@ -380,7 +412,7 @@ const mp_obj_property_t wifi_radio_ipv4_address_obj = { }; //| ipv4_address_ap: Optional[ipaddress.IPv4Address] -//| """IP v4 Address of the radio access point, when enabled. None otherwise.""" +//| """IP v4 Address of the access point, when enabled. None otherwise.""" //| STATIC mp_obj_t wifi_radio_get_ipv4_address_ap(mp_obj_t self) { return common_hal_wifi_radio_get_ipv4_address_ap(self); @@ -482,7 +514,9 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ap_info), MP_ROM_PTR(&wifi_radio_ap_info_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_dns), MP_ROM_PTR(&wifi_radio_ipv4_dns_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_gateway), MP_ROM_PTR(&wifi_radio_ipv4_gateway_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipv4_gateway_ap), MP_ROM_PTR(&wifi_radio_ipv4_gateway_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_subnet), MP_ROM_PTR(&wifi_radio_ipv4_subnet_obj) }, + { MP_ROM_QSTR(MP_QSTR_ipv4_subnet_ap), MP_ROM_PTR(&wifi_radio_ipv4_subnet_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_address), MP_ROM_PTR(&wifi_radio_ipv4_address_obj) }, { MP_ROM_QSTR(MP_QSTR_ipv4_address_ap), MP_ROM_PTR(&wifi_radio_ipv4_address_ap_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 8bcc02063b..8848a45cc9 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -105,7 +105,9 @@ extern wifi_radio_error_t common_hal_wifi_radio_connect(wifi_radio_obj_t *self, extern mp_obj_t common_hal_wifi_radio_get_ap_info(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_dns(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ipv4_gateway_ap(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet(wifi_radio_obj_t *self); +extern mp_obj_t common_hal_wifi_radio_get_ipv4_subnet_ap(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_address(wifi_radio_obj_t *self); extern mp_obj_t common_hal_wifi_radio_get_ipv4_address_ap(wifi_radio_obj_t *self); From 7a40b4daecccde5f4ae41a1f363c2261fcb08995 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 26 Apr 2021 23:54:01 -0400 Subject: [PATCH 30/66] very much WIP --- py/circuitpy_mpconfig.mk | 2 +- shared-bindings/usb_hid/Device.c | 13 +++++----- shared-bindings/usb_hid/Device.h | 4 ++- shared-bindings/usb_hid/__init__.c | 15 +++++------- shared-bindings/usb_hid/__init__.h | 6 ++--- shared-module/storage/__init__.c | 2 +- shared-module/usb_cdc/__init__.c | 38 ++++++++++++++--------------- shared-module/usb_hid/Device.c | 4 +-- shared-module/usb_hid/Device.h | 3 ++- shared-module/usb_hid/__init__.c | 10 ++++++-- shared-module/usb_hid/__init__.h | 2 ++ shared-module/usb_midi/__init__.c | 8 +++--- supervisor/shared/usb/tusb_config.h | 8 ++++++ supervisor/shared/usb/usb.c | 8 ++++++ supervisor/shared/usb/usb_desc.c | 35 ++++++++++++++------------ supervisor/supervisor.mk | 9 +++++++ supervisor/usb.h | 9 ++++--- 17 files changed, 108 insertions(+), 68 deletions(-) diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 622f991ffb..8801213655 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -331,7 +331,7 @@ CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP) CIRCUITPY_USB ?= 1 CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB) -# If you need to count endpoints, do: +# If you need to count endpoints, use: # $(shell expr $(USB_NUM_EP) '>=' 8) CIRCUITPY_USB_CDC ?= 1 diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 8b205934e3..13afbbf3e6 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -26,6 +26,7 @@ #include "py/objproperty.h" #include "shared-bindings/usb_hid/Device.h" +#include "py/runtime.h" //| class Device: //| """HID Device @@ -73,12 +74,11 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; - mp_get_buffer_raise(descriptor, &bufinfo, MP_BUFFER_READ); - - bytearray_obj_t descriptor = mp_obj_array_t new_bytearray(bufinfo.len, bufinfo.buf); + mp_get_buffer_raise(args[ARG_descriptor].u_obj, &bufinfo, MP_BUFFER_READ); + mp_obj_t descriptor = mp_obj_new_bytearray(bufinfo.len, bufinfo.buf); const mp_int_t usage_page_arg = args[ARG_usage_page].u_int; - if (usage_page_arg <= 0 || usage_arg > 255) { + if (usage_page_arg <= 0 || usage_page_arg > 255) { mp_raise_ValueError_varg(translate("%q must be 1-255"), MP_QSTR_usage_page); } const uint8_t usage_page = usage_page_arg; @@ -91,7 +91,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args const mp_int_t in_report_length_arg = args[ARG_in_report_length].u_int; if (in_report_length_arg <= 0 || in_report_length_arg > 255) { - mp_raise_ValueError_varg(translate("%q must be > 1-255"), MP_QSTR_in_report_length); + mp_raise_ValueError_varg(translate("%q must be 1-255"), MP_QSTR_in_report_length); } const uint8_t in_report_length = in_report_length_arg; @@ -102,7 +102,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args else if (!MP_OBJ_IS_SMALL_INT(out_report_length_arg) || MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) <= 0 || MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) > 255) { - mp_raise_ValueError_varg(translate("%q must be None or > 1-255"), MP_QSTR_out_report_length); + mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_out_report_length); } uint8_t out_report_length = MP_OBJ_SMALL_INT_VALUE(out_report_length_arg); @@ -118,6 +118,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args uint8_t report_id_index = MP_OBJ_SMALL_INT_VALUE(report_id_index_arg); common_hal_usb_hid_device_construct(self, descriptor, usage_page, usage, in_report_length, out_report_length, report_id_index); + return (mp_obj_t)self; } diff --git a/shared-bindings/usb_hid/Device.h b/shared-bindings/usb_hid/Device.h index c9ca3e16f0..c1af92fd4f 100644 --- a/shared-bindings/usb_hid/Device.h +++ b/shared-bindings/usb_hid/Device.h @@ -27,11 +27,13 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_USB_HID_DEVICE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_USB_HID_DEVICE_H +#include "py/objarray.h" + #include "shared-module/usb_hid/Device.h" extern const mp_obj_type_t usb_hid_device_type; -void common_hal_usb_hid_device_construct(usb_hid_device_obj_t *self, ***); +void common_hal_usb_hid_device_construct(usb_hid_device_obj_t *self, mp_obj_t descriptor, uint8_t usage_page, uint8_t usage, uint8_t in_report_length, uint8_t out_report_length, uint8_t report_id_index); void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *report, uint8_t len); uint8_t common_hal_usb_hid_device_get_usage_page(usb_hid_device_obj_t *self); uint8_t common_hal_usb_hid_device_get_usage(usb_hid_device_obj_t *self); diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index ccfaaaf96e..8d5d67d52a 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -51,18 +51,15 @@ //| ... //| STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { - - mp_obj_iter_buf_t iter_buf; - - const mp_int_t len = mp_obj_get_int(mp_obj_len(devices_seq)); - for (size_t i = 0; i < len; i++) { - mp_obj_t item = mp_obj_subscr(devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + const mp_int_t len = mp_obj_get_int(mp_obj_len(devices)); + for (mp_int_t i = 0; i < len; i++) { + mp_obj_t item = mp_obj_subscr(devices, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL); if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { - mp_raise_ValueError_varg(translate("non-Device in %q", MP_QSTR_devices)); + mp_raise_ValueError_varg(translate("non-Device in %q"), MP_QSTR_devices); } } - if (!common_hal_usb_hid_configure_usb(descriptors)) { + if (!common_hal_usb_hid_configure_usb(devices)) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } @@ -73,7 +70,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_configure_usb_obj, usb_hid_configure_usb); STATIC const mp_rom_map_elem_t usb_hid_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, - { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_midi_configure_usb_obj) }, + { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_hid_configure_usb_obj) }, { MP_ROM_QSTR(MP_QSTR_devices), MP_ROM_PTR(&common_hal_usb_hid_devices) }, { MP_ROM_QSTR(MP_QSTR_Device), MP_ROM_PTR(&usb_hid_device_type) }, }; diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index 89779a84a7..532625d623 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -27,12 +27,12 @@ #ifndef SHARED_BINDINGS_USB_HID_H #define SHARED_BINDINGS_USB_HID_H -#include -#include +#include "py/obj.h" +#include "py/objtuple.h" extern mp_obj_tuple_t common_hal_usb_hid_devices; void common_hal_usb_hid_configure_usb_defaults(void); -usb_hid_configure_status common_hal_usb_hid_configure_usb(mp_obj_t devices_seq); +bool common_hal_usb_hid_configure_usb(mp_obj_t devices_seq); #endif // SHARED_BINDINGS_USB_HID_H diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 0a64a1e3a7..3a4fc1f3b5 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -81,7 +81,7 @@ size_t storage_usb_descriptor_length(void) { return sizeof(usb_msc_descriptor); } -static const char[] storage_interface_name = USB_INTERFACE_NAME " Mass Storage"; +static const char[] storage_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " Mass Storage"; size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { memcpy(descriptor_buf, storage_usb_msc_descriptor_template, sizeof(storage_usb_msc_descriptor_template)); diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 72eb1d8291..a918476320 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -135,15 +135,29 @@ static const uint8_t usb_cdc_descriptor_template[] = { 0x00, // 65 bInterval 0 (unit depends on device speed) }; +static const char[] repl_cdc_comm_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC control"; +static const char[] data_cdc_comm_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC2 control"; +static const char[] repl_cdc_data_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC data"; +static const char[] data_cdc_data_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC2 data"; + +static usb_cdc_serial_obj_t usb_cdc_repl_obj = { + .base.type = &usb_cdc_serial_type, + .timeout = -1.0f, + .write_timeout = -1.0f, + .idx = 0, +}; + +static usb_cdc_serial_obj_t usb_cdc_data_obj = { + .base.type = &usb_cdc_serial_type, + .timeout = -1.0f, + .write_timeout = -1.0f, + .idx = 1, +}; + size_t usb_cdc_descriptor_length(void) { return sizeof(usb_cdc_descriptor_template); } -static const char[] repl_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC control"; -static const char[] data_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC2 control"; -static const char[] repl_cdc_data_interface_name = USB_INTERFACE_NAME " CDC data"; -static const char[] data_cdc_data_interface_name = USB_INTERFACE_NAME " CDC2 data"; - size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl) { memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); @@ -185,20 +199,6 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_midi_descriptor_template); } -static usb_cdc_serial_obj_t usb_cdc_repl_obj = { - .base.type = &usb_cdc_serial_type, - .timeout = -1.0f, - .write_timeout = -1.0f, - .idx = 0, -}; - -static usb_cdc_serial_obj_t usb_cdc_data_obj = { - .base.type = &usb_cdc_serial_type, - .timeout = -1.0f, - .write_timeout = -1.0f, - .idx = 1, -}; - void usb_cdc_init(void) { usb_cdc_repl_enabled = true; usb_cdc_data_enabled = false; diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 368372df89..02f43c167c 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -66,7 +66,7 @@ static const uint8_t keyboard_descriptor[] = { 0x95, 0x03, // Report Count (3) 0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) 0xC0, // End Collection - }, +}; const usb_hid_device_obj_t usb_hid_device_keyboard_obj = { .descriptor = keyboard_descriptor, @@ -154,7 +154,7 @@ const usb_hid_device_obj_t usb_hid_device_consumer_control_obj = { }; -void common_hal_usb_hid_device_construct(usb_hid_dev_obj_t *self, mp_obj_array_t *descriptor, uint8_t usage_page, uint8_t usage, uint8_t in_report_length, uint8_t out_report_length, uint8_t report_id_index) { +void common_hal_usb_hid_device_construct(usb_hid_device_obj_t *self, mp_obj_t descriptor, uint8_t usage_page, uint8_t usage, uint8_t in_report_length, uint8_t out_report_length, uint8_t report_id_index) { // report buffer pointers are NULL at start, and are created on demand. self->descriptor_obj = descriptor; diff --git a/shared-module/usb_hid/Device.h b/shared-module/usb_hid/Device.h index f15b70d79a..e6ac32bb54 100644 --- a/shared-module/usb_hid/Device.h +++ b/shared-module/usb_hid/Device.h @@ -40,6 +40,7 @@ typedef struct { uint8_t *descriptor; uint8_t *in_report_buffer; uint8_t *out_report_buffer; + uint16_t report_id_index; uint16_t descriptor_length; uint8_t usage_page; uint8_t usage; @@ -50,6 +51,6 @@ typedef struct { extern usb_hid_device_obj_t usb_hid_device_keyboard_obj; extern usb_hid_device_obj_t usb_hid_device_mouse_obj; -extern usb_hid_device_mouse_obj usb_hid_device_consumer_control_obj; +extern usb_hid_device_obj_t usb_hid_device_consumer_control_obj; #endif /* SHARED_MODULE_USB_HID_DEVICE_H */ diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 7ab6b7592b..5d364e20a1 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -24,6 +24,11 @@ * THE SOFTWARE. */ +#include + +#include "shared-module/usb_hid/__init__.h" +#include "supervisor/memory.h" + static const uint8_t usb_hid_descriptor_template[] = { 0x09, // 0 bLength 0x21, // 1 bDescriptorType (HID) @@ -62,10 +67,10 @@ supervisor_allocation *hid_devices_allocation; // This is the interface descriptor, not the report descriptor. size_t usb_hid_descriptor_length(void) { - return sizeof(usb_hid_descriptor); + return sizeof(usb_hid_descriptor_template); } -static const char[] usb_hid_interface_name = USB_INTERFACE_NAME " HID"; +static const char usb_hid_interface_name[] = MP_STRINGIFY(USB_INTERFACE_NAME) " HID"; // This is the interface descriptor, not the report descriptor. size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length) { @@ -84,6 +89,7 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac static mp_obj_t default_hid_devices[] = { MP_OBJ_FROM_PTR(usb_hid_device_keyboard_obj), MP_OBJ_FROM_PTR(usb_hid_device_mouse_obj), + MP_OBJ_FROM_PTR(usb_hid_device_consumer_control_obj), }; // Set the default list of devices that will be included. Called before boot.py runs, in the boot.py VM. diff --git a/shared-module/usb_hid/__init__.h b/shared-module/usb_hid/__init__.h index 6eab014459..f95a94c679 100644 --- a/shared-module/usb_hid/__init__.h +++ b/shared-module/usb_hid/__init__.h @@ -27,6 +27,8 @@ #ifndef SHARED_MODULE_USB_HID___INIT___H #define SHARED_MODULE_USB_HID___INIT___H +#include "shared-module/usb_hid/Device.h" + extern bool usb_hid_enabled; extern usb_hid_device_obj_t usb_hid_devices[]; diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 14c3cfa5ae..d1402d3e59 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -162,10 +162,10 @@ size_t usb_midi_descriptor_length(void) { return sizeof(usb_midi_descriptor_template); } -static const char[] midi_streaming_interface_name = USB_INTERFACE_NAME " MIDI"; -static const char[] midi_audio_control_interface_name = USB_INTERFACE_NAME " Audio"; -static const char[] midi_in_jack_name = USB_INTERFACE_NAME " usb_midi.ports[0]"; -static const char[] midi_out_jack_name = USB_INTERFACE_NAME " usb_midi.ports[0]"; +static const char[] midi_streaming_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " MIDI"; +static const char[] midi_audio_control_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " Audio"; +static const char[] midi_in_jack_name = MP_STRINGIFY(USB_INTERFACE_NAME) " usb_midi.ports[0]"; +static const char[] midi_out_jack_name = MP_STRINGIFY(USB_INTERFACE_NAME) " usb_midi.ports[0]"; size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 16f8d13c5f..5bccc51c71 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -59,6 +59,14 @@ extern "C" { // DEVICE CONFIGURATION // --------------------------------------------------------------------+ +#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) + +// Vendor name included in Inquiry response, max 8 bytes +#define CFG_TUD_MSC_VENDOR USB_MANUFACTURER + +// Product name included in Inquiry response, max 16 bytes +#define CFG_TUD_MSC_PRODUCT USB_PRODUCT + #define CFG_TUD_ENDPOINT0_SIZE 64 // ------------- CLASS -------------// diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 983112f001..ebdc82a960 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -34,6 +34,10 @@ #include "lib/utils/interrupt_char.h" #include "lib/mp-readline/readline.h" +#if CIRCUITPY_USB_HID +#include "shared-module/usb_hid/__init__.h" +#endif + #if CIRCUITPY_USB_MIDI #include "shared-module/usb_midi/__init__.h" #endif @@ -78,6 +82,10 @@ void usb_init(void) { tud_cdc_set_wanted_char(CHAR_CTRL_C); #endif + #if CIRCUITPY_USB_CDC + usb_cdcx_usb_init(); + #endif + #if CIRCUITPY_USB_MIDI usb_midi_usb_init(); #endif diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index b9c3e64951..04a482886e 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -26,23 +26,26 @@ #include "lib/tinyusb/src/tusb.h" +#include "supervisor/usb.h" + #if CIRCUITPY_USB_CDC -#include "shared-module/storage/__init__.h" +#include "shared-bindings/usb_cdc/__init__.h" #endif #if CIRCUITPY_USB_HID -#include "shared-module/usb_hid/__init__.h" +#include "shared-bindings/usb_hid/__init__.h" #endif #if CIRCUITPY_USB_MIDI -#include "shared-module/usb_midi/__init__.h" +#include "shared-bindings/usb_midi/__init__.h" #endif -#if CIRCUITPY_USB_MSC -#include "shared-module/storage/__init__.h" +#if CIRCUITPY_USB_MSC && CIRCUITPY_STORAGE +#include "shared-bindings/storage/__init__.h" #endif -#include "shared-module/usb_hid/Device.h" +// For COMMON_HAL_MCU_PROCESSOR_UID_LENGTH +#include "common-hal/microcontroller/Processor.h" uint8_t *device_descriptor; uint8_t *config_descriptor; @@ -53,8 +56,8 @@ uint8_t *config_descriptor; static char * collected_interface_strings[]; static uint16_t current_interface_string; -static const char[] manufacturer_name = USB_MANUFACTURER; -static const char[] product_name = USB_PRODUCT; +static const char manufacturer_name[] = MP_STRINGIFY(USB_MANUFACTURER); +static const char product_name[] = MP_STRINGIFY(USB_PRODUCT); // Serial number string is UID length * 2 (2 nibbles per byte) + 1 byte for null termination. static char serial_number_hex_string[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2 + 1]; @@ -67,12 +70,12 @@ static const uint8_t device_descriptor_template[] = { 0x00, // 5 bDeviceSubClass 0x00, // 6 bDeviceProtocol 0x40, // 7 bMaxPacketSize0 64 - 0x9A, 0x23, // 8,9 idVendor [SET AT RUNTIME: lo,hi] + 0xFF, 0xFF, // 8,9 idVendor [SET AT RUNTIME: lo,hi] #define DEVICE_VID_LO_INDEX (8) #define DEVICE_VID_HI_INDEX (9) - 0x, 0xFF, // 10,11 idProduct [SET AT RUNTIME: lo,hi] -#define DEVICE PID_LO_INDEX (10) -#define DEVICE PID_HI_INDEX (11) + 0xFF, 0xFF, // 10,11 idProduct [SET AT RUNTIME: lo,hi] +#define DEVICE_PID_LO_INDEX (10) +#define DEVICE_PID_HI_INDEX (11) 0x00, 0x01, // 12,13 bcdDevice 2.00 0x02, // 14 iManufacturer (String Index) [SET AT RUNTIME] #define DEVICE_MANUFACTURER_STRING_INDEX (14) @@ -117,11 +120,11 @@ void reset_usb_desc(void) { #endif #if CIRCUITPY_USB_HID - common_hal_usb_hid_configure_usb_default(); + common_hal_usb_hid_configure_usb_defaults(); #endif } -static void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string) { +static void usb_build_device_descriptor(uint16_t vid, uint16_t pid) { memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); device_descriptor[DEVICE_VID_LO_INDEX] = vid & 0xFF; @@ -234,7 +237,7 @@ static void usb_build_configuration_descriptor(uint16_t total_length, uint8_t nu } -static void usb_add_interface_string(uint8_t interface_string_index, const char[] str) { +void usb_add_interface_string(uint8_t interface_string_index, const char[] str) { if (interface_string_index > MAX_INTERFACE_STRINGS) { mp_raise_SystemError("Too many USB interface names"); } @@ -277,7 +280,7 @@ static void usb_desc_init(void) { collected_interface_strings = m_malloc(MAX_INTERFACE_STRINGS + 1, false); current_interface_string = 1; - usb_build_device_descriptor(); + usb_build_device_descriptor(USB_VID, USB_PID); usb_build_configuration_descriptor(); usb_build_hid_descriptor(); usb_build_string_descriptors(); diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index ad3a2c0fdc..34a5a5cc7f 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -135,6 +135,7 @@ ifeq ($(CIRCUITPY_DISPLAYIO), 1) endif USB_INTERFACE_NAME ?= "CircuitPython" +CFLAGS += -DUSB_INTERFACE_NAME=$(USB_INTERFACE_NAME) ifneq ($(USB_VID),) CFLAGS += -DUSB_VID=$(USB_VID) @@ -154,15 +155,23 @@ endif USB_HIGHSPEED ?= 0 +************ move these from make variables to cpp only ??? USB_CDC_EP_NUM_NOTIFICATION ?= 0 +CFLAGS += -DUSB_CDC_EP_NUM_NOTIFICATION=$(USB_CDC_EP_NUM_NOTIFICATION) USB_CDC_EP_NUM_DATA_OUT ?= 0 +CFLAGS += -DUSB_CDC_EP_NUM_DATA_OUT=$(USB_CDC_EP_NUM_DATA_OUT) USB_CDC_EP_NUM_DATA_IN ?= 0 +CFLAGS += -DUSB_CDC_EP_NUM_DATA_IN=$(USB_CDC_EP_NUM_DATA_IN) USB_CDC2_EP_NUM_NOTIFICATION ?= 0 +CFLAGS += -DUSB_CDC2_EP_NUM_NOTIFICATION=$(USB_CDC2_EP_NUM_NOTIFICATION) USB_CDC2_EP_NUM_DATA_OUT ?= 0 +CFLAGS += -DUSB_CDC2_EP_NUM_DATA_OUT=$(USB_CDC2_EP_NUM_DATA_OUT) USB_CDC2_EP_NUM_DATA_IN ?= 0 +CFLAGS += -DUSB_CDC2_EP_NUM_DATA_IN=$(USB_CDC2_EP_NUM_DATA_IN) USB_MSC_EP_NUM_OUT ?= 0 +CFLAGS += -DUSB USB_MSC_EP_NUM_IN ?= 0 USB_HID_EP_NUM_OUT ?= 0 diff --git a/supervisor/usb.h b/supervisor/usb.h index 9e3e14c2fd..96071b0cb1 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -49,16 +49,19 @@ void init_usb_hardware(void); void post_usb_init(void); // Shared implementation. +void reset_usb(void); bool usb_enabled(void); void usb_init(void); void usb_disconnect(void); void usb_gc_collect(void); +void usb_post_boot_py(void); -void usb_add_interface_string(uint8_t interface_string_index, const char[] str); +void usb_add_interface_string(uint8_t interface_string_index, const char str[]); + +void reset_usb_desc(void); void usb_desc_gc_collect(void); void usb_desc_init(void); -void usb_build_device_descriptor(uint16_t vid, uint16_t pid, uint8_t *current_interface_string); -void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces); +void usb_desc_post_boot_py(void); // Propagate plug/unplug events to the MSC logic. #if CIRCUITPY_USB_MSC From f98a54628bb42c927538475a7958cad7e7f5939a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 27 Apr 2021 14:37:36 -0400 Subject: [PATCH 31/66] wip: compiles --- locale/circuitpython.pot | 16 +-- main.c | 8 ++ ports/cxd56/mpconfigport.h | 7 + ports/cxd56/mpconfigport.mk | 6 - py/circuitpy_mpconfig.h | 53 ++++++++ py/circuitpy_mpconfig.mk | 4 + shared-bindings/storage/__init__.h | 2 + shared-bindings/usb_hid/Device.c | 8 +- shared-bindings/usb_hid/__init__.c | 18 ++- shared-bindings/usb_hid/__init__.h | 3 + shared-bindings/usb_midi/__init__.h | 1 + shared-module/storage/__init__.c | 26 ++-- shared-module/storage/__init__.h | 2 +- shared-module/usb_cdc/__init__.c | 26 ++-- shared-module/usb_cdc/__init__.h | 4 +- shared-module/usb_hid/Device.c | 51 +++----- shared-module/usb_hid/Device.h | 12 +- shared-module/usb_hid/__init__.c | 195 ++++++++++++++++++---------- shared-module/usb_hid/__init__.h | 13 +- shared-module/usb_midi/__init__.c | 28 ++-- shared-module/usb_midi/__init__.h | 2 +- supervisor/shared/usb/usb_desc.c | 104 +++++++-------- supervisor/supervisor.mk | 39 +----- 23 files changed, 374 insertions(+), 254 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 9d276a8342..9cd3b36e14 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -91,10 +91,6 @@ msgstr "" msgid "%q must be 1-255" msgstr "" -#: shared-bindings/usb_hid/Device.c -msgid "%q must be > 1-255" -msgstr "" - #: shared-bindings/memorymonitor/AllocationAlarm.c msgid "%q must be >= 0" msgstr "" @@ -111,10 +107,6 @@ msgstr "" msgid "%q must be None or 1-255" msgstr "" -#: shared-bindings/usb_hid/Device.c -msgid "%q must be None or > 1-255" -msgstr "" - #: shared-module/vectorio/Polygon.c msgid "%q must be a tuple of length 2" msgstr "" @@ -1643,6 +1635,10 @@ msgstr "" msgid "Not connected" msgstr "" +#: supervisor/shared/usb/usb_desc.c +msgid "Not enough USB endpoints" +msgstr "" + #: shared-bindings/audiobusio/I2SOut.c shared-bindings/audioio/AudioOut.c #: shared-bindings/audiopwmio/PWMAudioOut.c msgid "Not playing" @@ -2149,6 +2145,10 @@ msgstr "" msgid "To exit, please reset the board without " msgstr "" +#: supervisor/shared/usb/usb_desc.c +msgid "Too many USB interface names" +msgstr "" + #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/raspberrypi/common-hal/audiobusio/I2SOut.c msgid "Too many channels in sample." diff --git a/main.c b/main.c index 21e7775a9f..610fb0d302 100755 --- a/main.c +++ b/main.c @@ -103,6 +103,10 @@ #include "shared-module/usb_cdc/__init__.h" #endif +#if CIRCUITPY_USB_HID +#include "shared-module/usb_hid/__init__.h" +#endif + #if CIRCUITPY_USB_MIDI #include "shared-module/usb_midi/__init__.h" #endif @@ -189,6 +193,10 @@ STATIC void start_mp(supervisor_allocation* heap) { usb_cdc_init(); #endif + #if CIRCUITPY_USB_HID + usb_hid_init(); + #endif + #if CIRCUITPY_USB_MIDI usb_midi_init(); #endif diff --git a/ports/cxd56/mpconfigport.h b/ports/cxd56/mpconfigport.h index 27c82337bc..bce68f83f2 100644 --- a/ports/cxd56/mpconfigport.h +++ b/ports/cxd56/mpconfigport.h @@ -36,6 +36,13 @@ #define MICROPY_BYTES_PER_GC_BLOCK (32) +// CXD56 architecture uses fixed endpoint numbers +#define USB_CDC_EP_NUM_NOTIFICATION (3) +#define USB_CDC_EP_NUM_DATA_OUT (2) +#define USB_CDC_EP_NUM_DATA_IN (2) +#define USB_MSC_EP_NUM_OUT (5) +#define USB_MSC_EP_NUM_IN (4) + #define MICROPY_PORT_ROOT_POINTERS \ CIRCUITPY_COMMON_ROOT_POINTERS \ diff --git a/ports/cxd56/mpconfigport.mk b/ports/cxd56/mpconfigport.mk index a010f16778..5dbc71825d 100644 --- a/ports/cxd56/mpconfigport.mk +++ b/ports/cxd56/mpconfigport.mk @@ -1,10 +1,4 @@ USB_HIGHSPEED = 1 -USB_RENUMBER_ENDPOINTS = 0 -USB_CDC_EP_NUM_NOTIFICATION = 3 -USB_CDC_EP_NUM_DATA_OUT = 2 -USB_CDC_EP_NUM_DATA_IN = 1 -USB_MSC_EP_NUM_OUT = 5 -USB_MSC_EP_NUM_IN = 4 # Number of USB endpoint pairs. USB_NUM_EP = 6 diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 15881f41bd..99f7168565 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -992,4 +992,57 @@ void supervisor_run_background_tasks_if_tick(void); #define CIRCUITPY_VERBOSE_BLE 0 +// USB settings + +// If the port requires certain USB endpoint numbers, define these in mpconfigport.h. + +#ifndef USB_CDC_EP_NUM_NOTIFICATION +#define USB_CDC_EP_NUM_NOTIFICATION (0) +#endif + +#ifndef USB_CDC_EP_NUM_DATA_OUT +#define USB_CDC_EP_NUM_DATA_OUT (0) +#endif + +#ifndef USB_CDC_EP_NUM_DATA_IN +#define USB_CDC_EP_NUM_DATA_IN (0) +#endif + +#ifndef USB_CDC2_EP_NUM_NOTIFICATION +#define USB_CDC2_EP_NUM_NOTIFICATION (0) +#endif + +#ifndef USB_CDC2_EP_NUM_DATA_OUT +#define USB_CDC2_EP_NUM_DATA_OUT (0) +#endif + +#ifndef USB_CDC2_EP_NUM_DATA_IN +#define USB_CDC2_EP_NUM_DATA_IN (0) +#endif + +#ifndef USB_MSC_EP_NUM_OUT +#define USB_MSC_EP_NUM_OUT (0) +#endif + +#ifndef USB_MSC_EP_NUM_IN +#define USB_MSC_EP_NUM_IN (0) +#endif + +#ifndef USB_HID_EP_NUM_OUT +#define USB_HID_EP_NUM_OUT (0) +#endif + +#ifndef USB_HID_EP_NUM_IN +#define USB_HID_EP_NUM_IN (0) +#endif + +#ifndef USB_MIDI_EP_NUM_OUT +#define USB_MIDI_EP_NUM_OUT (0) +#endif + +#ifndef USB_MIDI_EP_NUM_IN +#define USB_MIDI_EP_NUM_IN (0) +#endif + + #endif // __INCLUDED_MPCONFIG_CIRCUITPY_H diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 8801213655..b87ffaedba 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -271,6 +271,9 @@ CFLAGS += -DCIRCUITPY_RGBMATRIX=$(CIRCUITPY_RGBMATRIX) CIRCUITPY_ROTARYIO ?= 1 CFLAGS += -DCIRCUITPY_ROTARYIO=$(CIRCUITPY_ROTARYIO) +CIRCUITPY_ROTARYIO_SOFTENCODER ?= 0 +CFLAGS += -DCIRCUITPY_ROTARYIO_SOFTENCODER=$(CIRCUITPY_ROTARYIO_SOFTENCODER) + CIRCUITPY_RTC ?= 1 CFLAGS += -DCIRCUITPY_RTC=$(CIRCUITPY_RTC) @@ -366,6 +369,7 @@ CFLAGS += -DCIRCUITPY_USB_VENDOR=$(CIRCUITPY_USB_VENDOR) ifndef USB_NUM_EP $(error "USB_NUM_EP (number of USB endpoint pairs)must be defined") endif +CFLAGS += -DUSB_NUM_EP=$(USB_NUM_EP) # For debugging. CIRCUITPY_USTACK ?= 0 diff --git a/shared-bindings/storage/__init__.h b/shared-bindings/storage/__init__.h index cd9366c1bc..0303e0440c 100644 --- a/shared-bindings/storage/__init__.h +++ b/shared-bindings/storage/__init__.h @@ -30,6 +30,8 @@ #include #include +#include "shared-module/storage/__init__.h" + void common_hal_storage_mount(mp_obj_t vfs_obj, const char *path, bool readonly); void common_hal_storage_umount_path(const char *path); void common_hal_storage_umount_object(mp_obj_t vfs_obj); diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 13afbbf3e6..af2ed81085 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -44,7 +44,7 @@ //| """Create a description of a USB HID device. To create an actual device, //| pass a `Device` to `usb_hid.configure_usb()`. //| -//| :param ReadableBuffer descriptor: The USB HID Report descriptor bytes. The descriptor is not +//| :param ReadableBuffer report_descriptor: The USB HID Report descriptor bytes. The descriptor is not //| not verified for correctness; it is up to you to make sure it is not malformed. //| :param int usage_page: The Usage Page value from the descriptor. Must match what is in the descriptor. //| :param int usage: The Usage value from the descriptor. Must match what is in the descriptor. @@ -60,9 +60,9 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { usb_hid_device_obj_t *self = m_new_obj(usb_hid_device_obj_t); self->base.type = &usb_hid_device_type; - enum { ARG_descriptor, ARG_usage, ARG_usage_page, ARG_in_report_length, ARG_out_report_length, ARG_report_id_index }; + enum { ARG_report_descriptor, ARG_usage, ARG_usage_page, ARG_in_report_length, ARG_out_report_length, ARG_report_id_index }; static const mp_arg_t allowed_args[] = { - { MP_QSTR_descriptor, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_report_descriptor, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_usage_page, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_usage, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_in_report_length, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT } , @@ -74,7 +74,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; - mp_get_buffer_raise(args[ARG_descriptor].u_obj, &bufinfo, MP_BUFFER_READ); + mp_get_buffer_raise(args[ARG_report_descriptor].u_obj, &bufinfo, MP_BUFFER_READ); mp_obj_t descriptor = mp_obj_new_bytearray(bufinfo.len, bufinfo.buf); const mp_int_t usage_page_arg = args[ARG_usage_page].u_int; diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 8d5d67d52a..953a97ab7b 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -67,17 +67,25 @@ STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { } MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_configure_usb_obj, usb_hid_configure_usb); - -STATIC const mp_rom_map_elem_t usb_hid_module_globals_table[] = { +// usb_hid.devices is set once the usb devices are determined, after boot.py runs. +STATIC mp_map_elem_t usb_hid_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_hid_configure_usb_obj) }, - { MP_ROM_QSTR(MP_QSTR_devices), MP_ROM_PTR(&common_hal_usb_hid_devices) }, - { MP_ROM_QSTR(MP_QSTR_Device), MP_ROM_PTR(&usb_hid_device_type) }, + { MP_ROM_QSTR(MP_QSTR_devices), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_Device), MP_OBJ_FROM_PTR(&usb_hid_device_type) }, }; -STATIC MP_DEFINE_CONST_DICT(usb_hid_module_globals, usb_hid_module_globals_table); +STATIC MP_DEFINE_MUTABLE_DICT(usb_hid_module_globals, usb_hid_module_globals_table); const mp_obj_module_t usb_hid_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t *)&usb_hid_module_globals, }; + +void usb_hid_set_devices(mp_obj_t devices) { + mp_map_elem_t *elem = + mp_map_lookup(&usb_hid_module_globals.map, MP_ROM_QSTR(MP_QSTR_devices), MP_MAP_LOOKUP); + if (elem) { + elem->value = devices; + } +} diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index 532625d623..3e51170cc4 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -29,9 +29,12 @@ #include "py/obj.h" #include "py/objtuple.h" +#include "shared-module/usb_hid/__init__.h" extern mp_obj_tuple_t common_hal_usb_hid_devices; +void usb_hid_set_devices(mp_obj_t devices); + void common_hal_usb_hid_configure_usb_defaults(void); bool common_hal_usb_hid_configure_usb(mp_obj_t devices_seq); diff --git a/shared-bindings/usb_midi/__init__.h b/shared-bindings/usb_midi/__init__.h index 25e0fbfcbf..dab3dc8f72 100644 --- a/shared-bindings/usb_midi/__init__.h +++ b/shared-bindings/usb_midi/__init__.h @@ -28,6 +28,7 @@ #define MICROPY_INCLUDED_SHARED_BINDINGS_USB_MIDI___INIT___H #include "py/obj.h" +#include "shared-module/usb_midi/__init__.h" extern mp_obj_dict_t usb_midi_module_globals; diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 3a4fc1f3b5..6a16ba9ebe 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -41,7 +41,7 @@ #include "supervisor/usb.h" #include "tusb.h" -static const uint8_t storage_usb_msc_descriptor_template[] = { +static const uint8_t usb_msc_descriptor_template[] = { // MSC Interface Descriptor 0x09, // 0 bLength 0x04, // 1 bDescriptorType (Interface) @@ -75,28 +75,32 @@ static const uint8_t storage_usb_msc_descriptor_template[] = { }; // Is the MSC device enabled? -bool storage_usb_enabled; +bool storage_usb_is_enabled; -size_t storage_usb_descriptor_length(void) { - return sizeof(usb_msc_descriptor); +bool storage_usb_enabled(void) { + return storage_usb_is_enabled; } -static const char[] storage_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " Mass Storage"; +size_t storage_usb_descriptor_length(void) { + return sizeof(usb_msc_descriptor_template); +} + +static const char storage_interface_name[] = USB_INTERFACE_NAME " Mass Storage"; size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { - memcpy(descriptor_buf, storage_usb_msc_descriptor_template, sizeof(storage_usb_msc_descriptor_template)); + memcpy(descriptor_buf, usb_msc_descriptor_template, sizeof(usb_msc_descriptor_template)); descriptor_buf[MSC_INTERFACE_INDEX] = *current_interface; (*current_interface)++; descriptor_buf[MSC_IN_ENDPOINT_INDEX] = USB_MSC_EP_NUM_IN ? USB_MSC_EP_NUM_IN : *current_endpoint; descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | (USB_MSC_EP_NUM_OUT ? USB_MSC_EP_NUM_OUT : *current_endpoint); - (*current_endpoint)++: + (*current_endpoint)++; - usb_add_interface_string(*current_interface_string,); + usb_add_interface_string(*current_interface_string, storage_interface_name); descriptor_buf[MSC_INTERFACE_STRING_INDEX] = *current_interface_string; (*current_interface_string)++; - return sizeof(storage_usb_msc_descriptor_template); + return sizeof(usb_msc_descriptor_template); } @@ -118,7 +122,7 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_ } void storage_init(void) { - storage_usb_enabled = true; + storage_usb_is_enabled = true; } void common_hal_storage_mount(mp_obj_t vfs_obj, const char *mount_path, bool readonly) { @@ -238,6 +242,6 @@ bool common_hal_storage_configure_usb(bool enabled) { if (tud_connected()) { return false; } - storage_usb_enabled = enabled; + storage_usb_is_enabled = enabled; return true; } diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index 58ece345d1..e9149bfa1b 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -27,7 +27,7 @@ #ifndef SHARED_MODULE_STORAGE___INIT___H #define SHARED_MODULE_STORAGE___INIT___H -extern bool storage_usb_enabled; +bool storage_usb_enabled(void); void storage_init(void); size_t storage_usb_descriptor_length(void); diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index a918476320..5de32fcde2 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -37,9 +37,6 @@ #error CFG_TUD_CDC must be exactly 2 #endif -bool usb_cdc_repl_enabled; -bool usb_cdc_data_enabled; - static const uint8_t usb_cdc_descriptor_template[] = { // CDC IAD Descriptor 0x08, // 0 bLength @@ -135,10 +132,10 @@ static const uint8_t usb_cdc_descriptor_template[] = { 0x00, // 65 bInterval 0 (unit depends on device speed) }; -static const char[] repl_cdc_comm_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC control"; -static const char[] data_cdc_comm_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC2 control"; -static const char[] repl_cdc_data_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC data"; -static const char[] data_cdc_data_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " CDC2 data"; +static const char[] repl_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC control"; +static const char[] data_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC2 control"; +static const char[] repl_cdc_data_interface_name = USB_INTERFACE_NAME " CDC data"; +static const char[] data_cdc_data_interface_name = USB_INTERFACE_NAME " CDC2 data"; static usb_cdc_serial_obj_t usb_cdc_repl_obj = { .base.type = &usb_cdc_serial_type, @@ -154,6 +151,17 @@ static usb_cdc_serial_obj_t usb_cdc_data_obj = { .idx = 1, }; +static bool usb_cdc_repl_is_enabled; +static bool usb_cdc_data_is_enabled; + +bool usb_cdc_repl_enabled(void) { + return usb_cdc_repl_is_enabled; +} + +bool usb_cdc_data_enabled(void) { + return usb_cdc_data_enabled; +} + size_t usb_cdc_descriptor_length(void) { return sizeof(usb_cdc_descriptor_template); } @@ -200,8 +208,8 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac } void usb_cdc_init(void) { - usb_cdc_repl_enabled = true; - usb_cdc_data_enabled = false; + usb_cdc_repl_is_enabled = true; + usb_cdc_data_is_enabled = false; } bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) { diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 973569530f..770ee13170 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -29,8 +29,8 @@ #include "py/objtuple.h" -extern bool usb_cdc_repl_enabled; -extern bool usb_cdc_data_enabled; +bool usb_cdc_repl_enabled(void); +bool usb_cdc_data_enabled(void); void usb_cdc_init(void); size_t usb_cdc_descriptor_length(void); diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 02f43c167c..532be81051 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -28,12 +28,13 @@ #include "py/runtime.h" #include "shared-bindings/usb_hid/Device.h" +#include "shared-module/usb_hid/__init__.h" #include "shared-module/usb_hid/Device.h" #include "supervisor/shared/translate.h" #include "supervisor/shared/tick.h" #include "tusb.h" -static const uint8_t keyboard_descriptor[] = { +static const uint8_t keyboard_report_descriptor[] = { 0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls) 0x09, 0x06, // 2,3 Usage (Keyboard) 0xA1, 0x01, // 4,5 Collection (Application) @@ -69,9 +70,9 @@ static const uint8_t keyboard_descriptor[] = { }; const usb_hid_device_obj_t usb_hid_device_keyboard_obj = { - .descriptor = keyboard_descriptor, - .descriptor_length = sizeof(keyboard_descriptor), - .usage_page = 0x01 + .report_descriptor = keyboard_report_descriptor, + .report_descriptor_length = sizeof(keyboard_report_descriptor), + .usage_page = 0x01, .usage = 0x06, .in_report_length = 8, .out_report_length = 1, @@ -79,7 +80,7 @@ const usb_hid_device_obj_t usb_hid_device_keyboard_obj = { }; -static const uint8_t mouse_descriptor[] = { +static const uint8_t mouse_report_descriptor[] = { 0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls) 0x09, 0x02, // 2,3 Usage (Mouse) 0xA1, 0x01, // 4,5 Collection (Application) @@ -117,17 +118,16 @@ static const uint8_t mouse_descriptor[] = { }; const usb_hid_device_obj_t usb_hid_device_mouse_obj = { - .descriptor = mouse_descriptor, - .descriptor_length = sizeof(mouse_descriptor), - .usage_page = 0x01 + .report_descriptor = mouse_report_descriptor, + .report_descriptor_length = sizeof(mouse_report_descriptor), + .usage_page = 0x01, .usage = 0x02, .in_report_length = 4, .out_report_length = 0, - .descriptor = { .report_id_index = MOUSE_REPORT_ID_INDEX, }; -static const uint8_t consumer_control_descriptor[] = { +static const uint8_t consumer_control_report_descriptor[] = { 0x05, 0x0C, // 0,1 Usage Page (Consumer) 0x09, 0x01, // 2,3 Usage (Consumer Control) 0xA1, 0x01, // 4,5 Collection (Application) @@ -144,9 +144,9 @@ static const uint8_t consumer_control_descriptor[] = { }; const usb_hid_device_obj_t usb_hid_device_consumer_control_obj = { - .descriptor = consumer_control_descriptor, - .descriptor_length = sizeof(consumer_control_descriptor), - .usage_page = 0x0C + .report_descriptor = consumer_control_report_descriptor, + .report_descriptor_length = sizeof(consumer_control_report_descriptor), + .usage_page = 0x0C, .usage = 0x01, .in_report_length = 2, .out_report_length = 0, @@ -154,14 +154,14 @@ const usb_hid_device_obj_t usb_hid_device_consumer_control_obj = { }; -void common_hal_usb_hid_device_construct(usb_hid_device_obj_t *self, mp_obj_t descriptor, uint8_t usage_page, uint8_t usage, uint8_t in_report_length, uint8_t out_report_length, uint8_t report_id_index) { +void common_hal_usb_hid_device_construct(usb_hid_device_obj_t *self, mp_obj_t report_descriptor, uint8_t usage_page, uint8_t usage, uint8_t in_report_length, uint8_t out_report_length, uint8_t report_id_index) { // report buffer pointers are NULL at start, and are created on demand. - self->descriptor_obj = descriptor; + self->report_descriptor_obj = report_descriptor; mp_buffer_info_t bufinfo; - mp_get_buffer_raise(descriptor, &bufinfo, MP_BUFFER_READ); - self->descriptor = bufinfo.buf; - self->descriptor_length = bufinfo.len; + mp_get_buffer_raise(report_descriptor, &bufinfo, MP_BUFFER_READ); + self->report_descriptor = bufinfo.buf; + self->report_descriptor_length = bufinfo.len; self->usage_page = usage_page; self->usage = usage; @@ -195,20 +195,11 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t * memcpy(self->in_report_buffer, report, len); - if (!tud_hid_report(self->in_report_id, self->in_report_buffer, len)) { + if (!tud_hid_report(self->report_id, self->in_report_buffer, len)) { mp_raise_msg(&mp_type_OSError, translate("USB Error")); } } -static usb_hid_device_obj_t *get_hid_device(uint8_t report_id) { - for (uint8_t i = 0; i < USB_HID_NUM_DEVICES; i++) { - if (usb_hid_devices[i].report_id == report_id) { - return &usb_hid_devices[i]; - } - } - return NULL; -} - // Callbacks invoked when receive Get_Report request through control endpoint uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) { (void)itf; @@ -218,7 +209,7 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t } // fill buffer with current report - memcpy(buffer, get_hid_device(report_id)->in_report_buffer, reqlen); + memcpy(buffer, usb_hid_get_device_with_report_id(report_id)->in_report_buffer, reqlen); return reqlen; } @@ -233,7 +224,7 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t rep return; } - usb_hid_device_obj_t *hid_device = get_hid_device(report_id); + usb_hid_device_obj_t *hid_device = usb_hid_get_device_with_report_id(report_id); if (hid_device && hid_device->out_report_length >= bufsize) { memcpy(hid_device->out_report_buffer, buffer, bufsize); diff --git a/shared-module/usb_hid/Device.h b/shared-module/usb_hid/Device.h index e6ac32bb54..fb46f4a710 100644 --- a/shared-module/usb_hid/Device.h +++ b/shared-module/usb_hid/Device.h @@ -35,13 +35,13 @@ typedef struct { mp_obj_base_t base; // If not MP_OBJ_NULL, points to Python array object whose contents are the descriptor. - mp_obj_t descriptor_obj; + mp_obj_t report_descriptor_obj; // If not NULL, points to raw bytes that are the descriptor. - uint8_t *descriptor; + const uint8_t *report_descriptor; uint8_t *in_report_buffer; uint8_t *out_report_buffer; uint16_t report_id_index; - uint16_t descriptor_length; + uint16_t report_descriptor_length; uint8_t usage_page; uint8_t usage; uint8_t report_id; @@ -49,8 +49,8 @@ typedef struct { uint8_t out_report_length; } usb_hid_device_obj_t; -extern usb_hid_device_obj_t usb_hid_device_keyboard_obj; -extern usb_hid_device_obj_t usb_hid_device_mouse_obj; -extern usb_hid_device_obj_t usb_hid_device_consumer_control_obj; +extern const usb_hid_device_obj_t usb_hid_device_keyboard_obj; +extern const usb_hid_device_obj_t usb_hid_device_mouse_obj; +extern const usb_hid_device_obj_t usb_hid_device_consumer_control_obj; #endif /* SHARED_MODULE_USB_HID_DEVICE_H */ diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 5d364e20a1..a59fa069d8 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -26,70 +26,106 @@ #include -#include "shared-module/usb_hid/__init__.h" +#include "tusb.h" + +#include "py/gc.h" +#include "shared-bindings/usb_hid/__init__.h" +#include "shared-module/usb_hid/Device.h" #include "supervisor/memory.h" +#include "supervisor/usb.h" static const uint8_t usb_hid_descriptor_template[] = { 0x09, // 0 bLength - 0x21, // 1 bDescriptorType (HID) - 0x11, 0x01, // 2 bcdHID 1.11 - 0x00, // 3 bCountryCode - 0x01, // 4 bNumDescriptors - 0x22, // 5 bDescriptorType[0] (HID) - 0xFF, 0xFF, // 6,7 wDescriptorLength[0] [SET AT RUNTIME: lo, hi] -#define HID_DESCRIPTOR_LENGTH_INDEX (6) + 0x04, // 1 bDescriptorType (Interface) + 0xFF, // 2 bInterfaceNumber 3 +#define HID_DESCRIPTOR_INTERFACE_INDEX (2) + 0x00, // 3 bAlternateSetting + 0x02, // 4 bNumEndpoints 2 + 0x03, // 5 bInterfaceClass: HID + 0x00, // 6 bInterfaceSubClass: NOBOOT + 0x00, // 7 bInterfaceProtocol: NONE + 0xFF, // 8 iInterface (String Index) [SET AT RUNTIME] +#define HID_DESCRIPTOR_INTERFACE_STRING_INDEX (8) - 0x07, // 8 bLength - 0x05, // 9 bDescriptorType (Endpoint) - 0xFF, // 10 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | endpoint] -#define HID_IN_ENDPOINT_INDEX (10) - 0x03, // 11 bmAttributes (Interrupt) - 0x40, 0x00, // 12,13 wMaxPacketSize 64 - 0x08, // 14 bInterval 8 (unit depends on device speed) + 0x09, // 9 bLength + 0x21, // 10 bDescriptorType (HID) + 0x11, 0x01, // 11,12 bcdHID 1.11 + 0x00, // 13 bCountryCode + 0x01, // 14 bNumDescriptors + 0x22, // 15 bDescriptorType[0] (HID) + 0xFF, 0xFF, // 16,17 wDescriptorLength[0] [SET AT RUNTIME: lo, hi] +#define HID_DESCRIPTOR_LENGTH_INDEX (16) - 0x07, // 15 bLength - 0x05, // 16 bDescriptorType (Endpoint) - 0xFF, // 17 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] -#define HID_OUT_ENDPOINT_INDEX (17) - 0x03, // 18 bmAttributes (Interrupt) - 0x40, 0x00, // 19,20 wMaxPacketSize 64 - 0x08, // 21 bInterval 8 (unit depends on device speed) + 0x07, // 18 bLength + 0x05, // 19 bDescriptorType (Endpoint) + 0xFF, // 20 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | endpoint] +#define HID_IN_ENDPOINT_INDEX (20) + 0x03, // 21 bmAttributes (Interrupt) + 0x40, 0x00, // 22,23 wMaxPacketSize 64 + 0x08, // 24 bInterval 8 (unit depends on device speed) + + 0x07, // 25 bLength + 0x05, // 26 bDescriptorType (Endpoint) + 0xFF, // 27 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] +#define HID_OUT_ENDPOINT_INDEX (26) + 0x03, // 28 bmAttributes (Interrupt) + 0x40, 0x00, // 29,30 wMaxPacketSize 64 + 0x08, // 31 bInterval 8 (unit depends on device speed) }; -// Sequence of devices to configure. +// Sequence of devices to configure. Passed to usb_hid.configure_usb(). +// Not used after boot.py finishes and VM restarts. static mp_obj_t hid_devices_seq; // Is the HID device enabled? -bool usb_hid_enabled; -supervisor_allocation *hid_report_descriptor_allocation; -supervisor_allocation *hid_devices_allocation; +static bool usb_hid_is_enabled; +static supervisor_allocation *hid_report_descriptor_allocation; +static size_t total_hid_report_descriptor_length; +static supervisor_allocation *hid_devices_allocation; +static mp_int_t hid_devices_num; // This is the interface descriptor, not the report descriptor. size_t usb_hid_descriptor_length(void) { return sizeof(usb_hid_descriptor_template); } -static const char usb_hid_interface_name[] = MP_STRINGIFY(USB_INTERFACE_NAME) " HID"; +// Total length of the report descriptor, with all configured devices. +size_t usb_hid_report_descriptor_length(void) { + return total_hid_report_descriptor_length; +} + +bool usb_hid_enabled(void) { + return usb_hid_is_enabled; +} + +static const char usb_hid_interface_name[] = USB_INTERFACE_NAME " HID"; // This is the interface descriptor, not the report descriptor. size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length) { memcpy(descriptor_buf, usb_hid_descriptor_template, sizeof(usb_hid_descriptor_template)); + descriptor_buf[HID_DESCRIPTOR_INTERFACE_INDEX] = *current_interface; + (*current_interface)++; + + usb_add_interface_string(*current_interface, usb_hid_interface_name); + descriptor_buf[HID_DESCRIPTOR_INTERFACE_STRING_INDEX] = *current_interface_string; + (*current_interface_string)++; + descriptor_buf[HID_DESCRIPTOR_LENGTH_INDEX] = report_descriptor_length & 0xFF; descriptor_buf[HID_DESCRIPTOR_LENGTH_INDEX + 1] = (report_descriptor_length >> 8); descriptor_buf[HID_IN_ENDPOINT_INDEX] = USB_HID_EP_NUM_IN ? USB_HID_EP_NUM_IN : *current_endpoint; descriptor_buf[HID_OUT_ENDPOINT_INDEX] = 0x80 | (USB_HID_EP_NUM_OUT ? USB_HID_EP_NUM_OUT : *current_endpoint); - (*current_endpoint)++: + (*current_endpoint)++; return sizeof(usb_hid_descriptor_template); } static mp_obj_t default_hid_devices[] = { - MP_OBJ_FROM_PTR(usb_hid_device_keyboard_obj), - MP_OBJ_FROM_PTR(usb_hid_device_mouse_obj), - MP_OBJ_FROM_PTR(usb_hid_device_consumer_control_obj), + MP_OBJ_FROM_PTR(&usb_hid_device_keyboard_obj), + MP_OBJ_FROM_PTR(&usb_hid_device_mouse_obj), + MP_OBJ_FROM_PTR(&usb_hid_device_consumer_control_obj), }; // Set the default list of devices that will be included. Called before boot.py runs, in the boot.py VM. @@ -97,78 +133,79 @@ void common_hal_usb_hid_configure_usb_defaults(void) { common_hal_usb_hid_configure_usb(mp_obj_new_tuple(sizeof(default_hid_devices), default_hid_devices)); } -bool common_hal_usb_hid_configure_usb(mp_obj_t devices_seq) { +bool common_hal_usb_hid_configure_usb(mp_obj_t devices) { // We can't change the devices once we're connected. if (tud_connected()) { return false; } // Remember the devices for use in usb_hid_post_boot_py. - hid_devices_seq = devices_seq; + hid_devices_seq = devices; return true; } +void usb_hid_init(void) { + usb_hid_is_enabled = true; +} + // Build the combined HID report descriptor and save the chosen devices. // Both are saved in supervisor allocations. void usb_hid_post_boot_py(void) { - size_t total_report_descriptors_length = 0; // Build a combined report descriptor - mp_int_t len = mp_obj_get_int(mp_obj_len(hid_devices_seq)); + hid_devices_num = mp_obj_get_int(mp_obj_len(hid_devices_seq)); // First get the total size. - for (size_t i = 0; i < len; i++) { - mp_obj_t item = mp_obj_subscr(devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); - if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { - return USB_CONFIG_NON_DEVICE; for (size_t i = 0; i < len; i++) { - mp_obj_t item = (devices, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); - if (!MP_OBJ_IS_TYPE(item, &usb_hid_device_type)) { - return USB_CONFIG_NON_DEVICE; - } - total_report_descriptors_length += device->report_descriptor_length; + total_hid_report_descriptor_length = 0; + for (mp_int_t i = 0; i < hid_devices_num; i++) { + // hid_devices_seq has already been validated to contain only usb_hid_device_obj_t objects. + usb_hid_device_obj_t *device = + MP_OBJ_TO_PTR(mp_obj_subscr(hid_devices_seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL)); + total_hid_report_descriptor_length += device->report_descriptor_length; } - } - total_report_descriptors_length += device->report_descriptor_length; - } - if (len == 1) { - // Don't need space for a report id if there's only one device. - total_report_descriptors_length -= 2; + // Don't need space for a report id if there's only one device. + if (hid_devices_num == 1) { + total_hid_report_descriptor_length -= 2; } // Allocate storage that persists across VMs to build the combined descriptor // and to remember the device details. hid_report_descriptor_allocation = - allocate_memory(total_report_descriptors_length, false /*highaddress*/, true /*movable*/); + allocate_memory(align32_size(total_hid_report_descriptor_length), + false /*highaddress*/, true /*movable*/); - hid_devices_allocation = allocate_memory(sizeof(usb_hid_device_obj_t) * len); - usb_hid_device_obj_t hid_devices[] = (usb_hid_device_obj_t[]) hid_devices_allocation->ptr; + hid_devices_allocation = + allocate_memory(align32_size(sizeof(usb_hid_device_obj_t) * hid_devices_num), + false /*highaddress*/, true /*movable*/); + usb_hid_device_obj_t *hid_devices = (usb_hid_device_obj_t *) hid_devices_allocation->ptr; - uint8_t *descriptor_start = (uint8_t *) hid_report_descriptor_allocation->ptr; + uint8_t *report_descriptor_start = (uint8_t *) hid_report_descriptor_allocation->ptr; - for (size_t i = 0; i < len; i++) { - usb_hid_device_obj_t *device = MP_OBJ_TO_PTR(hid_devices_seq, mp_obj_new_small_int(i), MP_OBJ_SENTINEL); + for (mp_int_t i = 0; i < hid_devices_num; i++) { + usb_hid_device_obj_t *device = + MP_OBJ_TO_PTR(mp_obj_subscr(hid_devices_seq, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL)); // Copy the report descriptor for this device. - if (len == 1) { + if (hid_devices_num == 1) { // Theres only one device, so it shouldn't have a report ID. // Copy the descriptor, but splice out the report id indicator and value (2 bytes). - memcpy(descriptor_start, device->descriptor, device->report_id_index - 1); - descriptor_start += device->report_id_index - 1; - memcpy(descriptor_start, device->descriptor + device->report_id_index + 1, + memcpy(report_descriptor_start, device->report_descriptor, device->report_id_index - 1); + report_descriptor_start += device->report_id_index - 1; + memcpy(report_descriptor_start, device->report_descriptor + device->report_id_index + 1, device->report_descriptor_length - device->report_id_index - 1); } else { // Copy the whole descriptor and fill in the report id. - memcpy(descriptor_start, device->descriptor, device->descriptor_len); - descriptor_start[device->report_id_index] = i + 1; - descriptor_start += device->descriptor_len; + memcpy(report_descriptor_start, device->report_descriptor, device->report_descriptor_length); + report_descriptor_start[device->report_id_index] = i + 1; + report_descriptor_start += device->report_descriptor_length; } // Copy the device data and discard any descriptor-bytes object pointer. memcpy(&hid_devices[i], device, sizeof(usb_hid_device_obj_t)); - hid_devices[i].descriptor_obj = mp_const_none; + hid_devices[i].report_descriptor_obj = mp_const_none; } // No longer keeping the Python object of devices to configure. @@ -176,13 +213,31 @@ void usb_hid_post_boot_py(void) { } void usb_hid_gc_collect(void) { - // Once tud_mounted() is true, we're done with the constructed descriptors. if (tud_mounted()) { + // Once tud_mounted() is true, we're done with the constructed descriptors. free_memory(hid_report_descriptor_allocation); - free_memory(usb_hid_devices_allocation); - } else { - gc_collect_ptr(hid_devices_seq); - gc_collect_ptr(hid_report_descriptor_allocation->ptr); - gc_collect_ptr(usb_hid_devices_allocation_ptr); } + + gc_collect_ptr(hid_devices_seq); + gc_collect_ptr(hid_report_descriptor_allocation->ptr); + gc_collect_ptr(hid_devices_allocation->ptr); +} + +#if CIRCUITPY_USB_HID +// Invoked when GET HID REPORT DESCRIPTOR is received. +// Application return pointer to descriptor +// Descriptor contents must exist long enough for transfer to complete +uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { + return (uint8_t *) hid_report_descriptor_allocation->ptr; +} +#endif + +usb_hid_device_obj_t *usb_hid_get_device_with_report_id(uint8_t report_id) { + for (uint8_t i = 0; i < hid_devices_num; i++) { + usb_hid_device_obj_t *hid_devices = (usb_hid_device_obj_t *) hid_devices_allocation->ptr; + if (hid_devices[i].report_id == report_id) { + return &hid_devices[i]; + } + } + return NULL; } diff --git a/shared-module/usb_hid/__init__.h b/shared-module/usb_hid/__init__.h index f95a94c679..048e6107bc 100644 --- a/shared-module/usb_hid/__init__.h +++ b/shared-module/usb_hid/__init__.h @@ -29,10 +29,19 @@ #include "shared-module/usb_hid/Device.h" -extern bool usb_hid_enabled; extern usb_hid_device_obj_t usb_hid_devices[]; +bool usb_hid_enabled(void); + +void usb_hid_init(void); +void usb_hid_post_boot_py(void); + +size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length); +size_t usb_hid_descriptor_length(void); +size_t usb_hid_report_descriptor_length(void); + +usb_hid_device_obj_t *usb_hid_get_device_with_report_id(uint8_t report_id); + void usb_hid_gc_collect(void); - #endif // SHARED_MODULE_USB_HID___INIT___H diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index d1402d3e59..8897fd39b7 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -33,6 +33,7 @@ #include "shared-bindings/usb_midi/PortIn.h" #include "shared-bindings/usb_midi/PortOut.h" #include "supervisor/memory.h" +#include "supervisor/usb.h" #include "tusb.h" supervisor_allocation *usb_midi_allocation; @@ -79,7 +80,7 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x24, // 28 bDescriptorType: CLASS SPECIFIC INTERFACE 0x01, // 29 bDescriptorSubtype: MIDI STREAMING HEADER 0x00, 0x01, // 30,31 bsdMSC (MIDI STREAMING) version 1.0 - 0x25, 0x00 // 32,33 wLength + 0x25, 0x00, // 32,33 wLength // MIDI Embedded In Jack Descriptor 0x06, // 34 bLength @@ -155,17 +156,21 @@ static const uint8_t usb_midi_descriptor_template[] = { }; // Is the USB MIDI device enabled? -bool usb_midi_enabled; +static bool usb_midi_is_enabled; + +bool usb_midi_enabled(void) { + return usb_midi_is_enabled; +} size_t usb_midi_descriptor_length(void) { return sizeof(usb_midi_descriptor_template); } -static const char[] midi_streaming_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " MIDI"; -static const char[] midi_audio_control_interface_name = MP_STRINGIFY(USB_INTERFACE_NAME) " Audio"; -static const char[] midi_in_jack_name = MP_STRINGIFY(USB_INTERFACE_NAME) " usb_midi.ports[0]"; -static const char[] midi_out_jack_name = MP_STRINGIFY(USB_INTERFACE_NAME) " usb_midi.ports[0]"; +static const char midi_streaming_interface_name[] = USB_INTERFACE_NAME " MIDI"; +static const char midi_audio_control_interface_name[] = USB_INTERFACE_NAME " Audio"; +static const char midi_in_jack_name[] = USB_INTERFACE_NAME " usb_midi.ports[0]"; +static const char midi_out_jack_name[] = USB_INTERFACE_NAME " usb_midi.ports[0]"; size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); @@ -173,8 +178,9 @@ size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfa descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX] = *current_interface; (*current_interface)++; - descriptor_buf[MSC_IN_ENDPOINT_INDEX] = USB_MIDI_EP_NUM_IN ? USB_MIDI_EP_NUM_IN : *current_endpoint; - descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = + descriptor_buf[MIDI_STREAMING_IN_ENDPOINT_INDEX] = + USB_MIDI_EP_NUM_IN ? USB_MIDI_EP_NUM_IN : *current_endpoint; + descriptor_buf[MIDI_STREAMING_OUT_ENDPOINT_INDEX] = 0x80 | (USB_MIDI_EP_NUM_OUT ? USB_MIDI_EP_NUM_OUT : *current_endpoint); (*current_endpoint)++; @@ -203,13 +209,13 @@ size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfa void usb_midi_init(void) { - usb_midi_enabled = true; + usb_midi_is_enabled = true; } void usb_midi_usb_init(void) { mp_obj_tuple_t *ports; - if (usb_midi_enabled) { + if (usb_midi_is_enabled) { // TODO(tannewt): Make this dynamic. size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t *) * 2); size_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t)); @@ -241,6 +247,6 @@ bool common_hal_usb_midi_configure_usb(bool enabled) { if (tud_connected()) { return false; } - usb_midi_enabled = enabled; + usb_midi_is_enabled = enabled; return true; } diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index 28871185cf..4bb5e5f52a 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -27,11 +27,11 @@ #ifndef SHARED_MODULE_USB_MIDI___INIT___H #define SHARED_MODULE_USB_MIDI___INIT___H -extern bool usb_midi_enabled; void usb_midi_init(void); void usb_midi_usb_init(void); +bool usb_midi_enabled(void); size_t usb_midi_descriptor_length(void); size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string); diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 04a482886e..d866c71f4b 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -26,6 +26,9 @@ #include "lib/tinyusb/src/tusb.h" +#include "py/gc.h" +#include "py/objstr.h" +#include "py/runtime.h" #include "supervisor/usb.h" #if CIRCUITPY_USB_CDC @@ -44,20 +47,17 @@ #include "shared-bindings/storage/__init__.h" #endif -// For COMMON_HAL_MCU_PROCESSOR_UID_LENGTH -#include "common-hal/microcontroller/Processor.h" +#include "shared-bindings/microcontroller/Processor.h" -uint8_t *device_descriptor; -uint8_t *config_descriptor; // Table for collecting interface strings (interface names) as descriptor is built. #define MAX_INTERFACE_STRINGS 16 // slot 0 is not used. -static char * collected_interface_strings[]; -static uint16_t current_interface_string; +static uint16_t **collected_interface_strings; +static uint8_t current_interface_string; -static const char manufacturer_name[] = MP_STRINGIFY(USB_MANUFACTURER); -static const char product_name[] = MP_STRINGIFY(USB_PRODUCT); +static const char manufacturer_name[] = USB_MANUFACTURER; +static const char product_name[] = USB_PRODUCT; // Serial number string is UID length * 2 (2 nibbles per byte) + 1 byte for null termination. static char serial_number_hex_string[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2 + 1]; @@ -86,6 +86,8 @@ static const uint8_t device_descriptor_template[] = { 0x01, // 17 bNumConfigurations 1 }; +static uint8_t device_descriptor[sizeof(device_descriptor_template)]; + static const uint8_t configuration_descriptor_template[] = { 0x09, // 0 bLength 0x02, // 1 bDescriptorType (Configuration) @@ -100,6 +102,8 @@ static const uint8_t configuration_descriptor_template[] = { 0x32, // 8 bMaxPower 100mA }; +static uint8_t configuration_descriptor[sizeof(configuration_descriptor_template)]; + // Initialization done before boot.py is run. // Turn on or off various USB devices. On devices with limited endpoints, // some may be off by default. @@ -132,55 +136,53 @@ static void usb_build_device_descriptor(uint16_t vid, uint16_t pid) { device_descriptor[DEVICE_PID_LO_INDEX] = pid & 0xFF; device_descriptor[DEVICE_PID_HI_INDEX] = pid >> 8; - usb_add_interface_string(*current_interface_string, manufacturer_name); - device_descriptor[DEVICE_MANUFACTURER_STRING_INDEX] = *current_interface_string; - (*current_interface_string)++; + usb_add_interface_string(current_interface_string, manufacturer_name); + device_descriptor[DEVICE_MANUFACTURER_STRING_INDEX] = current_interface_string; + current_interface_string++; - usb_add_interface_string(*current_interface_string, product_name); - device_descriptor[DEVICE_PRODUCT_STRING_INDEX] = *current_interface_string; - (*current_interface_string)++; + usb_add_interface_string(current_interface_string, product_name); + device_descriptor[DEVICE_PRODUCT_STRING_INDEX] = current_interface_string; + current_interface_string++; - usb_add_interface_string(*current_interface_string, serial_number_hex_string); - device_descriptor[DEVICE_SERIAL_NUMBER_STRING_INDEX] = *current_interface_string; - (*current_interface_string)++; + usb_add_interface_string(current_interface_string, serial_number_hex_string); + device_descriptor[DEVICE_SERIAL_NUMBER_STRING_INDEX] = current_interface_string; + current_interface_string++; } -static void usb_build_configuration_descriptor(uint16_t total_length, uint8_t num_interfaces) { +static void usb_build_configuration_descriptor(void) { size_t total_descriptor_length = sizeof(configuration_descriptor_template); // CDC should be first, for compatibility with Adafruit Windows 7 drivers. - // In the past, the order has been CDC, MSC, MIDI, HID, so preserve - // that order. + // In the past, the order has been CDC, MSC, MIDI, HID, so preserve that order. #if CIRCUITPY_USB_CDC - if (usb_cdc_repl_enabled) { + if (usb_cdc_repl_enabled()) { total_descriptor_length += usb_cdc_descriptor_length(); } - if (usb_cdc_data_enabled) { + if (usb_cdc_data_enabled()) { total_descriptor_length += usb_cdc_descriptor_length(); } #endif #if CIRCUITPY_USB_MSC - if (storage_usb_enabled) { + if (storage_usb_enabled()) { total_descriptor_length += storage_usb_descriptor_length(); } #endif #if CIRCUITPY_USB_MIDI - if (usb_midi_enabled) { + if (usb_midi_enabled()) { total_descriptor_length += usb_midi_descriptor_length(); } #endif #if CIRCUITPY_USB_HID - if (usb_hid_enabled) { + if (usb_hid_enabled()) { total_descriptor_length += usb_hid_descriptor_length(); } #endif // Now we now how big the configuration descriptor will be. // Copy the top-level template, and fix up its length. - memcpy(config_descriptor, configuration_descriptor_template, sizeof(configuration_descriptor_template)); configuration_descriptor[CONFIG_TOTAL_LENGTH_LO_INDEX] = total_descriptor_length & 0xFF; configuration_descriptor[CONFIG_TOTAL_LENGTH_HI_INDEX] = (total_descriptor_length >> 8) & 0xFF; @@ -192,38 +194,39 @@ static void usb_build_configuration_descriptor(uint16_t total_length, uint8_t nu uint8_t *descriptor_buf_remaining = configuration_descriptor + sizeof(configuration_descriptor_template); #if CIRCUITPY_USB_CDC - if (usb_cdc_repl_enabled) { + if (usb_cdc_repl_enabled()) { // Concatenate and fix up the CDC REPL descriptor. descriptor_buf_remaining += usb_cdc_add_descriptor( - descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string, true); + descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string, true); } - if (usb_cdc_data_enabled) { + if (usb_cdc_data_enabled()) { // Concatenate and fix up the CDC data descriptor. descriptor_buf_remaining += usb_cdc_add_descriptor( - descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string, false); + descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string, false); } #endif #if CIRCUITPY_USB_MSC - if (storage_usb_enabled) { + if (storage_usb_enabled()) { // Concatenate and fix up the MSC descriptor. descriptor_buf_remaining += storage_usb_add_descriptor( - descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string); + descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string); } #endif #if CIRCUITPY_USB_MIDI - if (usb_midi_enabled) { + if (usb_midi_enabled()) { // Concatenate and fix up the MIDI descriptor. descriptor_buf_remaining += usb_midi_add_descriptor( - descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string); + descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string); } #endif #if CIRCUITPY_USB_HID - if (usb_hid_enabled) { + if (usb_hid_enabled()) { descriptor_buf_remaining += usb_hid_add_descriptor( - descriptor_buf_remaining, *current_interface, *current_endpoint, *current_interface_string); + descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string, + usb_hid_report_descriptor_length()); } #endif @@ -232,14 +235,14 @@ static void usb_build_configuration_descriptor(uint16_t total_length, uint8_t nu // Did we run out of endpoints? if (current_endpoint - 1 > USB_NUM_EP) { - mp_raise_SystemError("Not enough USB endpoints"); + mp_raise_RuntimeError(translate("Not enough USB endpoints")); } } -void usb_add_interface_string(uint8_t interface_string_index, const char[] str) { +void usb_add_interface_string(uint8_t interface_string_index, const char str[]) { if (interface_string_index > MAX_INTERFACE_STRINGS) { - mp_raise_SystemError("Too many USB interface names"); + mp_raise_RuntimeError(translate("Too many USB interface names")); } // 2 bytes for String Descriptor header, then 2 bytes for each character const size_t str_len = strlen(str); @@ -247,7 +250,7 @@ void usb_add_interface_string(uint8_t interface_string_index, const char[] str) uint16_t *string_descriptor = (uint16_t *) m_malloc(descriptor_size, false); string_descriptor[0] = 0x0300 | descriptor_size; // Convert to le16 - for (i = 0; i <= str_len; i++) { + for (size_t i = 0; i <= str_len; i++) { string_descriptor[i + 1] = str[i]; } @@ -261,8 +264,8 @@ void usb_desc_post_boot_py(void) { usb_hid_post_boot_py(); } -// Called in a the new VM created after boot.py is run. The USB devices to be used are now chosen. -static void usb_desc_init(void) { +// Called in the new VM created after boot.py is run. The USB devices to be used are now chosen. +void usb_desc_init(void) { uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; common_hal_mcu_processor_get_uid(raw_id); @@ -282,14 +285,12 @@ static void usb_desc_init(void) { usb_build_device_descriptor(USB_VID, USB_PID); usb_build_configuration_descriptor(); - usb_build_hid_descriptor(); - usb_build_string_descriptors(); } void usb_desc_gc_collect(void) { // Once tud_mounted() is true, we're done with the constructed descriptors. if (tud_mounted()) { - gc_free(device_descriptor_allocation); + gc_free(device_descriptor); gc_free(configuration_descriptor); } else { gc_collect_ptr(device_descriptor); @@ -301,7 +302,7 @@ void usb_desc_gc_collect(void) { // Invoked when GET DEVICE DESCRIPTOR is received. // Application return pointer to descriptor uint8_t const *tud_descriptor_device_cb(void) { - return usb_descriptor_dev; + return device_descriptor; } // Invoked when GET CONFIGURATION DESCRIPTOR is received. @@ -309,18 +310,9 @@ uint8_t const *tud_descriptor_device_cb(void) { // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { (void)index; // for multiple configurations - return config_desc; + return configuration_descriptor; } -#if CIRCUITPY_USB_HID -// Invoked when GET HID REPORT DESCRIPTOR is received. -// Application return pointer to descriptor -// Descriptor contents must exist long enough for transfer to complete -uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { - return hid_report_descriptor; -} -#endif - // Invoked when GET STRING DESCRIPTOR request is received. // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 34a5a5cc7f..305b6a2c39 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -134,14 +134,16 @@ ifeq ($(CIRCUITPY_DISPLAYIO), 1) endif endif +# Preserve double quotes in these values by single-quoting them. + USB_INTERFACE_NAME ?= "CircuitPython" -CFLAGS += -DUSB_INTERFACE_NAME=$(USB_INTERFACE_NAME) +CFLAGS += -DUSB_INTERFACE_NAME='$(USB_INTERFACE_NAME)' ifneq ($(USB_VID),) CFLAGS += -DUSB_VID=$(USB_VID) -CFLAGS += -DSUB_PID=$(USB_PID) -CFLAGS += -DUSB_MANUFACTURER=$(USB_MANUFACTURER) -CFLAGS += -DUSB_PRODUCT=$(USB_PRODUCT) +CFLAGS += -DUSB_PID=$(USB_PID) +CFLAGS += -DUSB_MANUFACTURER='$(USB_MANUFACTURER)' +CFLAGS += -DUSB_PRODUCT='$(USB_PRODUCT)' endif # In the following URL, don't include the https:// prefix. @@ -149,39 +151,12 @@ endif USB_WEBUSB_URL ?= "circuitpython.org" ifeq ($(CIRCUITPY_USB_CDC),1) -# Inform TinyUSB there are two CDC devices. +# Inform TinyUSB there will be up to two CDC devices. CFLAGS += -DCFG_TUD_CDC=2 endif USB_HIGHSPEED ?= 0 -************ move these from make variables to cpp only ??? -USB_CDC_EP_NUM_NOTIFICATION ?= 0 -CFLAGS += -DUSB_CDC_EP_NUM_NOTIFICATION=$(USB_CDC_EP_NUM_NOTIFICATION) -USB_CDC_EP_NUM_DATA_OUT ?= 0 -CFLAGS += -DUSB_CDC_EP_NUM_DATA_OUT=$(USB_CDC_EP_NUM_DATA_OUT) -USB_CDC_EP_NUM_DATA_IN ?= 0 -CFLAGS += -DUSB_CDC_EP_NUM_DATA_IN=$(USB_CDC_EP_NUM_DATA_IN) - -USB_CDC2_EP_NUM_NOTIFICATION ?= 0 -CFLAGS += -DUSB_CDC2_EP_NUM_NOTIFICATION=$(USB_CDC2_EP_NUM_NOTIFICATION) -USB_CDC2_EP_NUM_DATA_OUT ?= 0 -CFLAGS += -DUSB_CDC2_EP_NUM_DATA_OUT=$(USB_CDC2_EP_NUM_DATA_OUT) -USB_CDC2_EP_NUM_DATA_IN ?= 0 -CFLAGS += -DUSB_CDC2_EP_NUM_DATA_IN=$(USB_CDC2_EP_NUM_DATA_IN) - -USB_MSC_EP_NUM_OUT ?= 0 -CFLAGS += -DUSB -USB_MSC_EP_NUM_IN ?= 0 - -USB_HID_EP_NUM_OUT ?= 0 -USB_HID_EP_NUM_IN ?= 0 - -USB_MIDI_EP_NUM_OUT ?= 0 -USB_MIDI_EP_NUM_IN ?= 0 - -USB_NUM_EP ?= 0 - $(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf" From 8500e846c653910a741bc21eff883beea5f28515 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 27 Apr 2021 23:53:23 -0400 Subject: [PATCH 32/66] partially working --- main.c | 232 +++++++++++++++--------------- ports/atmel-samd/mpconfigport.mk | 2 +- py/circuitpy_mpconfig.mk | 6 +- shared-module/storage/__init__.c | 32 +++-- shared-module/storage/__init__.h | 7 +- shared-module/usb_cdc/__init__.c | 41 +++--- shared-module/usb_cdc/__init__.h | 3 +- shared-module/usb_hid/__init__.c | 27 ++-- shared-module/usb_hid/__init__.h | 2 +- shared-module/usb_midi/__init__.c | 43 +++--- shared-module/usb_midi/__init__.h | 4 +- supervisor/shared/memory.c | 7 - supervisor/shared/serial.c | 2 +- supervisor/shared/usb/usb.c | 28 +++- supervisor/shared/usb/usb_desc.c | 66 +++++---- supervisor/usb.h | 1 + 16 files changed, 273 insertions(+), 230 deletions(-) diff --git a/main.c b/main.c index 610fb0d302..7726ae6947 100755 --- a/main.c +++ b/main.c @@ -182,24 +182,6 @@ STATIC void start_mp(supervisor_allocation* heap) { #if CIRCUITPY_NETWORK network_module_init(); #endif - - // Do before boot.py. - - #if CIRCUITPY_STORAGE - storage_init(); - #endif - - #if CIRCUITPY_USB_CDC - usb_cdc_init(); - #endif - - #if CIRCUITPY_USB_HID - usb_hid_init(); - #endif - - #if CIRCUITPY_USB_MIDI - usb_midi_init(); - #endif } STATIC void stop_mp(void) { @@ -284,6 +266,97 @@ STATIC void cleanup_after_vm(supervisor_allocation* heap) { reset_status_led(); } +FIL* boot_output_file; + +STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { + // If not in safe mode, run boot before initing USB and capture output in a + // file. + if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) { + static const char * const boot_py_filenames[] = STRING_LIST("settings.txt", "settings.py", "boot.py", "boot.txt"); + + new_status_color(BOOT_RUNNING); + + #ifdef CIRCUITPY_BOOT_OUTPUT_FILE + FIL file_pointer; + boot_output_file = &file_pointer; + + // Get the base filesystem. + FATFS *fs = &((fs_user_mount_t *) MP_STATE_VM(vfs_mount_table)->obj)->fatfs; + + bool have_boot_py = first_existing_file_in_list(boot_py_filenames) != NULL; + + bool skip_boot_output = false; + + // If there's no boot.py file that might write some changing output, + // read the existing copy of CIRCUITPY_BOOT_OUTPUT_FILE and see if its contents + // match the version info we would print anyway. If so, skip writing CIRCUITPY_BOOT_OUTPUT_FILE. + // This saves wear and tear on the flash and also prevents filesystem damage if power is lost + // during the write, which may happen due to bobbling the power connector or weak power. + + static const size_t NUM_CHARS_TO_COMPARE = 160; + if (!have_boot_py && f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_READ) == FR_OK) { + + char file_contents[NUM_CHARS_TO_COMPARE]; + UINT chars_read = 0; + f_read(boot_output_file, file_contents, NUM_CHARS_TO_COMPARE, &chars_read); + f_close(boot_output_file); + skip_boot_output = + // + 2 accounts for \r\n. + chars_read == strlen(MICROPY_FULL_VERSION_INFO) + 2 && + strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0; + } + + if (!skip_boot_output) { + // Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write, + // in case power is momentary or will fail shortly due to, say a low, battery. + if (common_hal_mcu_processor_get_reset_reason() == RESET_REASON_POWER_ON) { + mp_hal_delay_ms(1500); + } + // USB isn't up, so we can write the file. + filesystem_set_internal_writable_by_usb(false); + f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_WRITE | FA_CREATE_ALWAYS); + + // Switch the filesystem back to non-writable by Python now instead of later, + // since boot.py might change it back to writable. + filesystem_set_internal_writable_by_usb(true); + + // Write version info to boot_out.txt. + mp_hal_stdout_tx_str(MICROPY_FULL_VERSION_INFO); + mp_hal_stdout_tx_str("\r\n"); + } + #endif + + filesystem_flush(); + supervisor_allocation* heap = allocate_remaining_memory(); + start_mp(heap); + + #if CIRCUITPY_USB + // Set up default USB values after boot.py VM starts but before running boot.py. + usb_pre_boot_py(); + #endif + + // TODO(tannewt): Re-add support for flashing boot error output. + bool found_boot = maybe_run_list(boot_py_filenames, NULL); + (void) found_boot; + + #ifdef CIRCUITPY_BOOT_OUTPUT_FILE + if (!skip_boot_output) { + f_close(boot_output_file); + filesystem_flush(); + } + boot_output_file = NULL; + #endif + + #if CIRCUITPY_USB + // Remember USB settings, which may have changed during boot.py. + // Call this before the boot.py heap is destroyed. + usb_post_boot_py(); + #endif + + cleanup_after_vm(heap); + } +} + STATIC void print_code_py_status_message(safe_mode_t safe_mode) { if (autoreload_is_enabled()) { serial_write_compressed(translate("Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.\n")); @@ -296,7 +369,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } } -STATIC bool run_code_py(safe_mode_t safe_mode) { +STATIC bool run_code_py(safe_mode_t safe_mode, supervisor_allocation *heap) { bool serial_connected_at_start = serial_connected(); #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 serial_write("\n"); @@ -324,11 +397,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { "main.txt.py", "main.py.txt", "main.txt.txt","main.py.py"); #endif - stack_resize(); - filesystem_flush(); - supervisor_allocation* heap = allocate_remaining_memory(); - start_mp(heap); - found_main = maybe_run_list(supported_filenames, &result); #if CIRCUITPY_FULL_BUILD if (!found_main){ @@ -466,98 +534,9 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { } } -FIL* boot_output_file; - -STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { - // If not in safe mode, run boot before initing USB and capture output in a - // file. - if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) { - static const char * const boot_py_filenames[] = STRING_LIST("settings.txt", "settings.py", "boot.py", "boot.txt"); - - new_status_color(BOOT_RUNNING); - - #ifdef CIRCUITPY_BOOT_OUTPUT_FILE - FIL file_pointer; - boot_output_file = &file_pointer; - - // Get the base filesystem. - FATFS *fs = &((fs_user_mount_t *) MP_STATE_VM(vfs_mount_table)->obj)->fatfs; - - bool have_boot_py = first_existing_file_in_list(boot_py_filenames) != NULL; - - bool skip_boot_output = false; - - // If there's no boot.py file that might write some changing output, - // read the existing copy of CIRCUITPY_BOOT_OUTPUT_FILE and see if its contents - // match the version info we would print anyway. If so, skip writing CIRCUITPY_BOOT_OUTPUT_FILE. - // This saves wear and tear on the flash and also prevents filesystem damage if power is lost - // during the write, which may happen due to bobbling the power connector or weak power. - - static const size_t NUM_CHARS_TO_COMPARE = 160; - if (!have_boot_py && f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_READ) == FR_OK) { - - char file_contents[NUM_CHARS_TO_COMPARE]; - UINT chars_read = 0; - f_read(boot_output_file, file_contents, NUM_CHARS_TO_COMPARE, &chars_read); - f_close(boot_output_file); - skip_boot_output = - // + 2 accounts for \r\n. - chars_read == strlen(MICROPY_FULL_VERSION_INFO) + 2 && - strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0; - } - - if (!skip_boot_output) { - // Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write, - // in case power is momentary or will fail shortly due to, say a low, battery. - if (common_hal_mcu_processor_get_reset_reason() == RESET_REASON_POWER_ON) { - mp_hal_delay_ms(1500); - } - // USB isn't up, so we can write the file. - filesystem_set_internal_writable_by_usb(false); - f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_WRITE | FA_CREATE_ALWAYS); - - // Switch the filesystem back to non-writable by Python now instead of later, - // since boot.py might change it back to writable. - filesystem_set_internal_writable_by_usb(true); - - // Write version info to boot_out.txt. - mp_hal_stdout_tx_str(MICROPY_FULL_VERSION_INFO); - mp_hal_stdout_tx_str("\r\n"); - } - #endif - - filesystem_flush(); - supervisor_allocation* heap = allocate_remaining_memory(); - start_mp(heap); - - // TODO(tannewt): Re-add support for flashing boot error output. - bool found_boot = maybe_run_list(boot_py_filenames, NULL); - (void) found_boot; - - #ifdef CIRCUITPY_BOOT_OUTPUT_FILE - if (!skip_boot_output) { - f_close(boot_output_file); - filesystem_flush(); - } - boot_output_file = NULL; - #endif - - #if CIRCUITPY_USB - // Remember USB settings done during boot.py. - // Call this before the boot.py heap is destroyed. - usb_post_boot_py(); - #endif - - cleanup_after_vm(heap); - } -} - -STATIC int run_repl(void) { +STATIC int run_repl(supervisor_allocation *heap) { int exit_code = PYEXEC_FORCED_EXIT; - stack_resize(); - filesystem_flush(); - supervisor_allocation* heap = allocate_remaining_memory(); - start_mp(heap); + autoreload_suspend(); new_status_color(REPL_RUNNING); if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { @@ -618,27 +597,40 @@ int __attribute__((used)) main(void) { run_boot_py(safe_mode); - // Start serial and HID after giving boot.py a chance to tweak behavior. - serial_init(); - #if CIRCUITPY_BLEIO supervisor_start_bluetooth(); #endif // Boot script is finished, so now go into REPL/main mode. + + // Set up heap for REPL or code.py + stack_resize(); + filesystem_flush(); + supervisor_allocation* heap = allocate_remaining_memory(); + start_mp(heap); + + #if CIRCUITPY_USB + // Setup USB connection after heap is available. + // It needs the heap to build descriptors. + usb_init(); + #endif + + // Set up any other serial connection. + serial_init(); + int exit_code = PYEXEC_FORCED_EXIT; bool skip_repl = true; bool first_run = true; for (;;) { if (!skip_repl) { - exit_code = run_repl(); + exit_code = run_repl(heap); } if (exit_code == PYEXEC_FORCED_EXIT) { if (!first_run) { serial_write_compressed(translate("soft reboot\n")); } first_run = false; - skip_repl = run_code_py(safe_mode); + skip_repl = run_code_py(safe_mode, heap); } else if (exit_code != 0) { break; } diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 3537123cce..f31360312c 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -51,7 +51,7 @@ CIRCUITPY_SDCARDIO ?= 0 CIRCUITPY_FRAMEBUFFERIO ?= 0 # Not enough room in 192kB or 256kB builds for secondary CDC. -CIRCUITPY_USB_CDC ?= 0 +CIRCUITPY_USB_CDC ?= 1 CIRCUITPY_ULAB = 0 diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index b87ffaedba..d991208f0e 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -339,9 +339,9 @@ CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB) CIRCUITPY_USB_CDC ?= 1 CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC) -CIRCUITPY_USB_CDC_REPL_ENABLED ?= 1 -CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT) -CIRCUITPY_USB_CDC_DATA_ENABLED ?= 0 +CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT ?= 1 +CFLAGS += -DCIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT) +CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT ?= 0 CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT) CIRCUITPY_USB_HID ?= 1 diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 6a16ba9ebe..9157118dd0 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -39,6 +39,8 @@ #include "supervisor/filesystem.h" #include "supervisor/flash.h" #include "supervisor/usb.h" + +#if CIRCUITPY_USB_MSC #include "tusb.h" static const uint8_t usb_msc_descriptor_template[] = { @@ -77,6 +79,10 @@ static const uint8_t usb_msc_descriptor_template[] = { // Is the MSC device enabled? bool storage_usb_is_enabled; +void storage_init_usb(void) { + storage_usb_is_enabled = true; +} + bool storage_usb_enabled(void) { return storage_usb_is_enabled; } @@ -92,8 +98,8 @@ size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_inte descriptor_buf[MSC_INTERFACE_INDEX] = *current_interface; (*current_interface)++; - descriptor_buf[MSC_IN_ENDPOINT_INDEX] = USB_MSC_EP_NUM_IN ? USB_MSC_EP_NUM_IN : *current_endpoint; - descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = 0x80 | (USB_MSC_EP_NUM_OUT ? USB_MSC_EP_NUM_OUT : *current_endpoint); + descriptor_buf[MSC_IN_ENDPOINT_INDEX] = 0x80 | (USB_MSC_EP_NUM_IN ? USB_MSC_EP_NUM_IN : *current_endpoint); + descriptor_buf[MSC_OUT_ENDPOINT_INDEX] = USB_MSC_EP_NUM_OUT ? USB_MSC_EP_NUM_OUT : *current_endpoint; (*current_endpoint)++; usb_add_interface_string(*current_interface_string, storage_interface_name); @@ -103,6 +109,15 @@ size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_inte return sizeof(usb_msc_descriptor_template); } +bool common_hal_storage_configure_usb(bool enabled) { + // We can't change the descriptors once we're connected. + if (tud_connected()) { + return false; + } + storage_usb_is_enabled = enabled; + return true; +} +#endif // CIRCUITPY_USB_MSC STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { if (vfs == MP_VFS_NONE) { @@ -121,10 +136,6 @@ STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_ return mp_call_method_n_kw(n_args, 0, meth); } -void storage_init(void) { - storage_usb_is_enabled = true; -} - void common_hal_storage_mount(mp_obj_t vfs_obj, const char *mount_path, bool readonly) { // create new object mp_vfs_mount_t *vfs = m_new_obj(mp_vfs_mount_t); @@ -236,12 +247,3 @@ void common_hal_storage_erase_filesystem(void) { common_hal_mcu_reset(); // We won't actually get here, since we're resetting. } - -bool common_hal_storage_configure_usb(bool enabled) { - // We can't change the descriptors once we're connected. - if (tud_connected()) { - return false; - } - storage_usb_is_enabled = enabled; - return true; -} diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index e9149bfa1b..2202fc0eb8 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -27,10 +27,13 @@ #ifndef SHARED_MODULE_STORAGE___INIT___H #define SHARED_MODULE_STORAGE___INIT___H -bool storage_usb_enabled(void); +#include "py/mpconfig.h" -void storage_init(void); +#if CIRCUITPY_USB +bool storage_usb_enabled(void); +void storage_init_usb(void); size_t storage_usb_descriptor_length(void); size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string); +#endif #endif // SHARED_MODULE_STORAGE___INIT___H diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 5de32fcde2..28e9c830ac 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -31,6 +31,8 @@ #include "py/objtuple.h" #include "shared-bindings/usb_cdc/__init__.h" #include "shared-bindings/usb_cdc/Serial.h" +#include "supervisor/usb.h" + #include "tusb.h" #if CFG_TUD_CDC != 2 @@ -94,7 +96,7 @@ static const uint8_t usb_cdc_descriptor_template[] = { // CDC Control IN Endpoint Descriptor 0x07, // 36 bLength 0x05, // 37 bDescriptorType (Endpoint) - 0xFF, // 38 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] + 0xFF, // 38 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | number] #define CDC_CONTROL_IN_ENDPOINT_INDEX 38 0x03, // 39 bmAttributes (Interrupt) 0x40, 0x00, // 40, 41 wMaxPacketSize 64 @@ -125,17 +127,17 @@ static const uint8_t usb_cdc_descriptor_template[] = { // CDC Data IN Endpoint Descriptor 0x07, // 59 bLength 0x05, // 60 bDescriptorType (Endpoint) - 0xFF, // 61 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] + 0xFF, // 61 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | number] #define CDC_DATA_IN_ENDPOINT_INDEX 61 0x02, // 62 bmAttributes (Bulk) 0x40, 0x00, // 63,64 wMaxPacketSize 64 0x00, // 65 bInterval 0 (unit depends on device speed) }; -static const char[] repl_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC control"; -static const char[] data_cdc_comm_interface_name = USB_INTERFACE_NAME " CDC2 control"; -static const char[] repl_cdc_data_interface_name = USB_INTERFACE_NAME " CDC data"; -static const char[] data_cdc_data_interface_name = USB_INTERFACE_NAME " CDC2 data"; +static const char repl_cdc_comm_interface_name[] = USB_INTERFACE_NAME " CDC control"; +static const char data_cdc_comm_interface_name[] = USB_INTERFACE_NAME " CDC2 control"; +static const char repl_cdc_data_interface_name[] = USB_INTERFACE_NAME " CDC data"; +static const char data_cdc_data_interface_name[] = USB_INTERFACE_NAME " CDC2 data"; static usb_cdc_serial_obj_t usb_cdc_repl_obj = { .base.type = &usb_cdc_serial_type, @@ -159,7 +161,7 @@ bool usb_cdc_repl_enabled(void) { } bool usb_cdc_data_enabled(void) { - return usb_cdc_data_enabled; + return usb_cdc_data_is_enabled; } size_t usb_cdc_descriptor_length(void) { @@ -167,7 +169,7 @@ size_t usb_cdc_descriptor_length(void) { } size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl) { - memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); + memcpy(descriptor_buf, usb_cdc_descriptor_template, sizeof(usb_cdc_descriptor_template)); // Store comm interface number. descriptor_buf[CDC_FIRST_INTERFACE_INDEX] = *current_interface; @@ -179,19 +181,23 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac descriptor_buf[CDC_CALL_MANAGEMENT_DATA_INTERFACE_INDEX] = *current_interface; descriptor_buf[CDC_UNION_SLAVE_INTERFACE_INDEX] = *current_interface; descriptor_buf[CDC_DATA_INTERFACE_INDEX] = *current_interface; + (*current_interface)++; - descriptor_buf[CDC_CONTROL_IN_ENDPOINT_INDEX] = repl + descriptor_buf[CDC_CONTROL_IN_ENDPOINT_INDEX] = 0x80 | ( + repl ? (USB_CDC_EP_NUM_NOTIFICATION ? USB_CDC_EP_NUM_NOTIFICATION : *current_endpoint) - : (USB_CDC2_EP_NUM_NOTIFICATION ? USB_CDC2_EP_NUM_NOTIFICATION : *current_endpoint); + : (USB_CDC2_EP_NUM_NOTIFICATION ? USB_CDC2_EP_NUM_NOTIFICATION : *current_endpoint)); (*current_endpoint)++; - descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = repl + descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = + repl ? (USB_CDC_EP_NUM_DATA_OUT ? USB_CDC_EP_NUM_DATA_OUT : *current_endpoint) : (USB_CDC2_EP_NUM_DATA_OUT ? USB_CDC2_EP_NUM_DATA_OUT : *current_endpoint); - descriptor_buf[CDC_DATA_IN_ENDPOINT_INDEX] = repl + descriptor_buf[CDC_DATA_IN_ENDPOINT_INDEX] = 0x80 | ( + repl ? (USB_CDC_EP_NUM_DATA_IN ? USB_CDC_EP_NUM_DATA_IN : *current_endpoint) - : (USB_CDC2_EP_NUM_DATA_IN ? USB_CDC2_EP_NUM_DATA_IN : *current_endpoint); + : (USB_CDC2_EP_NUM_DATA_IN ? USB_CDC2_EP_NUM_DATA_IN : *current_endpoint)); (*current_endpoint)++; usb_add_interface_string(*current_interface_string, @@ -204,10 +210,11 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac descriptor_buf[CDC_DATA_INTERFACE_STRING_INDEX] = *current_interface_string; (*current_interface_string)++; - return sizeof(usb_midi_descriptor_template); + return sizeof(usb_cdc_descriptor_template); } -void usb_cdc_init(void) { +// Called only once, before boot.py +void usb_cdc_init_usb(void) { usb_cdc_repl_is_enabled = true; usb_cdc_data_is_enabled = false; } @@ -218,10 +225,10 @@ bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) { return false; } - usb_cdc_repl_enabled = repl_enabled; + usb_cdc_repl_is_enabled = repl_enabled; usb_cdc_set_repl(repl_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_repl_obj) : mp_const_none); - usb_cdc_data_enabled = data_enabled; + usb_cdc_data_is_enabled = data_enabled; usb_cdc_set_data(data_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_data_obj) : mp_const_none); return true; diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 770ee13170..6c947a84fd 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -27,12 +27,13 @@ #ifndef SHARED_MODULE_USB_CDC___INIT___H #define SHARED_MODULE_USB_CDC___INIT___H +#include "py/mpconfig.h" #include "py/objtuple.h" bool usb_cdc_repl_enabled(void); bool usb_cdc_data_enabled(void); -void usb_cdc_init(void); +void usb_cdc_init_usb(void); size_t usb_cdc_descriptor_length(void); size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl); diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index a59fa069d8..1bb88fed5c 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -67,7 +67,7 @@ static const uint8_t usb_hid_descriptor_template[] = { 0x07, // 25 bLength 0x05, // 26 bDescriptorType (Endpoint) 0xFF, // 27 bEndpointAddress (OUT/H2D) [SET AT RUNTIME] -#define HID_OUT_ENDPOINT_INDEX (26) +#define HID_OUT_ENDPOINT_INDEX (27) 0x03, // 28 bmAttributes (Interrupt) 0x40, 0x00, // 29,30 wMaxPacketSize 64 0x08, // 31 bInterval 8 (unit depends on device speed) @@ -115,22 +115,28 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac descriptor_buf[HID_DESCRIPTOR_LENGTH_INDEX] = report_descriptor_length & 0xFF; descriptor_buf[HID_DESCRIPTOR_LENGTH_INDEX + 1] = (report_descriptor_length >> 8); - descriptor_buf[HID_IN_ENDPOINT_INDEX] = USB_HID_EP_NUM_IN ? USB_HID_EP_NUM_IN : *current_endpoint; - descriptor_buf[HID_OUT_ENDPOINT_INDEX] = 0x80 | (USB_HID_EP_NUM_OUT ? USB_HID_EP_NUM_OUT : *current_endpoint); + descriptor_buf[HID_IN_ENDPOINT_INDEX] = 0x80 | (USB_HID_EP_NUM_IN ? USB_HID_EP_NUM_IN : *current_endpoint); + descriptor_buf[HID_OUT_ENDPOINT_INDEX] = USB_HID_EP_NUM_OUT ? USB_HID_EP_NUM_OUT : *current_endpoint; (*current_endpoint)++; return sizeof(usb_hid_descriptor_template); } -static mp_obj_t default_hid_devices[] = { - MP_OBJ_FROM_PTR(&usb_hid_device_keyboard_obj), - MP_OBJ_FROM_PTR(&usb_hid_device_mouse_obj), - MP_OBJ_FROM_PTR(&usb_hid_device_consumer_control_obj), +static mp_rom_obj_tuple_t default_hid_devices_tuple = { + .base = { + .type = &mp_type_tuple, + }, + .len = 3, + .items = { + MP_OBJ_FROM_PTR(&usb_hid_device_keyboard_obj), + MP_OBJ_FROM_PTR(&usb_hid_device_mouse_obj), + MP_OBJ_FROM_PTR(&usb_hid_device_consumer_control_obj), + }, }; // Set the default list of devices that will be included. Called before boot.py runs, in the boot.py VM. void common_hal_usb_hid_configure_usb_defaults(void) { - common_hal_usb_hid_configure_usb(mp_obj_new_tuple(sizeof(default_hid_devices), default_hid_devices)); + common_hal_usb_hid_configure_usb(&default_hid_devices_tuple); } bool common_hal_usb_hid_configure_usb(mp_obj_t devices) { @@ -144,7 +150,8 @@ bool common_hal_usb_hid_configure_usb(mp_obj_t devices) { return true; } -void usb_hid_init(void) { +// Called only once, before boot.py +void usb_hid_init_usb(void) { usb_hid_is_enabled = true; } @@ -170,7 +177,7 @@ void usb_hid_post_boot_py(void) { total_hid_report_descriptor_length -= 2; } - // Allocate storage that persists across VMs to build the combined descriptor + // Allocate storage that persists across VMs to build the combined report descriptor // and to remember the device details. hid_report_descriptor_allocation = diff --git a/shared-module/usb_hid/__init__.h b/shared-module/usb_hid/__init__.h index 048e6107bc..c55e1970ab 100644 --- a/shared-module/usb_hid/__init__.h +++ b/shared-module/usb_hid/__init__.h @@ -33,7 +33,7 @@ extern usb_hid_device_obj_t usb_hid_devices[]; bool usb_hid_enabled(void); -void usb_hid_init(void); +void usb_hid_init_usb(void); void usb_hid_post_boot_py(void); size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length); diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 8897fd39b7..3a216da6e8 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -26,6 +26,7 @@ #include "shared-bindings/usb_midi/__init__.h" +#include "py/gc.h" #include "py/obj.h" #include "py/mphal.h" #include "py/runtime.h" @@ -72,7 +73,7 @@ static const uint8_t usb_midi_descriptor_template[] = { 0x01, // 23 bInterfaceClass (Audio) 0x03, // 24 bInterfaceSubClass (MIDI Streaming) 0x00, // 25 bInterfaceProtocol - 0xFF, // 26 iInterface (String Index) [SET AT RUNTIME] + 0xFF, // 26 iInterface (String Index) [SET AT RUNTIME] #define MIDI_STREAMING_INTERFACE_STRING_INDEX (26) // MIDI Header Descriptor @@ -141,7 +142,7 @@ static const uint8_t usb_midi_descriptor_template[] = { // MIDI IN Data Endpoint 0x07, // 76 bLength 0x05, // 77 bDescriptorType: Endpoint - 0xFF, // 78 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x8 | number] + 0xFF, // 78 bEndpointAddress (IN/D2H) [SET AT RUNTIME: 0x80 | number] #define MIDI_STREAMING_IN_ENDPOINT_INDEX (78) 0x02, // 79 bmAttributes (Bulk) 0x40, 0x00, // 8081 wMaxPacketSize 64 @@ -179,9 +180,9 @@ size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfa (*current_interface)++; descriptor_buf[MIDI_STREAMING_IN_ENDPOINT_INDEX] = - USB_MIDI_EP_NUM_IN ? USB_MIDI_EP_NUM_IN : *current_endpoint; + 0x80 | (USB_MIDI_EP_NUM_IN ? USB_MIDI_EP_NUM_IN : *current_endpoint); descriptor_buf[MIDI_STREAMING_OUT_ENDPOINT_INDEX] = - 0x80 | (USB_MIDI_EP_NUM_OUT ? USB_MIDI_EP_NUM_OUT : *current_endpoint); + USB_MIDI_EP_NUM_OUT ? USB_MIDI_EP_NUM_OUT : *current_endpoint; (*current_endpoint)++; descriptor_buf[MIDI_STREAMING_INTERFACE_NUMBER_INDEX] = *current_interface; @@ -208,38 +209,36 @@ size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfa } -void usb_midi_init(void) { +// Called once, before +void usb_midi_init_usb(void) { usb_midi_is_enabled = true; } -void usb_midi_usb_init(void) { +// Called before REPL or code.py +void usb_midi_setup(void) { mp_obj_tuple_t *ports; if (usb_midi_is_enabled) { - // TODO(tannewt): Make this dynamic. - size_t tuple_size = align32_size(sizeof(mp_obj_tuple_t) + sizeof(mp_obj_t *) * 2); - size_t portin_size = align32_size(sizeof(usb_midi_portin_obj_t)); - size_t portout_size = align32_size(sizeof(usb_midi_portout_obj_t)); + // Make these objects long-lived, because they will not be going away. - // For each embedded MIDI Jack in the descriptor we create a Port - usb_midi_allocation = allocate_memory(tuple_size + portin_size + portout_size, false, false); - - ports = (mp_obj_tuple_t *)usb_midi_allocation->ptr; - ports->base.type = &mp_type_tuple; - ports->len = 2; - - usb_midi_portin_obj_t *in = (usb_midi_portin_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4); + usb_midi_portin_obj_t *in = gc_alloc(sizeof(usb_midi_portin_obj_t), false, true); in->base.type = &usb_midi_portin_type; - ports->items[0] = MP_OBJ_FROM_PTR(in); - usb_midi_portout_obj_t *out = (usb_midi_portout_obj_t *)(usb_midi_allocation->ptr + tuple_size / 4 + portin_size / 4); + usb_midi_portout_obj_t *out = gc_alloc(sizeof(usb_midi_portout_obj_t), false, true); out->base.type = &usb_midi_portout_type; - ports->items[1] = MP_OBJ_FROM_PTR(out); + + mp_obj_t tuple_items[2] = { + MP_OBJ_FROM_PTR(in), + MP_OBJ_FROM_PTR(out), + }; + + ports = mp_obj_new_tuple(2, tuple_items); } else { ports = mp_const_empty_tuple; } - mp_map_lookup(&usb_midi_module_globals.map, MP_ROM_QSTR(MP_QSTR_ports), MP_MAP_LOOKUP)->value = MP_OBJ_FROM_PTR(ports); + mp_map_lookup(&usb_midi_module_globals.map, MP_ROM_QSTR(MP_QSTR_ports), MP_MAP_LOOKUP)->value = + MP_OBJ_FROM_PTR(ports); } bool common_hal_usb_midi_configure_usb(bool enabled) { diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index 4bb5e5f52a..a29c56109c 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -28,8 +28,8 @@ #define SHARED_MODULE_USB_MIDI___INIT___H -void usb_midi_init(void); -void usb_midi_usb_init(void); +void usb_midi_init_usb(void); +void usb_midi_setup(void); bool usb_midi_enabled(void); size_t usb_midi_descriptor_length(void); diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index 7cb00006e5..4bdbf67652 100644 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -39,16 +39,9 @@ enum { #if INTERNAL_FLASH_FILESYSTEM == 0 + 1 #endif - #if CIRCUITPY_USB_MIDI - + 1 - #endif , CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT = 0 - #if CIRCUITPY_USB - + 1 // device_descriptor_allocation - + 1 // config_descriptor_allocation - #endif #if CIRCUITPY_USB_HID + 1 // hid_report_descriptor_allocation + 1 // hid_devices_allocation diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index bd2bf4ba22..2be4f3df12 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -67,7 +67,7 @@ void serial_early_init(void) { } void serial_init(void) { - usb_init(); + // USB serial is set up separately. } bool serial_connected(void) { diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index ebdc82a960..47f431e08f 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -34,6 +34,14 @@ #include "lib/utils/interrupt_char.h" #include "lib/mp-readline/readline.h" +#if CIRCUITPY_STORAGE +#include "shared-module/storage/__init__.h" +#endif + +#if CIRCUITPY_USB_CDC +#include "shared-module/usb_cdc/__init__.h" +#endif + #if CIRCUITPY_USB_HID #include "shared-module/usb_hid/__init__.h" #endif @@ -82,14 +90,28 @@ void usb_init(void) { tud_cdc_set_wanted_char(CHAR_CTRL_C); #endif + #if CIRCUITPY_USB_MIDI + usb_midi_setup(); + #endif +} + +void usb_pre_boot_py(void) { + #if CIRCUITPY_STORAGE + storage_init_usb(); + #endif + #if CIRCUITPY_USB_CDC - usb_cdcx_usb_init(); + usb_cdc_init_usb(); + #endif + + #if CIRCUITPY_USB_HID + usb_hid_init_usb(); #endif #if CIRCUITPY_USB_MIDI - usb_midi_usb_init(); + usb_midi_init_usb(); #endif -} +}; // Remember USB settings done during boot.py. // The boot.py heap is still valid at this point. diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index d866c71f4b..aa01ea8897 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -52,8 +52,8 @@ // Table for collecting interface strings (interface names) as descriptor is built. #define MAX_INTERFACE_STRINGS 16 -// slot 0 is not used. -static uint16_t **collected_interface_strings; +// slot 0 is always the Language ID +static uint16_t *collected_interface_strings[MAX_INTERFACE_STRINGS]; static uint8_t current_interface_string; static const char manufacturer_name[] = USB_MANUFACTURER; @@ -77,11 +77,11 @@ static const uint8_t device_descriptor_template[] = { #define DEVICE_PID_LO_INDEX (10) #define DEVICE_PID_HI_INDEX (11) 0x00, 0x01, // 12,13 bcdDevice 2.00 - 0x02, // 14 iManufacturer (String Index) [SET AT RUNTIME] + 0xFF, // 14 iManufacturer (String Index) [SET AT RUNTIME] #define DEVICE_MANUFACTURER_STRING_INDEX (14) - 0x03, // 15 iProduct (String Index) [SET AT RUNTIME] + 0xFF, // 15 iProduct (String Index) [SET AT RUNTIME] #define DEVICE_PRODUCT_STRING_INDEX (15) - 0x01, // 16 iSerialNumber (String Index) [SET AT RUNTIME] + 0xFF, // 16 iSerialNumber (String Index) [SET AT RUNTIME] #define DEVICE_SERIAL_NUMBER_STRING_INDEX (16) 0x01, // 17 bNumConfigurations 1 }; @@ -102,7 +102,7 @@ static const uint8_t configuration_descriptor_template[] = { 0x32, // 8 bMaxPower 100mA }; -static uint8_t configuration_descriptor[sizeof(configuration_descriptor_template)]; +static uint8_t *configuration_descriptor; // Initialization done before boot.py is run. // Turn on or off various USB devices. On devices with limited endpoints, @@ -169,20 +169,23 @@ static void usb_build_configuration_descriptor(void) { } #endif -#if CIRCUITPY_USB_MIDI - if (usb_midi_enabled()) { - total_descriptor_length += usb_midi_descriptor_length(); - } -#endif - #if CIRCUITPY_USB_HID if (usb_hid_enabled()) { total_descriptor_length += usb_hid_descriptor_length(); } #endif +#if CIRCUITPY_USB_MIDI + if (usb_midi_enabled()) { + total_descriptor_length += usb_midi_descriptor_length(); + } +#endif + // Now we now how big the configuration descriptor will be. - // Copy the top-level template, and fix up its length. + // Copy the template, which is the first part of the descriptor, and fix up its length. + configuration_descriptor = gc_alloc(total_descriptor_length, false, false); + memcpy(configuration_descriptor, configuration_descriptor_template, sizeof(configuration_descriptor_template)); + configuration_descriptor[CONFIG_TOTAL_LENGTH_LO_INDEX] = total_descriptor_length & 0xFF; configuration_descriptor[CONFIG_TOTAL_LENGTH_HI_INDEX] = (total_descriptor_length >> 8) & 0xFF; @@ -214,14 +217,6 @@ static void usb_build_configuration_descriptor(void) { } #endif -#if CIRCUITPY_USB_MIDI - if (usb_midi_enabled()) { - // Concatenate and fix up the MIDI descriptor. - descriptor_buf_remaining += usb_midi_add_descriptor( - descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string); - } -#endif - #if CIRCUITPY_USB_HID if (usb_hid_enabled()) { descriptor_buf_remaining += usb_hid_add_descriptor( @@ -230,8 +225,19 @@ static void usb_build_configuration_descriptor(void) { } #endif +#if CIRCUITPY_USB_MIDI + if (usb_midi_enabled()) { + // Concatenate and fix up the MIDI descriptor. + descriptor_buf_remaining += usb_midi_add_descriptor( + descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string); + } +#endif + // Now we know how many interfaces have been used. - configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface - 1; + // current_interface is the next free interface, counting from 0, + // so move back to the last interface number, and then get a count. + // (E.g., interfaces 0-5 are used, so the number of interfaces is 6.) + configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface - 1 + 1; // Did we run out of endpoints? if (current_endpoint - 1 > USB_NUM_EP) { @@ -266,6 +272,14 @@ void usb_desc_post_boot_py(void) { // Called in the new VM created after boot.py is run. The USB devices to be used are now chosen. void usb_desc_init(void) { + memset(collected_interface_strings, 0, sizeof(collected_interface_strings)); + + // Language ID is always the 0th string descriptor. + collected_interface_strings[0] = (uint16_t[]) { + 0x0304, + 0x0409, + }; + uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; common_hal_mcu_processor_get_uid(raw_id); @@ -277,10 +291,8 @@ void usb_desc_init(void) { } // Null-terminate the string. - serial_number_hex_string[sizeof(serial_number_hex_string)] = '\0'; + serial_number_hex_string[sizeof(serial_number_hex_string) - 1] = '\0'; - // Memory is cleared to zero when allocated; we depend on that. - collected_interface_strings = m_malloc(MAX_INTERFACE_STRINGS + 1, false); current_interface_string = 1; usb_build_device_descriptor(USB_VID, USB_PID); @@ -292,9 +304,13 @@ void usb_desc_gc_collect(void) { if (tud_mounted()) { gc_free(device_descriptor); gc_free(configuration_descriptor); + for (size_t i = 0; i < MAX_INTERFACE_STRINGS; i ++) { + gc_free(collected_interface_strings[i]); + } } else { gc_collect_ptr(device_descriptor); gc_collect_ptr(configuration_descriptor); + gc_collect_root((void **) collected_interface_strings, MAX_INTERFACE_STRINGS); } } diff --git a/supervisor/usb.h b/supervisor/usb.h index 96071b0cb1..a0e31f1913 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -54,6 +54,7 @@ bool usb_enabled(void); void usb_init(void); void usb_disconnect(void); void usb_gc_collect(void); +void usb_pre_boot_py(void); void usb_post_boot_py(void); void usb_add_interface_string(uint8_t interface_string_index, const char str[]); From 587aedd14f15972ac28cd30aca4078d2e336411b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 28 Apr 2021 13:00:44 -0400 Subject: [PATCH 33/66] rework storage allocation --- main.c | 223 ++++++++++++++--------------- shared-bindings/usb_hid/__init__.h | 1 - shared-module/storage/__init__.c | 4 +- shared-module/storage/__init__.h | 2 +- shared-module/usb_cdc/__init__.c | 7 +- shared-module/usb_cdc/__init__.h | 2 +- shared-module/usb_hid/__init__.c | 44 +++--- shared-module/usb_hid/__init__.h | 2 +- shared-module/usb_midi/__init__.c | 53 +++---- shared-module/usb_midi/__init__.h | 4 +- supervisor/shared/memory.c | 54 ++++--- supervisor/shared/usb/usb.c | 39 +++-- supervisor/shared/usb/usb_desc.c | 141 +++++++++--------- supervisor/usb.h | 8 +- 14 files changed, 280 insertions(+), 304 deletions(-) diff --git a/main.c b/main.c index 7726ae6947..52191cee4f 100755 --- a/main.c +++ b/main.c @@ -266,97 +266,6 @@ STATIC void cleanup_after_vm(supervisor_allocation* heap) { reset_status_led(); } -FIL* boot_output_file; - -STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { - // If not in safe mode, run boot before initing USB and capture output in a - // file. - if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) { - static const char * const boot_py_filenames[] = STRING_LIST("settings.txt", "settings.py", "boot.py", "boot.txt"); - - new_status_color(BOOT_RUNNING); - - #ifdef CIRCUITPY_BOOT_OUTPUT_FILE - FIL file_pointer; - boot_output_file = &file_pointer; - - // Get the base filesystem. - FATFS *fs = &((fs_user_mount_t *) MP_STATE_VM(vfs_mount_table)->obj)->fatfs; - - bool have_boot_py = first_existing_file_in_list(boot_py_filenames) != NULL; - - bool skip_boot_output = false; - - // If there's no boot.py file that might write some changing output, - // read the existing copy of CIRCUITPY_BOOT_OUTPUT_FILE and see if its contents - // match the version info we would print anyway. If so, skip writing CIRCUITPY_BOOT_OUTPUT_FILE. - // This saves wear and tear on the flash and also prevents filesystem damage if power is lost - // during the write, which may happen due to bobbling the power connector or weak power. - - static const size_t NUM_CHARS_TO_COMPARE = 160; - if (!have_boot_py && f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_READ) == FR_OK) { - - char file_contents[NUM_CHARS_TO_COMPARE]; - UINT chars_read = 0; - f_read(boot_output_file, file_contents, NUM_CHARS_TO_COMPARE, &chars_read); - f_close(boot_output_file); - skip_boot_output = - // + 2 accounts for \r\n. - chars_read == strlen(MICROPY_FULL_VERSION_INFO) + 2 && - strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0; - } - - if (!skip_boot_output) { - // Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write, - // in case power is momentary or will fail shortly due to, say a low, battery. - if (common_hal_mcu_processor_get_reset_reason() == RESET_REASON_POWER_ON) { - mp_hal_delay_ms(1500); - } - // USB isn't up, so we can write the file. - filesystem_set_internal_writable_by_usb(false); - f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_WRITE | FA_CREATE_ALWAYS); - - // Switch the filesystem back to non-writable by Python now instead of later, - // since boot.py might change it back to writable. - filesystem_set_internal_writable_by_usb(true); - - // Write version info to boot_out.txt. - mp_hal_stdout_tx_str(MICROPY_FULL_VERSION_INFO); - mp_hal_stdout_tx_str("\r\n"); - } - #endif - - filesystem_flush(); - supervisor_allocation* heap = allocate_remaining_memory(); - start_mp(heap); - - #if CIRCUITPY_USB - // Set up default USB values after boot.py VM starts but before running boot.py. - usb_pre_boot_py(); - #endif - - // TODO(tannewt): Re-add support for flashing boot error output. - bool found_boot = maybe_run_list(boot_py_filenames, NULL); - (void) found_boot; - - #ifdef CIRCUITPY_BOOT_OUTPUT_FILE - if (!skip_boot_output) { - f_close(boot_output_file); - filesystem_flush(); - } - boot_output_file = NULL; - #endif - - #if CIRCUITPY_USB - // Remember USB settings, which may have changed during boot.py. - // Call this before the boot.py heap is destroyed. - usb_post_boot_py(); - #endif - - cleanup_after_vm(heap); - } -} - STATIC void print_code_py_status_message(safe_mode_t safe_mode) { if (autoreload_is_enabled()) { serial_write_compressed(translate("Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.\n")); @@ -369,7 +278,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } } -STATIC bool run_code_py(safe_mode_t safe_mode, supervisor_allocation *heap) { +STATIC bool run_code_py(safe_mode_t safe_mode) { bool serial_connected_at_start = serial_connected(); #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 serial_write("\n"); @@ -397,6 +306,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode, supervisor_allocation *heap) { "main.txt.py", "main.py.txt", "main.txt.txt","main.py.py"); #endif + stack_resize(); + filesystem_flush(); + supervisor_allocation* heap = allocate_remaining_memory(); + start_mp(heap); + found_main = maybe_run_list(supported_filenames, &result); #if CIRCUITPY_FULL_BUILD if (!found_main){ @@ -534,9 +448,103 @@ STATIC bool run_code_py(safe_mode_t safe_mode, supervisor_allocation *heap) { } } -STATIC int run_repl(supervisor_allocation *heap) { - int exit_code = PYEXEC_FORCED_EXIT; +FIL* boot_output_file; +STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { + // If not in safe mode, run boot before initing USB and capture output in a + // file. + if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) { + static const char * const boot_py_filenames[] = STRING_LIST("settings.txt", "settings.py", "boot.py", "boot.txt"); + + new_status_color(BOOT_RUNNING); + + #ifdef CIRCUITPY_BOOT_OUTPUT_FILE + FIL file_pointer; + boot_output_file = &file_pointer; + + // Get the base filesystem. + FATFS *fs = &((fs_user_mount_t *) MP_STATE_VM(vfs_mount_table)->obj)->fatfs; + + bool have_boot_py = first_existing_file_in_list(boot_py_filenames) != NULL; + + bool skip_boot_output = false; + + // If there's no boot.py file that might write some changing output, + // read the existing copy of CIRCUITPY_BOOT_OUTPUT_FILE and see if its contents + // match the version info we would print anyway. If so, skip writing CIRCUITPY_BOOT_OUTPUT_FILE. + // This saves wear and tear on the flash and also prevents filesystem damage if power is lost + // during the write, which may happen due to bobbling the power connector or weak power. + + static const size_t NUM_CHARS_TO_COMPARE = 160; + if (!have_boot_py && f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_READ) == FR_OK) { + + char file_contents[NUM_CHARS_TO_COMPARE]; + UINT chars_read = 0; + f_read(boot_output_file, file_contents, NUM_CHARS_TO_COMPARE, &chars_read); + f_close(boot_output_file); + skip_boot_output = + // + 2 accounts for \r\n. + chars_read == strlen(MICROPY_FULL_VERSION_INFO) + 2 && + strncmp(file_contents, MICROPY_FULL_VERSION_INFO, strlen(MICROPY_FULL_VERSION_INFO)) == 0; + } + + if (!skip_boot_output) { + // Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write, + // in case power is momentary or will fail shortly due to, say a low, battery. + if (common_hal_mcu_processor_get_reset_reason() == RESET_REASON_POWER_ON) { + mp_hal_delay_ms(1500); + } + // USB isn't up, so we can write the file. + filesystem_set_internal_writable_by_usb(false); + f_open(fs, boot_output_file, CIRCUITPY_BOOT_OUTPUT_FILE, FA_WRITE | FA_CREATE_ALWAYS); + + // Switch the filesystem back to non-writable by Python now instead of later, + // since boot.py might change it back to writable. + filesystem_set_internal_writable_by_usb(true); + + // Write version info to boot_out.txt. + mp_hal_stdout_tx_str(MICROPY_FULL_VERSION_INFO); + mp_hal_stdout_tx_str("\r\n"); + } + #endif + + filesystem_flush(); + supervisor_allocation* heap = allocate_remaining_memory(); + start_mp(heap); + + #if CIRCUITPY_USB + // Set up default USB values after boot.py VM starts but before running boot.py. + usb_pre_boot_py(); + #endif + + // TODO(tannewt): Re-add support for flashing boot error output. + bool found_boot = maybe_run_list(boot_py_filenames, NULL); + (void) found_boot; + + #ifdef CIRCUITPY_BOOT_OUTPUT_FILE + if (!skip_boot_output) { + f_close(boot_output_file); + filesystem_flush(); + } + boot_output_file = NULL; + #endif + + #if CIRCUITPY_USB + // Remember USB settings, which may have changed during boot.py. + // Call this before the boot.py heap is destroyed. + usb_post_boot_py(); + #endif + + cleanup_after_vm(heap); + } +} + +STATIC int run_repl(void) { + int exit_code = PYEXEC_FORCED_EXIT; + stack_resize(); + filesystem_flush(); + supervisor_allocation* heap = allocate_remaining_memory(); + start_mp(heap); autoreload_suspend(); new_status_color(REPL_RUNNING); if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { @@ -580,7 +588,6 @@ int __attribute__((used)) main(void) { // Port-independent devices, like CIRCUITPY_BLEIO_HCI. reset_devices(); reset_board(); - reset_usb(); // This is first time we are running CircuitPython after a reset or power-up. supervisor_set_run_reason(RUN_REASON_STARTUP); @@ -597,18 +604,7 @@ int __attribute__((used)) main(void) { run_boot_py(safe_mode); - #if CIRCUITPY_BLEIO - supervisor_start_bluetooth(); - #endif - - // Boot script is finished, so now go into REPL/main mode. - - // Set up heap for REPL or code.py - stack_resize(); - filesystem_flush(); - supervisor_allocation* heap = allocate_remaining_memory(); - start_mp(heap); - + // Start USB after giving boot.py a chance to tweak behavior. #if CIRCUITPY_USB // Setup USB connection after heap is available. // It needs the heap to build descriptors. @@ -618,19 +614,24 @@ int __attribute__((used)) main(void) { // Set up any other serial connection. serial_init(); + #if CIRCUITPY_BLEIO + supervisor_start_bluetooth(); + #endif + + // Boot script is finished, so now go into REPL/main mode. int exit_code = PYEXEC_FORCED_EXIT; bool skip_repl = true; bool first_run = true; for (;;) { if (!skip_repl) { - exit_code = run_repl(heap); + exit_code = run_repl(); } if (exit_code == PYEXEC_FORCED_EXIT) { if (!first_run) { serial_write_compressed(translate("soft reboot\n")); } first_run = false; - skip_repl = run_code_py(safe_mode, heap); + skip_repl = run_code_py(safe_mode); } else if (exit_code != 0) { break; } @@ -651,10 +652,6 @@ void gc_collect(void) { background_callback_gc_collect(); - #if CIRCUITPY_USB - usb_gc_collect(); - #endif - #if CIRCUITPY_ALARM common_hal_alarm_gc_collect(); #endif diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index 3e51170cc4..49b83c9bf0 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -35,7 +35,6 @@ extern mp_obj_tuple_t common_hal_usb_hid_devices; void usb_hid_set_devices(mp_obj_t devices); -void common_hal_usb_hid_configure_usb_defaults(void); bool common_hal_usb_hid_configure_usb(mp_obj_t devices_seq); #endif // SHARED_BINDINGS_USB_HID_H diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 9157118dd0..f53949d302 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -79,8 +79,8 @@ static const uint8_t usb_msc_descriptor_template[] = { // Is the MSC device enabled? bool storage_usb_is_enabled; -void storage_init_usb(void) { - storage_usb_is_enabled = true; +void storage_pre_boot_py(void) { + storage_usb_is_enabled = CIRCUITPY_USB_MSC_ENABLED_DEFAULT; } bool storage_usb_enabled(void) { diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index 2202fc0eb8..ed13696929 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -31,7 +31,7 @@ #if CIRCUITPY_USB bool storage_usb_enabled(void); -void storage_init_usb(void); +void storage_pre_boot_py(void); size_t storage_usb_descriptor_length(void); size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string); #endif diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 28e9c830ac..fb5da438a9 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -213,10 +213,9 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_cdc_descriptor_template); } -// Called only once, before boot.py -void usb_cdc_init_usb(void) { - usb_cdc_repl_is_enabled = true; - usb_cdc_data_is_enabled = false; +void usb_cdc_pre_boot_py(void) { + usb_cdc_repl_is_enabled = CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT; + usb_cdc_data_is_enabled = CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT; } bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) { diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 6c947a84fd..546fe8f778 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -33,7 +33,7 @@ bool usb_cdc_repl_enabled(void); bool usb_cdc_data_enabled(void); -void usb_cdc_init_usb(void); +void usb_cdc_pre_boot_py(void); size_t usb_cdc_descriptor_length(void); size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl); diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 1bb88fed5c..0c614629ec 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -85,6 +85,23 @@ static size_t total_hid_report_descriptor_length; static supervisor_allocation *hid_devices_allocation; static mp_int_t hid_devices_num; +static mp_obj_tuple_t default_hid_devices_tuple = { + .base = { + .type = &mp_type_tuple, + }, + .len = 3, + .items = { + MP_OBJ_FROM_PTR(&usb_hid_device_keyboard_obj), + MP_OBJ_FROM_PTR(&usb_hid_device_mouse_obj), + MP_OBJ_FROM_PTR(&usb_hid_device_consumer_control_obj), + }, +}; + +void usb_hid_pre_boot_py(void) { + usb_hid_is_enabled = true; + common_hal_usb_hid_configure_usb(&default_hid_devices_tuple); +} + // This is the interface descriptor, not the report descriptor. size_t usb_hid_descriptor_length(void) { return sizeof(usb_hid_descriptor_template); @@ -122,23 +139,6 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_hid_descriptor_template); } -static mp_rom_obj_tuple_t default_hid_devices_tuple = { - .base = { - .type = &mp_type_tuple, - }, - .len = 3, - .items = { - MP_OBJ_FROM_PTR(&usb_hid_device_keyboard_obj), - MP_OBJ_FROM_PTR(&usb_hid_device_mouse_obj), - MP_OBJ_FROM_PTR(&usb_hid_device_consumer_control_obj), - }, -}; - -// Set the default list of devices that will be included. Called before boot.py runs, in the boot.py VM. -void common_hal_usb_hid_configure_usb_defaults(void) { - common_hal_usb_hid_configure_usb(&default_hid_devices_tuple); -} - bool common_hal_usb_hid_configure_usb(mp_obj_t devices) { // We can't change the devices once we're connected. if (tud_connected()) { @@ -150,11 +150,6 @@ bool common_hal_usb_hid_configure_usb(mp_obj_t devices) { return true; } -// Called only once, before boot.py -void usb_hid_init_usb(void) { - usb_hid_is_enabled = true; -} - // Build the combined HID report descriptor and save the chosen devices. // Both are saved in supervisor allocations. void usb_hid_post_boot_py(void) { @@ -220,11 +215,6 @@ void usb_hid_post_boot_py(void) { } void usb_hid_gc_collect(void) { - if (tud_mounted()) { - // Once tud_mounted() is true, we're done with the constructed descriptors. - free_memory(hid_report_descriptor_allocation); - } - gc_collect_ptr(hid_devices_seq); gc_collect_ptr(hid_report_descriptor_allocation->ptr); gc_collect_ptr(hid_devices_allocation->ptr); diff --git a/shared-module/usb_hid/__init__.h b/shared-module/usb_hid/__init__.h index c55e1970ab..5262718126 100644 --- a/shared-module/usb_hid/__init__.h +++ b/shared-module/usb_hid/__init__.h @@ -33,7 +33,7 @@ extern usb_hid_device_obj_t usb_hid_devices[]; bool usb_hid_enabled(void); -void usb_hid_init_usb(void); +void usb_hid_pre_boot_py(void); void usb_hid_post_boot_py(void); size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length); diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 3a216da6e8..2f5cffc383 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -159,6 +159,10 @@ static const uint8_t usb_midi_descriptor_template[] = { // Is the USB MIDI device enabled? static bool usb_midi_is_enabled; +void usb_midi_pre_boot_py(void) { + usb_midi_is_enabled = CIRCUITPY_USB_MIDI_ENABLED_DEFAULT; +} + bool usb_midi_enabled(void) { return usb_midi_is_enabled; } @@ -208,35 +212,32 @@ size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfa return sizeof(usb_midi_descriptor_template); } +static const usb_midi_portin_obj_t midi_portin_obj = { + .base = { + .type = &usb_midi_portin_type, + }, +}; -// Called once, before -void usb_midi_init_usb(void) { - usb_midi_is_enabled = true; -} - -// Called before REPL or code.py -void usb_midi_setup(void) { - mp_obj_tuple_t *ports; - - if (usb_midi_is_enabled) { - // Make these objects long-lived, because they will not be going away. - - usb_midi_portin_obj_t *in = gc_alloc(sizeof(usb_midi_portin_obj_t), false, true); - in->base.type = &usb_midi_portin_type; - - usb_midi_portout_obj_t *out = gc_alloc(sizeof(usb_midi_portout_obj_t), false, true); - out->base.type = &usb_midi_portout_type; - - mp_obj_t tuple_items[2] = { - MP_OBJ_FROM_PTR(in), - MP_OBJ_FROM_PTR(out), - }; - - ports = mp_obj_new_tuple(2, tuple_items); - } else { - ports = mp_const_empty_tuple; +static const usb_midi_portout_obj_t midi_portout_obj = { + .base = { + .type = &usb_midi_portout_type, } +}; +static const mp_rom_obj_tuple_t midi_ports_tuple = { + .base = { + .type = &mp_type_tuple, + }, + .len = 2, + .items = { + MP_ROM_PTR(&midi_portin_obj), + MP_ROM_PTR(&midi_portout_obj), + }, +}; + + +void usb_midi_post_boot_py(void) { + mp_obj_tuple_t *ports = usb_midi_is_enabled ? MP_OBJ_FROM_PTR(&midi_ports_tuple) : mp_const_empty_tuple; mp_map_lookup(&usb_midi_module_globals.map, MP_ROM_QSTR(MP_QSTR_ports), MP_MAP_LOOKUP)->value = MP_OBJ_FROM_PTR(ports); } diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index a29c56109c..fbcb89bd70 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -28,8 +28,8 @@ #define SHARED_MODULE_USB_MIDI___INIT___H -void usb_midi_init_usb(void); -void usb_midi_setup(void); +void usb_midi_pre_boot_py(void); +void usb_midi_post_boot_py(void); bool usb_midi_enabled(void); size_t usb_midi_descriptor_length(void); diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index 4bdbf67652..27022b2ff8 100644 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -35,33 +35,43 @@ enum { CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT = // stack + heap - 2 - #if INTERNAL_FLASH_FILESYSTEM == 0 - + 1 - #endif + 2 + + #if INTERNAL_FLASH_FILESYSTEM == 0 + + 1 + #endif + + #if CIRCUITPY_USB + +1 // device_descriptor_allocation + +1 // configuration_descriptor_allocation + +1 // string_descriptors_allocation + #endif + + #if CIRCUITPY_USB_HID + + 1 // hid_report_descriptor_allocation + + 1 // hid_devices_allocation + #endif , + CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT = + 0 + #if CIRCUITPY_DISPLAYIO + #if CIRCUITPY_TERMINALIO + + 1 + #endif + + CIRCUITPY_DISPLAY_LIMIT * ( + // Maximum needs of one display: max(4 if RGBMATRIX, 1 if SHARPDISPLAY, 0) + #if CIRCUITPY_RGBMATRIX + 4 + #elif CIRCUITPY_SHARPDISPLAY + 1 + #else 0 - #if CIRCUITPY_USB_HID - + 1 // hid_report_descriptor_allocation - + 1 // hid_devices_allocation - #endif - #if CIRCUITPY_DISPLAYIO - #if CIRCUITPY_TERMINALIO - + 1 - #endif - + CIRCUITPY_DISPLAY_LIMIT * ( - // Maximum needs of one display: max(4 if RGBMATRIX, 1 if SHARPDISPLAY, 0) - #if CIRCUITPY_RGBMATRIX - 4 - #elif CIRCUITPY_SHARPDISPLAY - 1 - #else - 0 - #endif - ) #endif + ) + #endif , + CIRCUITPY_SUPERVISOR_ALLOC_COUNT = CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT + CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT }; diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 47f431e08f..0c86e79026 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -66,18 +66,10 @@ bool usb_enabled(void) { return tusb_inited(); } -// Initialization done only once, before boot.py is run. -void reset_usb(void) { - reset_usb_desc(); -} - - MP_WEAK void post_usb_init(void) { } void usb_init(void) { - usb_desc_init(); - init_usb_hardware(); tusb_init(); @@ -89,34 +81,40 @@ void usb_init(void) { // This usb_callback always got invoked regardless of mp_interrupt_char value since we only set it once here tud_cdc_set_wanted_char(CHAR_CTRL_C); #endif - - #if CIRCUITPY_USB_MIDI - usb_midi_setup(); - #endif } +// Set up USB defaults before any USB changes are made in boot.py void usb_pre_boot_py(void) { #if CIRCUITPY_STORAGE - storage_init_usb(); + storage_pre_boot_py(); #endif #if CIRCUITPY_USB_CDC - usb_cdc_init_usb(); + usb_cdc_pre_boot_py(); #endif #if CIRCUITPY_USB_HID - usb_hid_init_usb(); + usb_hid_pre_boot_py(); #endif #if CIRCUITPY_USB_MIDI - usb_midi_init_usb(); + usb_midi_pre_boot_py(); #endif }; -// Remember USB settings done during boot.py. -// The boot.py heap is still valid at this point. +// Act on USB settings done during boot.py. void usb_post_boot_py(void) { + #if CIRCUITPY_USB usb_desc_post_boot_py(); + #endif + + #if CIRCUITPY_USB_MIDI + usb_midi_post_boot_py(); + #endif + + #if CIRCUITPY_USB_HID + usb_hid_post_boot_py(); + #endif } @@ -147,11 +145,6 @@ void usb_irq_handler(void) { usb_background_schedule(); } -void usb_gc_collect(void) { - usb_desc_gc_collect(); - usb_hid_gc_collect(); -} - // --------------------------------------------------------------------+ // tinyusb callbacks // --------------------------------------------------------------------+ diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index aa01ea8897..1da1d8d19e 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -26,9 +26,9 @@ #include "lib/tinyusb/src/tusb.h" -#include "py/gc.h" #include "py/objstr.h" #include "py/runtime.h" +#include "supervisor/memory.h" #include "supervisor/usb.h" #if CIRCUITPY_USB_CDC @@ -51,17 +51,29 @@ // Table for collecting interface strings (interface names) as descriptor is built. +// We reuse the same table after collection, replacing the char string pointers with le16 string pointers. #define MAX_INTERFACE_STRINGS 16 // slot 0 is always the Language ID -static uint16_t *collected_interface_strings[MAX_INTERFACE_STRINGS]; +typedef union { + const char *char_str; + const uint16_t *descriptor; +} interface_string_t; +static interface_string_t collected_interface_strings[MAX_INTERFACE_STRINGS]; + +static size_t collected_interface_strings_length; static uint8_t current_interface_string; +supervisor_allocation *device_descriptor_allocation; +supervisor_allocation *configuration_descriptor_allocation; +supervisor_allocation *string_descriptors_allocation; + static const char manufacturer_name[] = USB_MANUFACTURER; static const char product_name[] = USB_PRODUCT; // Serial number string is UID length * 2 (2 nibbles per byte) + 1 byte for null termination. static char serial_number_hex_string[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH * 2 + 1]; + static const uint8_t device_descriptor_template[] = { 0x12, // 0 bLength 0x01, // 1 bDescriptorType (Device) @@ -86,8 +98,6 @@ static const uint8_t device_descriptor_template[] = { 0x01, // 17 bNumConfigurations 1 }; -static uint8_t device_descriptor[sizeof(device_descriptor_template)]; - static const uint8_t configuration_descriptor_template[] = { 0x09, // 0 bLength 0x02, // 1 bDescriptorType (Configuration) @@ -102,33 +112,10 @@ static const uint8_t configuration_descriptor_template[] = { 0x32, // 8 bMaxPower 100mA }; -static uint8_t *configuration_descriptor; - -// Initialization done before boot.py is run. -// Turn on or off various USB devices. On devices with limited endpoints, -// some may be off by default. -void reset_usb_desc(void) { - // Set defaults for enabling/disabling of various USB devices. -#if CIRCUITPY_USB_CDC - common_hal_usb_cdc_configure_usb( - (bool) CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT, - (bool) CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT); -#endif - -#if CIRCUITPY_USB_MSC - common_hal_storage_configure_usb((bool) CIRCUITPY_USB_MSC_ENABLED_DEFAULT); -#endif - -#if CIRCUITPY_USB_MIDI - common_hal_usb_midi_configure_usb((bool) CIRCUITPY_USB_MIDI_ENABLED_DEFAULT); -#endif - -#if CIRCUITPY_USB_HID - common_hal_usb_hid_configure_usb_defaults(); -#endif -} - static void usb_build_device_descriptor(uint16_t vid, uint16_t pid) { + device_descriptor_allocation = + allocate_memory(sizeof(device_descriptor_template), /*high_address*/ false, /*movable*/ false); + uint8_t *device_descriptor = (uint8_t *) device_descriptor_allocation->ptr; memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); device_descriptor[DEVICE_VID_LO_INDEX] = vid & 0xFF; @@ -181,9 +168,13 @@ static void usb_build_configuration_descriptor(void) { } #endif - // Now we now how big the configuration descriptor will be. + // Now we now how big the configuration descriptor will be, so we can allocate space for it. + configuration_descriptor_allocation = + allocate_memory(total_descriptor_length, /*high_address*/ false, /*movable*/ false); + uint8_t *configuration_descriptor = (uint8_t *) configuration_descriptor_allocation->ptr; + // Copy the template, which is the first part of the descriptor, and fix up its length. - configuration_descriptor = gc_alloc(total_descriptor_length, false, false); + memcpy(configuration_descriptor, configuration_descriptor_template, sizeof(configuration_descriptor_template)); configuration_descriptor[CONFIG_TOTAL_LENGTH_LO_INDEX] = total_descriptor_length & 0xFF; @@ -234,10 +225,7 @@ static void usb_build_configuration_descriptor(void) { #endif // Now we know how many interfaces have been used. - // current_interface is the next free interface, counting from 0, - // so move back to the last interface number, and then get a count. - // (E.g., interfaces 0-5 are used, so the number of interfaces is 6.) - configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface - 1 + 1; + configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface; // Did we run out of endpoints? if (current_endpoint - 1 > USB_NUM_EP) { @@ -246,40 +234,59 @@ static void usb_build_configuration_descriptor(void) { } +// str must not be on the heap. void usb_add_interface_string(uint8_t interface_string_index, const char str[]) { if (interface_string_index > MAX_INTERFACE_STRINGS) { mp_raise_RuntimeError(translate("Too many USB interface names")); } - // 2 bytes for String Descriptor header, then 2 bytes for each character - const size_t str_len = strlen(str); - uint8_t descriptor_size = 2 + (str_len * 2); - uint16_t *string_descriptor = (uint16_t *) m_malloc(descriptor_size, false); - string_descriptor[0] = 0x0300 | descriptor_size; - // Convert to le16 - for (size_t i = 0; i <= str_len; i++) { - string_descriptor[i + 1] = str[i]; - } - collected_interface_strings[interface_string_index] = string_descriptor; + collected_interface_strings[interface_string_index].char_str = str; + collected_interface_strings_length += strlen(str); } +static void usb_build_interface_string_table(void) { + // Allocate space for the le16 String descriptors. + // Space needed is 2 bytes for String Descriptor header, then 2 bytes for each character + string_descriptors_allocation = + allocate_memory(current_interface_string * 2 + collected_interface_strings_length * 2, + /*high_address*/ false, /*movable*/ false); + uint16_t *string_descriptors = (uint16_t *) string_descriptors_allocation->ptr; -// Remember USB information that must persist from the boot.py VM to the next VM. -// Some of this is already remembered in globals, for example, usb_midi_enabled and similar bools. -void usb_desc_post_boot_py(void) { - usb_hid_post_boot_py(); -} -// Called in the new VM created after boot.py is run. The USB devices to be used are now chosen. -void usb_desc_init(void) { - memset(collected_interface_strings, 0, sizeof(collected_interface_strings)); + uint16_t *string_descriptor = string_descriptors; // Language ID is always the 0th string descriptor. - collected_interface_strings[0] = (uint16_t[]) { + collected_interface_strings[0].descriptor = (uint16_t[]) { 0x0304, 0x0409, }; + // Build the le16 versions of all the descriptor strings. + // Start at 1 to skip the Language ID. + for (uint8_t string_index = 1; string_index < current_interface_string; string_index++) { + const char *str = collected_interface_strings[string_index].char_str; + const size_t str_len = strlen(str); + uint8_t descriptor_size = 2 + (str_len * 2); + string_descriptor[0] = 0x0300 | descriptor_size; + + // Convert to le16. + for (size_t i = 0; i <= str_len; i++) { + string_descriptor[i + 1] = str[i]; + } + + // Save ptr to string descriptor with le16 str. + collected_interface_strings[string_index].descriptor = string_descriptor; + + // Move to next descriptor slot. + string_descriptor += descriptor_size; + } +} + +// After boot.py runs, the USB devices to be used have been chosen, and the descriptors can be set up. +// This should be called before the heap is destroyed, so that any objects in the heap, +// such as +// can be used. +void usb_desc_post_boot_py(void) { uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; common_hal_mcu_processor_get_uid(raw_id); @@ -294,31 +301,17 @@ void usb_desc_init(void) { serial_number_hex_string[sizeof(serial_number_hex_string) - 1] = '\0'; current_interface_string = 1; + collected_interface_strings_length = 0; usb_build_device_descriptor(USB_VID, USB_PID); usb_build_configuration_descriptor(); + usb_build_interface_string_table(); } -void usb_desc_gc_collect(void) { - // Once tud_mounted() is true, we're done with the constructed descriptors. - if (tud_mounted()) { - gc_free(device_descriptor); - gc_free(configuration_descriptor); - for (size_t i = 0; i < MAX_INTERFACE_STRINGS; i ++) { - gc_free(collected_interface_strings[i]); - } - } else { - gc_collect_ptr(device_descriptor); - gc_collect_ptr(configuration_descriptor); - gc_collect_root((void **) collected_interface_strings, MAX_INTERFACE_STRINGS); - } -} - - // Invoked when GET DEVICE DESCRIPTOR is received. // Application return pointer to descriptor uint8_t const *tud_descriptor_device_cb(void) { - return device_descriptor; + return (uint8_t *) device_descriptor_allocation; } // Invoked when GET CONFIGURATION DESCRIPTOR is received. @@ -326,7 +319,7 @@ uint8_t const *tud_descriptor_device_cb(void) { // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { (void)index; // for multiple configurations - return configuration_descriptor; + return (uint8_t *) configuration_descriptor_allocation->ptr; } // Invoked when GET STRING DESCRIPTOR request is received. @@ -335,5 +328,5 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) { if (index > MAX_INTERFACE_STRINGS) { return NULL; } - return collected_interface_strings[index]; + return collected_interface_strings[index].descriptor; } diff --git a/supervisor/usb.h b/supervisor/usb.h index a0e31f1913..d59217e491 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -49,20 +49,14 @@ void init_usb_hardware(void); void post_usb_init(void); // Shared implementation. -void reset_usb(void); bool usb_enabled(void); void usb_init(void); void usb_disconnect(void); -void usb_gc_collect(void); void usb_pre_boot_py(void); void usb_post_boot_py(void); -void usb_add_interface_string(uint8_t interface_string_index, const char str[]); - -void reset_usb_desc(void); -void usb_desc_gc_collect(void); -void usb_desc_init(void); void usb_desc_post_boot_py(void); +void usb_add_interface_string(uint8_t interface_string_index, const char str[]); // Propagate plug/unplug events to the MSC logic. #if CIRCUITPY_USB_MSC From abfb020d417fbead65c216132a759217fba2d97d Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 29 Apr 2021 17:41:43 -0400 Subject: [PATCH 34/66] MSC, CDC, HID keyboard definitely working --- main.c | 6 ---- shared-module/usb_cdc/__init__.c | 3 ++ shared-module/usb_hid/Device.c | 9 ++++++ shared-module/usb_hid/__init__.c | 46 ++++++++++++++++++++--------- shared-module/usb_midi/__init__.c | 3 ++ supervisor/shared/usb/tusb_config.h | 9 ++++-- supervisor/shared/usb/usb_desc.c | 16 +++++----- supervisor/supervisor.mk | 7 +++++ 8 files changed, 69 insertions(+), 30 deletions(-) diff --git a/main.c b/main.c index 28d275bd2b..119bc0ce9b 100755 --- a/main.c +++ b/main.c @@ -170,12 +170,6 @@ STATIC void start_mp(supervisor_allocation* heap) { #if CIRCUITPY_NETWORK network_module_init(); #endif - - #if CIRCUITPY_USB_HID - if (usb_enabled()) { - usb_hid_setup_devices(); - } - #endif } STATIC void stop_mp(void) { diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 1a9fe2ac45..7c2f94c84d 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -224,6 +224,9 @@ bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) { return false; } + // Right now these objects contain no heap objects, but if that changes, + // they will need to be protected against gc. + usb_cdc_repl_is_enabled = repl_enabled; usb_cdc_set_repl(repl_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_repl_obj) : mp_const_none); diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 1b7a6b9063..173090b999 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -71,6 +71,9 @@ static const uint8_t keyboard_report_descriptor[] = { }; const usb_hid_device_obj_t usb_hid_device_keyboard_obj = { + .base = { + .type = &usb_hid_device_type, + }, .report_descriptor = keyboard_report_descriptor, .report_descriptor_length = sizeof(keyboard_report_descriptor), .usage_page = 0x01, @@ -119,6 +122,9 @@ static const uint8_t mouse_report_descriptor[] = { }; const usb_hid_device_obj_t usb_hid_device_mouse_obj = { + .base = { + .type = &usb_hid_device_type, + }, .report_descriptor = mouse_report_descriptor, .report_descriptor_length = sizeof(mouse_report_descriptor), .usage_page = 0x01, @@ -145,6 +151,9 @@ static const uint8_t consumer_control_report_descriptor[] = { }; const usb_hid_device_obj_t usb_hid_device_consumer_control_obj = { + .base = { + .type = &usb_hid_device_type, + }, .report_descriptor = consumer_control_report_descriptor, .report_descriptor_length = sizeof(consumer_control_report_descriptor), .usage_page = 0x0C, diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 907a07e6ac..f4d4e14d87 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -83,6 +83,9 @@ static supervisor_allocation *hid_report_descriptor_allocation; static usb_hid_device_obj_t hid_devices[MAX_HID_DEVICES]; static mp_int_t hid_devices_num; +// This tuple is store in usb_hid.devices. +static mp_obj_tuple_t *hid_devices_tuple; + static mp_obj_tuple_t default_hid_devices_tuple = { .base = { .type = &mp_type_tuple, @@ -132,6 +135,19 @@ size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac return sizeof(usb_hid_descriptor_template); } +// Make up a fresh tuple containing the device objects saved in the static +// devices table. Save the tuple in usb_hid.devices. +static void usb_hid_set_devices_from_hid_devices(void) { + mp_obj_t tuple_items[hid_devices_num]; + for (mp_int_t i = 0; i < hid_devices_num; i++) { + tuple_items[i] = &hid_devices[i]; + } + + // Remember tuple for gc purposes. + hid_devices_tuple = mp_obj_new_tuple(hid_devices_num, tuple_items); + usb_hid_set_devices(hid_devices_tuple); +} + bool common_hal_usb_hid_configure_usb(const mp_obj_t devices) { // We can't change the devices once we're connected. if (tud_connected()) { @@ -151,20 +167,16 @@ bool common_hal_usb_hid_configure_usb(const mp_obj_t devices) { memcpy(&hid_devices[i], device, sizeof(usb_hid_device_obj_t)); } + usb_hid_set_devices_from_hid_devices(); + return true; } +// Called when HID devices are ready to be used, when code.py or the REPL starts running. void usb_hid_setup_devices(void) { - // Make up a fresh tuple containing the device objects are saved in the static - // devices table. Save the tuple in usb_hid.devices. + usb_hid_set_devices_from_hid_devices(); - mp_obj_t tuple_items[hid_devices_num]; - for (mp_int_t i = 0; i < hid_devices_num; i++) { - tuple_items[i] = &hid_devices[i]; - } - usb_hid_set_devices(mp_obj_new_tuple(hid_devices_num, tuple_items)); - - // Create report buffers on the heap. + // Create report buffers on the heap. for (mp_int_t i = 0; i < hid_devices_num; i++) { usb_hid_device_create_report_buffers(&hid_devices[i]); } @@ -174,10 +186,7 @@ void usb_hid_setup_devices(void) { size_t usb_hid_report_descriptor_length(void) { size_t total_hid_report_descriptor_length = 0; for (mp_int_t i = 0; i < hid_devices_num; i++) { - // hid_devices has already been validated to contain only usb_hid_device_obj_t objects. - usb_hid_device_obj_t *device = - MP_OBJ_TO_PTR(mp_obj_subscr(hid_devices, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL)); - total_hid_report_descriptor_length += device->report_descriptor_length; + total_hid_report_descriptor_length += hid_devices[i].report_descriptor_length; } // Don't need space for a report id if there's only one device. @@ -205,9 +214,15 @@ void usb_hid_build_report_descriptor(uint8_t* report_descriptor_space, size_t re // Copy the whole descriptor and fill in the report id. memcpy(report_descriptor_start, device->report_descriptor, device->report_descriptor_length); report_descriptor_start[device->report_id_index] = i + 1; + + // Remember the report id that was assigned. + device->report_id = i + 1; + + // Advance to the next free chunk for the next report descriptor.x report_descriptor_start += device->report_descriptor_length; } // Clear the heap pointer to the bytes of the descriptor. + // We don't need it any more and it will get lost when the heap goes away. device->report_descriptor = NULL; } } @@ -220,11 +235,14 @@ void usb_hid_save_report_descriptor(uint8_t *report_descriptor_space, size_t rep // Copy the descriptor from the temporary area to a supervisor storage allocation that // will leave between VM instantiations. hid_report_descriptor_allocation = - allocate_memory(report_descriptor_length, /*high_address*/ false, /*movable*/ false); + allocate_memory(align32_size(report_descriptor_length), + /*high_address*/ false, /*movable*/ false); memcpy((uint8_t *) hid_report_descriptor_allocation->ptr, report_descriptor_space, report_descriptor_length); } void usb_hid_gc_collect(void) { + gc_collect_ptr(hid_devices_tuple); + // Mark any heap pointers in the static device list as in use. for (mp_int_t i = 0; i < hid_devices_num; i++) { gc_collect_ptr(&hid_devices[i]); diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 150666287e..153e6910f2 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -234,6 +234,9 @@ static const mp_rom_obj_tuple_t midi_ports_tuple = { }; void usb_midi_setup_ports(void) { + // Right now midi_ports_tuple contains no heap objects, but if it does in the future, + // it will need to be protected against gc. + mp_obj_tuple_t *ports = usb_midi_is_enabled ? MP_OBJ_FROM_PTR(&midi_ports_tuple) : mp_const_empty_tuple; mp_map_lookup(&usb_midi_module_globals.map, MP_ROM_QSTR(MP_QSTR_ports), MP_MAP_LOOKUP)->value = MP_OBJ_FROM_PTR(ports); diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 5bccc51c71..24977c59c2 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -59,14 +59,17 @@ extern "C" { // DEVICE CONFIGURATION // --------------------------------------------------------------------+ +#if USB_HIGHSPEED #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | OPT_MODE_HIGH_SPEED) +#else +#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE) +#endif // Vendor name included in Inquiry response, max 8 bytes -#define CFG_TUD_MSC_VENDOR USB_MANUFACTURER +#define CFG_TUD_MSC_VENDOR USB_MANUFACTURER_8 // Product name included in Inquiry response, max 16 bytes -#define CFG_TUD_MSC_PRODUCT USB_PRODUCT - +#define CFG_TUD_MSC_PRODUCT USB_PRODUCT_16 #define CFG_TUD_ENDPOINT0_SIZE 64 // ------------- CLASS -------------// diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 7dc1f97407..4d6ea401b7 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -63,9 +63,9 @@ static interface_string_t collected_interface_strings[MAX_INTERFACE_STRINGS]; static size_t collected_interface_strings_length; static uint8_t current_interface_string; -supervisor_allocation *device_descriptor_allocation; -supervisor_allocation *configuration_descriptor_allocation; -supervisor_allocation *string_descriptors_allocation; +static supervisor_allocation *device_descriptor_allocation; +static supervisor_allocation *configuration_descriptor_allocation; +static supervisor_allocation *string_descriptors_allocation; static const char manufacturer_name[] = USB_MANUFACTURER; static const char product_name[] = USB_PRODUCT; @@ -114,7 +114,8 @@ static const uint8_t configuration_descriptor_template[] = { static void usb_build_device_descriptor(uint16_t vid, uint16_t pid) { device_descriptor_allocation = - allocate_memory(sizeof(device_descriptor_template), /*high_address*/ false, /*movable*/ false); + allocate_memory(align32_size(sizeof(device_descriptor_template)), + /*high_address*/ false, /*movable*/ false); uint8_t *device_descriptor = (uint8_t *) device_descriptor_allocation->ptr; memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); @@ -170,7 +171,8 @@ static void usb_build_configuration_descriptor(void) { // Now we now how big the configuration descriptor will be, so we can allocate space for it. configuration_descriptor_allocation = - allocate_memory(total_descriptor_length, /*high_address*/ false, /*movable*/ false); + allocate_memory(align32_size(total_descriptor_length), + /*high_address*/ false, /*movable*/ false); uint8_t *configuration_descriptor = (uint8_t *) configuration_descriptor_allocation->ptr; // Copy the template, which is the first part of the descriptor, and fix up its length. @@ -248,7 +250,7 @@ static void usb_build_interface_string_table(void) { // Allocate space for the le16 String descriptors. // Space needed is 2 bytes for String Descriptor header, then 2 bytes for each character string_descriptors_allocation = - allocate_memory(current_interface_string * 2 + collected_interface_strings_length * 2, + allocate_memory(align32_size(current_interface_string * 2 + collected_interface_strings_length * 2), /*high_address*/ false, /*movable*/ false); uint16_t *string_descriptors = (uint16_t *) string_descriptors_allocation->ptr; @@ -309,7 +311,7 @@ void usb_build_descriptors(void) { // Invoked when GET DEVICE DESCRIPTOR is received. // Application return pointer to descriptor uint8_t const *tud_descriptor_device_cb(void) { - return (uint8_t *) device_descriptor_allocation; + return (uint8_t *) device_descriptor_allocation->ptr; } // Invoked when GET CONFIGURATION DESCRIPTOR is received. diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 93da9e1b59..1ca937cdab 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -144,7 +144,13 @@ ifneq ($(USB_VID),) CFLAGS += -DUSB_VID=$(USB_VID) CFLAGS += -DUSB_PID=$(USB_PID) CFLAGS += -DUSB_MANUFACTURER='$(USB_MANUFACTURER)' +USB_MANUFACTURER_8 := "$(shell echo $(USB_MANUFACTURER) | cut -c 1-8)" +# Length-limited versions of strings for MSC names. +CFLAGS += -DUSB_MANUFACTURER_8='$(USB_MANUFACTURER_8)' +USB_PRODUCT_16 := "$(shell echo $(USB_PRODUCT) | cut -c 1-16)" +CFLAGS += -DUSB_PRODUCT_16='$(USB_PRODUCT_16)' CFLAGS += -DUSB_PRODUCT='$(USB_PRODUCT)' + endif # In the following URL, don't include the https:// prefix. @@ -157,6 +163,7 @@ CFLAGS += -DCFG_TUD_CDC=2 endif USB_HIGHSPEED ?= 0 +CFLAGS += -DUSB_HIGHSPEED=$(USB_HIGHSPEED) $(BUILD)/supervisor/shared/translate.o: $(HEADER_BUILD)/qstrdefs.generated.h From 71a8cadb097c503539c0dae1589b686d22271c4a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 29 Apr 2021 22:26:38 -0400 Subject: [PATCH 35/66] working! --- locale/circuitpython.pot | 2 +- shared-bindings/usb_cdc/__init__.c | 18 ++++++++++++------ shared-bindings/usb_hid/Device.c | 2 +- shared-module/storage/__init__.c | 4 ++-- supervisor/shared/serial.c | 23 +++++++++++++++++++---- supervisor/shared/usb/tusb_config.h | 2 +- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index beb10061c1..3c9ce25036 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -659,7 +659,7 @@ msgid "Cannot record to a file" msgstr "" #: shared-module/storage/__init__.c -msgid "Cannot remount '/' when USB is active." +msgid "Cannot remount '/' when visible via USB." msgstr "" #: ports/atmel-samd/common-hal/microcontroller/__init__.c diff --git a/shared-bindings/usb_cdc/__init__.c b/shared-bindings/usb_cdc/__init__.c index 24728366a6..ac39b6d50d 100644 --- a/shared-bindings/usb_cdc/__init__.c +++ b/shared-bindings/usb_cdc/__init__.c @@ -60,7 +60,7 @@ //| the host. //| Note that `data` is *disabled* by default.""" -//| def configure_usb(repl_enabled: bool, data_enabled: bool) -> None: +//| def configure_usb(*, repl_enabled: bool = True, data_enabled: bool = False) -> None: //| """Configure the USB CDC devices. Can be called in ``boot.py``, before USB is connected. //| //| :param repl_enabled bool: Enable or disable the `repl` USB serial device. @@ -69,15 +69,21 @@ //| True to enable; False to disable. *Disabled* by default.""" //| ... //| -STATIC mp_obj_t usb_cdc_configure_usb(mp_obj_t repl_enabled, mp_obj_t data_enabled) { - if (!common_hal_usb_cdc_configure_usb( - mp_obj_is_true(repl_enabled), - mp_obj_is_true(data_enabled))) { +STATIC mp_obj_t usb_cdc_configure_usb(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_repl_enabled, ARG_data_enabled }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_repl_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true } }, + { MP_QSTR_data_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (!common_hal_usb_cdc_configure_usb(args[ARG_repl_enabled].u_bool, args[ARG_data_enabled].u_bool)) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(usb_cdc_configure_usb_obj, usb_cdc_configure_usb); +MP_DEFINE_CONST_FUN_OBJ_KW(usb_cdc_configure_usb_obj, 0, usb_cdc_configure_usb); // The usb_cdc module dict is mutable so that .repl and .data may // be set to a Serial or to None depending on whether they are enabled or not. diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 72eb5f219a..6b2f3005d2 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -60,7 +60,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { usb_hid_device_obj_t *self = m_new_obj(usb_hid_device_obj_t); self->base.type = &usb_hid_device_type; - enum { ARG_report_descriptor, ARG_usage, ARG_usage_page, ARG_in_report_length, ARG_out_report_length, ARG_report_id_index }; + enum { ARG_report_descriptor, ARG_usage_page, ARG_usage, ARG_in_report_length, ARG_out_report_length, ARG_report_id_index }; static const mp_arg_t allowed_args[] = { { MP_QSTR_report_descriptor, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_usage_page, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 6d66025222..383882e8bc 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -229,8 +229,8 @@ void common_hal_storage_remount(const char *mount_path, bool readonly, bool disa } #if CIRCUITPY_USB_MSC - if (!usb_msc_ejected()) { - mp_raise_RuntimeError(translate("Cannot remount '/' when USB is active.")); + if (!usb_msc_ejected() && storage_usb_is_enabled) { + mp_raise_RuntimeError(translate("Cannot remount '/' when visible via USB.")); } #endif diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 6108bfacf4..42d2e6caf9 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -34,6 +34,7 @@ #include "supervisor/serial.h" #include "supervisor/usb.h" #include "shared-bindings/microcontroller/Pin.h" +#include "shared-module/usb_cdc/__init__.h" #include "tusb.h" @@ -92,6 +93,8 @@ bool serial_connected(void) { #if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX) return true; + #elif CIRCUITPY_USB_CDC + return usb_cdc_repl_enabled() && tud_cdc_connected(); #else return tud_cdc_connected(); #endif @@ -114,9 +117,12 @@ char serial_read(void) { char text; common_hal_busio_uart_read(&debug_uart, (uint8_t *)&text, 1, &uart_errcode); return text; - #else - return (char)tud_cdc_read_char(); + #elif CIRCUITPY_USB_CDC + if (!usb_cdc_repl_enabled()) { + return -1; + } #endif + return (char)tud_cdc_read_char(); } bool serial_bytes_available(void) { @@ -128,9 +134,12 @@ bool serial_bytes_available(void) { #if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX) return common_hal_busio_uart_rx_characters_available(&debug_uart) || (tud_cdc_available() > 0); - #else - return tud_cdc_available() > 0; + #elif CIRCUITPY_USB_CDC + if (!usb_cdc_repl_enabled()) { + return 0; + } #endif + return tud_cdc_available() > 0; } void serial_write_substring(const char *text, uint32_t length) { if (length == 0) { @@ -147,6 +156,12 @@ void serial_write_substring(const char *text, uint32_t length) { } #endif + #if CIRCUITPY_USB_CDC + if (!usb_cdc_repl_enabled()) { + return; + } + #endif + uint32_t count = 0; while (count < length && tud_cdc_connected()) { count += tud_cdc_write(text + count, length - count); diff --git a/supervisor/shared/usb/tusb_config.h b/supervisor/shared/usb/tusb_config.h index 24977c59c2..e75a653244 100644 --- a/supervisor/shared/usb/tusb_config.h +++ b/supervisor/shared/usb/tusb_config.h @@ -74,7 +74,7 @@ extern "C" { // ------------- CLASS -------------// -// Could be 2 if secondary CDC channel requested. +// Will be set to 2 in supervisor.mk if CIRCUITPY_USB_CDC is set. #ifndef CFG_TUD_CDC #define CFG_TUD_CDC 1 #endif From b5efce12cd61500b5665b98984fe2c2ab352dec1 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 29 Apr 2021 23:05:31 -0400 Subject: [PATCH 36/66] delete hid .py; undo some debugging changes --- ports/atmel-samd/Makefile | 2 +- .../boards/metro_m4_express/mpconfigboard.mk | 1 - tools/hid_report_descriptors.py | 61 ------------------- 3 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 tools/hid_report_descriptors.py diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 63b4a35f56..574d115260 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -126,7 +126,7 @@ ifeq ($(DEBUG), 1) # You may want to disable -flto if it interferes with debugging. CFLAGS += -flto -flto-partition=none # You may want to enable these flags to make setting breakpoints easier. - CFLAGS += -fno-inline -fno-ipa-sra + # CFLAGS += -fno-inline -fno-ipa-sra ifeq ($(CHIP_FAMILY), samd21) CFLAGS += -DENABLE_MICRO_TRACE_BUFFER endif diff --git a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk index c944cd6e0c..553bf14f2e 100644 --- a/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m4_express/mpconfigboard.mk @@ -11,4 +11,3 @@ EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C" LONGINT_IMPL = MPZ CIRCUITPY__EVE = 1 -CIRCUITPY_ULAB = 0 diff --git a/tools/hid_report_descriptors.py b/tools/hid_report_descriptors.py deleted file mode 100644 index c8dd5238ca..0000000000 --- a/tools/hid_report_descriptors.py +++ /dev/null @@ -1,61 +0,0 @@ -# SPDX-FileCopyrightText: Copyright (c) 2018 Dan Halbert for Adafruit Industries -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -import struct - -""" -HID specific descriptors -======================== - -* Author(s): Dan Halbert -""" - -from collections import namedtuple - -from adafruit_usb_descriptor import hid - -# Information about each kind of device -# report_length does not include report ID in first byte, if present when sent. -DeviceData = namedtuple( - "DeviceData", ("report_length", "out_report_length", "usage_page", "usage") -) -HID_DEVICE_DATA = { - "KEYBOARD": DeviceData( - report_length=8, out_report_length=1, usage_page=0x01, usage=0x06 - ), # Generic Desktop, Keyboard - "MOUSE": DeviceData( - report_length=4, out_report_length=0, usage_page=0x01, usage=0x02 - ), # Generic Desktop, Mouse - "CONSUMER": DeviceData( - report_length=2, out_report_length=0, usage_page=0x0C, usage=0x01 - ), # Consumer, Consumer Control - "SYS_CONTROL": DeviceData( - report_length=1, out_report_length=0, usage_page=0x01, usage=0x80 - ), # Generic Desktop, Sys Control - "GAMEPAD": DeviceData( - report_length=6, out_report_length=0, usage_page=0x01, usage=0x05 - ), # Generic Desktop, Game Pad - "DIGITIZER": DeviceData( - report_length=5, out_report_length=0, usage_page=0x0D, usage=0x02 - ), # Digitizers, Pen - "XAC_COMPATIBLE_GAMEPAD": DeviceData( - report_length=3, out_report_length=0, usage_page=0x01, usage=0x05 - ), # Generic Desktop, Game Pad - "RAW": DeviceData( - report_length=64, out_report_length=0, usage_page=0xFFAF, usage=0xAF - ), # Vendor 0xFFAF "Adafruit", 0xAF -} - -# Function to call for each kind of HID descriptor. -REPORT_DESCRIPTOR_FUNCTIONS = { - "KEYBOARD": hid.ReportDescriptor.keyboard, - "MOUSE": hid.ReportDescriptor.mouse, - "CONSUMER": hid.ReportDescriptor.consumer_control, - "SYS_CONTROL": hid.ReportDescriptor.sys_control, - "GAMEPAD": hid.ReportDescriptor.gamepad, - "DIGITIZER": hid.ReportDescriptor.digitizer, - "XAC_COMPATIBLE_GAMEPAD": hid.ReportDescriptor.xac_compatible_gamepad, - "RAW": hid.ReportDescriptor.raw, -} From 3189668781bd84154cac4a25fa1952bdaccdb92b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 29 Apr 2021 23:15:32 -0400 Subject: [PATCH 37/66] bring protomatter up to date --- lib/protomatter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protomatter b/lib/protomatter index c2c81ded11..98017c5734 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit c2c81ded118484f8925bf81e270b416739cd72d9 +Subproject commit 98017c57349e259fab70c6a7830436b19a55f6f4 From 48dd54cb854b7a98d09c418806a151b3e3393fbd Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 29 Apr 2021 23:17:10 -0400 Subject: [PATCH 38/66] undo requirements-dev.txt changes --- requirements-dev.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 4b0e36d617..1c956f0f98 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,7 +8,7 @@ typer requests sh -click>=7.1.2 +click setuptools cpp-coveralls @@ -20,14 +20,14 @@ sphinx-autoapi sphinxcontrib-svg2pdfconverter # For translate check -polib>=1.1.0 +polib # For pre-commit pyyaml -astroid>=2.5.1 -isort>=5.7.0 -black>=20.8b1 -mypy>=0.812 +astroid +isort +black +mypy # For uploading artifacts awscli From b8b20faa20d9802e6530699f68287864af3e3740 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 29 Apr 2021 23:51:39 -0400 Subject: [PATCH 39/66] doc fixes --- shared-bindings/usb_hid/Device.c | 14 +++++++------- shared-bindings/usb_hid/__init__.c | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 6b2f3005d2..9c5f105c66 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -36,25 +36,25 @@ //| import usb_hid //| //| mouse = usb_hid.devices[0] -//| //| mouse.send_report()""" //| -//| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: Optional[int], , report_id_index: Optional[int]) -> None: +//| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: Optional[int], report_id_index: Optional[int]) -> None: //| """Create a description of a USB HID device. To create an actual device, //| pass a `Device` to `usb_hid.configure_usb()`. //| //| :param ReadableBuffer report_descriptor: The USB HID Report descriptor bytes. The descriptor is not -//| not verified for correctness; it is up to you to make sure it is not malformed. +//| not verified for correctness; it is up to you to make sure it is not malformed. //| :param int usage_page: The Usage Page value from the descriptor. Must match what is in the descriptor. //| :param int usage: The Usage value from the descriptor. Must match what is in the descriptor. //| :param int in_report_length: Size in bytes of the HID report sent to the host. -//| "In" is with respect to the host. +//| "In" is with respect to the host. //| :param int out_report_length: Size in bytes of the HID report received from the host. -//| "Out" is with respect to the host. If no reports are expected, use ``None``. +//| "Out" is with respect to the host. If no reports are expected, use ``None``. //| :param int report_id_index: position of byte in descriptor that contains the Report ID. -//| A Report ID will be assigned when the device is created. If there is no -//| Report ID, use ``None``. +//| A Report ID will be assigned when the device is created. If there is no +//| Report ID, use ``None``. +//| """ //| ... //| STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 68fcee56c4..372f64a218 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -48,6 +48,7 @@ //| If `devices` is empty, HID is disabled. The order of the ``Devices`` //| may matter to the host. For instance, for MacOS, put the mouse device //| before any Gamepad or Digitizer HID device or else it will not work. +//| """ //| ... //| STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { From cc95b71d64e781a1b566ffa59d74801cb9fef25b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 30 Apr 2021 09:40:40 -0400 Subject: [PATCH 40/66] fix type annotations --- shared-bindings/storage/__init__.c | 2 +- shared-bindings/usb_hid/__init__.c | 2 +- shared-bindings/usb_midi/__init__.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 74afe61da2..a6e5fdd10e 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -158,7 +158,7 @@ mp_obj_t storage_erase_filesystem(void) { } MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem); -//| def configure_usb(enabled: True) -> None: +//| def configure_usb(enabled: bool = True) -> None: //| """Configure the USB mass storage device. //| Enable or disable presenting ``CIRCUITPY`` as a USB mass storage device. //| By default, the device is enabled and ``CIRCUITPY`` is visible. diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 372f64a218..2f01560ccf 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -40,7 +40,7 @@ //| """Tuple of all active HID device interfaces.""" //| -//| def configure_usb(devices: Optional[Sequence[Device, ...]]) -> None: +//| def configure_usb(devices: Optional[Sequence[Device]]) -> None: //| """Configure the USB HID devices that will be available. //| Can be called in ``boot.py``, before USB is connected. //| diff --git a/shared-bindings/usb_midi/__init__.c b/shared-bindings/usb_midi/__init__.c index 6aaa60aa48..a18ba599b7 100644 --- a/shared-bindings/usb_midi/__init__.c +++ b/shared-bindings/usb_midi/__init__.c @@ -43,7 +43,7 @@ //| """Tuple of all MIDI ports. Each item is ether `PortIn` or `PortOut`.""" //| -//| def configure_usb(enabled: True) -> None: +//| def configure_usb(enabled: bool = True) -> None: //| """Configure the USB MIDI device. //| Can be called in ``boot.py``, before USB is connected. //| From be7b2b00a889203fca377dd28984883fd63ce308 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 30 Apr 2021 10:40:12 -0400 Subject: [PATCH 41/66] uncrustify with newer version of uncrustify --- .../common-hal/audiobusio/PDMIn.c.uncrustify | 0 shared-bindings/usb_hid/Device.c | 16 +++-- shared-module/storage/__init__.c | 4 +- shared-module/storage/__init__.h | 2 +- shared-module/usb_cdc/__init__.c | 6 +- shared-module/usb_cdc/__init__.h | 2 +- shared-module/usb_hid/Device.c | 62 +++++++++---------- shared-module/usb_hid/__init__.c | 16 ++--- shared-module/usb_hid/__init__.h | 4 +- shared-module/usb_midi/__init__.c | 8 +-- shared-module/usb_midi/__init__.h | 2 +- supervisor/shared/memory.c | 56 ++++++++--------- 12 files changed, 88 insertions(+), 90 deletions(-) delete mode 100644 ports/atmel-samd/common-hal/audiobusio/PDMIn.c.uncrustify diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c.uncrustify b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c.uncrustify deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 9c5f105c66..2f279e8f16 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -65,7 +65,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args { MP_QSTR_report_descriptor, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_usage_page, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_usage, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, - { MP_QSTR_in_report_length, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT } , + { MP_QSTR_in_report_length, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_out_report_length, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } }, { MP_QSTR_report_id_index, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } }, }; @@ -98,10 +98,9 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args const mp_obj_t out_report_length_arg = args[ARG_out_report_length].u_obj; if (out_report_length_arg == mp_const_none) { self->out_report_length = 0; - } - else if (!mp_obj_is_small_int(out_report_length_arg) || - MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) <= 0 || - MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) > 255) { + } else if (!mp_obj_is_small_int(out_report_length_arg) || + MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) <= 0 || + MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) > 255) { mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_out_report_length); } uint8_t out_report_length = MP_OBJ_SMALL_INT_VALUE(out_report_length_arg); @@ -109,10 +108,9 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args const mp_obj_t report_id_index_arg = args[ARG_report_id_index].u_obj; if (report_id_index_arg == mp_const_none) { self->report_id_index = 0; - } - else if (!mp_obj_is_small_int(report_id_index_arg) || - MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) <= 0 || - MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) > 255 ) { + } else if (!mp_obj_is_small_int(report_id_index_arg) || + MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) <= 0 || + MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) > 255) { mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_report_id_index); } uint8_t report_id_index = MP_OBJ_SMALL_INT_VALUE(report_id_index_arg); diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 383882e8bc..64fbc4608b 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -91,9 +91,9 @@ size_t storage_usb_descriptor_length(void) { return sizeof(usb_msc_descriptor_template); } -static const char storage_interface_name[] = USB_INTERFACE_NAME " Mass Storage"; +static const char storage_interface_name[] = USB_INTERFACE_NAME " Mass Storage"; -size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { +size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string) { memcpy(descriptor_buf, usb_msc_descriptor_template, sizeof(usb_msc_descriptor_template)); descriptor_buf[MSC_INTERFACE_INDEX] = *current_interface; (*current_interface)++; diff --git a/shared-module/storage/__init__.h b/shared-module/storage/__init__.h index 8e74e7c975..addc8e3d05 100644 --- a/shared-module/storage/__init__.h +++ b/shared-module/storage/__init__.h @@ -33,7 +33,7 @@ bool storage_usb_enabled(void); void storage_usb_set_defaults(void); size_t storage_usb_descriptor_length(void); -size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string); +size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string); #endif #endif // SHARED_MODULE_STORAGE___INIT___H diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 7c2f94c84d..9be8483c7c 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -173,7 +173,7 @@ size_t usb_cdc_descriptor_length(void) { return sizeof(usb_cdc_descriptor_template); } -size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl) { +size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string, bool repl) { memcpy(descriptor_buf, usb_cdc_descriptor_template, sizeof(usb_cdc_descriptor_template)); // Store comm interface number. @@ -206,12 +206,12 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac (*current_endpoint)++; usb_add_interface_string(*current_interface_string, - repl ? repl_cdc_comm_interface_name : data_cdc_comm_interface_name); + repl ? repl_cdc_comm_interface_name : data_cdc_comm_interface_name); descriptor_buf[CDC_COMM_INTERFACE_STRING_INDEX] = *current_interface_string; (*current_interface_string)++; usb_add_interface_string(*current_interface_string, - repl ? repl_cdc_data_interface_name : data_cdc_data_interface_name); + repl ? repl_cdc_data_interface_name : data_cdc_data_interface_name); descriptor_buf[CDC_DATA_INTERFACE_STRING_INDEX] = *current_interface_string; (*current_interface_string)++; diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index 949917ef24..b2cb8aa075 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -36,6 +36,6 @@ bool usb_cdc_data_enabled(void); void usb_cdc_set_defaults(void); size_t usb_cdc_descriptor_length(void); -size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, bool repl); +size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string, bool repl); #endif /* SHARED_MODULE_USB_CDC___INIT___H */ diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 173090b999..7650854de3 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -36,38 +36,38 @@ #include "tusb.h" static const uint8_t keyboard_report_descriptor[] = { - 0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls) - 0x09, 0x06, // 2,3 Usage (Keyboard) - 0xA1, 0x01, // 4,5 Collection (Application) - 0x85, 0xFF, // 6,7 Report ID [SET AT RUNTIME] + 0x05, 0x01, // 0,1 Usage Page (Generic Desktop Ctrls) + 0x09, 0x06, // 2,3 Usage (Keyboard) + 0xA1, 0x01, // 4,5 Collection (Application) + 0x85, 0xFF, // 6,7 Report ID [SET AT RUNTIME] #define KEYBOARD_REPORT_ID_INDEX (7) - 0x05, 0x07, // Usage Page (Kbrd/Keypad) - 0x19, 0xE0, // Usage Minimum (0xE0) - 0x29, 0xE7, // Usage Maximum (0xE7) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0x01, // Logical Maximum (1) - 0x75, 0x01, // Report Size (1) - 0x95, 0x08, // Report Count (8) - 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x19, 0x00, // Usage Minimum (0x00) - 0x29, 0xDD, // Usage Maximum (0xDD) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0xDD, // Logical Maximum (-35) - 0x75, 0x08, // Report Size (8) - 0x95, 0x06, // Report Count (6) - 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) - 0x05, 0x08, // Usage Page (LEDs) - 0x19, 0x01, // Usage Minimum (Num Lock) - 0x29, 0x05, // Usage Maximum (Kana) - 0x15, 0x00, // Logical Minimum (0) - 0x25, 0x01, // Logical Maximum (1) - 0x75, 0x01, // Report Size (1) - 0x95, 0x05, // Report Count (5) - 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) - 0x95, 0x03, // Report Count (3) - 0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) - 0xC0, // End Collection + 0x05, 0x07, // Usage Page (Kbrd/Keypad) + 0x19, 0xE0, // Usage Minimum (0xE0) + 0x29, 0xE7, // Usage Maximum (0xE7) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x75, 0x01, // Report Size (1) + 0x95, 0x08, // Report Count (8) + 0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x19, 0x00, // Usage Minimum (0x00) + 0x29, 0xDD, // Usage Maximum (0xDD) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0xDD, // Logical Maximum (-35) + 0x75, 0x08, // Report Size (8) + 0x95, 0x06, // Report Count (6) + 0x81, 0x00, // Input (Data,Array,Abs,No Wrap,Linear,Preferred State,No Null Position) + 0x05, 0x08, // Usage Page (LEDs) + 0x19, 0x01, // Usage Minimum (Num Lock) + 0x29, 0x05, // Usage Maximum (Kana) + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x75, 0x01, // Report Size (1) + 0x95, 0x05, // Report Count (5) + 0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) + 0x95, 0x03, // Report Count (3) + 0x91, 0x01, // Output (Const,Array,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile) + 0xC0, // End Collection }; const usb_hid_device_obj_t usb_hid_device_keyboard_obj = { diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index f4d4e14d87..831c961955 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -112,10 +112,10 @@ size_t usb_hid_descriptor_length(void) { return sizeof(usb_hid_descriptor_template); } -static const char usb_hid_interface_name[] = USB_INTERFACE_NAME " HID"; +static const char usb_hid_interface_name[] = USB_INTERFACE_NAME " HID"; // This is the interface descriptor, not the report descriptor. -size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length) { +size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string, uint16_t report_descriptor_length) { memcpy(descriptor_buf, usb_hid_descriptor_template, sizeof(usb_hid_descriptor_template)); descriptor_buf[HID_DESCRIPTOR_INTERFACE_INDEX] = *current_interface; @@ -176,7 +176,7 @@ bool common_hal_usb_hid_configure_usb(const mp_obj_t devices) { void usb_hid_setup_devices(void) { usb_hid_set_devices_from_hid_devices(); - // Create report buffers on the heap. + // Create report buffers on the heap. for (mp_int_t i = 0; i < hid_devices_num; i++) { usb_hid_device_create_report_buffers(&hid_devices[i]); } @@ -197,7 +197,7 @@ size_t usb_hid_report_descriptor_length(void) { } // Build the combined HID report descriptor in the given space. -void usb_hid_build_report_descriptor(uint8_t* report_descriptor_space, size_t report_descriptor_length) { +void usb_hid_build_report_descriptor(uint8_t *report_descriptor_space, size_t report_descriptor_length) { uint8_t *report_descriptor_start = report_descriptor_space; for (mp_int_t i = 0; i < hid_devices_num; i++) { @@ -209,7 +209,7 @@ void usb_hid_build_report_descriptor(uint8_t* report_descriptor_space, size_t re memcpy(report_descriptor_start, device->report_descriptor, device->report_id_index - 1); report_descriptor_start += device->report_id_index - 1; memcpy(report_descriptor_start, device->report_descriptor + device->report_id_index + 1, - device->report_descriptor_length - device->report_id_index - 1); + device->report_descriptor_length - device->report_id_index - 1); } else { // Copy the whole descriptor and fill in the report id. memcpy(report_descriptor_start, device->report_descriptor, device->report_descriptor_length); @@ -236,8 +236,8 @@ void usb_hid_save_report_descriptor(uint8_t *report_descriptor_space, size_t rep // will leave between VM instantiations. hid_report_descriptor_allocation = allocate_memory(align32_size(report_descriptor_length), - /*high_address*/ false, /*movable*/ false); - memcpy((uint8_t *) hid_report_descriptor_allocation->ptr, report_descriptor_space, report_descriptor_length); + /*high_address*/ false, /*movable*/ false); + memcpy((uint8_t *)hid_report_descriptor_allocation->ptr, report_descriptor_space, report_descriptor_length); } void usb_hid_gc_collect(void) { @@ -263,5 +263,5 @@ usb_hid_device_obj_t *usb_hid_get_device_with_report_id(uint8_t report_id) { // Application return pointer to descriptor // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { - return (uint8_t *) hid_report_descriptor_allocation->ptr; + return (uint8_t *)hid_report_descriptor_allocation->ptr; } diff --git a/shared-module/usb_hid/__init__.h b/shared-module/usb_hid/__init__.h index 56682c24cf..24a4d57a69 100644 --- a/shared-module/usb_hid/__init__.h +++ b/shared-module/usb_hid/__init__.h @@ -34,13 +34,13 @@ extern usb_hid_device_obj_t usb_hid_devices[]; bool usb_hid_enabled(void); void usb_hid_set_defaults(void); -size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string, uint16_t report_descriptor_length); +size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string, uint16_t report_descriptor_length); size_t usb_hid_descriptor_length(void); size_t usb_hid_report_descriptor_length(void); void usb_hid_setup_devices(void); size_t usb_hid_report_descriptor_length(void); -void usb_hid_build_report_descriptor(uint8_t* report_descriptor_space, size_t report_descriptor_length); +void usb_hid_build_report_descriptor(uint8_t *report_descriptor_space, size_t report_descriptor_length); void usb_hid_save_report_descriptor(uint8_t *report_descriptor_space, size_t report_descriptor_length); usb_hid_device_obj_t *usb_hid_get_device_with_report_id(uint8_t report_id); diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 153e6910f2..3d33eefc97 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -170,12 +170,12 @@ size_t usb_midi_descriptor_length(void) { return sizeof(usb_midi_descriptor_template); } -static const char midi_streaming_interface_name[] = USB_INTERFACE_NAME " MIDI"; +static const char midi_streaming_interface_name[] = USB_INTERFACE_NAME " MIDI"; static const char midi_audio_control_interface_name[] = USB_INTERFACE_NAME " Audio"; -static const char midi_in_jack_name[] = USB_INTERFACE_NAME " usb_midi.ports[0]"; -static const char midi_out_jack_name[] = USB_INTERFACE_NAME " usb_midi.ports[0]"; +static const char midi_in_jack_name[] = USB_INTERFACE_NAME " usb_midi.ports[0]"; +static const char midi_out_jack_name[] = USB_INTERFACE_NAME " usb_midi.ports[0]"; -size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string) { +size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string) { memcpy(descriptor_buf, usb_midi_descriptor_template, sizeof(usb_midi_descriptor_template)); descriptor_buf[MIDI_AUDIO_CONTROL_INTERFACE_NUMBER_INDEX] = *current_interface; diff --git a/shared-module/usb_midi/__init__.h b/shared-module/usb_midi/__init__.h index 95820c5e11..9ab61e12db 100644 --- a/shared-module/usb_midi/__init__.h +++ b/shared-module/usb_midi/__init__.h @@ -32,6 +32,6 @@ void usb_midi_set_defaults(void); void usb_midi_setup_ports(void); size_t usb_midi_descriptor_length(void); -size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t* current_interface_string); +size_t usb_midi_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string); #endif /* SHARED_MODULE_USB_MIDI___INIT___H */ diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index 27022b2ff8..a20df618ca 100644 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -34,42 +34,42 @@ enum { CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT = - // stack + heap - 2 + // stack + heap + 2 - #if INTERNAL_FLASH_FILESYSTEM == 0 - + 1 - #endif + #if INTERNAL_FLASH_FILESYSTEM == 0 + + 1 + #endif - #if CIRCUITPY_USB - +1 // device_descriptor_allocation - +1 // configuration_descriptor_allocation - +1 // string_descriptors_allocation - #endif + #if CIRCUITPY_USB + + 1 // device_descriptor_allocation + + 1 // configuration_descriptor_allocation + + 1 // string_descriptors_allocation + #endif - #if CIRCUITPY_USB_HID - + 1 // hid_report_descriptor_allocation - + 1 // hid_devices_allocation - #endif + #if CIRCUITPY_USB_HID + + 1 // hid_report_descriptor_allocation + + 1 // hid_devices_allocation + #endif , CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT = - 0 - #if CIRCUITPY_DISPLAYIO - #if CIRCUITPY_TERMINALIO - + 1 - #endif - + CIRCUITPY_DISPLAY_LIMIT * ( - // Maximum needs of one display: max(4 if RGBMATRIX, 1 if SHARPDISPLAY, 0) - #if CIRCUITPY_RGBMATRIX - 4 - #elif CIRCUITPY_SHARPDISPLAY - 1 - #else 0 + #if CIRCUITPY_DISPLAYIO + #if CIRCUITPY_TERMINALIO + + 1 + #endif + + CIRCUITPY_DISPLAY_LIMIT * ( + // Maximum needs of one display: max(4 if RGBMATRIX, 1 if SHARPDISPLAY, 0) + #if CIRCUITPY_RGBMATRIX + 4 + #elif CIRCUITPY_SHARPDISPLAY + 1 + #else + 0 + #endif + ) #endif - ) - #endif , CIRCUITPY_SUPERVISOR_ALLOC_COUNT = CIRCUITPY_SUPERVISOR_IMMOVABLE_ALLOC_COUNT + CIRCUITPY_SUPERVISOR_MOVABLE_ALLOC_COUNT From 6640db9555aac19bc0115e1144da0516e0fc47c9 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 30 Apr 2021 17:24:36 +0530 Subject: [PATCH 42/66] make authmode settable --- locale/circuitpython.pot | 22 ++++++-------- ports/esp32s2/common-hal/wifi/Network.c | 1 - ports/esp32s2/common-hal/wifi/Radio.c | 28 ++++++++++++++++++ shared-bindings/wifi/AuthMode.h | 3 ++ shared-bindings/wifi/Radio.c | 38 ++++++++++++++----------- shared-bindings/wifi/Radio.h | 12 -------- shared-bindings/wifi/__init__.c | 14 +++++---- 7 files changed, 69 insertions(+), 49 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index ddf1e1aeda..b475bbc4b1 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -350,7 +350,7 @@ msgstr "" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -441,6 +441,10 @@ msgstr "" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "" @@ -1193,6 +1197,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "" @@ -2115,14 +2123,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "" @@ -2352,10 +2352,6 @@ msgid "" "To list built-in modules please do `help(\"modules\")`.\n" msgstr "" -#: shared-bindings/wifi/Radio.c -msgid "WiFi password is not used with OPEN authentication" -msgstr "" - #: shared-bindings/wifi/Radio.c msgid "WiFi password must be between 8 and 63 characters" msgstr "" diff --git a/ports/esp32s2/common-hal/wifi/Network.c b/ports/esp32s2/common-hal/wifi/Network.c index db99f264b6..34cb15d603 100644 --- a/ports/esp32s2/common-hal/wifi/Network.c +++ b/ports/esp32s2/common-hal/wifi/Network.c @@ -26,7 +26,6 @@ #include -#include "py/enum.h" #include "shared-bindings/wifi/Network.h" #include "shared-bindings/wifi/AuthMode.h" diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index 17a7421642..db9c9a36b1 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -35,6 +35,7 @@ #include "py/runtime.h" #include "shared-bindings/ipaddress/IPv4Address.h" #include "shared-bindings/wifi/ScannedNetworks.h" +#include "shared-bindings/wifi/AuthMode.h" #include "shared-module/ipaddress/__init__.h" #include "components/esp_wifi/include/esp_wifi.h" @@ -165,6 +166,33 @@ void common_hal_wifi_radio_stop_station(wifi_radio_obj_t *self) { void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_t ssid_len, uint8_t *password, size_t password_len, uint8_t channel, uint8_t authmode) { set_mode_ap(self, true); + switch (authmode) { + case (1 << AUTHMODE_OPEN): + authmode = WIFI_AUTH_OPEN; + break; + case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_PSK)): + authmode = WIFI_AUTH_WPA_PSK; + break; + case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)): + authmode = WIFI_AUTH_WPA2_PSK; + break; + case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)): + authmode = WIFI_AUTH_WPA_WPA2_PSK; + break; + case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_ENTERPRISE)): + authmode = WIFI_AUTH_WPA2_ENTERPRISE; + break; + case ((1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK)): + authmode = WIFI_AUTH_WPA3_PSK; + break; + case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK)): + authmode = WIFI_AUTH_WPA2_WPA3_PSK; + break; + default: + mp_raise_ValueError(translate("Invalid AuthMode")); + break; + } + wifi_config_t *config = &self->ap_config; memcpy(&config->ap.ssid, ssid, ssid_len); config->ap.ssid[ssid_len] = 0; diff --git a/shared-bindings/wifi/AuthMode.h b/shared-bindings/wifi/AuthMode.h index f7056ea97c..a1016d6c8a 100644 --- a/shared-bindings/wifi/AuthMode.h +++ b/shared-bindings/wifi/AuthMode.h @@ -27,6 +27,8 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H +#include "py/enum.h" + typedef enum { AUTHMODE_OPEN, AUTHMODE_WEP, @@ -38,5 +40,6 @@ typedef enum { } wifi_authmode_t; extern const mp_obj_type_t wifi_authmode_type; +extern const cp_enum_obj_t authmode_OPEN_obj; #endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index 09ed804d6f..aeda4f631e 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -25,6 +25,7 @@ */ #include "shared-bindings/wifi/__init__.h" +#include "shared-bindings/wifi/AuthMode.h" #include #include @@ -190,19 +191,13 @@ STATIC mp_obj_t wifi_radio_stop_station(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); -//| OPEN: int -//| WPA_PSK: int -//| WPA2_PSK: int -//| WPA_WPA2_PSK: int -//| //| def start_ap(self, //| ssid: ReadableBuffer, //| password: ReadableBuffer = b"", //| *, //| channel: Optional[int] = 1, -//| authmode: Optional[int] = WPA_WPA2_PSK) -> None: -//| """Starts an Access Point with the specified ssid and password -//| If an empty. +//| authmode: Optional[AuthMode]) -> None: +//| """Starts an Access Point with the specified ssid and password. //| //| If ``channel`` is given, the access point will use that channel unless //| a station is already operating on a different channel. @@ -217,29 +212,42 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ { MP_QSTR_ssid, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_password, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, - { MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = WIFI_RADIO_AUTH_WPA_WPA2_PSK} }, + { MP_QSTR_authmode, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, }; wifi_radio_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + uint8_t authmode = 0; + if (args[ARG_authmode].u_obj != MP_OBJ_NULL) { + mp_obj_iter_buf_t iter_buf; + mp_obj_t item, iterable = mp_getiter(args[ARG_authmode].u_obj, &iter_buf); + while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + authmode |= (1 << (wifi_authmode_t)cp_enum_value(&wifi_authmode_type, item)); + } + } + mp_buffer_info_t ssid; mp_get_buffer_raise(args[ARG_ssid].u_obj, &ssid, MP_BUFFER_READ); mp_buffer_info_t password; password.len = 0; if (args[ARG_password].u_obj != MP_OBJ_NULL) { + if (authmode == 1) { + mp_raise_ValueError(translate("AuthMode.OPEN is not used with password")); + } else if (authmode == 0) { + authmode = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK); + } mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ); if (password.len > 0 && (password.len < 8 || password.len > 63)) { mp_raise_ValueError(translate("WiFi password must be between 8 and 63 characters")); } - if (args[ARG_authmode].u_int == WIFI_RADIO_AUTH_OPEN) { - mp_raise_ValueError(translate("WiFi password is not used with OPEN authentication")); - } + } else { + authmode = 1; } - common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, args[ARG_authmode].u_int); + common_hal_wifi_radio_start_ap(self, ssid.buf, ssid.len, password.buf, password.len, args[ARG_channel].u_int, authmode); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wifi_radio_start_ap_obj, 1, wifi_radio_start_ap); @@ -503,10 +511,6 @@ STATIC const mp_rom_map_elem_t wifi_radio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_stop_station), MP_ROM_PTR(&wifi_radio_stop_station_obj) }, { MP_ROM_QSTR(MP_QSTR_stop_ap), MP_ROM_PTR(&wifi_radio_stop_ap_obj) }, { MP_ROM_QSTR(MP_QSTR_start_ap), MP_ROM_PTR(&wifi_radio_start_ap_obj) }, - { MP_ROM_QSTR(MP_QSTR_OPEN), MP_ROM_INT(WIFI_RADIO_AUTH_OPEN) }, - { MP_ROM_QSTR(MP_QSTR_WPA_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA_PSK) }, - { MP_ROM_QSTR(MP_QSTR_WPA2_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA2_PSK) }, - { MP_ROM_QSTR(MP_QSTR_WPA_WPA2_PSK), MP_ROM_INT(WIFI_RADIO_AUTH_WPA_WPA2_PSK) }, { MP_ROM_QSTR(MP_QSTR_connect), MP_ROM_PTR(&wifi_radio_connect_obj) }, // { MP_ROM_QSTR(MP_QSTR_connect_to_enterprise), MP_ROM_PTR(&wifi_radio_connect_to_enterprise_obj) }, diff --git a/shared-bindings/wifi/Radio.h b/shared-bindings/wifi/Radio.h index 8848a45cc9..5716d155f4 100644 --- a/shared-bindings/wifi/Radio.h +++ b/shared-bindings/wifi/Radio.h @@ -71,18 +71,6 @@ typedef enum { WIFI_RADIO_ERROR_AP_TSF_RESET = 206, } wifi_radio_error_t; -typedef enum { - WIFI_RADIO_AUTH_OPEN = 0, // OK - WIFI_RADIO_AUTH_WEP, // not supported in SoftAP - WIFI_RADIO_AUTH_WPA_PSK, // OK - WIFI_RADIO_AUTH_WPA2_PSK, // OK - WIFI_RADIO_AUTH_WPA_WPA2_PSK, // OK - WIFI_RADIO_AUTH_WPA2_ENTERPRISE, // not currently supported - WIFI_RADIO_AUTH_WPA3_PSK, // not currently supported - WIFI_RADIO_AUTH_WPA2_WPA3_PSK, // not currently supported - WIFI_RADIO_AUTH_MAX, // not currently supported -} wifi_radio_authmode_t; - extern bool common_hal_wifi_radio_get_enabled(wifi_radio_obj_t *self); extern void common_hal_wifi_radio_set_enabled(wifi_radio_obj_t *self, bool enabled); diff --git a/shared-bindings/wifi/__init__.c b/shared-bindings/wifi/__init__.c index 38bd1bf078..0285b98a07 100644 --- a/shared-bindings/wifi/__init__.c +++ b/shared-bindings/wifi/__init__.c @@ -27,11 +27,12 @@ #include "py/objexcept.h" #include "py/runtime.h" #include "shared-bindings/wifi/__init__.h" +#include "shared-bindings/wifi/AuthMode.h" #include "shared-bindings/wifi/Network.h" #include "shared-bindings/wifi/Radio.h" //| """ -//| The `wifi` module provides necessary low-level functionality for managing wifi +//| The `wifi` module provides necessary low-level functionality for managing //| wifi connections. Use `socketpool` for communicating over the network.""" //| //| radio: Radio @@ -49,15 +50,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(wifi___init___obj, wifi___init__); STATIC const mp_rom_map_elem_t wifi_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) }, - { MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) }, - { MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wifi) }, + { MP_ROM_QSTR(MP_QSTR_Radio), MP_ROM_PTR(&wifi_radio_type) }, + { MP_ROM_QSTR(MP_QSTR_Network), MP_ROM_PTR(&wifi_network_type) }, + { MP_ROM_QSTR(MP_QSTR_AuthMode), MP_ROM_PTR(&wifi_authmode_type) }, // Properties - { MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) }, + { MP_ROM_QSTR(MP_QSTR_radio), MP_ROM_PTR(&common_hal_wifi_radio_obj) }, // Initialization - { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) }, + { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&wifi___init___obj) }, }; From eebcd2eeaf9152aa38ffbc53696ed2ccf08035f6 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Fri, 30 Apr 2021 22:11:32 +0530 Subject: [PATCH 43/66] remove unsupported authmodes --- ports/esp32s2/common-hal/wifi/Radio.c | 9 --------- shared-bindings/wifi/Radio.c | 4 +++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/ports/esp32s2/common-hal/wifi/Radio.c b/ports/esp32s2/common-hal/wifi/Radio.c index db9c9a36b1..9d48ff1257 100644 --- a/ports/esp32s2/common-hal/wifi/Radio.c +++ b/ports/esp32s2/common-hal/wifi/Radio.c @@ -179,15 +179,6 @@ void common_hal_wifi_radio_start_ap(wifi_radio_obj_t *self, uint8_t *ssid, size_ case ((1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK)): authmode = WIFI_AUTH_WPA_WPA2_PSK; break; - case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_ENTERPRISE)): - authmode = WIFI_AUTH_WPA2_ENTERPRISE; - break; - case ((1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK)): - authmode = WIFI_AUTH_WPA3_PSK; - break; - case ((1 << AUTHMODE_WPA2) | (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK)): - authmode = WIFI_AUTH_WPA2_WPA3_PSK; - break; default: mp_raise_ValueError(translate("Invalid AuthMode")); break; diff --git a/shared-bindings/wifi/Radio.c b/shared-bindings/wifi/Radio.c index aeda4f631e..74d0410e61 100644 --- a/shared-bindings/wifi/Radio.c +++ b/shared-bindings/wifi/Radio.c @@ -203,7 +203,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| a station is already operating on a different channel. //| //| If ``authmode`` is given, the access point will use that Authentication -//| mode. If a password is given, ``authmode`` must not be ``OPEN``.""" +//| mode. If a password is given, ``authmode`` must not be ``OPEN``. +//| If ``authmode`` isn't given, ``OPEN`` will be used when password isn't provided, +//| otherwise ``WPA_WPA2_PSK``.""" //| ... //| STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { From 7d3511d06fb46e02690ccc9725450f8483b35dac Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Tue, 4 May 2021 01:43:27 +0200 Subject: [PATCH 44/66] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 48 +++++++++++++--------------- locale/cs.po | 44 ++++++++++++------------- locale/de_DE.po | 59 ++++++++++++++++++---------------- locale/el.po | 44 ++++++++++++------------- locale/en_GB.po | 59 ++++++++++++++++++---------------- locale/es.po | 65 +++++++++++++++++++++---------------- locale/fil.po | 58 ++++++++++++++++++--------------- locale/fr.po | 69 +++++++++++++++++++++++----------------- locale/hi.po | 44 ++++++++++++------------- locale/it_IT.po | 50 +++++++++++++++-------------- locale/ja.po | 53 +++++++++++++++--------------- locale/ko.po | 47 ++++++++++++++------------- locale/nl.po | 59 ++++++++++++++++++---------------- locale/pl.po | 59 ++++++++++++++++++---------------- locale/pt_BR.po | 65 +++++++++++++++++++++---------------- locale/sv.po | 65 +++++++++++++++++++++---------------- locale/zh_Latn_pinyin.po | 59 ++++++++++++++++++---------------- 17 files changed, 504 insertions(+), 443 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index ac07d1544d..6026486edc 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -357,7 +357,7 @@ msgstr "Semua channel event sedang digunakan" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Semua channel event yang disinkronisasi sedang digunakan" @@ -754,6 +754,10 @@ msgid "" msgstr "" "Koneksi telah terputus dan tidak dapat lagi digunakan. Buat koneksi baru." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "File .mpy rusak" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1488,7 +1492,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Nama terlalu panjang" @@ -2156,14 +2160,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Untuk keluar, silahkan reset board tanpa " @@ -2577,10 +2573,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2687,10 +2679,6 @@ msgstr "" msgid "can't load with '%q' index" msgstr "" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -3042,6 +3030,10 @@ msgstr "" msgid "float too big" msgstr "" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "" @@ -3110,7 +3102,7 @@ msgstr "" msgid "generator ignored GeneratorExit" msgstr "" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3130,6 +3122,10 @@ msgstr "identifier didefinisi ulang sebagai global" msgid "identifier redefined as nonlocal" msgstr "identifier didefinisi ulang sebagai nonlocal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3274,10 +3270,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "indeks dupterm tidak valid" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3672,6 +3664,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3891,7 +3887,7 @@ msgid "sampling rate out of range" msgstr "nilai sampling keluar dari jangkauan" #: py/modmicropython.c -msgid "schedule stack full" +msgid "schedule queue full" msgstr "" #: lib/utils/pyexec.c py/builtinimport.c @@ -4309,8 +4305,8 @@ msgstr "zi harus berjenis float" msgid "zi must be of shape (n_section, 2)" msgstr "" -#~ msgid "Corrupt .mpy file" -#~ msgstr "File .mpy rusak" +#~ msgid "invalid dupterm index" +#~ msgstr "indeks dupterm tidak valid" #~ msgid "Corrupt raw code" #~ msgstr "Kode raw rusak" diff --git a/locale/cs.po b/locale/cs.po index 5c1d1d77ba..b7ec951e2f 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -353,7 +353,7 @@ msgstr "" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -737,6 +737,10 @@ msgid "" "connection." msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1469,7 +1473,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "" @@ -2118,14 +2122,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "" @@ -2531,10 +2527,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2641,10 +2633,6 @@ msgstr "" msgid "can't load with '%q' index" msgstr "" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -2996,6 +2984,10 @@ msgstr "" msgid "float too big" msgstr "" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "" @@ -3064,7 +3056,7 @@ msgstr "" msgid "generator ignored GeneratorExit" msgstr "" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3084,6 +3076,10 @@ msgstr "" msgid "identifier redefined as nonlocal" msgstr "" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3228,10 +3224,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3625,6 +3617,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3844,7 +3840,7 @@ msgid "sampling rate out of range" msgstr "" #: py/modmicropython.c -msgid "schedule stack full" +msgid "schedule queue full" msgstr "" #: lib/utils/pyexec.c py/builtinimport.c diff --git a/locale/de_DE.po b/locale/de_DE.po index e71d79d94f..e72d49004d 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -359,7 +359,7 @@ msgstr "Alle event Kanäle werden benutzt" msgid "All state machines in use" msgstr "Alle state machines in verwendung" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Alle sync event Kanäle werden benutzt" @@ -752,6 +752,10 @@ msgstr "" "Die Verbindung wurde getrennt und kann nicht mehr verwendet werden. " "Erstellen Sie eine neue Verbindung." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Beschädigte .mpy Datei" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "Konnte Kamera nicht initialisieren" @@ -1490,7 +1494,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Name zu lang" @@ -2162,14 +2166,6 @@ msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" "Zeitbeschränkung ist zu groß: Maximale Zeitbeschränkung ist %d Sekunden" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Zum beenden, resette bitte das board ohne " @@ -2590,10 +2586,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "Tasten müssen digitalio.DigitalInOut sein" -#: py/vm.c -msgid "byte code not implemented" -msgstr "Bytecode nicht implementiert" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "Byteorder ist kein String" @@ -2702,10 +2694,6 @@ msgstr "Laden von '%q' nicht möglich" msgid "can't load with '%q' index" msgstr "Laden mit '%q' index nicht möglich" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "Ich kann den Wurf nicht an den gerade gestarteten Generator hängen" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -3067,6 +3055,10 @@ msgstr "Das Flip-Argument muss ein Ndarray sein" msgid "float too big" msgstr "float zu groß" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "Die Schriftart (font) muss 2048 Byte lang sein" @@ -3137,7 +3129,7 @@ msgstr "Generator läuft bereits" msgid "generator ignored GeneratorExit" msgstr "Generator ignoriert GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3157,6 +3149,10 @@ msgstr "Bezeichner als global neu definiert" msgid "identifier redefined as nonlocal" msgstr "Bezeichner als nonlocal definiert" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3301,10 +3297,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "ungültiger dupterm index" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3706,6 +3698,10 @@ msgid "only slices with step=1 (aka None) are supported" msgstr "" "Es werden nur Slices mit Schritt = 1 (auch bekannt als None) unterstützt" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3929,8 +3925,8 @@ msgid "sampling rate out of range" msgstr "Abtastrate außerhalb der Reichweite" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "Der schedule stack ist voll" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4352,8 +4348,17 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Beschädigte .mpy Datei" +#~ msgid "byte code not implemented" +#~ msgstr "Bytecode nicht implementiert" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "Ich kann den Wurf nicht an den gerade gestarteten Generator hängen" + +#~ msgid "invalid dupterm index" +#~ msgstr "ungültiger dupterm index" + +#~ msgid "schedule stack full" +#~ msgstr "Der schedule stack ist voll" #~ msgid "Corrupt raw code" #~ msgstr "Beschädigter raw code" diff --git a/locale/el.po b/locale/el.po index de02ad0ca2..8106a86683 100644 --- a/locale/el.po +++ b/locale/el.po @@ -350,7 +350,7 @@ msgstr "" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -734,6 +734,10 @@ msgid "" "connection." msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1466,7 +1470,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "" @@ -2115,14 +2119,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "" @@ -2528,10 +2524,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2638,10 +2630,6 @@ msgstr "" msgid "can't load with '%q' index" msgstr "" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -2993,6 +2981,10 @@ msgstr "" msgid "float too big" msgstr "" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "" @@ -3061,7 +3053,7 @@ msgstr "" msgid "generator ignored GeneratorExit" msgstr "" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3081,6 +3073,10 @@ msgstr "" msgid "identifier redefined as nonlocal" msgstr "" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3225,10 +3221,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3622,6 +3614,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3841,7 +3837,7 @@ msgid "sampling rate out of range" msgstr "" #: py/modmicropython.c -msgid "schedule stack full" +msgid "schedule queue full" msgstr "" #: lib/utils/pyexec.c py/builtinimport.c diff --git a/locale/en_GB.po b/locale/en_GB.po index d8ddf8f91f..e08d5c00ae 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -359,7 +359,7 @@ msgstr "All event channels in use" msgid "All state machines in use" msgstr "All state machines in use" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "All sync event channels in use" @@ -749,6 +749,10 @@ msgstr "" "Connection has been disconnected and can no longer be used. Create a new " "connection." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Corrupt .mpy file" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "Could not initialise camera" @@ -1483,7 +1487,7 @@ msgstr "" msgid "NVS Error" msgstr "NVS Error" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Name too long" @@ -2152,14 +2156,6 @@ msgstr "Time is in the past." msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "Timeout is too long: Maximum timeout length is %d seconds" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "To exit, please reset the board without " @@ -2572,10 +2568,6 @@ msgstr "Buffer too small for requested bytes" msgid "buttons must be digitalio.DigitalInOut" msgstr "Buttons must be digitalio.DigitalInOut" -#: py/vm.c -msgid "byte code not implemented" -msgstr "Byte code not implemented" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "Byteorder is not a string" @@ -2682,10 +2674,6 @@ msgstr "can't load from '%q'" msgid "can't load with '%q' index" msgstr "can't load with '%q' index" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "can't pend throw to just-started generator" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "can't send non-None value to a just-started generator" @@ -3040,6 +3028,10 @@ msgstr "flip argument must be an ndarray" msgid "float too big" msgstr "float too big" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "font must be 2048 bytes long" @@ -3108,7 +3100,7 @@ msgstr "generator already executing" msgid "generator ignored GeneratorExit" msgstr "generator ignored GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3128,6 +3120,10 @@ msgstr "identifier redefined as global" msgid "identifier redefined as nonlocal" msgstr "identifier redefined as nonlocal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3272,10 +3268,6 @@ msgstr "invalid bits_per_pixel %d, must be, 1, 4, 8, 16, 24, or 32" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "invalid dupterm index" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3670,6 +3662,10 @@ msgstr "only sample_rate=16000 is supported" msgid "only slices with step=1 (aka None) are supported" msgstr "only slices with step=1 (aka None) are supported" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3891,8 +3887,8 @@ msgid "sampling rate out of range" msgstr "sampling rate out of range" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "schedule stack full" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4309,8 +4305,17 @@ msgstr "zi must be of float type" msgid "zi must be of shape (n_section, 2)" msgstr "zi must be of shape (n_section, 2)" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Corrupt .mpy file" +#~ msgid "byte code not implemented" +#~ msgstr "Byte code not implemented" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "can't pend throw to just-started generator" + +#~ msgid "invalid dupterm index" +#~ msgstr "invalid dupterm index" + +#~ msgid "schedule stack full" +#~ msgstr "schedule stack full" #~ msgid "Corrupt raw code" #~ msgstr "Corrupt raw code" diff --git a/locale/es.po b/locale/es.po index 61ec78ce0f..f9841bb4f4 100644 --- a/locale/es.po +++ b/locale/es.po @@ -361,7 +361,7 @@ msgstr "Todos los canales de eventos estan siendo usados" msgid "All state machines in use" msgstr "Todas las máquinas de estado en uso" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" "Todos los canales de eventos de sincronización (sync event channels) están " @@ -758,6 +758,10 @@ msgstr "" "La conexión se ha desconectado y ya no se puede usar. Crea una nueva " "conexión." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Archivo .mpy corrupto" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "No se puede inicializar Camera" @@ -1504,7 +1508,7 @@ msgstr "Salto NLR falló. Probablemente corrupción de memoria." msgid "NVS Error" msgstr "Error NVS" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Nombre muy largo" @@ -2181,14 +2185,6 @@ msgstr "" "Tiempo de espera demasiado largo: El tiempo máximo de espera es de %d " "segundos" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "Tiempo de espera agotado esperado por DRDY" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "Tiempo de espera agotado esperando por VSYNC" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Para salir, por favor reinicia la tarjeta sin " @@ -2605,10 +2601,6 @@ msgstr "búfer muy pequeño para los bytes solicitados" msgid "buttons must be digitalio.DigitalInOut" msgstr "los botones necesitan ser digitalio.DigitalInOut" -#: py/vm.c -msgid "byte code not implemented" -msgstr "codigo byte no implementado" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "byteorder no es una cadena" @@ -2715,10 +2707,6 @@ msgstr "no se puede cargar desde '%q'" msgid "can't load with '%q' index" msgstr "no se puede cargar con el índice '%q'" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "no se puede colgar al generador recién iniciado" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -3077,6 +3065,10 @@ msgstr "el argumento invertido debe ser un ndarray" msgid "float too big" msgstr "punto flotante demasiado grande" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "font debe ser 2048 bytes de largo" @@ -3145,7 +3137,7 @@ msgstr "generador ya se esta ejecutando" msgid "generator ignored GeneratorExit" msgstr "generador ignorado GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "el generador genero StopIteration" @@ -3165,6 +3157,10 @@ msgstr "identificador redefinido como global" msgid "identifier redefined as nonlocal" msgstr "identificador redefinido como nonlocal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "archivo .mpy incompatible" @@ -3309,10 +3305,6 @@ msgstr "los bits_per_pixel %d no son validos, deben ser 1, 4, 8, 16, 24 o 32" msgid "invalid decorator" msgstr "decorador invalido" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "index dupterm inválido" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3713,6 +3705,10 @@ msgstr "solo se admite sample_rate=16000" msgid "only slices with step=1 (aka None) are supported" msgstr "solo se admiten segmentos con step=1 (alias None)" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3934,8 +3930,8 @@ msgid "sampling rate out of range" msgstr "frecuencia de muestreo fuera de rango" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "pila de horario llena" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4353,8 +4349,23 @@ msgstr "zi debe ser de tipo flotante" msgid "zi must be of shape (n_section, 2)" msgstr "zi debe ser una forma (n_section,2)" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Archivo .mpy corrupto" +#~ msgid "Timeout waiting for DRDY" +#~ msgstr "Tiempo de espera agotado esperado por DRDY" + +#~ msgid "Timeout waiting for VSYNC" +#~ msgstr "Tiempo de espera agotado esperando por VSYNC" + +#~ msgid "byte code not implemented" +#~ msgstr "codigo byte no implementado" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "no se puede colgar al generador recién iniciado" + +#~ msgid "invalid dupterm index" +#~ msgstr "index dupterm inválido" + +#~ msgid "schedule stack full" +#~ msgstr "pila de horario llena" #~ msgid "Corrupt raw code" #~ msgstr "Código crudo corrupto" diff --git a/locale/fil.po b/locale/fil.po index 511b273934..42862d7501 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -353,7 +353,7 @@ msgstr "Lahat ng event channels ginagamit" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Lahat ng sync event channels ay ginagamit" @@ -742,6 +742,10 @@ msgid "" "connection." msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1481,7 +1485,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "" @@ -2135,14 +2139,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Para lumabas, paki-reset ang board na wala ang " @@ -2557,10 +2553,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: py/vm.c -msgid "byte code not implemented" -msgstr "byte code hindi pa implemented" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2669,10 +2661,6 @@ msgstr "hidi ma i-load galing sa '%q'" msgid "can't load with '%q' index" msgstr "hindi ma i-load gamit ng '%q' na index" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "hindi mapadala ang send throw sa isang kaka umpisang generator" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "hindi mapadala ang non-None value sa isang kaka umpisang generator" @@ -3033,6 +3021,10 @@ msgstr "" msgid "float too big" msgstr "masyadong malaki ang float" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "font ay dapat 2048 bytes ang haba" @@ -3102,7 +3094,7 @@ msgstr "insinasagawa na ng generator" msgid "generator ignored GeneratorExit" msgstr "hindi pinansin ng generator ang GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3122,6 +3114,10 @@ msgstr "identifier ginawang global" msgid "identifier redefined as nonlocal" msgstr "identifier ginawang nonlocal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3266,10 +3262,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "mali ang dupterm index" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3668,6 +3660,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "ang mga slices lamang na may hakbang = 1 (aka None) ang sinusuportahan" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3890,8 +3886,8 @@ msgid "sampling rate out of range" msgstr "pagpili ng rate wala sa sakop" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "puno na ang schedule stack" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4312,6 +4308,18 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "byte code not implemented" +#~ msgstr "byte code hindi pa implemented" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "hindi mapadala ang send throw sa isang kaka umpisang generator" + +#~ msgid "invalid dupterm index" +#~ msgstr "mali ang dupterm index" + +#~ msgid "schedule stack full" +#~ msgstr "puno na ang schedule stack" + #~ msgid "can only save bytecode" #~ msgstr "maaring i-save lamang ang bytecode" diff --git a/locale/fr.po b/locale/fr.po index fee1a85a25..46bbcf7e84 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -361,7 +361,7 @@ msgstr "Tous les canaux d'événements sont utilisés" msgid "All state machines in use" msgstr "Tous les automates finis sont utilisés" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Tout les canaux d'événements sync sont utilisés" @@ -765,6 +765,10 @@ msgstr "" "La connexion a été déconnectée et ne peut plus être utilisée. Créez une " "nouvelle connexion." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Fichier .mpy corrompu" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "Impossible d'initialiser Camera" @@ -1514,7 +1518,7 @@ msgstr "Saut NLR échoué. Corruption de mémoire probable." msgid "NVS Error" msgstr "Erreur NVS" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Nom trop long" @@ -2192,14 +2196,6 @@ msgstr "L'heure est dans le passé." msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "Le délai est trop long : le délai maximal est de %d secondes" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "Délais expiré en attandant DRDY" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "Délais expiré en attandant VSYNC" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Pour quitter, SVP redémarrez la carte sans " @@ -2620,10 +2616,6 @@ msgstr "tampon trop petit pour le nombre d'octets demandé" msgid "buttons must be digitalio.DigitalInOut" msgstr "les boutons doivent être des digitalio.DigitalInOut" -#: py/vm.c -msgid "byte code not implemented" -msgstr "bytecode non implémenté" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "byteorder n'est pas une chaîne" @@ -2731,12 +2723,6 @@ msgstr "impossible de charger depuis '%q'" msgid "can't load with '%q' index" msgstr "impossible de charger avec l'indice '%q'" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" -"on ne peut effectuer une action de type 'pend throw' sur un générateur " -"fraîchement démarré" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -3100,6 +3086,10 @@ msgstr "le paramêtre flip doit être un ndarray" msgid "float too big" msgstr "nombre à virgule flottante trop grand" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "la police doit être longue de 2048 octets" @@ -3168,7 +3158,7 @@ msgstr "générateur déjà en cours d'exécution" msgid "generator ignored GeneratorExit" msgstr "le générateur a ignoré GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "générateur (generator) à surlevé StopIteration" @@ -3188,6 +3178,10 @@ msgstr "identifiant redéfini comme global" msgid "identifier redefined as nonlocal" msgstr "identifiant redéfini comme nonlocal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "Fichier .mpy incompatible" @@ -3333,10 +3327,6 @@ msgstr "bits_per_pixel %d est invalid, doit être 1, 4, 8, 16, 24 ou 32" msgid "invalid decorator" msgstr "décorateur invalide" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "index invalide pour dupterm" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3736,6 +3726,10 @@ msgstr "seul sample_rate = 16000 est pris en charge" msgid "only slices with step=1 (aka None) are supported" msgstr "seules les tranches avec 'step=1' (cad None) sont supportées" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3960,8 +3954,8 @@ msgid "sampling rate out of range" msgstr "taux d'échantillonage hors bornes" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "pile de planification pleine" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4379,8 +4373,25 @@ msgstr "zi doit être de type float" msgid "zi must be of shape (n_section, 2)" msgstr "zi doit être de forme (n_section, 2)" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Fichier .mpy corrompu" +#~ msgid "Timeout waiting for DRDY" +#~ msgstr "Délais expiré en attandant DRDY" + +#~ msgid "Timeout waiting for VSYNC" +#~ msgstr "Délais expiré en attandant VSYNC" + +#~ msgid "byte code not implemented" +#~ msgstr "bytecode non implémenté" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "" +#~ "on ne peut effectuer une action de type 'pend throw' sur un générateur " +#~ "fraîchement démarré" + +#~ msgid "invalid dupterm index" +#~ msgstr "index invalide pour dupterm" + +#~ msgid "schedule stack full" +#~ msgstr "pile de planification pleine" #~ msgid "Corrupt raw code" #~ msgstr "Code brut corrompu" diff --git a/locale/hi.po b/locale/hi.po index 4a4539ba2c..5e55b35421 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -350,7 +350,7 @@ msgstr "" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -734,6 +734,10 @@ msgid "" "connection." msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1466,7 +1470,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "" @@ -2115,14 +2119,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "" @@ -2528,10 +2524,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2638,10 +2630,6 @@ msgstr "" msgid "can't load with '%q' index" msgstr "" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -2993,6 +2981,10 @@ msgstr "" msgid "float too big" msgstr "" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "" @@ -3061,7 +3053,7 @@ msgstr "" msgid "generator ignored GeneratorExit" msgstr "" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3081,6 +3073,10 @@ msgstr "" msgid "identifier redefined as nonlocal" msgstr "" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3225,10 +3221,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3622,6 +3614,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3841,7 +3837,7 @@ msgid "sampling rate out of range" msgstr "" #: py/modmicropython.c -msgid "schedule stack full" +msgid "schedule queue full" msgstr "" #: lib/utils/pyexec.c py/builtinimport.c diff --git a/locale/it_IT.po b/locale/it_IT.po index f641552686..5feca60282 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -362,7 +362,7 @@ msgstr "Tutti i canali eventi utilizati" msgid "All state machines in use" msgstr "Tutte le state machines sono in uso" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Tutti i canali di eventi sincronizzati in uso" @@ -752,6 +752,10 @@ msgid "" "connection." msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1494,7 +1498,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "" @@ -2156,14 +2160,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Per uscire resettare la scheda senza " @@ -2574,10 +2570,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: py/vm.c -msgid "byte code not implemented" -msgstr "byte code non implementato" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2685,10 +2677,6 @@ msgstr "impossibile caricare da '%q'" msgid "can't load with '%q' index" msgstr "impossibile caricare con indice '%q'" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -3046,6 +3034,10 @@ msgstr "" msgid "float too big" msgstr "float troppo grande" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "il font deve essere lungo 2048 byte" @@ -3115,7 +3107,7 @@ msgstr "" msgid "generator ignored GeneratorExit" msgstr "" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3135,6 +3127,10 @@ msgstr "identificatore ridefinito come globale" msgid "identifier redefined as nonlocal" msgstr "identificatore ridefinito come nonlocal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3279,10 +3275,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "indice dupterm non valido" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3685,6 +3677,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "solo slice con step=1 (aka None) sono supportate" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3909,7 +3905,7 @@ msgid "sampling rate out of range" msgstr "frequenza di campionamento fuori intervallo" #: py/modmicropython.c -msgid "schedule stack full" +msgid "schedule queue full" msgstr "" #: lib/utils/pyexec.c py/builtinimport.c @@ -4331,6 +4327,12 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "byte code not implemented" +#~ msgstr "byte code non implementato" + +#~ msgid "invalid dupterm index" +#~ msgstr "indice dupterm non valido" + #~ msgid "can only save bytecode" #~ msgstr "È possibile salvare solo bytecode" diff --git a/locale/ja.po b/locale/ja.po index c057a9d8a7..f7fbaacf08 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -355,7 +355,7 @@ msgstr "全てのイベントチャネルが使用中" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "全ての同期イベントチャネルが使用中" @@ -745,6 +745,10 @@ msgid "" "connection." msgstr "接続は切断済みでもう使えません。新しい接続を作成してください" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "破損した .mpy ファイル" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "カメラを初期化できません" @@ -1479,7 +1483,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "名前が長すぎます" @@ -2137,14 +2141,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "タイムアウトが長すぎです。最大のタイムアウト長は%d秒" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "" @@ -2551,10 +2547,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "buttonsはdigitalio.DigitalInOutでなければなりません" -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "byteorderが文字列ではありません" @@ -2661,10 +2653,6 @@ msgstr "" msgid "can't load with '%q' index" msgstr "" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -3020,6 +3008,10 @@ msgstr "flipの引数はndarrayでなければなりません" msgid "float too big" msgstr "floatの値が大きすぎます" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "fontは2048バイト長でなければなりません" @@ -3088,7 +3080,7 @@ msgstr "" msgid "generator ignored GeneratorExit" msgstr "" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3108,6 +3100,10 @@ msgstr "" msgid "identifier redefined as nonlocal" msgstr "" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3253,10 +3249,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "不正なduptermインデクス" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3650,6 +3642,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3872,8 +3868,8 @@ msgid "sampling rate out of range" msgstr "サンプリングレートが範囲外" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "スケジュールスタックが一杯" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4290,8 +4286,11 @@ msgstr "ziはfloat値でなければなりません" msgid "zi must be of shape (n_section, 2)" msgstr "" -#~ msgid "Corrupt .mpy file" -#~ msgstr "破損した .mpy ファイル" +#~ msgid "invalid dupterm index" +#~ msgstr "不正なduptermインデクス" + +#~ msgid "schedule stack full" +#~ msgstr "スケジュールスタックが一杯" #~ msgid "Corrupt raw code" #~ msgstr "破損したraw code" diff --git a/locale/ko.po b/locale/ko.po index 5add85aed8..b9293d00e0 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -351,7 +351,7 @@ msgstr "" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "" @@ -737,6 +737,10 @@ msgid "" "connection." msgstr "" +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1469,7 +1473,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "" @@ -2118,14 +2122,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "" @@ -2532,10 +2528,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "" -#: py/vm.c -msgid "byte code not implemented" -msgstr "" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2642,10 +2634,6 @@ msgstr "" msgid "can't load with '%q' index" msgstr "" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -2997,6 +2985,10 @@ msgstr "" msgid "float too big" msgstr "float이 너무 큽니다" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "" @@ -3065,7 +3057,7 @@ msgstr "" msgid "generator ignored GeneratorExit" msgstr "" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3085,6 +3077,10 @@ msgstr "" msgid "identifier redefined as nonlocal" msgstr "" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3229,10 +3225,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "Dupterm index가 유효하지 않습니다" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3626,6 +3618,10 @@ msgstr "" msgid "only slices with step=1 (aka None) are supported" msgstr "" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3845,7 +3841,7 @@ msgid "sampling rate out of range" msgstr "" #: py/modmicropython.c -msgid "schedule stack full" +msgid "schedule queue full" msgstr "" #: lib/utils/pyexec.c py/builtinimport.c @@ -4263,6 +4259,9 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "invalid dupterm index" +#~ msgstr "Dupterm index가 유효하지 않습니다" + #~ msgid "invalid cert" #~ msgstr "cert가 유효하지 않습니다" diff --git a/locale/nl.po b/locale/nl.po index 3a450d2112..48861d929c 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -353,7 +353,7 @@ msgstr "Alle event kanalen zijn in gebruik" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Alle sync event kanalen zijn in gebruik" @@ -745,6 +745,10 @@ msgstr "" "Verbinding is verbroken en kan niet langer gebruikt worden. Creëer een " "nieuwe verbinding." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Corrupt .mpy bestand" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "Kon camera niet initialiseren" @@ -1480,7 +1484,7 @@ msgstr "" msgid "NVS Error" msgstr "NVS-fout" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Naam te lang" @@ -2155,14 +2159,6 @@ msgstr "Tijdstip ligt in het verleden." msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "Time-out is te lang. Maximale time-out lengte is %d seconden" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Om te beëindigen, reset het bord zonder " @@ -2579,10 +2575,6 @@ msgstr "buffer te klein voor gevraagde bytes" msgid "buttons must be digitalio.DigitalInOut" msgstr "buttons moeten digitalio.DigitalInOut zijn" -#: py/vm.c -msgid "byte code not implemented" -msgstr "byte code niet geïmplementeerd" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "byteorder is geen string" @@ -2690,10 +2682,6 @@ msgstr "kan niet laden van '%q'" msgid "can't load with '%q' index" msgstr "kan niet met '%q' index laden" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "kan throw niet aan net gestartte generator toevoegen" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "kan geen niet-'None' waarde naar een net gestartte generator sturen" @@ -3048,6 +3036,10 @@ msgstr "flip argumenten moeten een ndarray zijn" msgid "float too big" msgstr "float is te groot" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "lettertype moet 2048 bytes lang zijn" @@ -3117,7 +3109,7 @@ msgstr "generator wordt al uitgevoerd" msgid "generator ignored GeneratorExit" msgstr "generator negeerde GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3137,6 +3129,10 @@ msgstr "identifier is opnieuw gedefinieerd als global" msgid "identifier redefined as nonlocal" msgstr "identifier is opnieuw gedefinieerd als nonlocal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3281,10 +3277,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "ongeldige dupterm index" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3681,6 +3673,10 @@ msgstr "alleen sample_rate=16000 wordt ondersteund" msgid "only slices with step=1 (aka None) are supported" msgstr "alleen segmenten met step=1 (ook wel None) worden ondersteund" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3903,8 +3899,8 @@ msgid "sampling rate out of range" msgstr "bemonsteringssnelheid buiten bereik" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "schedule stack is vol" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4321,8 +4317,17 @@ msgstr "zi moet van type float zijn" msgid "zi must be of shape (n_section, 2)" msgstr "zi moet vorm (n_section, 2) hebben" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Corrupt .mpy bestand" +#~ msgid "byte code not implemented" +#~ msgstr "byte code niet geïmplementeerd" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "kan throw niet aan net gestartte generator toevoegen" + +#~ msgid "invalid dupterm index" +#~ msgstr "ongeldige dupterm index" + +#~ msgid "schedule stack full" +#~ msgstr "schedule stack is vol" #~ msgid "Corrupt raw code" #~ msgstr "Corrupt raw code" diff --git a/locale/pl.po b/locale/pl.po index 1062baf66a..c11d260b1e 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -355,7 +355,7 @@ msgstr "Wszystkie kanały zdarzeń w użyciu" msgid "All state machines in use" msgstr "" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Wszystkie kanały zdarzeń synchronizacji w użyciu" @@ -745,6 +745,10 @@ msgstr "" "Połączenie zostało rozłączone i nie można go już używać. Utwórz nowe " "połączenie." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Uszkodzony plik .mpy" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "" @@ -1479,7 +1483,7 @@ msgstr "" msgid "NVS Error" msgstr "" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Za długa nazwa" @@ -2128,14 +2132,6 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "By wyjść, proszę zresetować płytkę bez " @@ -2547,10 +2543,6 @@ msgstr "" msgid "buttons must be digitalio.DigitalInOut" msgstr "buttons musi być digitalio.DigitalInOut" -#: py/vm.c -msgid "byte code not implemented" -msgstr "bajtkod niezaimplemntowany" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "" @@ -2657,10 +2649,6 @@ msgstr "nie można ładować z '%q'" msgid "can't load with '%q' index" msgstr "nie można ładować z indeksem '%q'" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "nie można skoczyć do świeżo stworzonego generatora" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "świeżo stworzony generator może tylko przyjąć None" @@ -3013,6 +3001,10 @@ msgstr "" msgid "float too big" msgstr "float zbyt wielki" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "font musi mieć 2048 bajtów długości" @@ -3081,7 +3073,7 @@ msgstr "generator już się wykonuje" msgid "generator ignored GeneratorExit" msgstr "generator zignorował GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3101,6 +3093,10 @@ msgstr "nazwa przedefiniowana jako globalna" msgid "identifier redefined as nonlocal" msgstr "nazwa przedefiniowana jako nielokalna" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3245,10 +3241,6 @@ msgstr "" msgid "invalid decorator" msgstr "" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "zły indeks dupterm" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3642,6 +3634,10 @@ msgstr "obsługiwane jest tylko sample_rate=16000" msgid "only slices with step=1 (aka None) are supported" msgstr "tylko fragmenty ze step=1 (lub None) są wspierane" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3863,8 +3859,8 @@ msgid "sampling rate out of range" msgstr "częstotliwość próbkowania poza zakresem" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "stos planu pełen" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4281,8 +4277,17 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Uszkodzony plik .mpy" +#~ msgid "byte code not implemented" +#~ msgstr "bajtkod niezaimplemntowany" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "nie można skoczyć do świeżo stworzonego generatora" + +#~ msgid "invalid dupterm index" +#~ msgstr "zły indeks dupterm" + +#~ msgid "schedule stack full" +#~ msgstr "stos planu pełen" #~ msgid "can only save bytecode" #~ msgstr "można zapisać tylko bytecode" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index afde2984c1..03110715fc 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -363,7 +363,7 @@ msgstr "Todos os canais de eventos em uso" msgid "All state machines in use" msgstr "O estado de todas as máquinas em uso" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Todos os canais dos eventos de sincronização em uso" @@ -762,6 +762,10 @@ msgid "" msgstr "" "A conexão foi desconectada e não pode mais ser usada. Crie uma nova conexão." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Arquivo .mpy corrompido" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "Não foi possível inicializar a Câmera" @@ -1503,7 +1507,7 @@ msgstr "O salto NLR falhou. Possível corrupção da memória." msgid "NVS Error" msgstr "Erro NVS" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Nome muito longo" @@ -2187,14 +2191,6 @@ msgstr "" "O tempo limite é long demais: O comprimento máximo do tempo limite é de %d " "segundos" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "Esgotou-se o tempo limite de espera pelo DRDY" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "Esgotou-se o tempo de espera pelo VSYNC" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Para sair, por favor, reinicie a placa sem " @@ -2612,10 +2608,6 @@ msgstr "o buffer é pequeno demais para os bytes requisitados" msgid "buttons must be digitalio.DigitalInOut" msgstr "os botões devem ser digitalio.DigitalInOut" -#: py/vm.c -msgid "byte code not implemented" -msgstr "o código dos bytes ainda não foi implementado" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "a ordem dos bytes não é uma cadeia de caracteres" @@ -2722,10 +2714,6 @@ msgstr "não é possível carregar a partir de '%q'" msgid "can't load with '%q' index" msgstr "não é possível carregar com o índice '%q'" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "não pode pendurar o lançamento para o gerador recém-iniciado" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "" @@ -3086,6 +3074,10 @@ msgstr "o argumento flip deve ser um ndarray" msgid "float too big" msgstr "float muito grande" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "a fonte deve ter 2048 bytes de comprimento" @@ -3154,7 +3146,7 @@ msgstr "o gerador já está em execução" msgid "generator ignored GeneratorExit" msgstr "ignorando o gerador GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "gerador StopIteration elevado" @@ -3174,6 +3166,10 @@ msgstr "o identificador foi redefinido como global" msgid "identifier redefined as nonlocal" msgstr "o identificador foi redefinido como não-local" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "arquivo .mpy incompatível" @@ -3319,10 +3315,6 @@ msgstr "bits_per_pixel %d é inválido, deve ser, 1, 4, 8, 16, 24, ou 32" msgid "invalid decorator" msgstr "decorador inválido" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "Índice de dupterm inválido" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3722,6 +3714,10 @@ msgid "only slices with step=1 (aka None) are supported" msgstr "" "apenas fatias com a etapa=1 (também conhecida como Nenhuma) são compatíveis" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3947,8 +3943,8 @@ msgid "sampling rate out of range" msgstr "Taxa de amostragem fora do intervalo" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "agende a pilha de função completa" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4365,8 +4361,23 @@ msgstr "zi deve ser de um tipo float" msgid "zi must be of shape (n_section, 2)" msgstr "zi deve estar na forma (n_section, 2)" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Arquivo .mpy corrompido" +#~ msgid "Timeout waiting for DRDY" +#~ msgstr "Esgotou-se o tempo limite de espera pelo DRDY" + +#~ msgid "Timeout waiting for VSYNC" +#~ msgstr "Esgotou-se o tempo de espera pelo VSYNC" + +#~ msgid "byte code not implemented" +#~ msgstr "o código dos bytes ainda não foi implementado" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "não pode pendurar o lançamento para o gerador recém-iniciado" + +#~ msgid "invalid dupterm index" +#~ msgstr "Índice de dupterm inválido" + +#~ msgid "schedule stack full" +#~ msgstr "agende a pilha de função completa" #~ msgid "Corrupt raw code" #~ msgstr "Código bruto corrompido" diff --git a/locale/sv.po b/locale/sv.po index 0423871517..5797bd2c69 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -358,7 +358,7 @@ msgstr "Alla händelsekanaler används" msgid "All state machines in use" msgstr "Alla tillståndsmaskiner används" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Alla händelsekanaler används" @@ -751,6 +751,10 @@ msgstr "" "Anslutningen har kopplats bort och kan inte längre användas. Skapa en ny " "anslutning." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Skadad .mpy-fil" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "Kunde inte initiera Camera" @@ -1488,7 +1492,7 @@ msgstr "NLR jump misslyckades. Troligen korrupt minne." msgid "NVS Error" msgstr "NVS-fel" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Name är för långt" @@ -2161,14 +2165,6 @@ msgstr "Tid har passerats." msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "Åtgärden tog för lång tid: Max väntetid är %d sekunder" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "Timeout i väntan på DRDY" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "Timeout i väntan på VSYNC" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "För att avsluta, gör reset på kortet utan " @@ -2582,10 +2578,6 @@ msgstr "buffert för liten för begärd längd" msgid "buttons must be digitalio.DigitalInOut" msgstr "buttons måste vara digitalio.DigitalInOut" -#: py/vm.c -msgid "byte code not implemented" -msgstr "byte-kod inte implementerad" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "byteorder är inte en sträng" @@ -2692,10 +2684,6 @@ msgstr "kan inte ladda från '%q'" msgid "can't load with '%q' index" msgstr "kan inte ladda med '%q' index" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "kan inte 'pend throw' för nystartad generator" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "kan inte skicka icke-None värde till nystartad generator" @@ -3052,6 +3040,10 @@ msgstr "Argumentet flip måste vara en ndarray" msgid "float too big" msgstr "flyttalet för stort" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "typsnitt måste vara 2048 bytes långt" @@ -3120,7 +3112,7 @@ msgstr "generatorn kör redan" msgid "generator ignored GeneratorExit" msgstr "generatorn ignorerade GeneratorExit" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "generator kastade StopIteration" @@ -3140,6 +3132,10 @@ msgstr "identifieraren omdefinierad till global" msgid "identifier redefined as nonlocal" msgstr "identifieraren omdefinierad som icke-lokal" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "inkompatibel .mpy-fil" @@ -3284,10 +3280,6 @@ msgstr "ogiltig bits_per_pixel %d, måste vara 1, 4, 8, 16, 24 eller 32" msgid "invalid decorator" msgstr "ogiltig dekorator" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "ogiltigt dupterm index" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3684,6 +3676,10 @@ msgstr "enbart sample_rate=16000 stöds" msgid "only slices with step=1 (aka None) are supported" msgstr "endast segment med steg=1 (aka Ingen) stöds" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3906,8 +3902,8 @@ msgid "sampling rate out of range" msgstr "samplingsfrekvens utanför räckvidden" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "schemastack full" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4324,8 +4320,23 @@ msgstr "zi måste vara av typ float" msgid "zi must be of shape (n_section, 2)" msgstr "zi måste vara i formen (n_section, 2)" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Skadad .mpy-fil" +#~ msgid "Timeout waiting for DRDY" +#~ msgstr "Timeout i väntan på DRDY" + +#~ msgid "Timeout waiting for VSYNC" +#~ msgstr "Timeout i väntan på VSYNC" + +#~ msgid "byte code not implemented" +#~ msgstr "byte-kod inte implementerad" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "kan inte 'pend throw' för nystartad generator" + +#~ msgid "invalid dupterm index" +#~ msgstr "ogiltigt dupterm index" + +#~ msgid "schedule stack full" +#~ msgstr "schemastack full" #~ msgid "Corrupt raw code" #~ msgstr "Korrupt rå kod" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 7c7db58dcd..a48d20c912 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -360,7 +360,7 @@ msgstr "Suǒyǒu shǐyòng de shìjiàn píndào" msgid "All state machines in use" msgstr "suǒ yǒu zhèng zài shǐ yòng de zhuàng tài jī" -#: ports/atmel-samd/audio_dma.c ports/atmel-samd/common-hal/audiobusio/PDMIn.c +#: ports/atmel-samd/audio_dma.c msgid "All sync event channels in use" msgstr "Suǒyǒu tóngbù shìjiàn píndào shǐyòng" @@ -750,6 +750,10 @@ msgid "" "connection." msgstr "Liánjiē yǐ duàn kāi, wúfǎ zài shǐyòng. Chuàngjiàn yīgè xīn de liánjiē." +#: py/persistentcode.c +msgid "Corrupt .mpy file" +msgstr "Fǔbài de .mpy wénjiàn" + #: ports/cxd56/common-hal/camera/Camera.c msgid "Could not initialize Camera" msgstr "Wúfǎ chūshǐhuà xiàngjī" @@ -1490,7 +1494,7 @@ msgstr "NLR tiào zhuǎn shī bài. kě néng shì nèi cún sǔn huài." msgid "NVS Error" msgstr "NVS cuò wù" -#: py/parse.c +#: py/qstr.c msgid "Name too long" msgstr "Míngchēng tài zhǎng" @@ -2158,14 +2162,6 @@ msgstr "shí jiān yǐ jīng guò qù." msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "Chāoshí shíjiān tài zhǎng: Zuìdà chāoshí shíjiān wèi%d miǎo" -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for DRDY" -msgstr "" - -#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c -msgid "Timeout waiting for VSYNC" -msgstr "" - #: supervisor/shared/safe_mode.c msgid "To exit, please reset the board without " msgstr "Yào tuìchū, qǐng chóng zhì bǎnkuài ér bùyòng " @@ -2580,10 +2576,6 @@ msgstr "huǎn chōng qū tài xiǎo, duì yú qǐng qiú de zì jié" msgid "buttons must be digitalio.DigitalInOut" msgstr "ànniǔ bìxū shì digitalio.DigitalInOut" -#: py/vm.c -msgid "byte code not implemented" -msgstr "zì jié dàimǎ wèi zhíxíng" - #: shared-bindings/_pixelbuf/PixelBuf.c msgid "byteorder is not a string" msgstr "byteorder bùshì zìfú chuàn" @@ -2690,10 +2682,6 @@ msgstr "wúfǎ cóng '%q' jiāzài" msgid "can't load with '%q' index" msgstr "wúfǎ yòng '%q' ' suǒyǐn jiāzài" -#: py/objgenerator.c -msgid "can't pend throw to just-started generator" -msgstr "bùnéng bǎ tā rēng dào gāng qǐdòng de fā diànjī shàng" - #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" msgstr "wúfǎ xiàng gānggāng qǐdòng de shēngchéng qì fāsòng fēi zhí" @@ -3051,6 +3039,10 @@ msgstr "fānzhuǎn shēn shù bìxū shì ndarray" msgid "float too big" msgstr "fú diǎn tài dà" +#: py/nativeglue.c +msgid "float unsupported" +msgstr "" + #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" msgstr "zìtǐ bìxū wèi 2048 zì jié" @@ -3119,7 +3111,7 @@ msgstr "shēngchéng qì yǐjīng zhíxíng" msgid "generator ignored GeneratorExit" msgstr "shēngchéng qì hūlüè shēngchéng qì tuìchū" -#: py/objgenerator.c +#: py/objgenerator.c py/runtime.c msgid "generator raised StopIteration" msgstr "" @@ -3139,6 +3131,10 @@ msgstr "biāozhì fú chóngxīn dìngyì wèi quánjú" msgid "identifier redefined as nonlocal" msgstr "biāozhì fú chóngxīn dìngyì wéi fēi běndì" +#: py/compile.c +msgid "import * not at module level" +msgstr "" + #: py/persistentcode.c msgid "incompatible .mpy file" msgstr "" @@ -3283,10 +3279,6 @@ msgstr "wú xiào bits_per_pixel %d, bì xū shì, 1, 4, 8, 16, 24, huò 32" msgid "invalid decorator" msgstr "wú xiào zhuāng shì" -#: extmod/uos_dupterm.c -msgid "invalid dupterm index" -msgstr "dupterm suǒyǐn wúxiào" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid element size %d for bits_per_pixel %d\n" @@ -3681,6 +3673,10 @@ msgstr "Jǐn zhīchí cǎiyàng lǜ = 16000" msgid "only slices with step=1 (aka None) are supported" msgstr "jǐn zhīchí bù zhǎng = 1(jí wú) de qiēpiàn" +#: py/vm.c +msgid "opcode" +msgstr "" + #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c msgid "operands could not be broadcast together" @@ -3902,8 +3898,8 @@ msgid "sampling rate out of range" msgstr "qǔyàng lǜ chāochū fànwéi" #: py/modmicropython.c -msgid "schedule stack full" -msgstr "jìhuà duīzhàn yǐ mǎn" +msgid "schedule queue full" +msgstr "" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" @@ -4320,8 +4316,17 @@ msgstr "zi bìxū wèi fú diǎn xíng" msgid "zi must be of shape (n_section, 2)" msgstr "zi bìxū jùyǒu xíngzhuàng (n_section,2)" -#~ msgid "Corrupt .mpy file" -#~ msgstr "Fǔbài de .mpy wénjiàn" +#~ msgid "byte code not implemented" +#~ msgstr "zì jié dàimǎ wèi zhíxíng" + +#~ msgid "can't pend throw to just-started generator" +#~ msgstr "bùnéng bǎ tā rēng dào gāng qǐdòng de fā diànjī shàng" + +#~ msgid "invalid dupterm index" +#~ msgstr "dupterm suǒyǐn wúxiào" + +#~ msgid "schedule stack full" +#~ msgstr "jìhuà duīzhàn yǐ mǎn" #~ msgid "Corrupt raw code" #~ msgstr "Sǔnhuài de yuánshǐ dàimǎ" From 5b5de4b92e55cfaa56aaf411735da9ac8b8c2e08 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 3 May 2021 20:53:31 -0400 Subject: [PATCH 45/66] fix sHID report doc and API --- shared-bindings/usb_hid/Device.c | 37 +++++++++++++++----------------- shared-module/usb_hid/__init__.c | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 2f279e8f16..5e759ab92d 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -39,7 +39,7 @@ //| mouse.send_report()""" //| -//| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: Optional[int], report_id_index: Optional[int]) -> None: +//| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: int = 0, report_id_index: Optional[int]) -> None: //| """Create a description of a USB HID device. To create an actual device, //| pass a `Device` to `usb_hid.configure_usb()`. //| @@ -50,7 +50,7 @@ //| :param int in_report_length: Size in bytes of the HID report sent to the host. //| "In" is with respect to the host. //| :param int out_report_length: Size in bytes of the HID report received from the host. -//| "Out" is with respect to the host. If no reports are expected, use ``None``. +//| "Out" is with respect to the host. If no reports are expected, use 0. //| :param int report_id_index: position of byte in descriptor that contains the Report ID. //| A Report ID will be assigned when the device is created. If there is no //| Report ID, use ``None``. @@ -66,8 +66,8 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args { MP_QSTR_usage_page, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_usage, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, { MP_QSTR_in_report_length, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, - { MP_QSTR_out_report_length, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } }, - { MP_QSTR_report_id_index, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none } }, + { MP_QSTR_out_report_length, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_int = 0 } }, + { MP_QSTR_report_id_index, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = mp_const_none } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -95,27 +95,24 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args } const uint8_t in_report_length = in_report_length_arg; - const mp_obj_t out_report_length_arg = args[ARG_out_report_length].u_obj; - if (out_report_length_arg == mp_const_none) { - self->out_report_length = 0; - } else if (!mp_obj_is_small_int(out_report_length_arg) || - MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) <= 0 || - MP_OBJ_SMALL_INT_VALUE(out_report_length_arg) > 255) { - mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_out_report_length); + const mp_int_t out_report_length_arg = args[ARG_out_report_length].u_int; + if (out_report_length_arg <= 0 || out_report_length_arg > 255) { + mp_raise_ValueError_varg(translate("%q must be 1-255"), MP_QSTR_out_report_length); } - uint8_t out_report_length = MP_OBJ_SMALL_INT_VALUE(out_report_length_arg); + const uint8_t out_report_length = out_report_length_arg; const mp_obj_t report_id_index_arg = args[ARG_report_id_index].u_obj; - if (report_id_index_arg == mp_const_none) { - self->report_id_index = 0; - } else if (!mp_obj_is_small_int(report_id_index_arg) || - MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) <= 0 || - MP_OBJ_SMALL_INT_VALUE(report_id_index_arg) > 255) { - mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_report_id_index); + uint8_t report_id_index = 0; + if (report_id_index_arg != mp_const_none) { + const mp_int_t report_id_index_int = mp_obj_int_get_checked(report_id_index_arg); + if (report_id_index_int <= 0 || report_id_index_int > 255) { + mp_raise_ValueError_varg(translate("%q must be None or 1-255"), MP_QSTR_report_id_index); + } + report_id_index = report_id_index_int; } - uint8_t report_id_index = MP_OBJ_SMALL_INT_VALUE(report_id_index_arg); - common_hal_usb_hid_device_construct(self, descriptor, usage_page, usage, in_report_length, out_report_length, report_id_index); + common_hal_usb_hid_device_construct( + self, descriptor, usage_page, usage, in_report_length, out_report_length, report_id_index); return (mp_obj_t)self; } diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 831c961955..4c97f8d07e 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -204,7 +204,7 @@ void usb_hid_build_report_descriptor(uint8_t *report_descriptor_space, size_t re usb_hid_device_obj_t *device = &hid_devices[i]; // Copy the report descriptor for this device. if (hid_devices_num == 1) { - // Theres only one device, so it shouldn't have a report ID. + // There's only one device, so it shouldn't have a report ID. // Copy the descriptor, but splice out the report id indicator and value (2 bytes). memcpy(report_descriptor_start, device->report_descriptor, device->report_id_index - 1); report_descriptor_start += device->report_id_index - 1; From 3e2236be8eb7a54eb93c0394035f2851a74afbec Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 3 May 2021 20:59:50 -0400 Subject: [PATCH 46/66] missed an uncrustify --- supervisor/shared/usb/usb_desc.c | 50 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 4d6ea401b7..f8b094591d 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -115,8 +115,8 @@ static const uint8_t configuration_descriptor_template[] = { static void usb_build_device_descriptor(uint16_t vid, uint16_t pid) { device_descriptor_allocation = allocate_memory(align32_size(sizeof(device_descriptor_template)), - /*high_address*/ false, /*movable*/ false); - uint8_t *device_descriptor = (uint8_t *) device_descriptor_allocation->ptr; + /*high_address*/ false, /*movable*/ false); + uint8_t *device_descriptor = (uint8_t *)device_descriptor_allocation->ptr; memcpy(device_descriptor, device_descriptor_template, sizeof(device_descriptor_template)); device_descriptor[DEVICE_VID_LO_INDEX] = vid & 0xFF; @@ -142,38 +142,38 @@ static void usb_build_configuration_descriptor(void) { // CDC should be first, for compatibility with Adafruit Windows 7 drivers. // In the past, the order has been CDC, MSC, MIDI, HID, so preserve that order. -#if CIRCUITPY_USB_CDC + #if CIRCUITPY_USB_CDC if (usb_cdc_repl_enabled()) { total_descriptor_length += usb_cdc_descriptor_length(); } if (usb_cdc_data_enabled()) { total_descriptor_length += usb_cdc_descriptor_length(); } -#endif + #endif -#if CIRCUITPY_USB_MSC + #if CIRCUITPY_USB_MSC if (storage_usb_enabled()) { total_descriptor_length += storage_usb_descriptor_length(); } -#endif + #endif -#if CIRCUITPY_USB_HID + #if CIRCUITPY_USB_HID if (usb_hid_enabled()) { total_descriptor_length += usb_hid_descriptor_length(); } -#endif + #endif -#if CIRCUITPY_USB_MIDI + #if CIRCUITPY_USB_MIDI if (usb_midi_enabled()) { total_descriptor_length += usb_midi_descriptor_length(); } -#endif + #endif // Now we now how big the configuration descriptor will be, so we can allocate space for it. configuration_descriptor_allocation = allocate_memory(align32_size(total_descriptor_length), - /*high_address*/ false, /*movable*/ false); - uint8_t *configuration_descriptor = (uint8_t *) configuration_descriptor_allocation->ptr; + /*high_address*/ false, /*movable*/ false); + uint8_t *configuration_descriptor = (uint8_t *)configuration_descriptor_allocation->ptr; // Copy the template, which is the first part of the descriptor, and fix up its length. @@ -189,7 +189,7 @@ static void usb_build_configuration_descriptor(void) { uint8_t *descriptor_buf_remaining = configuration_descriptor + sizeof(configuration_descriptor_template); -#if CIRCUITPY_USB_CDC + #if CIRCUITPY_USB_CDC if (usb_cdc_repl_enabled()) { // Concatenate and fix up the CDC REPL descriptor. descriptor_buf_remaining += usb_cdc_add_descriptor( @@ -200,31 +200,31 @@ static void usb_build_configuration_descriptor(void) { descriptor_buf_remaining += usb_cdc_add_descriptor( descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string, false); } -#endif + #endif -#if CIRCUITPY_USB_MSC + #if CIRCUITPY_USB_MSC if (storage_usb_enabled()) { // Concatenate and fix up the MSC descriptor. descriptor_buf_remaining += storage_usb_add_descriptor( descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string); } -#endif + #endif -#if CIRCUITPY_USB_HID + #if CIRCUITPY_USB_HID if (usb_hid_enabled()) { descriptor_buf_remaining += usb_hid_add_descriptor( descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string, usb_hid_report_descriptor_length()); } -#endif + #endif -#if CIRCUITPY_USB_MIDI + #if CIRCUITPY_USB_MIDI if (usb_midi_enabled()) { // Concatenate and fix up the MIDI descriptor. descriptor_buf_remaining += usb_midi_add_descriptor( descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string); } -#endif + #endif // Now we know how many interfaces have been used. configuration_descriptor[CONFIG_NUM_INTERFACES_INDEX] = current_interface; @@ -251,8 +251,8 @@ static void usb_build_interface_string_table(void) { // Space needed is 2 bytes for String Descriptor header, then 2 bytes for each character string_descriptors_allocation = allocate_memory(align32_size(current_interface_string * 2 + collected_interface_strings_length * 2), - /*high_address*/ false, /*movable*/ false); - uint16_t *string_descriptors = (uint16_t *) string_descriptors_allocation->ptr; + /*high_address*/ false, /*movable*/ false); + uint16_t *string_descriptors = (uint16_t *)string_descriptors_allocation->ptr; uint16_t *string_descriptor = string_descriptors; @@ -268,7 +268,7 @@ static void usb_build_interface_string_table(void) { for (uint8_t string_index = 1; string_index < current_interface_string; string_index++) { const char *str = collected_interface_strings[string_index].char_str; const size_t str_len = strlen(str); - uint8_t descriptor_size = 2 + (str_len * 2); + uint8_t descriptor_size = 2 + (str_len * 2); string_descriptor[0] = 0x0300 | descriptor_size; // Convert to le16. @@ -311,7 +311,7 @@ void usb_build_descriptors(void) { // Invoked when GET DEVICE DESCRIPTOR is received. // Application return pointer to descriptor uint8_t const *tud_descriptor_device_cb(void) { - return (uint8_t *) device_descriptor_allocation->ptr; + return (uint8_t *)device_descriptor_allocation->ptr; } // Invoked when GET CONFIGURATION DESCRIPTOR is received. @@ -319,7 +319,7 @@ uint8_t const *tud_descriptor_device_cb(void) { // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_descriptor_configuration_cb(uint8_t index) { (void)index; // for multiple configurations - return (uint8_t *) configuration_descriptor_allocation->ptr; + return (uint8_t *)configuration_descriptor_allocation->ptr; } // Invoked when GET STRING DESCRIPTOR request is received. From adc3d7d55e74723c3cf97110f9794d31f64f0b7c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 3 May 2021 22:22:29 -0400 Subject: [PATCH 47/66] update Python API according to review comments --- ports/nrf/bluetooth/ble_uart.c | 4 +- ports/nrf/supervisor/serial.c | 10 ++-- py/circuitpy_mpconfig.mk | 16 +++--- shared-bindings/storage/__init__.c | 44 ++++++++------ shared-bindings/storage/__init__.h | 4 +- shared-bindings/usb_cdc/__init__.c | 89 +++++++++++++++++------------ shared-bindings/usb_cdc/__init__.h | 5 +- shared-bindings/usb_hid/Device.c | 4 +- shared-bindings/usb_hid/__init__.c | 30 +++++++--- shared-bindings/usb_hid/__init__.h | 3 +- shared-bindings/usb_midi/__init__.c | 41 ++++++++----- shared-bindings/usb_midi/__init__.h | 3 +- shared-module/storage/__init__.c | 10 +++- shared-module/usb_cdc/__init__.c | 40 +++++++------ shared-module/usb_cdc/__init__.h | 2 +- shared-module/usb_hid/__init__.c | 26 ++++++--- shared-module/usb_midi/__init__.c | 10 +++- supervisor/shared/serial.c | 8 +-- supervisor/shared/usb/usb_desc.c | 4 +- 19 files changed, 221 insertions(+), 132 deletions(-) diff --git a/ports/nrf/bluetooth/ble_uart.c b/ports/nrf/bluetooth/ble_uart.c index df64568678..022b866ce6 100644 --- a/ports/nrf/bluetooth/ble_uart.c +++ b/ports/nrf/bluetooth/ble_uart.c @@ -40,7 +40,7 @@ #include "shared-bindings/_bleio/Service.h" #include "shared-bindings/_bleio/UUID.h" -#if CIRCUITPY_REPL_BLE +#if CIRCUITPY_CONSOLE_BLE static const char default_name[] = "CP-REPL"; // max 8 chars or uuid won't fit in adv data static const char NUS_UUID[] = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"; @@ -188,4 +188,4 @@ void mp_hal_stdout_tx_strn(const char *str, size_t len) { } } -#endif // CIRCUITPY_REPL_BLE +#endif // CIRCUITPY_CONSOLE_BLE diff --git a/ports/nrf/supervisor/serial.c b/ports/nrf/supervisor/serial.c index 10bdb2819a..41aa34721a 100644 --- a/ports/nrf/supervisor/serial.c +++ b/ports/nrf/supervisor/serial.c @@ -28,15 +28,15 @@ #include "supervisor/serial.h" -#if CIRCUITPY_REPL_BLE +#if CIRCUITPY_CONSOLE_BLE #include "ble_uart.h" -#elif CIRCUITPY_REPL_UART +#elif CIRCUITPY_CONSOLE_UART #include #include "nrf_gpio.h" #include "nrfx_uarte.h" #endif -#if CIRCUITPY_REPL_BLE +#if CIRCUITPY_CONSOLE_BLE void serial_init(void) { ble_uart_init(); @@ -58,7 +58,7 @@ void serial_write(const char *text) { ble_uart_stdout_tx_str(text); } -#elif CIRCUITPY_REPL_UART +#elif CIRCUITPY_CONSOLE_UART uint8_t serial_received_char; nrfx_uarte_t serial_instance = NRFX_UARTE_INSTANCE(0); @@ -124,4 +124,4 @@ void serial_write_substring(const char *text, uint32_t len) { } } -#endif // CIRCUITPY_REPL_UART +#endif // CIRCUITPY_CONSOLE_UART diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index a730ad64ce..ec4dea1975 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -133,6 +133,12 @@ CFLAGS += -DCIRCUITPY_DIGITALIO=$(CIRCUITPY_DIGITALIO) CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 0 CFLAGS += -DCIRCUITPY_COMPUTED_GOTO_SAVE_SPACE=$(CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE) +CIRCUITPY_CONSOLE_BLE ?= 0 +CFLAGS += -DCIRCUITPY_CONSOLE_BLE=$(CIRCUITPY_CONSOLE_BLE) + +CIRCUITPY_CONSOLE_UART ?= 0 +CFLAGS += -DCIRCUITPY_CONSOLE_UART=$(CIRCUITPY_CONSOLE_UART) + CIRCUITPY_COUNTIO ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO) @@ -246,12 +252,6 @@ CFLAGS += -DCIRCUITPY_RE=$(CIRCUITPY_RE) CIRCUITPY_RE_DEBUG ?= 0 CFLAGS += -DCIRCUITPY_RE_DEBUG=$(CIRCUITPY_RE_DEBUG) -CIRCUITPY_REPL_BLE ?= 0 -CFLAGS += -DCIRCUITPY_REPL_BLE=$(CIRCUITPY_REPL_BLE) - -CIRCUITPY_REPL_UART ?= 0 -CFLAGS += -DCIRCUITPY_REPL_UART=$(CIRCUITPY_REPL_UART) - # Should busio.I2C() check for pullups? # Some boards in combination with certain peripherals may not want this. CIRCUITPY_REQUIRE_I2C_PULLUPS ?= 1 @@ -337,8 +337,8 @@ CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB) CIRCUITPY_USB_CDC ?= 1 CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC) -CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT ?= 1 -CFLAGS += -DCIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT) +CIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT ?= 1 +CFLAGS += -DCIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT) CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT ?= 0 CFLAGS += -DCIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT=$(CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT) diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index a6e5fdd10e..75a271f64d 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -158,33 +158,45 @@ mp_obj_t storage_erase_filesystem(void) { } MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem); -//| def configure_usb(enabled: bool = True) -> None: -//| """Configure the USB mass storage device. -//| Enable or disable presenting ``CIRCUITPY`` as a USB mass storage device. +//| def disable_usb_drive() -> None: +//| """Disable presenting ``CIRCUITPY`` as a USB mass storage device. //| By default, the device is enabled and ``CIRCUITPY`` is visible. -//| Can be called in ``boot.py``, before USB is connected. -//| -//| :param enabled bool: Enable or disable the USB mass storage device. -//| True to enable; False to disable. Enabled by default.""" +//| Can be called in ``boot.py``, before USB is connected.""" //| ... //| -STATIC mp_obj_t storage_configure_usb(mp_obj_t enabled) { - if (!common_hal_storage_configure_usb(mp_obj_is_true(enabled))) { +STATIC mp_obj_t storage_disable_usb_drive(void) { + if (!common_hal_storage_disable_usb_drive()) { mp_raise_RuntimeError(translate("Cannot change usb devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(storage_configure_usb_obj, storage_configure_usb); +MP_DEFINE_CONST_FUN_OBJ_0(storage_disable_usb_drive_obj, storage_disable_usb_drive); + +//| def enable_usb_drive() -> None: +//| """Enabled presenting ``CIRCUITPY`` as a USB mass storage device. +//| By default, the device is enabled and ``CIRCUITPY`` is visible, +//| so you do not normally need to call this function. +//| Can be called in ``boot.py``, before USB is connected.""" +//| ... +//| +STATIC mp_obj_t storage_enable_usb_drive(void) { + if (!common_hal_storage_enable_usb_drive()) { + mp_raise_RuntimeError(translate("Cannot change usb devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_0(storage_enable_usb_drive_obj, storage_enable_usb_drive); STATIC const mp_rom_map_elem_t storage_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_storage) }, - { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) }, - { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) }, - { MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) }, - { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, - { MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) }, - { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_ROM_PTR(&storage_configure_usb_obj) }, + { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&storage_mount_obj) }, + { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&storage_umount_obj) }, + { MP_ROM_QSTR(MP_QSTR_remount), MP_ROM_PTR(&storage_remount_obj) }, + { MP_ROM_QSTR(MP_QSTR_getmount), MP_ROM_PTR(&storage_getmount_obj) }, + { MP_ROM_QSTR(MP_QSTR_erase_filesystem), MP_ROM_PTR(&storage_erase_filesystem_obj) }, + { MP_ROM_QSTR(MP_QSTR_disable_usb_drive), MP_ROM_PTR(&storage_disable_usb_drive_obj) }, + { MP_ROM_QSTR(MP_QSTR_enable_usb_drive), MP_ROM_PTR(&storage_enable_usb_drive_obj) }, //| class VfsFat: //| def __init__(self, block_device: str) -> None: diff --git a/shared-bindings/storage/__init__.h b/shared-bindings/storage/__init__.h index 0303e0440c..fbf492efab 100644 --- a/shared-bindings/storage/__init__.h +++ b/shared-bindings/storage/__init__.h @@ -38,6 +38,8 @@ void common_hal_storage_umount_object(mp_obj_t vfs_obj); void common_hal_storage_remount(const char *path, bool readonly, bool disable_concurrent_write_protection); mp_obj_t common_hal_storage_getmount(const char *path); void common_hal_storage_erase_filesystem(void); -bool common_hal_storage_configure_usb(bool enabled); + +bool common_hal_storage_disable_usb_drive(void); +bool common_hal_storage_enable_usb_drive(void); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_STORAGE___INIT___H diff --git a/shared-bindings/usb_cdc/__init__.c b/shared-bindings/usb_cdc/__init__.c index ac39b6d50d..557c06a3ec 100644 --- a/shared-bindings/usb_cdc/__init__.c +++ b/shared-bindings/usb_cdc/__init__.c @@ -39,60 +39,77 @@ //| The `usb_cdc` module allows access to USB CDC (serial) communications. //| //| On Windows, each `Serial` is visible as a separate COM port. The ports will often -//| be assigned consecutively, REPL first, but this is not always true. +//| be assigned consecutively, `console` first, but this is not always true. //| -//| On Linux, the ports are typically ``/dev/ttyACM0`` and ``/dev/ttyACM1``. The REPL -//| is usually first. +//| On Linux, the ports are typically ``/dev/ttyACM0`` and ``/dev/ttyACM1``. +//| The `console` port will usually be first. //| //| On MacOS, the ports are typically ``/dev/cu.usbmodem``. The something -//| varies based on the USB bus and port used. The REPL is usually first. +//| varies based on the USB bus and port used. The `console` port will usually be first. //| """ //| -//| repl: Optional[Serial] -//| """The `Serial` object that can be used to communicate over the REPL serial -//| channel. ``None`` if disabled. +//| console: Optional[Serial] +//| """The `console` `Serial` object is used for the REPL, and for `sys.stdin` and `sys.stdout`. +//| `console` is ``None`` if disabled. //| -//| Note that`sys.stdin` and `sys.stdout` are also connected to the REPL, though -//| they are text-based streams, and the `repl` object is a binary stream.""" +//| However, note that`sys.stdin` and `sys.stdout` are text-based streams, +//| and the `console` object is a binary stream. +//| You do not normally need to write to `console` unless you wnat to write binary data. +//| """ //| //| data: Optional[Serial] //| """A `Serial` object that can be used to send and receive binary data to and from //| the host. -//| Note that `data` is *disabled* by default.""" +//| Note that `data` is *disabled* by default. ``data`` is ``None`` if disabled.""" -//| def configure_usb(*, repl_enabled: bool = True, data_enabled: bool = False) -> None: -//| """Configure the USB CDC devices. Can be called in ``boot.py``, before USB is connected. -//| -//| :param repl_enabled bool: Enable or disable the `repl` USB serial device. -//| True to enable; False to disable. Enabled by default. -//| :param data_enabled bool: Enable or disable the `data` USB serial device. -//| True to enable; False to disable. *Disabled* by default.""" +//| def disable() -> None: +//| """Do not present any USB CDC device to the host. +//| Can be called in ``boot.py``, before USB is connected. +//| Equivalent to ``usb_cdc.enable(console=False, data=False)``.""" //| ... //| -STATIC mp_obj_t usb_cdc_configure_usb(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_repl_enabled, ARG_data_enabled }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_repl_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true } }, - { MP_QSTR_data_enabled, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } }, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - if (!common_hal_usb_cdc_configure_usb(args[ARG_repl_enabled].u_bool, args[ARG_data_enabled].u_bool)) { +STATIC mp_obj_t usb_cdc_disable(void) { + if (!common_hal_usb_cdc_disable()) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(usb_cdc_configure_usb_obj, 0, usb_cdc_configure_usb); +MP_DEFINE_CONST_FUN_OBJ_0(usb_cdc_disable_obj, usb_cdc_disable); -// The usb_cdc module dict is mutable so that .repl and .data may +//| def enable(*, console: bool = True, data: bool = False) -> None: +//| """Enable or disable each CDC device. Can be called in ``boot.py``, before USB is connected. +//| +//| :param console bool: Enable or disable the `console` USB serial device. +//| True to enable; False to disable. Enabled by default. +//| :param data bool: Enable or disable the `data` USB serial device. +//| True to enable; False to disable. *Disabled* by default.""" +//| ... +//| +STATIC mp_obj_t usb_cdc_enable(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_console, ARG_data }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_console, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true } }, + { MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (!common_hal_usb_cdc_enable(args[ARG_console].u_bool, args[ARG_data].u_bool)) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(usb_cdc_enable_obj, 0, usb_cdc_enable); + +// The usb_cdc module dict is mutable so that .console and .data may // be set to a Serial or to None depending on whether they are enabled or not. static mp_map_elem_t usb_cdc_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) }, - { MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) }, - { MP_ROM_QSTR(MP_QSTR_repl), mp_const_none }, - { MP_ROM_QSTR(MP_QSTR_data), mp_const_none }, - { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_cdc_configure_usb_obj) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_cdc) }, + { MP_ROM_QSTR(MP_QSTR_Serial), MP_OBJ_FROM_PTR(&usb_cdc_serial_type) }, + { MP_ROM_QSTR(MP_QSTR_console), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_data), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_disable), MP_OBJ_FROM_PTR(&usb_cdc_disable_obj) }, + { MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_cdc_enable_obj) }, }; static MP_DEFINE_MUTABLE_DICT(usb_cdc_module_globals, usb_cdc_module_globals_table); @@ -109,8 +126,8 @@ static void set_module_dict_entry(mp_obj_t key_qstr, mp_obj_t serial_obj) { } } -void usb_cdc_set_repl(mp_obj_t serial_obj) { - set_module_dict_entry(MP_ROM_QSTR(MP_QSTR_repl), serial_obj); +void usb_cdc_set_console(mp_obj_t serial_obj) { + set_module_dict_entry(MP_ROM_QSTR(MP_QSTR_console), serial_obj); } void usb_cdc_set_data(mp_obj_t serial_obj) { diff --git a/shared-bindings/usb_cdc/__init__.h b/shared-bindings/usb_cdc/__init__.h index abf148e9f6..0a517f4cec 100644 --- a/shared-bindings/usb_cdc/__init__.h +++ b/shared-bindings/usb_cdc/__init__.h @@ -30,9 +30,10 @@ #include "shared-module/usb_cdc/__init__.h" // Set the module dict entries. -void usb_cdc_set_repl(mp_obj_t serial_obj); +void usb_cdc_set_console(mp_obj_t serial_obj); void usb_cdc_set_data(mp_obj_t serial_obj); -extern bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled); +extern bool common_hal_usb_cdc_disable(void); +extern bool common_hal_usb_cdc_enable(bool console, bool data); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_CDC___INIT___H diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 5e759ab92d..de9cb8bfef 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -40,8 +40,8 @@ //| //| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: int = 0, report_id_index: Optional[int]) -> None: -//| """Create a description of a USB HID device. To create an actual device, -//| pass a `Device` to `usb_hid.configure_usb()`. +//| """Create a description of a USB HID device. The actual device is created when you +//| pass a `Device` to `usb_hid.enable()`. //| //| :param ReadableBuffer report_descriptor: The USB HID Report descriptor bytes. The descriptor is not //| not verified for correctness; it is up to you to make sure it is not malformed. diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index 2f01560ccf..8e85cc67f0 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -40,8 +40,19 @@ //| """Tuple of all active HID device interfaces.""" //| -//| def configure_usb(devices: Optional[Sequence[Device]]) -> None: -//| """Configure the USB HID devices that will be available. +//| def disable() -> None: +//| """Do not present any USB HID devices to the host computer. +//| Can be called in ``boot.py``, before USB is connected.""" +STATIC mp_obj_t usb_hid_disable(void) { + if (!common_hal_usb_hid_disable()) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_0(usb_hid_disable_obj, usb_hid_disable); + +//| def enable(devices: Optional[Sequence[Device]]) -> None: +//| """Specify which USB HID devices that will be available. //| Can be called in ``boot.py``, before USB is connected. //| //| :param Sequence devices: `Device` objects. @@ -51,7 +62,7 @@ //| """ //| ... //| -STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { +STATIC mp_obj_t usb_hid_enable(mp_obj_t devices) { const mp_int_t len = mp_obj_get_int(mp_obj_len(devices)); for (mp_int_t i = 0; i < len; i++) { mp_obj_t item = mp_obj_subscr(devices, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL); @@ -60,20 +71,21 @@ STATIC mp_obj_t usb_hid_configure_usb(mp_obj_t devices) { } } - if (!common_hal_usb_hid_configure_usb(devices)) { + if (!common_hal_usb_hid_enable(devices)) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_configure_usb_obj, usb_hid_configure_usb); +MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_enable_obj, usb_hid_enable); // usb_hid.devices is set once the usb devices are determined, after boot.py runs. STATIC mp_map_elem_t usb_hid_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, - { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_hid_configure_usb_obj) }, - { MP_ROM_QSTR(MP_QSTR_devices), mp_const_none }, - { MP_ROM_QSTR(MP_QSTR_Device), MP_OBJ_FROM_PTR(&usb_hid_device_type) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, + { MP_ROM_QSTR(MP_QSTR_Device), MP_OBJ_FROM_PTR(&usb_hid_device_type) }, + { MP_ROM_QSTR(MP_QSTR_devices), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_disable), MP_OBJ_FROM_PTR(&usb_hid_disable_obj) }, + { MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_hid_enable_obj) }, }; STATIC MP_DEFINE_MUTABLE_DICT(usb_hid_module_globals, usb_hid_module_globals_table); diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index 479a937f54..d5fc7743a3 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -35,6 +35,7 @@ extern mp_obj_tuple_t common_hal_usb_hid_devices; void usb_hid_set_devices(mp_obj_t devices); -bool common_hal_usb_hid_configure_usb(const mp_obj_t devices_seq); +bool common_hal_usb_hid_disable(void); +bool common_hal_usb_hid_enable(const mp_obj_t devices_seq); #endif // SHARED_BINDINGS_USB_HID_H diff --git a/shared-bindings/usb_midi/__init__.c b/shared-bindings/usb_midi/__init__.c index a18ba599b7..a3ed06dd8c 100644 --- a/shared-bindings/usb_midi/__init__.c +++ b/shared-bindings/usb_midi/__init__.c @@ -43,28 +43,41 @@ //| """Tuple of all MIDI ports. Each item is ether `PortIn` or `PortOut`.""" //| -//| def configure_usb(enabled: bool = True) -> None: -//| """Configure the USB MIDI device. -//| Can be called in ``boot.py``, before USB is connected. -//| -//| :param enabled bool: Enable or disable the USB MIDI Device. -//| True to enable; False to disable. Enabled by default.""" +//| def disable() -> None: +//| """Disable presenting a USB MIDI device to the host. +//| The device is normally enabled by default. +//| Can be called in ``boot.py``, before USB is connected.""" //| ... //| -STATIC mp_obj_t usb_midi_configure_usb(mp_obj_t enabled) { - if (!common_hal_usb_midi_configure_usb(mp_obj_is_true(enabled))) { +STATIC mp_obj_t usb_midi_disable(void) { + if (!common_hal_usb_midi_disable()) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(usb_midi_configure_usb_obj, usb_midi_configure_usb); +MP_DEFINE_CONST_FUN_OBJ_0(usb_midi_disable_obj, usb_midi_disable); + +//| def enable() -> None: +//| """Enable presenting a USB MIDI device to the host. +//| The device is enabled by default, so you do not normally need to call this function. +//| Can be called in ``boot.py``, before USB is connected.""" +//| ... +//| +STATIC mp_obj_t usb_midi_enable(void) { + if (!common_hal_usb_midi_enable()) { + mp_raise_RuntimeError(translate("Cannot change USB devices now")); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_0(usb_midi_enable_obj, usb_midi_enable); mp_map_elem_t usb_midi_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) }, - { MP_ROM_QSTR(MP_QSTR_configure_usb), MP_OBJ_FROM_PTR(&usb_midi_configure_usb_obj) }, - { MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple }, - { MP_ROM_QSTR(MP_QSTR_PortIn), MP_OBJ_FROM_PTR(&usb_midi_portin_type) }, - { MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_usb_midi) }, + { MP_ROM_QSTR(MP_QSTR_disable), MP_OBJ_FROM_PTR(&usb_midi_disable_obj) }, + { MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_midi_enable_obj) }, + { MP_ROM_QSTR(MP_QSTR_ports), mp_const_empty_tuple }, + { MP_ROM_QSTR(MP_QSTR_PortIn), MP_OBJ_FROM_PTR(&usb_midi_portin_type) }, + { MP_ROM_QSTR(MP_QSTR_PortOut), MP_OBJ_FROM_PTR(&usb_midi_portout_type) }, }; // This isn't const so we can set ports dynamically. diff --git a/shared-bindings/usb_midi/__init__.h b/shared-bindings/usb_midi/__init__.h index dab3dc8f72..b657cfe57b 100644 --- a/shared-bindings/usb_midi/__init__.h +++ b/shared-bindings/usb_midi/__init__.h @@ -32,6 +32,7 @@ extern mp_obj_dict_t usb_midi_module_globals; -bool common_hal_usb_midi_configure_usb(bool enabled); +bool common_hal_usb_midi_disable(void); +bool common_hal_usb_midi_enable(void); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_MIDI___INIT___H diff --git a/shared-module/storage/__init__.c b/shared-module/storage/__init__.c index 64fbc4608b..b1d038a7d3 100644 --- a/shared-module/storage/__init__.c +++ b/shared-module/storage/__init__.c @@ -109,7 +109,7 @@ size_t storage_usb_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_inte return sizeof(usb_msc_descriptor_template); } -bool common_hal_storage_configure_usb(bool enabled) { +static bool usb_drive_set_enabled(bool enabled) { // We can't change the descriptors once we're connected. if (tud_connected()) { return false; @@ -117,6 +117,14 @@ bool common_hal_storage_configure_usb(bool enabled) { storage_usb_is_enabled = enabled; return true; } + +bool common_hal_storage_disable_usb_drive(void) { + return usb_drive_set_enabled(false); +} + +bool common_hal_storage_enable_usb_drive(void) { + return usb_drive_set_enabled(true); +} #endif // CIRCUITPY_USB_MSC STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { diff --git a/shared-module/usb_cdc/__init__.c b/shared-module/usb_cdc/__init__.c index 9be8483c7c..446c65931e 100644 --- a/shared-module/usb_cdc/__init__.c +++ b/shared-module/usb_cdc/__init__.c @@ -134,12 +134,12 @@ static const uint8_t usb_cdc_descriptor_template[] = { 0x00, // 65 bInterval 0 (unit depends on device speed) }; -static const char repl_cdc_comm_interface_name[] = USB_INTERFACE_NAME " CDC control"; +static const char console_cdc_comm_interface_name[] = USB_INTERFACE_NAME " CDC control"; static const char data_cdc_comm_interface_name[] = USB_INTERFACE_NAME " CDC2 control"; -static const char repl_cdc_data_interface_name[] = USB_INTERFACE_NAME " CDC data"; +static const char console_cdc_data_interface_name[] = USB_INTERFACE_NAME " CDC data"; static const char data_cdc_data_interface_name[] = USB_INTERFACE_NAME " CDC2 data"; -static usb_cdc_serial_obj_t usb_cdc_repl_obj = { +static usb_cdc_serial_obj_t usb_cdc_console_obj = { .base.type = &usb_cdc_serial_type, .timeout = -1.0f, .write_timeout = -1.0f, @@ -153,16 +153,16 @@ static usb_cdc_serial_obj_t usb_cdc_data_obj = { .idx = 1, }; -static bool usb_cdc_repl_is_enabled; +static bool usb_cdc_console_is_enabled; static bool usb_cdc_data_is_enabled; void usb_cdc_set_defaults(void) { - usb_cdc_repl_is_enabled = CIRCUITPY_USB_CDC_REPL_ENABLED_DEFAULT; + usb_cdc_console_is_enabled = CIRCUITPY_USB_CDC_CONSOLE_ENABLED_DEFAULT; usb_cdc_data_is_enabled = CIRCUITPY_USB_CDC_DATA_ENABLED_DEFAULT; } -bool usb_cdc_repl_enabled(void) { - return usb_cdc_repl_is_enabled; +bool usb_cdc_console_enabled(void) { + return usb_cdc_console_is_enabled; } bool usb_cdc_data_enabled(void) { @@ -173,7 +173,7 @@ size_t usb_cdc_descriptor_length(void) { return sizeof(usb_cdc_descriptor_template); } -size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string, bool repl) { +size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interface, uint8_t *current_endpoint, uint8_t *current_interface_string, bool console) { memcpy(descriptor_buf, usb_cdc_descriptor_template, sizeof(usb_cdc_descriptor_template)); // Store comm interface number. @@ -189,36 +189,40 @@ size_t usb_cdc_add_descriptor(uint8_t *descriptor_buf, uint8_t *current_interfac (*current_interface)++; descriptor_buf[CDC_CONTROL_IN_ENDPOINT_INDEX] = 0x80 | ( - repl + console ? (USB_CDC_EP_NUM_NOTIFICATION ? USB_CDC_EP_NUM_NOTIFICATION : *current_endpoint) : (USB_CDC2_EP_NUM_NOTIFICATION ? USB_CDC2_EP_NUM_NOTIFICATION : *current_endpoint)); (*current_endpoint)++; descriptor_buf[CDC_DATA_OUT_ENDPOINT_INDEX] = - repl + console ? (USB_CDC_EP_NUM_DATA_OUT ? USB_CDC_EP_NUM_DATA_OUT : *current_endpoint) : (USB_CDC2_EP_NUM_DATA_OUT ? USB_CDC2_EP_NUM_DATA_OUT : *current_endpoint); descriptor_buf[CDC_DATA_IN_ENDPOINT_INDEX] = 0x80 | ( - repl + console ? (USB_CDC_EP_NUM_DATA_IN ? USB_CDC_EP_NUM_DATA_IN : *current_endpoint) : (USB_CDC2_EP_NUM_DATA_IN ? USB_CDC2_EP_NUM_DATA_IN : *current_endpoint)); (*current_endpoint)++; usb_add_interface_string(*current_interface_string, - repl ? repl_cdc_comm_interface_name : data_cdc_comm_interface_name); + console ? console_cdc_comm_interface_name : data_cdc_comm_interface_name); descriptor_buf[CDC_COMM_INTERFACE_STRING_INDEX] = *current_interface_string; (*current_interface_string)++; usb_add_interface_string(*current_interface_string, - repl ? repl_cdc_data_interface_name : data_cdc_data_interface_name); + console ? console_cdc_data_interface_name : data_cdc_data_interface_name); descriptor_buf[CDC_DATA_INTERFACE_STRING_INDEX] = *current_interface_string; (*current_interface_string)++; return sizeof(usb_cdc_descriptor_template); } -bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) { +bool common_hal_usb_cdc_disable(void) { + return common_hal_usb_cdc_enable(false, false); +} + +bool common_hal_usb_cdc_enable(bool console, bool data) { // We can't change the descriptors once we're connected. if (tud_connected()) { return false; @@ -227,11 +231,11 @@ bool common_hal_usb_cdc_configure_usb(bool repl_enabled, bool data_enabled) { // Right now these objects contain no heap objects, but if that changes, // they will need to be protected against gc. - usb_cdc_repl_is_enabled = repl_enabled; - usb_cdc_set_repl(repl_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_repl_obj) : mp_const_none); + usb_cdc_console_is_enabled = console; + usb_cdc_set_console(console ? MP_OBJ_FROM_PTR(&usb_cdc_console_obj) : mp_const_none); - usb_cdc_data_is_enabled = data_enabled; - usb_cdc_set_data(data_enabled ? MP_OBJ_FROM_PTR(&usb_cdc_data_obj) : mp_const_none); + usb_cdc_data_is_enabled = data; + usb_cdc_set_data(data ? MP_OBJ_FROM_PTR(&usb_cdc_data_obj) : mp_const_none); return true; } diff --git a/shared-module/usb_cdc/__init__.h b/shared-module/usb_cdc/__init__.h index b2cb8aa075..ae39143017 100644 --- a/shared-module/usb_cdc/__init__.h +++ b/shared-module/usb_cdc/__init__.h @@ -30,7 +30,7 @@ #include "py/mpconfig.h" #include "py/objtuple.h" -bool usb_cdc_repl_enabled(void); +bool usb_cdc_console_enabled(void); bool usb_cdc_data_enabled(void); void usb_cdc_set_defaults(void); diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index 4c97f8d07e..42c1347357 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -74,13 +74,11 @@ static const uint8_t usb_hid_descriptor_template[] = { 0x08, // 31 bInterval 8 (unit depends on device speed) }; -// Is the HID device enabled? -static bool usb_hid_is_enabled; - #define MAX_HID_DEVICES 8 static supervisor_allocation *hid_report_descriptor_allocation; static usb_hid_device_obj_t hid_devices[MAX_HID_DEVICES]; +// If 0, USB HID is disabled. static mp_int_t hid_devices_num; // This tuple is store in usb_hid.devices. @@ -99,12 +97,12 @@ static mp_obj_tuple_t default_hid_devices_tuple = { }; bool usb_hid_enabled(void) { - return usb_hid_is_enabled; + return hid_devices_num == 0; } void usb_hid_set_defaults(void) { - usb_hid_is_enabled = CIRCUITPY_USB_HID_ENABLED_DEFAULT; - common_hal_usb_hid_configure_usb(usb_hid_is_enabled ? &default_hid_devices_tuple : mp_const_empty_tuple); + common_hal_usb_hid_enable( + CIRCUITPY_USB_HID_ENABLED_DEFAULT ? &default_hid_devices_tuple : mp_const_empty_tuple); } // This is the interface descriptor, not the report descriptor. @@ -148,7 +146,11 @@ static void usb_hid_set_devices_from_hid_devices(void) { usb_hid_set_devices(hid_devices_tuple); } -bool common_hal_usb_hid_configure_usb(const mp_obj_t devices) { +bool common_hal_usb_hid_disable(void) { + return common_hal_usb_hid_enable(mp_const_empty_tuple); +} + +bool common_hal_usb_hid_enable(const mp_obj_t devices) { // We can't change the devices once we're connected. if (tud_connected()) { return false; @@ -198,6 +200,10 @@ size_t usb_hid_report_descriptor_length(void) { // Build the combined HID report descriptor in the given space. void usb_hid_build_report_descriptor(uint8_t *report_descriptor_space, size_t report_descriptor_length) { + if (!usb_hid_enabled()) { + return; + } + uint8_t *report_descriptor_start = report_descriptor_space; for (mp_int_t i = 0; i < hid_devices_num; i++) { @@ -229,7 +235,11 @@ void usb_hid_build_report_descriptor(uint8_t *report_descriptor_space, size_t re // Call this after the heap and VM are finished. void usb_hid_save_report_descriptor(uint8_t *report_descriptor_space, size_t report_descriptor_length) { - // Allocate storage that persists across VMs to hold the combind report descriptor. + if (!usb_hid_enabled()) { + return; + } + + // Allocate storage that persists across VMs to hold the combined report descriptor. // and to remember the device details. // Copy the descriptor from the temporary area to a supervisor storage allocation that diff --git a/shared-module/usb_midi/__init__.c b/shared-module/usb_midi/__init__.c index 3d33eefc97..fb564af8d4 100644 --- a/shared-module/usb_midi/__init__.c +++ b/shared-module/usb_midi/__init__.c @@ -242,7 +242,7 @@ void usb_midi_setup_ports(void) { MP_OBJ_FROM_PTR(ports); } -bool common_hal_usb_midi_configure_usb(bool enabled) { +static bool usb_midi_set_enabled(bool enabled) { // We can't change the descriptors once we're connected. if (tud_connected()) { return false; @@ -250,3 +250,11 @@ bool common_hal_usb_midi_configure_usb(bool enabled) { usb_midi_is_enabled = enabled; return true; } + +bool common_hal_usb_midi_disable(void) { + return usb_midi_set_enabled(false); +} + +bool common_hal_usb_midi_enable(void) { + return usb_midi_set_enabled(true); +} diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 42d2e6caf9..f7e0aafaaf 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -94,7 +94,7 @@ bool serial_connected(void) { #if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX) return true; #elif CIRCUITPY_USB_CDC - return usb_cdc_repl_enabled() && tud_cdc_connected(); + return usb_cdc_console_enabled() && tud_cdc_connected(); #else return tud_cdc_connected(); #endif @@ -118,7 +118,7 @@ char serial_read(void) { common_hal_busio_uart_read(&debug_uart, (uint8_t *)&text, 1, &uart_errcode); return text; #elif CIRCUITPY_USB_CDC - if (!usb_cdc_repl_enabled()) { + if (!usb_cdc_console_enabled()) { return -1; } #endif @@ -135,7 +135,7 @@ bool serial_bytes_available(void) { #if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX) return common_hal_busio_uart_rx_characters_available(&debug_uart) || (tud_cdc_available() > 0); #elif CIRCUITPY_USB_CDC - if (!usb_cdc_repl_enabled()) { + if (!usb_cdc_console_enabled()) { return 0; } #endif @@ -157,7 +157,7 @@ void serial_write_substring(const char *text, uint32_t length) { #endif #if CIRCUITPY_USB_CDC - if (!usb_cdc_repl_enabled()) { + if (!usb_cdc_console_enabled()) { return; } #endif diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index f8b094591d..38289552d6 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -143,7 +143,7 @@ static void usb_build_configuration_descriptor(void) { // CDC should be first, for compatibility with Adafruit Windows 7 drivers. // In the past, the order has been CDC, MSC, MIDI, HID, so preserve that order. #if CIRCUITPY_USB_CDC - if (usb_cdc_repl_enabled()) { + if (usb_cdc_console_enabled()) { total_descriptor_length += usb_cdc_descriptor_length(); } if (usb_cdc_data_enabled()) { @@ -190,7 +190,7 @@ static void usb_build_configuration_descriptor(void) { uint8_t *descriptor_buf_remaining = configuration_descriptor + sizeof(configuration_descriptor_template); #if CIRCUITPY_USB_CDC - if (usb_cdc_repl_enabled()) { + if (usb_cdc_console_enabled()) { // Concatenate and fix up the CDC REPL descriptor. descriptor_buf_remaining += usb_cdc_add_descriptor( descriptor_buf_remaining, ¤t_interface, ¤t_endpoint, ¤t_interface_string, true); From 2d73ba21860e2374bb5e678d88c2593009c7cc08 Mon Sep 17 00:00:00 2001 From: Artyom Skrobov Date: Tue, 4 May 2021 03:35:45 -0400 Subject: [PATCH 48/66] qstr: Use `const` consistently to avoid a cast. --- py/qstr.c | 10 +++++----- py/qstr.h | 2 +- tools/mpy-tool.py | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/py/qstr.c b/py/qstr.c index 879fe30f22..7df83e25cb 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -123,7 +123,7 @@ void qstr_init(void) { STATIC const char *find_qstr(qstr q, qstr_attr_t *attr) { // search pool for this qstr // total_prev_len==0 in the final pool, so the loop will always terminate - qstr_pool_t *pool = MP_STATE_VM(last_pool); + const qstr_pool_t *pool = MP_STATE_VM(last_pool); while (q < pool->total_prev_len) { pool = pool->prev; } @@ -181,7 +181,7 @@ qstr qstr_find_strn(const char *str, size_t str_len) { mp_uint_t str_hash = qstr_compute_hash((const byte *)str, str_len); // search pools for the data - for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) { + for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) { qstr_attr_t *attrs = pool->attrs; for (mp_uint_t at = 0, top = pool->len; at < top; at++) { if (attrs[at].hash == str_hash && attrs[at].len == str_len && memcmp(pool->qstrs[at], str, str_len) == 0) { @@ -290,7 +290,7 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si *n_qstr = 0; *n_str_data_bytes = 0; *n_total_bytes = 0; - for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) { + for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) { *n_pool += 1; *n_qstr += pool->len; for (const qstr_attr_t *q = pool->attrs, *q_top = pool->attrs + pool->len; q < q_top; q++) { @@ -310,8 +310,8 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si #if MICROPY_PY_MICROPYTHON_MEM_INFO void qstr_dump_data(void) { QSTR_ENTER(); - for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) { - for (const char **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) { + for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) { + for (const char *const *q = pool->qstrs, *const *q_top = pool->qstrs + pool->len; q < q_top; q++) { mp_printf(&mp_plat_print, "Q(%s)\n", *q); } } diff --git a/py/qstr.h b/py/qstr.h index bf9e30231b..6326426b0f 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -65,7 +65,7 @@ typedef struct _qstr_attr_t { } qstr_attr_t; typedef struct _qstr_pool_t { - struct _qstr_pool_t *prev; + const struct _qstr_pool_t *prev; size_t total_prev_len; size_t alloc; size_t len; diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 0fbbce40f2..90578da72b 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -878,7 +878,7 @@ def freeze_mpy(base_qstrs, raw_codes): print() print("extern const qstr_pool_t mp_qstr_const_pool;") print("const qstr_pool_t mp_qstr_frozen_const_pool = {") - print(" (qstr_pool_t*)&mp_qstr_const_pool, // previous pool") + print(" &mp_qstr_const_pool, // previous pool") print(" MP_QSTRnumber_of, // previous pool size") print(" %u, // allocated entries" % qstr_pool_alloc) print(" %u, // used entries" % len(new)) From 17ee507f0900f7be85dfaeee7f7e576b6a8c0230 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 4 May 2021 17:04:24 -0400 Subject: [PATCH 49/66] Remove overwrite of run_reason in main When `reload_requested` is detected, the run reason will no longer be automatically overwritten as an AUTO_RELOAD, making SUPERVISOR_RELOAD a detectable reload reason. Autoreload now sets the reload reason itself. --- main.c | 1 - supervisor/shared/autoreload.c | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index cd80ad0fa6..116436c0aa 100755 --- a/main.c +++ b/main.c @@ -340,7 +340,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { board_init(); } #endif - supervisor_set_run_reason(RUN_REASON_AUTO_RELOAD); reload_requested = false; return true; } diff --git a/supervisor/shared/autoreload.c b/supervisor/shared/autoreload.c index 1976f66470..c61c4220d7 100644 --- a/supervisor/shared/autoreload.c +++ b/supervisor/shared/autoreload.c @@ -30,6 +30,8 @@ #include "py/reload.h" #include "supervisor/shared/tick.h" +#include "shared-bindings/supervisor/Runtime.h" + static volatile uint32_t autoreload_delay_ms = 0; static bool autoreload_enabled = false; static bool autoreload_suspended = false; @@ -44,6 +46,7 @@ inline void autoreload_tick() { !autoreload_suspended && !reload_requested) { mp_raise_reload_exception(); reload_requested = true; + supervisor_set_run_reason(RUN_REASON_AUTO_RELOAD); supervisor_disable_tick(); } autoreload_delay_ms--; @@ -91,4 +94,5 @@ void autoreload_now() { } mp_raise_reload_exception(); reload_requested = true; + supervisor_set_run_reason(RUN_REASON_AUTO_RELOAD); } From 8bb3c6fd790ceb4d0d16eaf2a3054860ffb5ed16 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 4 May 2021 18:07:01 -0400 Subject: [PATCH 50/66] handle := defs in shared_bindings_matrix.py; update adafruit_hid --- docs/shared_bindings_matrix.py | 3 ++- frozen/Adafruit_CircuitPython_HID | 2 +- py/circuitpy_mpconfig.mk | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index e87769f06c..0590647e39 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -155,7 +155,8 @@ def get_settings_from_makefile(port_dir, board_name): settings = {} for line in contents.stdout.split('\n'): - m = re.match(r'^([A-Z][A-Z0-9_]*) = (.*)$', line) + # Handle both = and := definitions. + m = re.match(r'^([A-Z][A-Z0-9_]*) :?= (.*)$', line) if m: settings[m.group(1)] = m.group(2) diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index 829ba0f0a2..de68b7d457 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit 829ba0f0a2d8a63f7d0215c6c9fc821e14e52a93 +Subproject commit de68b7d4575151c1648c734559e59c2932965939 diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index ec4dea1975..fe212f6fb6 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -332,8 +332,8 @@ CFLAGS += -DCIRCUITPY_UHEAP=$(CIRCUITPY_UHEAP) CIRCUITPY_USB ?= 1 CFLAGS += -DCIRCUITPY_USB=$(CIRCUITPY_USB) -# If you need to count endpoints, use: -# $(shell expr $(USB_NUM_EP) '>=' 8) +# Compute this value once, so the shell command is not reinvoked many times. +USB_NUM_EP_8_OR_GREATER := $(shell expr $(USB_NUM_EP) '>=' 8) CIRCUITPY_USB_CDC ?= 1 CFLAGS += -DCIRCUITPY_USB_CDC=$(CIRCUITPY_USB_CDC) @@ -348,7 +348,7 @@ CIRCUITPY_USB_HID_ENABLED_DEFAULT = $(CIRCUITPY_USB_HID) CFLAGS += -DCIRCUITPY_USB_HID_ENABLED_DEFAULT=$(CIRCUITPY_USB_HID_ENABLED_DEFAULT) # MIDI is usually available if there are at least 8 endpoints. -CIRCUITPY_USB_MIDI ?= $(shell expr $(USB_NUM_EP) '>=' 8) +CIRCUITPY_USB_MIDI ?= $(USB_NUM_EP_8_OR_GREATER) CFLAGS += -DCIRCUITPY_USB_MIDI=$(CIRCUITPY_USB_MIDI) CIRCUITPY_USB_MIDI_ENABLED_DEFAULT = $(CIRCUITPY_USB_MIDI) CFLAGS += -DCIRCUITPY_USB_MIDI_ENABLED_DEFAULT=$(CIRCUITPY_USB_MIDI_ENABLED_DEFAULT) From 0fa6f4ed76f8bdc1dfc39f5253e4949b110b3788 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 4 May 2021 22:14:06 -0400 Subject: [PATCH 51/66] adding_usage_template --- docs/design_guide.rst | 49 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 04a2cc874f..cc6288ccd9 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -251,15 +251,17 @@ After the license comment:: **Hardware:** - * Adafruit `Device Description + * `Adafruit Device Description `_ (Product ID: ) **Software and Dependencies:** * Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads + * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + * Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register @@ -525,6 +527,51 @@ SPI Example spi.readinto(self.buf) return self.buf[0] + + +Class example template +-------------------------------------------------------------------------------- +When documenting classes, you could use the following template to illustrate the basic class functioning. +it is closely related with the simpletest, however this will display the information in the readthedocs +documentation. +The advantage of using this, is users will be familiar with this as it is used across libraries + +This is an example for a AHT20 temperature sensor. You could locate this after the class parameter +definitions. + + +.. code-block:: python + + """ + + **Quickstart: Importing and using the AHT10/AHT20 temperature sensor** + + Here is an example of using the :class:`AHTx0` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_ahtx0 + + Once this is done you can define your `board.I2C` object and define your sensor object + + .. code-block:: python + + i2c = board.I2C() # uses board.SCL and board.SDA + aht = adafruit_ahtx0.AHTx0(i2c) + + Now you have access to the temperature and humidity using + the :attr:`temperature` and :attr:`relative_humidity` attributes + + .. code-block:: python + + temperature = aht.temperature + relative_humidity = aht.relative_humidity + + """ + + Use composition -------------------------------------------------------------------------------- From 269d5bc80acea4f5e5f5b3598f2e22600c05b7bb Mon Sep 17 00:00:00 2001 From: Artyom Skrobov Date: Wed, 5 May 2021 09:01:47 +0300 Subject: [PATCH 52/66] qstr: One more cast could be avoided. --- py/qstr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/py/qstr.c b/py/qstr.c index 7df83e25cb..25012a3cb7 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -149,14 +149,14 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { new_pool_length = MICROPY_ALLOC_QSTR_ENTRIES_INIT; } #endif - mp_uint_t pool_size = sizeof(qstr_pool_t) + sizeof(const char *) * new_pool_length; - void *chunk = m_malloc_maybe(pool_size + sizeof(qstr_attr_t) * new_pool_length, true); - if (chunk == NULL) { + mp_uint_t pool_size = sizeof(qstr_pool_t) + + (sizeof(const char *) + sizeof(qstr_attr_t)) * new_pool_length; + qstr_pool_t *pool = (qstr_pool_t *)m_malloc_maybe(pool_size, true); + if (pool == NULL) { QSTR_EXIT(); m_malloc_fail(new_pool_length); } - qstr_pool_t *pool = (qstr_pool_t *)chunk; - pool->attrs = (qstr_attr_t *)(void *)((char *)chunk + pool_size); + pool->attrs = (qstr_attr_t *)(pool->qstrs + new_pool_length); pool->prev = MP_STATE_VM(last_pool); pool->total_prev_len = MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len; pool->alloc = new_pool_length; From 78b27c200085271455c879b97b18531672ab25b3 Mon Sep 17 00:00:00 2001 From: Alvaro Figueroa Date: Tue, 4 May 2021 15:16:01 +0000 Subject: [PATCH 53/66] Translated using Weblate (Spanish) Currently translated at 100.0% (971 of 971 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/es/ --- locale/es.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/locale/es.po b/locale/es.po index f9841bb4f4..e7d8855862 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-28 16:11+0000\n" +"PO-Revision-Date: 2021-05-05 15:32+0000\n" "Last-Translator: Alvaro Figueroa \n" "Language-Team: \n" "Language: es\n" @@ -3067,7 +3067,7 @@ msgstr "punto flotante demasiado grande" #: py/nativeglue.c msgid "float unsupported" -msgstr "" +msgstr "sin capacidades de flotante" #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" @@ -3159,7 +3159,7 @@ msgstr "identificador redefinido como nonlocal" #: py/compile.c msgid "import * not at module level" -msgstr "" +msgstr "import * no a nivel de módulo" #: py/persistentcode.c msgid "incompatible .mpy file" @@ -3707,7 +3707,7 @@ msgstr "solo se admiten segmentos con step=1 (alias None)" #: py/vm.c msgid "opcode" -msgstr "" +msgstr "código de operación" #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c @@ -3931,7 +3931,7 @@ msgstr "frecuencia de muestreo fuera de rango" #: py/modmicropython.c msgid "schedule queue full" -msgstr "" +msgstr "cola de planificación llena" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" From c78d2e1556f9e579d24f0a7b9aee0ad7e49ea822 Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Tue, 4 May 2021 02:53:05 +0000 Subject: [PATCH 54/66] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (971 of 971 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 03110715fc..cbba35b1f8 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-28 16:11+0000\n" +"PO-Revision-Date: 2021-05-05 15:32+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -3076,7 +3076,7 @@ msgstr "float muito grande" #: py/nativeglue.c msgid "float unsupported" -msgstr "" +msgstr "Flutuante não compatível" #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" @@ -3168,7 +3168,7 @@ msgstr "o identificador foi redefinido como não-local" #: py/compile.c msgid "import * not at module level" -msgstr "" +msgstr "importação * não está no nível do módulo" #: py/persistentcode.c msgid "incompatible .mpy file" @@ -3716,7 +3716,7 @@ msgstr "" #: py/vm.c msgid "opcode" -msgstr "" +msgstr "opcode" #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c @@ -3944,7 +3944,7 @@ msgstr "Taxa de amostragem fora do intervalo" #: py/modmicropython.c msgid "schedule queue full" -msgstr "" +msgstr "fila de espera cheia" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" From 278dcff1aa1c613b804e1bb5c0668a838ba28b21 Mon Sep 17 00:00:00 2001 From: Jonny Bergdahl Date: Tue, 4 May 2021 09:02:32 +0000 Subject: [PATCH 55/66] Translated using Weblate (Swedish) Currently translated at 100.0% (971 of 971 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/sv/ --- locale/sv.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/locale/sv.po b/locale/sv.po index 5797bd2c69..645c8d56f5 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-28 16:11+0000\n" +"PO-Revision-Date: 2021-05-05 15:32+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" "Language: sv\n" @@ -3042,7 +3042,7 @@ msgstr "flyttalet för stort" #: py/nativeglue.c msgid "float unsupported" -msgstr "" +msgstr "float stöds ej" #: shared-bindings/_stage/Text.c msgid "font must be 2048 bytes long" @@ -3134,7 +3134,7 @@ msgstr "identifieraren omdefinierad som icke-lokal" #: py/compile.c msgid "import * not at module level" -msgstr "" +msgstr "import * inte på modulnivå" #: py/persistentcode.c msgid "incompatible .mpy file" @@ -3678,7 +3678,7 @@ msgstr "endast segment med steg=1 (aka Ingen) stöds" #: py/vm.c msgid "opcode" -msgstr "" +msgstr "opkod" #: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/compare/compare.c #: extmod/ulab/code/numpy/vector/vector.c @@ -3903,7 +3903,7 @@ msgstr "samplingsfrekvens utanför räckvidden" #: py/modmicropython.c msgid "schedule queue full" -msgstr "" +msgstr "schemakön full" #: lib/utils/pyexec.c py/builtinimport.c msgid "script compilation not supported" From 8491b1263aefac160ad3b1733db1bd4ada4f0a6a Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Wed, 5 May 2021 17:48:04 +0200 Subject: [PATCH 56/66] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 8 ++++++++ locale/cs.po | 8 ++++++++ locale/de_DE.po | 8 ++++++++ locale/el.po | 8 ++++++++ locale/en_GB.po | 8 ++++++++ locale/es.po | 8 ++++++++ locale/fil.po | 8 ++++++++ locale/fr.po | 8 ++++++++ locale/hi.po | 8 ++++++++ locale/it_IT.po | 8 ++++++++ locale/ja.po | 8 ++++++++ locale/ko.po | 8 ++++++++ locale/nl.po | 8 ++++++++ locale/pl.po | 8 ++++++++ locale/pt_BR.po | 8 ++++++++ locale/sv.po | 8 ++++++++ locale/zh_Latn_pinyin.po | 8 ++++++++ 17 files changed, 136 insertions(+) diff --git a/locale/ID.po b/locale/ID.po index 6026486edc..7d576698ad 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -448,6 +448,10 @@ msgstr "" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "" @@ -1219,6 +1223,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "Nilai Unit ADC tidak valid" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "File BMP tidak valid" diff --git a/locale/cs.po b/locale/cs.po index b7ec951e2f..9cf5e17765 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -444,6 +444,10 @@ msgstr "" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "" @@ -1200,6 +1204,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index e72d49004d..d0c0eff063 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -450,6 +450,10 @@ msgstr "Versuche %d Blöcke zu allokieren" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Authentifizierungsfehler" @@ -1220,6 +1224,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "Ungültiger ADC-Einheitenwert" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Ungültige BMP-Datei" diff --git a/locale/el.po b/locale/el.po index 8106a86683..0b70b9a990 100644 --- a/locale/el.po +++ b/locale/el.po @@ -441,6 +441,10 @@ msgstr "" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "" @@ -1197,6 +1201,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index e08d5c00ae..4eb62b21ae 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -450,6 +450,10 @@ msgstr "Attempt to allocate %d blocks" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Authentication failure" @@ -1214,6 +1218,10 @@ msgstr "Invalid %q pin selection" msgid "Invalid ADC Unit value" msgstr "Invalid ADC unit value" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Invalid BMP file" diff --git a/locale/es.po b/locale/es.po index e7d8855862..bfd26dc145 100644 --- a/locale/es.po +++ b/locale/es.po @@ -454,6 +454,10 @@ msgstr "Tratando de localizar %d bloques" msgid "Attempted heap allocation when VM not running." msgstr "Asignación del montículo mientras la VM no esta ejecutándose." +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Fallo de autenticación" @@ -1231,6 +1235,10 @@ msgstr "selección inválida de pin %q" msgid "Invalid ADC Unit value" msgstr "Valor de unidad de ADC no válido" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Archivo BMP inválido" diff --git a/locale/fil.po b/locale/fil.po index 42862d7501..07ea67a7d6 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -444,6 +444,10 @@ msgstr "" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "" @@ -1212,6 +1216,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Mali ang BMP file" diff --git a/locale/fr.po b/locale/fr.po index 46bbcf7e84..5b8c112384 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -456,6 +456,10 @@ msgstr "" "Tentative d'allocation à la pile quand la Machine Virtuelle n'est pas en " "exécution." +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Échec d'authentification" @@ -1243,6 +1247,10 @@ msgstr "Sélection de broche %q invalide" msgid "Invalid ADC Unit value" msgstr "Valeur d'unité ADC non valide" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Fichier BMP invalide" diff --git a/locale/hi.po b/locale/hi.po index 5e55b35421..6736f746ea 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -441,6 +441,10 @@ msgstr "" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "" @@ -1197,6 +1201,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index 5feca60282..559ffd9fb6 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -453,6 +453,10 @@ msgstr "Provo ad allocare %d blocchi" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Autenticazione Fallita" @@ -1221,6 +1225,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "File BMP non valido" diff --git a/locale/ja.po b/locale/ja.po index f7fbaacf08..2a33e1f4dc 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -446,6 +446,10 @@ msgstr "%d個のブロックの確保を試みました" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "認証失敗" @@ -1210,6 +1214,10 @@ msgstr "不正な%qピン選択" msgid "Invalid ADC Unit value" msgstr "不正なADCユニット値" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "不正なBMPファイル" diff --git a/locale/ko.po b/locale/ko.po index b9293d00e0..e6fa831dd8 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -442,6 +442,10 @@ msgstr "" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "" @@ -1200,6 +1204,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index 48861d929c..b2959ee892 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -444,6 +444,10 @@ msgstr "Poging om %d blokken toe te wijzen" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Authenticatiefout" @@ -1211,6 +1215,10 @@ msgstr "Ongeldige %q pin selectie" msgid "Invalid ADC Unit value" msgstr "Ongeldige ADC Unit waarde" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Ongeldig BMP bestand" diff --git a/locale/pl.po b/locale/pl.po index c11d260b1e..8d8a9e51f4 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -446,6 +446,10 @@ msgstr "Próba przydzielenia %d bloków" msgid "Attempted heap allocation when VM not running." msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Błąd autoryzacji" @@ -1210,6 +1214,10 @@ msgstr "" msgid "Invalid ADC Unit value" msgstr "" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Zły BMP" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index cbba35b1f8..c6517e96ec 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -455,6 +455,10 @@ msgid "Attempted heap allocation when VM not running." msgstr "" "Tentativa de alocação das pilhas quando o VM não estiver em funcionamento." +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Houve um falha na autenticação" @@ -1234,6 +1238,10 @@ msgstr "Seleção inválida dos pinos %q" msgid "Invalid ADC Unit value" msgstr "Valor inválido da unidade ADC" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Arquivo BMP inválido" diff --git a/locale/sv.po b/locale/sv.po index 645c8d56f5..1f91867c7f 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -449,6 +449,10 @@ msgstr "Försök att tilldela %d block" msgid "Attempted heap allocation when VM not running." msgstr "Försök till heap-allokering när den virtuella maskinen inte är igång." +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "Autentiseringsfel" @@ -1218,6 +1222,10 @@ msgstr "Ogiltigt val av %q pinne" msgid "Invalid ADC Unit value" msgstr "Ogiltigt ADC-enhetsvärde" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Ogiltig BMP-fil" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index a48d20c912..ceb891ccd0 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -451,6 +451,10 @@ msgstr "cháng shì fēn pèi %d kuài" msgid "Attempted heap allocation when VM not running." msgstr "dāng VM bú yùn xíng shí, cháng shì duī fēn pèi." +#: shared-bindings/wifi/Radio.c +msgid "AuthMode.OPEN is not used with password" +msgstr "" + #: shared-bindings/wifi/Radio.c msgid "Authentication failure" msgstr "shēn fèn yàn zhèng shī bài" @@ -1220,6 +1224,10 @@ msgstr "wú xiào %q yǐn jiǎo xuǎn zé" msgid "Invalid ADC Unit value" msgstr "Wúxiào de ADC dānwèi zhí" +#: ports/esp32s2/common-hal/wifi/Radio.c +msgid "Invalid AuthMode" +msgstr "" + #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" msgstr "Wúxiào de BMP wénjiàn" From 0f60a3b997b26b5d0a67d547247867d0b63bb2f0 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 5 May 2021 12:18:26 -0400 Subject: [PATCH 57/66] Better_phrasing --- docs/design_guide.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index cc6288ccd9..e91060f776 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -529,15 +529,14 @@ SPI Example -Class example template +Class documentation example template -------------------------------------------------------------------------------- -When documenting classes, you could use the following template to illustrate the basic class functioning. -it is closely related with the simpletest, however this will display the information in the readthedocs +When documenting classes, you should use the following template to illustrate basic usage. +It is similar with the simpletest example, however this will display the information in the Read The Docs documentation. -The advantage of using this, is users will be familiar with this as it is used across libraries +The advantage of using this template is it makes the documentation consistent across the libraries. -This is an example for a AHT20 temperature sensor. You could locate this after the class parameter -definitions. +This is an example for a AHT20 temperature sensor. Include the following after the class parameter: .. code-block:: python From fc8e1c4c2e253d5e52649463a33bce118d83b106 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 5 May 2021 12:35:12 -0400 Subject: [PATCH 58/66] address review comments --- locale/circuitpython.pot | 24 +- .../asf4_conf/samd21/hpl_usb_config.h | 382 -------- .../atmel-samd/asf4_conf/samd21/usbd_config.h | 850 ------------------ .../asf4_conf/samd51/hpl_usb_config.h | 382 -------- .../atmel-samd/asf4_conf/samd51/usbd_config.h | 850 ------------------ .../asf4_conf/same51/hpl_usb_config.h | 382 -------- .../atmel-samd/asf4_conf/same51/usbd_config.h | 850 ------------------ .../asf4_conf/same54/hpl_usb_config.h | 382 -------- .../atmel-samd/asf4_conf/same54/usbd_config.h | 850 ------------------ py/circuitpy_mpconfig.mk | 28 +- shared-bindings/storage/__init__.c | 4 +- shared-bindings/usb_hid/Device.c | 19 +- supervisor/shared/safe_mode.c | 31 +- supervisor/shared/safe_mode.h | 2 + supervisor/shared/usb/usb_desc.c | 5 +- 15 files changed, 62 insertions(+), 4979 deletions(-) delete mode 100644 ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h delete mode 100644 ports/atmel-samd/asf4_conf/samd21/usbd_config.h delete mode 100644 ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h delete mode 100644 ports/atmel-samd/asf4_conf/samd51/usbd_config.h delete mode 100644 ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h delete mode 100644 ports/atmel-samd/asf4_conf/same51/usbd_config.h delete mode 100644 ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h delete mode 100644 ports/atmel-samd/asf4_conf/same54/usbd_config.h diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index ac60b9384f..f3483b3e99 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -608,15 +608,11 @@ msgstr "" msgid "Can't set CCCD on local Characteristic" msgstr "" -#: shared-bindings/usb_cdc/__init__.c shared-bindings/usb_hid/__init__.c -#: shared-bindings/usb_midi/__init__.c +#: shared-bindings/storage/__init__.c shared-bindings/usb_cdc/__init__.c +#: shared-bindings/usb_hid/__init__.c shared-bindings/usb_midi/__init__.c msgid "Cannot change USB devices now" msgstr "" -#: shared-bindings/storage/__init__.c -msgid "Cannot change usb devices now" -msgstr "" - #: shared-bindings/_bleio/Adapter.c msgid "Cannot create a new Adapter; use _bleio.adapter;" msgstr "" @@ -1638,10 +1634,6 @@ msgstr "" msgid "Not connected" msgstr "" -#: supervisor/shared/usb/usb_desc.c -msgid "Not enough USB endpoints" -msgstr "" - #: shared-bindings/audiobusio/I2SOut.c shared-bindings/audioio/AudioOut.c #: shared-bindings/audiopwmio/PWMAudioOut.c msgid "Not playing" @@ -2149,10 +2141,6 @@ msgstr "" msgid "To exit, please reset the board without " msgstr "" -#: supervisor/shared/usb/usb_desc.c -msgid "Too many USB interface names" -msgstr "" - #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/raspberrypi/common-hal/audiobusio/I2SOut.c msgid "Too many channels in sample." @@ -2206,6 +2194,14 @@ msgstr "" msgid "USB Error" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "USB devices need more endpoints than are available." +msgstr "" + +#: supervisor/shared/safe_mode.c +msgid "USB devices specify too many interface names." +msgstr "" + #: shared-bindings/_bleio/UUID.c msgid "UUID integer value must be 0-0xffff" msgstr "" diff --git a/ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h deleted file mode 100644 index 51c71cb823..0000000000 --- a/ports/atmel-samd/asf4_conf/samd21/hpl_usb_config.h +++ /dev/null @@ -1,382 +0,0 @@ -/* Auto-generated config file hpl_usb_config.h */ -#ifndef HPL_USB_CONFIG_H -#define HPL_USB_CONFIG_H - -// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. -// So provide cache space for all of them. - -#define CONF_USB_EP1_CACHE 64 -#define CONF_USB_EP1_I_CACHE 64 - -#define CONF_USB_EP2_CACHE 64 -#define CONF_USB_EP2_I_CACHE 64 - -#define CONF_USB_EP3_CACHE 64 -#define CONF_USB_EP3_I_CACHE 64 - -#define CONF_USB_EP4_CACHE 64 -#define CONF_USB_EP4_I_CACHE 64 - -#define CONF_USB_EP5_CACHE 64 -#define CONF_USB_EP5_I_CACHE 64 - -#define CONF_USB_EP6_CACHE 64 -#define CONF_USB_EP6_I_CACHE 64 - -#define CONF_USB_EP7_CACHE 64 -#define CONF_USB_EP7_I_CACHE 64 - - -// <<< Use Configuration Wizard in Context Menu >>> - -#define CONF_USB_N_0 0 -#define CONF_USB_N_1 1 -#define CONF_USB_N_2 2 -#define CONF_USB_N_3 3 -#define CONF_USB_N_4 4 -#define CONF_USB_N_5 5 -#define CONF_USB_N_6 6 -#define CONF_USB_N_7 7 -#define CONF_USB_N_8 8 -#define CONF_USB_N_9 9 -#define CONF_USB_N_10 10 -#define CONF_USB_N_11 11 -#define CONF_USB_N_12 12 -#define CONF_USB_N_13 13 -#define CONF_USB_N_14 14 -#define CONF_USB_N_15 15 - -#define CONF_USB_D_EP_N_MAX (USB_EPT_NUM - 1) -#define CONF_USB_D_N_EP_MAX (CONF_USB_D_EP_N_MAX * 2 - 1) - -// USB Device HAL Configuration - -// Max number of endpoints supported -// Limits the number of endpoints (described by EP address) can be used in app. -// NOTE(tannewt): This not only limits the number of endpoints but also the -// addresses. In other words, even if you use endpoint 6 you need to set this to 11. -// 1 (EP0 only) -// 2 (EP0 + 1 endpoint) -// 3 (EP0 + 2 endpoints) -// 4 (EP0 + 3 endpoints) -// 5 (EP0 + 4 endpoints) -// 6 (EP0 + 5 endpoints) -// 7 (EP0 + 6 endpoints) -// 8 (EP0 + 7 endpoints) -// Max possible (by "Max Endpoint Number" config) -// usbd_num_ep_sp -#ifndef CONF_USB_D_NUM_EP_SP -#define CONF_USB_D_NUM_EP_SP CONF_USB_D_N_EP_MAX -#endif - -// - -// Max Endpoint Number supported -// Limits the max endpoint number. -// USB endpoint address is constructed by direction and endpoint number. Bit 8 of address set indicates the direction is IN. E.g., EP0x81 and EP0x01 have the same endpoint number, 1. -// Reduce the value according to specific device design, to cut-off memory usage. -// 0 (only EP0) -// 1 (EP 0x81 or 0x01) -// 2 (EP 0x82 or 0x02) -// 3 (EP 0x83 or 0x03) -// 4 (EP 0x84 or 0x04) -// 5 (EP 0x85 or 0x05) -// 6 (EP 0x86 or 0x06) -// 7 (EP 0x87 or 0x07) -// Max possible (by HW) -// The number of physical endpoints - 1 -// usbd_arch_max_ep_n -#ifndef CONF_USB_D_MAX_EP_N -#define CONF_USB_D_MAX_EP_N CONF_USB_D_EP_N_MAX -#endif - -// USB Speed Limit -// Limits the working speed of the device. -// Full speed -// Low Speed -// usbd_arch_speed -#ifndef CONF_USB_D_SPEED -#define CONF_USB_D_SPEED USB_SPEED_FS -#endif - -// Cache buffer size for EP0 -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// EP0 is default control endpoint, so cache must be used to be able to receive SETUP packet at any time. -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// usb_arch_ep0_cache -#ifndef CONF_USB_EP0_CACHE -#define CONF_USB_EP0_CACHE 64 -#endif - -// Cache configuration EP1 -// Cache buffer size for EP1 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep1_cache -#ifndef CONF_USB_EP1_CACHE -#define CONF_USB_EP1_CACHE 0 -#endif - -// Cache buffer size for EP1 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep1_I_CACHE -#ifndef CONF_USB_EP1_I_CACHE -#define CONF_USB_EP1_I_CACHE 0 -#endif -// - -// Cache configuration EP2 -// Cache buffer size for EP2 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep2_cache -#ifndef CONF_USB_EP2_CACHE -#define CONF_USB_EP2_CACHE 0 -#endif - -// Cache buffer size for EP2 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep2_I_CACHE -#ifndef CONF_USB_EP2_I_CACHE -#define CONF_USB_EP2_I_CACHE 0 -#endif -// - -// Cache configuration EP3 -// Cache buffer size for EP3 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep3_cache -#ifndef CONF_USB_EP3_CACHE -#define CONF_USB_EP3_CACHE 0 -#endif - -// Cache buffer size for EP3 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep3_I_CACHE -#ifndef CONF_USB_EP3_I_CACHE -#define CONF_USB_EP3_I_CACHE 0 -#endif -// - -// Cache configuration EP4 -// Cache buffer size for EP4 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep4_cache -#ifndef CONF_USB_EP4_CACHE -#define CONF_USB_EP4_CACHE 0 -#endif - -// Cache buffer size for EP4 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep4_I_CACHE -#ifndef CONF_USB_EP4_I_CACHE -#define CONF_USB_EP4_I_CACHE 0 -#endif -// - -// Cache configuration EP5 -// Cache buffer size for EP5 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep5_cache -#ifndef CONF_USB_EP5_CACHE -#define CONF_USB_EP5_CACHE 0 -#endif - -// Cache buffer size for EP5 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep5_I_CACHE -#ifndef CONF_USB_EP5_I_CACHE -#define CONF_USB_EP5_I_CACHE 0 -#endif -// - -// Cache configuration EP6 -// Cache buffer size for EP6 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep6_cache -#ifndef CONF_USB_EP6_CACHE -#define CONF_USB_EP6_CACHE 0 -#endif - -// Cache buffer size for EP6 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep6_I_CACHE -#ifndef CONF_USB_EP6_I_CACHE -#define CONF_USB_EP6_I_CACHE 0 -#endif -// - -// Cache configuration EP7 -// Cache buffer size for EP7 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep7_cache -#ifndef CONF_USB_EP7_CACHE -#define CONF_USB_EP7_CACHE 0 -#endif - -// Cache buffer size for EP7 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep7_I_CACHE -#ifndef CONF_USB_EP7_I_CACHE -#define CONF_USB_EP7_I_CACHE 0 -#endif -// - -// <<< end of configuration section >>> - -#endif // HPL_USB_CONFIG_H diff --git a/ports/atmel-samd/asf4_conf/samd21/usbd_config.h b/ports/atmel-samd/asf4_conf/samd21/usbd_config.h deleted file mode 100644 index b0f570b5e5..0000000000 --- a/ports/atmel-samd/asf4_conf/samd21/usbd_config.h +++ /dev/null @@ -1,850 +0,0 @@ -/* Auto-generated config file usbd_config.h */ -#ifndef USBD_CONFIG_H -#define USBD_CONFIG_H - -// <<< Use Configuration Wizard in Context Menu >>> - -// ---- USB Device Stack Core Options ---- - -// High Speed Support -// Enable high speed specific descriptors support, e.g., DeviceQualifierDescriptor and OtherSpeedConfiguration Descriptor. -// High speed support require descriptors description array on start, for LS/FS and HS support in first and second place. -// usbd_hs_sp -#ifndef CONF_USBD_HS_SP -#define CONF_USBD_HS_SP 0 -#endif - -// ---- USB Device Stack Composite Options ---- - -// Enable String Descriptors -// usb_composite_str_en -#ifndef CONF_USB_COMPOSITE_STR_EN -#define CONF_USB_COMPOSITE_STR_EN 0 -#endif -// Language IDs -// Language IDs in c format, split by comma (E.g., 0x0409 ...) -// usb_composite_langid -#ifndef CONF_USB_COMPOSITE_LANGID -#define CONF_USB_COMPOSITE_LANGID "0x0409" -#endif - -#ifndef CONF_USB_COMPOSITE_LANGID_DESC -#define CONF_USB_COMPOSITE_LANGID_DESC -#endif -// - -// Composite Device Descriptor - -// bcdUSB -// <0x0200=> USB 2.0 version -// <0x0210=> USB 2.1 version -// usb_composite_bcdusb -#ifndef CONF_USB_COMPOSITE_BCDUSB -#define CONF_USB_COMPOSITE_BCDUSB 0x200 -#endif - -// bMaxPackeSize0 -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_bmaxpksz0 -#ifndef CONF_USB_COMPOSITE_BMAXPKSZ0 -#define CONF_USB_COMPOSITE_BMAXPKSZ0 0x40 -#endif - -// idVender <0x0000-0xFFFF> -// usb_composite_idvender -#ifndef CONF_USB_COMPOSITE_IDVENDER -#define CONF_USB_COMPOSITE_IDVENDER 0x3eb -#endif - -// idProduct <0x0000-0xFFFF> -// usb_composite_idproduct -#ifndef CONF_USB_COMPOSITE_IDPRODUCT -#define CONF_USB_COMPOSITE_IDPRODUCT 0x2421 -#endif - -// bcdDevice <0x0000-0xFFFF> -// usb_composite_bcddevice -#ifndef CONF_USB_COMPOSITE_BCDDEVICE -#define CONF_USB_COMPOSITE_BCDDEVICE 0x100 -#endif - -// Enable string descriptor of iManufact -// usb_composite_imanufact_en -#ifndef CONF_USB_COMPOSITE_IMANUFACT_EN -#define CONF_USB_COMPOSITE_IMANUFACT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT -#define CONF_USB_COMPOSITE_IMANUFACT (CONF_USB_COMPOSITE_IMANUFACT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN)) -#endif - -// Unicode string of iManufact -// usb_composite_imanufact_str -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR -#define CONF_USB_COMPOSITE_IMANUFACT_STR "Atmel" -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#define CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#endif - -// - -// Enable string descriptor of iProduct -// usb_composite_iproduct_en -#ifndef CONF_USB_COMPOSITE_IPRODUCT_EN -#define CONF_USB_COMPOSITE_IPRODUCT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT -#define CONF_USB_COMPOSITE_IPRODUCT \ - (CONF_USB_COMPOSITE_IPRODUCT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN)) -#endif - -// Unicode string of iProduct -// usb_composite_iproduct_str -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR -#define CONF_USB_COMPOSITE_IPRODUCT_STR "Composite Demo" -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#define CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#endif - -// - -// Enable string descriptor of iSerialNum -// usb_composite_iserialnum_en -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_EN -#define CONF_USB_COMPOSITE_ISERIALNUM_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM -#define CONF_USB_COMPOSITE_ISERIALNUM \ - (CONF_USB_COMPOSITE_ISERIALNUM_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN)) -#endif - -// Unicode string of iSerialNum -// usb_composite_iserialnum_str -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR -#define CONF_USB_COMPOSITE_ISERIALNUM_STR "123456789ABCDEF" -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#define CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#endif - -// - -// bNumConfigurations <0x01-0xFF> -// usb_composite_bnumconfig -#ifndef CONF_USB_COMPOSITE_BNUMCONFIG -#define CONF_USB_COMPOSITE_BNUMCONFIG 0x1 -#endif - -// - -// Composite Configuration Descriptor -// bConfigurationValue <0x01-0xFF> -// usb_composite_bconfigval -#ifndef CONF_USB_COMPOSITE_BCONFIGVAL -#define CONF_USB_COMPOSITE_BCONFIGVAL 0x1 -#endif -// Enable string descriptor of iConfig -// usb_composite_iconfig_en -#ifndef CONF_USB_COMPOSITE_ICONFIG_EN -#define CONF_USB_COMPOSITE_ICONFIG_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG -#define CONF_USB_COMPOSITE_ICONFIG \ - (CONF_USB_COMPOSITE_ICONFIG_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN \ - + CONF_USB_COMPOSITE_ICONFIG_EN)) -#endif - -// Unicode string of iConfig -// usb_composite_iconfig_str -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR -#define CONF_USB_COMPOSITE_ICONFIG_STR "" -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#define CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#endif - -// - -// bmAttributes -// <0x80=> Bus power supply, not support for remote wakeup -// <0xA0=> Bus power supply, support for remote wakeup -// <0xC0=> Self powered, not support for remote wakeup -// <0xE0=> Self powered, support for remote wakeup -// usb_composite_bmattri -#ifndef CONF_USB_COMPOSITE_BMATTRI -#define CONF_USB_COMPOSITE_BMATTRI 0x80 -#endif - -// bMaxPower <0x00-0xFF> -// usb_composite_bmaxpower -#ifndef CONF_USB_COMPOSITE_BMAXPOWER -#define CONF_USB_COMPOSITE_BMAXPOWER 0x32 -#endif -// - -// CDC ACM Support -// usb_composite_cdc_acm_support -#ifndef CONF_USB_COMPOSITE_CDC_ACM_EN -#define CONF_USB_COMPOSITE_CDC_ACM_EN 1 -#endif - -// CDC ACM Comm Interrupt IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR 0x82 -#endif - -// CDC ACM Comm Interrupt IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_comm_int_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_data_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR 0x81 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS 0x0200 -#endif - -// CDC ACM Data BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_cdc_acm_data_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR 0x1 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS 0x0200 -#endif - -// CDC ACM Echo Demo generation -// conf_usb_composite_cdc_echo_demo -// Invoke cdcdf_acm_demo_init(buf[wMaxPacketSize]) to enable the echo demo. -// Buf is packet buffer for data receive and echo back. -// The buffer is 4 byte aligned to support DMA. -#ifndef CONF_USB_COMPOSITE_CDC_ECHO_DEMO -#define CONF_USB_COMPOSITE_CDC_ECHO_DEMO 0 -#endif - -// - -// HID Mouse Support -// usb_composite_hid_mouse_support -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_EN -#define CONF_USB_COMPOSITE_HID_MOUSE_EN 0 -#endif - -// HID Mouse INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_mouse_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR 0x83 -#endif - -// HID Mouse INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_mouse_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ 0x8 -#endif - -// HID Mouse Move Demo generation -// conf_usb_composite_hid_mouse_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Button1 and button3 are the pins used for mouse moving left and right. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_DEMO -#define CONF_USB_COMPOSITE_HID_MOUSE_DEMO 0 -#endif - -// - -// HID Keyboard Support -// usb_composite_hid_keyboard_support -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_EN -#define CONF_USB_COMPOSITE_HID_KEYBOARD_EN 0 -#endif - -// HID Keyboard INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_keyboard_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR 0x84 -#endif - -// HID Keyboard INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ 0x8 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_keyboard_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR 0x2 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ 0x8 -#endif - -// HID Keyboard Caps Lock Demo generation -// conf_usb_composite_hid_keyboard_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Buffon2 is the pin used for keyboard CAPS LOCK simulation. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO -#define CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO 0 -#endif - -// - -// HID Generic Support -// usb_composite_hid_generic_support -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_EN -#define CONF_USB_COMPOSITE_HID_GENERIC_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN 53 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT \ - 0x06, 0xFF, 0xFF, 0x09, 0x01, 0xA1, 0x01, 0x09, 0x02, 0x09, 0x03, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, \ - 0x40, 0x81, 0x02, 0x09, 0x04, 0x09, 0x05, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x40, 0x91, 0x02, \ - 0x09, 0x06, 0x09, 0x07, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x04, 0xB1, 0x02, 0xC0 -#endif - -// HID Generic INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_generic_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR 0x85 -#endif - -// HID Generic INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_generic_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ 0x40 -#endif - -// HID Generic INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_generic_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR 0x3 -#endif - -// HID Generic INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_hid_generic_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ 0x40 -#endif - -// - -// MSC Support -// usb_composite_msc_support -#ifndef CONF_USB_COMPOSITE_MSC_EN -#define CONF_USB_COMPOSITE_MSC_EN 0 -#endif - -// MSC BULK Endpoints wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_msc_bulk_maxpksz -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ 0x0040 -#endif - -// MSC BULK Endpoints wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_msc_bulk_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS 0x0200 -#endif - -// MSC BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_msc_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR 0x86 -#endif - -// MSC BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_msc_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR 0x04 -#endif - -// Enable Demo code for Disk LUN handling -// usb_composite_msc_demo_en -#ifndef CONF_USB_COMPOSITE_MSC_LUN_DEMO -#define CONF_USB_COMPOSITE_MSC_LUN_DEMO 1 -#endif - -// Disk access cache/buffer of sectors if non-RAM disk (e.g., SD/MMC) enabled <1-64> -// conf_usb_msc_lun_buf_sectors -#ifndef CONF_USB_MSC_LUN_BUF_SECTORS -#define CONF_USB_MSC_LUN_BUF_SECTORS 4 -#endif - -// Enable Demo for RAM Disk -// conf_usb_msc_lun0_enable -#ifndef CONF_USB_MSC_LUN0_ENABLE -#define CONF_USB_MSC_LUN0_ENABLE 1 -#endif - -#ifndef CONF_USB_MSC_LUN0_TYPE -#define CONF_USB_MSC_LUN0_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun0_rmb -#ifndef CONF_USB_MSC_LUN0_RMB -#define CONF_USB_MSC_LUN0_RMB 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN0_ISO -#define CONF_USB_MSC_LUN0_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ECMA -#define CONF_USB_MSC_LUN0_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ANSI -#define CONF_USB_MSC_LUN0_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_REPO -#define CONF_USB_MSC_LUN0_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN0_FACTORY -#define CONF_USB_MSC_LUN0_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT -#define CONF_USB_MSC_LUN0_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT_VERSION -#define CONF_USB_MSC_LUN0_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// Windows will not show disk less than 20K, so 22K is used to reserve more RAM for APP -// conf_usb_msc_lun0_capacity - -#ifndef CONF_USB_MSC_LUN0_CAPACITY -#define CONF_USB_MSC_LUN0_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN0_BLOCK_SIZE -#define CONF_USB_MSC_LUN0_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN0_CAPACITY * 1024 / CONF_USB_MSC_LUN0_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for SD/MMC Disk -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_enable -#ifndef CONF_USB_MSC_LUN1_ENABLE -#define CONF_USB_MSC_LUN1_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN1_TYPE -#define CONF_USB_MSC_LUN1_TYPE 0x00 -#endif - -// The disk is removable -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_rmb -#ifndef CONF_USB_MSC_LUN1_RMB -#define CONF_USB_MSC_LUN1_RMB 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN1_ISO -#define CONF_USB_MSC_LUN1_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ECMA -#define CONF_USB_MSC_LUN1_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ANSI -#define CONF_USB_MSC_LUN1_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_REPO -#define CONF_USB_MSC_LUN1_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN1_FACTORY -#define CONF_USB_MSC_LUN1_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT -#define CONF_USB_MSC_LUN1_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT_VERSION -#define CONF_USB_MSC_LUN1_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_CAPACITY -#define CONF_USB_MSC_LUN1_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN1_BLOCK_SIZE -#define CONF_USB_MSC_LUN1_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN1_CAPACITY * 1024 / CONF_USB_MSC_LUN1_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 2 -// conf_usb_msc_lun2_enable -#ifndef CONF_USB_MSC_LUN2_ENABLE -#define CONF_USB_MSC_LUN2_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN2_TYPE -#define CONF_USB_MSC_LUN2_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun2_rmb -#ifndef CONF_USB_MSC_LUN2_RMB -#define CONF_USB_MSC_LUN2_RMB 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN2_ISO -#define CONF_USB_MSC_LUN2_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ECMA -#define CONF_USB_MSC_LUN2_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ANSI -#define CONF_USB_MSC_LUN2_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_REPO -#define CONF_USB_MSC_LUN2_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN2_FACTORY -#define CONF_USB_MSC_LUN2_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT -#define CONF_USB_MSC_LUN2_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT_VERSION -#define CONF_USB_MSC_LUN2_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun2_capacity - -#ifndef CONF_USB_MSC_LUN2_CAPACITY -#define CONF_USB_MSC_LUN2_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN2_BLOCK_SIZE -#define CONF_USB_MSC_LUN2_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN2_CAPACITY * 1024 / CONF_USB_MSC_LUN2_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 3 -// conf_usb_msc_lun3_enable -#ifndef CONF_USB_MSC_LUN3_ENABLE -#define CONF_USB_MSC_LUN3_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN3_TYPE -#define CONF_USB_MSC_LUN3_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun3_rmb -#ifndef CONF_USB_MSC_LUN3_RMB -#define CONF_USB_MSC_LUN3_RMB 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN3_ISO -#define CONF_USB_MSC_LUN3_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ECMA -#define CONF_USB_MSC_LUN3_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ANSI -#define CONF_USB_MSC_LUN3_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_REPO -#define CONF_USB_MSC_LUN3_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN3_FACTORY -#define CONF_USB_MSC_LUN3_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT -#define CONF_USB_MSC_LUN3_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT_VERSION -#define CONF_USB_MSC_LUN3_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun3_capacity - -#ifndef CONF_USB_MSC_LUN3_CAPACITY -#define CONF_USB_MSC_LUN3_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN3_BLOCK_SIZE -#define CONF_USB_MSC_LUN3_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN3_CAPACITY * 1024 / CONF_USB_MSC_LUN3_BLOCK_SIZE - 1) -#endif - -// - -// -// - -// <<< end of configuration section >>> - -#endif // USBD_CONFIG_H diff --git a/ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h deleted file mode 100644 index 51c71cb823..0000000000 --- a/ports/atmel-samd/asf4_conf/samd51/hpl_usb_config.h +++ /dev/null @@ -1,382 +0,0 @@ -/* Auto-generated config file hpl_usb_config.h */ -#ifndef HPL_USB_CONFIG_H -#define HPL_USB_CONFIG_H - -// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. -// So provide cache space for all of them. - -#define CONF_USB_EP1_CACHE 64 -#define CONF_USB_EP1_I_CACHE 64 - -#define CONF_USB_EP2_CACHE 64 -#define CONF_USB_EP2_I_CACHE 64 - -#define CONF_USB_EP3_CACHE 64 -#define CONF_USB_EP3_I_CACHE 64 - -#define CONF_USB_EP4_CACHE 64 -#define CONF_USB_EP4_I_CACHE 64 - -#define CONF_USB_EP5_CACHE 64 -#define CONF_USB_EP5_I_CACHE 64 - -#define CONF_USB_EP6_CACHE 64 -#define CONF_USB_EP6_I_CACHE 64 - -#define CONF_USB_EP7_CACHE 64 -#define CONF_USB_EP7_I_CACHE 64 - - -// <<< Use Configuration Wizard in Context Menu >>> - -#define CONF_USB_N_0 0 -#define CONF_USB_N_1 1 -#define CONF_USB_N_2 2 -#define CONF_USB_N_3 3 -#define CONF_USB_N_4 4 -#define CONF_USB_N_5 5 -#define CONF_USB_N_6 6 -#define CONF_USB_N_7 7 -#define CONF_USB_N_8 8 -#define CONF_USB_N_9 9 -#define CONF_USB_N_10 10 -#define CONF_USB_N_11 11 -#define CONF_USB_N_12 12 -#define CONF_USB_N_13 13 -#define CONF_USB_N_14 14 -#define CONF_USB_N_15 15 - -#define CONF_USB_D_EP_N_MAX (USB_EPT_NUM - 1) -#define CONF_USB_D_N_EP_MAX (CONF_USB_D_EP_N_MAX * 2 - 1) - -// USB Device HAL Configuration - -// Max number of endpoints supported -// Limits the number of endpoints (described by EP address) can be used in app. -// NOTE(tannewt): This not only limits the number of endpoints but also the -// addresses. In other words, even if you use endpoint 6 you need to set this to 11. -// 1 (EP0 only) -// 2 (EP0 + 1 endpoint) -// 3 (EP0 + 2 endpoints) -// 4 (EP0 + 3 endpoints) -// 5 (EP0 + 4 endpoints) -// 6 (EP0 + 5 endpoints) -// 7 (EP0 + 6 endpoints) -// 8 (EP0 + 7 endpoints) -// Max possible (by "Max Endpoint Number" config) -// usbd_num_ep_sp -#ifndef CONF_USB_D_NUM_EP_SP -#define CONF_USB_D_NUM_EP_SP CONF_USB_D_N_EP_MAX -#endif - -// - -// Max Endpoint Number supported -// Limits the max endpoint number. -// USB endpoint address is constructed by direction and endpoint number. Bit 8 of address set indicates the direction is IN. E.g., EP0x81 and EP0x01 have the same endpoint number, 1. -// Reduce the value according to specific device design, to cut-off memory usage. -// 0 (only EP0) -// 1 (EP 0x81 or 0x01) -// 2 (EP 0x82 or 0x02) -// 3 (EP 0x83 or 0x03) -// 4 (EP 0x84 or 0x04) -// 5 (EP 0x85 or 0x05) -// 6 (EP 0x86 or 0x06) -// 7 (EP 0x87 or 0x07) -// Max possible (by HW) -// The number of physical endpoints - 1 -// usbd_arch_max_ep_n -#ifndef CONF_USB_D_MAX_EP_N -#define CONF_USB_D_MAX_EP_N CONF_USB_D_EP_N_MAX -#endif - -// USB Speed Limit -// Limits the working speed of the device. -// Full speed -// Low Speed -// usbd_arch_speed -#ifndef CONF_USB_D_SPEED -#define CONF_USB_D_SPEED USB_SPEED_FS -#endif - -// Cache buffer size for EP0 -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// EP0 is default control endpoint, so cache must be used to be able to receive SETUP packet at any time. -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// usb_arch_ep0_cache -#ifndef CONF_USB_EP0_CACHE -#define CONF_USB_EP0_CACHE 64 -#endif - -// Cache configuration EP1 -// Cache buffer size for EP1 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep1_cache -#ifndef CONF_USB_EP1_CACHE -#define CONF_USB_EP1_CACHE 0 -#endif - -// Cache buffer size for EP1 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep1_I_CACHE -#ifndef CONF_USB_EP1_I_CACHE -#define CONF_USB_EP1_I_CACHE 0 -#endif -// - -// Cache configuration EP2 -// Cache buffer size for EP2 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep2_cache -#ifndef CONF_USB_EP2_CACHE -#define CONF_USB_EP2_CACHE 0 -#endif - -// Cache buffer size for EP2 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep2_I_CACHE -#ifndef CONF_USB_EP2_I_CACHE -#define CONF_USB_EP2_I_CACHE 0 -#endif -// - -// Cache configuration EP3 -// Cache buffer size for EP3 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep3_cache -#ifndef CONF_USB_EP3_CACHE -#define CONF_USB_EP3_CACHE 0 -#endif - -// Cache buffer size for EP3 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep3_I_CACHE -#ifndef CONF_USB_EP3_I_CACHE -#define CONF_USB_EP3_I_CACHE 0 -#endif -// - -// Cache configuration EP4 -// Cache buffer size for EP4 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep4_cache -#ifndef CONF_USB_EP4_CACHE -#define CONF_USB_EP4_CACHE 0 -#endif - -// Cache buffer size for EP4 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep4_I_CACHE -#ifndef CONF_USB_EP4_I_CACHE -#define CONF_USB_EP4_I_CACHE 0 -#endif -// - -// Cache configuration EP5 -// Cache buffer size for EP5 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep5_cache -#ifndef CONF_USB_EP5_CACHE -#define CONF_USB_EP5_CACHE 0 -#endif - -// Cache buffer size for EP5 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep5_I_CACHE -#ifndef CONF_USB_EP5_I_CACHE -#define CONF_USB_EP5_I_CACHE 0 -#endif -// - -// Cache configuration EP6 -// Cache buffer size for EP6 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep6_cache -#ifndef CONF_USB_EP6_CACHE -#define CONF_USB_EP6_CACHE 0 -#endif - -// Cache buffer size for EP6 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep6_I_CACHE -#ifndef CONF_USB_EP6_I_CACHE -#define CONF_USB_EP6_I_CACHE 0 -#endif -// - -// Cache configuration EP7 -// Cache buffer size for EP7 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep7_cache -#ifndef CONF_USB_EP7_CACHE -#define CONF_USB_EP7_CACHE 0 -#endif - -// Cache buffer size for EP7 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep7_I_CACHE -#ifndef CONF_USB_EP7_I_CACHE -#define CONF_USB_EP7_I_CACHE 0 -#endif -// - -// <<< end of configuration section >>> - -#endif // HPL_USB_CONFIG_H diff --git a/ports/atmel-samd/asf4_conf/samd51/usbd_config.h b/ports/atmel-samd/asf4_conf/samd51/usbd_config.h deleted file mode 100644 index b2629e1239..0000000000 --- a/ports/atmel-samd/asf4_conf/samd51/usbd_config.h +++ /dev/null @@ -1,850 +0,0 @@ -/* Auto-generated config file usbd_config.h */ -#ifndef USBD_CONFIG_H -#define USBD_CONFIG_H - -// <<< Use Configuration Wizard in Context Menu >>> - -// ---- USB Device Stack Core Options ---- - -// High Speed Support -// Enable high speed specific descriptors support, e.g., DeviceQualifierDescriptor and OtherSpeedConfiguration Descriptor. -// High speed support require descriptors description array on start, for LS/FS and HS support in first and second place. -// usbd_hs_sp -#ifndef CONF_USBD_HS_SP -#define CONF_USBD_HS_SP 0 -#endif - -// ---- USB Device Stack Composite Options ---- - -// Enable String Descriptors -// usb_composite_str_en -#ifndef CONF_USB_COMPOSITE_STR_EN -#define CONF_USB_COMPOSITE_STR_EN 0 -#endif -// Language IDs -// Language IDs in c format, split by comma (E.g., 0x0409 ...) -// usb_composite_langid -#ifndef CONF_USB_COMPOSITE_LANGID -#define CONF_USB_COMPOSITE_LANGID "0x0409" -#endif - -#ifndef CONF_USB_COMPOSITE_LANGID_DESC -#define CONF_USB_COMPOSITE_LANGID_DESC -#endif -// - -// Composite Device Descriptor - -// bcdUSB -// <0x0200=> USB 2.0 version -// <0x0210=> USB 2.1 version -// usb_composite_bcdusb -#ifndef CONF_USB_COMPOSITE_BCDUSB -#define CONF_USB_COMPOSITE_BCDUSB 0x200 -#endif - -// bMaxPackeSize0 -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_bmaxpksz0 -#ifndef CONF_USB_COMPOSITE_BMAXPKSZ0 -#define CONF_USB_COMPOSITE_BMAXPKSZ0 0x40 -#endif - -// idVender <0x0000-0xFFFF> -// usb_composite_idvender -#ifndef CONF_USB_COMPOSITE_IDVENDER -#define CONF_USB_COMPOSITE_IDVENDER 0x3eb -#endif - -// idProduct <0x0000-0xFFFF> -// usb_composite_idproduct -#ifndef CONF_USB_COMPOSITE_IDPRODUCT -#define CONF_USB_COMPOSITE_IDPRODUCT 0x2421 -#endif - -// bcdDevice <0x0000-0xFFFF> -// usb_composite_bcddevice -#ifndef CONF_USB_COMPOSITE_BCDDEVICE -#define CONF_USB_COMPOSITE_BCDDEVICE 0x100 -#endif - -// Enable string descriptor of iManufact -// usb_composite_imanufact_en -#ifndef CONF_USB_COMPOSITE_IMANUFACT_EN -#define CONF_USB_COMPOSITE_IMANUFACT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT -#define CONF_USB_COMPOSITE_IMANUFACT (CONF_USB_COMPOSITE_IMANUFACT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN)) -#endif - -// Unicode string of iManufact -// usb_composite_imanufact_str -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR -#define CONF_USB_COMPOSITE_IMANUFACT_STR "Atmel" -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#define CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#endif - -// - -// Enable string descriptor of iProduct -// usb_composite_iproduct_en -#ifndef CONF_USB_COMPOSITE_IPRODUCT_EN -#define CONF_USB_COMPOSITE_IPRODUCT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT -#define CONF_USB_COMPOSITE_IPRODUCT \ - (CONF_USB_COMPOSITE_IPRODUCT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN)) -#endif - -// Unicode string of iProduct -// usb_composite_iproduct_str -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR -#define CONF_USB_COMPOSITE_IPRODUCT_STR "Composite Demo" -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#define CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#endif - -// - -// Enable string descriptor of iSerialNum -// usb_composite_iserialnum_en -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_EN -#define CONF_USB_COMPOSITE_ISERIALNUM_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM -#define CONF_USB_COMPOSITE_ISERIALNUM \ - (CONF_USB_COMPOSITE_ISERIALNUM_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN)) -#endif - -// Unicode string of iSerialNum -// usb_composite_iserialnum_str -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR -#define CONF_USB_COMPOSITE_ISERIALNUM_STR "123456789ABCDEF" -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#define CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#endif - -// - -// bNumConfigurations <0x01-0xFF> -// usb_composite_bnumconfig -#ifndef CONF_USB_COMPOSITE_BNUMCONFIG -#define CONF_USB_COMPOSITE_BNUMCONFIG 0x1 -#endif - -// - -// Composite Configuration Descriptor -// bConfigurationValue <0x01-0xFF> -// usb_composite_bconfigval -#ifndef CONF_USB_COMPOSITE_BCONFIGVAL -#define CONF_USB_COMPOSITE_BCONFIGVAL 0x1 -#endif -// Enable string descriptor of iConfig -// usb_composite_iconfig_en -#ifndef CONF_USB_COMPOSITE_ICONFIG_EN -#define CONF_USB_COMPOSITE_ICONFIG_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG -#define CONF_USB_COMPOSITE_ICONFIG \ - (CONF_USB_COMPOSITE_ICONFIG_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN \ - + CONF_USB_COMPOSITE_ICONFIG_EN)) -#endif - -// Unicode string of iConfig -// usb_composite_iconfig_str -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR -#define CONF_USB_COMPOSITE_ICONFIG_STR "" -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#define CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#endif - -// - -// bmAttributes -// <0x80=> Bus power supply, not support for remote wakeup -// <0xA0=> Bus power supply, support for remote wakeup -// <0xC0=> Self powered, not support for remote wakeup -// <0xE0=> Self powered, support for remote wakeup -// usb_composite_bmattri -#ifndef CONF_USB_COMPOSITE_BMATTRI -#define CONF_USB_COMPOSITE_BMATTRI 0x80 -#endif - -// bMaxPower <0x00-0xFF> -// usb_composite_bmaxpower -#ifndef CONF_USB_COMPOSITE_BMAXPOWER -#define CONF_USB_COMPOSITE_BMAXPOWER 0x32 -#endif -// - -// CDC ACM Support -// usb_composite_cdc_acm_support -#ifndef CONF_USB_COMPOSITE_CDC_ACM_EN -#define CONF_USB_COMPOSITE_CDC_ACM_EN 0 -#endif - -// CDC ACM Comm Interrupt IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR 0x82 -#endif - -// CDC ACM Comm Interrupt IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_comm_int_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_data_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR 0x81 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS 0x200 -#endif - -// CDC ACM Data BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_cdc_acm_data_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR 0x1 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS 0x200 -#endif - -// CDC ACM Echo Demo generation -// conf_usb_composite_cdc_echo_demo -// Invoke cdcdf_acm_demo_init(buf[wMaxPacketSize]) to enable the echo demo. -// Buf is packet buffer for data receive and echo back. -// The buffer is 4 byte aligned to support DMA. -#ifndef CONF_USB_COMPOSITE_CDC_ECHO_DEMO -#define CONF_USB_COMPOSITE_CDC_ECHO_DEMO 0 -#endif - -// - -// HID Mouse Support -// usb_composite_hid_mouse_support -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_EN -#define CONF_USB_COMPOSITE_HID_MOUSE_EN 0 -#endif - -// HID Mouse INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_mouse_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR 0x83 -#endif - -// HID Mouse INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_mouse_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ 0x8 -#endif - -// HID Mouse Move Demo generation -// conf_usb_composite_hid_mouse_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Button1 and button3 are the pins used for mouse moving left and right. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_DEMO -#define CONF_USB_COMPOSITE_HID_MOUSE_DEMO 0 -#endif - -// - -// HID Keyboard Support -// usb_composite_hid_keyboard_support -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_EN -#define CONF_USB_COMPOSITE_HID_KEYBOARD_EN 0 -#endif - -// HID Keyboard INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_keyboard_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR 0x84 -#endif - -// HID Keyboard INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ 0x8 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_keyboard_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR 0x2 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ 0x8 -#endif - -// HID Keyboard Caps Lock Demo generation -// conf_usb_composite_hid_keyboard_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Buffon2 is the pin used for keyboard CAPS LOCK simulation. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO -#define CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO 0 -#endif - -// - -// HID Generic Support -// usb_composite_hid_generic_support -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_EN -#define CONF_USB_COMPOSITE_HID_GENERIC_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN 53 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT \ - 0x06, 0xFF, 0xFF, 0x09, 0x01, 0xA1, 0x01, 0x09, 0x02, 0x09, 0x03, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, \ - 0x40, 0x81, 0x02, 0x09, 0x04, 0x09, 0x05, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x40, 0x91, 0x02, \ - 0x09, 0x06, 0x09, 0x07, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x04, 0xB1, 0x02, 0xC0 -#endif - -// HID Generic INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_generic_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR 0x85 -#endif - -// HID Generic INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_generic_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ 0x40 -#endif - -// HID Generic INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_generic_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR 0x3 -#endif - -// HID Generic INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_hid_generic_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ 0x40 -#endif - -// - -// MSC Support -// usb_composite_msc_support -#ifndef CONF_USB_COMPOSITE_MSC_EN -#define CONF_USB_COMPOSITE_MSC_EN 0 -#endif - -// MSC BULK Endpoints wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_msc_bulk_maxpksz -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ 0x40 -#endif - -// MSC BULK Endpoints wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_msc_bulk_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS 0x200 -#endif - -// MSC BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_msc_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR 0x86 -#endif - -// MSC BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_msc_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR 0x4 -#endif - -// Enable Demo code for Disk LUN handling -// usb_composite_msc_demo_en -#ifndef CONF_USB_COMPOSITE_MSC_LUN_DEMO -#define CONF_USB_COMPOSITE_MSC_LUN_DEMO 1 -#endif - -// Disk access cache/buffer of sectors if non-RAM disk (e.g., SD/MMC) enabled <1-64> -// conf_usb_msc_lun_buf_sectors -#ifndef CONF_USB_MSC_LUN_BUF_SECTORS -#define CONF_USB_MSC_LUN_BUF_SECTORS 4 -#endif - -// Enable Demo for RAM Disk -// conf_usb_msc_lun0_enable -#ifndef CONF_USB_MSC_LUN0_ENABLE -#define CONF_USB_MSC_LUN0_ENABLE 1 -#endif - -#ifndef CONF_USB_MSC_LUN0_TYPE -#define CONF_USB_MSC_LUN0_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun0_rmb -#ifndef CONF_USB_MSC_LUN0_RMB -#define CONF_USB_MSC_LUN0_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN0_ISO -#define CONF_USB_MSC_LUN0_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ECMA -#define CONF_USB_MSC_LUN0_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ANSI -#define CONF_USB_MSC_LUN0_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_REPO -#define CONF_USB_MSC_LUN0_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN0_FACTORY -#define CONF_USB_MSC_LUN0_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT -#define CONF_USB_MSC_LUN0_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT_VERSION -#define CONF_USB_MSC_LUN0_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// Windows will not show disk less than 20K, so 22K is used to reserve more RAM for APP -// conf_usb_msc_lun0_capacity - -#ifndef CONF_USB_MSC_LUN0_CAPACITY -#define CONF_USB_MSC_LUN0_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN0_BLOCK_SIZE -#define CONF_USB_MSC_LUN0_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN0_CAPACITY * 1024 / CONF_USB_MSC_LUN0_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for SD/MMC Disk -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_enable -#ifndef CONF_USB_MSC_LUN1_ENABLE -#define CONF_USB_MSC_LUN1_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN1_TYPE -#define CONF_USB_MSC_LUN1_TYPE 0x00 -#endif - -// The disk is removable -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_rmb -#ifndef CONF_USB_MSC_LUN1_RMB -#define CONF_USB_MSC_LUN1_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN1_ISO -#define CONF_USB_MSC_LUN1_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ECMA -#define CONF_USB_MSC_LUN1_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ANSI -#define CONF_USB_MSC_LUN1_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_REPO -#define CONF_USB_MSC_LUN1_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN1_FACTORY -#define CONF_USB_MSC_LUN1_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT -#define CONF_USB_MSC_LUN1_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT_VERSION -#define CONF_USB_MSC_LUN1_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_CAPACITY -#define CONF_USB_MSC_LUN1_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN1_BLOCK_SIZE -#define CONF_USB_MSC_LUN1_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN1_CAPACITY * 1024 / CONF_USB_MSC_LUN1_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 2 -// conf_usb_msc_lun2_enable -#ifndef CONF_USB_MSC_LUN2_ENABLE -#define CONF_USB_MSC_LUN2_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN2_TYPE -#define CONF_USB_MSC_LUN2_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun2_rmb -#ifndef CONF_USB_MSC_LUN2_RMB -#define CONF_USB_MSC_LUN2_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN2_ISO -#define CONF_USB_MSC_LUN2_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ECMA -#define CONF_USB_MSC_LUN2_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ANSI -#define CONF_USB_MSC_LUN2_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_REPO -#define CONF_USB_MSC_LUN2_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN2_FACTORY -#define CONF_USB_MSC_LUN2_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT -#define CONF_USB_MSC_LUN2_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT_VERSION -#define CONF_USB_MSC_LUN2_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun2_capacity - -#ifndef CONF_USB_MSC_LUN2_CAPACITY -#define CONF_USB_MSC_LUN2_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN2_BLOCK_SIZE -#define CONF_USB_MSC_LUN2_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN2_CAPACITY * 1024 / CONF_USB_MSC_LUN2_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 3 -// conf_usb_msc_lun3_enable -#ifndef CONF_USB_MSC_LUN3_ENABLE -#define CONF_USB_MSC_LUN3_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN3_TYPE -#define CONF_USB_MSC_LUN3_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun3_rmb -#ifndef CONF_USB_MSC_LUN3_RMB -#define CONF_USB_MSC_LUN3_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN3_ISO -#define CONF_USB_MSC_LUN3_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ECMA -#define CONF_USB_MSC_LUN3_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ANSI -#define CONF_USB_MSC_LUN3_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_REPO -#define CONF_USB_MSC_LUN3_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN3_FACTORY -#define CONF_USB_MSC_LUN3_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT -#define CONF_USB_MSC_LUN3_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT_VERSION -#define CONF_USB_MSC_LUN3_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun3_capacity - -#ifndef CONF_USB_MSC_LUN3_CAPACITY -#define CONF_USB_MSC_LUN3_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN3_BLOCK_SIZE -#define CONF_USB_MSC_LUN3_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN3_CAPACITY * 1024 / CONF_USB_MSC_LUN3_BLOCK_SIZE - 1) -#endif - -// - -// -// - -// <<< end of configuration section >>> - -#endif // USBD_CONFIG_H diff --git a/ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h deleted file mode 100644 index 51c71cb823..0000000000 --- a/ports/atmel-samd/asf4_conf/same51/hpl_usb_config.h +++ /dev/null @@ -1,382 +0,0 @@ -/* Auto-generated config file hpl_usb_config.h */ -#ifndef HPL_USB_CONFIG_H -#define HPL_USB_CONFIG_H - -// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. -// So provide cache space for all of them. - -#define CONF_USB_EP1_CACHE 64 -#define CONF_USB_EP1_I_CACHE 64 - -#define CONF_USB_EP2_CACHE 64 -#define CONF_USB_EP2_I_CACHE 64 - -#define CONF_USB_EP3_CACHE 64 -#define CONF_USB_EP3_I_CACHE 64 - -#define CONF_USB_EP4_CACHE 64 -#define CONF_USB_EP4_I_CACHE 64 - -#define CONF_USB_EP5_CACHE 64 -#define CONF_USB_EP5_I_CACHE 64 - -#define CONF_USB_EP6_CACHE 64 -#define CONF_USB_EP6_I_CACHE 64 - -#define CONF_USB_EP7_CACHE 64 -#define CONF_USB_EP7_I_CACHE 64 - - -// <<< Use Configuration Wizard in Context Menu >>> - -#define CONF_USB_N_0 0 -#define CONF_USB_N_1 1 -#define CONF_USB_N_2 2 -#define CONF_USB_N_3 3 -#define CONF_USB_N_4 4 -#define CONF_USB_N_5 5 -#define CONF_USB_N_6 6 -#define CONF_USB_N_7 7 -#define CONF_USB_N_8 8 -#define CONF_USB_N_9 9 -#define CONF_USB_N_10 10 -#define CONF_USB_N_11 11 -#define CONF_USB_N_12 12 -#define CONF_USB_N_13 13 -#define CONF_USB_N_14 14 -#define CONF_USB_N_15 15 - -#define CONF_USB_D_EP_N_MAX (USB_EPT_NUM - 1) -#define CONF_USB_D_N_EP_MAX (CONF_USB_D_EP_N_MAX * 2 - 1) - -// USB Device HAL Configuration - -// Max number of endpoints supported -// Limits the number of endpoints (described by EP address) can be used in app. -// NOTE(tannewt): This not only limits the number of endpoints but also the -// addresses. In other words, even if you use endpoint 6 you need to set this to 11. -// 1 (EP0 only) -// 2 (EP0 + 1 endpoint) -// 3 (EP0 + 2 endpoints) -// 4 (EP0 + 3 endpoints) -// 5 (EP0 + 4 endpoints) -// 6 (EP0 + 5 endpoints) -// 7 (EP0 + 6 endpoints) -// 8 (EP0 + 7 endpoints) -// Max possible (by "Max Endpoint Number" config) -// usbd_num_ep_sp -#ifndef CONF_USB_D_NUM_EP_SP -#define CONF_USB_D_NUM_EP_SP CONF_USB_D_N_EP_MAX -#endif - -// - -// Max Endpoint Number supported -// Limits the max endpoint number. -// USB endpoint address is constructed by direction and endpoint number. Bit 8 of address set indicates the direction is IN. E.g., EP0x81 and EP0x01 have the same endpoint number, 1. -// Reduce the value according to specific device design, to cut-off memory usage. -// 0 (only EP0) -// 1 (EP 0x81 or 0x01) -// 2 (EP 0x82 or 0x02) -// 3 (EP 0x83 or 0x03) -// 4 (EP 0x84 or 0x04) -// 5 (EP 0x85 or 0x05) -// 6 (EP 0x86 or 0x06) -// 7 (EP 0x87 or 0x07) -// Max possible (by HW) -// The number of physical endpoints - 1 -// usbd_arch_max_ep_n -#ifndef CONF_USB_D_MAX_EP_N -#define CONF_USB_D_MAX_EP_N CONF_USB_D_EP_N_MAX -#endif - -// USB Speed Limit -// Limits the working speed of the device. -// Full speed -// Low Speed -// usbd_arch_speed -#ifndef CONF_USB_D_SPEED -#define CONF_USB_D_SPEED USB_SPEED_FS -#endif - -// Cache buffer size for EP0 -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// EP0 is default control endpoint, so cache must be used to be able to receive SETUP packet at any time. -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// usb_arch_ep0_cache -#ifndef CONF_USB_EP0_CACHE -#define CONF_USB_EP0_CACHE 64 -#endif - -// Cache configuration EP1 -// Cache buffer size for EP1 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep1_cache -#ifndef CONF_USB_EP1_CACHE -#define CONF_USB_EP1_CACHE 0 -#endif - -// Cache buffer size for EP1 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep1_I_CACHE -#ifndef CONF_USB_EP1_I_CACHE -#define CONF_USB_EP1_I_CACHE 0 -#endif -// - -// Cache configuration EP2 -// Cache buffer size for EP2 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep2_cache -#ifndef CONF_USB_EP2_CACHE -#define CONF_USB_EP2_CACHE 0 -#endif - -// Cache buffer size for EP2 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep2_I_CACHE -#ifndef CONF_USB_EP2_I_CACHE -#define CONF_USB_EP2_I_CACHE 0 -#endif -// - -// Cache configuration EP3 -// Cache buffer size for EP3 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep3_cache -#ifndef CONF_USB_EP3_CACHE -#define CONF_USB_EP3_CACHE 0 -#endif - -// Cache buffer size for EP3 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep3_I_CACHE -#ifndef CONF_USB_EP3_I_CACHE -#define CONF_USB_EP3_I_CACHE 0 -#endif -// - -// Cache configuration EP4 -// Cache buffer size for EP4 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep4_cache -#ifndef CONF_USB_EP4_CACHE -#define CONF_USB_EP4_CACHE 0 -#endif - -// Cache buffer size for EP4 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep4_I_CACHE -#ifndef CONF_USB_EP4_I_CACHE -#define CONF_USB_EP4_I_CACHE 0 -#endif -// - -// Cache configuration EP5 -// Cache buffer size for EP5 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep5_cache -#ifndef CONF_USB_EP5_CACHE -#define CONF_USB_EP5_CACHE 0 -#endif - -// Cache buffer size for EP5 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep5_I_CACHE -#ifndef CONF_USB_EP5_I_CACHE -#define CONF_USB_EP5_I_CACHE 0 -#endif -// - -// Cache configuration EP6 -// Cache buffer size for EP6 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep6_cache -#ifndef CONF_USB_EP6_CACHE -#define CONF_USB_EP6_CACHE 0 -#endif - -// Cache buffer size for EP6 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep6_I_CACHE -#ifndef CONF_USB_EP6_I_CACHE -#define CONF_USB_EP6_I_CACHE 0 -#endif -// - -// Cache configuration EP7 -// Cache buffer size for EP7 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep7_cache -#ifndef CONF_USB_EP7_CACHE -#define CONF_USB_EP7_CACHE 0 -#endif - -// Cache buffer size for EP7 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep7_I_CACHE -#ifndef CONF_USB_EP7_I_CACHE -#define CONF_USB_EP7_I_CACHE 0 -#endif -// - -// <<< end of configuration section >>> - -#endif // HPL_USB_CONFIG_H diff --git a/ports/atmel-samd/asf4_conf/same51/usbd_config.h b/ports/atmel-samd/asf4_conf/same51/usbd_config.h deleted file mode 100644 index b2629e1239..0000000000 --- a/ports/atmel-samd/asf4_conf/same51/usbd_config.h +++ /dev/null @@ -1,850 +0,0 @@ -/* Auto-generated config file usbd_config.h */ -#ifndef USBD_CONFIG_H -#define USBD_CONFIG_H - -// <<< Use Configuration Wizard in Context Menu >>> - -// ---- USB Device Stack Core Options ---- - -// High Speed Support -// Enable high speed specific descriptors support, e.g., DeviceQualifierDescriptor and OtherSpeedConfiguration Descriptor. -// High speed support require descriptors description array on start, for LS/FS and HS support in first and second place. -// usbd_hs_sp -#ifndef CONF_USBD_HS_SP -#define CONF_USBD_HS_SP 0 -#endif - -// ---- USB Device Stack Composite Options ---- - -// Enable String Descriptors -// usb_composite_str_en -#ifndef CONF_USB_COMPOSITE_STR_EN -#define CONF_USB_COMPOSITE_STR_EN 0 -#endif -// Language IDs -// Language IDs in c format, split by comma (E.g., 0x0409 ...) -// usb_composite_langid -#ifndef CONF_USB_COMPOSITE_LANGID -#define CONF_USB_COMPOSITE_LANGID "0x0409" -#endif - -#ifndef CONF_USB_COMPOSITE_LANGID_DESC -#define CONF_USB_COMPOSITE_LANGID_DESC -#endif -// - -// Composite Device Descriptor - -// bcdUSB -// <0x0200=> USB 2.0 version -// <0x0210=> USB 2.1 version -// usb_composite_bcdusb -#ifndef CONF_USB_COMPOSITE_BCDUSB -#define CONF_USB_COMPOSITE_BCDUSB 0x200 -#endif - -// bMaxPackeSize0 -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_bmaxpksz0 -#ifndef CONF_USB_COMPOSITE_BMAXPKSZ0 -#define CONF_USB_COMPOSITE_BMAXPKSZ0 0x40 -#endif - -// idVender <0x0000-0xFFFF> -// usb_composite_idvender -#ifndef CONF_USB_COMPOSITE_IDVENDER -#define CONF_USB_COMPOSITE_IDVENDER 0x3eb -#endif - -// idProduct <0x0000-0xFFFF> -// usb_composite_idproduct -#ifndef CONF_USB_COMPOSITE_IDPRODUCT -#define CONF_USB_COMPOSITE_IDPRODUCT 0x2421 -#endif - -// bcdDevice <0x0000-0xFFFF> -// usb_composite_bcddevice -#ifndef CONF_USB_COMPOSITE_BCDDEVICE -#define CONF_USB_COMPOSITE_BCDDEVICE 0x100 -#endif - -// Enable string descriptor of iManufact -// usb_composite_imanufact_en -#ifndef CONF_USB_COMPOSITE_IMANUFACT_EN -#define CONF_USB_COMPOSITE_IMANUFACT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT -#define CONF_USB_COMPOSITE_IMANUFACT (CONF_USB_COMPOSITE_IMANUFACT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN)) -#endif - -// Unicode string of iManufact -// usb_composite_imanufact_str -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR -#define CONF_USB_COMPOSITE_IMANUFACT_STR "Atmel" -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#define CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#endif - -// - -// Enable string descriptor of iProduct -// usb_composite_iproduct_en -#ifndef CONF_USB_COMPOSITE_IPRODUCT_EN -#define CONF_USB_COMPOSITE_IPRODUCT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT -#define CONF_USB_COMPOSITE_IPRODUCT \ - (CONF_USB_COMPOSITE_IPRODUCT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN)) -#endif - -// Unicode string of iProduct -// usb_composite_iproduct_str -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR -#define CONF_USB_COMPOSITE_IPRODUCT_STR "Composite Demo" -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#define CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#endif - -// - -// Enable string descriptor of iSerialNum -// usb_composite_iserialnum_en -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_EN -#define CONF_USB_COMPOSITE_ISERIALNUM_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM -#define CONF_USB_COMPOSITE_ISERIALNUM \ - (CONF_USB_COMPOSITE_ISERIALNUM_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN)) -#endif - -// Unicode string of iSerialNum -// usb_composite_iserialnum_str -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR -#define CONF_USB_COMPOSITE_ISERIALNUM_STR "123456789ABCDEF" -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#define CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#endif - -// - -// bNumConfigurations <0x01-0xFF> -// usb_composite_bnumconfig -#ifndef CONF_USB_COMPOSITE_BNUMCONFIG -#define CONF_USB_COMPOSITE_BNUMCONFIG 0x1 -#endif - -// - -// Composite Configuration Descriptor -// bConfigurationValue <0x01-0xFF> -// usb_composite_bconfigval -#ifndef CONF_USB_COMPOSITE_BCONFIGVAL -#define CONF_USB_COMPOSITE_BCONFIGVAL 0x1 -#endif -// Enable string descriptor of iConfig -// usb_composite_iconfig_en -#ifndef CONF_USB_COMPOSITE_ICONFIG_EN -#define CONF_USB_COMPOSITE_ICONFIG_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG -#define CONF_USB_COMPOSITE_ICONFIG \ - (CONF_USB_COMPOSITE_ICONFIG_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN \ - + CONF_USB_COMPOSITE_ICONFIG_EN)) -#endif - -// Unicode string of iConfig -// usb_composite_iconfig_str -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR -#define CONF_USB_COMPOSITE_ICONFIG_STR "" -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#define CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#endif - -// - -// bmAttributes -// <0x80=> Bus power supply, not support for remote wakeup -// <0xA0=> Bus power supply, support for remote wakeup -// <0xC0=> Self powered, not support for remote wakeup -// <0xE0=> Self powered, support for remote wakeup -// usb_composite_bmattri -#ifndef CONF_USB_COMPOSITE_BMATTRI -#define CONF_USB_COMPOSITE_BMATTRI 0x80 -#endif - -// bMaxPower <0x00-0xFF> -// usb_composite_bmaxpower -#ifndef CONF_USB_COMPOSITE_BMAXPOWER -#define CONF_USB_COMPOSITE_BMAXPOWER 0x32 -#endif -// - -// CDC ACM Support -// usb_composite_cdc_acm_support -#ifndef CONF_USB_COMPOSITE_CDC_ACM_EN -#define CONF_USB_COMPOSITE_CDC_ACM_EN 0 -#endif - -// CDC ACM Comm Interrupt IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR 0x82 -#endif - -// CDC ACM Comm Interrupt IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_comm_int_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_data_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR 0x81 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS 0x200 -#endif - -// CDC ACM Data BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_cdc_acm_data_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR 0x1 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS 0x200 -#endif - -// CDC ACM Echo Demo generation -// conf_usb_composite_cdc_echo_demo -// Invoke cdcdf_acm_demo_init(buf[wMaxPacketSize]) to enable the echo demo. -// Buf is packet buffer for data receive and echo back. -// The buffer is 4 byte aligned to support DMA. -#ifndef CONF_USB_COMPOSITE_CDC_ECHO_DEMO -#define CONF_USB_COMPOSITE_CDC_ECHO_DEMO 0 -#endif - -// - -// HID Mouse Support -// usb_composite_hid_mouse_support -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_EN -#define CONF_USB_COMPOSITE_HID_MOUSE_EN 0 -#endif - -// HID Mouse INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_mouse_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR 0x83 -#endif - -// HID Mouse INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_mouse_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ 0x8 -#endif - -// HID Mouse Move Demo generation -// conf_usb_composite_hid_mouse_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Button1 and button3 are the pins used for mouse moving left and right. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_DEMO -#define CONF_USB_COMPOSITE_HID_MOUSE_DEMO 0 -#endif - -// - -// HID Keyboard Support -// usb_composite_hid_keyboard_support -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_EN -#define CONF_USB_COMPOSITE_HID_KEYBOARD_EN 0 -#endif - -// HID Keyboard INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_keyboard_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR 0x84 -#endif - -// HID Keyboard INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ 0x8 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_keyboard_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR 0x2 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ 0x8 -#endif - -// HID Keyboard Caps Lock Demo generation -// conf_usb_composite_hid_keyboard_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Buffon2 is the pin used for keyboard CAPS LOCK simulation. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO -#define CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO 0 -#endif - -// - -// HID Generic Support -// usb_composite_hid_generic_support -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_EN -#define CONF_USB_COMPOSITE_HID_GENERIC_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN 53 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT \ - 0x06, 0xFF, 0xFF, 0x09, 0x01, 0xA1, 0x01, 0x09, 0x02, 0x09, 0x03, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, \ - 0x40, 0x81, 0x02, 0x09, 0x04, 0x09, 0x05, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x40, 0x91, 0x02, \ - 0x09, 0x06, 0x09, 0x07, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x04, 0xB1, 0x02, 0xC0 -#endif - -// HID Generic INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_generic_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR 0x85 -#endif - -// HID Generic INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_generic_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ 0x40 -#endif - -// HID Generic INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_generic_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR 0x3 -#endif - -// HID Generic INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_hid_generic_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ 0x40 -#endif - -// - -// MSC Support -// usb_composite_msc_support -#ifndef CONF_USB_COMPOSITE_MSC_EN -#define CONF_USB_COMPOSITE_MSC_EN 0 -#endif - -// MSC BULK Endpoints wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_msc_bulk_maxpksz -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ 0x40 -#endif - -// MSC BULK Endpoints wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_msc_bulk_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS 0x200 -#endif - -// MSC BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_msc_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR 0x86 -#endif - -// MSC BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_msc_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR 0x4 -#endif - -// Enable Demo code for Disk LUN handling -// usb_composite_msc_demo_en -#ifndef CONF_USB_COMPOSITE_MSC_LUN_DEMO -#define CONF_USB_COMPOSITE_MSC_LUN_DEMO 1 -#endif - -// Disk access cache/buffer of sectors if non-RAM disk (e.g., SD/MMC) enabled <1-64> -// conf_usb_msc_lun_buf_sectors -#ifndef CONF_USB_MSC_LUN_BUF_SECTORS -#define CONF_USB_MSC_LUN_BUF_SECTORS 4 -#endif - -// Enable Demo for RAM Disk -// conf_usb_msc_lun0_enable -#ifndef CONF_USB_MSC_LUN0_ENABLE -#define CONF_USB_MSC_LUN0_ENABLE 1 -#endif - -#ifndef CONF_USB_MSC_LUN0_TYPE -#define CONF_USB_MSC_LUN0_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun0_rmb -#ifndef CONF_USB_MSC_LUN0_RMB -#define CONF_USB_MSC_LUN0_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN0_ISO -#define CONF_USB_MSC_LUN0_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ECMA -#define CONF_USB_MSC_LUN0_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ANSI -#define CONF_USB_MSC_LUN0_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_REPO -#define CONF_USB_MSC_LUN0_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN0_FACTORY -#define CONF_USB_MSC_LUN0_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT -#define CONF_USB_MSC_LUN0_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT_VERSION -#define CONF_USB_MSC_LUN0_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// Windows will not show disk less than 20K, so 22K is used to reserve more RAM for APP -// conf_usb_msc_lun0_capacity - -#ifndef CONF_USB_MSC_LUN0_CAPACITY -#define CONF_USB_MSC_LUN0_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN0_BLOCK_SIZE -#define CONF_USB_MSC_LUN0_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN0_CAPACITY * 1024 / CONF_USB_MSC_LUN0_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for SD/MMC Disk -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_enable -#ifndef CONF_USB_MSC_LUN1_ENABLE -#define CONF_USB_MSC_LUN1_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN1_TYPE -#define CONF_USB_MSC_LUN1_TYPE 0x00 -#endif - -// The disk is removable -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_rmb -#ifndef CONF_USB_MSC_LUN1_RMB -#define CONF_USB_MSC_LUN1_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN1_ISO -#define CONF_USB_MSC_LUN1_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ECMA -#define CONF_USB_MSC_LUN1_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ANSI -#define CONF_USB_MSC_LUN1_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_REPO -#define CONF_USB_MSC_LUN1_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN1_FACTORY -#define CONF_USB_MSC_LUN1_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT -#define CONF_USB_MSC_LUN1_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT_VERSION -#define CONF_USB_MSC_LUN1_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_CAPACITY -#define CONF_USB_MSC_LUN1_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN1_BLOCK_SIZE -#define CONF_USB_MSC_LUN1_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN1_CAPACITY * 1024 / CONF_USB_MSC_LUN1_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 2 -// conf_usb_msc_lun2_enable -#ifndef CONF_USB_MSC_LUN2_ENABLE -#define CONF_USB_MSC_LUN2_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN2_TYPE -#define CONF_USB_MSC_LUN2_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun2_rmb -#ifndef CONF_USB_MSC_LUN2_RMB -#define CONF_USB_MSC_LUN2_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN2_ISO -#define CONF_USB_MSC_LUN2_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ECMA -#define CONF_USB_MSC_LUN2_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ANSI -#define CONF_USB_MSC_LUN2_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_REPO -#define CONF_USB_MSC_LUN2_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN2_FACTORY -#define CONF_USB_MSC_LUN2_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT -#define CONF_USB_MSC_LUN2_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT_VERSION -#define CONF_USB_MSC_LUN2_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun2_capacity - -#ifndef CONF_USB_MSC_LUN2_CAPACITY -#define CONF_USB_MSC_LUN2_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN2_BLOCK_SIZE -#define CONF_USB_MSC_LUN2_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN2_CAPACITY * 1024 / CONF_USB_MSC_LUN2_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 3 -// conf_usb_msc_lun3_enable -#ifndef CONF_USB_MSC_LUN3_ENABLE -#define CONF_USB_MSC_LUN3_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN3_TYPE -#define CONF_USB_MSC_LUN3_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun3_rmb -#ifndef CONF_USB_MSC_LUN3_RMB -#define CONF_USB_MSC_LUN3_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN3_ISO -#define CONF_USB_MSC_LUN3_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ECMA -#define CONF_USB_MSC_LUN3_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ANSI -#define CONF_USB_MSC_LUN3_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_REPO -#define CONF_USB_MSC_LUN3_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN3_FACTORY -#define CONF_USB_MSC_LUN3_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT -#define CONF_USB_MSC_LUN3_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT_VERSION -#define CONF_USB_MSC_LUN3_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun3_capacity - -#ifndef CONF_USB_MSC_LUN3_CAPACITY -#define CONF_USB_MSC_LUN3_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN3_BLOCK_SIZE -#define CONF_USB_MSC_LUN3_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN3_CAPACITY * 1024 / CONF_USB_MSC_LUN3_BLOCK_SIZE - 1) -#endif - -// - -// -// - -// <<< end of configuration section >>> - -#endif // USBD_CONFIG_H diff --git a/ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h b/ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h deleted file mode 100644 index 51c71cb823..0000000000 --- a/ports/atmel-samd/asf4_conf/same54/hpl_usb_config.h +++ /dev/null @@ -1,382 +0,0 @@ -/* Auto-generated config file hpl_usb_config.h */ -#ifndef HPL_USB_CONFIG_H -#define HPL_USB_CONFIG_H - -// CIRCUITPY: Since we have dynamic USB descriptors, we may end up using all endpoints. -// So provide cache space for all of them. - -#define CONF_USB_EP1_CACHE 64 -#define CONF_USB_EP1_I_CACHE 64 - -#define CONF_USB_EP2_CACHE 64 -#define CONF_USB_EP2_I_CACHE 64 - -#define CONF_USB_EP3_CACHE 64 -#define CONF_USB_EP3_I_CACHE 64 - -#define CONF_USB_EP4_CACHE 64 -#define CONF_USB_EP4_I_CACHE 64 - -#define CONF_USB_EP5_CACHE 64 -#define CONF_USB_EP5_I_CACHE 64 - -#define CONF_USB_EP6_CACHE 64 -#define CONF_USB_EP6_I_CACHE 64 - -#define CONF_USB_EP7_CACHE 64 -#define CONF_USB_EP7_I_CACHE 64 - - -// <<< Use Configuration Wizard in Context Menu >>> - -#define CONF_USB_N_0 0 -#define CONF_USB_N_1 1 -#define CONF_USB_N_2 2 -#define CONF_USB_N_3 3 -#define CONF_USB_N_4 4 -#define CONF_USB_N_5 5 -#define CONF_USB_N_6 6 -#define CONF_USB_N_7 7 -#define CONF_USB_N_8 8 -#define CONF_USB_N_9 9 -#define CONF_USB_N_10 10 -#define CONF_USB_N_11 11 -#define CONF_USB_N_12 12 -#define CONF_USB_N_13 13 -#define CONF_USB_N_14 14 -#define CONF_USB_N_15 15 - -#define CONF_USB_D_EP_N_MAX (USB_EPT_NUM - 1) -#define CONF_USB_D_N_EP_MAX (CONF_USB_D_EP_N_MAX * 2 - 1) - -// USB Device HAL Configuration - -// Max number of endpoints supported -// Limits the number of endpoints (described by EP address) can be used in app. -// NOTE(tannewt): This not only limits the number of endpoints but also the -// addresses. In other words, even if you use endpoint 6 you need to set this to 11. -// 1 (EP0 only) -// 2 (EP0 + 1 endpoint) -// 3 (EP0 + 2 endpoints) -// 4 (EP0 + 3 endpoints) -// 5 (EP0 + 4 endpoints) -// 6 (EP0 + 5 endpoints) -// 7 (EP0 + 6 endpoints) -// 8 (EP0 + 7 endpoints) -// Max possible (by "Max Endpoint Number" config) -// usbd_num_ep_sp -#ifndef CONF_USB_D_NUM_EP_SP -#define CONF_USB_D_NUM_EP_SP CONF_USB_D_N_EP_MAX -#endif - -// - -// Max Endpoint Number supported -// Limits the max endpoint number. -// USB endpoint address is constructed by direction and endpoint number. Bit 8 of address set indicates the direction is IN. E.g., EP0x81 and EP0x01 have the same endpoint number, 1. -// Reduce the value according to specific device design, to cut-off memory usage. -// 0 (only EP0) -// 1 (EP 0x81 or 0x01) -// 2 (EP 0x82 or 0x02) -// 3 (EP 0x83 or 0x03) -// 4 (EP 0x84 or 0x04) -// 5 (EP 0x85 or 0x05) -// 6 (EP 0x86 or 0x06) -// 7 (EP 0x87 or 0x07) -// Max possible (by HW) -// The number of physical endpoints - 1 -// usbd_arch_max_ep_n -#ifndef CONF_USB_D_MAX_EP_N -#define CONF_USB_D_MAX_EP_N CONF_USB_D_EP_N_MAX -#endif - -// USB Speed Limit -// Limits the working speed of the device. -// Full speed -// Low Speed -// usbd_arch_speed -#ifndef CONF_USB_D_SPEED -#define CONF_USB_D_SPEED USB_SPEED_FS -#endif - -// Cache buffer size for EP0 -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// EP0 is default control endpoint, so cache must be used to be able to receive SETUP packet at any time. -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// usb_arch_ep0_cache -#ifndef CONF_USB_EP0_CACHE -#define CONF_USB_EP0_CACHE 64 -#endif - -// Cache configuration EP1 -// Cache buffer size for EP1 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep1_cache -#ifndef CONF_USB_EP1_CACHE -#define CONF_USB_EP1_CACHE 0 -#endif - -// Cache buffer size for EP1 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep1_I_CACHE -#ifndef CONF_USB_EP1_I_CACHE -#define CONF_USB_EP1_I_CACHE 0 -#endif -// - -// Cache configuration EP2 -// Cache buffer size for EP2 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep2_cache -#ifndef CONF_USB_EP2_CACHE -#define CONF_USB_EP2_CACHE 0 -#endif - -// Cache buffer size for EP2 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep2_I_CACHE -#ifndef CONF_USB_EP2_I_CACHE -#define CONF_USB_EP2_I_CACHE 0 -#endif -// - -// Cache configuration EP3 -// Cache buffer size for EP3 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep3_cache -#ifndef CONF_USB_EP3_CACHE -#define CONF_USB_EP3_CACHE 0 -#endif - -// Cache buffer size for EP3 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep3_I_CACHE -#ifndef CONF_USB_EP3_I_CACHE -#define CONF_USB_EP3_I_CACHE 0 -#endif -// - -// Cache configuration EP4 -// Cache buffer size for EP4 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep4_cache -#ifndef CONF_USB_EP4_CACHE -#define CONF_USB_EP4_CACHE 0 -#endif - -// Cache buffer size for EP4 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep4_I_CACHE -#ifndef CONF_USB_EP4_I_CACHE -#define CONF_USB_EP4_I_CACHE 0 -#endif -// - -// Cache configuration EP5 -// Cache buffer size for EP5 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep5_cache -#ifndef CONF_USB_EP5_CACHE -#define CONF_USB_EP5_CACHE 0 -#endif - -// Cache buffer size for EP5 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep5_I_CACHE -#ifndef CONF_USB_EP5_I_CACHE -#define CONF_USB_EP5_I_CACHE 0 -#endif -// - -// Cache configuration EP6 -// Cache buffer size for EP6 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep6_cache -#ifndef CONF_USB_EP6_CACHE -#define CONF_USB_EP6_CACHE 0 -#endif - -// Cache buffer size for EP6 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep6_I_CACHE -#ifndef CONF_USB_EP6_I_CACHE -#define CONF_USB_EP6_I_CACHE 0 -#endif -// - -// Cache configuration EP7 -// Cache buffer size for EP7 OUT -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_arch_ep7_cache -#ifndef CONF_USB_EP7_CACHE -#define CONF_USB_EP7_CACHE 0 -#endif - -// Cache buffer size for EP7 IN -// Cache is used because the USB hardware always uses DMA which requires specific memory feature. -// This cache must not be allocated if you plan to use the endpoint as control endpoint. -// No cache means IN transaction not support data buffer outside of RAM, OUT transaction not support unaligned buffer and buffer size less than endpoint max packet size -// <0=> No cache -// <8=> Cached by 8 bytes buffer -// <16=> Cached by 16 bytes buffer -// <32=> Cached by 32 bytes buffer -// <64=> Cached by 64 bytes buffer -// <128=> Cached by 128 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <256=> Cached by 256 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <512=> Cached by 512 bytes buffer (HS Bulk or interrupt or isochronous EP) -// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP) -// usb_ep7_I_CACHE -#ifndef CONF_USB_EP7_I_CACHE -#define CONF_USB_EP7_I_CACHE 0 -#endif -// - -// <<< end of configuration section >>> - -#endif // HPL_USB_CONFIG_H diff --git a/ports/atmel-samd/asf4_conf/same54/usbd_config.h b/ports/atmel-samd/asf4_conf/same54/usbd_config.h deleted file mode 100644 index b2629e1239..0000000000 --- a/ports/atmel-samd/asf4_conf/same54/usbd_config.h +++ /dev/null @@ -1,850 +0,0 @@ -/* Auto-generated config file usbd_config.h */ -#ifndef USBD_CONFIG_H -#define USBD_CONFIG_H - -// <<< Use Configuration Wizard in Context Menu >>> - -// ---- USB Device Stack Core Options ---- - -// High Speed Support -// Enable high speed specific descriptors support, e.g., DeviceQualifierDescriptor and OtherSpeedConfiguration Descriptor. -// High speed support require descriptors description array on start, for LS/FS and HS support in first and second place. -// usbd_hs_sp -#ifndef CONF_USBD_HS_SP -#define CONF_USBD_HS_SP 0 -#endif - -// ---- USB Device Stack Composite Options ---- - -// Enable String Descriptors -// usb_composite_str_en -#ifndef CONF_USB_COMPOSITE_STR_EN -#define CONF_USB_COMPOSITE_STR_EN 0 -#endif -// Language IDs -// Language IDs in c format, split by comma (E.g., 0x0409 ...) -// usb_composite_langid -#ifndef CONF_USB_COMPOSITE_LANGID -#define CONF_USB_COMPOSITE_LANGID "0x0409" -#endif - -#ifndef CONF_USB_COMPOSITE_LANGID_DESC -#define CONF_USB_COMPOSITE_LANGID_DESC -#endif -// - -// Composite Device Descriptor - -// bcdUSB -// <0x0200=> USB 2.0 version -// <0x0210=> USB 2.1 version -// usb_composite_bcdusb -#ifndef CONF_USB_COMPOSITE_BCDUSB -#define CONF_USB_COMPOSITE_BCDUSB 0x200 -#endif - -// bMaxPackeSize0 -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_bmaxpksz0 -#ifndef CONF_USB_COMPOSITE_BMAXPKSZ0 -#define CONF_USB_COMPOSITE_BMAXPKSZ0 0x40 -#endif - -// idVender <0x0000-0xFFFF> -// usb_composite_idvender -#ifndef CONF_USB_COMPOSITE_IDVENDER -#define CONF_USB_COMPOSITE_IDVENDER 0x3eb -#endif - -// idProduct <0x0000-0xFFFF> -// usb_composite_idproduct -#ifndef CONF_USB_COMPOSITE_IDPRODUCT -#define CONF_USB_COMPOSITE_IDPRODUCT 0x2421 -#endif - -// bcdDevice <0x0000-0xFFFF> -// usb_composite_bcddevice -#ifndef CONF_USB_COMPOSITE_BCDDEVICE -#define CONF_USB_COMPOSITE_BCDDEVICE 0x100 -#endif - -// Enable string descriptor of iManufact -// usb_composite_imanufact_en -#ifndef CONF_USB_COMPOSITE_IMANUFACT_EN -#define CONF_USB_COMPOSITE_IMANUFACT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT -#define CONF_USB_COMPOSITE_IMANUFACT (CONF_USB_COMPOSITE_IMANUFACT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN)) -#endif - -// Unicode string of iManufact -// usb_composite_imanufact_str -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR -#define CONF_USB_COMPOSITE_IMANUFACT_STR "Atmel" -#endif - -#ifndef CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#define CONF_USB_COMPOSITE_IMANUFACT_STR_DESC -#endif - -// - -// Enable string descriptor of iProduct -// usb_composite_iproduct_en -#ifndef CONF_USB_COMPOSITE_IPRODUCT_EN -#define CONF_USB_COMPOSITE_IPRODUCT_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT -#define CONF_USB_COMPOSITE_IPRODUCT \ - (CONF_USB_COMPOSITE_IPRODUCT_EN * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN)) -#endif - -// Unicode string of iProduct -// usb_composite_iproduct_str -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR -#define CONF_USB_COMPOSITE_IPRODUCT_STR "Composite Demo" -#endif - -#ifndef CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#define CONF_USB_COMPOSITE_IPRODUCT_STR_DESC -#endif - -// - -// Enable string descriptor of iSerialNum -// usb_composite_iserialnum_en -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_EN -#define CONF_USB_COMPOSITE_ISERIALNUM_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM -#define CONF_USB_COMPOSITE_ISERIALNUM \ - (CONF_USB_COMPOSITE_ISERIALNUM_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN)) -#endif - -// Unicode string of iSerialNum -// usb_composite_iserialnum_str -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR -#define CONF_USB_COMPOSITE_ISERIALNUM_STR "123456789ABCDEF" -#endif - -#ifndef CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#define CONF_USB_COMPOSITE_ISERIALNUM_STR_DESC -#endif - -// - -// bNumConfigurations <0x01-0xFF> -// usb_composite_bnumconfig -#ifndef CONF_USB_COMPOSITE_BNUMCONFIG -#define CONF_USB_COMPOSITE_BNUMCONFIG 0x1 -#endif - -// - -// Composite Configuration Descriptor -// bConfigurationValue <0x01-0xFF> -// usb_composite_bconfigval -#ifndef CONF_USB_COMPOSITE_BCONFIGVAL -#define CONF_USB_COMPOSITE_BCONFIGVAL 0x1 -#endif -// Enable string descriptor of iConfig -// usb_composite_iconfig_en -#ifndef CONF_USB_COMPOSITE_ICONFIG_EN -#define CONF_USB_COMPOSITE_ICONFIG_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG -#define CONF_USB_COMPOSITE_ICONFIG \ - (CONF_USB_COMPOSITE_ICONFIG_EN \ - * (CONF_USB_COMPOSITE_IMANUFACT_EN + CONF_USB_COMPOSITE_IPRODUCT_EN + CONF_USB_COMPOSITE_ISERIALNUM_EN \ - + CONF_USB_COMPOSITE_ICONFIG_EN)) -#endif - -// Unicode string of iConfig -// usb_composite_iconfig_str -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR -#define CONF_USB_COMPOSITE_ICONFIG_STR "" -#endif - -#ifndef CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#define CONF_USB_COMPOSITE_ICONFIG_STR_DESC -#endif - -// - -// bmAttributes -// <0x80=> Bus power supply, not support for remote wakeup -// <0xA0=> Bus power supply, support for remote wakeup -// <0xC0=> Self powered, not support for remote wakeup -// <0xE0=> Self powered, support for remote wakeup -// usb_composite_bmattri -#ifndef CONF_USB_COMPOSITE_BMATTRI -#define CONF_USB_COMPOSITE_BMATTRI 0x80 -#endif - -// bMaxPower <0x00-0xFF> -// usb_composite_bmaxpower -#ifndef CONF_USB_COMPOSITE_BMAXPOWER -#define CONF_USB_COMPOSITE_BMAXPOWER 0x32 -#endif -// - -// CDC ACM Support -// usb_composite_cdc_acm_support -#ifndef CONF_USB_COMPOSITE_CDC_ACM_EN -#define CONF_USB_COMPOSITE_CDC_ACM_EN 0 -#endif - -// CDC ACM Comm Interrupt IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_EPADDR 0x82 -#endif - -// CDC ACM Comm Interrupt IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_comm_int_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_COMM_INT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_cdc_acm_data_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_EPADDR 0x81 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK IN Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_builin_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKIN_MAXPKSZ_HS 0x200 -#endif - -// CDC ACM Data BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_cdc_acm_data_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_EPADDR 0x1 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ 0x40 -#endif - -// CDC ACM Data BULK OUT Endpoint wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_cdc_acm_data_buckout_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_CDC_ACM_DATA_BULKOUT_MAXPKSZ_HS 0x200 -#endif - -// CDC ACM Echo Demo generation -// conf_usb_composite_cdc_echo_demo -// Invoke cdcdf_acm_demo_init(buf[wMaxPacketSize]) to enable the echo demo. -// Buf is packet buffer for data receive and echo back. -// The buffer is 4 byte aligned to support DMA. -#ifndef CONF_USB_COMPOSITE_CDC_ECHO_DEMO -#define CONF_USB_COMPOSITE_CDC_ECHO_DEMO 0 -#endif - -// - -// HID Mouse Support -// usb_composite_hid_mouse_support -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_EN -#define CONF_USB_COMPOSITE_HID_MOUSE_EN 0 -#endif - -// HID Mouse INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_mouse_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_EPADDR 0x83 -#endif - -// HID Mouse INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_mouse_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_MOUSE_INTIN_MAXPKSZ 0x8 -#endif - -// HID Mouse Move Demo generation -// conf_usb_composite_hid_mouse_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Button1 and button3 are the pins used for mouse moving left and right. -#ifndef CONF_USB_COMPOSITE_HID_MOUSE_DEMO -#define CONF_USB_COMPOSITE_HID_MOUSE_DEMO 0 -#endif - -// - -// HID Keyboard Support -// usb_composite_hid_keyboard_support -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_EN -#define CONF_USB_COMPOSITE_HID_KEYBOARD_EN 0 -#endif - -// HID Keyboard INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_keyboard_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_EPADDR 0x84 -#endif - -// HID Keyboard INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTIN_MAXPKSZ 0x8 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_keyboard_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_EPADDR 0x2 -#endif - -// HID Keyboard INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_keyboard_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_KEYBOARD_INTOUT_MAXPKSZ 0x8 -#endif - -// HID Keyboard Caps Lock Demo generation -// conf_usb_composite_hid_keyboard_demo -// Invoke hiddf_demo_init(button1, button2, button3) to enabled the move demo. -// Buffon2 is the pin used for keyboard CAPS LOCK simulation. -#ifndef CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO -#define CONF_USB_COMPOSITE_HID_KEYBOARD_DEMO 0 -#endif - -// - -// HID Generic Support -// usb_composite_hid_generic_support -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_EN -#define CONF_USB_COMPOSITE_HID_GENERIC_EN 0 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT_LEN 53 -#endif - -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_REPORT -#define CONF_USB_COMPOSITE_HID_GENERIC_REPORT \ - 0x06, 0xFF, 0xFF, 0x09, 0x01, 0xA1, 0x01, 0x09, 0x02, 0x09, 0x03, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, \ - 0x40, 0x81, 0x02, 0x09, 0x04, 0x09, 0x05, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x40, 0x91, 0x02, \ - 0x09, 0x06, 0x09, 0x07, 0x15, 0x00, 0x26, 0xFF, 0x00, 0x75, 0x08, 0x95, 0x04, 0xB1, 0x02, 0xC0 -#endif - -// HID Generic INTERRUPT IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_hid_generic_intin_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_EPADDR 0x85 -#endif - -// HID Generic INTERRUPT IN Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_hid_generic_intin_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTIN_MAXPKSZ 0x40 -#endif - -// HID Generic INTERRUPT OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_hid_generic_intout_epaddr -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_EPADDR 0x3 -#endif - -// HID Generic INTERRUPT OUT Endpoint wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// usb_composite_hid_generic_intout_maxpksz -// Please make sure that the setting here is coincide with the endpoint setting in USB device driver. -#ifndef CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ -#define CONF_USB_COMPOSITE_HID_GENERIC_INTOUT_MAXPKSZ 0x40 -#endif - -// - -// MSC Support -// usb_composite_msc_support -#ifndef CONF_USB_COMPOSITE_MSC_EN -#define CONF_USB_COMPOSITE_MSC_EN 0 -#endif - -// MSC BULK Endpoints wMaxPacketSize -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes - -// usb_composite_msc_bulk_maxpksz -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ 0x40 -#endif - -// MSC BULK Endpoints wMaxPacketSize for High Speed -// <0x0008=> 8 bytes -// <0x0010=> 16 bytes -// <0x0020=> 32 bytes -// <0x0040=> 64 bytes -// <0x0080=> 128 bytes -// <0x0100=> 256 bytes -// <0x0200=> 512 bytes - -// usb_composite_msc_bulk_maxpksz_hs -#ifndef CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS -#define CONF_USB_COMPOSITE_MSC_BULK_MAXPKSZ_HS 0x200 -#endif - -// MSC BULK IN Endpoint Address -// <0x81=> EndpointAddress = 0x81 -// <0x82=> EndpointAddress = 0x82 -// <0x83=> EndpointAddress = 0x83 -// <0x84=> EndpointAddress = 0x84 -// <0x85=> EndpointAddress = 0x85 -// <0x86=> EndpointAddress = 0x86 -// <0x87=> EndpointAddress = 0x87 -// <0x88=> EndpointAddress = 0x88 -// <0x89=> EndpointAddress = 0x89 - -// usb_composite_msc_bulkin_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKIN_EPADDR 0x86 -#endif - -// MSC BULK OUT Endpoint Address -// <0x01=> EndpointAddress = 0x01 -// <0x02=> EndpointAddress = 0x02 -// <0x03=> EndpointAddress = 0x03 -// <0x04=> EndpointAddress = 0x04 -// <0x05=> EndpointAddress = 0x05 -// <0x06=> EndpointAddress = 0x06 -// <0x07=> EndpointAddress = 0x07 -// <0x08=> EndpointAddress = 0x08 -// <0x09=> EndpointAddress = 0x09 - -// usb_composite_msc_bulkout_epaddr -#ifndef CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR -#define CONF_USB_COMPOSITE_MSC_BULKOUT_EPADDR 0x4 -#endif - -// Enable Demo code for Disk LUN handling -// usb_composite_msc_demo_en -#ifndef CONF_USB_COMPOSITE_MSC_LUN_DEMO -#define CONF_USB_COMPOSITE_MSC_LUN_DEMO 1 -#endif - -// Disk access cache/buffer of sectors if non-RAM disk (e.g., SD/MMC) enabled <1-64> -// conf_usb_msc_lun_buf_sectors -#ifndef CONF_USB_MSC_LUN_BUF_SECTORS -#define CONF_USB_MSC_LUN_BUF_SECTORS 4 -#endif - -// Enable Demo for RAM Disk -// conf_usb_msc_lun0_enable -#ifndef CONF_USB_MSC_LUN0_ENABLE -#define CONF_USB_MSC_LUN0_ENABLE 1 -#endif - -#ifndef CONF_USB_MSC_LUN0_TYPE -#define CONF_USB_MSC_LUN0_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun0_rmb -#ifndef CONF_USB_MSC_LUN0_RMB -#define CONF_USB_MSC_LUN0_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN0_ISO -#define CONF_USB_MSC_LUN0_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ECMA -#define CONF_USB_MSC_LUN0_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_ANSI -#define CONF_USB_MSC_LUN0_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_REPO -#define CONF_USB_MSC_LUN0_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN0_FACTORY -#define CONF_USB_MSC_LUN0_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT -#define CONF_USB_MSC_LUN0_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN0_PRODUCT_VERSION -#define CONF_USB_MSC_LUN0_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// Windows will not show disk less than 20K, so 22K is used to reserve more RAM for APP -// conf_usb_msc_lun0_capacity - -#ifndef CONF_USB_MSC_LUN0_CAPACITY -#define CONF_USB_MSC_LUN0_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN0_BLOCK_SIZE -#define CONF_USB_MSC_LUN0_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN0_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN0_CAPACITY * 1024 / CONF_USB_MSC_LUN0_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for SD/MMC Disk -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_enable -#ifndef CONF_USB_MSC_LUN1_ENABLE -#define CONF_USB_MSC_LUN1_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN1_TYPE -#define CONF_USB_MSC_LUN1_TYPE 0x00 -#endif - -// The disk is removable -// SD/MMC stack must be added before enable SD/MMC demo -// SD/MMC insert/eject not supported by this simple demo -// conf_usb_msc_lun1_rmb -#ifndef CONF_USB_MSC_LUN1_RMB -#define CONF_USB_MSC_LUN1_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN1_ISO -#define CONF_USB_MSC_LUN1_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ECMA -#define CONF_USB_MSC_LUN1_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_ANSI -#define CONF_USB_MSC_LUN1_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_REPO -#define CONF_USB_MSC_LUN1_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN1_FACTORY -#define CONF_USB_MSC_LUN1_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT -#define CONF_USB_MSC_LUN1_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_PRODUCT_VERSION -#define CONF_USB_MSC_LUN1_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN1_CAPACITY -#define CONF_USB_MSC_LUN1_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN1_BLOCK_SIZE -#define CONF_USB_MSC_LUN1_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN1_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN1_CAPACITY * 1024 / CONF_USB_MSC_LUN1_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 2 -// conf_usb_msc_lun2_enable -#ifndef CONF_USB_MSC_LUN2_ENABLE -#define CONF_USB_MSC_LUN2_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN2_TYPE -#define CONF_USB_MSC_LUN2_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun2_rmb -#ifndef CONF_USB_MSC_LUN2_RMB -#define CONF_USB_MSC_LUN2_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN2_ISO -#define CONF_USB_MSC_LUN2_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ECMA -#define CONF_USB_MSC_LUN2_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_ANSI -#define CONF_USB_MSC_LUN2_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_REPO -#define CONF_USB_MSC_LUN2_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN2_FACTORY -#define CONF_USB_MSC_LUN2_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT -#define CONF_USB_MSC_LUN2_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN2_PRODUCT_VERSION -#define CONF_USB_MSC_LUN2_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun2_capacity - -#ifndef CONF_USB_MSC_LUN2_CAPACITY -#define CONF_USB_MSC_LUN2_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN2_BLOCK_SIZE -#define CONF_USB_MSC_LUN2_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN2_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN2_CAPACITY * 1024 / CONF_USB_MSC_LUN2_BLOCK_SIZE - 1) -#endif - -// - -// Enable Demo for LUN 3 -// conf_usb_msc_lun3_enable -#ifndef CONF_USB_MSC_LUN3_ENABLE -#define CONF_USB_MSC_LUN3_ENABLE 0 -#endif - -#ifndef CONF_USB_MSC_LUN3_TYPE -#define CONF_USB_MSC_LUN3_TYPE 0x00 -#endif - -// The disk is removable -// conf_usb_msc_lun3_rmb -#ifndef CONF_USB_MSC_LUN3_RMB -#define CONF_USB_MSC_LUN3_RMB 0x1 -#endif - -#ifndef CONF_USB_MSC_LUN3_ISO -#define CONF_USB_MSC_LUN3_ISO 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ECMA -#define CONF_USB_MSC_LUN3_ECMA 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_ANSI -#define CONF_USB_MSC_LUN3_ANSI 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_REPO -#define CONF_USB_MSC_LUN3_REPO 0x01 -#endif - -#ifndef CONF_USB_MSC_LUN3_FACTORY -#define CONF_USB_MSC_LUN3_FACTORY 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT -#define CONF_USB_MSC_LUN3_PRODUCT 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -#endif - -#ifndef CONF_USB_MSC_LUN3_PRODUCT_VERSION -#define CONF_USB_MSC_LUN3_PRODUCT_VERSION 0x00, 0x00, 0x00, 0x00 -#endif - -// Disk Size (in KB) <0x1-0xFFFFFFFF> -// conf_usb_msc_lun3_capacity - -#ifndef CONF_USB_MSC_LUN3_CAPACITY -#define CONF_USB_MSC_LUN3_CAPACITY 22 -#endif - -#ifndef CONF_USB_MSC_LUN3_BLOCK_SIZE -#define CONF_USB_MSC_LUN3_BLOCK_SIZE 512 -#endif - -#ifndef CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR -#define CONF_USB_MSC_LUN3_LAST_BLOCK_ADDR \ - ((uint32_t)CONF_USB_MSC_LUN3_CAPACITY * 1024 / CONF_USB_MSC_LUN3_BLOCK_SIZE - 1) -#endif - -// - -// -// - -// <<< end of configuration section >>> - -#endif // USBD_CONFIG_H diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index fe212f6fb6..295682e905 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -145,6 +145,20 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO) CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO) +# bitmaptools and framebufferio rely on displayio +ifeq ($(CIRCUITPY_DISPLAYIO),1) +CIRCUITPY_BITMAPTOOLS ?= $(CIRCUITPY_FULL_BUILD) +CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD) +CIRCUITPY_VECTORIO ?= 1 +else +CIRCUITPY_BITMAPTOOLS ?= 0 +CIRCUITPY_FRAMEBUFFERIO ?= 0 +CIRCUITPY_VECTORIO ?= 0 +endif +CFLAGS += -DCIRCUITPY_BITMAPTOOLS=$(CIRCUITPY_BITMAPTOOLS) +CFLAGS += -DCIRCUITPY_FRAMEBUFFERIO=$(CIRCUITPY_FRAMEBUFFERIO) +CFLAGS += -DCIRCUITPY_VECTORIO=$(CIRCUITPY_VECTORIO) + CIRCUITPY_DUALBANK ?= 0 CFLAGS += -DCIRCUITPY_DUALBANK=$(CIRCUITPY_DUALBANK) @@ -161,20 +175,6 @@ CFLAGS += -DCIRCUITPY_ERRNO=$(CIRCUITPY_ERRNO) CIRCUITPY_ESPIDF ?= 0 CFLAGS += -DCIRCUITPY_ESPIDF=$(CIRCUITPY_ESPIDF) -# bitmaptools and framebufferio rely on displayio -ifeq ($(CIRCUITPY_DISPLAYIO),1) -CIRCUITPY_BITMAPTOOLS ?= $(CIRCUITPY_FULL_BUILD) -CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD) -else -CIRCUITPY_BITMAPTOOLS ?= 0 -CIRCUITPY_FRAMEBUFFERIO ?= 0 -endif -CFLAGS += -DCIRCUITPY_BITMAPTOOLS=$(CIRCUITPY_BITMAPTOOLS) -CFLAGS += -DCIRCUITPY_FRAMEBUFFERIO=$(CIRCUITPY_FRAMEBUFFERIO) - -CIRCUITPY_VECTORIO ?= $(CIRCUITPY_DISPLAYIO) -CFLAGS += -DCIRCUITPY_VECTORIO=$(CIRCUITPY_VECTORIO) - CIRCUITPY_FREQUENCYIO ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_FREQUENCYIO=$(CIRCUITPY_FREQUENCYIO) diff --git a/shared-bindings/storage/__init__.c b/shared-bindings/storage/__init__.c index 75a271f64d..754b6866c8 100644 --- a/shared-bindings/storage/__init__.c +++ b/shared-bindings/storage/__init__.c @@ -166,7 +166,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(storage_erase_filesystem_obj, storage_erase_filesystem //| STATIC mp_obj_t storage_disable_usb_drive(void) { if (!common_hal_storage_disable_usb_drive()) { - mp_raise_RuntimeError(translate("Cannot change usb devices now")); + mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } @@ -181,7 +181,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(storage_disable_usb_drive_obj, storage_disable_usb_dri //| STATIC mp_obj_t storage_enable_usb_drive(void) { if (!common_hal_storage_enable_usb_drive()) { - mp_raise_RuntimeError(translate("Cannot change usb devices now")); + mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index de9cb8bfef..67247c8f64 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -31,14 +31,6 @@ //| class Device: //| """HID Device //| -//| Usage:: -//| -//| import usb_hid -//| -//| mouse = usb_hid.devices[0] -//| mouse.send_report()""" -//| - //| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: int = 0, report_id_index: Optional[int]) -> None: //| """Create a description of a USB HID device. The actual device is created when you //| pass a `Device` to `usb_hid.enable()`. @@ -57,6 +49,17 @@ //| """ //| ... //| +//| KEYBOARD: Device +//| """Standard keyboard device supporting keycodes 0x00-0xDD, modifiers 0xE-0xE7, and five LED indicators.""" +//| +//| MOUSE: Device +//| """Standard mouse device supporting five mouse buttons, X and Y relative movements from -127 to 127 +//| in each report, and a relative mouse wheel change from -127 to 127 in each report.""" +//| +//| CONSUMER_CONTROL: Device +//| """Consumer Control device supporting sent values from 1-652, with no rollover.""" +//| + STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { usb_hid_device_obj_t *self = m_new_obj(usb_hid_device_obj_t); self->base.type = &usb_hid_device_type; diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index cd73e1b9f9..661fd79af8 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -165,38 +165,47 @@ void print_safe_mode_message(safe_mode_t reason) { } serial_write_compressed(translate("CircuitPython core code crashed hard. Whoops!\n")); + + const compressed_string_t *message = NULL; switch (reason) { case HARD_CRASH: - serial_write_compressed(translate("Crash into the HardFault_Handler.")); - return; + message = translate("Crash into the HardFault_Handler."); + break; case MICROPY_NLR_JUMP_FAIL: - serial_write_compressed(translate("NLR jump failed. Likely memory corruption.")); - return; + message = translate("NLR jump failed. Likely memory corruption."); + break; case MICROPY_FATAL_ERROR: - serial_write_compressed(translate("Fatal error.")); + message = translate("Fatal error."); break; case GC_ALLOC_OUTSIDE_VM: - serial_write_compressed(translate("Attempted heap allocation when VM not running.")); + message = translate("Attempted heap allocation when VM not running."); break; #ifdef SOFTDEVICE_PRESENT // defined in ports/nrf/bluetooth/bluetooth_common.mk // will print "Unknown reason" if somehow encountered on other ports case NORDIC_SOFT_DEVICE_ASSERT: - serial_write_compressed(translate("Nordic system firmware failure assertion.")); + message = translate("Nordic system firmware failure assertion."); break; #endif case FLASH_WRITE_FAIL: - serial_write_compressed(translate("Failed to write internal flash.")); + message = translate("Failed to write internal flash."); break; case MEM_MANAGE: - serial_write_compressed(translate("Invalid memory access.")); + message = translate("Invalid memory access."); break; case WATCHDOG_RESET: - serial_write_compressed(translate("Watchdog timer expired.")); + message = translate("Watchdog timer expired."); + break; + case USB_TOO_MANY_ENDPOINTS: + message = translate("USB devices need more endpoints than are available."); + break; + case USB_TOO_MANY_INTERFACE_NAMES: + message = translate("USB devices specify too many interface names."); break; default: - serial_write_compressed(translate("Unknown reason.")); + message = translate("Unknown reason."); break; } + serial_write_compressed(message); serial_write_compressed(FILE_AN_ISSUE); } diff --git a/supervisor/shared/safe_mode.h b/supervisor/shared/safe_mode.h index 722e970333..01aed37d63 100644 --- a/supervisor/shared/safe_mode.h +++ b/supervisor/shared/safe_mode.h @@ -44,6 +44,8 @@ typedef enum { FLASH_WRITE_FAIL, MEM_MANAGE, WATCHDOG_RESET, + USB_TOO_MANY_ENDPOINTS, + USB_TOO_MANY_INTERFACE_NAMES, NO_HEAP, } safe_mode_t; diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 38289552d6..99a769c704 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -29,6 +29,7 @@ #include "py/objstr.h" #include "py/runtime.h" #include "supervisor/memory.h" +#include "supervisor/shared/safe_mode.h" #include "supervisor/usb.h" #if CIRCUITPY_USB_CDC @@ -231,7 +232,7 @@ static void usb_build_configuration_descriptor(void) { // Did we run out of endpoints? if (current_endpoint - 1 > USB_NUM_EP) { - mp_raise_RuntimeError(translate("Not enough USB endpoints")); + reset_into_safe_mode(USB_TOO_MANY_ENDPOINTS); } } @@ -239,7 +240,7 @@ static void usb_build_configuration_descriptor(void) { // str must not be on the heap. void usb_add_interface_string(uint8_t interface_string_index, const char str[]) { if (interface_string_index > MAX_INTERFACE_STRINGS) { - mp_raise_RuntimeError(translate("Too many USB interface names")); + reset_into_safe_mode(USB_TOO_MANY_INTERFACE_NAMES); } collected_interface_strings[interface_string_index].char_str = str; From c37f021791ec3d9afc8ba34445e9fb0d4eb4d211 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 5 May 2021 12:35:41 -0400 Subject: [PATCH 59/66] regularize and shrink many builds --- .github/workflows/build.yml | 1 - frozen/Adafruit_CircuitPython_SimpleMath | 2 +- .../boards/8086_commander/mpconfigboard.mk | 4 -- .../mpconfigboard.mk | 25 +++-------- .../mpconfigboard.mk | 27 ++++------- .../mpconfigboard.mk | 13 +----- .../mpconfigboard.mk | 15 +------ .../boards/arduino_mkr1300/mpconfigboard.mk | 3 -- .../boards/arduino_mkrzero/mpconfigboard.mk | 3 -- .../arduino_nano_33_iot/mpconfigboard.mk | 3 -- .../boards/arduino_zero/mpconfigboard.mk | 3 -- .../boards/bast_pro_mini_m0/mpconfigboard.mk | 3 -- .../boards/bdmicro_vina_d21/mpconfigboard.mk | 13 ------ .../boards/blm_badge/mpconfigboard.mk | 5 +-- .../boards/catwan_usbstick/mpconfigboard.mk | 4 -- .../circuitbrains_basic_m0/mpconfigboard.mk | 26 ----------- .../mpconfigboard.mk | 13 +++--- .../mpconfigboard.mk | 14 +----- .../mpconfigboard.mk | 15 ++----- .../boards/cp_sapling_m0/mpconfigboard.mk | 3 -- .../cp_sapling_m0_revb/mpconfigboard.mk | 3 -- .../cp_sapling_m0_spiflash/mpconfigboard.mk | 18 -------- .../boards/datum_distance/mpconfigboard.mk | 3 -- .../boards/datum_imu/mpconfigboard.mk | 3 -- .../boards/datum_light/mpconfigboard.mk | 3 -- .../boards/datum_weather/mpconfigboard.mk | 3 -- .../boards/dynalora_usb/mpconfigboard.mk | 22 +-------- .../boards/dynossat_edu_eps/mpconfigboard.mk | 9 ---- .../boards/dynossat_edu_obc/mpconfigboard.mk | 3 -- .../boards/escornabot_makech/mpconfigboard.mk | 4 -- .../feather_m0_adalogger/mpconfigboard.mk | 3 -- .../boards/feather_m0_basic/mpconfigboard.mk | 3 -- .../feather_m0_express/mpconfigboard.mk | 12 ----- .../mpconfigboard.mk | 7 --- .../boards/feather_m0_rfm69/mpconfigboard.mk | 8 ---- .../boards/feather_m0_rfm9x/mpconfigboard.mk | 8 ---- .../feather_m0_supersized/mpconfigboard.mk | 16 ------- .../boards/feather_m4_can/mpconfigboard.mk | 1 - .../feather_m4_express/mpconfigboard.mk | 1 - .../boards/feather_radiofruit_zigbee/board.c | 37 --------------- .../feather_radiofruit_zigbee/mpconfigboard.h | 31 ------------- .../mpconfigboard.mk | 39 ---------------- .../boards/feather_radiofruit_zigbee/pins.c | 45 ------------------- .../boards/fluff_m0/mpconfigboard.mk | 3 -- .../boards/gemma_m0/mpconfigboard.mk | 3 -- .../hallowing_m0_express/mpconfigboard.mk | 13 ------ .../boards/huntercat_nfc/mpconfigboard.mk | 14 ------ .../itsybitsy_m0_express/mpconfigboard.mk | 30 ------------- .../boards/meowmeow/mpconfigboard.mk | 6 --- .../boards/metro_m0_express/mpconfigboard.mk | 12 ----- .../boards/ndgarage_ndbit6/mpconfigboard.mk | 3 -- .../ndgarage_ndbit6_v2/mpconfigboard.mk | 3 -- .../neopixel_trinkey_m0/mpconfigboard.mk | 10 +---- .../boards/pewpew10/mpconfigboard.mk | 7 --- .../boards/picoplanet/mpconfigboard.mk | 3 -- .../boards/pirkey_m0/mpconfigboard.mk | 7 +-- .../boards/pyruler/mpconfigboard.mk | 5 --- .../boards/qtpy_m0/mpconfigboard.mk | 3 -- .../boards/qtpy_m0_haxpress/mpconfigboard.mk | 13 ------ .../atmel-samd/boards/sam32/mpconfigboard.mk | 4 -- .../seeeduino_wio_terminal/mpconfigboard.mk | 2 - .../boards/seeeduino_xiao/mpconfigboard.mk | 3 -- .../boards/sensebox_mcu/mpconfigboard.mk | 3 -- .../boards/serpente/mpconfigboard.mk | 10 ----- .../boards/shirtty/mpconfigboard.mk | 5 --- .../silicognition-m4-shim/mpconfigboard.mk | 2 - .../boards/snekboard/mpconfigboard.mk | 27 ----------- .../sparkfun_lumidrive/mpconfigboard.mk | 6 --- .../mpconfigboard.mk | 3 -- .../mpconfigboard.mk | 1 - .../sparkfun_redboard_turbo/mpconfigboard.mk | 27 ----------- .../sparkfun_samd21_dev/mpconfigboard.mk | 3 -- .../sparkfun_samd21_mini/mpconfigboard.mk | 3 -- .../stackrduino_m0_pro/mpconfigboard.mk | 14 ------ .../stringcar_m0_express/mpconfigboard.mk | 26 ----------- .../boards/trinket_m0/mpconfigboard.mk | 6 --- .../trinket_m0_haxpress/mpconfigboard.mk | 16 ------- .../atmel-samd/boards/uchip/mpconfigboard.mk | 3 -- .../boards/ugame10/mpconfigboard.mk | 2 - .../boards/xinabox_cc03/mpconfigboard.mk | 6 +-- .../boards/xinabox_cs11/mpconfigboard.mk | 12 ++--- ports/atmel-samd/mpconfigport.mk | 41 +++++++++++------ 82 files changed, 70 insertions(+), 767 deletions(-) delete mode 100644 ports/atmel-samd/boards/feather_radiofruit_zigbee/board.c delete mode 100644 ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.h delete mode 100755 ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.mk delete mode 100755 ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 95b5379d59..9d52667879 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -238,7 +238,6 @@ jobs: - "feather_mimxrt1011" - "feather_mimxrt1062" - "feather_nrf52840_express" - - "feather_radiofruit_zigbee" - "feather_stm32f405_express" - "fluff_m0" - "gemma_m0" diff --git a/frozen/Adafruit_CircuitPython_SimpleMath b/frozen/Adafruit_CircuitPython_SimpleMath index cdf9944730..5f382650e6 160000 --- a/frozen/Adafruit_CircuitPython_SimpleMath +++ b/frozen/Adafruit_CircuitPython_SimpleMath @@ -1 +1 @@ -Subproject commit cdf99447307473080b2f2e95e7c3667247095ac0 +Subproject commit 5f382650e62e05cc72a67dbedce13d706d699621 diff --git a/ports/atmel-samd/boards/8086_commander/mpconfigboard.mk b/ports/atmel-samd/boards/8086_commander/mpconfigboard.mk index c7918ad05c..200eea0630 100644 --- a/ports/atmel-samd/boards/8086_commander/mpconfigboard.mk +++ b/ports/atmel-samd/boards/8086_commander/mpconfigboard.mk @@ -11,10 +11,6 @@ EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ" LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -CIRCUITPY_USB_MIDI = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 CIRCUITPY_GAMEPAD = 1 CIRCUITPY_BUSDEVICE = 1 diff --git a/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk index 56cbede39f..a552fc3d64 100644 --- a/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk @@ -8,26 +8,15 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE - -CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 -CIRCUITPY_PS2IO = 0 -CIRCUITPY_PULSEIO = 0 -CIRCUITPY_PWMIO = 0 -CIRCUITPY_AUDIOCORE = 0 -CIRCUITPY_BUSIO = 0 -CIRCUITPY_STORAGE = 1 - -CIRCUITPY_MATH = 1 -CIRCUITPY_PIXELBUF = 1 -CIRCUITPY_USB_MIDI = 1 -CIRCUITPY_TOUCHIO = 1 CIRCUITPY_FULL_BUILD = 0 -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 +CIRCUITPY_ANALOGIO = 0 +CIRCUITPY_AUDIOCORE = 0 +CIRCUITPY_BUSIO = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_RTC = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk index 92e7a17f3e..49e5a88c57 100644 --- a/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk @@ -8,26 +8,17 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE - -CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 -CIRCUITPY_PS2IO = 0 -CIRCUITPY_PULSEIO = 0 -CIRCUITPY_PWMIO = 0 -CIRCUITPY_AUDIOCORE = 0 -CIRCUITPY_BUSIO = 1 -CIRCUITPY_STORAGE = 1 - -CIRCUITPY_MATH = 1 -CIRCUITPY_PIXELBUF = 0 -CIRCUITPY_USB_MIDI = 1 -CIRCUITPY_TOUCHIO = 1 CIRCUITPY_FULL_BUILD = 0 -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 +CIRCUITPY_ANALOGIO = 0 +CIRCUITPY_AUDIOCORE = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_RTC = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 0 + +CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_TOUCHIO = 1 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID diff --git a/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.mk index 29cc9ee195..b596c726cd 100644 --- a/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.mk @@ -8,26 +8,15 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE +CIRCUITPY_FULL_BUILD = 0 CIRCUITPY_ANALOGIO = 0 -CIRCUITPY_ROTARYIO = 1 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 -CIRCUITPY_PS2IO = 0 CIRCUITPY_PULSEIO = 0 CIRCUITPY_PWMIO = 0 CIRCUITPY_AUDIOCORE = 0 CIRCUITPY_BUSIO = 0 -CIRCUITPY_STORAGE = 1 - -CIRCUITPY_MATH = 0 -CIRCUITPY_PIXELBUF = 1 -CIRCUITPY_USB_MIDI = 1 CIRCUITPY_TOUCHIO = 0 -CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk index 2bc2def52e..5ef783908b 100644 --- a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk @@ -9,25 +9,14 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE -CIRCUITPY_ANALOGIO = 1 +CIRCUITPY_FULL_BUILD = 0 + CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 -CIRCUITPY_PS2IO = 0 CIRCUITPY_PULSEIO = 0 CIRCUITPY_PWMIO = 0 CIRCUITPY_AUDIOCORE = 0 CIRCUITPY_BUSIO = 0 -CIRCUITPY_STORAGE = 1 - -CIRCUITPY_MATH = 1 -CIRCUITPY_PIXELBUF = 1 -CIRCUITPY_USB_MIDI = 1 -CIRCUITPY_TOUCHIO = 1 -CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SimpleMath diff --git a/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk index 1fd96b0aee..c3d75202bf 100644 --- a/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk index fabe52ce23..eea3a27f13 100644 --- a/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_mkrzero/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk index c16c53e6d6..895c027ee5 100644 --- a/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk index 697ec02c36..5ee22c59ad 100644 --- a/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk +++ b/ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk b/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk index ec037837e5..055e6b19e2 100644 --- a/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/bast_pro_mini_m0/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk b/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk index fea765c3f0..1a8cddfda7 100644 --- a/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk +++ b/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk @@ -9,16 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "MX25L51245G","GD25S512MD" LONGINT_IMPL = MPZ - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 - -CFLAGS_INLINE_LIMIT = 60 -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 diff --git a/ports/atmel-samd/boards/blm_badge/mpconfigboard.mk b/ports/atmel-samd/boards/blm_badge/mpconfigboard.mk index 794e38d792..8ba3ae94c3 100644 --- a/ports/atmel-samd/boards/blm_badge/mpconfigboard.mk +++ b/ports/atmel-samd/boards/blm_badge/mpconfigboard.mk @@ -14,11 +14,8 @@ CIRCUITPY_AUDIOIO = 1 CIRCUITPY_AUDIOBUSIO = 1 # Pins for I2SOut are not available. CIRCUITPY_AUDIOBUSIO_I2SOUT = 0 -CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 CIRCUITPY_USB_HID = 1 CIRCUITPY_USB_MIDI = 0 - -SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/catwan_usbstick/mpconfigboard.mk b/ports/atmel-samd/boards/catwan_usbstick/mpconfigboard.mk index b1306f54b6..8724e0d4bb 100644 --- a/ports/atmel-samd/boards/catwan_usbstick/mpconfigboard.mk +++ b/ports/atmel-samd/boards/catwan_usbstick/mpconfigboard.mk @@ -9,7 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_ROTARYIO = 0 - -SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/circuitbrains_basic_m0/mpconfigboard.mk b/ports/atmel-samd/boards/circuitbrains_basic_m0/mpconfigboard.mk index 870edb06ee..fbc67f3c71 100755 --- a/ports/atmel-samd/boards/circuitbrains_basic_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitbrains_basic_m0/mpconfigboard.mk @@ -9,29 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" LONGINT_IMPL = MPZ - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 -MICROPY_PY_ASYNC_AWAIT = 0 - -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif diff --git a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk index 97434a90b8..5311cdc1d4 100644 --- a/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express/mpconfigboard.mk @@ -10,16 +10,13 @@ SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" LONGINT_IMPL = MPZ -# Make room for frozen libs. -CIRCUITPY_BITMAPTOOLS = 0 +# Turn off displayio to make room for frozen libs. CIRCUITPY_DISPLAYIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -MICROPY_PY_ASYNC_AWAIT = 0 -SUPEROPT_GC = 0 -CFLAGS_INLINE_LIMIT = 55 +# Now we actually have a lot of room. Put back some useful modules. +CIRCUITPY_BITBANGIO = 1 +CIRCUITPY_COUNTIO = 1 +CIRCUITPY_BUSDEVICE = 1 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground diff --git a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk index d6994a4c01..902e9594e3 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express_crickit/mpconfigboard.mk @@ -11,19 +11,9 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" # Turn off features and optimizations for Crickit build to make room for additional frozen libs. LONGINT_IMPL = NONE -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 + +CIRCUITPY_BUSDEVICE = 1 CIRCUITPY_DISPLAYIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_PIXELBUF = 1 -CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_RTC = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 - # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground diff --git a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk index ec85666719..68fb51ab00 100644 --- a/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk +++ b/ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.mk @@ -9,23 +9,16 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" -# Turn off features and optimizations for Crickit build to make room for additional frozen libs. +# Turn off features and optimizations for displayio build to make room for additional frozen libs. LONGINT_IMPL = NONE -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 CIRCUITPY_PIXELBUF = 0 -CIRCUITPY_RE = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 +CIRCUITPY_USB_MIDI = 0 + # So not all of displayio, sorry! CIRCUITPY_VECTORIO = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 +CIRCUITPY_BITMAPTOOLS = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_CircuitPlayground diff --git a/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk index 3799d7ef73..4b32f1f623 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp_sapling_m0/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk index 173327a3af..6bf1d73079 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/cp_sapling_m0_spiflash/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0_spiflash/mpconfigboard.mk index 1a1bf8cc79..7a060a168b 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_spiflash/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp_sapling_m0_spiflash/mpconfigboard.mk @@ -13,21 +13,3 @@ EXTERNAL_FLASH_DEVICES = AT25DF081A CIRCUITPY_AUDIOIO = 0 CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 - -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif diff --git a/ports/atmel-samd/boards/datum_distance/mpconfigboard.mk b/ports/atmel-samd/boards/datum_distance/mpconfigboard.mk index 22b55f6fd5..f51bd9a5c9 100644 --- a/ports/atmel-samd/boards/datum_distance/mpconfigboard.mk +++ b/ports/atmel-samd/boards/datum_distance/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/datum_imu/mpconfigboard.mk b/ports/atmel-samd/boards/datum_imu/mpconfigboard.mk index 7e99182912..9c3b642330 100644 --- a/ports/atmel-samd/boards/datum_imu/mpconfigboard.mk +++ b/ports/atmel-samd/boards/datum_imu/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/datum_light/mpconfigboard.mk b/ports/atmel-samd/boards/datum_light/mpconfigboard.mk index 5916f23b31..a34b751042 100644 --- a/ports/atmel-samd/boards/datum_light/mpconfigboard.mk +++ b/ports/atmel-samd/boards/datum_light/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/datum_weather/mpconfigboard.mk b/ports/atmel-samd/boards/datum_weather/mpconfigboard.mk index 1065fb50aa..01a9063654 100644 --- a/ports/atmel-samd/boards/datum_weather/mpconfigboard.mk +++ b/ports/atmel-samd/boards/datum_weather/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/dynalora_usb/mpconfigboard.mk b/ports/atmel-samd/boards/dynalora_usb/mpconfigboard.mk index 8b2ce7fbf4..3c88b60a37 100644 --- a/ports/atmel-samd/boards/dynalora_usb/mpconfigboard.mk +++ b/ports/atmel-samd/boards/dynalora_usb/mpconfigboard.mk @@ -10,28 +10,10 @@ SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = GD25Q32C LONGINT_IMPL = MPZ -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_GAMEPAD = 0 -CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FULL_BUILD = 0 -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif +CIRCUITPY_DISPLAYIO = 0 +CIRCUITPY_SDCARDIO = 1 FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_RFM9x diff --git a/ports/atmel-samd/boards/dynossat_edu_eps/mpconfigboard.mk b/ports/atmel-samd/boards/dynossat_edu_eps/mpconfigboard.mk index 915270c579..04cc49e181 100644 --- a/ports/atmel-samd/boards/dynossat_edu_eps/mpconfigboard.mk +++ b/ports/atmel-samd/boards/dynossat_edu_eps/mpconfigboard.mk @@ -14,15 +14,6 @@ LONGINT_IMPL = MPZ CIRCUITPY_FULLBUILD = 0 CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_I2CPERIPHERAL = 1 -CIRCUITPY_VECTORIO = 0 CIRCUITPY_BUSDEVICE = 0 -CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_ROTARYIO = 0 - -CFLAGS_INLINE_LIMIT = 60 - -SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/dynossat_edu_obc/mpconfigboard.mk b/ports/atmel-samd/boards/dynossat_edu_obc/mpconfigboard.mk index 8f552c5b4d..8ac6c0a2d0 100644 --- a/ports/atmel-samd/boards/dynossat_edu_obc/mpconfigboard.mk +++ b/ports/atmel-samd/boards/dynossat_edu_obc/mpconfigboard.mk @@ -10,6 +10,3 @@ CHIP_FAMILY = samd51 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "GD25Q32C" LONGINT_IMPL = MPZ - -CFLAGS_INLINE_LIMIT = 60 -SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk b/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk index ffe76d9307..7317dfbf1b 100644 --- a/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk +++ b/ports/atmel-samd/boards/escornabot_makech/mpconfigboard.mk @@ -9,7 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -CIRCUITPY_RTC = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk index ab6c4ed99d..62336ecf50 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk index 183a80ffa4..cfd1f63cb3 100644 --- a/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_basic/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk index fcf1b4a1aa..3aa03e61f6 100644 --- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk @@ -9,15 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" LONGINT_IMPL = MPZ - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk index e29f3c0b29..d18d986e6d 100644 --- a/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_express_crickit/mpconfigboard.mk @@ -11,14 +11,7 @@ EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" LONGINT_IMPL = MPZ # Make space for frozen libs -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_DISPLAYIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_GAMEPAD = 0 -CFLAGS_INLINE_LIMIT = 50 -CIRCUITPY_MSGPACK = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Crickit diff --git a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk index b544a3680a..48c0f47064 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk @@ -13,20 +13,12 @@ CIRCUITPY_FULL_BUILD = 0 # A number of modules are removed for RFM69 to make room for frozen libraries. # Many I/O functions are not available. CIRCUITPY_ANALOGIO = 1 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_PULSEIO = 0 -CIRCUITPY_NEOPIXEL_WRITE = 1 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_HID = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_BUSDEVICE = 1 -CFLAGS_INLINE_LIMIT = 35 - -# Make more room. -SUPEROPT_GC = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_RFM69 diff --git a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk index e307ab4f6b..4003dd67f0 100644 --- a/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_rfm9x/mpconfigboard.mk @@ -14,20 +14,12 @@ CIRCUITPY_FULL_BUILD = 0 # A number of modules are removed for RFM9x to make room for frozen libraries. # Many I/O functions are not available. CIRCUITPY_ANALOGIO = 1 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_PULSEIO = 0 -CIRCUITPY_NEOPIXEL_WRITE = 1 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 CIRCUITPY_USB_MIDI = 0 CIRCUITPY_USB_HID = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_BUSDEVICE = 1 -CFLAGS_INLINE_LIMIT = 35 -# Make more room. -SUPEROPT_GC = 0 - # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_RFM9x diff --git a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk index 5921bd2f1a..811336885b 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.mk @@ -9,19 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL064L" LONGINT_IMPL = MPZ - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_BUSDEVICE = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -# supersized, not ultra-supersized -CIRCUITPY_VECTORIO = 0 - -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 diff --git a/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk index 4c0c5137c1..ecadf211ff 100644 --- a/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m4_can/mpconfigboard.mk @@ -10,5 +10,4 @@ QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ -CIRCUITPY_VECTORIO = 1 CIRCUITPY_CANIO = 1 diff --git a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk index a8b4460a6e..2606572d8c 100644 --- a/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m4_express/mpconfigboard.mk @@ -10,5 +10,4 @@ QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ -CIRCUITPY_VECTORIO = 1 CIRCUITPY__EVE = 1 diff --git a/ports/atmel-samd/boards/feather_radiofruit_zigbee/board.c b/ports/atmel-samd/boards/feather_radiofruit_zigbee/board.c deleted file mode 100644 index 84960e73cf..0000000000 --- a/ports/atmel-samd/boards/feather_radiofruit_zigbee/board.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "supervisor/board.h" - -void board_init(void) { -} - -bool board_requests_safe_mode(void) { - return false; -} - -void reset_board(void) { -} diff --git a/ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.h b/ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.h deleted file mode 100644 index b1839f2c99..0000000000 --- a/ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.h +++ /dev/null @@ -1,31 +0,0 @@ -#define MICROPY_HW_BOARD_NAME "Adafruit Feather RadioFruit Zigbee" -#define MICROPY_HW_MCU_NAME "samr21g18" - -#define MICROPY_HW_LED_STATUS (&pin_PA27) -#define MICROPY_HW_NEOPIXEL (&pin_PA22) - -#define SPI_FLASH_MOSI_PIN &pin_PA31 -#define SPI_FLASH_MISO_PIN &pin_PA30 -#define SPI_FLASH_SCK_PIN &pin_PA17 -#define SPI_FLASH_CS_PIN &pin_PA28 - -// These are pins not to reset. -#define MICROPY_PORT_A (PORT_PA22) -#define MICROPY_PORT_B (0) -#define MICROPY_PORT_C (0) - -#define BOARD_HAS_CRYSTAL 1 - -#define DEFAULT_I2C_BUS_SCL (&pin_PA13) -#define DEFAULT_I2C_BUS_SDA (&pin_PA12) - -#define DEFAULT_SPI_BUS_SCK (&pin_PB23) -#define DEFAULT_SPI_BUS_MOSI (&pin_PB22) -#define DEFAULT_SPI_BUS_MISO (&pin_PA23) - -#define DEFAULT_UART_BUS_RX (&pin_PA09) -#define DEFAULT_UART_BUS_TX (&pin_PA08) - -// USB is always used internally so skip the pin objects for it. -#define IGNORE_PIN_PA24 1 -#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.mk b/ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.mk deleted file mode 100755 index 29774db742..0000000000 --- a/ports/atmel-samd/boards/feather_radiofruit_zigbee/mpconfigboard.mk +++ /dev/null @@ -1,39 +0,0 @@ -USB_VID = 0x239A -USB_PID = 0x80D0 -USB_PRODUCT = "Feather RadioFruit Zigbee" -USB_MANUFACTURER = "Adafruit Industries LLC" - -CHIP_VARIANT = SAMR21G18A -CHIP_FAMILY = samd21 - -SPI_FLASH_FILESYSTEM = 1 -EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" -LONGINT_IMPL = MPZ - -# No I2S on SAMR21G -CIRCUITPY_AUDIOBUSIO = 0 -# No DAC on SAMR21G -CIRCUITPY_AUDIOIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_RTC = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 - -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif diff --git a/ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c b/ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c deleted file mode 100755 index 7133978784..0000000000 --- a/ports/atmel-samd/boards/feather_radiofruit_zigbee/pins.c +++ /dev/null @@ -1,45 +0,0 @@ -#include "shared-bindings/board/__init__.h" - -STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PB02) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PB03) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA04) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA05) }, - { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA06) }, - { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA07) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PB23) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB22) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA23) }, - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA12) }, - { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA13) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA14) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA15) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA16) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA19) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA27) }, - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, - - // Internally connected within the package - { MP_ROM_QSTR(MP_QSTR_DIG3), MP_ROM_PTR(&pin_PA10) }, - { MP_ROM_QSTR(MP_QSTR_DIG4), MP_ROM_PTR(&pin_PA11) }, - { MP_ROM_QSTR(MP_QSTR_SLP_TR), MP_ROM_PTR(&pin_PA20) }, - { MP_ROM_QSTR(MP_QSTR_IRQ), MP_ROM_PTR(&pin_PB00) }, - { MP_ROM_QSTR(MP_QSTR_DIG1), MP_ROM_PTR(&pin_PA16) }, - { MP_ROM_QSTR(MP_QSTR_DIG2), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_RF_MOSI), MP_ROM_PTR(&pin_PB30) }, - { MP_ROM_QSTR(MP_QSTR_SEL), MP_ROM_PTR(&pin_PB31) }, - { MP_ROM_QSTR(MP_QSTR_CLKM), MP_ROM_PTR(&pin_PC16) }, - { MP_ROM_QSTR(MP_QSTR_RF_SCK), MP_ROM_PTR(&pin_PC18) }, - { MP_ROM_QSTR(MP_QSTR_RF_MISO), MP_ROM_PTR(&pin_PC19) }, - { MP_ROM_QSTR(MP_QSTR_RESETN), MP_ROM_PTR(&pin_PB15) }, -}; -MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/fluff_m0/mpconfigboard.mk b/ports/atmel-samd/boards/fluff_m0/mpconfigboard.mk index 52fcaec020..8825143d02 100644 --- a/ports/atmel-samd/boards/fluff_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/fluff_m0/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk index 9d086c8f59..f37b8c7be7 100644 --- a/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/gemma_m0/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk index e97f9884da..300419fa19 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/hallowing_m0_express/mpconfigboard.mk @@ -12,20 +12,7 @@ LONGINT_IMPL = NONE # To keep the build small CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_GAMEPAD = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_RTC = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_VECTORIO = 0 - -CFLAGS_INLINE_LIMIT = 55 -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_LIS3DH diff --git a/ports/atmel-samd/boards/huntercat_nfc/mpconfigboard.mk b/ports/atmel-samd/boards/huntercat_nfc/mpconfigboard.mk index 43a0d38d7d..5e9a1372b4 100644 --- a/ports/atmel-samd/boards/huntercat_nfc/mpconfigboard.mk +++ b/ports/atmel-samd/boards/huntercat_nfc/mpconfigboard.mk @@ -6,20 +6,6 @@ USB_MANUFACTURER = "Electronic Cats" CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 -INTERNAL_FLASH_FILESYSTEM = 0 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" LONGINT_IMPL = MPZ - -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_NEOPIXEL_WRITE = 0 -CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_RTC = 0 -CIRCUITPY_USB_MIDI = 1 -CIRCUITPY_TOUCHIO = 0 -CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk index 106eef89cf..b8f7f9a8b4 100644 --- a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk @@ -11,33 +11,3 @@ EXTERNAL_FLASH_DEVICES = "W25Q16FW, GD25Q16C" LONGINT_IMPL = MPZ CIRCUITPY_BITBANG_APA102 = 1 - -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_GAMEPAD = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_RTC = 0 -# too itsy bitsy for all of displayio -CIRCUITPY_VECTORIO = 0 - -CFLAGS_INLINE_LIMIT = 60 -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif diff --git a/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk b/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk index 8ee9d23fe5..55c6bb6de3 100644 --- a/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk +++ b/ports/atmel-samd/boards/meowmeow/mpconfigboard.mk @@ -9,9 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_RTC = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk index 01e6094cdf..4e7d799985 100644 --- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.mk @@ -9,15 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C" LONGINT_IMPL = MPZ - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 -MICROPY_PY_ASYNC_AWAIT = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/ndgarage_ndbit6/mpconfigboard.mk b/ports/atmel-samd/boards/ndgarage_ndbit6/mpconfigboard.mk index 3882e780eb..b60852d470 100644 --- a/ports/atmel-samd/boards/ndgarage_ndbit6/mpconfigboard.mk +++ b/ports/atmel-samd/boards/ndgarage_ndbit6/mpconfigboard.mk @@ -10,6 +10,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/ndgarage_ndbit6_v2/mpconfigboard.mk b/ports/atmel-samd/boards/ndgarage_ndbit6_v2/mpconfigboard.mk index 4ae1d8741d..58ef17ce03 100644 --- a/ports/atmel-samd/boards/ndgarage_ndbit6_v2/mpconfigboard.mk +++ b/ports/atmel-samd/boards/ndgarage_ndbit6_v2/mpconfigboard.mk @@ -10,6 +10,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk index 0f90dba6a1..4ff9677693 100644 --- a/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk @@ -9,25 +9,19 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE +CIRCUITPY_FULL_BUILD = 0 + CIRCUITPY_ANALOGIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 -CIRCUITPY_PS2IO = 0 CIRCUITPY_PULSEIO = 0 CIRCUITPY_PWMIO = 0 CIRCUITPY_AUDIOCORE = 0 CIRCUITPY_BUSIO = 0 -CIRCUITPY_STORAGE = 1 -CIRCUITPY_MATH = 1 CIRCUITPY_PIXELBUF = 1 CIRCUITPY_USB_MIDI = 1 CIRCUITPY_TOUCHIO = 1 -CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk index 8b2ac7ff78..869ad42fa9 100644 --- a/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew10/mpconfigboard.mk @@ -11,15 +11,8 @@ LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 CIRCUITPY_PEW = 1 -CIRCUITPY_ANALOGIO = 1 -CIRCUITPY_MATH = 1 -CIRCUITPY_NEOPIXEL_WRITE = 1 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 CIRCUITPY_USB_MIDI = 0 -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 - FROZEN_MPY_DIRS += $(TOP)/frozen/pew-pewpew-standalone-10.x diff --git a/ports/atmel-samd/boards/picoplanet/mpconfigboard.mk b/ports/atmel-samd/boards/picoplanet/mpconfigboard.mk index e931553747..5769493579 100644 --- a/ports/atmel-samd/boards/picoplanet/mpconfigboard.mk +++ b/ports/atmel-samd/boards/picoplanet/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk index 22e59cd773..33ebf81a4c 100644 --- a/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pirkey_m0/mpconfigboard.mk @@ -8,6 +8,7 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE +CIRCUITPY_FULL_BUILD = 0 # A number of modules are removed for pIRKey to make room for frozen libraries. # Many I/O functions are not available. @@ -15,16 +16,10 @@ LONGINT_IMPL = NONE CIRCUITPY_ANALOGIO = 0 CIRCUITPY_MATH = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 -CIRCUITPY_PULSEIO = 1 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 -CIRCUITPY_SAMD = 0 CIRCUITPY_USB_MIDI = 1 CIRCUITPY_TOUCHIO = 0 -CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 # Include these Python libraries in firmware. # FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_DotStar diff --git a/ports/atmel-samd/boards/pyruler/mpconfigboard.mk b/ports/atmel-samd/boards/pyruler/mpconfigboard.mk index 1a73ade94d..82ed445658 100644 --- a/ports/atmel-samd/boards/pyruler/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pyruler/mpconfigboard.mk @@ -9,8 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_RTC = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/qtpy_m0/mpconfigboard.mk b/ports/atmel-samd/boards/qtpy_m0/mpconfigboard.mk index c214006ead..a53694e74e 100644 --- a/ports/atmel-samd/boards/qtpy_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/qtpy_m0/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.mk b/ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.mk index 1ffe1669e7..f9928c21b8 100644 --- a/ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.mk +++ b/ports/atmel-samd/boards/qtpy_m0_haxpress/mpconfigboard.mk @@ -6,19 +6,6 @@ USB_MANUFACTURER = "Adafruit Industries LLC" CHIP_VARIANT = SAMD21E18A CHIP_FAMILY = samd21 -INTERNAL_FLASH_FILESYSTEM = 0 LONGINT_IMPL = MPZ SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = GD25Q16C - -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/sam32/mpconfigboard.mk b/ports/atmel-samd/boards/sam32/mpconfigboard.mk index 9ac24a014c..cddfa49b3b 100644 --- a/ports/atmel-samd/boards/sam32/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sam32/mpconfigboard.mk @@ -9,8 +9,4 @@ CHIP_FAMILY = samd51 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = MPZ -# No I2S on SAMD51 -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_USTACK = 1 - FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/atmel-samd/boards/seeeduino_wio_terminal/mpconfigboard.mk b/ports/atmel-samd/boards/seeeduino_wio_terminal/mpconfigboard.mk index 9788f5ff40..fefc78addc 100644 --- a/ports/atmel-samd/boards/seeeduino_wio_terminal/mpconfigboard.mk +++ b/ports/atmel-samd/boards/seeeduino_wio_terminal/mpconfigboard.mk @@ -9,5 +9,3 @@ CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" LONGINT_IMPL = MPZ - -CIRCUITPY_VECTORIO = 1 diff --git a/ports/atmel-samd/boards/seeeduino_xiao/mpconfigboard.mk b/ports/atmel-samd/boards/seeeduino_xiao/mpconfigboard.mk index 6bbd84235a..1334c8312c 100644 --- a/ports/atmel-samd/boards/seeeduino_xiao/mpconfigboard.mk +++ b/ports/atmel-samd/boards/seeeduino_xiao/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk index f5ce4a5d13..196d36816f 100644 --- a/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/serpente/mpconfigboard.mk b/ports/atmel-samd/boards/serpente/mpconfigboard.mk index 422baf46ad..5fa4485552 100644 --- a/ports/atmel-samd/boards/serpente/mpconfigboard.mk +++ b/ports/atmel-samd/boards/serpente/mpconfigboard.mk @@ -9,13 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = GD25Q32C LONGINT_IMPL = NONE - -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_BUSDEVICE = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_GAMEPAD = 0 -CIRCUITPY_MSGPACK = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/shirtty/mpconfigboard.mk b/ports/atmel-samd/boards/shirtty/mpconfigboard.mk index 70fe447232..798fd8fcb3 100644 --- a/ports/atmel-samd/boards/shirtty/mpconfigboard.mk +++ b/ports/atmel-samd/boards/shirtty/mpconfigboard.mk @@ -9,8 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 -CIRCUITPY_I2CPERIPHERAL = 1 -CIRCUITPY_TOUCHIO = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk b/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk index e64045f13a..58411aa03e 100644 --- a/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk +++ b/ports/atmel-samd/boards/silicognition-m4-shim/mpconfigboard.mk @@ -9,5 +9,3 @@ CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = GD25Q16C LONGINT_IMPL = MPZ - -CIRCUITPY_VECTORIO = 1 diff --git a/ports/atmel-samd/boards/snekboard/mpconfigboard.mk b/ports/atmel-samd/boards/snekboard/mpconfigboard.mk index 3467ef7578..d19e606319 100644 --- a/ports/atmel-samd/boards/snekboard/mpconfigboard.mk +++ b/ports/atmel-samd/boards/snekboard/mpconfigboard.mk @@ -9,30 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" LONGINT_IMPL = MPZ - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_GAMEPAD = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 - -CFLAGS_INLINE_LIMIT = 60 - -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif diff --git a/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk index aca557cec6..dcf15beb11 100755 --- a/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_lumidrive/mpconfigboard.mk @@ -12,11 +12,5 @@ LONGINT_IMPL = MPZ CIRCUITPY_AUDIOIO = 0 CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_BUSDEVICE = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_DotStar - -SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/sparkfun_qwiic_micro_no_flash/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_qwiic_micro_no_flash/mpconfigboard.mk index 435ee87fde..5c2ad88dfc 100644 --- a/ports/atmel-samd/boards/sparkfun_qwiic_micro_no_flash/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_qwiic_micro_no_flash/mpconfigboard.mk @@ -10,6 +10,3 @@ INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/sparkfun_qwiic_micro_with_flash/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_qwiic_micro_with_flash/mpconfigboard.mk index 7c2fd57ea1..468aa7360b 100644 --- a/ports/atmel-samd/boards/sparkfun_qwiic_micro_with_flash/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_qwiic_micro_with_flash/mpconfigboard.mk @@ -11,4 +11,3 @@ EXTERNAL_FLASH_DEVICES = "W25Q32FV" LONGINT_IMPL = MPZ CIRCUITPY_FULL_BUILD = 0 -SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk index a5cd49239e..70ece9b9fc 100755 --- a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk @@ -9,30 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q32FV" LONGINT_IMPL = MPZ - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_GAMEPAD = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 - -CFLAGS_INLINE_LIMIT = 60 -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif diff --git a/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk index bafcc02a2b..b8ac2dc256 100644 --- a/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_samd21_dev/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk b/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk index aef38661be..77dfe8887d 100644 --- a/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk +++ b/ports/atmel-samd/boards/sparkfun_samd21_mini/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk index 0f9b8a3c18..1088ca1e8d 100644 --- a/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk +++ b/ports/atmel-samd/boards/stackrduino_m0_pro/mpconfigboard.mk @@ -9,17 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "W25Q64JVxQ" LONGINT_IMPL = MPZ - - -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_MSGPACK = 0 -CIRCUITPY_VECTORIO = 0 -CIRCUITPY_BUSDEVICE = 0 -MICROPY_PY_ASYNC_AWAIT = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/stringcar_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/stringcar_m0_express/mpconfigboard.mk index 91644386f2..53aeda3c50 100644 --- a/ports/atmel-samd/boards/stringcar_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/stringcar_m0_express/mpconfigboard.mk @@ -12,29 +12,3 @@ EXTERNAL_FLASH_DEVICES = AT25SF161 LONGINT_IMPL = MPZ CIRCUITPY_BITBANG_APA102 = 1 - -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_GAMEPAD = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -CIRCUITPY_RTC = 0 -CIRCUITPY_VECTORIO = 0 - -CFLAGS_INLINE_LIMIT = 60 -SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -SUPEROPT_VM = 0 -endif diff --git a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk index fbbb974cdf..a51349f5f3 100644 --- a/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trinket_m0/mpconfigboard.mk @@ -9,9 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 - -# On this particular board, these save about 180 bytes. On other boards, they may -increase- space used. -CFLAGS_BOARD = -fweb -frename-registers diff --git a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk index e91c94e56d..028114091e 100644 --- a/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk +++ b/ports/atmel-samd/boards/trinket_m0_haxpress/mpconfigboard.mk @@ -9,19 +9,3 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = W25Q32BV LONGINT_IMPL = MPZ - -CIRCUITPY_AUDIOBUSIO = 0 -CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_COUNTIO = 0 -CIRCUITPY_RTC = 0 -CIRCUITPY_FREQUENCYIO = 0 -CIRCUITPY_I2CPERIPHERAL = 0 -MICROPY_PY_ASYNC_AWAIT = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 - -CFLAGS_INLINE_LIMIT = 35 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 diff --git a/ports/atmel-samd/boards/uchip/mpconfigboard.mk b/ports/atmel-samd/boards/uchip/mpconfigboard.mk index d6ba805b14..90b5600dcb 100644 --- a/ports/atmel-samd/boards/uchip/mpconfigboard.mk +++ b/ports/atmel-samd/boards/uchip/mpconfigboard.mk @@ -9,6 +9,3 @@ CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 - -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk index 74f438b714..2f1062e419 100644 --- a/ports/atmel-samd/boards/ugame10/mpconfigboard.mk +++ b/ports/atmel-samd/boards/ugame10/mpconfigboard.mk @@ -34,5 +34,3 @@ CIRCUITPY_BUSDEVICE = 0 FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/ugame10 CIRCUITPY_DISPLAY_FONT = $(TOP)/ports/atmel-samd/boards/ugame10/brutalist-6.bdf - -SUPEROPT_GC = 0 diff --git a/ports/atmel-samd/boards/xinabox_cc03/mpconfigboard.mk b/ports/atmel-samd/boards/xinabox_cc03/mpconfigboard.mk index 9497bf78cb..321ebd951b 100644 --- a/ports/atmel-samd/boards/xinabox_cc03/mpconfigboard.mk +++ b/ports/atmel-samd/boards/xinabox_cc03/mpconfigboard.mk @@ -8,11 +8,9 @@ CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 -LONGINT_IMPL = MPZ -CIRCUITPY_FULL_BUILD = 0 +LONGINT_IMPL = NONE -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 +CIRCUITPY_FULL_BUILD = 0 # Make room for frozen libs. CIRCUITPY_FREQUENCYIO = 0 diff --git a/ports/atmel-samd/boards/xinabox_cs11/mpconfigboard.mk b/ports/atmel-samd/boards/xinabox_cs11/mpconfigboard.mk index eb43bd8afd..e0bec4e623 100644 --- a/ports/atmel-samd/boards/xinabox_cs11/mpconfigboard.mk +++ b/ports/atmel-samd/boards/xinabox_cs11/mpconfigboard.mk @@ -8,24 +8,20 @@ CHIP_VARIANT = SAMD21G18A CHIP_FAMILY = samd21 INTERNAL_FLASH_FILESYSTEM = 1 -LONGINT_IMPL = MPZ +LONGINT_IMPL = NONE + CIRCUITPY_FULL_BUILD = 0 -SUPEROPT_GC = 0 -SUPEROPT_VM = 0 - # Make room for frozen libs. -CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_ANALOGIO=0 +CIRCUITPY_BUSDEVICE=1 CIRCUITPY_NEOPIXEL_WRITE=0 CIRCUITPY_PULSEIO=0 CIRCUITPY_ROTARYIO=0 -CIRCUITPY_TOUCHIO_USE_NATIVE=0 CIRCUITPY_TOUCHIO=0 CIRCUITPY_USB_MIDI=0 CIRCUITPY_RTC=0 -CIRCUITPY_COUNTIO=0 -CIRCUITPY_BUSDEVICE=1 +CIRCUITPY_SDCARDIO=1 # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index f31360312c..060b17daf5 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -32,28 +32,33 @@ ifeq ($(CHIP_FAMILY),samd21) # The ?='s allow overriding in mpconfigboard.mk. +# Some of these are on by default with CIRCUITPY_FULL_BUILD, but don't +# fit in 256kB of flash + CIRCUITPY_AUDIOMIXER ?= 0 CIRCUITPY_BINASCII ?= 0 +CIRCUITPY_BITBANGIO ?= 0 +CIRCUITPY_BITMAPTOOLS ?= 0 +CIRCUITPY_BUSDEVICE ?= 0 CIRCUITPY_AUDIOMP3 ?= 0 +CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_BUILTINS_POW3 ?= 0 CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 1 -CIRCUITPY_FREQUENCYIO ?= 0 -CIRCUITPY_JSON ?= 0 -CIRCUITPY_SYNTHIO ?= 0 -CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1 - -# No room for HCI _bleio on SAMD21. -CIRCUITPY_BLEIO_HCI = 0 - -CIRCUITPY_SDCARDIO ?= 0 - +CIRCUITPY_COUNTIO ?= 0 # Not enough RAM for framebuffers CIRCUITPY_FRAMEBUFFERIO ?= 0 - -# Not enough room in 192kB or 256kB builds for secondary CDC. -CIRCUITPY_USB_CDC ?= 1 - +CIRCUITPY_FREQUENCYIO ?= 0 +CIRCUITPY_I2CPERIPHERAL ?= 0 +CIRCUITPY_JSON ?= 0 +CIRCUITPY_MSGPACK ?= 0 +CIRCUITPY_RE ?= 0 +CIRCUITPY_SDCARDIO ?= 0 +CIRCUITPY_SYNTHIO ?= 0 +CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1 CIRCUITPY_ULAB = 0 +CIRCUITPY_VECTORIO = 0 + +MICROPY_PY_ASYNC_AWAIT = 0 ifeq ($(TRANSLATION), ja) RELEASE_NEEDS_CLEAN_BUILD = 1 @@ -65,6 +70,14 @@ RELEASE_NEEDS_CLEAN_BUILD = 1 CIRCUITPY_TERMINALIO = 0 endif +SUPEROPT_GC = 0 +SUPEROPT_VM = 0 + +ifeq ($(CIRCUITPY_FULL_BUILD),0) +# On the smallest boards, this saves about 180 bytes. On other boards, it may -increase- space used. +CFLAGS_BOARD = -fweb -frename-registers +endif + endif # samd21 ###################################################################### From 8f9c9dd45f5ba6edf6a25948bd5d1c0f869b25cf Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 5 May 2021 13:41:44 -0400 Subject: [PATCH 60/66] doc error --- shared-bindings/usb_hid/Device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 67247c8f64..511966731c 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -29,7 +29,7 @@ #include "py/runtime.h" //| class Device: -//| """HID Device +//| """HID Device specification""" //| //| def __init__(self, *, descriptor: ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: int = 0, report_id_index: Optional[int]) -> None: //| """Create a description of a USB HID device. The actual device is created when you From 2c66dd869e3892cf3e6aeafe3f5833e19e29c3e6 Mon Sep 17 00:00:00 2001 From: Jonny Bergdahl Date: Wed, 5 May 2021 16:30:20 +0000 Subject: [PATCH 61/66] Translated using Weblate (Swedish) Currently translated at 100.0% (973 of 973 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/sv/ --- locale/sv.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/sv.po b/locale/sv.po index 1f91867c7f..944a6b9394 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-05-05 15:32+0000\n" +"PO-Revision-Date: 2021-05-05 18:42+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" "Language: sv\n" @@ -451,7 +451,7 @@ msgstr "Försök till heap-allokering när den virtuella maskinen inte är igån #: shared-bindings/wifi/Radio.c msgid "AuthMode.OPEN is not used with password" -msgstr "" +msgstr "AuthMode.OPEN används inte med lösenord" #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -1224,7 +1224,7 @@ msgstr "Ogiltigt ADC-enhetsvärde" #: ports/esp32s2/common-hal/wifi/Radio.c msgid "Invalid AuthMode" -msgstr "" +msgstr "Ogiltig AuthMode" #: shared-module/displayio/OnDiskBitmap.c msgid "Invalid BMP file" From b9f349779eaec113932e33a22f8c3247baa3e862 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 5 May 2021 13:24:08 -0500 Subject: [PATCH 62/66] Build an aarch64 version of mpy-cross --- .github/workflows/build.yml | 9 ++++++++- mpy-cross/Makefile.static-aarch64 | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 mpy-cross/Makefile.static-aarch64 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 95b5379d59..626e5f381b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -37,7 +37,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y eatmydata - sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64 latexmk texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra + sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64 latexmk texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra gcc-aarch64-linux-gnu pip install -r requirements-dev.txt - name: Versions run: | @@ -93,6 +93,12 @@ jobs: - name: mpy Tests run: MICROPY_CPYTHON3=python3.8 MICROPY_MICROPYTHON=../ports/unix/micropython_coverage ./run-tests -j1 --via-mpy -d basics float working-directory: tests + - name: Build mpy-cross.static-aarch64 + run: make -C mpy-cross -j2 -f Makefile.static-aarch64 + - uses: actions/upload-artifact@v2 + with: + name: mpy-cross.static-aarch64 + path: mpy-cross/mpy-cross.static-aarch64 - name: Build mpy-cross.static-raspbian run: make -C mpy-cross -j2 -f Makefile.static-raspbian - uses: actions/upload-artifact@v2 @@ -113,6 +119,7 @@ jobs: path: mpy-cross/mpy-cross.static.exe - name: Upload stubs and mpy-cross builds to S3 run: | + [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static-aarch64 s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-aarch64-${{ env.CP_VERSION }} --no-progress --region us-east-1 [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static-raspbian s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-raspbian-${{ env.CP_VERSION }} --no-progress --region us-east-1 [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-amd64-linux-${{ env.CP_VERSION }} --no-progress --region us-east-1 [ -z "$AWS_ACCESS_KEY_ID" ] || aws s3 cp mpy-cross/mpy-cross.static.exe s3://adafruit-circuit-python/bin/mpy-cross/mpy-cross.static-x64-windows-${{ env.CP_VERSION }}.exe --no-progress --region us-east-1 diff --git a/mpy-cross/Makefile.static-aarch64 b/mpy-cross/Makefile.static-aarch64 new file mode 100644 index 0000000000..e59ba8331f --- /dev/null +++ b/mpy-cross/Makefile.static-aarch64 @@ -0,0 +1,10 @@ +# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) +# +# SPDX-License-Identifier: MIT + +PROG=mpy-cross.static-aarch64 +BUILD=build-static-aarch64 +STATIC_BUILD=1 + +CROSS_COMPILE = aarch64-linux-gnu- +include mpy-cross.mk From 579cdf30f18891def56587c88621651fce629af8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 5 May 2021 16:49:29 -0400 Subject: [PATCH 63/66] fix more build errors --- .../boards/kicksat-sprite/mpconfigboard.mk | 5 ++++- ports/cxd56/mpconfigport.h | 12 +++++++----- ports/nrf/boards/pca10100/mpconfigboard.mk | 11 +++++------ py/repl.c | 2 +- supervisor/usb.h | 2 ++ 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk index ea010ed2ee..d7b8a4bb1e 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk @@ -12,12 +12,15 @@ LONGINT_IMPL = MPZ # Not needed. CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOMP3 = 0 -CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BLEIO_HCI = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 +CIRCUITPY_MSGPACK = 0 CIRCUITPY_PS2IO = 0 CIRCUITPY_RGBMATRIX = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_TOUCHIO = 0 + CIRCUITPY_ULAB = 0 # Override optimization to keep binary small diff --git a/ports/cxd56/mpconfigport.h b/ports/cxd56/mpconfigport.h index bce68f83f2..4c332577e6 100644 --- a/ports/cxd56/mpconfigport.h +++ b/ports/cxd56/mpconfigport.h @@ -32,17 +32,19 @@ // 64kiB stack #define CIRCUITPY_DEFAULT_STACK_SIZE (0x10000) -#include "py/circuitpy_mpconfig.h" - -#define MICROPY_BYTES_PER_GC_BLOCK (32) - -// CXD56 architecture uses fixed endpoint numbers +// CXD56 architecture uses fixed endpoint numbers. +// Override default definitions in circuitpy_mpconfig.h, +// so define these before #include'ing that file. #define USB_CDC_EP_NUM_NOTIFICATION (3) #define USB_CDC_EP_NUM_DATA_OUT (2) #define USB_CDC_EP_NUM_DATA_IN (2) #define USB_MSC_EP_NUM_OUT (5) #define USB_MSC_EP_NUM_IN (4) +#include "py/circuitpy_mpconfig.h" + +#define MICROPY_BYTES_PER_GC_BLOCK (32) + #define MICROPY_PORT_ROOT_POINTERS \ CIRCUITPY_COMMON_ROOT_POINTERS \ diff --git a/ports/nrf/boards/pca10100/mpconfigboard.mk b/ports/nrf/boards/pca10100/mpconfigboard.mk index dd59eb96c9..9fae5ccc4d 100644 --- a/ports/nrf/boards/pca10100/mpconfigboard.mk +++ b/ports/nrf/boards/pca10100/mpconfigboard.mk @@ -9,25 +9,24 @@ INTERNAL_FLASH_FILESYSTEM = 1 CIRCUITPY_ALARM = 0 CIRCUITPY_AUDIOMP3 = 0 +CIRCUITPY_BINASCII = 0 CIRCUITPY_BITBANGIO = 0 -CIRCUITPY_BITMAPTOOLS = 0 -CIRCUITPY_BUSIO = 1 +CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_COUNTIO = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_I2CPERIPHERAL = 0 +CIRCUITPY_JSON = 0 CIRCUITPY_MSGPACK = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NVM = 0 CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_RE = 0 CIRCUITPY_RGBMATRIX = 0 -CIRCUITPY_ROTARYIO = 0 -CIRCUITPY_RTC = 1 CIRCUITPY_SDCARDIO = 0 -CIRCUITPY_TOUCHIO = 0 CIRCUITPY_ULAB = 0 -CIRCUITPY_BUSDEVICE = 0 + MICROPY_PY_ASYNC_AWAIT = 0 SUPEROPT_GC = 0 diff --git a/py/repl.c b/py/repl.c index ac88e91114..7ceae573d4 100644 --- a/py/repl.c +++ b/py/repl.c @@ -153,7 +153,7 @@ STATIC bool test_qstr(mp_obj_t obj, qstr name) { } else { // try builtin module return mp_map_lookup((mp_map_t *)&mp_builtin_module_map, - MP_OBJ_NEW_QSTR(name), MP_MAP_LOOKUP); + MP_OBJ_NEW_QSTR(name), MP_MAP_LOOKUP) != NULL; } } diff --git a/supervisor/usb.h b/supervisor/usb.h index 9c792d07f1..918da98897 100644 --- a/supervisor/usb.h +++ b/supervisor/usb.h @@ -28,6 +28,8 @@ #define MICROPY_INCLUDED_SUPERVISOR_USB_H #include +#include +#include // Ports must call this as frequently as they can in order to keep the USB // connection alive and responsive. Normally this is called from background From f38f5dbce6187708d331266e73e324008558046b Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 5 May 2021 17:02:32 -0400 Subject: [PATCH 64/66] Set reload reason when reloaded from repl --- main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.c b/main.c index 116436c0aa..8b2458785d 100755 --- a/main.c +++ b/main.c @@ -334,6 +334,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { bool fake_sleeping = false; while (true) { RUN_BACKGROUND_TASKS; + + // If a reload was requested by the supervisor or autoreload, return if (reload_requested) { #if CIRCUITPY_ALARM if (fake_sleeping) { @@ -344,6 +346,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { return true; } + // If interrupted by keyboard, return if (serial_connected() && serial_bytes_available()) { #if CIRCUITPY_ALARM if (fake_sleeping) { @@ -370,6 +373,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { } #endif + // If messages haven't been printed yet, print them if (!printed_press_any_key && serial_connected()) { if (!serial_connected_at_start) { print_code_py_status_message(safe_mode); @@ -596,6 +600,7 @@ int __attribute__((used)) main(void) { for (;;) { if (!skip_repl) { exit_code = run_repl(); + supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); } if (exit_code == PYEXEC_FORCED_EXIT) { if (!first_run) { From 843598ec3aa6a87031c2cff8e72d48eb7dd98ea8 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 5 May 2021 18:44:27 -0400 Subject: [PATCH 65/66] fix more board builds --- .../boards/itsybitsy_m0_express/mpconfigboard.mk | 2 ++ ports/stm/boards/espruino_pico/mpconfigboard.mk | 8 +++++--- .../stm32f411ce_blackpill_with_flash/mpconfigboard.mk | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk index b8f7f9a8b4..447e15600e 100644 --- a/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/itsybitsy_m0_express/mpconfigboard.mk @@ -11,3 +11,5 @@ EXTERNAL_FLASH_DEVICES = "W25Q16FW, GD25Q16C" LONGINT_IMPL = MPZ CIRCUITPY_BITBANG_APA102 = 1 + +CIRCUITPY_PULSEIO = 0 diff --git a/ports/stm/boards/espruino_pico/mpconfigboard.mk b/ports/stm/boards/espruino_pico/mpconfigboard.mk index 9148160286..efbbaa22e2 100644 --- a/ports/stm/boards/espruino_pico/mpconfigboard.mk +++ b/ports/stm/boards/espruino_pico/mpconfigboard.mk @@ -9,8 +9,6 @@ MCU_SERIES = F4 MCU_VARIANT = STM32F401xE MCU_PACKAGE = UFQFPN48 -OPTIMIZATION_FLAGS = -Os - LD_COMMON = boards/common_default.ld # use for internal flash LD_FILE = boards/STM32F401xd_fs.ld @@ -19,11 +17,15 @@ LD_FILE = boards/STM32F401xd_fs.ld # INTERNAL_FLASH_FILESYSTEM. It can probably be reenabled if we enable # lto for this port, and if other stuff hasn't been added in the # meantime -CIRCUITPY_ULAB = 0 CIRCUITPY_AUDIOCORE = 0 CIRCUITPY_AUDIOPWMIO = 0 CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_FRAMEBUFFERIO = 0 +CIRCUITPY_ULAB = 0 +CIRCUITPY_VECTORIO = 0 SUPEROPT_GC = 0 +SUPEROPT_VM = 0 + +OPTIMIZATION_FLAGS = -Os diff --git a/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk b/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk index 211a658967..2dff6e8955 100644 --- a/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk +++ b/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk @@ -17,4 +17,5 @@ MCU_PACKAGE = UFQFPN48 LD_COMMON = boards/common_default.ld LD_FILE = boards/STM32F411_nvm_nofs.ld -CIRCUITPY_SYNTHIO = 0 +CIRCUITPY_BITMAPTOOLS = 0 +CIRCUITPY_VECTORIO = 0 From ef3ec93c8bc3785dd210335aac458e873813bd1b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 5 May 2021 18:04:41 -0500 Subject: [PATCH 66/66] Change the first byte of CircuitPython 'mpy' files to "C" .. and also distinguish CircuitPython better in `mpy-cross --version` --- mpy-cross/main.c | 4 ++-- py/persistentcode.c | 4 ++-- tests/import/mpy_native.py | 8 ++++---- tools/mpy-tool.py | 4 ++-- tools/mpy_ld.py | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mpy-cross/main.c b/mpy-cross/main.c index d16ebc4a05..466f8e6769 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -210,8 +210,8 @@ MP_NOINLINE int main_(int argc, char **argv) { if (strcmp(argv[a], "-X") == 0) { a += 1; } else if (strcmp(argv[a], "--version") == 0) { - printf("MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE - "; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "\n"); + printf("CircuitPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE + "; mpy-cross emitting mpy v" MP_STRINGIFY(MPY_VERSION) "-CircuitPython\n"); return 0; } else if (strcmp(argv[a], "-v") == 0) { mp_verbose_flag++; diff --git a/py/persistentcode.c b/py/persistentcode.c index e7423745f6..c5d57f6140 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -564,7 +564,7 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, qstr_window_t *qw) { mp_raw_code_t *mp_raw_code_load(mp_reader_t *reader) { byte header[4]; read_bytes(reader, header, sizeof(header)); - if (header[0] != 'M' + if (header[0] != 'C' || header[1] != MPY_VERSION || MPY_FEATURE_DECODE_FLAGS(header[2]) != MPY_FEATURE_FLAGS || header[3] > mp_small_int_bits() @@ -819,7 +819,7 @@ void mp_raw_code_save(mp_raw_code_t *rc, mp_print_t *print) { // byte number of bits in a small int // uint size of qstr window byte header[4] = { - 'M', + 'C', MPY_VERSION, MPY_FEATURE_ENCODE_FLAGS(MPY_FEATURE_FLAGS_DYNAMIC), #if MICROPY_DYNAMIC_COMPILER diff --git a/tests/import/mpy_native.py b/tests/import/mpy_native.py index 19805bab97..bab5f91d53 100644 --- a/tests/import/mpy_native.py +++ b/tests/import/mpy_native.py @@ -58,10 +58,10 @@ class UserFS: # these are the test .mpy files user_files = { # bad architecture - "/mod0.mpy": b"M\x05\xff\x00\x10", + "/mod0.mpy": b"C\x05\xff\x00\x10", # test loading of viper and asm "/mod1.mpy": ( - b"M\x05\x0b\x1f\x20" # header + b"C\x05\x0b\x1f\x20" # header b"\x20" # n bytes, bytecode b"\x00\x08\x02m\x02m" # prelude b"\x51" # LOAD_CONST_NONE @@ -78,7 +78,7 @@ user_files = { ), # test loading viper with truncated data "/mod2.mpy": ( - b"M\x05\x0b\x1f\x20" # header + b"C\x05\x0b\x1f\x20" # header b"\x20" # n bytes, bytecode b"\x00\x08\x02m\x02m" # prelude b"\x51" # LOAD_CONST_NONE @@ -88,7 +88,7 @@ user_files = { ), # test loading viper with additional scope flags and relocation "/mod3.mpy": ( - b"M\x05\x0b\x1f\x20" # header + b"C\x05\x0b\x1f\x20" # header b"\x20" # n bytes, bytecode b"\x00\x08\x02m\x02m" # prelude b"\x51" # LOAD_CONST_NONE diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 90578da72b..41224a8a0a 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -767,8 +767,8 @@ def read_raw_code(f, qstr_win): def read_mpy(filename): with open(filename, "rb") as f: header = bytes_cons(f.read(4)) - if header[0] != ord("M"): - raise Exception("not a valid .mpy file") + if header[0] != ord("C"): + raise Exception("not a valid CircuitPython .mpy file") if header[1] != config.MPY_VERSION: raise Exception("incompatible .mpy version") feature_byte = header[2] diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py index 4493bb70e1..98aadcdf01 100755 --- a/tools/mpy_ld.py +++ b/tools/mpy_ld.py @@ -909,7 +909,7 @@ def build_mpy(env, entry_offset, fmpy, native_qstr_vals, native_qstr_objs): out.write_bytes( bytearray( [ - ord("M"), + ord("C"), MPY_VERSION, env.arch.mpy_feature, MP_SMALL_INT_BITS,