summaryrefslogtreecommitdiff
path: root/examples/device
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2021-02-12 18:05:20 +0100
committerReinhard Panhuber <[email protected]>2021-02-12 18:05:20 +0100
commitcdf600048f717f187243b8118eac43b793c3feec (patch)
tree00d88a8e39560c2e1a35f6c9feb97062733d9d8b /examples/device
parent185414721ff549058a199ade40966015e6260996 (diff)
parent09868434cd9f53394350cce682333ada97f796c3 (diff)
Merge remote-tracking branch 'upstream/master' into edpt_ISO_xfer
Diffstat (limited to 'examples/device')
-rw-r--r--examples/device/audio_test/CMakeLists.txt41
-rw-r--r--examples/device/audio_test/src/tusb_config.h2
-rw-r--r--examples/device/board_test/CMakeLists.txt46
-rw-r--r--examples/device/board_test/src/CMakeLists.txt1
-rw-r--r--examples/device/board_test/src/main.c4
-rw-r--r--examples/device/cdc_dual_ports/CMakeLists.txt41
-rw-r--r--examples/device/cdc_msc/CMakeLists.txt47
-rw-r--r--examples/device/cdc_msc/src/tusb_config.h2
-rw-r--r--examples/device/cdc_msc/src/usb_descriptors.c12
-rw-r--r--examples/device/cdc_msc_freertos/.skip.MCU_RP20400
-rw-r--r--examples/device/cdc_msc_freertos/CMakeLists.txt19
-rw-r--r--examples/device/dfu_runtime/CMakeLists.txt41
-rw-r--r--examples/device/dfu_runtime/Makefile (renamed from examples/device/dfu_rt/Makefile)0
-rw-r--r--examples/device/dfu_runtime/src/main.c (renamed from examples/device/dfu_rt/src/main.c)2
-rw-r--r--examples/device/dfu_runtime/src/tusb_config.h (renamed from examples/device/dfu_rt/src/tusb_config.h)5
-rw-r--r--examples/device/dfu_runtime/src/usb_descriptors.c (renamed from examples/device/dfu_rt/src/usb_descriptors.c)0
-rw-r--r--examples/device/dynamic_configuration/CMakeLists.txt42
-rw-r--r--examples/device/dynamic_configuration/src/main.c6
-rw-r--r--examples/device/dynamic_configuration/src/tusb_config.h3
-rw-r--r--examples/device/hid_composite/CMakeLists.txt41
-rw-r--r--examples/device/hid_composite/src/main.c140
-rw-r--r--examples/device/hid_composite/src/tusb_config.h3
-rw-r--r--examples/device/hid_composite/src/usb_descriptors.c10
-rw-r--r--examples/device/hid_composite/src/usb_descriptors.h5
-rw-r--r--examples/device/hid_composite_freertos/.skip.MCU_RP20400
-rw-r--r--examples/device/hid_composite_freertos/CMakeLists.txt19
-rw-r--r--examples/device/hid_composite_freertos/src/main.c137
-rw-r--r--examples/device/hid_composite_freertos/src/usb_descriptors.c10
-rw-r--r--examples/device/hid_composite_freertos/src/usb_descriptors.h5
-rw-r--r--examples/device/hid_generic_inout/CMakeLists.txt41
-rw-r--r--examples/device/hid_generic_inout/src/main.c4
-rw-r--r--examples/device/hid_generic_inout/src/tusb_config.h3
-rw-r--r--examples/device/hid_multiple_interface/CMakeLists.txt41
-rw-r--r--examples/device/hid_multiple_interface/src/tusb_config.h3
-rw-r--r--examples/device/hid_multiple_interface/src/usb_descriptors.c12
-rw-r--r--examples/device/midi_test/CMakeLists.txt41
-rw-r--r--examples/device/midi_test/src/main.c6
-rw-r--r--examples/device/midi_test/src/tusb_config.h3
-rw-r--r--examples/device/msc_dual_lun/CMakeLists.txt42
-rw-r--r--examples/device/msc_dual_lun/src/tusb_config.h3
-rw-r--r--examples/device/net_lwip_webserver/CMakeLists.txt88
-rw-r--r--examples/device/net_lwip_webserver/src/tusb_config.h3
-rw-r--r--examples/device/uac2_headset/.skip.MCU_SAMD110
-rw-r--r--examples/device/uac2_headset/.skip.MCU_SAME5X0
-rw-r--r--examples/device/uac2_headset/.skip.MCU_SAMG0
-rw-r--r--examples/device/uac2_headset/CMakeLists.txt41
-rw-r--r--examples/device/uac2_headset/src/tusb_config.h2
-rw-r--r--examples/device/usbtmc/CMakeLists.txt42
-rw-r--r--examples/device/usbtmc/src/tusb_config.h3
-rw-r--r--examples/device/usbtmc/src/usb_descriptors.c5
-rw-r--r--examples/device/webusb_serial/CMakeLists.txt41
-rw-r--r--examples/device/webusb_serial/src/main.c78
-rw-r--r--examples/device/webusb_serial/src/tusb_config.h3
53 files changed, 1027 insertions, 162 deletions
diff --git a/examples/device/audio_test/CMakeLists.txt b/examples/device/audio_test/CMakeLists.txt
new file mode 100644
index 000000000..a10473b79
--- /dev/null
+++ b/examples/device/audio_test/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use BOARD-Directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/audio_test/src/tusb_config.h b/examples/device/audio_test/src/tusb_config.h
index 0744afdf0..66a2ae22c 100644
--- a/examples/device/audio_test/src/tusb_config.h
+++ b/examples/device/audio_test/src/tusb_config.h
@@ -45,7 +45,9 @@ extern "C" {
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
#endif
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
#ifndef CFG_TUSB_DEBUG
#define CFG_TUSB_DEBUG 0
diff --git a/examples/device/board_test/CMakeLists.txt b/examples/device/board_test/CMakeLists.txt
index f0437dd04..b8b7e7297 100644
--- a/examples/device/board_test/CMakeLists.txt
+++ b/examples/device/board_test/CMakeLists.txt
@@ -1,15 +1,45 @@
-# The following five lines of boilerplate have to be in your project's
-# CMakeLists in this exact order for cmake to work correctly
-cmake_minimum_required(VERSION 3.5)
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
# TOP is absolute path to root directory of TinyUSB git repo
set(TOP "../../..")
get_filename_component(TOP "${TOP}" REALPATH)
-# Add example src and bsp directories
-set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/${BOARD}")
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "esp32s2")
+ cmake_minimum_required(VERSION 3.5)
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+ project(${PROJECT})
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-set(SUPPORTED_TARGETS esp32s2)
+elseif(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
-project(board_test)
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/board_test/src/CMakeLists.txt b/examples/device/board_test/src/CMakeLists.txt
index 29ae46a33..e59661069 100644
--- a/examples/device/board_test/src/CMakeLists.txt
+++ b/examples/device/board_test/src/CMakeLists.txt
@@ -1,3 +1,4 @@
+# FAMILY = "esp32s2"
idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
REQUIRES freertos soc)
diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c
index 71665550f..d94b24650 100644
--- a/examples/device/board_test/src/main.c
+++ b/examples/device/board_test/src/main.c
@@ -55,10 +55,6 @@ int main(void)
{
uint32_t interval_ms = board_button_read() ? BLINK_PRESSED : BLINK_UNPRESSED;
- // uart echo
-// uint8_t ch;
-// if ( board_uart_read(&ch, 1) ) board_uart_write(&ch, 1);
-
// Blink every interval ms
if ( !(board_millis() - start_ms < interval_ms) )
{
diff --git a/examples/device/cdc_dual_ports/CMakeLists.txt b/examples/device/cdc_dual_ports/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/cdc_dual_ports/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/cdc_msc/CMakeLists.txt b/examples/device/cdc_msc/CMakeLists.txt
new file mode 100644
index 000000000..9e0d1f790
--- /dev/null
+++ b/examples/device/cdc_msc/CMakeLists.txt
@@ -0,0 +1,47 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "esp32s2")
+ cmake_minimum_required(VERSION 3.5)
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+ project(${PROJECT})
+
+elseif(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/cdc_msc/src/tusb_config.h b/examples/device/cdc_msc/src/tusb_config.h
index 1370e61c5..e0099785b 100644
--- a/examples/device/cdc_msc/src/tusb_config.h
+++ b/examples/device/cdc_msc/src/tusb_config.h
@@ -65,7 +65,9 @@
#endif
// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/cdc_msc/src/usb_descriptors.c b/examples/device/cdc_msc/src/usb_descriptors.c
index e13b8189b..fa4342165 100644
--- a/examples/device/cdc_msc/src/usb_descriptors.c
+++ b/examples/device/cdc_msc/src/usb_descriptors.c
@@ -104,6 +104,18 @@ enum
#define EPNUM_MSC_OUT 0x04
#define EPNUM_MSC_IN 0x85
+#elif CFG_TUSB_MCU == OPT_MCU_CXD56
+ // CXD56 doesn't support a same endpoint number with different direction IN and OUT
+ // e.g EP1 OUT & EP1 IN cannot exist together
+ // CXD56 USB driver has fixed endpoint type (bulk/interrupt/iso) and direction (IN/OUT) by its number
+ // 0 control (IN/OUT), 1 Bulk (IN), 2 Bulk (OUT), 3 In (IN), 4 Bulk (IN), 5 Bulk (OUT), 6 In (IN)
+ #define EPNUM_CDC_NOTIF 0x83
+ #define EPNUM_CDC_OUT 0x02
+ #define EPNUM_CDC_IN 0x81
+
+ #define EPNUM_MSC_OUT 0x05
+ #define EPNUM_MSC_IN 0x84
+
#else
#define EPNUM_CDC_NOTIF 0x81
#define EPNUM_CDC_OUT 0x02
diff --git a/examples/device/cdc_msc_freertos/.skip.MCU_RP2040 b/examples/device/cdc_msc_freertos/.skip.MCU_RP2040
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/cdc_msc_freertos/.skip.MCU_RP2040
diff --git a/examples/device/cdc_msc_freertos/CMakeLists.txt b/examples/device/cdc_msc_freertos/CMakeLists.txt
index 339f43a09..dabb4bc80 100644
--- a/examples/device/cdc_msc_freertos/CMakeLists.txt
+++ b/examples/device/cdc_msc_freertos/CMakeLists.txt
@@ -1,15 +1,18 @@
-# The following five lines of boilerplate have to be in your project's
-# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
+# use BOARD-Directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
# TOP is absolute path to root directory of TinyUSB git repo
set(TOP "../../..")
get_filename_component(TOP "${TOP}" REALPATH)
-# Add example src and bsp directories
-set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/${BOARD}")
-
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-set(SUPPORTED_TARGETS esp32s2)
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "esp32s2")
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+ project(${PROJECT})
-project(cdc_msc_freertos)
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/dfu_runtime/CMakeLists.txt b/examples/device/dfu_runtime/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/dfu_runtime/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/dfu_rt/Makefile b/examples/device/dfu_runtime/Makefile
index 69b633fea..69b633fea 100644
--- a/examples/device/dfu_rt/Makefile
+++ b/examples/device/dfu_runtime/Makefile
diff --git a/examples/device/dfu_rt/src/main.c b/examples/device/dfu_runtime/src/main.c
index 029ff7312..823c71ae5 100644
--- a/examples/device/dfu_rt/src/main.c
+++ b/examples/device/dfu_runtime/src/main.c
@@ -112,7 +112,7 @@ void tud_resume_cb(void)
}
// Invoked on DFU_DETACH request to reboot to the bootloader
-void tud_dfu_rt_reboot_to_dfu(void)
+void tud_dfu_runtime_reboot_to_dfu_cb(void)
{
blink_interval_ms = BLINK_DFU_MODE;
}
diff --git a/examples/device/dfu_rt/src/tusb_config.h b/examples/device/dfu_runtime/src/tusb_config.h
index 226573263..bdae1d2e9 100644
--- a/examples/device/dfu_rt/src/tusb_config.h
+++ b/examples/device/dfu_runtime/src/tusb_config.h
@@ -46,8 +46,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
@@ -77,7 +78,7 @@
//------------- CLASS -------------//
-#define CFG_TUD_DFU_RT 1
+#define CFG_TUD_DFU_RUNTIME 1
#ifdef __cplusplus
}
diff --git a/examples/device/dfu_rt/src/usb_descriptors.c b/examples/device/dfu_runtime/src/usb_descriptors.c
index 8b2bd265d..8b2bd265d 100644
--- a/examples/device/dfu_rt/src/usb_descriptors.c
+++ b/examples/device/dfu_runtime/src/usb_descriptors.c
diff --git a/examples/device/dynamic_configuration/CMakeLists.txt b/examples/device/dynamic_configuration/CMakeLists.txt
new file mode 100644
index 000000000..b4c95652a
--- /dev/null
+++ b/examples/device/dynamic_configuration/CMakeLists.txt
@@ -0,0 +1,42 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/dynamic_configuration/src/main.c b/examples/device/dynamic_configuration/src/main.c
index 3ad13aefa..45786e99a 100644
--- a/examples/device/dynamic_configuration/src/main.c
+++ b/examples/device/dynamic_configuration/src/main.c
@@ -165,6 +165,12 @@ void midi_task(void)
{
static uint32_t start_ms = 0;
+ // The MIDI interface always creates input and output port/jack descriptors
+ // regardless of these being used or not. Therefore incoming traffic should be read
+ // (possibly just discarded) to avoid the sender blocking in IO
+ uint8_t packet[4];
+ while(tud_midi_available()) tud_midi_receive(packet);
+
// send note every 1000 ms
if (board_millis() - start_ms < 286) return; // not enough time
start_ms += 286;
diff --git a/examples/device/dynamic_configuration/src/tusb_config.h b/examples/device/dynamic_configuration/src/tusb_config.h
index 2f8072f89..23073faf3 100644
--- a/examples/device/dynamic_configuration/src/tusb_config.h
+++ b/examples/device/dynamic_configuration/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/hid_composite/CMakeLists.txt b/examples/device/hid_composite/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/hid_composite/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c
index 7207e4d4c..9fb2de88d 100644
--- a/examples/device/hid_composite/src/main.c
+++ b/examples/device/hid_composite/src/main.c
@@ -104,6 +104,98 @@ void tud_resume_cb(void)
// USB HID
//--------------------------------------------------------------------+
+static void send_hid_report(uint8_t report_id, uint32_t btn)
+{
+ // skip if hid is not ready yet
+ if ( !tud_hid_ready() ) return;
+
+ switch(report_id)
+ {
+ case REPORT_ID_KEYBOARD:
+ {
+ // use to avoid send multiple consecutive zero report for keyboard
+ static bool has_keyboard_key = false;
+
+ if ( btn )
+ {
+ uint8_t keycode[6] = { 0 };
+ keycode[0] = HID_KEY_A;
+
+ tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode);
+ has_keyboard_key = true;
+ }else
+ {
+ // send empty key report if previously has key pressed
+ if (has_keyboard_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL);
+ has_keyboard_key = false;
+ }
+ }
+ break;
+
+ case REPORT_ID_MOUSE:
+ {
+ int8_t const delta = 5;
+
+ // no button, right + down, no scroll, no pan
+ tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0);
+ }
+ break;
+
+ case REPORT_ID_CONSUMER_CONTROL:
+ {
+ // use to avoid send multiple consecutive zero report
+ static bool has_consumer_key = false;
+
+ if ( btn )
+ {
+ // volume down
+ uint16_t volume_down = HID_USAGE_CONSUMER_VOLUME_DECREMENT;
+ tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &volume_down, 2);
+ has_consumer_key = true;
+ }else
+ {
+ // send empty key report (release key) if previously has key pressed
+ uint16_t empty_key = 0;
+ if (has_consumer_key) tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2);
+ has_consumer_key = false;
+ }
+ }
+ break;
+
+ case REPORT_ID_GAMEPAD:
+ {
+ // use to avoid send multiple consecutive zero report for keyboard
+ static bool has_gamepad_key = false;
+
+ hid_gamepad_report_t report =
+ {
+ .x = 0, .y = 0, .z = 0, .rz = 0, .rx = 0, .ry = 0,
+ .hat = 0, .buttons = 0
+ };
+
+ if ( btn )
+ {
+ report.hat = GAMEPAD_HAT_UP;
+ report.buttons = GAMEPAD_BUTTON_A;
+ tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
+
+ has_gamepad_key = true;
+ }else
+ {
+ report.hat = GAMEPAD_HAT_CENTERED;
+ report.buttons = 0;
+ if (has_gamepad_key) tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
+ has_gamepad_key = false;
+ }
+ }
+ break;
+
+ default: break;
+ }
+}
+
+// Every 10ms, we will sent 1 report for each HID profile (keyboard, mouse etc ..)
+// tud_hid_report_complete_cb() is used to send the next report after previous one is complete
void hid_task(void)
{
// Poll every 10ms
@@ -121,47 +213,29 @@ void hid_task(void)
// Wake up host if we are in suspend mode
// and REMOTE_WAKEUP feature is enabled by host
tud_remote_wakeup();
- }
-
- /*------------- Mouse -------------*/
- if ( tud_hid_ready() )
+ }else
{
- if ( btn )
- {
- int8_t const delta = 5;
-
- // no button, right + down, no scroll pan
- tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0);
-
- // delay a bit before attempt to send keyboard report
- board_delay(10);
- }
+ // Send the 1st of report chain, the rest will be sent by tud_hid_report_complete_cb()
+ send_hid_report(REPORT_ID_KEYBOARD, btn);
}
+}
- /*------------- Keyboard -------------*/
- if ( tud_hid_ready() )
- {
- // use to avoid send multiple consecutive zero report for keyboard
- static bool has_key = false;
-
- if ( btn )
- {
- uint8_t keycode[6] = { 0 };
- keycode[0] = HID_KEY_A;
+// Invoked when sent REPORT successfully to host
+// Application can use this to send the next report
+// Note: For composite reports, report[0] is report ID
+void tud_hid_report_complete_cb(uint8_t itf, uint8_t const* report, uint8_t len)
+{
+ (void) itf;
+ (void) len;
- tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode);
+ uint8_t next_report_id = report[0] + 1;
- has_key = true;
- }else
- {
- // send empty key report if previously has key pressed
- if (has_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL);
- has_key = false;
- }
+ if (next_report_id < REPORT_ID_COUNT)
+ {
+ send_hid_report(next_report_id, board_button_read());
}
}
-
// Invoked when received GET_REPORT control request
// Application must fill buffer report's content and return its length.
// Return zero will cause the stack to STALL request
diff --git a/examples/device/hid_composite/src/tusb_config.h b/examples/device/hid_composite/src/tusb_config.h
index d8e6b73e8..3e608ed37 100644
--- a/examples/device/hid_composite/src/tusb_config.h
+++ b/examples/device/hid_composite/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c
index 5052a436f..ec4976188 100644
--- a/examples/device/hid_composite/src/usb_descriptors.c
+++ b/examples/device/hid_composite/src/usb_descriptors.c
@@ -73,8 +73,10 @@ uint8_t const * tud_descriptor_device_cb(void)
uint8_t const desc_hid_report[] =
{
- TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD) ),
- TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE) )
+ TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD )),
+ TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE )),
+ TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )),
+ TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(REPORT_ID_GAMEPAD ))
};
// Invoked when received GET HID REPORT DESCRIPTOR
@@ -104,8 +106,8 @@ uint8_t const desc_configuration[] =
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
- // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
- TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10)
+ // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
+ TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 5)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
diff --git a/examples/device/hid_composite/src/usb_descriptors.h b/examples/device/hid_composite/src/usb_descriptors.h
index 6992d3349..ca8925ad9 100644
--- a/examples/device/hid_composite/src/usb_descriptors.h
+++ b/examples/device/hid_composite/src/usb_descriptors.h
@@ -28,7 +28,10 @@
enum
{
REPORT_ID_KEYBOARD = 1,
- REPORT_ID_MOUSE
+ REPORT_ID_MOUSE,
+ REPORT_ID_CONSUMER_CONTROL,
+ REPORT_ID_GAMEPAD,
+ REPORT_ID_COUNT
};
#endif /* USB_DESCRIPTORS_H_ */
diff --git a/examples/device/hid_composite_freertos/.skip.MCU_RP2040 b/examples/device/hid_composite_freertos/.skip.MCU_RP2040
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/hid_composite_freertos/.skip.MCU_RP2040
diff --git a/examples/device/hid_composite_freertos/CMakeLists.txt b/examples/device/hid_composite_freertos/CMakeLists.txt
index a429a1336..dabb4bc80 100644
--- a/examples/device/hid_composite_freertos/CMakeLists.txt
+++ b/examples/device/hid_composite_freertos/CMakeLists.txt
@@ -1,15 +1,18 @@
-# The following five lines of boilerplate have to be in your project's
-# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
+# use BOARD-Directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
# TOP is absolute path to root directory of TinyUSB git repo
set(TOP "../../..")
get_filename_component(TOP "${TOP}" REALPATH)
-# Add example src and bsp directories
-set(EXTRA_COMPONENT_DIRS "src" "${TOP}/hw/bsp/${BOARD}")
-
-include($ENV{IDF_PATH}/tools/cmake/project.cmake)
-set(SUPPORTED_TARGETS esp32s2)
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "esp32s2")
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+ project(${PROJECT})
-project(hid_composite_freertos)
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c
index 83c68b515..aa006fbea 100644
--- a/examples/device/hid_composite_freertos/src/main.c
+++ b/examples/device/hid_composite_freertos/src/main.c
@@ -163,64 +163,139 @@ void tud_resume_cb(void)
// USB HID
//--------------------------------------------------------------------+
-void hid_task(void* param)
+static void send_hid_report(uint8_t report_id, uint32_t btn)
{
- (void) param;
+ // skip if hid is not ready yet
+ if ( !tud_hid_ready() ) return;
- while(1)
+ switch(report_id)
{
- // Poll every 10ms
- vTaskDelay(pdMS_TO_TICKS(10));
+ case REPORT_ID_KEYBOARD:
+ {
+ // use to avoid send multiple consecutive zero report for keyboard
+ static bool has_keyboard_key = false;
- uint32_t const btn = board_button_read();
+ if ( btn )
+ {
+ uint8_t keycode[6] = { 0 };
+ keycode[0] = HID_KEY_A;
- // Remote wakeup
- if ( tud_suspended() && btn )
+ tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode);
+ has_keyboard_key = true;
+ }else
+ {
+ // send empty key report if previously has key pressed
+ if (has_keyboard_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL);
+ has_keyboard_key = false;
+ }
+ }
+ break;
+
+ case REPORT_ID_MOUSE:
{
- // Wake up host if we are in suspend mode
- // and REMOTE_WAKEUP feature is enabled by host
- tud_remote_wakeup();
+ int8_t const delta = 5;
+
+ // no button, right + down, no scroll, no pan
+ tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0);
}
+ break;
- /*------------- Mouse -------------*/
- if ( tud_hid_ready() )
+ case REPORT_ID_CONSUMER_CONTROL:
{
+ // use to avoid send multiple consecutive zero report
+ static bool has_consumer_key = false;
+
if ( btn )
{
- int8_t const delta = 5;
-
- // no button, right + down, no scroll pan
- tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0);
-
- // delay a bit before attempt to send keyboard report
- vTaskDelay(pdMS_TO_TICKS(10));
+ // volume down
+ uint16_t volume_down = HID_USAGE_CONSUMER_VOLUME_DECREMENT;
+ tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &volume_down, 2);
+ has_consumer_key = true;
+ }else
+ {
+ // send empty key report (release key) if previously has key pressed
+ uint16_t empty_key = 0;
+ if (has_consumer_key) tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2);
+ has_consumer_key = false;
}
}
+ break;
- /*------------- Keyboard -------------*/
- if ( tud_hid_ready() )
+ case REPORT_ID_GAMEPAD:
{
// use to avoid send multiple consecutive zero report for keyboard
- static bool has_key = false;
+ static bool has_gamepad_key = false;
- if ( btn )
+ hid_gamepad_report_t report =
{
- uint8_t keycode[6] = { 0 };
- keycode[0] = HID_KEY_A;
+ .x = 0, .y = 0, .z = 0, .rz = 0, .rx = 0, .ry = 0,
+ .hat = 0, .buttons = 0
+ };
- tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode);
+ if ( btn )
+ {
+ report.hat = GAMEPAD_HAT_UP;
+ report.buttons = GAMEPAD_BUTTON_A;
+ tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
- has_key = true;
+ has_gamepad_key = true;
}else
{
- // send empty key report if previously has key pressed
- if (has_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL);
- has_key = false;
+ report.hat = GAMEPAD_HAT_CENTERED;
+ report.buttons = 0;
+ if (has_gamepad_key) tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
+ has_gamepad_key = false;
}
}
+ break;
+
+ default: break;
+ }
+}
+
+void hid_task(void* param)
+{
+ (void) param;
+
+ while(1)
+ {
+ // Poll every 10ms
+ vTaskDelay(pdMS_TO_TICKS(10));
+
+ uint32_t const btn = board_button_read();
+
+ // Remote wakeup
+ if ( tud_suspended() && btn )
+ {
+ // Wake up host if we are in suspend mode
+ // and REMOTE_WAKEUP feature is enabled by host
+ tud_remote_wakeup();
+ }
+ else
+ {
+ // Send the 1st of report chain, the rest will be sent by tud_hid_report_complete_cb()
+ send_hid_report(REPORT_ID_KEYBOARD, btn);
+ }
}
}
+// Invoked when sent REPORT successfully to host
+// Application can use this to send the next report
+// Note: For composite reports, report[0] is report ID
+void tud_hid_report_complete_cb(uint8_t itf, uint8_t const* report, uint8_t len)
+{
+ (void) itf;
+ (void) len;
+
+ uint8_t next_report_id = report[0] + 1;
+
+ if (next_report_id < REPORT_ID_COUNT)
+ {
+ send_hid_report(next_report_id, board_button_read());
+ }
+}
+
+
// Invoked when received GET_REPORT control request
// Application must fill buffer report's content and return its length.
// Return zero will cause the stack to STALL request
diff --git a/examples/device/hid_composite_freertos/src/usb_descriptors.c b/examples/device/hid_composite_freertos/src/usb_descriptors.c
index 5052a436f..ec4976188 100644
--- a/examples/device/hid_composite_freertos/src/usb_descriptors.c
+++ b/examples/device/hid_composite_freertos/src/usb_descriptors.c
@@ -73,8 +73,10 @@ uint8_t const * tud_descriptor_device_cb(void)
uint8_t const desc_hid_report[] =
{
- TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD) ),
- TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE) )
+ TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD )),
+ TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE )),
+ TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(REPORT_ID_CONSUMER_CONTROL )),
+ TUD_HID_REPORT_DESC_GAMEPAD ( HID_REPORT_ID(REPORT_ID_GAMEPAD ))
};
// Invoked when received GET HID REPORT DESCRIPTOR
@@ -104,8 +106,8 @@ uint8_t const desc_configuration[] =
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
- // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
- TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10)
+ // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
+ TUD_HID_DESCRIPTOR(ITF_NUM_HID, 0, HID_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 5)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
diff --git a/examples/device/hid_composite_freertos/src/usb_descriptors.h b/examples/device/hid_composite_freertos/src/usb_descriptors.h
index 6992d3349..ca8925ad9 100644
--- a/examples/device/hid_composite_freertos/src/usb_descriptors.h
+++ b/examples/device/hid_composite_freertos/src/usb_descriptors.h
@@ -28,7 +28,10 @@
enum
{
REPORT_ID_KEYBOARD = 1,
- REPORT_ID_MOUSE
+ REPORT_ID_MOUSE,
+ REPORT_ID_CONSUMER_CONTROL,
+ REPORT_ID_GAMEPAD,
+ REPORT_ID_COUNT
};
#endif /* USB_DESCRIPTORS_H_ */
diff --git a/examples/device/hid_generic_inout/CMakeLists.txt b/examples/device/hid_generic_inout/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/hid_generic_inout/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/hid_generic_inout/src/main.c b/examples/device/hid_generic_inout/src/main.c
index c1dc43b34..4573bd7e0 100644
--- a/examples/device/hid_generic_inout/src/main.c
+++ b/examples/device/hid_generic_inout/src/main.c
@@ -36,8 +36,8 @@
*
* There are 2 ways to test the sketch
* 1. Using nodejs
- * - Install nodejs and nmp to your PC
- * - Install execellent node-hid (https://github.com/node-hid/node-hid) by
+ * - Install nodejs and npm to your PC
+ * - Install excellent node-hid (https://github.com/node-hid/node-hid) by
* $ npm install node-hid
* - Run provided hid test script
* $ node hid_test.js
diff --git a/examples/device/hid_generic_inout/src/tusb_config.h b/examples/device/hid_generic_inout/src/tusb_config.h
index 347cb06d6..1b8b91c41 100644
--- a/examples/device/hid_generic_inout/src/tusb_config.h
+++ b/examples/device/hid_generic_inout/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/hid_multiple_interface/CMakeLists.txt b/examples/device/hid_multiple_interface/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/hid_multiple_interface/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/hid_multiple_interface/src/tusb_config.h b/examples/device/hid_multiple_interface/src/tusb_config.h
index 412f9b004..a0aa17a90 100644
--- a/examples/device/hid_multiple_interface/src/tusb_config.h
+++ b/examples/device/hid_multiple_interface/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c
index 0d67d499a..a28e57a2b 100644
--- a/examples/device/hid_multiple_interface/src/usb_descriptors.c
+++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c
@@ -118,7 +118,7 @@ uint8_t const desc_configuration[] =
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100),
- // Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
+ // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
TUD_HID_DESCRIPTOR(ITF_NUM_HID1, 4, HID_PROTOCOL_NONE, sizeof(desc_hid_report1), EPNUM_HID1, CFG_TUD_HID_EP_BUFSIZE, 10),
TUD_HID_DESCRIPTOR(ITF_NUM_HID2, 5, HID_PROTOCOL_NONE, sizeof(desc_hid_report2), EPNUM_HID2, CFG_TUD_HID_EP_BUFSIZE, 10)
};
@@ -140,11 +140,11 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
char const* string_desc_arr [] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "TinyUSB", // 1: Manufacturer
- "TinyUSB Device", // 2: Product
- "123456", // 3: Serials, should use chip ID
- "Keyboard Interface", // 4: Interface 1 String
- "Mouse Interface", // 5: Interface 2 String
+ "TinyUSB", // 1: Manufacturer
+ "TinyUSB Device", // 2: Product
+ "123456", // 3: Serials, should use chip ID
+ "Keyboard Interface", // 4: Interface 1 String
+ "Mouse Interface", // 5: Interface 2 String
};
static uint16_t _desc_str[32];
diff --git a/examples/device/midi_test/CMakeLists.txt b/examples/device/midi_test/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/midi_test/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/midi_test/src/main.c b/examples/device/midi_test/src/main.c
index 96292dd6b..d92621fc9 100644
--- a/examples/device/midi_test/src/main.c
+++ b/examples/device/midi_test/src/main.c
@@ -125,6 +125,12 @@ void midi_task(void)
{
static uint32_t start_ms = 0;
+ // The MIDI interface always creates input and output port/jack descriptors
+ // regardless of these being used or not. Therefore incoming traffic should be read
+ // (possibly just discarded) to avoid the sender blocking in IO
+ uint8_t packet[4];
+ while(tud_midi_available()) tud_midi_receive(packet);
+
// send note every 1000 ms
if (board_millis() - start_ms < 286) return; // not enough time
start_ms += 286;
diff --git a/examples/device/midi_test/src/tusb_config.h b/examples/device/midi_test/src/tusb_config.h
index d0c327e27..61b9b6552 100644
--- a/examples/device/midi_test/src/tusb_config.h
+++ b/examples/device/midi_test/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/msc_dual_lun/CMakeLists.txt b/examples/device/msc_dual_lun/CMakeLists.txt
new file mode 100644
index 000000000..6032308f2
--- /dev/null
+++ b/examples/device/msc_dual_lun/CMakeLists.txt
@@ -0,0 +1,42 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_disk_dual.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/msc_dual_lun/src/tusb_config.h b/examples/device/msc_dual_lun/src/tusb_config.h
index e153a7967..44da21e54 100644
--- a/examples/device/msc_dual_lun/src/tusb_config.h
+++ b/examples/device/msc_dual_lun/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/net_lwip_webserver/CMakeLists.txt b/examples/device/net_lwip_webserver/CMakeLists.txt
new file mode 100644
index 000000000..e3c8190f4
--- /dev/null
+++ b/examples/device/net_lwip_webserver/CMakeLists.txt
@@ -0,0 +1,88 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # lwip Stack source
+ set(SRC_LWIP
+ ${TOP}/lib/lwip/src/core/altcp.c
+ ${TOP}/lib/lwip/src/core/altcp_alloc.c
+ ${TOP}/lib/lwip/src/core/altcp_tcp.c
+ ${TOP}/lib/lwip/src/core/def.c
+ ${TOP}/lib/lwip/src/core/dns.c
+ ${TOP}/lib/lwip/src/core/inet_chksum.c
+ ${TOP}/lib/lwip/src/core/init.c
+ ${TOP}/lib/lwip/src/core/ip.c
+ ${TOP}/lib/lwip/src/core/mem.c
+ ${TOP}/lib/lwip/src/core/memp.c
+ ${TOP}/lib/lwip/src/core/netif.c
+ ${TOP}/lib/lwip/src/core/pbuf.c
+ ${TOP}/lib/lwip/src/core/raw.c
+ ${TOP}/lib/lwip/src/core/stats.c
+ ${TOP}/lib/lwip/src/core/sys.c
+ ${TOP}/lib/lwip/src/core/tcp.c
+ ${TOP}/lib/lwip/src/core/tcp_in.c
+ ${TOP}/lib/lwip/src/core/tcp_out.c
+ ${TOP}/lib/lwip/src/core/timeouts.c
+ ${TOP}/lib/lwip/src/core/udp.c
+ ${TOP}/lib/lwip/src/core/ipv4/autoip.c
+ ${TOP}/lib/lwip/src/core/ipv4/dhcp.c
+ ${TOP}/lib/lwip/src/core/ipv4/etharp.c
+ ${TOP}/lib/lwip/src/core/ipv4/icmp.c
+ ${TOP}/lib/lwip/src/core/ipv4/igmp.c
+ ${TOP}/lib/lwip/src/core/ipv4/ip4.c
+ ${TOP}/lib/lwip/src/core/ipv4/ip4_addr.c
+ ${TOP}/lib/lwip/src/core/ipv4/ip4_frag.c
+ ${TOP}/lib/lwip/src/netif/ethernet.c
+ ${TOP}/lib/lwip/src/netif/slipif.c
+ ${TOP}/lib/lwip/src/apps/http/httpd.c
+ ${TOP}/lib/lwip/src/apps/http/fs.c
+ ${TOP}/lib/networking/dhserver.c
+ ${TOP}/lib/networking/dnserver.c
+ ${TOP}/lib/networking/rndis_reports.c
+ )
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ ${SRC_LWIP}
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ ${TOP}/lib/lwip/src/include
+ ${TOP}/lib/lwip/src/include/ipv4
+ ${TOP}/lib/lwip/src/include/lwip/apps
+ ${TOP}/lib/networking
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ PBUF_POOL_SIZE=2
+ TCP_WND=2*TCP_MSS
+ HTTPD_USE_CUSTOM_FSDATA=0
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/net_lwip_webserver/src/tusb_config.h b/examples/device/net_lwip_webserver/src/tusb_config.h
index b6d0e7a86..262d4ebce 100644
--- a/examples/device/net_lwip_webserver/src/tusb_config.h
+++ b/examples/device/net_lwip_webserver/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/uac2_headset/.skip.MCU_SAMD11 b/examples/device/uac2_headset/.skip.MCU_SAMD11
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/uac2_headset/.skip.MCU_SAMD11
diff --git a/examples/device/uac2_headset/.skip.MCU_SAME5X b/examples/device/uac2_headset/.skip.MCU_SAME5X
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/uac2_headset/.skip.MCU_SAME5X
diff --git a/examples/device/uac2_headset/.skip.MCU_SAMG b/examples/device/uac2_headset/.skip.MCU_SAMG
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/examples/device/uac2_headset/.skip.MCU_SAMG
diff --git a/examples/device/uac2_headset/CMakeLists.txt b/examples/device/uac2_headset/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/uac2_headset/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/uac2_headset/src/tusb_config.h b/examples/device/uac2_headset/src/tusb_config.h
index 2ecfd59f6..2ad76b7dc 100644
--- a/examples/device/uac2_headset/src/tusb_config.h
+++ b/examples/device/uac2_headset/src/tusb_config.h
@@ -46,7 +46,9 @@ extern "C" {
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
#endif
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
#ifndef CFG_TUSB_DEBUG
// Can be set during compilation i.e.: make LOG=<value for CFG_TUSB_DEBUG> BOARD=<bsp>
diff --git a/examples/device/usbtmc/CMakeLists.txt b/examples/device/usbtmc/CMakeLists.txt
new file mode 100644
index 000000000..9a4aa382b
--- /dev/null
+++ b/examples/device/usbtmc/CMakeLists.txt
@@ -0,0 +1,42 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usbtmc_app.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/usbtmc/src/tusb_config.h b/examples/device/usbtmc/src/tusb_config.h
index 603e67453..a192d0dbc 100644
--- a/examples/device/usbtmc/src/tusb_config.h
+++ b/examples/device/usbtmc/src/tusb_config.h
@@ -46,8 +46,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
diff --git a/examples/device/usbtmc/src/usb_descriptors.c b/examples/device/usbtmc/src/usb_descriptors.c
index 505456769..2336266b8 100644
--- a/examples/device/usbtmc/src/usb_descriptors.c
+++ b/examples/device/usbtmc/src/usb_descriptors.c
@@ -80,10 +80,11 @@ uint8_t const * tud_descriptor_device_cb(void)
TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x01, /* IN = */ 0x81, /* packet size = */USBTMCD_MAX_PACKET_SIZE)
#if CFG_TUD_USBTMC_ENABLE_INT_EP
-// Interrupt endpoint should be 2 bytes on a FS USB link
+// USBTMC Interrupt xfer always has length of 2, but we use epMaxSize=8 for
+// compatibility with mcus that only allow 8, 16, 32 or 64 for FS endpoints
# define TUD_USBTMC_DESC(_itfnum) \
TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \
- TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 2, /* bInterval = */16u )
+ TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x82, /* epMaxSize = */ 8, /* bInterval = */16u )
# define TUD_USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN + TUD_USBTMC_INT_DESCRIPTOR_LEN)
#else
diff --git a/examples/device/webusb_serial/CMakeLists.txt b/examples/device/webusb_serial/CMakeLists.txt
new file mode 100644
index 000000000..f4bf75c26
--- /dev/null
+++ b/examples/device/webusb_serial/CMakeLists.txt
@@ -0,0 +1,41 @@
+# use directory name for project id
+get_filename_component(PROJECT ${CMAKE_CURRENT_SOURCE_DIR} NAME)
+set(PROJECT ${BOARD}-${PROJECT})
+
+# TOP is absolute path to root directory of TinyUSB git repo
+set(TOP "../../..")
+get_filename_component(TOP "${TOP}" REALPATH)
+
+# Check for -DFAMILY=
+if(FAMILY STREQUAL "rp2040")
+ cmake_minimum_required(VERSION 3.12)
+ set(PICO_SDK_PATH ${TOP}/hw/mcu/raspberrypi/pico-sdk)
+ include(${PICO_SDK_PATH}/pico_sdk_init.cmake)
+ project(${PROJECT})
+ pico_sdk_init()
+ add_executable(${PROJECT})
+
+ include(${TOP}/hw/bsp/${FAMILY}/family.cmake)
+
+ # Example source
+ target_sources(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
+ )
+
+ # Example include
+ target_include_directories(${PROJECT} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ )
+
+ # Example defines
+ target_compile_definitions(${PROJECT} PUBLIC
+ CFG_TUSB_OS=OPT_OS_PICO
+ )
+
+ target_link_libraries(${PROJECT} pico_stdlib pico_fix_rp2040_usb_device_enumeration)
+ pico_add_extra_outputs(${PROJECT})
+
+else()
+ message(FATAL_ERROR "Invalid FAMILY specified")
+endif()
diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c
index 9309bbf6e..143a73374 100644
--- a/examples/device/webusb_serial/src/main.c
+++ b/examples/device/webusb_serial/src/main.c
@@ -151,52 +151,54 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
// nothing to with DATA & ACK stage
if (stage != CONTROL_STAGE_SETUP ) return true;
- switch (request->bRequest)
- {
- case VENDOR_REQUEST_WEBUSB:
- // match vendor request in BOS descriptor
- // Get landing page url
- return tud_control_xfer(rhport, request, (void*) &desc_url, desc_url.bLength);
-
- case VENDOR_REQUEST_MICROSOFT:
- if ( request->wIndex == 7 )
- {
- // Get Microsoft OS 2.0 compatible descriptor
- uint16_t total_len;
- memcpy(&total_len, desc_ms_os_20+8, 2);
+ if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_VENDOR) {
+ switch (request->bRequest)
+ {
+ case VENDOR_REQUEST_WEBUSB:
+ // match vendor request in BOS descriptor
+ // Get landing page url
+ return tud_control_xfer(rhport, request, (void*) &desc_url, desc_url.bLength);
- return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
- }else
- {
- return false;
- }
+ case VENDOR_REQUEST_MICROSOFT:
+ if ( request->wIndex == 7 )
+ {
+ // Get Microsoft OS 2.0 compatible descriptor
+ uint16_t total_len;
+ memcpy(&total_len, desc_ms_os_20+8, 2);
- case 0x22:
- // Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
- // connect and disconnect.
- web_serial_connected = (request->wValue != 0);
+ return tud_control_xfer(rhport, request, (void*) desc_ms_os_20, total_len);
+ }else
+ {
+ return false;
+ }
- // Always lit LED if connected
- if ( web_serial_connected )
- {
- board_led_write(true);
- blink_interval_ms = BLINK_ALWAYS_ON;
+ default:
+ return false;
+ }
+ } else if (
+ request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
+ request->bRequest == 0x22) {
+ // Webserial simulate the CDC_REQUEST_SET_CONTROL_LINE_STATE (0x22) to
+ // connect and disconnect.
+ web_serial_connected = (request->wValue != 0);
- tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
- }else
- {
- blink_interval_ms = BLINK_MOUNTED;
- }
+ // Always lit LED if connected
+ if ( web_serial_connected ) {
+ board_led_write(true);
+ blink_interval_ms = BLINK_ALWAYS_ON;
- // response with status OK
- return tud_control_status(rhport, request);
+ tud_vendor_write_str("\r\nTinyUSB WebUSB device example\r\n");
+ }else
+ {
+ blink_interval_ms = BLINK_MOUNTED;
+ }
- default:
- // stall unknown request
- return false;
+ // response with status OK
+ return tud_control_status(rhport, request);
}
- return true;
+ // stall unknown request
+ return false;
}
void webserial_task(void)
diff --git a/examples/device/webusb_serial/src/tusb_config.h b/examples/device/webusb_serial/src/tusb_config.h
index 48c9ddad6..26b81b389 100644
--- a/examples/device/webusb_serial/src/tusb_config.h
+++ b/examples/device/webusb_serial/src/tusb_config.h
@@ -64,8 +64,9 @@
#error "Incorrect RHPort configuration"
#endif
-// This example doesn't use an RTOS
+#ifndef CFG_TUSB_OS
#define CFG_TUSB_OS OPT_OS_NONE
+#endif
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0