Merge branch 'add_ncm' of https://github.com/majbthrd/tinyusb into majbthrd-add_ncm

This commit is contained in:
hathach
2021-10-05 11:39:32 +07:00
13 changed files with 595 additions and 10 deletions

View File

@@ -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"

View File

@@ -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"

View File

@@ -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;

View File

@@ -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
}

View File

@@ -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

View File

@@ -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