WIP: seems to be done

This commit is contained in:
Dan Halbert 2018-04-02 19:08:18 -04:00
parent c00b25ec45
commit d005b12326
6 changed files with 158 additions and 31 deletions

@ -1 +1 @@
Subproject commit 1e2165aa981f3eef39db8c27c05836aa94788e3d
Subproject commit aaa0f428111fbea7d56ab548053b11c9f12068f1

View File

@ -2,6 +2,62 @@
#ifndef HPL_USB_CONFIG_H
#define HPL_USB_CONFIG_H
// CIRCUITPY:
// 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 >>>
#define CONF_USB_N_0 0
@ -28,6 +84,8 @@
// <y> Max number of endpoints supported
// <i> 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.
// <CONF_USB_N_1"> 1 (EP0 only)
// <CONF_USB_N_2"> 2 (EP0 + 1 endpoint)
// <CONF_USB_N_3"> 3 (EP0 + 2 endpoints)
@ -100,7 +158,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep1_cache
#ifndef CONF_USB_EP1_CACHE
#define CONF_USB_EP1_CACHE 64
#define CONF_USB_EP1_CACHE 0
#endif
// <o> Cache buffer size for EP1 IN
@ -138,7 +196,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep2_cache
#ifndef CONF_USB_EP2_CACHE
#define CONF_USB_EP2_CACHE 64
#define CONF_USB_EP2_CACHE 0
#endif
// <o> Cache buffer size for EP2 IN
@ -156,7 +214,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_ep2_I_CACHE
#ifndef CONF_USB_EP2_I_CACHE
#define CONF_USB_EP2_I_CACHE 64
#define CONF_USB_EP2_I_CACHE 0
#endif
// </h>
@ -194,7 +252,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_ep3_I_CACHE
#ifndef CONF_USB_EP3_I_CACHE
#define CONF_USB_EP3_I_CACHE 64
#define CONF_USB_EP3_I_CACHE 0
#endif
// </h>
@ -214,7 +272,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep4_cache
#ifndef CONF_USB_EP4_CACHE
#define CONF_USB_EP4_CACHE 64
#define CONF_USB_EP4_CACHE 0
#endif
// <o> Cache buffer size for EP4 IN

View File

@ -2,6 +2,62 @@
#ifndef HPL_USB_CONFIG_H
#define HPL_USB_CONFIG_H
// CIRCUITPY:
// 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 >>>
#define CONF_USB_N_0 0
@ -102,7 +158,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep1_cache
#ifndef CONF_USB_EP1_CACHE
#define CONF_USB_EP1_CACHE 64
#define CONF_USB_EP1_CACHE 0
#endif
// <o> Cache buffer size for EP1 IN
@ -140,7 +196,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep2_cache
#ifndef CONF_USB_EP2_CACHE
#define CONF_USB_EP2_CACHE 64
#define CONF_USB_EP2_CACHE 0
#endif
// <o> Cache buffer size for EP2 IN
@ -158,7 +214,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_ep2_I_CACHE
#ifndef CONF_USB_EP2_I_CACHE
#define CONF_USB_EP2_I_CACHE 64
#define CONF_USB_EP2_I_CACHE 0
#endif
// </h>
@ -178,7 +234,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep3_cache
#ifndef CONF_USB_EP3_CACHE
#define CONF_USB_EP3_CACHE 64
#define CONF_USB_EP3_CACHE 0
#endif
// <o> Cache buffer size for EP3 IN
@ -216,7 +272,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep4_cache
#ifndef CONF_USB_EP4_CACHE
#define CONF_USB_EP4_CACHE 64
#define CONF_USB_EP4_CACHE 0
#endif
// <o> Cache buffer size for EP4 IN
@ -254,7 +310,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep5_cache
#ifndef CONF_USB_EP5_CACHE
#define CONF_USB_EP5_CACHE 64
#define CONF_USB_EP5_CACHE 0
#endif
// <o> Cache buffer size for EP5 IN
@ -292,7 +348,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep6_cache
#ifndef CONF_USB_EP6_CACHE
#define CONF_USB_EP6_CACHE 64
#define CONF_USB_EP6_CACHE 0
#endif
// <o> Cache buffer size for EP6 IN
@ -310,7 +366,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_ep6_I_CACHE
#ifndef CONF_USB_EP6_I_CACHE
#define CONF_USB_EP6_I_CACHE 64
#define CONF_USB_EP6_I_CACHE 0
#endif
// </h>
@ -330,7 +386,7 @@
// <1024=> Cached by 1024 bytes buffer (interrupt or isochronous EP)
// <id> usb_arch_ep7_cache
#ifndef CONF_USB_EP7_CACHE
#define CONF_USB_EP7_CACHE 64
#define CONF_USB_EP7_CACHE 0
#endif
// <o> Cache buffer size for EP7 IN

View File

@ -119,7 +119,7 @@ hid_report_lengths = hid.ReportDescriptor.REPORT_LENGTHS
hid_max_report_length = max(hid_report_lengths.values())
# ASF4 expects keyboard and generic devices to have both in and out endpoints,
# and will fail in mysterious ways if you only supply one.
# and will fail (possibly silently) if both are not supplied.
hid_endpoint_in_descriptor = standard.EndpointDescriptor(
description="HID in",
bEndpointAddress=0x0 | standard.EndpointDescriptor.DIRECTION_IN,
@ -144,19 +144,12 @@ hid_interfaces = [
hid_endpoint_out_descriptor,
]
),
# bInterfaceClass = hid.HID_CLASS,
# bInterfaceSubClass = hid.HID_SUBCLASS_NOBOOT,
# bInterfaceProtocol=hid.HID_PROTOCOL_MOUSE,
# subdescriptors=[
# hid.HIDDescriptor(wDescriptorLength=len(bytes(hid_report_descriptor))),
# hid_endpoint_descriptor,
# ]
# ),
]
# This will renumber the endpoints to make them unique across descriptors.
#interfaces = util.join_interfaces(cdc_interfaces, msc_interfaces, hid_interfaces)
interfaces = util.join_interfaces(cdc_interfaces, hid_interfaces)
interfaces = util.join_interfaces(cdc_interfaces, msc_interfaces, hid_interfaces)
#interfaces = util.join_interfaces(cdc_interfaces, hid_interfaces, msc_interfaces)
#interfaces = util.join_interfaces(cdc_interfaces, hid_interfaces)
cdc_function = standard.InterfaceAssociationDescriptor(
description="CDC function",
@ -167,7 +160,7 @@ cdc_function = standard.InterfaceAssociationDescriptor(
bFunctionProtocol=0x1) # Common AT Commands
configuration = standard.ConfigurationDescriptor(
description="CDC configuration",
description="Composite configuration",
wTotalLength=(standard.ConfigurationDescriptor.bLength +
cdc_function.bLength +
sum([len(bytes(x)) for x in interfaces])),
@ -186,6 +179,8 @@ c_file.write("""\
#include "{H_FILE_NAME}"
#include "usb/device/usbdc.h"
""".format(H_FILE_NAME=h_file.name))
c_file.write("""\
@ -227,9 +222,6 @@ h_file.write("""\
#ifndef MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H
#define MICROPY_INCLUDED_AUTOGEN_USB_DESCRIPTOR_H
#include "usb/device/usbdc.h"
struct usbd_descriptors descriptor_bounds;
#define SERIAL_NUMBER_OFFSET {SERIAL_NUMBER_OFFSET}
#define SERIAL_NUMBER_LENGTH {SERIAL_NUMBER_LENGTH}
uint8_t* serial_number;
@ -245,6 +237,21 @@ uint8_t hid_report_descriptor[{HID_REPORT_DESCRIPTOR_LENGTH}];
HID_ENDPOINT_IN_ADDRESS=hex(hid_endpoint_in_descriptor.bEndpointAddress),
HID_ENDPOINT_OUT_ADDRESS=hex(hid_endpoint_out_descriptor.bEndpointAddress)))
# Write out #define's that declare which endpoints are in use.
# These provide information for declaring cache sizes and perhaps other things at compile time
for interface in interfaces:
for subdescriptor in interface.subdescriptors:
if isinstance(subdescriptor, standard.EndpointDescriptor):
endpoint_num = subdescriptor.bEndpointAddress & standard.EndpointDescriptor.NUMBER_MASK
endpoint_in = ((subdescriptor.bEndpointAddress & standard.EndpointDescriptor.DIRECTION_MASK) ==
standard.EndpointDescriptor.DIRECTION_IN)
h_file.write("""\
#define USB_ENDPOINT_{NUMBER}_{DIRECTION}_USED 1
""".format(NUMBER=endpoint_num,
DIRECTION="IN" if endpoint_in else "OUT"))
h_file.write("\n")
# #define the report ID's used in the combined HID descriptor
for name, id in hid_report_ids.items():
h_file.write("""\
@ -252,6 +259,8 @@ for name, id in hid_report_ids.items():
""".format(NAME=name,
ID = id))
h_file.write("\n")
# #define the report sizes used in the combined HID descriptor
for name, length in hid_report_lengths.items():
h_file.write("""\
@ -259,6 +268,8 @@ for name, length in hid_report_lengths.items():
""".format(NAME=name,
LENGTH=length))
h_file.write("\n")
h_file.write("""\
#define USB_HID_NUM_DEVICES {NUM_DEVICES}
#define USB_HID_MAX_REPORT_LENGTH {MAX_LENGTH}

View File

@ -48,6 +48,8 @@
#include "supervisor/shared/autoreload.h"
extern struct usbd_descriptors descriptor_bounds;
// Store received characters on our own so that we can filter control characters
// and act immediately on CTRL-C for example.

@ -1 +1 @@
Subproject commit b4aca689fd234b4e6ae37030f0815fbb519ce62d
Subproject commit 2edd94c50b67ac2acc665a5b06e34c2625a8f622