summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2021-10-12 22:01:02 +0700
committerGitHub <[email protected]>2021-10-12 22:01:02 +0700
commit379537cb6deed9c9c055d0fd34d9a941f47ffc02 (patch)
treea457364337eed1c0ad3bd01433ecf48d9d99015e /examples
parent557fa3900a78f1c378c5653d590253ea87450013 (diff)
parentecec0370cac2a64ef2a0cf2e4e13f1c4e738e81b (diff)
Merge branch 'master' into add_uvc
Diffstat (limited to 'examples')
-rw-r--r--examples/device/audio_4_channel_mic/src/usb_descriptors.c15
-rw-r--r--examples/device/audio_test/src/usb_descriptors.c13
-rw-r--r--examples/device/cdc_msc_freertos/src/CMakeLists.txt3
-rw-r--r--examples/device/hid_composite_freertos/src/CMakeLists.txt3
-rw-r--r--examples/device/net_lwip_webserver/src/main.c2
-rw-r--r--examples/device/net_lwip_webserver/src/tusb_config.h11
-rw-r--r--examples/device/net_lwip_webserver/src/usb_descriptors.c26
-rw-r--r--examples/device/uac2_headset/src/usb_descriptors.c29
-rw-r--r--examples/host/CMakeLists.txt1
-rw-r--r--examples/rules.mk3
10 files changed, 73 insertions, 33 deletions
diff --git a/examples/device/audio_4_channel_mic/src/usb_descriptors.c b/examples/device/audio_4_channel_mic/src/usb_descriptors.c
index 018919bf3..b6a5bd5c2 100644
--- a/examples/device/audio_4_channel_mic/src/usb_descriptors.c
+++ b/examples/device/audio_4_channel_mic/src/usb_descriptors.c
@@ -81,12 +81,17 @@ enum
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_FOUR_CH_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
-// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
-#define EPNUM_AUDIO 0x03
+#if TU_CHECK_MCU(LPC175X_6X) || TU_CHECK_MCU(LPC177X_8X) || TU_CHECK_MCU(LPC40XX)
+ // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
+ // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
+ #define EPNUM_AUDIO 0x03
+
+#elif TU_CHECK_MCU(NRF5X)
+ // nRF5x ISO can only be endpoint 8
+ #define EPNUM_AUDIO 0x08
+
#else
-#define EPNUM_AUDIO 0x01
+ #define EPNUM_AUDIO 0x01
#endif
uint8_t const desc_configuration[] =
diff --git a/examples/device/audio_test/src/usb_descriptors.c b/examples/device/audio_test/src/usb_descriptors.c
index a4e9dc8e1..348f5eede 100644
--- a/examples/device/audio_test/src/usb_descriptors.c
+++ b/examples/device/audio_test/src/usb_descriptors.c
@@ -82,11 +82,16 @@ enum
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_ONE_CH_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
-// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
-#define EPNUM_AUDIO 0x03
+ // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
+ // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
+ #define EPNUM_AUDIO 0x03
+
+#elif TU_CHECK_MCU(NRF5X)
+ // nRF5x ISO can only be endpoint 8
+ #define EPNUM_AUDIO 0x08
+
#else
-#define EPNUM_AUDIO 0x01
+ #define EPNUM_AUDIO 0x01
#endif
uint8_t const desc_configuration[] =
diff --git a/examples/device/cdc_msc_freertos/src/CMakeLists.txt b/examples/device/cdc_msc_freertos/src/CMakeLists.txt
index c0a665fa0..07fc4df89 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/ecm_rndis_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..6f156379f 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/ecm_rndis_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..114961cb7 100644
--- a/examples/device/net_lwip_webserver/src/tusb_config.h
+++ b/examples/device/net_lwip_webserver/src/tusb_config.h
@@ -95,12 +95,11 @@
#endif
//------------- CLASS -------------//
-#define CFG_TUD_CDC 0
-#define CFG_TUD_MSC 0
-#define CFG_TUD_HID 0
-#define CFG_TUD_MIDI 0
-#define CFG_TUD_VENDOR 0
-#define CFG_TUD_NET 1
+
+// Network class has 2 drivers: ECM/RNDIS and NCM.
+// Only one of the drivers can be enabled
+#define CFG_TUD_ECM_RNDIS 1
+#define CFG_TUD_NCM (1-CFG_TUD_ECM_RNDIS)
#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..2b4b2a0c3 100644
--- a/examples/device/net_lwip_webserver/src/usb_descriptors.c
+++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c
@@ -33,7 +33,7 @@
*/
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
- _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) | _PID_MAP(NET, 5) )
+ _PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) | _PID_MAP(ECM_RNDIS, 5) | _PID_MAP(NCM, 5) )
// String Descriptor Index
enum
@@ -55,8 +55,12 @@ enum
enum
{
+#if CFG_TUD_ECM_RNDIS
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,8 @@ uint8_t const * tud_descriptor_device_cb(void)
#define EPNUM_NET_IN 0x82
#endif
+#if CFG_TUD_ECM_RNDIS
+
static uint8_t const rndis_configuration[] =
{
// Config number (index+1), interface count, string index, total length, attribute, power in mA
@@ -138,14 +145,31 @@ static uint8_t const ecm_configuration[] =
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
// - MacOS only works with CDC-ECM
// - Linux will work on both
static uint8_t const * const configuration_arr[2] =
{
+#if CFG_TUD_ECM_RNDIS
[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/device/uac2_headset/src/usb_descriptors.c b/examples/device/uac2_headset/src/usb_descriptors.c
index 64fa3c25b..9e97845b8 100644
--- a/examples/device/uac2_headset/src/usb_descriptors.c
+++ b/examples/device/uac2_headset/src/usb_descriptors.c
@@ -77,22 +77,25 @@ uint8_t const * tud_descriptor_device_cb(void)
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_HEADSET_STEREO_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
-// 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
-#define EPNUM_AUDIO_IN 0x03
-#define EPNUM_AUDIO_OUT 0x03
+ // LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
+ // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
+ #define EPNUM_AUDIO_IN 0x03
+ #define EPNUM_AUDIO_OUT 0x03
+
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
-// ISO endpoints for NRF5x are fixed to 0x08 (0x88)
-#define EPNUM_AUDIO_IN 0x08
-#define EPNUM_AUDIO_OUT 0x08
+ // ISO endpoints for NRF5x are fixed to 0x08 (0x88)
+ #define EPNUM_AUDIO_IN 0x08
+ #define EPNUM_AUDIO_OUT 0x08
+
#elif CFG_TUSB_MCU == OPT_MCU_SAMG || CFG_TUSB_MCU == OPT_MCU_SAMX7X
-// SAMG & SAME70 don't support a same endpoint number with different direction IN and OUT
-// e.g EP1 OUT & EP1 IN cannot exist together
-#define EPNUM_AUDIO_IN 0x01
-#define EPNUM_AUDIO_OUT 0x02
+ // SAMG & SAME70 don't support a same endpoint number with different direction IN and OUT
+ // e.g EP1 OUT & EP1 IN cannot exist together
+ #define EPNUM_AUDIO_IN 0x01
+ #define EPNUM_AUDIO_OUT 0x02
+
#else
-#define EPNUM_AUDIO_IN 0x01
-#define EPNUM_AUDIO_OUT 0x01
+ #define EPNUM_AUDIO_IN 0x01
+ #define EPNUM_AUDIO_OUT 0x01
#endif
uint8_t const desc_configuration[] =
diff --git a/examples/host/CMakeLists.txt b/examples/host/CMakeLists.txt
index f185ac4f8..5c63ec0c0 100644
--- a/examples/host/CMakeLists.txt
+++ b/examples/host/CMakeLists.txt
@@ -7,3 +7,4 @@ family_initialize_project(tinyusb_host_examples ${CMAKE_CURRENT_LIST_DIR})
# family_add_subdirectory will filter what to actually add based on selected FAMILY
family_add_subdirectory(cdc_msc_hid)
+family_add_subdirectory(hid_controller)
diff --git a/examples/rules.mk b/examples/rules.mk
index 6f2d5a0ee..7e494b3d8 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/ecm_rndis_device.c \
+ src/class/net/ncm_device.c \
src/class/usbtmc/usbtmc_device.c \
src/class/video/video_device.c \
src/class/vendor/vendor_device.c