From 03d7988df3f491515389751a8cf4baecafb155fc Mon Sep 17 00:00:00 2001 From: Peter Lawrence <12226419+majbthrd@users.noreply.github.com> Date: Tue, 3 Aug 2021 11:28:44 -0500 Subject: add NCM driver in a compatible manner : hathach/tinyusb#550 --- examples/device/cdc_msc_freertos/src/CMakeLists.txt | 3 ++- .../device/hid_composite_freertos/src/CMakeLists.txt | 3 ++- examples/device/net_lwip_webserver/src/main.c | 2 +- examples/device/net_lwip_webserver/src/tusb_config.h | 1 + .../device/net_lwip_webserver/src/usb_descriptors.c | 20 ++++++++++++++++++++ examples/rules.mk | 3 ++- 6 files changed, 28 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/device/cdc_msc_freertos/src/CMakeLists.txt b/examples/device/cdc_msc_freertos/src/CMakeLists.txt index c0a665fa0..f1c1e8c5d 100644 --- a/examples/device/cdc_msc_freertos/src/CMakeLists.txt +++ b/examples/device/cdc_msc_freertos/src/CMakeLists.txt @@ -23,7 +23,8 @@ target_sources(${COMPONENT_TARGET} PUBLIC "${TOP}/src/class/hid/hid_device.c" "${TOP}/src/class/midi/midi_device.c" "${TOP}/src/class/msc/msc_device.c" - "${TOP}/src/class/net/net_device.c" + "${TOP}/src/class/net/ecmrndis_device.c" + "${TOP}/src/class/net/ncm_device.c" "${TOP}/src/class/usbtmc/usbtmc_device.c" "${TOP}/src/class/vendor/vendor_device.c" "${TOP}/src/portable/espressif/esp32sx/dcd_esp32sx.c" diff --git a/examples/device/hid_composite_freertos/src/CMakeLists.txt b/examples/device/hid_composite_freertos/src/CMakeLists.txt index a2a4fc9b1..70df447dd 100644 --- a/examples/device/hid_composite_freertos/src/CMakeLists.txt +++ b/examples/device/hid_composite_freertos/src/CMakeLists.txt @@ -23,7 +23,8 @@ target_sources(${COMPONENT_TARGET} PUBLIC "${TOP}/src/class/hid/hid_device.c" "${TOP}/src/class/midi/midi_device.c" "${TOP}/src/class/msc/msc_device.c" - "${TOP}/src/class/net/net_device.c" + "${TOP}/src/class/net/ecmrndis_device.c" + "${TOP}/src/class/net/ncm_device.c" "${TOP}/src/class/usbtmc/usbtmc_device.c" "${TOP}/src/class/vendor/vendor_device.c" "${TOP}/src/portable/espressif/esp32sx/dcd_esp32sx.c" diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c index 80831921a..a5bd2153a 100644 --- a/examples/device/net_lwip_webserver/src/main.c +++ b/examples/device/net_lwip_webserver/src/main.c @@ -97,7 +97,7 @@ static err_t linkoutput_fn(struct netif *netif, struct pbuf *p) return ERR_USE; /* if the network driver can accept another packet, we make it happen */ - if (tud_network_can_xmit()) + if (tud_network_can_xmit(p->tot_len)) { tud_network_xmit(p, 0 /* unused for this example */); return ERR_OK; diff --git a/examples/device/net_lwip_webserver/src/tusb_config.h b/examples/device/net_lwip_webserver/src/tusb_config.h index 262d4ebce..457918cac 100644 --- a/examples/device/net_lwip_webserver/src/tusb_config.h +++ b/examples/device/net_lwip_webserver/src/tusb_config.h @@ -101,6 +101,7 @@ #define CFG_TUD_MIDI 0 #define CFG_TUD_VENDOR 0 #define CFG_TUD_NET 1 +#define CFG_TUD_NCM 0 #ifdef __cplusplus } diff --git a/examples/device/net_lwip_webserver/src/usb_descriptors.c b/examples/device/net_lwip_webserver/src/usb_descriptors.c index 71e6c4582..d9618a3dc 100644 --- a/examples/device/net_lwip_webserver/src/usb_descriptors.c +++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c @@ -55,8 +55,12 @@ enum enum { +#if !CFG_TUD_NCM CONFIG_ID_RNDIS = 0, CONFIG_ID_ECM = 1, +#else + CONFIG_ID_NCM = 0, +#endif CONFIG_ID_COUNT }; @@ -99,6 +103,7 @@ uint8_t const * tud_descriptor_device_cb(void) //--------------------------------------------------------------------+ #define MAIN_CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_RNDIS_DESC_LEN) #define ALT_CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_ECM_DESC_LEN) +#define NCM_CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_NCM_DESC_LEN) #if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number @@ -120,6 +125,7 @@ uint8_t const * tud_descriptor_device_cb(void) #define EPNUM_NET_IN 0x82 #endif +#if !CFG_TUD_NCM static uint8_t const rndis_configuration[] = { // Config number (index+1), interface count, string index, total length, attribute, power in mA @@ -137,6 +143,16 @@ static uint8_t const ecm_configuration[] = // Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size. TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, EPNUM_NET_NOTIF, 64, EPNUM_NET_OUT, EPNUM_NET_IN, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU), }; +#else +static uint8_t const ncm_configuration[] = +{ + // Config number (index+1), interface count, string index, total length, attribute, power in mA + TUD_CONFIG_DESCRIPTOR(CONFIG_ID_NCM+1, ITF_NUM_TOTAL, 0, NCM_CONFIG_TOTAL_LEN, 0, 100), + + // Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size. + TUD_CDC_NCM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, EPNUM_NET_NOTIF, 64, EPNUM_NET_OUT, EPNUM_NET_IN, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU), +}; +#endif // Configuration array: RNDIS and CDC-ECM // - Windows only works with RNDIS @@ -144,8 +160,12 @@ static uint8_t const ecm_configuration[] = // - Linux will work on both static uint8_t const * const configuration_arr[2] = { +#if !CFG_TUD_NCM [CONFIG_ID_RNDIS] = rndis_configuration, [CONFIG_ID_ECM ] = ecm_configuration +#else + [CONFIG_ID_NCM ] = ncm_configuration +#endif }; // Invoked when received GET CONFIGURATION DESCRIPTOR diff --git a/examples/rules.mk b/examples/rules.mk index 861973284..a9dfa1363 100644 --- a/examples/rules.mk +++ b/examples/rules.mk @@ -33,7 +33,8 @@ SRC_C += \ src/class/hid/hid_device.c \ src/class/midi/midi_device.c \ src/class/msc/msc_device.c \ - src/class/net/net_device.c \ + src/class/net/ecmrndis_device.c \ + src/class/net/ncm_device.c \ src/class/usbtmc/usbtmc_device.c \ src/class/vendor/vendor_device.c -- cgit v1.3.1