Skip to content

Commit

Permalink
Merge #18903
Browse files Browse the repository at this point in the history
18903: pkg/tinyusb: add tinyUSB netdev driver r=dylad a=gschorcht

### Contribution description

This PR adds the tinyUSB netdev driver.

The tinyUSB netdev driver is part of the tinyUSB package and is enabled by module `tinyusb_netdev`. It is available for boards that provide the `tinyusb_device` feature.

**Please note** Since the tinyUSB package is distinct from (and incompatible with) the USB stack provided around USBUS in RIOT (see USB), the tinyUSB netdev driver cannot be used together with with any USBUS device class.

The tinyUSB netdev driver uses Ethernet over USB and supports the following protocols:
- CDC ECM (Ethernet Control Model)
- CDC NCM (Network Control Model)
- RNDIS (Microsoft Remote NDIS)

While Linux and macOS support all these protocols, Microsoft Windows only supports the RNDIS protocol and since Windows version 11 also the CDC NCM protocol. macOS supports the RNDIS protocol since version 10.15 (Catalina).

Which protocol is used is selected by the corresponding pseudomodules `tinyusb_class_net_cdc_ecm`, `tinyusb_class_net_cdc_ncm` and `tinyusb_class_net_rndis`.

The CDC ECM protocol (`tinyusb_class_net_cdc_ecm`) and the RNDIS protocol (`tinyusb_class_net_rndis`) can be used simultaneously to support all operating systems, for example :
```
USEMODULE='tinyusb_netdev tinyusb_class_net_rndis tinyusb_class_net_cdc_ecm' \
BOARD=... make -C ... flash
 ```
In this case, the CDC ECM protocol is the default protocol and the RNDIS protocol the alternative protocol defined as second device configuration. The CDC NCM protocol cannot be used together with the CDC ECM or the RNDIS protocol.

This PR includes PR #18983 for now to be compilable. 

Comparison with USBUS CDC ECM (`nucleo-f767zi` board):
```
   text	   data	    bss	    dec	    hex	filename
  65916	    596	  18728	  85240	  14cf8	tests_pkg_tinyusb_netdev.elf
```
```
   text	   data	    bss	    dec	    hex	filename
  63120	    544	  15444	  79108	  13504	tests_usbus_cdc_ecm.elf

```

### Testing procedure

Use a board that is supported by tinyUSB. Compile and flash the test application for each protocol:

1. RNDIS
    ```
    BOARD=... make -j8 -C tests/pkg_tinyusb_netdev flash
    ```
2. CDC ECM
    ```
    CLASS=tinyusb_class_net_cdc_ecm BOARD=... make -j8 -C tests/pkg_tinyusb_netdev flash
    ```
3. CDC NCM
    ```
    CLASS=tinyusb_class_net_cdc_ncm BOARD=... make -j8 -C tests/pkg_tinyusb_netdev flash
    ```
For each test, a network interface should be added on the host. Use command `ifconfig` on USB device and on the host and check that both have a link local address. In syslog there should be an output like the following:
<details>

```
Nov 13 18:14:46 gunny8 kernel: [4611465.480025] usb 1-2.2: new full-speed USB device number 28 using xhci_hcd
Nov 13 18:14:47 gunny8 kernel: [4611465.581641] usb 1-2.2: New USB device found, idVendor=1209, idProduct=7d01, bcdDevice= 1.00
Nov 13 18:14:47 gunny8 kernel: [4611465.581646] usb 1-2.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Nov 13 18:14:47 gunny8 kernel: [4611465.581650] usb 1-2.2: Product: nucleo-f767zi
Nov 13 18:14:47 gunny8 kernel: [4611465.581653] usb 1-2.2: Manufacturer: RIOT-os.org
Nov 13 18:14:47 gunny8 kernel: [4611465.581654] usb 1-2.2: SerialNumber: 6591620BCB270283
Nov 13 18:14:47 gunny8 vmnetBridge: RTM_NEWLINK: name:usb0 index:508 flags:0x00001002
Nov 13 18:14:47 gunny8 vmnet-natd: RTM_NEWLINK: name:usb0 index:508 flags:0x00001002
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.1066] manager: (usb0): new Ethernet device (/org/freedesktop/NetworkManager/Devices/528)
Nov 13 18:14:47 gunny8 kernel: [4611465.594604] rndis_host 1-2.2:1.0 usb0: register 'rndis_host' at usb-0000:00:14.0-2.2, RNDIS device, fa:db:7c:1b:58:80
Nov 13 18:14:47 gunny8 mtp-probe: checking bus 1, device 28: "/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2"
Nov 13 18:14:47 gunny8 mtp-probe: bus: 1, device: 28 was not an MTP device
Nov 13 18:14:47 gunny8 systemd-udevd[17796]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 13 18:14:47 gunny8 vmnet-natd: RTM_NEWLINK: name:usb0 index:508 flags:0x00001002
Nov 13 18:14:47 gunny8 kernel: [4611465.643852] rndis_host 1-2.2:1.0 enp0s20f0u2u2: renamed from usb0
Nov 13 18:14:47 gunny8 vmnetBridge: RTM_NEWLINK: name:usb0 index:508 flags:0x00001002
Nov 13 18:14:47 gunny8 vmnet-natd: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00001002
Nov 13 18:14:47 gunny8 vmnetBridge: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00001002
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.1833] device (usb0): interface index 508 renamed iface from 'usb0' to 'enp0s20f0u2u2'
Nov 13 18:14:47 gunny8 upowerd[2845]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2:1.1
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2037] device (enp0s20f0u2u2): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Nov 13 18:14:47 gunny8 vmnet-natd: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00011043
Nov 13 18:14:47 gunny8 vmnetBridge: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00011043
Nov 13 18:14:47 gunny8 vmnetBridge: Adding interface enp0s20f0u2u2 index:508
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2075] device (enp0s20f0u2u2): carrier: link connected
Nov 13 18:14:47 gunny8 upowerd[2845]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2/1-2.2:1.0
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2129] settings: (enp0s20f0u2u2): created default wired connection 'Kabelgebundene Verbindung 2'
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <warn>  [1668359687.2142] device (enp0s20f0u2u2): connectivity: "/proc/sys/net/ipv4/conf/enp0s20f0u2u2/rp_filter" is set to "1". This might break connectivity checking for IPv4 on this device
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2151] device (enp0s20f0u2u2): state change: unavailable -> disconnected (reason 'none', sys-iface-state: 'managed')
Nov 13 18:14:47 gunny8 vmnetBridge: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00011043
Nov 13 18:14:47 gunny8 vmnet-natd: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00011043
Nov 13 18:14:47 gunny8 upowerd[2845]: unhandled action 'bind' on /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2.2
Nov 13 18:14:47 gunny8 systemd-udevd[17796]: link_config: autonegotiation is unset or enabled, the speed and duplex are not writable.
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2403] policy: auto-activating connection 'Kabelgebundene Verbindung 2' (0b1ae45e-c76e-3efb-a2cd-138ca2b2a59c)
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2414] device (enp0s20f0u2u2): Activation: starting connection 'Kabelgebundene Verbindung 2' (0b1ae45e-c76e-3efb-a2cd-138ca2b2a59c)
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2419] device (enp0s20f0u2u2): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2429] device (enp0s20f0u2u2): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2440] device (enp0s20f0u2u2): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
Nov 13 18:14:47 gunny8 NetworkManager[24229]: <info>  [1668359687.2445] dhcp4 (enp0s20f0u2u2): activation: beginning transaction (timeout in 45 seconds)
Nov 13 18:14:47 gunny8 vmnetBridge: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00011043
Nov 13 18:14:47 gunny8 vmnet-natd: RTM_NEWLINK: name:enp0s20f0u2u2 index:508 flags:0x00011043
Nov 13 18:14:47 gunny8 avahi-daemon[1464]: Joining mDNS multicast group on interface enp0s20f0u2u2.IPv6 with address fe80::dba4:adb8:9ffe:d93e.
Nov 13 18:14:47 gunny8 avahi-daemon[1464]: New relevant interface enp0s20f0u2u2.IPv6 for mDNS.
Nov 13 18:14:47 gunny8 avahi-daemon[1464]: Registering new address record for fe80::dba4:adb8:9ffe:d93e on enp0s20f0u2u2.*.
Nov 13 18:14:47 gunny8 kernel: [4611465.895046] userif-1: sent link down event.
Nov 13 18:14:47 gunny8 kernel: [4611465.895052] userif-1: sent link up event.
```

</details>

Ping from and to the host.

### Issues/PRs references

Depends on PR #18983

Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
  • Loading branch information
bors[bot] and gschorcht committed Feb 3, 2023
2 parents 8700157 + ee8dcfe commit 0fb6a09
Show file tree
Hide file tree
Showing 24 changed files with 940 additions and 38 deletions.
1 change: 1 addition & 0 deletions drivers/Kconfig.net
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rsource "$(RIOTCPU)/stm32/periph/Kconfig.eth"
rsource "sx126x/Kconfig"
rsource "sx127x/Kconfig"
rsource "sx1280/Kconfig"
rsource "$(RIOTPKG)/tinyusb/netdev/Kconfig"
rsource "tja1042/Kconfig"
rsource "w5100/Kconfig"
endmenu # Network Device Drivers
1 change: 1 addition & 0 deletions drivers/include/net/netdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ typedef enum {
NETDEV_ESP_ETH,
NETDEV_ESP_WIFI,
NETDEV_CDC_ECM,
NETDEV_TINYUSB,
/* add more if needed */
} netdev_type_t;
/** @} */
Expand Down
11 changes: 4 additions & 7 deletions pkg/tinyusb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ config MODULE_TINYUSB_HOST
help
Select to enable tinyUSB host stack

config MODULE_TINYUSB_LIB_NETWORKING
bool

config MODULE_TINYUSB_PORTABLE_ESPRESSIF
bool
help
Expand Down Expand Up @@ -170,13 +173,7 @@ menu "Device Classes"
bool "Musical Instrument Digital Interface (MIDI)"
depends on MODULE_TINYUSB_DEVICE

config MODULE_TINYUSB_CLASS_NET_ECM_RNDIS
bool "Network with RNDIS, Ethernet Control Model (ECM)"
depends on MODULE_TINYUSB_DEVICE

config MODULE_TINYUSB_CLASS_NET_NCM
bool "Network with Network Control Model (NCM)"
depends on MODULE_TINYUSB_DEVICE
rsource "Kconfig.net"

config MODULE_TINYUSB_CLASS_USBTMC
bool "Test and Measurement Class (USBTMC)"
Expand Down
60 changes: 60 additions & 0 deletions pkg/tinyusb/Kconfig.net
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) 2022 Gunar Schorcht
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

menuconfig MODULE_TINYUSB_CLASS_NET
bool "Network Device Class"
depends on MODULE_TINYUSB_DEVICE

if MODULE_TINYUSB_CLASS_NET

config MODULE_TINYUSB_CLASS_NET_CDC_ECM
bool "CDC ECM network device"
default y

config MODULE_TINYUSB_CLASS_NET_CDC_NCM
bool "CDC NCM network device"

config MODULE_TINYUSB_CLASS_NET_RNDIS
bool "RNDIS network device"
select MODULE_TINYUSB_LIB_NETWORKING

config TUSBD_NET_NUMOF
int
default 1

if TUSBD_NET_NUMOF > 0

config TUSBD_NET_NOTIF_EP_SIZE
int "Net Notification endpoint size [byte]"
default 64

config TUSBD_NET_FS_EP_SIZE
int "Net Full-Speed endpoint size [byte]"
default 64

config TUSBD_NET_HS_EP_SIZE
int "Net High-Speed endpoint size [byte]"
default 512

config TUSBD_NET_MTU_SIZE
int "MTU size [byte]"
default 1514

config TUSBD_NET_DESC_STRING
string "Class descriptor string"
default "TinyUSB Net"

config TUSBD_NET_CUSTOM_MAC
bool "Use custom MAC address string"

config TUSBD_NET_MAC_STRING
string "MAC address string"
depends on TUSBD_ECM_CUSTOM_MAC
default "0123456789ab"

endif # TUSBD_NET_NUMOF > 0
endif # MODULE_TINYUSB_CLASS_NET
14 changes: 9 additions & 5 deletions pkg/tinyusb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ PKG_LICENSE=MIT
include $(RIOTBASE)/pkg/pkg.mk

PSRC = $(PKG_SOURCE_DIR)/src
PLIB = $(PKG_SOURCE_DIR)/lib

.PHONY: all

all: $(filter tinyusb_% stdio_tinyusb_cdc_acm,$(USEMODULE))
all: $(filter tinyusb_% stdio_tinyusb_cdc_acm,$(filter-out tinyusb_class_net_%,$(USEMODULE)))
$(QQ)"$(MAKE)" -C $(PSRC) -f $(RIOTBASE)/Makefile.base MODULE=tinyusb

stdio_tinyusb_cdc_acm:
Expand All @@ -26,6 +27,9 @@ tinyusb_dfu:
tinyusb_hw:
$(QQ)"$(MAKE)" -C $(RIOTPKG)/$(PKG_NAME)/hw

tinyusb_netdev:
$(QQ)"$(MAKE)" -C $(RIOTPKG)/$(PKG_NAME)/netdev

tinyusb_class_audio:
$(QQ)"$(MAKE)" -C $(PSRC)/class/audio -f $(RIOTBASE)/Makefile.base MODULE=$@

Expand All @@ -50,10 +54,7 @@ tinyusb_class_midi:
tinyusb_class_msc:
$(QQ)"$(MAKE)" -C $(PSRC)/class/msc -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_class_net_ecm_rndis:
$(QQ)"$(MAKE)" -C $(PSRC)/class/net -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_class_net_ncm:
tinyusb_class_net:
$(QQ)"$(MAKE)" -C $(PSRC)/class/net -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_class_usbtmc:
Expand All @@ -74,6 +75,9 @@ tinyusb_device:
tinyusb_host:
$(QQ)"$(MAKE)" -C $(PSRC)/host -f $(RIOTBASE)/Makefile.base MODULE=$@

tinyusb_lib_networking:
$(QQ)"$(MAKE)" -C $(PLIB)/networking -f $(RIOTPKG)/$(PKG_NAME)/Makefile.lib_networking

tinyusb_portable_espressif:
$(QQ)"$(MAKE)" -C $(PSRC)/portable/espressif/esp32sx -f $(RIOTBASE)/Makefile.base MODULE=$@

Expand Down
23 changes: 19 additions & 4 deletions pkg/tinyusb/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ ifneq (,$(filter tinyusb_dfu,$(USEMODULE)))
endif
endif

ifneq (,$(filter tinyusb_class_net_%,$(USEMODULE)))
USEMODULE += tinyusb_class_net
endif

ifneq (,$(filter tinyusb_netdev,$(USEMODULE)))
USEMODULE += luid
USEMODULE += netdev_eth
USEMODULE += tinyusb_device
ifeq (,$(filter tinyusb_class_net_%,$(USEMODULE)))
# default to CDC ECM
USEMODULE += tinyusb_class_net_cdc_ecm
endif
endif

ifneq (,$(filter tinyusb_class_net_rndis,$(USEMODULE)))
USEMODULE += tinyusb_lib_networking
endif

ifeq (,$(filter tinyusb_class_%,$(USEMODULE)))
$(error At least one tinyusb_class_* module has to be enabled)
endif
Expand Down Expand Up @@ -60,10 +78,7 @@ endif
ifneq (,$(filter tinyusb_class_midi,$(USEMODULE)))
USEMODULE += tinyusb_device
endif
ifneq (,$(filter tinyusb_class_net_ecm_rndis,$(USEMODULE)))
USEMODULE += tinyusb_device
endif
ifneq (,$(filter tinyusb_class_net_ncm,$(USEMODULE)))
ifneq (,$(filter tinyusb_class_net,$(USEMODULE)))
USEMODULE += tinyusb_device
endif
ifneq (,$(filter tinyusb_class_usbtmc,$(USEMODULE)))
Expand Down
10 changes: 9 additions & 1 deletion pkg/tinyusb/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
PSEUDOMODULES += tinyusb_class_net_cdc_ecm
PSEUDOMODULES += tinyusb_class_net_cdc_ncm
PSEUDOMODULES += tinyusb_class_net_rndis

INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/contrib
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/contrib/include
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/hw/include
Expand Down Expand Up @@ -30,10 +34,14 @@ else
$(error CPU $(CPU) or CPU family $(CPU_FAM) not supported)
endif

ifneq (,$(filter tinyusb_class_net_ecm_rndis,$(USEMODULE)))
ifneq (,$(filter tinyusb_class_net tinyusb_lib_networking,$(USEMODULE)))
INCLUDES += -I$(PKGDIRBASE)/tinyusb/lib/networking
endif

ifneq (,$(filter tinyusb_dfu,$(USEMODULE)))
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/dfu/include
endif

ifneq (,$(filter tinyusb_netdev,$(USEMODULE)))
INCLUDES += -I$(RIOTBASE)/pkg/tinyusb/netdev/include
endif
5 changes: 5 additions & 0 deletions pkg/tinyusb/Makefile.lib_networking
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = tinyusb_lib_networking

SRC = rndis_reports.c

include $(RIOTBASE)/Makefile.base
4 changes: 4 additions & 0 deletions pkg/tinyusb/contrib/include/tinyusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
extern "C" {
#endif

#if MODULE_TINYUSB_CLASS_NET_RNDIS
#define SIZEOF_ETH_HDR 14
#endif

/**
* @brief Initialize the tinyUSB stack including used peripherals and start the tinyUSB thread
*
Expand Down
51 changes: 49 additions & 2 deletions pkg/tinyusb/contrib/include/tinyusb_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ enum {
#if CONFIG_TUSBD_MSC_NUMOF
TUSBD_ITF_MSC, /**< MSC interface */
#endif
#if CONFIG_TUSBD_NET_NUMOF
TUSBD_ITF_NET, /**< NET Notification interface */
TUSBD_ITF_NET_DATA, /**< NET Data interface */
#endif
#if CONFIG_TUSBD_VENDOR_NUMOF
TUSBD_ITF_VENDOR, /**< Vendor interface */
#endif
Expand Down Expand Up @@ -87,6 +91,11 @@ enum {
TUSBD_EP_MSC_OUT = TUSBD_ITF_MSC + 0x01, /**< MSC EP OUT */
TUSBD_EP_MSC_IN = TUSBD_ITF_MSC + 0x81, /**< MSC EP IN */
#endif
#if CONFIG_TUSBD_NET_NUMOF
TUSBD_EP_NET_NOTIF = TUSBD_ITF_NET + 0x81, /**< NET Notification EP IN */
TUSBD_EP_NET_OUT = TUSBD_ITF_NET_DATA + 0x01, /**< NET Data EP OUT */
TUSBD_EP_NET_IN = TUSBD_ITF_NET_DATA + 0x81, /**< NET Data EP IN */
#endif
#if CONFIG_TUSBD_VENDOR_NUMOF
TUSBD_EP_VENDOR_OUT = TUSBD_ITF_VENDOR + 0x01, /**< Vendor EP OUT */
TUSBD_EP_VENDOR_IN = TUSBD_ITF_VENDOR + 0x81, /**< Vendor EP IN */
Expand Down Expand Up @@ -123,6 +132,20 @@ enum {
#if CONFIG_TUSBD_MSC_NUMOF
TUSBD_STR_IDX_MSC,
#endif

#if CONFIG_TUSBD_NET_NUMOF
#if CONFIG_TUSBD_NET_CDC_ECM
TUSBD_STR_IDX_NET_CDC_ECM,
#endif /* CONFIG_TUSBD_NET_CDC_ECM */
#if CONFIG_TUSBD_NET_CDC_NCM
TUSBD_STR_IDX_NET_CDC_NCM,
#endif /* CONFIG_TUSBD_NET_CDC_NCM */
#if CONFIG_TUSBD_NET_RNDIS
TUSBD_STR_IDX_NET_RNDIS,
#endif /* CONFIG_TUSBD_NET_RNDIS */
TUSBD_STR_IDX_NET_MAC,
#endif /* CONFIG_TUSBD_NET_NUMOF */

#if CONFIG_TUSBD_VENDOR_NUMOF
TUSBD_STR_IDX_VENDOR,
#endif
Expand All @@ -134,22 +157,46 @@ enum {
#define CONFIG_TUSBD_DFU_ALT_NUMOF 2

#if !defined(TUSBD_DESC_TOTAL_LEN)

#if CONFIG_TUSBD_NET_CDC_ECM
#define TUSBD_DESC_NET_LEN TUD_CDC_ECM_DESC_LEN
#elif CONFIG_TUSBD_NET_CDC_NCM
#define TUSBD_DESC_NET_LEN TUD_CDC_NCM_DESC_LEN
#elif CONFIG_TUSBD_NET_RNDIS
#define TUSBD_DESC_NET_LEN TUD_RNDIS_DESC_LEN
#else
#define TUSBD_DESC_NET_LEN 0
#endif

#define TUSBD_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
(CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
(CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
(CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
(CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
(CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN))
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN) + \
TUSBD_DESC_NET_LEN)

#endif /* !defined(TUSBD_DESC_TOTAL_LEN) */

/* If CDC ECM and RNDIS are used simultaneously, an alternative configuration
* descriptor is required. In this case, the main configuration descriptor
* contains the CDC ECM interface descriptor and the alternative configuration
* descriptor contains the RNDIS interface descriptor. */
#if CONFIG_TUSBD_NET_CDC_ECM && CONFIG_TUSBD_NET_RNDIS

#define TUSBD_DESC_ALT_NET_LEN TUD_RNDIS_DESC_LEN

#define TUSBD_DESC_ALT_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
(CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
(CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
(CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
(CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
(CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN))
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN) + \
TUSBD_DESC_ALT_NET_LEN)

#endif /* CONFIG_TUSBD_NET_CDC_ECM && CONFIG_TUSBD_NET_RNDIS */

#endif /* !defined(CONFIG_TUSBD_USE_CUSTOM_DESC) */

Expand Down
Loading

0 comments on commit 0fb6a09

Please sign in to comment.