summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhathach <[email protected]>2025-11-18 09:36:16 +0700
committerhathach <[email protected]>2025-11-18 09:36:16 +0700
commit98f7b0c7ba03fd770616195a6312e1bb65e5155f (patch)
tree6dce3fafc3794fd3cd1f13bd0cc04bfb84989e24 /examples
parentbeea882c6bcee352b5ff69446aef9fc43237bab0 (diff)
parent66c84528f67c0eedc23d25221500d820e702d93f (diff)
Merge branch 'master' into fork/HiFiPhile/dwc2_iso_incomp
Diffstat (limited to 'examples')
-rw-r--r--examples/build_system/cmake/toolchain/arm_clang.cmake2
-rw-r--r--examples/build_system/cmake/toolchain/arm_iar.cmake14
-rw-r--r--examples/build_system/cmake/toolchain/common.cmake23
-rw-r--r--examples/build_system/cmake/toolchain/cstat_sel_checks.txt247
-rw-r--r--examples/build_system/make/make.mk190
-rw-r--r--examples/build_system/make/rules.mk195
-rw-r--r--examples/device/audio_4_channel_mic/Makefile8
-rw-r--r--examples/device/audio_4_channel_mic/src/main.c55
-rw-r--r--examples/device/audio_4_channel_mic/src/tusb_config.h12
-rw-r--r--examples/device/audio_4_channel_mic/src/usb_descriptors.c24
-rw-r--r--examples/device/audio_4_channel_mic_freertos/Makefile8
-rw-r--r--examples/device/audio_4_channel_mic_freertos/skip.txt1
-rw-r--r--examples/device/audio_4_channel_mic_freertos/src/main.c44
-rw-r--r--examples/device/audio_4_channel_mic_freertos/src/tusb_config.h12
-rw-r--r--examples/device/audio_4_channel_mic_freertos/src/usb_descriptors.c20
-rw-r--r--examples/device/audio_test/Makefile8
-rw-r--r--examples/device/audio_test/src/main.c54
-rw-r--r--examples/device/audio_test/src/tusb_config.h11
-rw-r--r--examples/device/audio_test/src/usb_descriptors.c20
-rw-r--r--examples/device/audio_test_freertos/Makefile8
-rw-r--r--examples/device/audio_test_freertos/skip.txt1
-rw-r--r--examples/device/audio_test_freertos/src/main.c46
-rw-r--r--examples/device/audio_test_freertos/src/tusb_config.h11
-rw-r--r--examples/device/audio_test_freertos/src/usb_descriptors.c20
-rw-r--r--examples/device/audio_test_multi_rate/Makefile8
-rw-r--r--examples/device/audio_test_multi_rate/src/main.c375
-rw-r--r--examples/device/audio_test_multi_rate/src/tusb_config.h29
-rw-r--r--examples/device/audio_test_multi_rate/src/usb_descriptors.c101
-rw-r--r--examples/device/audio_test_multi_rate/src/usb_descriptors.h78
-rw-r--r--examples/device/board_test/Makefile8
-rw-r--r--examples/device/board_test/src/main.c4
-rw-r--r--examples/device/board_test/src/tusb_config.h6
-rw-r--r--examples/device/cdc_dual_ports/Makefile8
-rw-r--r--examples/device/cdc_dual_ports/src/main.c12
-rw-r--r--examples/device/cdc_dual_ports/src/tusb_config.h6
-rw-r--r--examples/device/cdc_dual_ports/src/usb_descriptors.c16
-rw-r--r--examples/device/cdc_msc/Makefile8
-rw-r--r--examples/device/cdc_msc/src/main.c52
-rw-r--r--examples/device/cdc_msc/src/msc_disk.c124
-rw-r--r--examples/device/cdc_msc/src/tusb_config.h6
-rw-r--r--examples/device/cdc_msc/src/usb_descriptors.c18
-rw-r--r--examples/device/cdc_msc_freertos/Makefile8
-rw-r--r--examples/device/cdc_msc_freertos/skip.txt1
-rw-r--r--examples/device/cdc_msc_freertos/src/main.c2
-rw-r--r--examples/device/cdc_msc_freertos/src/msc_disk.c39
-rw-r--r--examples/device/cdc_msc_freertos/src/tusb_config.h6
-rw-r--r--examples/device/cdc_msc_freertos/src/usb_descriptors.c18
-rw-r--r--examples/device/cdc_uac2/Makefile8
-rw-r--r--examples/device/cdc_uac2/src/cdc_app.c19
-rw-r--r--examples/device/cdc_uac2/src/common.h3
-rw-r--r--examples/device/cdc_uac2/src/main.c3
-rw-r--r--examples/device/cdc_uac2/src/tusb_config.h19
-rw-r--r--examples/device/cdc_uac2/src/uac2_app.c92
-rw-r--r--examples/device/cdc_uac2/src/usb_descriptors.c26
-rw-r--r--examples/device/cdc_uac2/src/usb_descriptors.h128
-rw-r--r--examples/device/dfu/Makefile8
-rw-r--r--examples/device/dfu/src/usb_descriptors.c18
-rw-r--r--examples/device/dfu_runtime/Makefile8
-rw-r--r--examples/device/dfu_runtime/src/main.c4
-rw-r--r--examples/device/dfu_runtime/src/usb_descriptors.c18
-rw-r--r--examples/device/dynamic_configuration/Makefile8
-rw-r--r--examples/device/dynamic_configuration/src/main.c56
-rw-r--r--examples/device/dynamic_configuration/src/msc_disk.c54
-rw-r--r--examples/device/dynamic_configuration/src/tusb_config.h6
-rw-r--r--examples/device/dynamic_configuration/src/usb_descriptors.c16
-rw-r--r--examples/device/hid_boot_interface/Makefile8
-rw-r--r--examples/device/hid_boot_interface/src/main.c147
-rw-r--r--examples/device/hid_boot_interface/src/tusb_config.h6
-rw-r--r--examples/device/hid_boot_interface/src/usb_descriptors.c118
-rw-r--r--examples/device/hid_composite/Makefile8
-rw-r--r--examples/device/hid_composite/src/main.c209
-rw-r--r--examples/device/hid_composite/src/tusb_config.h6
-rw-r--r--examples/device/hid_composite/src/usb_descriptors.c14
-rw-r--r--examples/device/hid_composite_freertos/Makefile8
-rw-r--r--examples/device/hid_composite_freertos/src/main.c2
-rw-r--r--examples/device/hid_composite_freertos/src/tusb_config.h6
-rw-r--r--examples/device/hid_composite_freertos/src/usb_descriptors.c14
-rw-r--r--examples/device/hid_generic_inout/Makefile8
-rw-r--r--examples/device/hid_generic_inout/src/tusb_config.h6
-rw-r--r--examples/device/hid_generic_inout/src/usb_descriptors.c10
-rw-r--r--examples/device/hid_multiple_interface/Makefile8
-rw-r--r--examples/device/hid_multiple_interface/src/tusb_config.h6
-rw-r--r--examples/device/hid_multiple_interface/src/usb_descriptors.c10
-rw-r--r--examples/device/midi_test/Makefile8
-rw-r--r--examples/device/midi_test/src/tusb_config.h6
-rw-r--r--examples/device/midi_test/src/usb_descriptors.c14
-rw-r--r--examples/device/midi_test_freertos/Makefile8
-rw-r--r--examples/device/midi_test_freertos/src/main.c2
-rw-r--r--examples/device/midi_test_freertos/src/tusb_config.h6
-rw-r--r--examples/device/midi_test_freertos/src/usb_descriptors.c14
-rw-r--r--examples/device/msc_dual_lun/Makefile8
-rw-r--r--examples/device/msc_dual_lun/src/msc_disk_dual.c10
-rw-r--r--examples/device/msc_dual_lun/src/tusb_config.h6
-rw-r--r--examples/device/msc_dual_lun/src/usb_descriptors.c14
-rw-r--r--examples/device/mtp/Makefile8
-rw-r--r--examples/device/mtp/src/mtp_fs_example.c86
-rw-r--r--examples/device/mtp/src/tusb_config.h6
-rw-r--r--examples/device/mtp/src/usb_descriptors.c16
-rw-r--r--examples/device/net_lwip_webserver/Makefile7
-rw-r--r--examples/device/net_lwip_webserver/skip.txt2
-rw-r--r--examples/device/net_lwip_webserver/src/arch/cc.h6
-rw-r--r--examples/device/net_lwip_webserver/src/lwipopts.h4
-rw-r--r--examples/device/net_lwip_webserver/src/main.c3
-rw-r--r--examples/device/net_lwip_webserver/src/tusb_config.h8
-rw-r--r--examples/device/net_lwip_webserver/src/usb_descriptors.c249
-rw-r--r--examples/device/uac2_headset/Makefile8
-rw-r--r--examples/device/uac2_headset/src/main.c332
-rw-r--r--examples/device/uac2_headset/src/tusb_config.h51
-rw-r--r--examples/device/uac2_headset/src/usb_descriptors.c103
-rw-r--r--examples/device/uac2_headset/src/usb_descriptors.h233
-rw-r--r--examples/device/uac2_speaker_fb/CMakeLists.txt1
-rw-r--r--examples/device/uac2_speaker_fb/Makefile8
-rw-r--r--examples/device/uac2_speaker_fb/src/common_types.h2
-rw-r--r--examples/device/uac2_speaker_fb/src/main.c388
-rw-r--r--examples/device/uac2_speaker_fb/src/quirk_os_guessing.c90
-rw-r--r--examples/device/uac2_speaker_fb/src/quirk_os_guessing.h75
-rw-r--r--examples/device/uac2_speaker_fb/src/tusb_config.h53
-rw-r--r--examples/device/uac2_speaker_fb/src/usb_descriptors.c178
-rw-r--r--examples/device/uac2_speaker_fb/src/usb_descriptors.h152
-rw-r--r--examples/device/usbtmc/Makefile8
-rw-r--r--examples/device/usbtmc/src/main.c1
-rw-r--r--examples/device/usbtmc/src/usb_descriptors.c35
-rw-r--r--examples/device/usbtmc/src/usbtmc_app.c1
-rw-r--r--examples/device/video_capture/Makefile8
-rw-r--r--examples/device/video_capture/skip.txt1
-rw-r--r--examples/device/video_capture/src/main.c85
-rw-r--r--examples/device/video_capture/src/tusb_config.h7
-rw-r--r--examples/device/video_capture/src/usb_descriptors.c10
-rw-r--r--examples/device/video_capture_2ch/Makefile8
-rw-r--r--examples/device/video_capture_2ch/skip.txt1
-rw-r--r--examples/device/video_capture_2ch/src/main.c11
-rw-r--r--examples/device/video_capture_2ch/src/tusb_config.h6
-rw-r--r--examples/device/video_capture_2ch/src/usb_descriptors.c10
-rw-r--r--examples/device/webusb_serial/Makefile8
-rw-r--r--examples/device/webusb_serial/src/main.c2
-rw-r--r--examples/device/webusb_serial/src/tusb_config.h6
-rw-r--r--examples/device/webusb_serial/src/usb_descriptors.c10
-rw-r--r--examples/dual/host_hid_to_device_cdc/Makefile8
-rw-r--r--examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c16
-rw-r--r--examples/dual/host_info_to_device_cdc/CMakeLists.txt7
-rw-r--r--examples/dual/host_info_to_device_cdc/Makefile8
-rw-r--r--examples/dual/host_info_to_device_cdc/only.txt1
-rw-r--r--examples/dual/host_info_to_device_cdc/src/CMakeLists.txt4
-rw-r--r--examples/dual/host_info_to_device_cdc/src/main.c156
-rw-r--r--examples/dual/host_info_to_device_cdc/src/tusb_config.h2
-rw-r--r--examples/dual/host_info_to_device_cdc/src/usb_descriptors.c16
-rw-r--r--examples/host/bare_api/Makefile8
-rw-r--r--examples/host/cdc_msc_hid/Makefile8
-rw-r--r--examples/host/cdc_msc_hid/src/app.h34
-rw-r--r--examples/host/cdc_msc_hid/src/cdc_app.c3
-rw-r--r--examples/host/cdc_msc_hid/src/hid_app.c2
-rw-r--r--examples/host/cdc_msc_hid/src/main.c3
-rw-r--r--examples/host/cdc_msc_hid/src/msc_app.c1
-rw-r--r--examples/host/cdc_msc_hid/src/tusb_config.h6
-rw-r--r--examples/host/cdc_msc_hid_freertos/Makefile8
-rw-r--r--examples/host/cdc_msc_hid_freertos/only.txt2
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/app.h35
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/cdc_app.c9
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/hid_app.c4
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/main.c6
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/msc_app.c3
-rw-r--r--examples/host/cdc_msc_hid_freertos/src/tusb_config.h6
-rw-r--r--examples/host/device_info/Makefile8
-rw-r--r--examples/host/device_info/only.txt4
-rw-r--r--examples/host/device_info/src/main.c4
-rw-r--r--examples/host/hid_controller/Makefile8
-rw-r--r--examples/host/hid_controller/src/app.h33
-rw-r--r--examples/host/hid_controller/src/hid_app.c1
-rw-r--r--examples/host/hid_controller/src/main.c20
-rw-r--r--examples/host/hid_controller/src/tusb_config.h6
-rw-r--r--examples/host/midi_rx/Makefile8
-rw-r--r--examples/host/msc_file_explorer/CMakeLists.txt6
-rw-r--r--examples/host/msc_file_explorer/Makefile7
-rw-r--r--examples/host/msc_file_explorer/src/main.c1
-rw-r--r--examples/host/msc_file_explorer/src/msc_app.h1
-rw-r--r--examples/host/msc_file_explorer/src/tusb_config.h6
-rw-r--r--examples/typec/power_delivery/Makefile12
-rw-r--r--examples/typec/power_delivery/src/tusb_config.h6
178 files changed, 3381 insertions, 2544 deletions
diff --git a/examples/build_system/cmake/toolchain/arm_clang.cmake b/examples/build_system/cmake/toolchain/arm_clang.cmake
index fe3c2b453..dba637367 100644
--- a/examples/build_system/cmake/toolchain/arm_clang.cmake
+++ b/examples/build_system/cmake/toolchain/arm_clang.cmake
@@ -7,6 +7,8 @@ if (NOT DEFINED CMAKE_CXX_COMPILER)
endif ()
set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
+set(TOOLCHAIN_ASM_FLAGS "-x assembler-with-cpp")
+
find_program(CMAKE_SIZE llvm-size)
find_program(CMAKE_OBJCOPY llvm-objcopy)
find_program(CMAKE_OBJDUMP llvm-objdump)
diff --git a/examples/build_system/cmake/toolchain/arm_iar.cmake b/examples/build_system/cmake/toolchain/arm_iar.cmake
index 083815715..0b7e0b585 100644
--- a/examples/build_system/cmake/toolchain/arm_iar.cmake
+++ b/examples/build_system/cmake/toolchain/arm_iar.cmake
@@ -14,4 +14,18 @@ find_program(CMAKE_SIZE size)
find_program(CMAKE_OBJCOPY ielftool)
find_program(CMAKE_OBJDUMP iefdumparm)
+find_program(CMAKE_IAR_CSTAT icstat)
+find_program(CMAKE_IAR_CHECKS ichecks)
+find_program(CMAKE_IAR_REPORT ireport)
+
+if (IAR_CSTAT)
+cmake_minimum_required(VERSION 4.1)
+set(CMAKE_C_ICSTAT ${CMAKE_IAR_CSTAT}
+ --checks=${CMAKE_CURRENT_LIST_DIR}/cstat_sel_checks.txt
+ --db=${CMAKE_BINARY_DIR}/cstat.db
+ --sarif_dir=${CMAKE_BINARY_DIR}/cstat_sarif
+ --exclude ${TOP}/hw/mcu --exclude ${TOP}/lib
+ )
+endif ()
+
include(${CMAKE_CURRENT_LIST_DIR}/common.cmake)
diff --git a/examples/build_system/cmake/toolchain/common.cmake b/examples/build_system/cmake/toolchain/common.cmake
index 4c181137b..14449b01d 100644
--- a/examples/build_system/cmake/toolchain/common.cmake
+++ b/examples/build_system/cmake/toolchain/common.cmake
@@ -20,11 +20,11 @@ include(${CMAKE_CURRENT_LIST_DIR}/../cpu/${CMAKE_SYSTEM_CPU}.cmake)
# ----------------------------------------------------------------------------
# Compile flags
# ----------------------------------------------------------------------------
-if (TOOLCHAIN STREQUAL "gcc")
+if (TOOLCHAIN STREQUAL "gcc" OR TOOLCHAIN STREQUAL "clang")
list(APPEND TOOLCHAIN_COMMON_FLAGS
-fdata-sections
-ffunction-sections
- -fsingle-precision-constant
+# -fsingle-precision-constant # not supported by clang
-fno-strict-aliasing
)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
@@ -32,24 +32,10 @@ if (TOOLCHAIN STREQUAL "gcc")
-Wl,--gc-sections
-Wl,--cref
)
-
elseif (TOOLCHAIN STREQUAL "iar")
- #list(APPEND TOOLCHAIN_COMMON_FLAGS)
list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
--diag_suppress=Li065
)
-
-elseif (TOOLCHAIN STREQUAL "clang")
- list(APPEND TOOLCHAIN_COMMON_FLAGS
- -fdata-sections
- -ffunction-sections
- -fno-strict-aliasing
- )
- list(APPEND TOOLCHAIN_EXE_LINKER_FLAGS
- -Wl,--print-memory-usage
- -Wl,--gc-sections
- -Wl,--cref
- )
endif ()
# join the toolchain flags into a single string
@@ -61,5 +47,10 @@ foreach (LANG IN ITEMS C CXX ASM)
#set(CMAKE_${LANG}_FLAGS_DEBUG_INIT "-O0")
endforeach ()
+# Assembler
+if (DEFINED TOOLCHAIN_ASM_FLAGS)
+ set(CMAKE_ASM_FLAGS_INIT "${CMAKE_ASM_FLAGS_INIT} ${TOOLCHAIN_ASM_FLAGS}")
+endif ()
+
# Linker
list(JOIN TOOLCHAIN_EXE_LINKER_FLAGS " " CMAKE_EXE_LINKER_FLAGS_INIT)
diff --git a/examples/build_system/cmake/toolchain/cstat_sel_checks.txt b/examples/build_system/cmake/toolchain/cstat_sel_checks.txt
new file mode 100644
index 000000000..b7efba4ad
--- /dev/null
+++ b/examples/build_system/cmake/toolchain/cstat_sel_checks.txt
@@ -0,0 +1,247 @@
+# IAR C-STAT Checks Manifest Handler V2.7.5.562
+#
+MISRAC2012-Dir-4.3
+MISRAC2012-Dir-4.7_c
+MISRAC2012-Dir-4.10
+MISRAC2012-Dir-4.11_a
+MISRAC2012-Dir-4.11_b
+MISRAC2012-Dir-4.11_c
+MISRAC2012-Dir-4.11_d
+MISRAC2012-Dir-4.11_e
+MISRAC2012-Dir-4.11_f
+MISRAC2012-Dir-4.11_g
+MISRAC2012-Dir-4.11_h
+MISRAC2012-Dir-4.11_i
+MISRAC2012-Dir-4.12
+MISRAC2012-Dir-4.14_a
+MISRAC2012-Dir-4.14_b
+MISRAC2012-Dir-4.14_c
+MISRAC2012-Dir-4.14_d
+MISRAC2012-Dir-4.14_e
+MISRAC2012-Dir-4.14_f
+MISRAC2012-Dir-4.14_g
+MISRAC2012-Dir-4.14_h
+MISRAC2012-Dir-4.14_i
+MISRAC2012-Dir-4.14_j
+MISRAC2012-Dir-4.14_l
+MISRAC2012-Dir-4.14_m
+MISRAC2012-Dir-4.15
+MISRAC2012-Rule-1.3_a
+MISRAC2012-Rule-1.3_b
+MISRAC2012-Rule-1.3_c
+MISRAC2012-Rule-1.3_d
+MISRAC2012-Rule-1.3_e
+MISRAC2012-Rule-1.3_f
+MISRAC2012-Rule-1.3_g
+MISRAC2012-Rule-1.3_h
+MISRAC2012-Rule-1.3_i
+MISRAC2012-Rule-1.3_j
+MISRAC2012-Rule-1.3_k
+MISRAC2012-Rule-1.3_l
+MISRAC2012-Rule-1.3_m
+MISRAC2012-Rule-1.3_n
+MISRAC2012-Rule-1.3_o
+MISRAC2012-Rule-1.3_p
+MISRAC2012-Rule-1.3_q
+MISRAC2012-Rule-1.3_r
+MISRAC2012-Rule-1.3_s
+MISRAC2012-Rule-1.3_t
+MISRAC2012-Rule-1.3_u
+MISRAC2012-Rule-1.3_v
+MISRAC2012-Rule-1.4
+MISRAC2012-Rule-1.5_b
+MISRAC2012-Rule-1.5_c
+MISRAC2012-Rule-1.5_d
+MISRAC2012-Rule-1.5_e
+MISRAC2012-Rule-1.5_f
+MISRAC2012-Rule-1.5_g
+MISRAC2012-Rule-2.1_a
+MISRAC2012-Rule-2.1_b
+MISRAC2012-Rule-2.2_a
+MISRAC2012-Rule-2.2_b
+MISRAC2012-Rule-2.2_c
+MISRAC2012-Rule-3.1
+MISRAC2012-Rule-3.2
+MISRAC2012-Rule-5.1
+MISRAC2012-Rule-5.2_c89
+MISRAC2012-Rule-5.2_c99
+MISRAC2012-Rule-5.3_c89
+MISRAC2012-Rule-5.3_c99
+MISRAC2012-Rule-5.4_c89
+MISRAC2012-Rule-5.4_c99
+MISRAC2012-Rule-5.5_c89
+MISRAC2012-Rule-5.5_c99
+MISRAC2012-Rule-5.6
+MISRAC2012-Rule-5.7
+MISRAC2012-Rule-5.8
+MISRAC2012-Rule-6.1
+MISRAC2012-Rule-6.2
+MISRAC2012-Rule-6.3
+MISRAC2012-Rule-7.1
+MISRAC2012-Rule-7.2
+MISRAC2012-Rule-7.3
+MISRAC2012-Rule-7.4_a
+MISRAC2012-Rule-7.4_b
+MISRAC2012-Rule-7.5
+MISRAC2012-Rule-7.6
+MISRAC2012-Rule-8.1
+MISRAC2012-Rule-8.2_a
+MISRAC2012-Rule-8.2_b
+MISRAC2012-Rule-8.3
+MISRAC2012-Rule-8.4
+MISRAC2012-Rule-8.5_a
+MISRAC2012-Rule-8.5_b
+MISRAC2012-Rule-8.10
+MISRAC2012-Rule-8.12
+MISRAC2012-Rule-8.14
+MISRAC2012-Rule-8.15
+MISRAC2012-Rule-9.1_a
+MISRAC2012-Rule-9.1_b
+MISRAC2012-Rule-9.1_d
+MISRAC2012-Rule-9.1_e
+MISRAC2012-Rule-9.2
+MISRAC2012-Rule-9.3
+MISRAC2012-Rule-9.4
+MISRAC2012-Rule-9.5_a
+MISRAC2012-Rule-9.5_b
+MISRAC2012-Rule-9.6
+MISRAC2012-Rule-9.7
+MISRAC2012-Rule-10.1_R2
+MISRAC2012-Rule-10.1_R3
+MISRAC2012-Rule-10.1_R4
+MISRAC2012-Rule-10.1_R5
+MISRAC2012-Rule-10.1_R6
+MISRAC2012-Rule-10.1_R7
+MISRAC2012-Rule-10.1_R8
+MISRAC2012-Rule-10.1_R10
+MISRAC2012-Rule-10.2
+MISRAC2012-Rule-10.3
+MISRAC2012-Rule-10.4_a
+MISRAC2012-Rule-10.4_b
+MISRAC2012-Rule-10.6
+MISRAC2012-Rule-10.7
+MISRAC2012-Rule-10.8
+MISRAC2012-Rule-11.1
+MISRAC2012-Rule-11.2
+MISRAC2012-Rule-11.3
+MISRAC2012-Rule-11.6
+MISRAC2012-Rule-11.7
+MISRAC2012-Rule-11.8
+MISRAC2012-Rule-11.9
+MISRAC2012-Rule-11.10
+MISRAC2012-Rule-12.2
+MISRAC2012-Rule-12.5
+MISRAC2012-Rule-12.6
+MISRAC2012-Rule-13.1
+MISRAC2012-Rule-13.2_a
+MISRAC2012-Rule-13.2_b
+MISRAC2012-Rule-13.2_c
+MISRAC2012-Rule-13.5
+MISRAC2012-Rule-13.6
+MISRAC2012-Rule-14.1_a
+MISRAC2012-Rule-14.1_b
+MISRAC2012-Rule-14.2
+MISRAC2012-Rule-14.3_a
+MISRAC2012-Rule-14.3_b
+MISRAC2012-Rule-14.4_a
+MISRAC2012-Rule-14.4_b
+MISRAC2012-Rule-14.4_c
+MISRAC2012-Rule-14.4_d
+MISRAC2012-Rule-15.2
+MISRAC2012-Rule-15.3
+MISRAC2012-Rule-15.6_a
+MISRAC2012-Rule-15.6_b
+MISRAC2012-Rule-15.6_c
+MISRAC2012-Rule-15.6_d
+MISRAC2012-Rule-15.6_e
+MISRAC2012-Rule-15.7
+MISRAC2012-Rule-16.1
+MISRAC2012-Rule-16.2
+MISRAC2012-Rule-16.3
+MISRAC2012-Rule-16.4
+MISRAC2012-Rule-16.5
+MISRAC2012-Rule-16.6
+MISRAC2012-Rule-16.7
+MISRAC2012-Rule-17.1
+MISRAC2012-Rule-17.2_a
+MISRAC2012-Rule-17.2_b
+MISRAC2012-Rule-17.3
+MISRAC2012-Rule-17.4
+MISRAC2012-Rule-17.5
+MISRAC2012-Rule-17.6
+MISRAC2012-Rule-17.7
+MISRAC2012-Rule-17.13
+MISRAC2012-Rule-18.1_a
+MISRAC2012-Rule-18.1_b
+MISRAC2012-Rule-18.1_c
+MISRAC2012-Rule-18.1_d
+MISRAC2012-Rule-18.2
+MISRAC2012-Rule-18.3
+MISRAC2012-Rule-18.4
+MISRAC2012-Rule-18.6_a
+MISRAC2012-Rule-18.6_b
+MISRAC2012-Rule-18.6_c
+MISRAC2012-Rule-18.6_d
+MISRAC2012-Rule-18.7
+MISRAC2012-Rule-18.8
+MISRAC2012-Rule-18.9
+MISRAC2012-Rule-18.10
+MISRAC2012-Rule-19.1
+MISRAC2012-Rule-20.2
+MISRAC2012-Rule-20.4_c89
+MISRAC2012-Rule-20.4_c99
+MISRAC2012-Rule-20.6_a
+MISRAC2012-Rule-20.6_b
+MISRAC2012-Rule-20.7
+MISRAC2012-Rule-21.1
+MISRAC2012-Rule-21.2
+MISRAC2012-Rule-21.3
+MISRAC2012-Rule-21.4
+MISRAC2012-Rule-21.5
+MISRAC2012-Rule-21.6
+MISRAC2012-Rule-21.7
+MISRAC2012-Rule-21.8
+MISRAC2012-Rule-21.9
+MISRAC2012-Rule-21.10
+MISRAC2012-Rule-21.12_a
+MISRAC2012-Rule-21.12_b
+MISRAC2012-Rule-21.12_c
+MISRAC2012-Rule-21.13
+MISRAC2012-Rule-21.14
+MISRAC2012-Rule-21.15
+MISRAC2012-Rule-21.16
+MISRAC2012-Rule-21.17_a
+MISRAC2012-Rule-21.17_b
+MISRAC2012-Rule-21.17_c
+MISRAC2012-Rule-21.17_d
+MISRAC2012-Rule-21.17_e
+MISRAC2012-Rule-21.17_f
+MISRAC2012-Rule-21.18_a
+MISRAC2012-Rule-21.18_b
+MISRAC2012-Rule-21.19_a
+MISRAC2012-Rule-21.19_b
+MISRAC2012-Rule-21.20
+MISRAC2012-Rule-21.21
+MISRAC2012-Rule-21.22
+MISRAC2012-Rule-21.23
+MISRAC2012-Rule-21.24
+MISRAC2012-Rule-21.25
+MISRAC2012-Rule-22.1_a
+MISRAC2012-Rule-22.1_b
+MISRAC2012-Rule-22.2_a
+MISRAC2012-Rule-22.2_b
+MISRAC2012-Rule-22.2_c
+MISRAC2012-Rule-22.3
+MISRAC2012-Rule-22.4
+MISRAC2012-Rule-22.5_a
+MISRAC2012-Rule-22.5_b
+MISRAC2012-Rule-22.6
+MISRAC2012-Rule-22.7_a
+MISRAC2012-Rule-22.7_b
+MISRAC2012-Rule-22.8
+MISRAC2012-Rule-22.9
+MISRAC2012-Rule-22.10
+MISRAC2012-Rule-23.2
+MISRAC2012-Rule-23.4
+MISRAC2012-Rule-23.6
+MISRAC2012-Rule-23.8
diff --git a/examples/build_system/make/make.mk b/examples/build_system/make/make.mk
deleted file mode 100644
index 4f5d3242e..000000000
--- a/examples/build_system/make/make.mk
+++ /dev/null
@@ -1,190 +0,0 @@
-# ---------------------------------------
-# Common make definition for all examples
-# ---------------------------------------
-
-# upper helper function
-to_upper = $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,$(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,$(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,$(subst z,Z,$(subst -,_,$(1))))))))))))))))))))))))))))
-
-#-------------------------------------------------------------
-# Toolchain
-# Can be changed via TOOLCHAIN=gcc|iar or CC=arm-none-eabi-gcc|iccarm|clang
-#-------------------------------------------------------------
-ifneq (,$(findstring clang,$(CC)))
- TOOLCHAIN = clang
-else ifneq (,$(findstring iccarm,$(CC)))
- TOOLCHAIN = iar
-else ifneq (,$(findstring gcc,$(CC)))
- TOOLCHAIN = gcc
-endif
-
-# Default to GCC
-ifndef TOOLCHAIN
- TOOLCHAIN = gcc
-endif
-
-#-------------- TOP and CURRENT_PATH ------------
-
-# Set TOP to be the path to get from the current directory (where make was invoked) to the top of the tree.
-# $(lastword $(MAKEFILE_LIST)) returns the name of this makefile relative to where make was invoked.
-THIS_MAKEFILE := $(lastword $(MAKEFILE_LIST))
-
-# strip off /examples/build_system/make to get for example ../../..
-# and Set TOP to an absolute path
-TOP = $(abspath $(subst make.mk,../../..,$(THIS_MAKEFILE)))
-
-# Set CURRENT_PATH to the relative path from TOP to the current directory, ie examples/device/cdc_msc_freertos
-CURRENT_PATH = $(subst $(TOP)/,,$(abspath .))
-
-#-------------- Linux/Windows ------------
-
-# Detect whether shell style is windows or not
-# https://stackoverflow.com/questions/714100/os-detecting-makefile/52062069#52062069
-ifeq '$(findstring ;,$(PATH))' ';'
-# PATH contains semicolon - so we're definitely on Windows.
-CMDEXE := 1
-
-# makefile shell commands should use syntax for DOS CMD, not unix sh
-# Force DOS command shell on Windows.
-SHELL := cmd.exe
-endif
-
-ifeq ($(CMDEXE),1)
- CP = copy
- RM = del
- MKDIR = mkdir
- PYTHON = python
-else
- CP = cp
- RM = rm
- MKDIR = mkdir
- PYTHON = python3
-endif
-
-
-# Build directory
-BUILD := _build/$(BOARD)
-
-PROJECT := $(notdir $(CURDIR))
-BIN := $(TOP)/_bin/$(BOARD)/$(notdir $(CURDIR))
-
-#-------------------------------------------------------------
-# Board / Family
-#-------------------------------------------------------------
-
-# Board without family
-ifneq ($(wildcard $(TOP)/hw/bsp/$(BOARD)/board.mk),)
- BOARD_PATH := hw/bsp/$(BOARD)
- FAMILY :=
-endif
-
-# Board within family
-ifeq ($(BOARD_PATH),)
- BOARD_PATH := $(subst $(TOP)/,,$(wildcard $(TOP)/hw/bsp/*/boards/$(BOARD)))
- FAMILY := $(word 3, $(subst /, ,$(BOARD_PATH)))
- FAMILY_PATH = hw/bsp/$(FAMILY)
-endif
-
-ifeq ($(BOARD_PATH),)
- $(info You must provide a BOARD parameter with 'BOARD=')
- $(error Invalid BOARD specified)
-endif
-
-ifeq ($(FAMILY),)
- include $(TOP)/hw/bsp/$(BOARD)/board.mk
-else
- # Include Family and Board specific defs
- include $(TOP)/$(FAMILY_PATH)/family.mk
- SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FAMILY_PATH)/*.c))
-endif
-
-#-------------------------------------------------------------
-# Source files and compiler flags
-#-------------------------------------------------------------
-# tinyusb makefile
-include $(TOP)/src/tinyusb.mk
-SRC_C += $(TINYUSB_SRC_C)
-
-# Include all source C in family & board folder
-SRC_C += hw/bsp/board.c
-SRC_C += $(subst $(TOP)/,,$(wildcard $(TOP)/$(BOARD_PATH)/*.c))
-
-INC += \
- $(TOP)/$(FAMILY_PATH) \
- $(TOP)/src \
-
-BOARD_UPPER = $(call to_upper,$(BOARD))
-CFLAGS += -DBOARD_$(BOARD_UPPER)
-
-ifdef CFLAGS_CLI
- CFLAGS += $(CFLAGS_CLI)
-endif
-
-# use max3421 as host controller
-ifeq (${MAX3421_HOST},1)
- SRC_C += src/portable/analog/max3421/hcd_max3421.c
- CFLAGS += -DCFG_TUH_MAX3421=1
-endif
-
-# Log level is mapped to TUSB DEBUG option
-ifneq ($(LOG),)
- CFLAGS += -DCFG_TUSB_DEBUG=$(LOG)
-endif
-
-# Logger: default is uart, can be set to rtt or swo
-ifeq ($(LOGGER),rtt)
- CFLAGS += -DLOGGER_RTT
- #CFLAGS += -DSEGGER_RTT_MODE_DEFAULT=SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL
- INC += $(TOP)/lib/SEGGER_RTT/RTT
- SRC_C += lib/SEGGER_RTT/RTT/SEGGER_RTT.c
-endif
-ifeq ($(LOGGER),swo)
- CFLAGS += -DLOGGER_SWO
-else
- CFLAGS += -DLOGGER_UART
-endif
-
-# CPU specific flags
-ifdef CPU_CORE
- include ${TOP}/examples/build_system/make/cpu/$(CPU_CORE).mk
-endif
-
-# toolchain specific
-include ${TOP}/examples/build_system/make/toolchain/arm_$(TOOLCHAIN).mk
-
-#---------------------- FreeRTOS -----------------------
-FREERTOS_SRC = lib/FreeRTOS-Kernel
-FREERTOS_PORTABLE_PATH = $(FREERTOS_SRC)/portable/$(if $(findstring iar,$(TOOLCHAIN)),IAR,GCC)
-
-ifeq ($(RTOS),freertos)
- SRC_C += \
- $(FREERTOS_SRC)/list.c \
- $(FREERTOS_SRC)/queue.c \
- $(FREERTOS_SRC)/tasks.c \
- $(FREERTOS_SRC)/timers.c \
- $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.c))
-
- SRC_S += $(subst $(TOP)/,,$(wildcard $(TOP)/$(FREERTOS_PORTABLE_SRC)/*.s))
- INC += \
- $(TOP)/hw/bsp/$(FAMILY)/FreeRTOSConfig \
- $(TOP)/$(FREERTOS_SRC)/include \
- $(TOP)/$(FREERTOS_PORTABLE_SRC)
-
- CFLAGS += -DCFG_TUSB_OS=OPT_OS_FREERTOS
-
- # Suppress FreeRTOSConfig.h warnings
- CFLAGS_GCC += -Wno-error=redundant-decls
-
- # Suppress FreeRTOS source warnings
- CFLAGS_GCC += -Wno-error=cast-qual
-
- # FreeRTOS (lto + Os) linker issue
- LDFLAGS_GCC += -Wl,--undefined=vTaskSwitchContext
-endif
-
-#---------------- Helper ----------------
-check_defined = \
- $(strip $(foreach 1,$1, \
- $(call __check_defined,$1,$(strip $(value 2)))))
-__check_defined = \
- $(if $(value $1),, \
- $(error Undefined make flag: $1$(if $2, ($2))))
diff --git a/examples/build_system/make/rules.mk b/examples/build_system/make/rules.mk
deleted file mode 100644
index 86de17b6c..000000000
--- a/examples/build_system/make/rules.mk
+++ /dev/null
@@ -1,195 +0,0 @@
-# ---------------------------------------
-# Common make rules for all examples
-# ---------------------------------------
-
-# Set all as default goal
-.DEFAULT_GOAL := all
-
-# ---------------- GNU Make Start -----------------------
-# ESP32-Sx and RP2040 has its own CMake build system
-ifeq (,$(findstring $(FAMILY),espressif rp2040))
-
-# ---------------------------------------
-# Rules
-# ---------------------------------------
-
-all: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex size
-
-uf2: $(BUILD)/$(PROJECT).uf2
-
-# We set vpath to point to the top of the tree so that the source files
-# can be located. By following this scheme, it allows a single build rule
-# to be used to compile all .c files.
-vpath %.c . $(TOP)
-vpath %.s . $(TOP)
-vpath %.S . $(TOP)
-
-include ${TOP}/examples/build_system/make/toolchain/$(TOOLCHAIN)_rules.mk
-
-# ---------------------------------------
-# Compiler Flags
-# ---------------------------------------
-
-CFLAGS += $(addprefix -I,$(INC))
-
-# Verbose mode
-ifeq ("$(V)","1")
-$(info CFLAGS $(CFLAGS) ) $(info )
-$(info LDFLAGS $(LDFLAGS)) $(info )
-$(info ASFLAGS $(ASFLAGS)) $(info )
-endif
-
-
-OBJ_DIRS = $(sort $(dir $(OBJ)))
-$(OBJ): | $(OBJ_DIRS)
-$(OBJ_DIRS):
-ifeq ($(CMDEXE),1)
- -@$(MKDIR) $(subst /,\,$@)
-else
- @$(MKDIR) -p $@
-endif
-
-# UF2 generation, iMXRT need to strip to text only before conversion
-ifneq ($(FAMILY),imxrt)
-$(BUILD)/$(PROJECT).uf2: $(BUILD)/$(PROJECT).hex
- @echo CREATE $@
- $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f $(UF2_FAMILY_ID) -c -o $@ $^
-endif
-
-copy-artifact: $(BUILD)/$(PROJECT).bin $(BUILD)/$(PROJECT).hex $(BUILD)/$(PROJECT).uf2
-
-endif
-# ---------------- GNU Make End -----------------------
-
-.PHONY: clean
-clean:
-ifeq ($(CMDEXE),1)
- rd /S /Q $(subst /,\,$(BUILD))
-else
- $(RM) -rf $(BUILD)
-endif
-
-# get depenecies
-.PHONY: get-deps
-get-deps:
- $(PYTHON) $(TOP)/tools/get_deps.py ${FAMILY}
-
-.PHONY: size
-size: $(BUILD)/$(PROJECT).elf
- -@echo ''
- @$(SIZE) $<
- -@echo ''
-
-# linkermap must be install previously at https://github.com/hathach/linkermap
-linkermap: $(BUILD)/$(PROJECT).elf
- @linkermap -v $<.map
-
-# ---------------------------------------
-# Flash Targets
-# ---------------------------------------
-
-# --------------- Jlink -----------------
-ifeq ($(OS),Windows_NT)
- JLINKEXE = JLink.exe
-else
- JLINKEXE = JLinkExe
-endif
-
-# Jlink Interface
-JLINK_IF ?= swd
-
-# Jlink script
-$(BUILD)/$(BOARD).jlink: $(BUILD)/$(PROJECT).hex
- @echo halt > $@
- @echo loadfile $^ >> $@
- @echo r >> $@
- @echo go >> $@
- @echo exit >> $@
-
-# Flash using jlink
-flash-jlink: $(BUILD)/$(BOARD).jlink
- $(JLINKEXE) -device $(JLINK_DEVICE) -if $(JLINK_IF) -JTAGConf -1,-1 -speed auto -CommandFile $<
-
-# --------------- stm32 cube programmer -----------------
-# Flash STM32 MCU using stlink with STM32 Cube Programmer CLI
-flash-stlink: $(BUILD)/$(PROJECT).elf
- STM32_Programmer_CLI --connect port=swd --write $< --go
-
-# --------------- xfel -----------------
-$(BUILD)/$(PROJECT)-sunxi.bin: $(BUILD)/$(PROJECT).bin
- $(PYTHON) $(TOP)/tools/mksunxi.py $< $@
-
-flash-xfel: $(BUILD)/$(PROJECT)-sunxi.bin
- xfel spinor write 0 $<
- xfel reset
-
-# --------------- pyocd -----------------
-PYOCD_OPTION ?=
-flash-pyocd: $(BUILD)/$(PROJECT).hex
- pyocd flash -t $(PYOCD_TARGET) $(PYOCD_OPTION) $<
- #pyocd reset -t $(PYOCD_TARGET)
-
-# --------------- openocd -----------------
-OPENOCD_OPTION ?=
-flash-openocd: $(BUILD)/$(PROJECT).elf
- openocd $(OPENOCD_OPTION) -c "program $< verify reset exit"
-
-# --------------- openocd-wch -----------------
-# wch-linke is not supported yet in official openOCD yet. We need to either use
-# 1. download openocd as part of mounriver studio http://www.mounriver.com/download or
-# 2. compiled from https://github.com/hathach/riscv-openocd-wch or
-# https://github.com/dragonlock2/miscboards/blob/main/wch/SDK/riscv-openocd.tar.xz
-# with ./configure --disable-werror --enable-wlinke --enable-ch347=no
-OPENOCD_WCH ?= /home/${USER}/app/riscv-openocd-wch/src/openocd
-OPENOCD_WCH_OPTION ?=
-flash-openocd-wch: $(BUILD)/$(PROJECT).elf
- $(OPENOCD_WCH) $(OPENOCD_WCH_OPTION) -c init -c halt -c "flash write_image $<" -c reset -c exit
-
-# --------------- wlink-rs -----------------
-# flash with https://github.com/ch32-rs/wlink
-WLINK_RS ?= wlink
-flash-wlink-rs: $(BUILD)/$(PROJECT).elf
- $(WLINK_RS) flash $<
-
-# --------------- dfu-util -----------------
-DFU_UTIL_OPTION ?= -a 0
-flash-dfu-util: $(BUILD)/$(PROJECT).bin
- dfu-util -R $(DFU_UTIL_OPTION) -D $<
-
-# --------------- Black Magic -----------------
-# This symlink is created by https://github.com/blacksphere/blackmagic/blob/master/driver/99-blackmagic.rules
-BMP ?= /dev/ttyBmpGdb
-
-flash-bmp: $(BUILD)/$(PROJECT).elf
- $(GDB) --batch -ex 'target extended-remote $(BMP)' -ex 'monitor swdp_scan' -ex 'attach 1' -ex load $<
-
-debug-bmp: $(BUILD)/$(PROJECT).elf
- $(GDB) -ex 'target extended-remote $(BMP)' -ex 'monitor swdp_scan' -ex 'attach 1' $<
-
-# --------------- TI Uniflash -----------------
-DSLITE ?= dslite.sh
-flash-uniflash: $(BUILD)/$(PROJECT).hex
- ${DSLITE} ${UNIFLASH_OPTION} -f $<
-
-#-------------- Artifacts --------------
-
-# Create binary directory
-$(BIN):
-ifeq ($(CMDEXE),1)
- @$(MKDIR) $(subst /,\,$@)
-else
- @$(MKDIR) -p $@
-endif
-
-# Copy binaries .elf, .bin, .hex, .uf2 to BIN for upload
-# due to large size of combined artifacts, only uf2 is uploaded for now
-copy-artifact: $(BIN)
- @$(CP) $(BUILD)/$(PROJECT).uf2 $(BIN)
- #@$(CP) $(BUILD)/$(PROJECT).bin $(BIN)
- #@$(CP) $(BUILD)/$(PROJECT).hex $(BIN)
- #@$(CP) $(BUILD)/$(PROJECT).elf $(BIN)
-
-# Print out the value of a make variable.
-# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
-print-%:
- @echo $* = $($*)
diff --git a/examples/device/audio_4_channel_mic/Makefile b/examples/device/audio_4_channel_mic/Makefile
index 2c825bbf7..31e2c6f44 100644
--- a/examples/device/audio_4_channel_mic/Makefile
+++ b/examples/device/audio_4_channel_mic/Makefile
@@ -1,14 +1,14 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
src/main.c \
src/usb_descriptors.c \
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/audio_4_channel_mic/src/main.c b/examples/device/audio_4_channel_mic/src/main.c
index 3e0f03a20..5767c7453 100644
--- a/examples/device/audio_4_channel_mic/src/main.c
+++ b/examples/device/audio_4_channel_mic/src/main.c
@@ -66,8 +66,8 @@ uint32_t sampFreq;
uint8_t clkValid;
// Range states
-audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
-audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
+audio20_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
+audio20_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
// Audio test data, 4 channels muxed together, buffer[0] for CH0, buffer[1] for CH1, buffer[2] for CH2, buffer[3] for CH3
uint16_t i2s_dummy_buffer[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX * CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE / 1000];
@@ -156,7 +156,9 @@ void tud_resume_cb(void) {
void audio_task(void) {
static uint32_t start_ms = 0;
uint32_t curr_ms = board_millis();
- if (start_ms == curr_ms) return;// not enough time
+ if (start_ms == curr_ms) {
+ return; // not enough time
+ }
start_ms = curr_ms;
tud_audio_write(i2s_dummy_buffer, AUDIO_SAMPLE_RATE / 1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX);
}
@@ -171,7 +173,7 @@ bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_req
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -191,7 +193,7 @@ bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_re
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -218,25 +220,25 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
(void) itf;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// If request is for our feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Request uses format layout 1
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_1_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_1_t));
- mute[channelNum] = ((audio_control_cur_1_t *) pBuff)->bCur;
+ mute[channelNum] = ((audio20_control_cur_1_t *) pBuff)->bCur;
TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
return true;
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
// Request uses format layout 2
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_2_t));
- volume[channelNum] = (uint16_t) ((audio_control_cur_2_t *) pBuff)->bCur;
+ volume[channelNum] = (uint16_t) ((audio20_control_cur_2_t *) pBuff)->bCur;
TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
return true;
@@ -297,13 +299,13 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Input terminal (Microphone input)
if (entityID == 1) {
switch (ctrlSel) {
- case AUDIO_TE_CTRL_CONNECTOR: {
+ case AUDIO20_TE_CTRL_CONNECTOR: {
// The terminal connector control only has a get request with only the CUR attribute.
- audio_desc_channel_cluster_t ret;
+ audio20_desc_channel_cluster_t ret;
// Those are dummy values for now
ret.bNrChannels = 1;
- ret.bmChannelConfig = (audio_channel_config_t) 0;
+ ret.bmChannelConfig = (audio20_channel_config_t) 0;
ret.iChannelNames = 0;
TU_LOG2(" Get terminal connector\r\n");
@@ -321,24 +323,23 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Audio control mute cur parameter block consists of only one byte - we thus can send it right away
// There does not exist a range parameter block for mute
TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
return tud_control_xfer(rhport, p_request, &mute[channelNum], 1);
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
return tud_control_xfer(rhport, p_request, &volume[channelNum], sizeof(volume[channelNum]));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG2(" Get Volume range of channel: %u\r\n", channelNum);
// Copy values - only for testing - better is version below
- audio_control_range_2_n_t(1)
- ret;
+ audio20_control_range_2_n_t(1) ret;
ret.wNumSubRanges = 1;
ret.subrange[0].bMin = -90;// -90 dB
@@ -364,15 +365,15 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Clock Source unit
if (entityID == 4) {
switch (ctrlSel) {
- case AUDIO_CS_CTRL_SAM_FREQ:
+ case AUDIO20_CS_CTRL_SAM_FREQ:
// channelNum is always zero in this case
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG2(" Get Sample Freq.\r\n");
// Buffered control transfer is needed for IN flow control to work
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG2(" Get Sample Freq. range\r\n");
return tud_control_xfer(rhport, p_request, &sampleFreqRng, sizeof(sampleFreqRng));
@@ -383,7 +384,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
break;
- case AUDIO_CS_CTRL_CLK_VALID:
+ case AUDIO20_CS_CTRL_CLK_VALID:
// Only cur attribute exists for this request
TU_LOG2(" Get Sample Freq. valid\r\n");
return tud_control_xfer(rhport, p_request, &clkValid, sizeof(clkValid));
@@ -407,7 +408,9 @@ void led_blinking_task(void) {
static bool led_state = false;
// Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return;// not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/audio_4_channel_mic/src/tusb_config.h b/examples/device/audio_4_channel_mic/src/tusb_config.h
index 0ee3ba2d0..085f9d168 100644
--- a/examples/device/audio_4_channel_mic/src/tusb_config.h
+++ b/examples/device/audio_4_channel_mic/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -105,14 +105,10 @@ extern "C" {
// Have a look into audio_device.h for all configurations
#define CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE 48000
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_FOUR_CH_DESC_LEN
-
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
-
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 4 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
-#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
#define CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL 1
@@ -123,4 +119,4 @@ extern "C" {
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
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 728a5f9ce..00337eee7 100644
--- a/examples/device/audio_4_channel_mic/src/usb_descriptors.c
+++ b/examples/device/audio_4_channel_mic/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -80,7 +80,7 @@ enum
ITF_NUM_TOTAL
};
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_FOUR_CH_DESC_LEN)
+#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO20_MIC_FOUR_CH_DESC_LEN)
#if TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
@@ -101,7 +101,7 @@ uint8_t const desc_configuration[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_MIC_FOUR_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
+ TUD_AUDIO20_MIC_FOUR_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -126,7 +126,7 @@ enum {
};
// array of pointer to string descriptors
-char const* string_desc_arr [] = {
+static char const* string_desc_arr [] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"PaniRCorp", // 1: Manufacturer
"MicNode_4_Ch", // 2: Product
@@ -156,18 +156,22 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if ( chr_count > max_count ) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
- _desc_str[1 + i] = str[i];
+ _desc_str[1 + i] = (uint16_t) str[i];
}
break;
}
diff --git a/examples/device/audio_4_channel_mic_freertos/Makefile b/examples/device/audio_4_channel_mic_freertos/Makefile
index bd625b345..3c421af74 100644
--- a/examples/device/audio_4_channel_mic_freertos/Makefile
+++ b/examples/device/audio_4_channel_mic_freertos/Makefile
@@ -1,15 +1,15 @@
RTOS = freertos
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
src/main.c \
src/usb_descriptors.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/audio_4_channel_mic_freertos/skip.txt b/examples/device/audio_4_channel_mic_freertos/skip.txt
index 30cd46e7e..65925b32c 100644
--- a/examples/device/audio_4_channel_mic_freertos/skip.txt
+++ b/examples/device/audio_4_channel_mic_freertos/skip.txt
@@ -17,3 +17,4 @@ board:lpcxpresso11u37
board:lpcxpresso1347
family:broadcom_32bit
family:broadcom_64bit
+family:nuc121_125
diff --git a/examples/device/audio_4_channel_mic_freertos/src/main.c b/examples/device/audio_4_channel_mic_freertos/src/main.c
index 96eca0be9..4572bbb3c 100644
--- a/examples/device/audio_4_channel_mic_freertos/src/main.c
+++ b/examples/device/audio_4_channel_mic_freertos/src/main.c
@@ -102,8 +102,8 @@ uint32_t sampFreq;
uint8_t clkValid;
// Range states
-audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
-audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
+audio20_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
+audio20_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
// Audio test data, 4 channels muxed together, buffer[0] for CH0, buffer[1] for CH1, buffer[2] for CH2, buffer[3] for CH3
uint16_t i2s_dummy_buffer[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX * CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE / 1000];
@@ -245,7 +245,7 @@ bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_req
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -265,7 +265,7 @@ bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_re
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -292,25 +292,25 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
(void) itf;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// If request is for our feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Request uses format layout 1
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_1_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_1_t));
- mute[channelNum] = ((audio_control_cur_1_t *) pBuff)->bCur;
+ mute[channelNum] = ((audio20_control_cur_1_t *) pBuff)->bCur;
TU_LOG1(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
return true;
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
// Request uses format layout 2
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_2_t));
- volume[channelNum] = ((audio_control_cur_2_t *) pBuff)->bCur;
+ volume[channelNum] = ((audio20_control_cur_2_t *) pBuff)->bCur;
TU_LOG1(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
return true;
@@ -368,9 +368,9 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Input terminal (Microphone input)
if (entityID == 1) {
switch (ctrlSel) {
- case AUDIO_TE_CTRL_CONNECTOR: {
+ case AUDIO20_TE_CTRL_CONNECTOR: {
// The terminal connector control only has a get request with only the CUR attribute.
- audio_desc_channel_cluster_t ret;
+ audio20_desc_channel_cluster_t ret;
// Those are dummy values for now
ret.bNrChannels = 1;
@@ -392,23 +392,23 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Audio control mute cur parameter block consists of only one byte - we thus can send it right away
// There does not exist a range parameter block for mute
TU_LOG1(" Get Mute of channel: %u\r\n", channelNum);
return tud_control_xfer(rhport, p_request, &mute[channelNum], 1);
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG1(" Get Volume of channel: %u\r\n", channelNum);
return tud_control_xfer(rhport, p_request, &volume[channelNum], sizeof(volume[channelNum]));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG1(" Get Volume range of channel: %u\r\n", channelNum);
// Copy values - only for testing - better is version below
- audio_control_range_2_n_t(1) ret;
+ audio20_control_range_2_n_t(1) ret;
ret.wNumSubRanges = 1;
ret.subrange[0].bMin = -90;// -90 dB
@@ -434,15 +434,15 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Clock Source unit
if (entityID == 4) {
switch (ctrlSel) {
- case AUDIO_CS_CTRL_SAM_FREQ:
+ case AUDIO20_CS_CTRL_SAM_FREQ:
// channelNum is always zero in this case
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG1(" Get Sample Freq.\r\n");
// Buffered control transfer is needed for IN flow control to work
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG1(" Get Sample Freq. range\r\n");
return tud_control_xfer(rhport, p_request, &sampleFreqRng, sizeof(sampleFreqRng));
@@ -453,7 +453,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
break;
- case AUDIO_CS_CTRL_CLK_VALID:
+ case AUDIO20_CS_CTRL_CLK_VALID:
// Only cur attribute exists for this request
TU_LOG1(" Get Sample Freq. valid\r\n");
return tud_control_xfer(rhport, p_request, &clkValid, sizeof(clkValid));
diff --git a/examples/device/audio_4_channel_mic_freertos/src/tusb_config.h b/examples/device/audio_4_channel_mic_freertos/src/tusb_config.h
index d973be2af..74729695f 100644
--- a/examples/device/audio_4_channel_mic_freertos/src/tusb_config.h
+++ b/examples/device/audio_4_channel_mic_freertos/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -111,14 +111,10 @@ extern "C" {
// Have a look into audio_device.h for all configurations
#define CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE 48000
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_FOUR_CH_DESC_LEN
-
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
-
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 4 // This value is not required by the driver, it parses this information from the descriptor once the alternate interface is set by the host - we use it for the setup
-#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
#define CFG_TUD_AUDIO_EP_IN_FLOW_CONTROL 1
@@ -129,4 +125,4 @@ extern "C" {
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/audio_4_channel_mic_freertos/src/usb_descriptors.c b/examples/device/audio_4_channel_mic_freertos/src/usb_descriptors.c
index 728a5f9ce..3bb93f67d 100644
--- a/examples/device/audio_4_channel_mic_freertos/src/usb_descriptors.c
+++ b/examples/device/audio_4_channel_mic_freertos/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -80,7 +80,7 @@ enum
ITF_NUM_TOTAL
};
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_FOUR_CH_DESC_LEN)
+#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO20_MIC_FOUR_CH_DESC_LEN)
#if TU_CHECK_MCU(OPT_MCU_LPC175X_6X, OPT_MCU_LPC177X_8X, OPT_MCU_LPC40XX)
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
@@ -101,7 +101,7 @@ uint8_t const desc_configuration[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_MIC_FOUR_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
+ TUD_AUDIO20_MIC_FOUR_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -156,14 +156,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if ( chr_count > max_count ) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/audio_test/Makefile b/examples/device/audio_test/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/audio_test/Makefile
+++ b/examples/device/audio_test/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/audio_test/src/main.c b/examples/device/audio_test/src/main.c
index 5b3beec24..2441eefbc 100644
--- a/examples/device/audio_test/src/main.c
+++ b/examples/device/audio_test/src/main.c
@@ -63,8 +63,8 @@ uint32_t sampFreq;
uint8_t clkValid;
// Range states
-audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
-audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
+audio20_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
+audio20_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
// Audio test data
uint16_t test_buffer_audio[CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE / 1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX / 2];
@@ -139,7 +139,9 @@ void tud_resume_cb(void) {
void audio_task(void) {
static uint32_t start_ms = 0;
uint32_t curr_ms = board_millis();
- if (start_ms == curr_ms) return;// not enough time
+ if (start_ms == curr_ms) {
+ return; // not enough time
+ }
start_ms = curr_ms;
for (size_t cnt = 0; cnt < sizeof(test_buffer_audio) / 2; cnt++) {
test_buffer_audio[cnt] = startVal++;
@@ -157,7 +159,7 @@ bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_req
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -177,7 +179,7 @@ bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_re
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -204,25 +206,25 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
(void) itf;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// If request is for our feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Request uses format layout 1
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_1_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_1_t));
- mute[channelNum] = ((audio_control_cur_1_t *) pBuff)->bCur;
+ mute[channelNum] = ((audio20_control_cur_1_t *) pBuff)->bCur;
TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
return true;
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
// Request uses format layout 2
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_2_t));
- volume[channelNum] = (uint16_t) ((audio_control_cur_2_t *) pBuff)->bCur;
+ volume[channelNum] = (uint16_t) ((audio20_control_cur_2_t *) pBuff)->bCur;
TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
return true;
@@ -283,13 +285,13 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Input terminal (Microphone input)
if (entityID == 1) {
switch (ctrlSel) {
- case AUDIO_TE_CTRL_CONNECTOR: {
+ case AUDIO20_TE_CTRL_CONNECTOR: {
// The terminal connector control only has a get request with only the CUR attribute.
- audio_desc_channel_cluster_t ret;
+ audio20_desc_channel_cluster_t ret;
// Those are dummy values for now
ret.bNrChannels = 1;
- ret.bmChannelConfig = (audio_channel_config_t) 0;
+ ret.bmChannelConfig = (audio20_channel_config_t) 0;
ret.iChannelNames = 0;
TU_LOG2(" Get terminal connector\r\n");
@@ -307,23 +309,23 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Audio control mute cur parameter block consists of only one byte - we thus can send it right away
// There does not exist a range parameter block for mute
TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &mute[channelNum], 1);
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &volume[channelNum], sizeof(volume[channelNum]));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG2(" Get Volume range of channel: %u\r\n", channelNum);
// Copy values - only for testing - better is version below
- audio_control_range_2_n_t(1)
+ audio20_control_range_2_n_t(1)
ret;
ret.wNumSubRanges = 1;
@@ -350,14 +352,14 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Clock Source unit
if (entityID == 4) {
switch (ctrlSel) {
- case AUDIO_CS_CTRL_SAM_FREQ:
+ case AUDIO20_CS_CTRL_SAM_FREQ:
// channelNum is always zero in this case
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG2(" Get Sample Freq.\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG2(" Get Sample Freq. range\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampleFreqRng, sizeof(sampleFreqRng));
@@ -368,7 +370,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
break;
- case AUDIO_CS_CTRL_CLK_VALID:
+ case AUDIO20_CS_CTRL_CLK_VALID:
// Only cur attribute exists for this request
TU_LOG2(" Get Sample Freq. valid\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &clkValid, sizeof(clkValid));
@@ -400,7 +402,9 @@ void led_blinking_task(void) {
static bool led_state = false;
// Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return;// not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/audio_test/src/tusb_config.h b/examples/device/audio_test/src/tusb_config.h
index 10bf53809..e311d892f 100644
--- a/examples/device/audio_test/src/tusb_config.h
+++ b/examples/device/audio_test/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -108,13 +108,10 @@ extern "C" {
// Have a look into audio_device.h for all configurations
#define CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE 48000
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_ONE_CH_DESC_LEN
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64 // Size of control request buffer
-
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below - be aware: for different number of channels you need another descriptor!
-#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_EP_SZ_IN // Example write FIFO every 1ms, so it should be 8 times larger for HS device
@@ -122,4 +119,4 @@ extern "C" {
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/audio_test/src/usb_descriptors.c b/examples/device/audio_test/src/usb_descriptors.c
index 9864377f6..ad161939e 100644
--- a/examples/device/audio_test/src/usb_descriptors.c
+++ b/examples/device/audio_test/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -80,7 +80,7 @@ enum
ITF_NUM_TOTAL
};
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_ONE_CH_DESC_LEN)
+#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO20_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
@@ -101,7 +101,7 @@ uint8_t const desc_configuration[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_MIC_ONE_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
+ TUD_AUDIO20_MIC_ONE_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -158,14 +158,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/audio_test_freertos/Makefile b/examples/device/audio_test_freertos/Makefile
index bd625b345..3c421af74 100644
--- a/examples/device/audio_test_freertos/Makefile
+++ b/examples/device/audio_test_freertos/Makefile
@@ -1,15 +1,15 @@
RTOS = freertos
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
src/main.c \
src/usb_descriptors.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/audio_test_freertos/skip.txt b/examples/device/audio_test_freertos/skip.txt
index 1f3d4281a..c9cdacad7 100644
--- a/examples/device/audio_test_freertos/skip.txt
+++ b/examples/device/audio_test_freertos/skip.txt
@@ -15,3 +15,4 @@ mcu:RAXXX
family:broadcom_32bit
family:broadcom_64bit
board:stm32l0538disco
+family:nuc121_125
diff --git a/examples/device/audio_test_freertos/src/main.c b/examples/device/audio_test_freertos/src/main.c
index 1eab5dab8..cf2fb74d1 100644
--- a/examples/device/audio_test_freertos/src/main.c
+++ b/examples/device/audio_test_freertos/src/main.c
@@ -100,8 +100,8 @@ uint32_t sampFreq;
uint8_t clkValid;
// Range states
-audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
-audio_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
+audio20_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
+audio20_control_range_4_n_t(1) sampleFreqRng; // Sample frequency range state
// Audio test data
uint16_t test_buffer_audio[CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE / 1000 * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX / 2];
@@ -231,7 +231,7 @@ bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_req
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -251,7 +251,7 @@ bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_re
(void) pBuff;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// Page 91 in UAC2 specification
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
@@ -278,25 +278,25 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
(void) itf;
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// If request is for our feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Request uses format layout 1
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_1_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_1_t));
- mute[channelNum] = ((audio_control_cur_1_t *) pBuff)->bCur;
+ mute[channelNum] = ((audio20_control_cur_1_t *) pBuff)->bCur;
TU_LOG1(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
return true;
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
// Request uses format layout 2
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_2_t));
- volume[channelNum] = (uint16_t) ((audio_control_cur_2_t *) pBuff)->bCur;
+ volume[channelNum] = (uint16_t) ((audio20_control_cur_2_t *) pBuff)->bCur;
TU_LOG1(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
return true;
@@ -354,13 +354,13 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Input terminal (Microphone input)
if (entityID == 1) {
switch (ctrlSel) {
- case AUDIO_TE_CTRL_CONNECTOR: {
+ case AUDIO20_TE_CTRL_CONNECTOR: {
// The terminal connector control only has a get request with only the CUR attribute.
- audio_desc_channel_cluster_t ret;
+ audio20_desc_channel_cluster_t ret;
// Those are dummy values for now
ret.bNrChannels = 1;
- ret.bmChannelConfig = (audio_channel_config_t) 0;
+ ret.bmChannelConfig = (audio20_channel_config_t) 0;
ret.iChannelNames = 0;
TU_LOG1(" Get terminal connector\r\n");
@@ -378,23 +378,23 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Feature unit
if (entityID == 2) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Audio control mute cur parameter block consists of only one byte - we thus can send it right away
// There does not exist a range parameter block for mute
TU_LOG1(" Get Mute of channel: %u\r\n", channelNum);
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &mute[channelNum], 1);
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG1(" Get Volume of channel: %u\r\n", channelNum);
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &volume[channelNum], sizeof(volume[channelNum]));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG1(" Get Volume range of channel: %u\r\n", channelNum);
// Copy values - only for testing - better is version below
- audio_control_range_2_n_t(1)
+ audio20_control_range_2_n_t(1)
ret;
ret.wNumSubRanges = 1;
@@ -421,14 +421,14 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Clock Source unit
if (entityID == 4) {
switch (ctrlSel) {
- case AUDIO_CS_CTRL_SAM_FREQ:
+ case AUDIO20_CS_CTRL_SAM_FREQ:
// channelNum is always zero in this case
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG1(" Get Sample Freq.\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG1(" Get Sample Freq. range\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampleFreqRng, sizeof(sampleFreqRng));
@@ -439,7 +439,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
break;
- case AUDIO_CS_CTRL_CLK_VALID:
+ case AUDIO20_CS_CTRL_CLK_VALID:
// Only cur attribute exists for this request
TU_LOG1(" Get Sample Freq. valid\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &clkValid, sizeof(clkValid));
diff --git a/examples/device/audio_test_freertos/src/tusb_config.h b/examples/device/audio_test_freertos/src/tusb_config.h
index c9dc50082..81f0c11f4 100644
--- a/examples/device/audio_test_freertos/src/tusb_config.h
+++ b/examples/device/audio_test_freertos/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -114,13 +114,10 @@ extern "C" {
// Have a look into audio_device.h for all configurations
#define CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE 48000
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_ONE_CH_DESC_LEN
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64 // Size of control request buffer
-
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX 2 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below - be aware: for different number of channels you need another descriptor!
-#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO_EP_SZ_IN TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX CFG_TUD_AUDIO_EP_SZ_IN
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_EP_SZ_IN // Example write FIFO every 1ms, so it should be 8 times larger for HS device
@@ -128,4 +125,4 @@ extern "C" {
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/audio_test_freertos/src/usb_descriptors.c b/examples/device/audio_test_freertos/src/usb_descriptors.c
index 9864377f6..ad161939e 100644
--- a/examples/device/audio_test_freertos/src/usb_descriptors.c
+++ b/examples/device/audio_test_freertos/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -80,7 +80,7 @@ enum
ITF_NUM_TOTAL
};
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_ONE_CH_DESC_LEN)
+#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO20_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
@@ -101,7 +101,7 @@ uint8_t const desc_configuration[] =
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_MIC_ONE_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
+ TUD_AUDIO20_MIC_ONE_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX, /*_nBitsUsedPerSample*/ CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX*8, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO_EP_SZ_IN)
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -158,14 +158,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/audio_test_multi_rate/Makefile b/examples/device/audio_test_multi_rate/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/audio_test_multi_rate/Makefile
+++ b/examples/device/audio_test_multi_rate/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/audio_test_multi_rate/src/main.c b/examples/device/audio_test_multi_rate/src/main.c
index 9d467991e..baeec870f 100644
--- a/examples/device/audio_test_multi_rate/src/main.c
+++ b/examples/device/audio_test_multi_rate/src/main.c
@@ -60,7 +60,7 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
// Audio controls
// Current states
bool mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1]; // +1 for master channel 0
-uint16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// +1 for master channel 0
+int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// +1 for master channel 0
uint32_t sampFreq;
uint8_t bytesPerSample;
uint8_t clkValid;
@@ -80,9 +80,6 @@ static const uint8_t bytesPerSampleAltList[CFG_TUD_AUDIO_FUNC_1_N_FORMATS] =
CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX,
};
-audio_control_range_2_n_t(1) volumeRng[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX + 1];// Volume range state
-
-
// Audio test data
CFG_TUD_MEM_ALIGN uint8_t test_buffer_audio[(TUD_OPT_HIGH_SPEED ? 8 : 1) * CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX];
uint16_t startVal = 0;
@@ -111,9 +108,6 @@ int main(void) {
led_blinking_task();
audio_task();
}
-
-
- return 0;
}
//--------------------------------------------------------------------+
@@ -153,7 +147,9 @@ void tud_resume_cb(void) {
void audio_task(void) {
static uint32_t start_ms = 0;
uint32_t curr_ms = board_millis();
- if (start_ms == curr_ms) return;// not enough time
+ if (start_ms == curr_ms) {
+ return; // not enough time
+ }
start_ms = curr_ms;
// 16bit
if (bytesPerSample == 2) {
@@ -176,91 +172,204 @@ void audio_task(void) {
// Application Callback API Implementations
//--------------------------------------------------------------------+
-// Invoked when set interface is called, typically on start/stop streaming or format change
-bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
- (void) rhport;
- //uint8_t const itf = tu_u16_low(tu_le16toh(p_request->wIndex));
- uint8_t const alt = tu_u16_low(tu_le16toh(p_request->wValue));
+//--------------------------------------------------------------------+
+// UAC1 Helper Functions
+//--------------------------------------------------------------------+
- // Clear buffer when streaming format is changed
- if (alt != 0) {
- bytesPerSample = bytesPerSampleAltList[alt - 1];
+static bool audio10_set_req_ep(tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+
+ switch (ctrlSel) {
+ case AUDIO10_EP_CTRL_SAMPLING_FREQ:
+ if (p_request->bRequest == AUDIO10_CS_REQ_SET_CUR) {
+ // Request uses 3 bytes
+ TU_VERIFY(p_request->wLength == 3);
+
+ sampFreq = tu_unaligned_read32(pBuff) & 0x00FFFFFF;
+
+ TU_LOG2("EP set current freq: %" PRIu32 "\r\n", sampFreq);
+
+ return true;
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
}
- return true;
+
+ return false;
}
-// Invoked when audio class specific set request received for an EP
-bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
- (void) rhport;
- (void) pBuff;
+static bool audio10_get_req_ep(uint8_t rhport, tusb_control_request_t const *p_request) {
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- // We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ switch (ctrlSel) {
+ case AUDIO10_EP_CTRL_SAMPLING_FREQ:
+ if (p_request->bRequest == AUDIO10_CS_REQ_GET_CUR) {
+ TU_LOG2("EP get current freq\r\n");
+
+ uint8_t freq[3];
+ freq[0] = (uint8_t) (sampFreq & 0xFF);
+ freq[1] = (uint8_t) ((sampFreq >> 8) & 0xFF);
+ freq[2] = (uint8_t) ((sampFreq >> 16) & 0xFF);
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, freq, sizeof(freq));
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+
+ return false;
+}
- // Page 91 in UAC2 specification
+static bool audio10_set_req_entity(tusb_control_request_t const *p_request, uint8_t *pBuff) {
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t ep = TU_U16_LOW(p_request->wIndex);
+ uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
- (void) channelNum;
- (void) ctrlSel;
- (void) ep;
+ // If request is for our feature unit (ID defined in usbd.h)
+ if (entityID == 0x02) {
+ switch (ctrlSel) {
+ case AUDIO10_FU_CTRL_MUTE:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_SET_CUR:
+ // Only 1st form is supported
+ TU_VERIFY(p_request->wLength ==1);
- return false;// Yet not implemented
-}
+ mute[channelNum] = pBuff[0];
-// Invoked when audio class specific set request received for an interface
-bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
- (void) rhport;
- (void) pBuff;
+ TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
+ return true;
- // We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ default:
+ return false; // not supported
+ }
- // Page 91 in UAC2 specification
+ case AUDIO10_FU_CTRL_VOLUME:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_SET_CUR:
+ // Only 1st form is supported
+ TU_VERIFY(p_request->wLength == 2);
+
+ volume[channelNum] = (int16_t)tu_unaligned_read16(pBuff) / 256;
+
+ TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
+ return true;
+
+ default:
+ return false; // not supported
+ }
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ }
+
+ return false;
+}
+
+static bool audio10_get_req_entity(uint8_t rhport, tusb_control_request_t const *p_request) {
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
+ uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
+
+ // If request is for our feature unit (ID defined in usbd.h)
+ if (entityID == 0x02) {
+ switch (ctrlSel) {
+ case AUDIO10_FU_CTRL_MUTE:
+ // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
+ // There does not exist a range parameter block for mute
+ TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &mute[channelNum], 1);
- (void) channelNum;
- (void) ctrlSel;
- (void) itf;
+ case AUDIO10_FU_CTRL_VOLUME:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_GET_CUR:
+ TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
+ {
+ int16_t vol = (int16_t) volume[channelNum];
+ vol = vol * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &vol, sizeof(vol));
+ }
- return false;// Yet not implemented
+ case AUDIO10_CS_REQ_GET_MIN:
+ TU_LOG2(" Get Volume min of channel: %u\r\n", channelNum);
+ {
+ int16_t min = -90; // -90 dB
+ min = min * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &min, sizeof(min));
+ }
+
+ case AUDIO10_CS_REQ_GET_MAX:
+ TU_LOG2(" Get Volume max of channel: %u\r\n", channelNum);
+ {
+ int16_t max = 30; // +30 dB
+ max = max * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &max, sizeof(max));
+ }
+
+ case AUDIO10_CS_REQ_GET_RES:
+ TU_LOG2(" Get Volume res of channel: %u\r\n", channelNum);
+ {
+ int16_t res = 1; // 1 dB
+ res = res * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &res, sizeof(res));
+ }
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ }
+
+ return false;
}
-// Invoked when audio class specific set request received for an entity
-bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
- (void) rhport;
+//--------------------------------------------------------------------+
+// UAC2 Helper Functions
+//--------------------------------------------------------------------+
+
+#if TUD_OPT_HIGH_SPEED
- // Page 91 in UAC2 specification
+static bool audio20_set_req_entity(tusb_control_request_t const *p_request, uint8_t *pBuff) {
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
- (void) itf;
-
// We do not support any set range requests here, only current value requests
- TU_VERIFY(p_request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(p_request->bRequest == AUDIO20_CS_REQ_CUR);
// If request is for our feature unit
if (entityID == UAC2_ENTITY_FEATURE_UNIT) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Request uses format layout 1
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_1_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_1_t));
- mute[channelNum] = ((audio_control_cur_1_t *) pBuff)->bCur;
+ mute[channelNum] = ((audio20_control_cur_1_t *) pBuff)->bCur;
TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
return true;
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
// Request uses format layout 2
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_2_t));
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_2_t));
- volume[channelNum] = (uint16_t) ((audio_control_cur_2_t *) pBuff)->bCur;
+ volume[channelNum] = (int16_t) ((audio20_control_cur_2_t *) pBuff)->bCur;
TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
return true;
@@ -275,10 +384,10 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Clock Source unit
if (entityID == UAC2_ENTITY_CLOCK) {
switch (ctrlSel) {
- case AUDIO_CS_CTRL_SAM_FREQ:
- TU_VERIFY(p_request->wLength == sizeof(audio_control_cur_4_t));
+ case AUDIO20_CS_CTRL_SAM_FREQ:
+ TU_VERIFY(p_request->wLength == sizeof(audio20_control_cur_4_t));
- sampFreq = (uint32_t) ((audio_control_cur_4_t *) pBuff)->bCur;
+ sampFreq = (uint32_t) ((audio20_control_cur_4_t *) pBuff)->bCur;
TU_LOG2("Clock set current freq: %" PRIu32 "\r\n", sampFreq);
@@ -292,59 +401,20 @@ bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
}
- return false;// Yet not implemented
+ return false;
}
-// Invoked when audio class specific get request received for an EP
-bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
- (void) rhport;
-
- // Page 91 in UAC2 specification
+static bool audio20_get_req_entity(uint8_t rhport, tusb_control_request_t const *p_request) {
uint8_t channelNum = TU_U16_LOW(p_request->wValue);
uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t ep = TU_U16_LOW(p_request->wIndex);
-
- (void) channelNum;
- (void) ctrlSel;
- (void) ep;
-
- // return tud_control_xfer(rhport, p_request, &tmp, 1);
-
- return false;// Yet not implemented
-}
-
-// Invoked when audio class specific get request received for an interface
-bool tud_audio_get_req_itf_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
- (void) rhport;
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- uint8_t itf = TU_U16_LOW(p_request->wIndex);
-
- (void) channelNum;
- (void) ctrlSel;
- (void) itf;
-
- return false;// Yet not implemented
-}
-
-// Invoked when audio class specific get request received for an entity
-bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
- (void) rhport;
-
- // Page 91 in UAC2 specification
- uint8_t channelNum = TU_U16_LOW(p_request->wValue);
- uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
- // uint8_t itf = TU_U16_LOW(p_request->wIndex); // Since we have only one audio function implemented, we do not need the itf value
uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
// Input terminal (Microphone input)
if (entityID == UAC2_ENTITY_INPUT_TERMINAL) {
switch (ctrlSel) {
- case AUDIO_TE_CTRL_CONNECTOR: {
+ case AUDIO20_TE_CTRL_CONNECTOR: {
// The terminal connector control only has a get request with only the CUR attribute.
- audio_desc_channel_cluster_t ret;
+ audio20_desc_channel_cluster_t ret;
// Those are dummy values for now
ret.bNrChannels = 1;
@@ -366,23 +436,23 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Feature unit
if (entityID == UAC2_ENTITY_FEATURE_UNIT) {
switch (ctrlSel) {
- case AUDIO_FU_CTRL_MUTE:
+ case AUDIO20_FU_CTRL_MUTE:
// Audio control mute cur parameter block consists of only one byte - we thus can send it right away
// There does not exist a range parameter block for mute
TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &mute[channelNum], 1);
- case AUDIO_FU_CTRL_VOLUME:
+ case AUDIO20_FU_CTRL_VOLUME:
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &volume[channelNum], sizeof(volume[channelNum]));
- case AUDIO_CS_REQ_RANGE:
+ case AUDIO20_CS_REQ_RANGE:
TU_LOG2(" Get Volume range of channel: %u\r\n", channelNum);
// Copy values - only for testing - better is version below
- audio_control_range_2_n_t(1)
+ audio20_control_range_2_n_t(1)
ret;
ret.wNumSubRanges = 1;
@@ -409,16 +479,16 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
// Clock Source unit
if (entityID == UAC2_ENTITY_CLOCK) {
switch (ctrlSel) {
- case AUDIO_CS_CTRL_SAM_FREQ:
+ case AUDIO20_CS_CTRL_SAM_FREQ:
// channelNum is always zero in this case
switch (p_request->bRequest) {
- case AUDIO_CS_REQ_CUR:
+ case AUDIO20_CS_REQ_CUR:
TU_LOG2(" Get Sample Freq.\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &sampFreq, sizeof(sampFreq));
- case AUDIO_CS_REQ_RANGE: {
+ case AUDIO20_CS_REQ_RANGE: {
TU_LOG2(" Get Sample Freq. range\r\n");
- audio_control_range_4_n_t(N_sampleRates) rangef =
+ audio20_control_range_4_n_t(N_sampleRates) rangef =
{
.wNumSubRanges = tu_htole16(N_sampleRates)};
TU_LOG1("Clock get %d freq ranges\r\n", N_sampleRates);
@@ -437,7 +507,7 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
break;
- case AUDIO_CS_CTRL_CLK_VALID:
+ case AUDIO20_CS_CTRL_CLK_VALID:
// Only cur attribute exists for this request
TU_LOG2(" Get Sample Freq. valid\r\n");
return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &clkValid, sizeof(clkValid));
@@ -449,7 +519,82 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
}
- TU_LOG2(" Unsupported entity: %d\r\n", entityID);
+ return false;
+}
+
+#endif // TUD_OPT_HIGH_SPEED
+
+//--------------------------------------------------------------------+
+// Main Callback Functions
+//--------------------------------------------------------------------+
+
+// Invoked when set interface is called, typically on start/stop streaming or format change
+bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+ //uint8_t const itf = tu_u16_low(tu_le16toh(p_request->wIndex));
+ uint8_t const alt = tu_u16_low(tu_le16toh(p_request->wValue));
+
+ // Clear buffer when streaming format is changed
+ if (alt != 0) {
+ bytesPerSample = bytesPerSampleAltList[alt - 1];
+ }
+ return true;
+}
+
+// Invoked when audio class specific set request received for an EP
+bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ (void) rhport;
+ (void) pBuff;
+
+ if (tud_audio_version() == 1) {
+ return audio10_set_req_ep(p_request, pBuff);
+ } else if (tud_audio_version() == 2) {
+ // We do not support any requests here
+ }
+
+ return false;// Yet not implemented
+}
+
+// Invoked when audio class specific get request received for an EP
+bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_get_req_ep(rhport, p_request);
+ } else if (tud_audio_version() == 2) {
+ // We do not support any requests here
+ }
+
+ return false;// Yet not implemented
+}
+
+// Invoked when audio class specific set request received for an entity
+bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_set_req_entity(p_request, pBuff);
+#if TUD_OPT_HIGH_SPEED
+ } else if (tud_audio_version() == 2) {
+ return audio20_set_req_entity(p_request, pBuff);
+#endif
+ }
+
+ return false;// Yet not implemented
+}
+
+// Invoked when audio class specific get request received for an entity
+bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_get_req_entity(rhport, p_request);
+#if TUD_OPT_HIGH_SPEED
+ } else if (tud_audio_version() == 2) {
+ return audio20_get_req_entity(rhport, p_request);
+#endif
+ }
+
return false;// Yet not implemented
}
@@ -469,7 +614,9 @@ void led_blinking_task(void) {
static bool led_state = false;
// Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return;// not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/audio_test_multi_rate/src/tusb_config.h b/examples/device/audio_test_multi_rate/src/tusb_config.h
index b48c0a0be..3587ae089 100644
--- a/examples/device/audio_test_multi_rate/src/tusb_config.h
+++ b/examples/device/audio_test_multi_rate/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -116,26 +116,31 @@ extern "C" {
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX 2
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX 16
-// 24bit in 32bit slots
+// 24bit in 32bit slots (UAC2 only)
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX 4
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX 24
// Have a look into audio_device.h for all configurations
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESC_LEN
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64 // Size of control request buffer
+#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
+#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below - be aware: for different number of channels you need another descriptor!
-#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
-#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX 1 // Driver gets this info from the descriptors - we define it here to use it to setup the descriptors and to do calculations with it below - be aware: for different number of channels you need another descriptor!
+// UAC1 (Full-Speed) Endpoint size calculation
+#define CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(false, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+// UAC2 (High-Speed) Endpoint size calculation
+#define CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(true, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(true, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN) // Maximum EP IN size for all AS alternate settings used
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX // Example write FIFO every 1ms, so it should be 8 times larger for HS device
+// Maximum EP IN size for all AS alternate settings used
+#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN, TU_MAX(CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN))
+
+// Tx flow control needs buffer size >= 4* EP size to work correctly
+// Example write FIFO every 1ms (8 HS frames), so buffer size should be 8 times larger for HS device
+#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ TU_MAX(4 * CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN, TU_MAX(32 * CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN, 32 * CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN))
#ifdef __cplusplus
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/audio_test_multi_rate/src/usb_descriptors.c b/examples/device/audio_test_multi_rate/src/usb_descriptors.c
index f50e70a25..471eb4f2e 100644
--- a/examples/device/audio_test_multi_rate/src/usb_descriptors.c
+++ b/examples/device/audio_test_multi_rate/src/usb_descriptors.c
@@ -34,15 +34,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
-{
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
@@ -67,23 +66,19 @@ tusb_desc_device_t const desc_device =
// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
-uint8_t const * tud_descriptor_device_cb(void)
-{
+uint8_t const * tud_descriptor_device_cb(void) {
return (uint8_t const *) &desc_device;
}
//--------------------------------------------------------------------+
// Configuration Descriptor
//--------------------------------------------------------------------+
-enum
-{
+enum {
ITF_NUM_AUDIO_CONTROL = 0,
ITF_NUM_AUDIO_STREAMING,
ITF_NUM_TOTAL
};
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_AUDIO * TUD_AUDIO_MIC_ONE_CH_2_FORMAT_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 ...
@@ -97,24 +92,81 @@ enum
#define EPNUM_AUDIO 0x01
#endif
-uint8_t const desc_configuration[] =
-{
+#define CONFIG_UAC1_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO10_MIC_ONE_CH_DESC_LEN(3))
+
+uint8_t const desc_uac1_configuration[] = {
+ // Config number, interface count, string index, total length, attribute, power in mA
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_UAC1_TOTAL_LEN, 0x00, 100),
+
+ // Interface number, string index, EP Out & EP In address, EP size
+ TUD_AUDIO10_MIC_ONE_CH_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_nBytesPerSample*/ 2, /*_nBitsUsedPerSample*/ 16, /*_epin*/ 0x80 | EPNUM_AUDIO, /*_epsize*/ CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN, 32000, 48000, 96000)
+};
+
+TU_VERIFY_STATIC(sizeof(desc_uac1_configuration) == CONFIG_UAC1_TOTAL_LEN, "Incorrect size");
+
+#if TUD_OPT_HIGH_SPEED
+#define CONFIG_UAC2_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO20_MIC_ONE_CH_2_FORMAT_DESC_LEN)
+
+uint8_t const desc2_uac2_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_UAC2_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_epin*/ 0x80 | EPNUM_AUDIO)
+ TUD_AUDIO20_MIC_ONE_CH_2_FORMAT_DESCRIPTOR(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_stridx*/ 0, /*_epin*/ 0x80 | EPNUM_AUDIO)
+};
+
+TU_VERIFY_STATIC(sizeof(desc2_uac2_configuration) == CONFIG_UAC2_TOTAL_LEN, "Incorrect size");
+
+// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
+tusb_desc_device_qualifier_t const desc_device_qualifier = {
+ .bLength = sizeof(tusb_desc_device_t),
+ .bDescriptorType = TUSB_DESC_DEVICE,
+ .bcdUSB = 0x0200,
+
+ .bDeviceClass = TUSB_CLASS_MISC,
+ .bDeviceSubClass = MISC_SUBCLASS_COMMON,
+ .bDeviceProtocol = MISC_PROTOCOL_IAD,
+
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+ .bNumConfigurations = 0x01,
+ .bReserved = 0x00
};
-TU_VERIFY_STATIC(sizeof(desc_configuration) == CONFIG_TOTAL_LEN, "Incorrect size");
+// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
+// device_qualifier descriptor describes information about a high-speed capable device that would
+// change if the device were operating at the other speed. If not highspeed capable stall this request.
+uint8_t const *tud_descriptor_device_qualifier_cb(void) {
+ return (uint8_t const *) &desc_device_qualifier;
+}
+
+// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
+uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index) {
+ (void) index;// for multiple configurations
+
+ // if link speed is high return fullspeed config, and vice versa
+ return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_uac1_configuration : desc2_uac2_configuration;
+}
+
+#endif// highspeed
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
-{
+uint8_t const * tud_descriptor_configuration_cb(uint8_t index) {
(void) index; // for multiple configurations
- return desc_configuration;
+#if TUD_OPT_HIGH_SPEED
+ // Although we are highspeed, host may be fullspeed.
+ if(tud_speed_get() == TUSB_SPEED_FULL) {
+ return desc_uac1_configuration;
+ } else {
+ return desc2_uac2_configuration;
+ }
+#else
+ return desc_uac1_configuration;
+#endif
}
//--------------------------------------------------------------------+
@@ -130,8 +182,7 @@ enum {
};
// array of pointer to string descriptors
-char const* string_desc_arr [] =
-{
+char const* string_desc_arr [] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"PaniRCorp", // 1: Manufacturer
"MicNode", // 2: Product
@@ -162,14 +213,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/audio_test_multi_rate/src/usb_descriptors.h b/examples/device/audio_test_multi_rate/src/usb_descriptors.h
index 8381e31f5..948a7f4ae 100644
--- a/examples/device/audio_test_multi_rate/src/usb_descriptors.h
+++ b/examples/device/audio_test_multi_rate/src/usb_descriptors.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _USB_DESCRIPTORS_H_
-#define _USB_DESCRIPTORS_H_
+#ifndef USB_DESCRIPTORS_H_
+#define USB_DESCRIPTORS_H_
// #include "tusb.h"
@@ -35,68 +35,68 @@
#define UAC2_ENTITY_FEATURE_UNIT 0x02
-#define TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
- + TUD_AUDIO_DESC_STD_AC_LEN\
- + TUD_AUDIO_DESC_CS_AC_LEN\
- + TUD_AUDIO_DESC_CLK_SRC_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- + TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN\
+#define TUD_AUDIO20_MIC_ONE_CH_2_FORMAT_DESC_LEN (TUD_AUDIO20_DESC_IAD_LEN\
+ + TUD_AUDIO20_DESC_STD_AC_LEN\
+ + TUD_AUDIO20_DESC_CS_AC_LEN\
+ + TUD_AUDIO20_DESC_CLK_SRC_LEN\
+ + TUD_AUDIO20_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_OUTPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(1)\
/* Interface 1, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
/* Interface 1, Alternate 1 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
/* Interface 1, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN)
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN)
-#define TUD_AUDIO_MIC_ONE_CH_2_FORMAT_DESCRIPTOR(_itfnum, _stridx, _epin) \
+#define TUD_AUDIO20_MIC_ONE_CH_2_FORMAT_DESCRIPTOR(_itfnum, _stridx, _epin) \
/* Standard Interface Association Descriptor (IAD) */\
- TUD_AUDIO_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
/* Standard AC Interface Descriptor(4.7.1) */\
- TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
+ TUD_AUDIO20_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
/* Class-Specific AC Interface Header Descriptor(4.7.2) */\
- TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_MICROPHONE, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
+ TUD_AUDIO20_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO20_FUNC_MICROPHONE, /*_totallen*/ TUD_AUDIO20_DESC_CLK_SRC_LEN+TUD_AUDIO20_DESC_INPUT_TERM_LEN+TUD_AUDIO20_DESC_OUTPUT_TERM_LEN+TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(1), /*_ctrl*/ AUDIO20_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
/* Clock Source Descriptor(4.7.2.1) */\
- TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ AUDIO_CLOCK_SOURCE_ATT_INT_PRO_CLK, /*_ctrl*/ AUDIO_CTRL_RW << AUDIO_CLOCK_SOURCE_CTRL_CLK_FRQ_POS | AUDIO_CTRL_R << AUDIO_CLOCK_SOURCE_CTRL_CLK_VAL_POS, /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ AUDIO20_CLOCK_SOURCE_ATT_INT_PRO_CLK, /*_ctrl*/ AUDIO20_CTRL_RW << AUDIO20_CLOCK_SOURCE_CTRL_CLK_FRQ_POS | AUDIO20_CTRL_R << AUDIO20_CLOCK_SOURCE_CTRL_CLK_VAL_POS, /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
/* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ AUDIO20_CTRL_R << AUDIO20_IN_TERM_CTRL_CONNECTOR_POS, /*_stridx*/ 0x00),\
/* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ UAC2_ENTITY_INPUT_TERMINAL, /*_srcid*/ UAC2_ENTITY_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ UAC2_ENTITY_INPUT_TERMINAL, /*_srcid*/ UAC2_ENTITY_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
/* Feature Unit Descriptor(4.7.2.8) */\
- TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL(/*_unitid*/ UAC2_ENTITY_FEATURE_UNIT, /*_srcid*/ 0x01, /*_ctrlch0master*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch1*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_FEATURE_UNIT(/*_unitid*/ UAC2_ENTITY_FEATURE_UNIT, /*_srcid*/ 0x01, /*_stridx*/ 0x00, /*_ctrlch0master*/ AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch1*/ AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN, /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
/* Interface 1, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN, /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN, /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
#endif
diff --git a/examples/device/board_test/Makefile b/examples/device/board_test/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/board_test/Makefile
+++ b/examples/device/board_test/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/board_test/src/main.c b/examples/device/board_test/src/main.c
index d91a8760e..ee0829e5b 100644
--- a/examples/device/board_test/src/main.c
+++ b/examples/device/board_test/src/main.c
@@ -66,12 +66,12 @@ int main(void) {
printf(HELLO_STR);
#ifndef LOGGER_UART
- board_uart_write(HELLO_STR, strlen(HELLO_STR));
+ board_uart_write(HELLO_STR, sizeof(HELLO_STR)-1);
#endif
}
board_led_write(led_state);
- led_state = 1 - led_state; // toggle
+ led_state = !led_state; // toggle
}
}
}
diff --git a/examples/device/board_test/src/tusb_config.h b/examples/device/board_test/src/tusb_config.h
index 81829d450..97ec65f66 100644
--- a/examples/device/board_test/src/tusb_config.h
+++ b/examples/device/board_test/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -74,4 +74,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/cdc_dual_ports/Makefile b/examples/device/cdc_dual_ports/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/cdc_dual_ports/Makefile
+++ b/examples/device/cdc_dual_ports/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c
index 8fe003f21..5ccb06a8a 100644
--- a/examples/device/cdc_dual_ports/src/main.c
+++ b/examples/device/cdc_dual_ports/src/main.c
@@ -75,10 +75,14 @@ static void echo_serial_port(uint8_t itf, uint8_t buf[], uint32_t count) {
for (uint32_t i = 0; i < count; i++) {
if (itf == 0) {
// echo back 1st port as lower case
- if (isupper(buf[i])) buf[i] += case_diff;
+ if (isupper(buf[i])) {
+ buf[i] += case_diff;
+ }
} else {
// echo back 2nd port as upper case
- if (islower(buf[i])) buf[i] -= case_diff;
+ if (islower(buf[i])) {
+ buf[i] -= case_diff;
+ }
}
tud_cdc_n_write_char(itf, buf[i]);
@@ -153,7 +157,9 @@ void led_blinking_task(void) {
static bool led_state = false;
// Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/cdc_dual_ports/src/tusb_config.h b/examples/device/cdc_dual_ports/src/tusb_config.h
index 7f7df3909..0da4032a7 100644
--- a/examples/device/cdc_dual_ports/src/tusb_config.h
+++ b/examples/device/cdc_dual_ports/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -110,4 +110,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/cdc_dual_ports/src/usb_descriptors.c b/examples/device/cdc_dual_ports/src/usb_descriptors.c
index bbcb479f5..dd0aefaea 100644
--- a/examples/device/cdc_dual_ports/src/usb_descriptors.c
+++ b/examples/device/cdc_dual_ports/src/usb_descriptors.c
@@ -32,9 +32,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -42,7 +42,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -127,7 +127,7 @@ enum {
#define EPNUM_CDC_1_IN 0x84
#endif
-uint8_t const desc_fs_configuration[] = {
+static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -140,7 +140,7 @@ uint8_t const desc_fs_configuration[] = {
#if TUD_OPT_HIGH_SPEED
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -152,7 +152,7 @@ uint8_t const desc_hs_configuration[] = {
};
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -213,7 +213,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] = {
+static char const *string_desc_arr[] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
diff --git a/examples/device/cdc_msc/Makefile b/examples/device/cdc_msc/Makefile
index 0c2e37180..de50d118f 100644
--- a/examples/device/cdc_msc/Makefile
+++ b/examples/device/cdc_msc/Makefile
@@ -1,8 +1,8 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
@@ -10,6 +10,6 @@ EXAMPLE_SOURCE += \
src/msc_disk.c \
src/usb_descriptors.c \
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c
index 4e7aa989e..e4a205533 100644
--- a/examples/device/cdc_msc/src/main.c
+++ b/examples/device/cdc_msc/src/main.c
@@ -37,11 +37,12 @@
*/
enum {
BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
+ BLINK_MOUNTED = 1000,
+ BLINK_SUSPENDED = 2500,
};
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
+static bool blink_enable = true;
void led_blinking_task(void);
void cdc_task(void);
@@ -51,10 +52,7 @@ int main(void) {
board_init();
// init device stack on configured roothub port
- tusb_rhport_init_t dev_init = {
- .role = TUSB_ROLE_DEVICE,
- .speed = TUSB_SPEED_AUTO
- };
+ tusb_rhport_init_t dev_init = {.role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO};
tusb_init(BOARD_TUD_RHPORT, &dev_init);
board_init_after_tusb();
@@ -85,7 +83,7 @@ void tud_umount_cb(void) {
// remote_wakeup_en : if host allow us to perform remote wakeup
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
void tud_suspend_cb(bool remote_wakeup_en) {
- (void) remote_wakeup_en;
+ (void)remote_wakeup_en;
blink_interval_ms = BLINK_SUSPENDED;
}
@@ -106,9 +104,9 @@ void cdc_task(void) {
// connected and there are data available
if (tud_cdc_available()) {
// read data
- char buf[64];
+ char buf[64];
uint32_t count = tud_cdc_read(buf, sizeof(buf));
- (void) count;
+ (void)count;
// Echo back
// Note: Skip echo by commenting out write() and write_flush()
@@ -119,10 +117,12 @@ void cdc_task(void) {
}
// Press on-board button to send Uart status notification
+ static cdc_notify_uart_state_t uart_state = {.value = 0};
+
static uint32_t btn_prev = 0;
- static cdc_notify_uart_state_t uart_state = { .value = 0 };
- const uint32_t btn = board_button_read();
- if (!btn_prev && btn) {
+ const uint32_t btn = board_button_read();
+
+ if ((btn_prev == 0u) && (btn != 0u)) {
uart_state.dsr ^= 1;
tud_cdc_notify_uart_state(&uart_state);
}
@@ -132,33 +132,39 @@ void cdc_task(void) {
// Invoked when cdc when line state changed e.g connected/disconnected
void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
- (void) itf;
- (void) rts;
+ (void)itf;
+ (void)rts;
- // TODO set some indicator
if (dtr) {
// Terminal connected
+ blink_enable = false;
+ board_led_write(true);
} else {
// Terminal disconnected
+ blink_enable = true;
}
}
// Invoked when CDC interface received data from host
void tud_cdc_rx_cb(uint8_t itf) {
- (void) itf;
+ (void)itf;
}
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
void led_blinking_task(void) {
- static uint32_t start_ms = 0;
- static bool led_state = false;
+ static uint32_t start_ms = 0;
+ static bool led_state = false;
- // Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
- start_ms += blink_interval_ms;
+ if (blink_enable) {
+ // Blink every interval ms
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
+ start_ms += blink_interval_ms;
- board_led_write(led_state);
- led_state = 1 - led_state; // toggle
+ board_led_write(led_state);
+ led_state = !led_state;
+ }
}
diff --git a/examples/device/cdc_msc/src/msc_disk.c b/examples/device/cdc_msc/src/msc_disk.c
index 96f9f19ec..e091c2985 100644
--- a/examples/device/cdc_msc/src/msc_disk.c
+++ b/examples/device/cdc_msc/src/msc_disk.c
@@ -45,6 +45,7 @@ enum {
DISK_BLOCK_SIZE = 512
};
+static
#ifdef CFG_EXAMPLE_MSC_READONLY
const
#endif
@@ -57,63 +58,64 @@ uint8_t msc_disk[DISK_BLOCK_NUM][DISK_BLOCK_SIZE] = {
// drive_number = 0x80; media_type = 0xf8; extended_boot_signature = 0x29;
// filesystem_type = "FAT12 "; volume_serial_number = 0x1234; volume_label = "TinyUSB MSC";
// FAT magic code at offset 510-511
-{
- 0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00,
- 0x01, 0x10, 0x00, 0x10, 0x00, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29, 0x34, 0x12, 0x00, 0x00, 'T', 'i', 'n', 'y', 'U',
- 'S', 'B', ' ', 'M', 'S', 'C', 0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
+ {
+ 0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00,
+ 0x01, 0x10, 0x00, 0x10, 0x00, 0xF8, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x29, 0x34, 0x12, 0x00, 0x00, 'T', 'i', 'n', 'y', 'U',
+ 'S', 'B', ' ', 'M', 'S', 'C', 0x46, 0x41, 0x54, 0x31, 0x32, 0x20, 0x20, 0x20, 0x00, 0x00,
- // Zero up to 2 last bytes of FAT magic code
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ // Zero up to 2 last bytes of FAT magic code
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xAA},
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0xAA
+ },
//------------- Block1: FAT12 Table -------------//
-{
- 0xF8, 0xFF, 0xFF, 0xFF, 0x0F// // first 2 entries must be F8FF, third entry is cluster end of readme file
+ {
+ 0xF8, 0xFF, 0xFF, 0xFF, 0x0F// first 2 entries must be F8FF, third entry is cluster end of readme file
},
//------------- Block2: Root Directory -------------//
-{
- // first entry is volume label
- 'T', 'i', 'n', 'y', 'U', 'S', 'B', ' ', 'M', 'S', 'C', 0x08, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0x6D, 0x65, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- // second entry is readme file
- 'R', 'E', 'A', 'D', 'M', 'E', ' ', ' ', 'T', 'X', 'T', 0x20, 0x00, 0xC6, 0x52, 0x6D,
- 0x65, 0x43, 0x65, 0x43, 0x00, 0x00, 0x88, 0x6D, 0x65, 0x43, 0x02, 0x00,
- sizeof(README_CONTENTS) - 1, 0x00, 0x00, 0x00// readme's files size (4 Bytes)
+ {
+ // first entry is volume label
+ 'T', 'i', 'n', 'y', 'U', 'S', 'B', ' ', 'M', 'S', 'C', 0x08, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4F, 0x6D, 0x65, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ // second entry is readme file
+ 'R', 'E', 'A', 'D', 'M', 'E', ' ', ' ', 'T', 'X', 'T', 0x20, 0x00, 0xC6, 0x52, 0x6D,
+ 0x65, 0x43, 0x65, 0x43, 0x00, 0x00, 0x88, 0x6D, 0x65, 0x43, 0x02, 0x00,
+ sizeof(README_CONTENTS) - 1, 0x00, 0x00, 0x00// readme's files size (4 Bytes)
},
//------------- Block3: Readme Content -------------//
- README_CONTENTS
+ {README_CONTENTS}
};
// Invoked when received SCSI_CMD_INQUIRY, v2 with full inquiry response
@@ -126,9 +128,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
const char pid[] = "Mass Storage";
const char rev[] = "1.0";
- memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
- memcpy(inquiry_resp->product_id, pid, strlen(pid));
- memcpy(inquiry_resp->product_rev, rev, strlen(rev));
+ (void) strncpy((char*) inquiry_resp->vendor_id, vid, 8);
+ (void) strncpy((char*) inquiry_resp->product_id, pid, 16);
+ (void) strncpy((char*) inquiry_resp->product_rev, rev, 4);
return sizeof(scsi_inquiry_resp_t); // 36 bytes
}
@@ -141,8 +143,7 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) {
// RAM disk is ready until ejected
if (ejected) {
// Additional Sense 3A-00 is NOT_FOUND
- tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3a, 0x00);
- return false;
+ return tud_msc_set_sense(lun, SCSI_SENSE_NOT_READY, 0x3a, 0x00);
}
return true;
@@ -152,7 +153,6 @@ bool tud_msc_test_unit_ready_cb(uint8_t lun) {
// Application update block count and block size
void tud_msc_capacity_cb(uint8_t lun, uint32_t *block_count, uint16_t *block_size) {
(void) lun;
-
*block_count = DISK_BLOCK_NUM;
*block_size = DISK_BLOCK_SIZE;
}
@@ -192,7 +192,7 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void *buff
}
uint8_t const *addr = msc_disk[lba] + offset;
- memcpy(buffer, addr, bufsize);
+ (void) memcpy(buffer, addr, bufsize);
return (int32_t) bufsize;
}
@@ -213,11 +213,13 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
(void) lun;
// out of ramdisk
- if (lba >= DISK_BLOCK_NUM) return -1;
+ if (lba >= DISK_BLOCK_NUM) {
+ return -1;
+ }
#ifndef CFG_EXAMPLE_MSC_READONLY
uint8_t *addr = msc_disk[lba] + offset;
- memcpy(addr, buffer, bufsize);
+ (void) memcpy(addr, buffer, bufsize);
#else
(void) lba;
(void) offset;
@@ -231,17 +233,17 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t *
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
// - READ10 and WRITE10 has their own callbacks
int32_t tud_msc_scsi_cb(uint8_t lun, uint8_t const scsi_cmd[16], void *buffer, uint16_t bufsize) {
+ (void) lun;
+ (void) scsi_cmd;
(void) buffer;
(void) bufsize;
- switch (scsi_cmd[0]) {
- default:
- // Set Sense = Invalid Command Operation
- tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
+ // currently no other commands is supported
- // negative means error -> tinyusb could stall and/or response with failed status
- return -1;
- }
+ // Set Sense = Invalid Command Operation
+ (void) tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
+
+ return -1; // stall/failed command request;
}
#endif
diff --git a/examples/device/cdc_msc/src/tusb_config.h b/examples/device/cdc_msc/src/tusb_config.h
index 811d464e9..fdb2ddf18 100644
--- a/examples/device/cdc_msc/src/tusb_config.h
+++ b/examples/device/cdc_msc/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -113,4 +113,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/cdc_msc/src/usb_descriptors.c b/examples/device/cdc_msc/src/usb_descriptors.c
index 597a6b1e6..c668ea3a7 100644
--- a/examples/device/cdc_msc/src/usb_descriptors.c
+++ b/examples/device/cdc_msc/src/usb_descriptors.c
@@ -32,9 +32,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -42,7 +42,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -125,7 +125,7 @@ enum {
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN)
// full speed configuration
-uint8_t const desc_fs_configuration[] = {
+static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -140,7 +140,7 @@ uint8_t const desc_fs_configuration[] = {
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -152,10 +152,10 @@ uint8_t const desc_hs_configuration[] = {
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
@@ -223,7 +223,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] = {
+static char const *string_desc_arr[] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
diff --git a/examples/device/cdc_msc_freertos/Makefile b/examples/device/cdc_msc_freertos/Makefile
index 10cff57a0..dbab13395 100644
--- a/examples/device/cdc_msc_freertos/Makefile
+++ b/examples/device/cdc_msc_freertos/Makefile
@@ -1,9 +1,9 @@
RTOS = freertos
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
@@ -11,6 +11,6 @@ EXAMPLE_SOURCE = \
src/msc_disk.c \
src/usb_descriptors.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/cdc_msc_freertos/skip.txt b/examples/device/cdc_msc_freertos/skip.txt
index b73a6d8dd..69fc883e6 100644
--- a/examples/device/cdc_msc_freertos/skip.txt
+++ b/examples/device/cdc_msc_freertos/skip.txt
@@ -15,3 +15,4 @@ mcu:RAXXX
mcu:STM32L0
family:broadcom_32bit
family:broadcom_64bit
+family:nuc121_125
diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c
index 69f2435ba..4fb209fd0 100644
--- a/examples/device/cdc_msc_freertos/src/main.c
+++ b/examples/device/cdc_msc_freertos/src/main.c
@@ -37,7 +37,7 @@
#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
#endif
-#define CDC_STACK_SIZE configMINIMAL_STACK_SIZE
+#define CDC_STACK_SIZE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 2 : 1))
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
//--------------------------------------------------------------------+
diff --git a/examples/device/cdc_msc_freertos/src/msc_disk.c b/examples/device/cdc_msc_freertos/src/msc_disk.c
index 849712e6a..29ff86281 100644
--- a/examples/device/cdc_msc_freertos/src/msc_disk.c
+++ b/examples/device/cdc_msc_freertos/src/msc_disk.c
@@ -76,6 +76,7 @@ enum {
DISK_BLOCK_SIZE = 512
};
+static
#ifdef CFG_EXAMPLE_MSC_READONLY
const
#endif
@@ -198,9 +199,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t* inquiry_resp, uin
const char pid[] = "Mass Storage";
const char rev[] = "1.0";
- memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
- memcpy(inquiry_resp->product_id, pid, strlen(pid));
- memcpy(inquiry_resp->product_rev, rev, strlen(rev));
+ strncpy((char*) inquiry_resp->vendor_id, vid, 8);
+ strncpy((char*) inquiry_resp->product_id, pid, 16);
+ strncpy((char*) inquiry_resp->product_rev, rev, 4);
return sizeof(scsi_inquiry_resp_t); // 36 bytes
}
@@ -299,13 +300,11 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
return TUD_MSC_RET_ERROR;
}
- #ifdef CFG_EXAMPLE_MSC_READONLY
+#ifdef CFG_EXAMPLE_MSC_READONLY
(void) lun;
(void) buffer;
return bufsize;
- #endif
-
- #if CFG_EXAMPLE_MSC_ASYNC_IO
+#elif CFG_EXAMPLE_MSC_ASYNC_IO
io_ops_t io_ops = {.is_read = false, .lun = lun, .lba = lba, .offset = offset, .buffer = buffer, .bufsize = bufsize};
// Send IO operation to IO task
@@ -318,7 +317,7 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
tusb_time_delay_ms_api(CFG_EXAMPLE_MSC_IO_DELAY_MS);
return bufsize;
- #endif
+#endif
}
// Callback invoked when received an SCSI command not in built-in list below
@@ -326,12 +325,8 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
// - READ10 and WRITE10 has their own callbacks
int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
// read10 & write10 has their own callback and MUST not be handled here
-
- void const *response = NULL;
- int32_t resplen = 0;
-
- // most scsi handled is input
- bool in_xfer = true;
+ (void) buffer;
+ (void) bufsize;
switch (scsi_cmd[0]) {
default:
@@ -339,22 +334,10 @@ int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer,
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
// negative means error -> tinyusb could stall and/or response with failed status
- resplen = -1;
- break;
- }
-
- // return resplen must not larger than bufsize
- if (resplen > bufsize) { resplen = bufsize; }
-
- if (response && (resplen > 0)) {
- if (in_xfer) {
- memcpy(buffer, response, (size_t) resplen);
- } else {
- // SCSI output
- }
+ return -1;
}
- return (int32_t) resplen;
+ return -1;
}
#endif
diff --git a/examples/device/cdc_msc_freertos/src/tusb_config.h b/examples/device/cdc_msc_freertos/src/tusb_config.h
index 9cc3a18d1..6b1937a8d 100644
--- a/examples/device/cdc_msc_freertos/src/tusb_config.h
+++ b/examples/device/cdc_msc_freertos/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -120,4 +120,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/cdc_msc_freertos/src/usb_descriptors.c b/examples/device/cdc_msc_freertos/src/usb_descriptors.c
index cb440c209..4950f02e0 100644
--- a/examples/device/cdc_msc_freertos/src/usb_descriptors.c
+++ b/examples/device/cdc_msc_freertos/src/usb_descriptors.c
@@ -32,9 +32,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -42,7 +42,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -124,7 +124,7 @@ enum {
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN + TUD_MSC_DESC_LEN)
-uint8_t const desc_fs_configuration[] =
+static uint8_t const desc_fs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -140,7 +140,7 @@ uint8_t const desc_fs_configuration[] =
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] =
+static uint8_t const desc_hs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -153,10 +153,10 @@ uint8_t const desc_hs_configuration[] =
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier =
+static tusb_desc_device_qualifier_t const desc_device_qualifier =
{
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
@@ -225,7 +225,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] = {
+static char const *string_desc_arr[] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
diff --git a/examples/device/cdc_uac2/Makefile b/examples/device/cdc_uac2/Makefile
index 21dcdb0b2..6276be8d0 100644
--- a/examples/device/cdc_uac2/Makefile
+++ b/examples/device/cdc_uac2/Makefile
@@ -1,8 +1,8 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
@@ -11,6 +11,6 @@ EXAMPLE_SOURCE += \
src/uac2_app.c \
src/usb_descriptors.c \
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/cdc_uac2/src/cdc_app.c b/examples/device/cdc_uac2/src/cdc_app.c
index 2166c1d6b..6d18a0e69 100644
--- a/examples/device/cdc_uac2/src/cdc_app.c
+++ b/examples/device/cdc_uac2/src/cdc_app.c
@@ -29,33 +29,26 @@
#include "common.h"
// Invoked when cdc when line state changed e.g connected/disconnected
-void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
-{
+void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
(void) itf;
(void) rts;
- if (dtr)
- {
+ if (dtr) {
// Terminal connected
- }
- else
- {
+ } else {
// Terminal disconnected
}
}
// Invoked when CDC interface received data from host
-void tud_cdc_rx_cb(uint8_t itf)
-{
+void tud_cdc_rx_cb(uint8_t itf) {
uint8_t buf[64];
uint32_t count;
// connected() check for DTR bit
// Most but not all terminal client set this when making connection
- if (tud_cdc_connected())
- {
- if (tud_cdc_available()) // data is available
- {
+ if (tud_cdc_connected()) {
+ if (tud_cdc_available() > 0) {
count = tud_cdc_n_read(itf, buf, sizeof(buf));
(void) count;
diff --git a/examples/device/cdc_uac2/src/common.h b/examples/device/cdc_uac2/src/common.h
index f281024c7..ff8b7a953 100644
--- a/examples/device/cdc_uac2/src/common.h
+++ b/examples/device/cdc_uac2/src/common.h
@@ -31,4 +31,7 @@ enum
VOLUME_CTRL_SILENCE = 0x8000,
};
+void led_blinking_task(void);
+void audio_task(void);
+
#endif
diff --git a/examples/device/cdc_uac2/src/main.c b/examples/device/cdc_uac2/src/main.c
index bc87f6e3c..22c462be7 100644
--- a/examples/device/cdc_uac2/src/main.c
+++ b/examples/device/cdc_uac2/src/main.c
@@ -38,9 +38,6 @@ extern uint32_t blink_interval_ms;
#include "pico/stdlib.h"
#endif
-void led_blinking_task(void);
-void audio_task(void);
-
/*------------- MAIN -------------*/
int main(void)
{
diff --git a/examples/device/cdc_uac2/src/tusb_config.h b/examples/device/cdc_uac2/src/tusb_config.h
index 2e744f8d2..b7ece8b7c 100644
--- a/examples/device/cdc_uac2/src/tusb_config.h
+++ b/examples/device/cdc_uac2/src/tusb_config.h
@@ -24,8 +24,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -105,8 +105,6 @@ extern "C" {
// AUDIO CLASS DRIVER CONFIGURATION
//--------------------------------------------------------------------
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_HEADSET_STEREO_DESC_LEN
-
// How many formats are used, need to adjust USB descriptor if changed
#define CFG_TUD_AUDIO_FUNC_1_N_FORMATS 2
@@ -142,8 +140,8 @@ extern "C" {
// EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN) // Maximum EP IN size for all AS alternate settings used
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX // Example read FIFO every 1ms, so it should be 8 times larger for HS device
@@ -151,15 +149,12 @@ extern "C" {
// EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
#define CFG_TUD_AUDIO_ENABLE_EP_OUT 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_OUT TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_OUT TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
+#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_OUT TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
+#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_OUT TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_OUT, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_OUT) // Maximum EP IN size for all AS alternate settings used
#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX // Example read FIFO every 1ms, so it should be 8 times larger for HS device
-// Size of control request buffer
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
-
// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
@@ -171,4 +166,4 @@ extern "C" {
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/cdc_uac2/src/uac2_app.c b/examples/device/cdc_uac2/src/uac2_app.c
index a1a0dd73d..73a262d0c 100644
--- a/examples/device/cdc_uac2/src/uac2_app.c
+++ b/examples/device/cdc_uac2/src/uac2_app.c
@@ -67,7 +67,9 @@ uint8_t current_resolution;
void audio_task(void) {
static uint32_t start_ms = 0;
uint32_t curr_ms = board_millis();
- if (start_ms == curr_ms) return;// not enough time
+ if (start_ms == curr_ms) {
+ return; // not enough time
+ }
start_ms = curr_ms;
// When new data arrived, copy data from speaker buffer, to microphone buffer
// and send it over
@@ -80,22 +82,22 @@ void audio_task(void) {
}
// Helper for clock get requests
-static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t const *request)
+static bool tud_audio_clock_get_request(uint8_t rhport, audio20_control_request_t const *request)
{
TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ)
+ if (request->bControlSelector == AUDIO20_CS_CTRL_SAM_FREQ)
{
- if (request->bRequest == AUDIO_CS_REQ_CUR)
+ if (request->bRequest == AUDIO20_CS_REQ_CUR)
{
TU_LOG1("Clock get current freq %" PRIu32 "\r\n", current_sample_rate);
- audio_control_cur_4_t curf = { (int32_t) tu_htole32(current_sample_rate) };
+ audio20_control_cur_4_t curf = { (int32_t) tu_htole32(current_sample_rate) };
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &curf, sizeof(curf));
}
- else if (request->bRequest == AUDIO_CS_REQ_RANGE)
+ else if (request->bRequest == AUDIO20_CS_REQ_RANGE)
{
- audio_control_range_4_n_t(N_SAMPLE_RATES) rangef =
+ audio20_control_range_4_n_t(N_SAMPLE_RATES) rangef =
{
.wNumSubRanges = tu_htole16(N_SAMPLE_RATES)
};
@@ -111,10 +113,10 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &rangef, sizeof(rangef));
}
}
- else if (request->bControlSelector == AUDIO_CS_CTRL_CLK_VALID &&
- request->bRequest == AUDIO_CS_REQ_CUR)
+ else if (request->bControlSelector == AUDIO20_CS_CTRL_CLK_VALID &&
+ request->bRequest == AUDIO20_CS_REQ_CUR)
{
- audio_control_cur_1_t cur_valid = { .bCur = 1 };
+ audio20_control_cur_1_t cur_valid = { .bCur = 1 };
TU_LOG1("Clock get is valid %u\r\n", cur_valid.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &cur_valid, sizeof(cur_valid));
}
@@ -124,18 +126,18 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
}
// Helper for clock set requests
-static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf)
+static bool tud_audio_clock_set_request(uint8_t rhport, audio20_control_request_t const *request, uint8_t const *buf)
{
(void)rhport;
TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(request->bRequest == AUDIO20_CS_REQ_CUR);
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ)
+ if (request->bControlSelector == AUDIO20_CS_CTRL_SAM_FREQ)
{
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_4_t));
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_4_t));
- current_sample_rate = (uint32_t) ((audio_control_cur_4_t const *)buf)->bCur;
+ current_sample_rate = (uint32_t) ((audio20_control_cur_4_t const *)buf)->bCur;
TU_LOG1("Clock set current freq: %" PRIu32 "\r\n", current_sample_rate);
@@ -150,21 +152,21 @@ static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t
}
// Helper for feature unit get requests
-static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_request_t const *request)
+static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio20_control_request_t const *request)
{
TU_ASSERT(request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT);
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE && request->bRequest == AUDIO_CS_REQ_CUR)
+ if (request->bControlSelector == AUDIO20_FU_CTRL_MUTE && request->bRequest == AUDIO20_CS_REQ_CUR)
{
- audio_control_cur_1_t mute1 = { .bCur = mute[request->bChannelNumber] };
+ audio20_control_cur_1_t mute1 = { .bCur = mute[request->bChannelNumber] };
TU_LOG1("Get channel %u mute %d\r\n", request->bChannelNumber, mute1.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &mute1, sizeof(mute1));
}
- else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
+ else if (request->bControlSelector == AUDIO20_FU_CTRL_VOLUME)
{
- if (request->bRequest == AUDIO_CS_REQ_RANGE)
+ if (request->bRequest == AUDIO20_CS_REQ_RANGE)
{
- audio_control_range_2_n_t(1) range_vol = {
+ audio20_control_range_2_n_t(1) range_vol = {
.wNumSubRanges = tu_htole16(1),
.subrange[0] = { .bMin = tu_htole16(-VOLUME_CTRL_50_DB), tu_htole16(VOLUME_CTRL_0_DB), tu_htole16(256) }
};
@@ -172,9 +174,9 @@ static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_req
range_vol.subrange[0].bMin / 256, range_vol.subrange[0].bMax / 256, range_vol.subrange[0].bRes / 256);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &range_vol, sizeof(range_vol));
}
- else if (request->bRequest == AUDIO_CS_REQ_CUR)
+ else if (request->bRequest == AUDIO20_CS_REQ_CUR)
{
- audio_control_cur_2_t cur_vol = { .bCur = tu_htole16(volume[request->bChannelNumber]) };
+ audio20_control_cur_2_t cur_vol = { .bCur = tu_htole16(volume[request->bChannelNumber]) };
TU_LOG1("Get channel %u volume %d dB\r\n", request->bChannelNumber, cur_vol.bCur / 256);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *)request, &cur_vol, sizeof(cur_vol));
}
@@ -186,28 +188,28 @@ static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_req
}
// Helper for feature unit set requests
-static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf)
+static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio20_control_request_t const *request, uint8_t const *buf)
{
(void)rhport;
TU_ASSERT(request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(request->bRequest == AUDIO20_CS_REQ_CUR);
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE)
+ if (request->bControlSelector == AUDIO20_FU_CTRL_MUTE)
{
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_1_t));
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_1_t));
- mute[request->bChannelNumber] = ((audio_control_cur_1_t const *)buf)->bCur;
+ mute[request->bChannelNumber] = ((audio20_control_cur_1_t const *)buf)->bCur;
TU_LOG1("Set channel %d Mute: %d\r\n", request->bChannelNumber, mute[request->bChannelNumber]);
return true;
}
- else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME)
+ else if (request->bControlSelector == AUDIO20_FU_CTRL_VOLUME)
{
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_2_t));
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_2_t));
- volume[request->bChannelNumber] = ((audio_control_cur_2_t const *)buf)->bCur;
+ volume[request->bChannelNumber] = ((audio20_control_cur_2_t const *)buf)->bCur;
TU_LOG1("Set channel %d volume: %d dB\r\n", request->bChannelNumber, volume[request->bChannelNumber] / 256);
@@ -226,16 +228,15 @@ static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_req
//--------------------------------------------------------------------+
// Invoked when audio class specific get request received for an entity
-bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request)
-{
- audio_control_request_t const *request = (audio_control_request_t const *)p_request;
+bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ audio20_control_request_t const *request = (audio20_control_request_t const *)p_request;
- if (request->bEntityID == UAC2_ENTITY_CLOCK)
+ if (request->bEntityID == UAC2_ENTITY_CLOCK) {
return tud_audio_clock_get_request(rhport, request);
- if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT)
+ }
+ if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT) {
return tud_audio_feature_unit_get_request(rhport, request);
- else
- {
+ } else {
TU_LOG1("Get request not handled, entity = %d, selector = %d, request = %d\r\n",
request->bEntityID, request->bControlSelector, request->bRequest);
}
@@ -243,14 +244,15 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
}
// Invoked when audio class specific set request received for an entity
-bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf)
-{
- audio_control_request_t const *request = (audio_control_request_t const *)p_request;
+bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf) {
+ audio20_control_request_t const *request = (audio20_control_request_t const *)p_request;
- if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT)
+ if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT) {
return tud_audio_feature_unit_set_request(rhport, request, buf);
- if (request->bEntityID == UAC2_ENTITY_CLOCK)
+ }
+ if (request->bEntityID == UAC2_ENTITY_CLOCK) {
return tud_audio_clock_set_request(rhport, request, buf);
+ }
TU_LOG1("Set request not handled, entity = %d, selector = %d, request = %d\r\n",
request->bEntityID, request->bControlSelector, request->bRequest);
@@ -301,7 +303,9 @@ void led_blinking_task(void)
static bool led_state = false;
// Blink every interval ms
- if (board_millis() - start_ms < blink_interval_ms) return;
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return;
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/cdc_uac2/src/usb_descriptors.c b/examples/device/cdc_uac2/src/usb_descriptors.c
index da55bdb5a..e6caaa971 100644
--- a/examples/device/cdc_uac2/src/usb_descriptors.c
+++ b/examples/device/cdc_uac2/src/usb_descriptors.c
@@ -35,14 +35,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -116,7 +116,7 @@ uint8_t const * tud_descriptor_device_cb(void)
#define EPNUM_CDC_IN 0x84
#endif
-uint8_t const desc_fs_configuration[] =
+static uint8_t const desc_fs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -132,7 +132,7 @@ uint8_t const desc_fs_configuration[] =
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -144,10 +144,10 @@ uint8_t const desc_hs_configuration[] = {
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = 0x0100,
@@ -215,7 +215,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
@@ -248,14 +248,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/cdc_uac2/src/usb_descriptors.h b/examples/device/cdc_uac2/src/usb_descriptors.h
index 736feeefe..139384d3e 100644
--- a/examples/device/cdc_uac2/src/usb_descriptors.h
+++ b/examples/device/cdc_uac2/src/usb_descriptors.h
@@ -24,8 +24,8 @@
*
*/
-#ifndef _USB_DESCRIPTORS_H_
-#define _USB_DESCRIPTORS_H_
+#ifndef USB_DESCRIPTORS_H_
+#define USB_DESCRIPTORS_H_
// #include "tusb.h"
@@ -49,110 +49,110 @@ enum
ITF_NUM_TOTAL
};
-#define TUD_AUDIO_HEADSET_STEREO_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
- + TUD_AUDIO_DESC_STD_AC_LEN\
- + TUD_AUDIO_DESC_CS_AC_LEN\
- + TUD_AUDIO_DESC_CLK_SRC_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
+#define TUD_AUDIO_HEADSET_STEREO_DESC_LEN (TUD_AUDIO20_DESC_IAD_LEN\
+ + TUD_AUDIO20_DESC_STD_AC_LEN\
+ + TUD_AUDIO20_DESC_CS_AC_LEN\
+ + TUD_AUDIO20_DESC_CLK_SRC_LEN\
+ + TUD_AUDIO20_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(2)\
+ + TUD_AUDIO20_DESC_OUTPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_OUTPUT_TERM_LEN\
/* Interface 1, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
/* Interface 1, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
/* Interface 1, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
/* Interface 2, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
/* Interface 2, Alternate 1 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
/* Interface 2, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN)
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN)
#define TUD_AUDIO_HEADSET_STEREO_DESCRIPTOR(_stridx, _epout, _epin) \
/* Standard Interface Association Descriptor (IAD) */\
- TUD_AUDIO_DESC_IAD(/*_firstitfs*/ ITF_NUM_AUDIO_CONTROL, /*_nitfs*/ 3, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_IAD(/*_firstitfs*/ ITF_NUM_AUDIO_CONTROL, /*_nitfs*/ 3, /*_stridx*/ 0x00),\
/* Standard AC Interface Descriptor(4.7.1) */\
- TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
+ TUD_AUDIO20_DESC_STD_AC(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
/* Class-Specific AC Interface Header Descriptor(4.7.2) */\
- TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_HEADSET, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
+ TUD_AUDIO20_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO20_FUNC_HEADSET, /*_totallen*/ TUD_AUDIO20_DESC_CLK_SRC_LEN+TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(2)+TUD_AUDIO20_DESC_INPUT_TERM_LEN+TUD_AUDIO20_DESC_OUTPUT_TERM_LEN+TUD_AUDIO20_DESC_INPUT_TERM_LEN+TUD_AUDIO20_DESC_OUTPUT_TERM_LEN, /*_ctrl*/ AUDIO20_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
/* Clock Source Descriptor(4.7.2.1) */\
- TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ 3, /*_ctrl*/ 7, /*_assocTerm*/ 0x00, /*_stridx*/ 0x00), \
+ TUD_AUDIO20_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ 3, /*_ctrl*/ 7, /*_assocTerm*/ 0x00, /*_stridx*/ 0x00), \
/* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x02, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x02, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO20_CTRL_R << AUDIO20_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
/* Feature Unit Descriptor(4.7.2.8) */\
- TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL(/*_unitid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_srcid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrlch0master*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch1*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch2*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_FEATURE_UNIT(/*_unitid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_srcid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_stridx*/ 0x00, /*_ctrlch0master*/ (AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch1*/ (AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch2*/ (AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS)),\
/* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_OUT_HEADPHONES, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_OUT_HEADPHONES, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
/* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO20_CTRL_R << AUDIO20_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
/* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x05),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x05),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
/* Interface 1, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ADAPTIVE | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 2, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x04),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x04),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 2, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
/* Interface 2, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
#endif
diff --git a/examples/device/dfu/Makefile b/examples/device/dfu/Makefile
index 52a24cdb0..9e1eab4a2 100644
--- a/examples/device/dfu/Makefile
+++ b/examples/device/dfu/Makefile
@@ -1,14 +1,14 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
src/main.c \
src/usb_descriptors.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/dfu/src/usb_descriptors.c b/examples/device/dfu/src/usb_descriptors.c
index fd469aaf2..48c9985f3 100644
--- a/examples/device/dfu/src/usb_descriptors.c
+++ b/examples/device/dfu/src/usb_descriptors.c
@@ -33,14 +33,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -126,7 +126,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
@@ -158,14 +158,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/dfu_runtime/Makefile b/examples/device/dfu_runtime/Makefile
index 1b4d398cf..1a4b428dc 100644
--- a/examples/device/dfu_runtime/Makefile
+++ b/examples/device/dfu_runtime/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/dfu_runtime/src/main.c b/examples/device/dfu_runtime/src/main.c
index 37cb80093..5de651bcd 100644
--- a/examples/device/dfu_runtime/src/main.c
+++ b/examples/device/dfu_runtime/src/main.c
@@ -132,7 +132,9 @@ void led_blinking_task(void)
static bool led_state = false;
// Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/dfu_runtime/src/usb_descriptors.c b/examples/device/dfu_runtime/src/usb_descriptors.c
index 7ac53d255..5d5cf52cd 100644
--- a/examples/device/dfu_runtime/src/usb_descriptors.c
+++ b/examples/device/dfu_runtime/src/usb_descriptors.c
@@ -33,14 +33,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -122,7 +122,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
@@ -153,14 +153,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/dynamic_configuration/Makefile b/examples/device/dynamic_configuration/Makefile
index 1b4d398cf..1a4b428dc 100644
--- a/examples/device/dynamic_configuration/Makefile
+++ b/examples/device/dynamic_configuration/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/dynamic_configuration/src/main.c b/examples/device/dynamic_configuration/src/main.c
index 258cfcd02..dac74bb7a 100644
--- a/examples/device/dynamic_configuration/src/main.c
+++ b/examples/device/dynamic_configuration/src/main.c
@@ -109,23 +109,18 @@ void tud_resume_cb(void)
//--------------------------------------------------------------------+
// USB CDC
//--------------------------------------------------------------------+
-void cdc_task(void)
-{
- if ( tud_cdc_connected() )
- {
- // connected and there are data available
- if ( tud_cdc_available() )
- {
+void cdc_task(void) {
+ if (tud_cdc_connected()) {
+ // connected and there are data available read and echo back
+ if (tud_cdc_available()) {
uint8_t buf[64];
-
- // read and echo back
uint32_t count = tud_cdc_read(buf, sizeof(buf));
- for(uint32_t i=0; i<count; i++)
- {
+ for (uint32_t i = 0; i < count; i++) {
tud_cdc_write_char(buf[i]);
-
- if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
+ if (buf[i] == '\r') {
+ tud_cdc_write_char('\n');
+ }
}
tud_cdc_write_flush();
@@ -134,23 +129,18 @@ void cdc_task(void)
}
// Invoked when cdc when line state changed e.g connected/disconnected
-void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
-{
+void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
(void) itf;
// connected
- if ( dtr && rts )
- {
+ if (dtr && rts) {
// print initial message when connected
tud_cdc_write_str("\r\nTinyUSB CDC MSC device example\r\n");
}
}
// Invoked when CDC interface received data from host
-void tud_cdc_rx_cb(uint8_t itf)
-{
- (void) itf;
-}
+void tud_cdc_rx_cb(uint8_t itf) { (void) itf; }
//--------------------------------------------------------------------+
// MIDI Task
@@ -167,8 +157,7 @@ static const uint8_t note_sequence[] =
56,61,64,68,74,78,81,86,90,93,98,102
};
-void midi_task(void)
-{
+void midi_task(void) {
static uint32_t start_ms = 0;
uint8_t const cable_num = 0; // MIDI jack associated with USB endpoint
@@ -181,7 +170,9 @@ void midi_task(void)
while( tud_midi_available() ) tud_midi_packet_read(packet);
// send note every 1000 ms
- if (board_millis() - start_ms < 286) return; // not enough time
+ if (board_millis() - start_ms < 286) {
+ return; // not enough time
+ }
start_ms += 286;
// Previous positions in the note sequence.
@@ -189,7 +180,9 @@ void midi_task(void)
// If we currently are at position 0, set the
// previous position to the last note in the sequence.
- if (previous < 0) previous = sizeof(note_sequence) - 1;
+ if (previous < 0) {
+ previous = sizeof(note_sequence) - 1;
+ }
// Send Note On for current position at full velocity (127) on channel 1.
uint8_t note_on[3] = { 0x90 | channel, note_sequence[note_pos], 127 };
@@ -203,21 +196,24 @@ void midi_task(void)
note_pos++;
// If we are at the end of the sequence, start over.
- if (note_pos >= sizeof(note_sequence)) note_pos = 0;
+ if (note_pos >= sizeof(note_sequence)) {
+ note_pos = 0;
+ }
}
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
+void led_blinking_task(void) {
static uint32_t start_ms = 0;
static bool led_state = false;
// Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return;// not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
- led_state = 1 - led_state; // toggle
+ led_state = 1 - led_state;// toggle
}
diff --git a/examples/device/dynamic_configuration/src/msc_disk.c b/examples/device/dynamic_configuration/src/msc_disk.c
index ebc86e260..e95b2e197 100644
--- a/examples/device/dynamic_configuration/src/msc_disk.c
+++ b/examples/device/dynamic_configuration/src/msc_disk.c
@@ -43,6 +43,7 @@ enum
DISK_BLOCK_SIZE = 512
};
+static
#ifdef CFG_EXAMPLE_MSC_READONLY
const
#endif
@@ -126,9 +127,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
const char pid[] = "Mass Storage";
const char rev[] = "1.0";
- memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
- memcpy(inquiry_resp->product_id, pid, strlen(pid));
- memcpy(inquiry_resp->product_rev, rev, strlen(rev));
+ strncpy((char*) inquiry_resp->vendor_id, vid, 8);
+ strncpy((char*) inquiry_resp->product_id, pid, 16);
+ strncpy((char*) inquiry_resp->product_rev, rev, 4);
return sizeof(scsi_inquiry_resp_t); // 36 bytes
}
@@ -176,12 +177,13 @@ bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, boo
// Callback invoked when received READ10 command.
// Copy disk's data to buffer (up to bufsize) and return number of copied bytes.
-int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize)
-{
+int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buffer, uint32_t bufsize) {
(void) lun;
// out of ramdisk
- if ( lba >= DISK_BLOCK_NUM ) return -1;
+ if ( lba >= DISK_BLOCK_NUM ) {
+ return -1;
+ }
uint8_t const* addr = msc_disk[lba] + offset;
memcpy(buffer, addr, bufsize);
@@ -191,12 +193,13 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff
// Callback invoked when received WRITE10 command.
// Process data in buffer to disk's storage and return number of written bytes
-int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize)
-{
+int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t* buffer, uint32_t bufsize) {
(void) lun;
// out of ramdisk
- if ( lba >= DISK_BLOCK_NUM ) return -1;
+ if ( lba >= DISK_BLOCK_NUM ) {
+ return -1;
+ }
#ifndef CFG_EXAMPLE_MSC_READONLY
uint8_t* addr = msc_disk[lba] + offset;
@@ -211,42 +214,21 @@ int32_t tud_msc_write10_cb(uint8_t lun, uint32_t lba, uint32_t offset, uint8_t*
// Callback invoked when received an SCSI command not in built-in list below
// - READ_CAPACITY10, READ_FORMAT_CAPACITY, INQUIRY, MODE_SENSE6, REQUEST_SENSE
// - READ10 and WRITE10 has their own callbacks
-int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize)
-{
+int32_t tud_msc_scsi_cb (uint8_t lun, uint8_t const scsi_cmd[16], void* buffer, uint16_t bufsize) {
// read10 & write10 has their own callback and MUST not be handled here
+ (void) buffer;
+ (void) bufsize;
- void const* response = NULL;
- int32_t resplen = 0;
-
- // most scsi handled is input
- bool in_xfer = true;
-
- switch (scsi_cmd[0])
- {
+ switch (scsi_cmd[0]) {
default:
// Set Sense = Invalid Command Operation
tud_msc_set_sense(lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00);
// negative means error -> tinyusb could stall and/or response with failed status
- resplen = -1;
- break;
- }
-
- // return resplen must not larger than bufsize
- if ( resplen > bufsize ) resplen = bufsize;
-
- if ( response && (resplen > 0) )
- {
- if(in_xfer)
- {
- memcpy(buffer, response, (size_t) resplen);
- }else
- {
- // SCSI output
- }
+ return -1;
}
- return resplen;
+ return -1;
}
#endif
diff --git a/examples/device/dynamic_configuration/src/tusb_config.h b/examples/device/dynamic_configuration/src/tusb_config.h
index b9b3878cc..7309d97c9 100644
--- a/examples/device/dynamic_configuration/src/tusb_config.h
+++ b/examples/device/dynamic_configuration/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -112,4 +112,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/dynamic_configuration/src/usb_descriptors.c b/examples/device/dynamic_configuration/src/usb_descriptors.c
index 0a2049288..458b7c2a5 100644
--- a/examples/device/dynamic_configuration/src/usb_descriptors.c
+++ b/examples/device/dynamic_configuration/src/usb_descriptors.c
@@ -32,9 +32,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
// Configuration mode
// 0 : enumerated as CDC/MIDI. Board button is not pressed when enumerating
@@ -202,7 +202,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
@@ -232,14 +232,18 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
for ( size_t i = 0; i < chr_count; i++ ) {
diff --git a/examples/device/hid_boot_interface/Makefile b/examples/device/hid_boot_interface/Makefile
index 52a24cdb0..9e1eab4a2 100644
--- a/examples/device/hid_boot_interface/Makefile
+++ b/examples/device/hid_boot_interface/Makefile
@@ -1,14 +1,14 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
src/main.c \
src/usb_descriptors.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/hid_boot_interface/src/main.c b/examples/device/hid_boot_interface/src/main.c
index 45712cede..44a91db67 100644
--- a/examples/device/hid_boot_interface/src/main.c
+++ b/examples/device/hid_boot_interface/src/main.c
@@ -23,8 +23,8 @@
*
*/
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "bsp/board_api.h"
@@ -40,10 +40,10 @@
* - 1000 ms : device mounted
* - 2500 ms : device is suspended
*/
-enum {
+enum {
BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
+ BLINK_MOUNTED = 1000,
+ BLINK_SUSPENDED = 2500,
};
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
@@ -52,21 +52,16 @@ void led_blinking_task(void);
void hid_task(void);
/*------------- MAIN -------------*/
-int main(void)
-{
+int main(void) {
board_init();
// init device stack on configured roothub port
- tusb_rhport_init_t dev_init = {
- .role = TUSB_ROLE_DEVICE,
- .speed = TUSB_SPEED_AUTO
- };
+ tusb_rhport_init_t dev_init = {.role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO};
tusb_init(BOARD_TUD_RHPORT, &dev_init);
board_init_after_tusb();
- while (1)
- {
+ while (1) {
tud_task(); // tinyusb device task
led_blinking_task();
@@ -81,29 +76,25 @@ int main(void)
//--------------------------------------------------------------------+
// Invoked when device is mounted
-void tud_mount_cb(void)
-{
+void tud_mount_cb(void) {
blink_interval_ms = BLINK_MOUNTED;
}
// Invoked when device is unmounted
-void tud_umount_cb(void)
-{
+void tud_umount_cb(void) {
blink_interval_ms = BLINK_NOT_MOUNTED;
}
// Invoked when usb bus is suspended
// remote_wakeup_en : if host allow us to perform remote wakeup
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
-void tud_suspend_cb(bool remote_wakeup_en)
-{
- (void) remote_wakeup_en;
+void tud_suspend_cb(bool remote_wakeup_en) {
+ (void)remote_wakeup_en;
blink_interval_ms = BLINK_SUSPENDED;
}
// Invoked when usb bus is resumed
-void tud_resume_cb(void)
-{
+void tud_resume_cb(void) {
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
}
@@ -113,59 +104,54 @@ void tud_resume_cb(void)
// 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)
-{
+void hid_task(void) {
// Poll every 10ms
- const uint32_t interval_ms = 10;
- static uint32_t start_ms = 0;
+ const uint32_t interval_ms = 10;
+ static uint32_t start_ms = 0;
- if ( board_millis() - start_ms < interval_ms) return; // not enough time
+ if (board_millis() - start_ms < interval_ms) {
+ return; // not enough time
+ }
start_ms += interval_ms;
uint32_t const btn = board_button_read();
- if ( tud_suspended() && btn )
- {
+ 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
- {
+ } else {
// keyboard interface
- if ( tud_hid_n_ready(ITF_NUM_KEYBOARD) )
- {
+ if (tud_hid_n_ready(ITF_NUM_KEYBOARD)) {
// used to avoid send multiple consecutive zero report for keyboard
static bool has_keyboard_key = false;
uint8_t const report_id = 0;
uint8_t const modifier = 0;
- if ( btn )
- {
- uint8_t keycode[6] = { 0 };
- keycode[0] = HID_KEY_ARROW_RIGHT;
+ if (btn) {
+ uint8_t keycode[6] = {0};
+ keycode[0] = HID_KEY_ARROW_RIGHT;
tud_hid_n_keyboard_report(ITF_NUM_KEYBOARD, report_id, modifier, keycode);
has_keyboard_key = true;
- }else
- {
+ } else {
// send empty key report if previously has key pressed
- if (has_keyboard_key) tud_hid_n_keyboard_report(ITF_NUM_KEYBOARD, report_id, modifier, NULL);
+ if (has_keyboard_key) {
+ tud_hid_n_keyboard_report(ITF_NUM_KEYBOARD, report_id, modifier, NULL);
+ }
has_keyboard_key = false;
}
}
// mouse interface
- if ( tud_hid_n_ready(ITF_NUM_MOUSE) )
- {
- if ( btn )
- {
+ if (tud_hid_n_ready(ITF_NUM_MOUSE)) {
+ if (btn) {
uint8_t const report_id = 0;
uint8_t const button_mask = 0;
- int8_t const vertical = 0;
- int8_t const horizontal = 0;
- int8_t const delta = 5;
+ int8_t const vertical = 0;
+ int8_t const horizontal = 0;
+ int8_t const delta = 5;
tud_hid_n_mouse_report(ITF_NUM_MOUSE, report_id, button_mask, delta, delta, vertical, horizontal);
}
@@ -175,10 +161,9 @@ void hid_task(void)
// Invoked when received SET_PROTOCOL request
// protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1)
-void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol)
-{
- (void) instance;
- (void) protocol;
+void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol) {
+ (void)instance;
+ (void)protocol;
// nothing to do since we use the same compatible boot report for both Boot and Report mode.
// TODO set a indicator for user
@@ -187,11 +172,10 @@ void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol)
// 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 instance, uint8_t const* report, uint16_t len)
-{
- (void) instance;
- (void) report;
- (void) len;
+void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_t len) {
+ (void)instance;
+ (void)report;
+ (void)len;
// nothing to do
}
@@ -199,42 +183,40 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint16_
// 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
-uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
-{
+uint16_t tud_hid_get_report_cb(
+ uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) {
// TODO not Implemented
- (void) instance;
- (void) report_id;
- (void) report_type;
- (void) buffer;
- (void) reqlen;
+ (void)instance;
+ (void)report_id;
+ (void)report_type;
+ (void)buffer;
+ (void)reqlen;
return 0;
}
// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
-void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
-{
- (void) report_id;
+void tud_hid_set_report_cb(
+ uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize) {
+ (void)report_id;
// keyboard interface
- if (instance == ITF_NUM_KEYBOARD)
- {
+ if (instance == ITF_NUM_KEYBOARD) {
// Set keyboard LED e.g Capslock, Numlock etc...
- if (report_type == HID_REPORT_TYPE_OUTPUT)
- {
+ if (report_type == HID_REPORT_TYPE_OUTPUT) {
// bufsize should be (at least) 1
- if ( bufsize < 1 ) return;
+ if (bufsize < 1) {
+ return;
+ }
uint8_t const kbd_leds = buffer[0];
- if (kbd_leds & KEYBOARD_LED_CAPSLOCK)
- {
+ if (kbd_leds & KEYBOARD_LED_CAPSLOCK) {
// Capslock On: disable blink, turn led on
blink_interval_ms = 0;
board_led_write(true);
- }else
- {
+ } else {
// Caplocks Off: back to normal blink
board_led_write(false);
blink_interval_ms = BLINK_MOUNTED;
@@ -246,16 +228,19 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
- static uint32_t start_ms = 0;
- static bool led_state = false;
+void led_blinking_task(void) {
+ static uint32_t start_ms = 0;
+ static bool led_state = false;
// blink is disabled
- if (!blink_interval_ms) return;
+ if (!blink_interval_ms) {
+ return;
+ }
// Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/hid_boot_interface/src/tusb_config.h b/examples/device/hid_boot_interface/src/tusb_config.h
index 52723e09f..5d6fd62e1 100644
--- a/examples/device/hid_boot_interface/src/tusb_config.h
+++ b/examples/device/hid_boot_interface/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -104,4 +104,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/hid_boot_interface/src/usb_descriptors.c b/examples/device/hid_boot_interface/src/usb_descriptors.c
index d68ef16d9..b5c31a94a 100644
--- a/examples/device/hid_boot_interface/src/usb_descriptors.c
+++ b/examples/device/hid_boot_interface/src/usb_descriptors.c
@@ -33,60 +33,49 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4))
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
-{
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
- .bcdUSB = 0x0200,
- .bDeviceClass = 0x00,
- .bDeviceSubClass = 0x00,
- .bDeviceProtocol = 0x00,
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+static tusb_desc_device_t const desc_device = {
+ .bLength = sizeof(tusb_desc_device_t),
+ .bDescriptorType = TUSB_DESC_DEVICE,
+ .bcdUSB = 0x0200,
+ .bDeviceClass = 0x00,
+ .bDeviceSubClass = 0x00,
+ .bDeviceProtocol = 0x00,
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
- .idVendor = 0xCafe,
- .idProduct = USB_PID,
- .bcdDevice = 0x0100,
+ .idVendor = 0xCafe,
+ .idProduct = USB_PID,
+ .bcdDevice = 0x0100,
- .iManufacturer = 0x01,
- .iProduct = 0x02,
- .iSerialNumber = 0x03,
+ .iManufacturer = 0x01,
+ .iProduct = 0x02,
+ .iSerialNumber = 0x03,
- .bNumConfigurations = 0x01
-};
+ .bNumConfigurations = 0x01};
// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
-uint8_t const * tud_descriptor_device_cb(void)
-{
- return (uint8_t const *) &desc_device;
+uint8_t const *tud_descriptor_device_cb(void) {
+ return (uint8_t const *)&desc_device;
}
//--------------------------------------------------------------------+
// HID Report Descriptor
//--------------------------------------------------------------------+
-uint8_t const desc_hid_keyboard_report[] =
-{
- TUD_HID_REPORT_DESC_KEYBOARD()
-};
+uint8_t const desc_hid_keyboard_report[] = {TUD_HID_REPORT_DESC_KEYBOARD()};
-uint8_t const desc_hid_mouse_report[] =
-{
- TUD_HID_REPORT_DESC_MOUSE()
-};
+uint8_t const desc_hid_mouse_report[] = {TUD_HID_REPORT_DESC_MOUSE()};
// Invoked when received GET HID REPORT DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance)
-{
+uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance) {
return (instance == 0) ? desc_hid_keyboard_report : desc_hid_mouse_report;
}
@@ -94,36 +83,37 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance)
// Configuration Descriptor
//--------------------------------------------------------------------+
-#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + 2*TUD_HID_DESC_LEN)
+#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + 2 * TUD_HID_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
- // 1 Interrupt, 2 Bulk, 3 Iso, 4 Interrupt, 5 Bulk etc ...
- #define EPNUM_KEYBOARD 0x81
- #define EPNUM_MOUSE 0x84
+// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number
+// 1 Interrupt, 2 Bulk, 3 Iso, 4 Interrupt, 5 Bulk etc ...
+#define EPNUM_KEYBOARD 0x81
+#define EPNUM_MOUSE 0x84
#else
- #define EPNUM_KEYBOARD 0x81
- #define EPNUM_MOUSE 0x82
+#define EPNUM_KEYBOARD 0x81
+#define EPNUM_MOUSE 0x82
#endif
-uint8_t const desc_configuration[] =
-{
+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 address, size & polling interval
- TUD_HID_DESCRIPTOR(ITF_NUM_KEYBOARD, 0, HID_ITF_PROTOCOL_KEYBOARD, sizeof(desc_hid_keyboard_report), EPNUM_KEYBOARD, CFG_TUD_HID_EP_BUFSIZE, 10),
+ TUD_HID_DESCRIPTOR(
+ ITF_NUM_KEYBOARD, 0, HID_ITF_PROTOCOL_KEYBOARD, sizeof(desc_hid_keyboard_report), EPNUM_KEYBOARD,
+ 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_MOUSE, 0, HID_ITF_PROTOCOL_MOUSE, sizeof(desc_hid_mouse_report), EPNUM_MOUSE, CFG_TUD_HID_EP_BUFSIZE, 10)
-};
+ TUD_HID_DESCRIPTOR(
+ ITF_NUM_MOUSE, 0, HID_ITF_PROTOCOL_MOUSE, sizeof(desc_hid_mouse_report), EPNUM_MOUSE, CFG_TUD_HID_EP_BUFSIZE,
+ 10)};
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
-{
- (void) index; // for multiple configurations
+uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
+ (void)index; // for multiple configurations
return desc_configuration;
}
@@ -140,12 +130,11 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
-{
- (const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
- "TinyUSB", // 1: Manufacturer
- "TinyUSB Device", // 2: Product
- NULL, // 3: Serials will use unique ID if possible
+static char const *string_desc_arr[] = {
+ (const char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
+ "TinyUSB", // 1: Manufacturer
+ "TinyUSB Device", // 2: Product
+ NULL, // 3: Serials will use unique ID if possible
};
static uint16_t _desc_str[32 + 1];
@@ -153,41 +142,44 @@ static uint16_t _desc_str[32 + 1];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
- (void) langid;
+ (void)langid;
size_t chr_count;
- switch ( index ) {
+ switch (index) {
case STRID_LANGID:
memcpy(&_desc_str[1], string_desc_arr[0], 2);
chr_count = 1;
break;
- case STRID_SERIAL:
- chr_count = board_usb_get_serial(_desc_str + 1, 32);
- break;
+ case STRID_SERIAL: chr_count = board_usb_get_serial(_desc_str + 1, 32); break;
default:
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (!(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0]))) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
+
size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
+ for (size_t i = 0; i < chr_count; i++) {
_desc_str[1 + i] = str[i];
}
break;
}
// first byte is length (including header), second byte is string type
- _desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
+ _desc_str[0] = (uint16_t)((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
return _desc_str;
}
diff --git a/examples/device/hid_composite/Makefile b/examples/device/hid_composite/Makefile
index 1b4d398cf..1a4b428dc 100644
--- a/examples/device/hid_composite/Makefile
+++ b/examples/device/hid_composite/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/hid_composite/src/main.c b/examples/device/hid_composite/src/main.c
index 89dab0bdc..9693d564d 100644
--- a/examples/device/hid_composite/src/main.c
+++ b/examples/device/hid_composite/src/main.c
@@ -23,8 +23,8 @@
*
*/
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "bsp/board_api.h"
@@ -41,10 +41,10 @@
* - 1000 ms : device mounted
* - 2500 ms : device is suspended
*/
-enum {
+enum {
BLINK_NOT_MOUNTED = 250,
- BLINK_MOUNTED = 1000,
- BLINK_SUSPENDED = 2500,
+ BLINK_MOUNTED = 1000,
+ BLINK_SUSPENDED = 2500,
};
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
@@ -53,24 +53,18 @@ void led_blinking_task(void);
void hid_task(void);
/*------------- MAIN -------------*/
-int main(void)
-{
+int main(void) {
board_init();
// init device stack on configured roothub port
- tusb_rhport_init_t dev_init = {
- .role = TUSB_ROLE_DEVICE,
- .speed = TUSB_SPEED_AUTO
- };
+ tusb_rhport_init_t dev_init = {.role = TUSB_ROLE_DEVICE, .speed = TUSB_SPEED_AUTO};
tusb_init(BOARD_TUD_RHPORT, &dev_init);
board_init_after_tusb();
- while (1)
- {
+ while (1) {
tud_task(); // tinyusb device task
led_blinking_task();
-
hid_task();
}
}
@@ -80,29 +74,25 @@ int main(void)
//--------------------------------------------------------------------+
// Invoked when device is mounted
-void tud_mount_cb(void)
-{
+void tud_mount_cb(void) {
blink_interval_ms = BLINK_MOUNTED;
}
// Invoked when device is unmounted
-void tud_umount_cb(void)
-{
+void tud_umount_cb(void) {
blink_interval_ms = BLINK_NOT_MOUNTED;
}
// Invoked when usb bus is suspended
// remote_wakeup_en : if host allow us to perform remote wakeup
// Within 7ms, device must draw an average of current less than 2.5 mA from bus
-void tud_suspend_cb(bool remote_wakeup_en)
-{
- (void) remote_wakeup_en;
+void tud_suspend_cb(bool remote_wakeup_en) {
+ (void)remote_wakeup_en;
blink_interval_ms = BLINK_SUSPENDED;
}
// Invoked when usb bus is resumed
-void tud_resume_cb(void)
-{
+void tud_resume_cb(void) {
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
}
@@ -110,138 +100,128 @@ void tud_resume_cb(void)
// USB HID
//--------------------------------------------------------------------+
-static void send_hid_report(uint8_t report_id, uint32_t btn)
-{
+static void send_hid_report(uint8_t report_id, uint32_t btn) {
// skip if hid is not ready yet
- if ( !tud_hid_ready() ) return;
+ if (!tud_hid_ready()) {
+ return;
+ }
- switch(report_id)
- {
- case REPORT_ID_KEYBOARD:
- {
+ 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;
+ if (btn != 0u) {
+ uint8_t keycode[6] = {0};
+ keycode[0] = HID_KEY_A;
tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, keycode);
has_keyboard_key = true;
- }else
- {
+ } else {
// send empty key report if previously has key pressed
- if (has_keyboard_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL);
+ if (has_keyboard_key) {
+ tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL);
+ }
has_keyboard_key = false;
}
+ break;
}
- break;
- case REPORT_ID_MOUSE:
- {
+ 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;
}
- break;
- case REPORT_ID_CONSUMER_CONTROL:
- {
+ case REPORT_ID_CONSUMER_CONTROL: {
// use to avoid send multiple consecutive zero report
static bool has_consumer_key = false;
- if ( btn )
- {
+ if (btn != 0u) {
// 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
- {
+ } 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);
+ if (has_consumer_key) {
+ tud_hid_report(REPORT_ID_CONSUMER_CONTROL, &empty_key, 2);
+ }
has_consumer_key = false;
}
+ break;
}
- break;
- case REPORT_ID_GAMEPAD:
- {
+ 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
- };
+ 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;
+ if (btn != 0u) {
+ 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;
+ } else {
+ report.hat = GAMEPAD_HAT_CENTERED;
report.buttons = 0;
- if (has_gamepad_key) tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
+ if (has_gamepad_key) {
+ tud_hid_report(REPORT_ID_GAMEPAD, &report, sizeof(report));
+ }
has_gamepad_key = false;
}
+ break;
}
- break;
case REPORT_ID_STYLUS_PEN: {
- static bool touch_state = false;
- hid_stylus_report_t report = {
- .attr = 0,
- .x = 0,
- .y = 0
- };
+ static bool touch_state = false;
+ hid_stylus_report_t report = {.attr = 0, .x = 0, .y = 0};
- if (btn) {
+ if (btn != 0u) {
report.attr = STYLUS_ATTR_TIP_SWITCH | STYLUS_ATTR_IN_RANGE;
- report.x = 100;
- report.y = 100;
+ report.x = 100;
+ report.y = 100;
tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
touch_state = true;
} else {
report.attr = 0;
- if (touch_state) tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
+ if (touch_state) {
+ tud_hid_report(REPORT_ID_STYLUS_PEN, &report, sizeof(report));
+ }
touch_state = false;
}
+ break;
}
- break;
- default: break;
+
+ default: break; // unknown report id
}
}
// 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)
-{
+void hid_task(void) {
// Poll every 10ms
- const uint32_t interval_ms = 10;
- static uint32_t start_ms = 0;
+ const uint32_t interval_ms = 10;
+ static uint32_t start_ms = 0;
- if ( board_millis() - start_ms < interval_ms) return; // not enough time
+ if (board_millis() - start_ms < interval_ms) {
+ return; // not enough time
+ }
start_ms += interval_ms;
uint32_t const btn = board_button_read();
// Remote wakeup
- if ( tud_suspended() && btn )
- {
+ if (tud_suspended() && btn != 0u) {
// Wake up host if we are in suspend mode
// and REMOTE_WAKEUP feature is enabled by host
tud_remote_wakeup();
- }else
- {
+ } 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);
}
@@ -250,15 +230,13 @@ void hid_task(void)
// 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 instance, uint8_t const* report, uint16_t len)
-{
- (void) instance;
- (void) len;
+void tud_hid_report_complete_cb(uint8_t instance, uint8_t const *report, uint16_t len) {
+ (void)instance;
+ (void)len;
uint8_t next_report_id = report[0] + 1u;
- if (next_report_id < REPORT_ID_COUNT)
- {
+ if (next_report_id < REPORT_ID_COUNT) {
send_hid_report(next_report_id, board_button_read());
}
}
@@ -266,41 +244,39 @@ void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint16_
// 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
-uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
-{
+uint16_t tud_hid_get_report_cb(
+ uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) {
// TODO not Implemented
- (void) instance;
- (void) report_id;
- (void) report_type;
- (void) buffer;
- (void) reqlen;
+ (void)instance;
+ (void)report_id;
+ (void)report_type;
+ (void)buffer;
+ (void)reqlen;
return 0;
}
// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
-void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
-{
- (void) instance;
+void tud_hid_set_report_cb(
+ uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize) {
+ (void)instance;
- if (report_type == HID_REPORT_TYPE_OUTPUT)
- {
+ if (report_type == HID_REPORT_TYPE_OUTPUT) {
// Set keyboard LED e.g Capslock, Numlock etc...
- if (report_id == REPORT_ID_KEYBOARD)
- {
+ if (report_id == REPORT_ID_KEYBOARD) {
// bufsize should be (at least) 1
- if ( bufsize < 1 ) return;
+ if (bufsize < 1) {
+ return;
+ }
uint8_t const kbd_leds = buffer[0];
- if (kbd_leds & KEYBOARD_LED_CAPSLOCK)
- {
+ if ((kbd_leds & KEYBOARD_LED_CAPSLOCK) != 0u) {
// Capslock On: disable blink, turn led on
blink_interval_ms = 0;
board_led_write(true);
- }else
- {
+ } else {
// Caplocks Off: back to normal blink
board_led_write(false);
blink_interval_ms = BLINK_MOUNTED;
@@ -312,16 +288,19 @@ void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_
//--------------------------------------------------------------------+
// BLINKING TASK
//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
- static uint32_t start_ms = 0;
- static bool led_state = false;
+void led_blinking_task(void) {
+ static uint32_t start_ms = 0;
+ static bool led_state = false;
// blink is disabled
- if (!blink_interval_ms) return;
+ if (0u == blink_interval_ms) {
+ return;
+ }
// Blink every interval ms
- if ( board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
start_ms += blink_interval_ms;
board_led_write(led_state);
diff --git a/examples/device/hid_composite/src/tusb_config.h b/examples/device/hid_composite/src/tusb_config.h
index 6bd32c427..895745ed2 100644
--- a/examples/device/hid_composite/src/tusb_config.h
+++ b/examples/device/hid_composite/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -104,4 +104,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/hid_composite/src/usb_descriptors.c b/examples/device/hid_composite/src/usb_descriptors.c
index ce7fbd13f..46e4b63f9 100644
--- a/examples/device/hid_composite/src/usb_descriptors.c
+++ b/examples/device/hid_composite/src/usb_descriptors.c
@@ -33,9 +33,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -43,7 +43,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -120,10 +120,10 @@ uint8_t const desc_configuration[] =
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier =
+static tusb_desc_device_qualifier_t const desc_device_qualifier =
{
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
@@ -188,7 +188,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
diff --git a/examples/device/hid_composite_freertos/Makefile b/examples/device/hid_composite_freertos/Makefile
index bd625b345..3c421af74 100644
--- a/examples/device/hid_composite_freertos/Makefile
+++ b/examples/device/hid_composite_freertos/Makefile
@@ -1,15 +1,15 @@
RTOS = freertos
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
src/main.c \
src/usb_descriptors.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/hid_composite_freertos/src/main.c b/examples/device/hid_composite_freertos/src/main.c
index 0eb13add3..391e3c42a 100644
--- a/examples/device/hid_composite_freertos/src/main.c
+++ b/examples/device/hid_composite_freertos/src/main.c
@@ -53,7 +53,7 @@
#define USBD_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
#endif
-#define HID_STACK_SZIE configMINIMAL_STACK_SIZE
+#define HID_STACK_SZIE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 2 : 1))
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
diff --git a/examples/device/hid_composite_freertos/src/tusb_config.h b/examples/device/hid_composite_freertos/src/tusb_config.h
index b28033a0c..ad067ac82 100644
--- a/examples/device/hid_composite_freertos/src/tusb_config.h
+++ b/examples/device/hid_composite_freertos/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -111,4 +111,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/hid_composite_freertos/src/usb_descriptors.c b/examples/device/hid_composite_freertos/src/usb_descriptors.c
index 3f231fecc..a745c17b5 100644
--- a/examples/device/hid_composite_freertos/src/usb_descriptors.c
+++ b/examples/device/hid_composite_freertos/src/usb_descriptors.c
@@ -33,9 +33,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -43,7 +43,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -119,10 +119,10 @@ uint8_t const desc_configuration[] =
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier =
+static tusb_desc_device_qualifier_t const desc_device_qualifier =
{
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
@@ -185,7 +185,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
diff --git a/examples/device/hid_generic_inout/Makefile b/examples/device/hid_generic_inout/Makefile
index 1b4d398cf..1a4b428dc 100644
--- a/examples/device/hid_generic_inout/Makefile
+++ b/examples/device/hid_generic_inout/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/hid_generic_inout/src/tusb_config.h b/examples/device/hid_generic_inout/src/tusb_config.h
index 98143ac4d..58dc52afc 100644
--- a/examples/device/hid_generic_inout/src/tusb_config.h
+++ b/examples/device/hid_generic_inout/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -104,4 +104,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/hid_generic_inout/src/usb_descriptors.c b/examples/device/hid_generic_inout/src/usb_descriptors.c
index 64f6d17ae..f26333d50 100644
--- a/examples/device/hid_generic_inout/src/usb_descriptors.c
+++ b/examples/device/hid_generic_inout/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -130,7 +130,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
diff --git a/examples/device/hid_multiple_interface/Makefile b/examples/device/hid_multiple_interface/Makefile
index 1b4d398cf..1a4b428dc 100644
--- a/examples/device/hid_multiple_interface/Makefile
+++ b/examples/device/hid_multiple_interface/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/hid_multiple_interface/src/tusb_config.h b/examples/device/hid_multiple_interface/src/tusb_config.h
index 49dc962fe..e1805017d 100644
--- a/examples/device/hid_multiple_interface/src/tusb_config.h
+++ b/examples/device/hid_multiple_interface/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -104,4 +104,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/hid_multiple_interface/src/usb_descriptors.c b/examples/device/hid_multiple_interface/src/usb_descriptors.c
index 86f567e8e..cd2d93c44 100644
--- a/examples/device/hid_multiple_interface/src/usb_descriptors.c
+++ b/examples/device/hid_multiple_interface/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -146,7 +146,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
diff --git a/examples/device/midi_test/Makefile b/examples/device/midi_test/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/midi_test/Makefile
+++ b/examples/device/midi_test/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/midi_test/src/tusb_config.h b/examples/device/midi_test/src/tusb_config.h
index 314dde438..f4282b2d7 100644
--- a/examples/device/midi_test/src/tusb_config.h
+++ b/examples/device/midi_test/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -105,4 +105,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/midi_test/src/usb_descriptors.c b/examples/device/midi_test/src/usb_descriptors.c
index 384742ae8..e969f33a3 100644
--- a/examples/device/midi_test/src/usb_descriptors.c
+++ b/examples/device/midi_test/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
@@ -98,7 +98,7 @@ enum {
#define EPNUM_MIDI_IN 0x81
#endif
-uint8_t const desc_fs_configuration[] = {
+static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -107,7 +107,7 @@ uint8_t const desc_fs_configuration[] = {
};
#if TUD_OPT_HIGH_SPEED
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -143,7 +143,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] = {
+static char const *string_desc_arr[] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
diff --git a/examples/device/midi_test_freertos/Makefile b/examples/device/midi_test_freertos/Makefile
index 26cd83486..ebacfecdf 100644
--- a/examples/device/midi_test_freertos/Makefile
+++ b/examples/device/midi_test_freertos/Makefile
@@ -1,15 +1,15 @@
RTOS = freertos
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
src/main.c \
src/usb_descriptors.c \
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/midi_test_freertos/src/main.c b/examples/device/midi_test_freertos/src/main.c
index 9dd66c526..f5267214e 100644
--- a/examples/device/midi_test_freertos/src/main.c
+++ b/examples/device/midi_test_freertos/src/main.c
@@ -48,7 +48,7 @@
#endif
#define BLINKY_STACK_SIZE configMINIMAL_STACK_SIZE
-#define MIDI_STACK_SIZE configMINIMAL_STACK_SIZE
+#define MIDI_STACK_SIZE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 2 : 1))
// static task
#if configSUPPORT_STATIC_ALLOCATION
diff --git a/examples/device/midi_test_freertos/src/tusb_config.h b/examples/device/midi_test_freertos/src/tusb_config.h
index 0ffdc37fb..c158f5197 100644
--- a/examples/device/midi_test_freertos/src/tusb_config.h
+++ b/examples/device/midi_test_freertos/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -105,4 +105,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/midi_test_freertos/src/usb_descriptors.c b/examples/device/midi_test_freertos/src/usb_descriptors.c
index 384742ae8..e969f33a3 100644
--- a/examples/device/midi_test_freertos/src/usb_descriptors.c
+++ b/examples/device/midi_test_freertos/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
@@ -98,7 +98,7 @@ enum {
#define EPNUM_MIDI_IN 0x81
#endif
-uint8_t const desc_fs_configuration[] = {
+static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -107,7 +107,7 @@ uint8_t const desc_fs_configuration[] = {
};
#if TUD_OPT_HIGH_SPEED
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -143,7 +143,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] = {
+static char const *string_desc_arr[] = {
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Device", // 2: Product
diff --git a/examples/device/msc_dual_lun/Makefile b/examples/device/msc_dual_lun/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/msc_dual_lun/Makefile
+++ b/examples/device/msc_dual_lun/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/msc_dual_lun/src/msc_disk_dual.c b/examples/device/msc_dual_lun/src/msc_disk_dual.c
index 775fa047e..694da11db 100644
--- a/examples/device/msc_dual_lun/src/msc_disk_dual.c
+++ b/examples/device/msc_dual_lun/src/msc_disk_dual.c
@@ -217,9 +217,9 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
const char pid[] = "Mass Storage";
const char rev[] = "1.0";
- memcpy(inquiry_resp->vendor_id, vid, strlen(vid));
- memcpy(inquiry_resp->product_id, pid, strlen(pid));
- memcpy(inquiry_resp->product_rev, rev, strlen(rev));
+ strncpy((char*) inquiry_resp->vendor_id, vid, 8);
+ strncpy((char*) inquiry_resp->product_id, pid, 16);
+ strncpy((char*) inquiry_resp->product_rev, rev, 4);
return sizeof(scsi_inquiry_resp_t); // 36 bytes
}
@@ -227,9 +227,7 @@ uint32_t tud_msc_inquiry2_cb(uint8_t lun, scsi_inquiry_resp_t *inquiry_resp, uin
// Invoked when received Test Unit Ready command.
// return true allowing host to read/write this LUN e.g SD card inserted
bool tud_msc_test_unit_ready_cb(uint8_t lun) {
- if ( lun == 1 && board_button_read() ) return false;
-
- return true; // RAM disk is always ready
+ return ( lun == 1 && board_button_read() ) ? false : true;
}
// Invoked when received SCSI_CMD_READ_CAPACITY_10 and SCSI_CMD_READ_FORMAT_CAPACITY to determine the disk size
diff --git a/examples/device/msc_dual_lun/src/tusb_config.h b/examples/device/msc_dual_lun/src/tusb_config.h
index 9cbbbade9..4fb6816c6 100644
--- a/examples/device/msc_dual_lun/src/tusb_config.h
+++ b/examples/device/msc_dual_lun/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -104,4 +104,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/msc_dual_lun/src/usb_descriptors.c b/examples/device/msc_dual_lun/src/usb_descriptors.c
index efb9a966d..f73935ee0 100644
--- a/examples/device/msc_dual_lun/src/usb_descriptors.c
+++ b/examples/device/msc_dual_lun/src/usb_descriptors.c
@@ -32,14 +32,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -103,7 +103,7 @@ enum
#endif
-uint8_t const desc_fs_configuration[] =
+static uint8_t const desc_fs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -113,7 +113,7 @@ uint8_t const desc_fs_configuration[] =
};
#if TUD_OPT_HIGH_SPEED
-uint8_t const desc_hs_configuration[] =
+static uint8_t const desc_hs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -151,7 +151,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
diff --git a/examples/device/mtp/Makefile b/examples/device/mtp/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/mtp/Makefile
+++ b/examples/device/mtp/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/mtp/src/mtp_fs_example.c b/examples/device/mtp/src/mtp_fs_example.c
index b4772f146..7fd7db61b 100644
--- a/examples/device/mtp/src/mtp_fs_example.c
+++ b/examples/device/mtp/src/mtp_fs_example.c
@@ -39,12 +39,15 @@
#define DEV_PROP_FRIENDLY_NAME "TinyUSB MTP"
//------------- storage info -------------//
-#define STORAGE_DESCRIPTRION { 'd', 'i', 's', 'k', 0 }
+#define STORAGE_DESCRIPTION { 'd', 'i', 's', 'k', 0 }
#define VOLUME_IDENTIFIER { 'v', 'o', 'l', 0 }
-typedef MTP_STORAGE_INFO_STRUCT(TU_ARRAY_SIZE((uint16_t[]) STORAGE_DESCRIPTRION),
- TU_ARRAY_SIZE(((uint16_t[])VOLUME_IDENTIFIER))
-) storage_info_t;
+enum {
+ STORAGE_DESC_LEN = TU_ARRAY_SIZE((uint16_t[]) STORAGE_DESCRIPTION),
+ VOLUME_ID_LEN = TU_ARRAY_SIZE((uint16_t[])VOLUME_IDENTIFIER)
+};
+
+typedef MTP_STORAGE_INFO_STRUCT(STORAGE_DESC_LEN, VOLUME_ID_LEN) storage_info_t;
storage_info_t storage_info = {
#ifdef CFG_EXAMPLE_MTP_READONLY
@@ -60,7 +63,7 @@ storage_info_t storage_info = {
.free_space_in_objects = 0, // calculated at runtime
.storage_description = {
.count = (TU_FIELD_SIZE(storage_info_t, storage_description)-1) / sizeof(uint16_t),
- .utf16 = STORAGE_DESCRIPTRION
+ .utf16 = STORAGE_DESCRIPTION
},
.volume_identifier = {
.count = (TU_FIELD_SIZE(storage_info_t, volume_identifier)-1) / sizeof(uint16_t),
@@ -320,9 +323,9 @@ int32_t tud_mtp_data_complete_cb(tud_mtp_cb_data_t* cb_data) {
break;
}
// parameter is: storage id, parent handle, new handle
- mtp_container_add_uint32(resp, SUPPORTED_STORAGE_ID);
- mtp_container_add_uint32(resp, f->parent);
- mtp_container_add_uint32(resp, send_obj_handle);
+ (void) mtp_container_add_uint32(resp, SUPPORTED_STORAGE_ID);
+ (void) mtp_container_add_uint32(resp, f->parent);
+ (void) mtp_container_add_uint32(resp, send_obj_handle);
resp->header->code = MTP_RESP_OK;
break;
}
@@ -346,19 +349,22 @@ int32_t tud_mtp_response_complete_cb(tud_mtp_cb_data_t* cb_data) {
//--------------------------------------------------------------------+
static int32_t fs_get_device_info(tud_mtp_cb_data_t* cb_data) {
// Device info is already prepared up to playback formats. Application only need to add string fields
+ int32_t resp_code = 0;
mtp_container_info_t* io_container = &cb_data->io_container;
- mtp_container_add_cstring(io_container, DEV_INFO_MANUFACTURER);
- mtp_container_add_cstring(io_container, DEV_INFO_MODEL);
- mtp_container_add_cstring(io_container, DEV_INFO_VERSION);
+ (void) mtp_container_add_cstring(io_container, DEV_INFO_MANUFACTURER);
+ (void) mtp_container_add_cstring(io_container, DEV_INFO_MODEL);
+ (void) mtp_container_add_cstring(io_container, DEV_INFO_VERSION);
enum { MAX_SERIAL_NCHARS = 32 };
uint16_t serial_utf16[MAX_SERIAL_NCHARS+1];
size_t nchars = board_usb_get_serial(serial_utf16, MAX_SERIAL_NCHARS);
serial_utf16[tu_min32(nchars, MAX_SERIAL_NCHARS)] = 0; // ensure null termination
- mtp_container_add_string(io_container, serial_utf16);
+ (void) mtp_container_add_string(io_container, serial_utf16);
- tud_mtp_data_send(io_container);
- return 0;
+ if (!tud_mtp_data_send(io_container)) {
+ resp_code = MTP_RESP_DEVICE_BUSY;
+ }
+ return resp_code;
}
static int32_t fs_open_close_session(tud_mtp_cb_data_t* cb_data) {
@@ -380,7 +386,7 @@ static int32_t fs_open_close_session(tud_mtp_cb_data_t* cb_data) {
static int32_t fs_get_storage_ids(tud_mtp_cb_data_t* cb_data) {
mtp_container_info_t* io_container = &cb_data->io_container;
uint32_t storage_ids [] = { SUPPORTED_STORAGE_ID };
- mtp_container_add_auint32(io_container, 1, storage_ids);
+ (void) mtp_container_add_auint32(io_container, 1, storage_ids);
tud_mtp_data_send(io_container);
return 0;
}
@@ -394,7 +400,7 @@ static int32_t fs_get_storage_info(tud_mtp_cb_data_t* cb_data) {
storage_info.max_capacity_in_bytes = sizeof(README_TXT_CONTENT) + LOGO_LEN + FS_MAX_CAPACITY_BYTES;
storage_info.free_space_in_objects = FS_MAX_FILE_COUNT - fs_get_file_count();
storage_info.free_space_in_bytes = storage_info.free_space_in_objects ? FS_MAX_CAPACITY_BYTES : 0;
- mtp_container_add_raw(io_container, &storage_info, sizeof(storage_info));
+ (void) mtp_container_add_raw(io_container, &storage_info, sizeof(storage_info));
tud_mtp_data_send(io_container);
return 0;
}
@@ -412,10 +418,10 @@ static int32_t fs_get_device_properties(tud_mtp_cb_data_t* cb_data) {
case MTP_DEV_PROP_DEVICE_FRIENDLY_NAME:
device_prop_header.datatype = MTP_DATA_TYPE_STR;
device_prop_header.get_set = MTP_MODE_GET;
- mtp_container_add_raw(io_container, &device_prop_header, sizeof(device_prop_header));
- mtp_container_add_cstring(io_container, DEV_PROP_FRIENDLY_NAME); // factory
- mtp_container_add_cstring(io_container, DEV_PROP_FRIENDLY_NAME); // current
- mtp_container_add_uint8(io_container, 0); // no form
+ (void) mtp_container_add_raw(io_container, &device_prop_header, sizeof(device_prop_header));
+ (void) mtp_container_add_cstring(io_container, DEV_PROP_FRIENDLY_NAME); // factory
+ (void) mtp_container_add_cstring(io_container, DEV_PROP_FRIENDLY_NAME); // current
+ (void) mtp_container_add_uint8(io_container, 0); // no form
tud_mtp_data_send(io_container);
break;
@@ -426,7 +432,7 @@ static int32_t fs_get_device_properties(tud_mtp_cb_data_t* cb_data) {
// get value
switch (dev_prop_code) {
case MTP_DEV_PROP_DEVICE_FRIENDLY_NAME:
- mtp_container_add_cstring(io_container, DEV_PROP_FRIENDLY_NAME);
+ (void) mtp_container_add_cstring(io_container, DEV_PROP_FRIENDLY_NAME);
tud_mtp_data_send(io_container);
break;
@@ -446,20 +452,20 @@ static int32_t fs_get_object_handles(tud_mtp_cb_data_t* cb_data) {
const uint32_t parent_handle = command->params[2]; // folder handle, 0xFFFFFFFF is root
(void)obj_format;
- if (storage_id != 0xFFFFFFFF && storage_id != SUPPORTED_STORAGE_ID) {
+ if (storage_id != 0xFFFFFFFFu && storage_id != SUPPORTED_STORAGE_ID) {
return MTP_RESP_INVALID_STORAGE_ID;
}
uint32_t handles[FS_MAX_FILE_COUNT] = { 0 };
- uint32_t count = 0;
- for (uint8_t i = 0; i < FS_MAX_FILE_COUNT; i++) {
+ uint32_t count = 0u;
+ for (uint8_t i = 0u; i < FS_MAX_FILE_COUNT; i++) {
fs_file_t* f = &fs_objects[i];
if (fs_file_exist(f) &&
- (parent_handle == f->parent || (parent_handle == 0xFFFFFFFF && f->parent == 0))) {
- handles[count++] = i + 1; // handle is index + 1
+ (parent_handle == f->parent || (parent_handle == 0xFFFFFFFFu && f->parent == 0u))) {
+ handles[count++] = (uint32_t) i + 1u; // handle is index + 1
}
}
- mtp_container_add_auint32(io_container, count, handles);
+ (void) mtp_container_add_auint32(io_container, count, handles);
tud_mtp_data_send(io_container);
return 0;
@@ -490,11 +496,11 @@ static int32_t fs_get_object_info(tud_mtp_cb_data_t* cb_data) {
.association_desc = 0,
.sequence_number = 0
};
- mtp_container_add_raw(io_container, &obj_info_header, sizeof(obj_info_header));
- mtp_container_add_string(io_container, f->name);
- mtp_container_add_cstring(io_container, FS_FIXED_DATETIME);
- mtp_container_add_cstring(io_container, FS_FIXED_DATETIME);
- mtp_container_add_cstring(io_container, ""); // keywords, not used
+ (void) mtp_container_add_raw(io_container, &obj_info_header, sizeof(obj_info_header));
+ (void) mtp_container_add_string(io_container, f->name);
+ (void) mtp_container_add_cstring(io_container, FS_FIXED_DATETIME);
+ (void) mtp_container_add_cstring(io_container, FS_FIXED_DATETIME);
+ (void) mtp_container_add_cstring(io_container, ""); // keywords, not used
tud_mtp_data_send(io_container);
return 0;
@@ -512,7 +518,7 @@ static int32_t fs_get_object(tud_mtp_cb_data_t* cb_data) {
if (cb_data->phase == MTP_PHASE_COMMAND) {
// If file contents is larger than CFG_TUD_MTP_EP_BUFSIZE, data may only partially is added here
// the rest will be sent in tud_mtp_data_more_cb
- mtp_container_add_raw(io_container, f->data, f->size);
+ (void) mtp_container_add_raw(io_container, f->data, f->size);
tud_mtp_data_send(io_container);
} else if (cb_data->phase == MTP_PHASE_DATA) {
// continue sending remaining data: file contents offset is xferred byte minus header size
@@ -522,6 +528,8 @@ static int32_t fs_get_object(tud_mtp_cb_data_t* cb_data) {
memcpy(io_container->payload, f->data + offset, xact_len);
tud_mtp_data_send(io_container);
}
+ } else {
+ // nothing to do
}
return 0;
@@ -537,21 +545,21 @@ static int32_t fs_send_object_info(tud_mtp_cb_data_t* cb_data) {
if (!is_session_opened) {
return MTP_RESP_SESSION_NOT_OPEN;
}
- if (storage_id != 0xFFFFFFFF && storage_id != SUPPORTED_STORAGE_ID) {
+ if (storage_id != 0xFFFFFFFFu && storage_id != SUPPORTED_STORAGE_ID) {
return MTP_RESP_INVALID_STORAGE_ID;
}
if (cb_data->phase == MTP_PHASE_COMMAND) {
- tud_mtp_data_receive(io_container);
+ (void) tud_mtp_data_receive(io_container);
} else if (cb_data->phase == MTP_PHASE_DATA) {
mtp_object_info_header_t* obj_info = (mtp_object_info_header_t*) io_container->payload;
if (obj_info->storage_id != 0 && obj_info->storage_id != SUPPORTED_STORAGE_ID) {
return MTP_RESP_INVALID_STORAGE_ID;
}
- if (obj_info->parent_object) {
+ if (obj_info->parent_object != 0) { // not root
fs_file_t* parent = fs_get_file(obj_info->parent_object);
- if (parent == NULL || !parent->association_type) {
+ if (parent == NULL || 0u == parent->association_type) {
return MTP_RESP_INVALID_PARENT_OBJECT;
}
}
@@ -575,8 +583,10 @@ static int32_t fs_send_object_info(tud_mtp_cb_data_t* cb_data) {
f->size = obj_info->object_compressed_size;
f->data = f_buf;
uint8_t* buf = io_container->payload + sizeof(mtp_object_info_header_t);
- mtp_container_get_string(buf, f->name);
+ (void) mtp_container_get_string(buf, f->name);
// ignore date created/modified/keywords
+ } else {
+ // nothing to do
}
return 0;
diff --git a/examples/device/mtp/src/tusb_config.h b/examples/device/mtp/src/tusb_config.h
index 4d166aa63..95cc048ee 100644
--- a/examples/device/mtp/src/tusb_config.h
+++ b/examples/device/mtp/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -136,4 +136,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/mtp/src/usb_descriptors.c b/examples/device/mtp/src/usb_descriptors.c
index 80345d8f8..f0aa3de6b 100644
--- a/examples/device/mtp/src/usb_descriptors.c
+++ b/examples/device/mtp/src/usb_descriptors.c
@@ -32,9 +32,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] MTP | VENDOR | MIDI | HID | MSC | CDC [LSB]
*/
-#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(MTP, 5))
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#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(MTP, 5))
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -42,7 +42,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -121,7 +121,7 @@ const uint8_t desc_fs_configuration[] = {
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
// Interface number, string index, EP event, EP event size, EP event polling, EP Out & EP In address, EP size
@@ -129,10 +129,10 @@ uint8_t const desc_hs_configuration[] = {
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
@@ -198,7 +198,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUsb", // 1: Manufacturer
diff --git a/examples/device/net_lwip_webserver/Makefile b/examples/device/net_lwip_webserver/Makefile
index 4ad110dec..9d8e8ec77 100644
--- a/examples/device/net_lwip_webserver/Makefile
+++ b/examples/device/net_lwip_webserver/Makefile
@@ -1,4 +1,4 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
# suppress warning caused by lwip
CFLAGS_GCC += \
@@ -8,7 +8,6 @@ CFLAGS_GCC += \
INC += \
src \
- $(TOP)/hw \
$(TOP)/lib/lwip/src/include \
$(TOP)/lib/lwip/src/include/ipv4 \
$(TOP)/lib/lwip/src/include/lwip/apps \
@@ -16,7 +15,7 @@ INC += \
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
# lwip sources
SRC_C += \
@@ -66,4 +65,4 @@ SRC_C += \
lib/networking/dnserver.c \
lib/networking/rndis_reports.c
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/net_lwip_webserver/skip.txt b/examples/device/net_lwip_webserver/skip.txt
index 6121f1f9d..ecb9eb7ec 100644
--- a/examples/device/net_lwip_webserver/skip.txt
+++ b/examples/device/net_lwip_webserver/skip.txt
@@ -20,3 +20,5 @@ board:curiosity_nano
board:frdm_kl25z
# lpc55 has weird error 'ncm_interface' causes a section type conflict with 'ntb_parameters'
family:lpc55
+family:nuc126
+family:nuc100_120
diff --git a/examples/device/net_lwip_webserver/src/arch/cc.h b/examples/device/net_lwip_webserver/src/arch/cc.h
index 9f30b91cb..c3fc12dda 100644
--- a/examples/device/net_lwip_webserver/src/arch/cc.h
+++ b/examples/device/net_lwip_webserver/src/arch/cc.h
@@ -29,8 +29,8 @@
* Author: Adam Dunkels <[email protected]>
*
*/
-#ifndef __CC_H__
-#define __CC_H__
+#ifndef CC_H__
+#define CC_H__
//#include "cpu.h"
@@ -72,4 +72,4 @@ typedef int sys_prot_t;
#define LWIP_PLATFORM_ASSERT(x) do { if(!(x)) while(1); } while(0)
-#endif /* __CC_H__ */
+#endif /* CC_H__ */
diff --git a/examples/device/net_lwip_webserver/src/lwipopts.h b/examples/device/net_lwip_webserver/src/lwipopts.h
index 04949cef9..11686ce2a 100644
--- a/examples/device/net_lwip_webserver/src/lwipopts.h
+++ b/examples/device/net_lwip_webserver/src/lwipopts.h
@@ -29,8 +29,8 @@
* Author: Simon Goldschmidt
*
*/
-#ifndef __LWIPOPTS_H__
-#define __LWIPOPTS_H__
+#ifndef LWIPOPTS_H__
+#define LWIPOPTS_H__
/* Prevent having to link sys_arch.c (we don't test the API layers in unit tests) */
#define NO_SYS 1
diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c
index dd9f213ae..867cf2812 100644
--- a/examples/device/net_lwip_webserver/src/main.c
+++ b/examples/device/net_lwip_webserver/src/main.c
@@ -58,6 +58,7 @@ try changing the first byte of tud_network_mac_address[] below from 0x02 to 0x00
#include "lwip/ethip6.h"
#include "lwip/init.h"
#include "lwip/timeouts.h"
+#include "lwip/sys.h"
#ifdef INCLUDE_IPERF
#include "lwip/apps/lwiperf.h"
@@ -172,7 +173,7 @@ static void init_lwip(void) {
}
/* handle any DNS requests from dns-server */
-bool dns_query_proc(const char *name, ip4_addr_t *addr) {
+static bool dns_query_proc(const char *name, ip4_addr_t *addr) {
if (0 == strcmp(name, "tiny.usb")) {
*addr = ipaddr;
return true;
diff --git a/examples/device/net_lwip_webserver/src/tusb_config.h b/examples/device/net_lwip_webserver/src/tusb_config.h
index c774f59ff..3285ea52c 100644
--- a/examples/device/net_lwip_webserver/src/tusb_config.h
+++ b/examples/device/net_lwip_webserver/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -88,7 +88,7 @@ extern "C" {
#ifndef USE_ECM
#if TU_CHECK_MCU(OPT_MCU_LPC15XX, OPT_MCU_LPC40XX, OPT_MCU_LPC51UXX, OPT_MCU_LPC54)
#define USE_ECM 1
-#elif TU_CHECK_MCU(OPT_MCU_SAMD21, OPT_MCU_SAML21, OPT_MCU_SAML22)
+#elif TU_CHECK_MCU(OPT_MCU_SAMD21, OPT_MCU_SAML2X)
#define USE_ECM 1
#elif TU_CHECK_MCU(OPT_MCU_STM32F0, OPT_MCU_STM32F1)
#define USE_ECM 1
@@ -141,4 +141,4 @@ extern "C" {
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/net_lwip_webserver/src/usb_descriptors.c b/examples/device/net_lwip_webserver/src/usb_descriptors.c
index cd800f521..c976cb62b 100644
--- a/examples/device/net_lwip_webserver/src/usb_descriptors.c
+++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c
@@ -24,6 +24,7 @@
*/
#include "bsp/board_api.h"
+#include "class/net/net_device.h"
#include "tusb.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
@@ -32,35 +33,34 @@
* Auto ProductID layout's Bitmap:
* [MSB] NET | VENDOR | MIDI | HID | MSC | CDC [LSB]
*/
-#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(ECM_RNDIS, 5) | _PID_MAP(NCM, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#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(ECM_RNDIS, 5) | PID_MAP(NCM, 5))
// String Descriptor Index
-enum
-{
+enum {
STRID_LANGID = 0,
STRID_MANUFACTURER,
STRID_PRODUCT,
STRID_SERIAL,
STRID_INTERFACE,
- STRID_MAC
+ STRID_MAC,
+ STRID_COUNT
};
-enum
-{
+enum {
ITF_NUM_CDC = 0,
ITF_NUM_CDC_DATA,
ITF_NUM_TOTAL
};
-enum
-{
+enum {
#if CFG_TUD_ECM_RNDIS
CONFIG_ID_RNDIS = 0,
CONFIG_ID_ECM = 1,
#else
- CONFIG_ID_NCM = 0,
+ CONFIG_ID_NCM = 0,
#endif
CONFIG_ID_COUNT
};
@@ -68,103 +68,103 @@ enum
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
-{
- .bLength = sizeof(tusb_desc_device_t),
- .bDescriptorType = TUSB_DESC_DEVICE,
+static const tusb_desc_device_t desc_device = {
+ .bLength = sizeof(tusb_desc_device_t),
+ .bDescriptorType = TUSB_DESC_DEVICE,
#if CFG_TUD_NCM
- .bcdUSB = 0x0201,
+ .bcdUSB = 0x0201,
#else
- .bcdUSB = 0x0200,
+ .bcdUSB = 0x0200,
#endif
- // Use Interface Association Descriptor (IAD) device class
- .bDeviceClass = TUSB_CLASS_MISC,
- .bDeviceSubClass = MISC_SUBCLASS_COMMON,
- .bDeviceProtocol = MISC_PROTOCOL_IAD,
+ // Use Interface Association Descriptor (IAD) device class
+ .bDeviceClass = TUSB_CLASS_MISC,
+ .bDeviceSubClass = MISC_SUBCLASS_COMMON,
+ .bDeviceProtocol = MISC_PROTOCOL_IAD,
- .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
- .idVendor = 0xCafe,
- .idProduct = USB_PID,
- .bcdDevice = 0x0101,
+ .idVendor = 0xCafe,
+ .idProduct = USB_PID,
+ .bcdDevice = 0x0101,
- .iManufacturer = STRID_MANUFACTURER,
- .iProduct = STRID_PRODUCT,
- .iSerialNumber = STRID_SERIAL,
+ .iManufacturer = STRID_MANUFACTURER,
+ .iProduct = STRID_PRODUCT,
+ .iSerialNumber = STRID_SERIAL,
- .bNumConfigurations = CONFIG_ID_COUNT // multiple configurations
+ .bNumConfigurations = CONFIG_ID_COUNT // multiple configurations
};
// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
-uint8_t const * tud_descriptor_device_cb(void)
-{
- return (uint8_t const *) &desc_device;
+const uint8_t *tud_descriptor_device_cb(void) {
+ return (const uint8_t *)&desc_device;
}
//--------------------------------------------------------------------+
// Configuration Descriptor
//--------------------------------------------------------------------+
-#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)
+#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
- // 0 control, 1 In, 2 Bulk, 3 Iso, 4 In etc ...
- #define EPNUM_NET_NOTIF 0x81
- #define EPNUM_NET_OUT 0x02
- #define EPNUM_NET_IN 0x82
+// 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_NET_NOTIF 0x81
+#define EPNUM_NET_OUT 0x02
+#define EPNUM_NET_IN 0x82
#elif CFG_TUSB_MCU == OPT_MCU_CXD56
- // 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_NET_NOTIF 0x83
- #define EPNUM_NET_OUT 0x02
- #define EPNUM_NET_IN 0x81
+// 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_NET_NOTIF 0x83
+#define EPNUM_NET_OUT 0x02
+#define EPNUM_NET_IN 0x81
#elif defined(TUD_ENDPOINT_ONE_DIRECTION_ONLY)
- // MCUs that don't support a same endpoint number with different direction IN and OUT defined in tusb_mcu.h
- // e.g EP1 OUT & EP1 IN cannot exist together
- #define EPNUM_NET_NOTIF 0x81
- #define EPNUM_NET_OUT 0x02
- #define EPNUM_NET_IN 0x83
+// MCUs that don't support a same endpoint number with different direction IN and OUT defined in tusb_mcu.h
+// e.g EP1 OUT & EP1 IN cannot exist together
+#define EPNUM_NET_NOTIF 0x81
+#define EPNUM_NET_OUT 0x02
+#define EPNUM_NET_IN 0x83
#else
- #define EPNUM_NET_NOTIF 0x81
- #define EPNUM_NET_OUT 0x02
- #define EPNUM_NET_IN 0x82
+#define EPNUM_NET_NOTIF 0x81
+#define EPNUM_NET_OUT 0x02
+#define EPNUM_NET_IN 0x82
#endif
#if CFG_TUD_ECM_RNDIS
-static uint8_t const rndis_configuration[] =
-{
+static uint8_t const rndis_configuration[] = {
// Config number (index+1), interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(CONFIG_ID_RNDIS+1, ITF_NUM_TOTAL, 0, MAIN_CONFIG_TOTAL_LEN, 0, 100),
+ TUD_CONFIG_DESCRIPTOR(CONFIG_ID_RNDIS + 1, ITF_NUM_TOTAL, 0, MAIN_CONFIG_TOTAL_LEN, 0, 100),
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
- TUD_RNDIS_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, EPNUM_NET_NOTIF, 8, EPNUM_NET_OUT, EPNUM_NET_IN, CFG_TUD_NET_ENDPOINT_SIZE),
+ TUD_RNDIS_DESCRIPTOR(
+ ITF_NUM_CDC, STRID_INTERFACE, EPNUM_NET_NOTIF, 8, EPNUM_NET_OUT, EPNUM_NET_IN, CFG_TUD_NET_ENDPOINT_SIZE),
};
-static uint8_t const ecm_configuration[] =
-{
+static const uint8_t ecm_configuration[] = {
// Config number (index+1), interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(CONFIG_ID_ECM+1, ITF_NUM_TOTAL, 0, ALT_CONFIG_TOTAL_LEN, 0, 100),
+ TUD_CONFIG_DESCRIPTOR(CONFIG_ID_ECM + 1, ITF_NUM_TOTAL, 0, ALT_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_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),
+ 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[] =
-{
+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),
+ 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),
+ 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
@@ -173,21 +173,19 @@ static uint8_t const ncm_configuration[] =
// - Windows only works with RNDIS
// - MacOS only works with CDC-ECM
// - Linux will work on both
-static uint8_t const * const configuration_arr[2] =
-{
+static const uint8_t *const configuration_arr[CONFIG_ID_COUNT] = {
#if CFG_TUD_ECM_RNDIS
[CONFIG_ID_RNDIS] = rndis_configuration,
- [CONFIG_ID_ECM ] = ecm_configuration
+ [CONFIG_ID_ECM] = ecm_configuration
#else
- [CONFIG_ID_NCM ] = ncm_configuration
+ [CONFIG_ID_NCM] = ncm_configuration
#endif
};
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
-{
+const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
return (index < CONFIG_ID_COUNT) ? configuration_arr[index] : NULL;
}
@@ -213,61 +211,62 @@ https://developers.google.com/web/fundamentals/native-hardware/build-for-webusb/
(Section Microsoft OS compatibility descriptors)
*/
-#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN)
+#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_MICROSOFT_OS_DESC_LEN)
-#define MS_OS_20_DESC_LEN 0xB2
+#define MS_OS_20_DESC_LEN 0xB2
// BOS Descriptor is required for webUSB
-uint8_t const desc_bos[] =
-{
+const uint8_t desc_bos[] = {
// total length, number of device caps
TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 1),
// Microsoft OS 2.0 descriptor
- TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, 1)
-};
+ TUD_BOS_MS_OS_20_DESCRIPTOR(MS_OS_20_DESC_LEN, 1)};
-uint8_t const * tud_descriptor_bos_cb(void)
-{
+const uint8_t *tud_descriptor_bos_cb(void) {
return desc_bos;
}
-uint8_t const desc_ms_os_20[] =
-{
+const uint8_t desc_ms_os_20[] = {
// Set header: length, type, windows version, total length
- U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(MS_OS_20_DESC_LEN),
+ U16_TO_U8S_LE(0x000A), U16_TO_U8S_LE(MS_OS_20_SET_HEADER_DESCRIPTOR), U32_TO_U8S_LE(0x06030000),
+ U16_TO_U8S_LE(MS_OS_20_DESC_LEN),
// Configuration subset header: length, type, configuration index, reserved, configuration total length
- U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A),
+ U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_CONFIGURATION), 0, 0,
+ U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A),
// Function Subset header: length, type, first interface, reserved, subset length
- U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_CDC, 0, U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08),
+ U16_TO_U8S_LE(0x0008), U16_TO_U8S_LE(MS_OS_20_SUBSET_HEADER_FUNCTION), ITF_NUM_CDC, 0,
+ U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08),
// MS OS 2.0 Compatible ID descriptor: length, type, compatible ID, sub compatible ID
- U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'N', 'C', 'M', 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
+ U16_TO_U8S_LE(0x0014), U16_TO_U8S_LE(MS_OS_20_FEATURE_COMPATBLE_ID), 'W', 'I', 'N', 'N', 'C', 'M', 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // sub-compatible
// MS OS 2.0 Registry property descriptor: length, type
- U16_TO_U8S_LE(MS_OS_20_DESC_LEN-0x0A-0x08-0x08-0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
- U16_TO_U8S_LE(0x0007), U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
- 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00,
- 'r', 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
+ U16_TO_U8S_LE(MS_OS_20_DESC_LEN - 0x0A - 0x08 - 0x08 - 0x14), U16_TO_U8S_LE(MS_OS_20_FEATURE_REG_PROPERTY),
+ U16_TO_U8S_LE(0x0007),
+ U16_TO_U8S_LE(0x002A), // wPropertyDataType, wPropertyNameLength and PropertyName "DeviceInterfaceGUIDs\0" in UTF-16
+ 'D', 0x00, 'e', 0x00, 'v', 0x00, 'i', 0x00, 'c', 0x00, 'e', 0x00, 'I', 0x00, 'n', 0x00, 't', 0x00, 'e', 0x00, 'r',
+ 0x00, 'f', 0x00, 'a', 0x00, 'c', 0x00, 'e', 0x00, 'G', 0x00, 'U', 0x00, 'I', 0x00, 'D', 0x00, 's', 0x00, 0x00, 0x00,
U16_TO_U8S_LE(0x0050), // wPropertyDataLength
- //bPropertyData: {12345678-0D08-43FD-8B3E-127CA8AFFF9D}
- '{', 0x00, '1', 0x00, '2', 0x00, '3', 0x00, '4', 0x00, '5', 0x00, '6', 0x00, '7', 0x00, '8', 0x00, '-', 0x00,
- '0', 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00,
- '8', 0x00, 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00,
- '8', 0x00, 'A', 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00
-};
+ //bPropertyData: {12345678-0D08-43FD-8B3E-127CA8AFFF9D}
+ '{', 0x00, '1', 0x00, '2', 0x00, '3', 0x00, '4', 0x00, '5', 0x00, '6', 0x00, '7', 0x00, '8', 0x00, '-', 0x00, '0',
+ 0x00, 'D', 0x00, '0', 0x00, '8', 0x00, '-', 0x00, '4', 0x00, '3', 0x00, 'F', 0x00, 'D', 0x00, '-', 0x00, '8', 0x00,
+ 'B', 0x00, '3', 0x00, 'E', 0x00, '-', 0x00, '1', 0x00, '2', 0x00, '7', 0x00, 'C', 0x00, 'A', 0x00, '8', 0x00, 'A',
+ 0x00, 'F', 0x00, 'F', 0x00, 'F', 0x00, '9', 0x00, 'D', 0x00, '}', 0x00, 0x00, 0x00, 0x00, 0x00};
TU_VERIFY_STATIC(sizeof(desc_ms_os_20) == MS_OS_20_DESC_LEN, "Incorrect size");
// Invoked when a control transfer occurred on an interface of this class
// Driver response accordingly to the request and the transfer stage (setup/data/ack)
// return false to stall control endpoint (e.g unsupported request)
-bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const* request) {
+bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, const tusb_control_request_t *request) {
// nothing to with DATA & ACK stage
- if (stage != CONTROL_STAGE_SETUP) return true;
+ if (stage != CONTROL_STAGE_SETUP) {
+ return true;
+ }
switch (request->bmRequestType_bit.type) {
case TUSB_REQ_TYPE_VENDOR:
@@ -278,16 +277,18 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
uint16_t total_len;
memcpy(&total_len, desc_ms_os_20 + 8, 2);
- return tud_control_xfer(rhport, request, (void*)(uintptr_t)desc_ms_os_20, total_len);
+ return tud_control_xfer(rhport, request, (void *)(uintptr_t)desc_ms_os_20, total_len);
} else {
return false;
}
- default: break;
+ default:
+ break; // nothing to do
}
break;
- default: break;
+ default:
+ break; // nothing to do
}
// stall unknown request
@@ -300,26 +301,24 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
//--------------------------------------------------------------------+
// array of pointer to string descriptors
-static char const* string_desc_arr [] =
-{
- [STRID_LANGID] = (const char[]) { 0x09, 0x04 }, // supported language is English (0x0409)
- [STRID_MANUFACTURER] = "TinyUSB", // Manufacturer
- [STRID_PRODUCT] = "TinyUSB Device", // Product
- [STRID_SERIAL] = NULL, // Serials will use unique ID if possible
- [STRID_INTERFACE] = "TinyUSB Network Interface" // Interface Description
-
- // STRID_MAC index is handled separately
+static const char *string_desc_arr[STRID_COUNT] = {
+ [STRID_LANGID] = (const char[]){0x09, 0x04}, // supported language is English (0x0409)
+ [STRID_MANUFACTURER] = "TinyUSB", // Manufacturer
+ [STRID_PRODUCT] = "TinyUSB Device", // Product
+ [STRID_SERIAL] = NULL, // Serials will use unique ID if possible
+ [STRID_INTERFACE] = "TinyUSB Network Interface", // Interface Description
+ [STRID_MAC] = NULL // STRID_MAC index is handled separately
};
static uint16_t _desc_str[32 + 1];
// Invoked when received GET STRING DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
-uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
- (void) langid;
+const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
+ (void)langid;
unsigned int chr_count = 0;
- switch ( index ) {
+ switch (index) {
case STRID_LANGID:
memcpy(&_desc_str[1], string_desc_arr[0], 2);
chr_count = 1;
@@ -331,34 +330,40 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
case STRID_MAC:
// Convert MAC address into UTF-16
- for (unsigned i=0; i<sizeof(tud_network_mac_address); i++) {
- _desc_str[1+chr_count++] = "0123456789ABCDEF"[(tud_network_mac_address[i] >> 4) & 0xf];
- _desc_str[1+chr_count++] = "0123456789ABCDEF"[(tud_network_mac_address[i] >> 0) & 0xf];
+ for (unsigned i = 0; i < sizeof(tud_network_mac_address); i++) {
+ _desc_str[1 + chr_count++] = "0123456789ABCDEF"[(tud_network_mac_address[i] >> 4) & 0xf];
+ _desc_str[1 + chr_count++] = "0123456789ABCDEF"[(tud_network_mac_address[i] >> 0) & 0xf];
}
break;
- default:
+ default: {
// Note: the 0xEE index string is a Microsoft OS 1.0 Descriptors.
// https://docs.microsoft.com/en-us/windows-hardware/drivers/usbcon/microsoft-defined-usb-descriptors
- if ( !(index < sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) ) return NULL;
+ if (index >= sizeof(string_desc_arr) / sizeof(string_desc_arr[0])) {
+ return NULL;
+ }
const char *str = string_desc_arr[index];
// Cap at max char
chr_count = strlen(str);
- size_t const max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
- if ( chr_count > max_count ) chr_count = max_count;
+
+ const size_t max_count = sizeof(_desc_str) / sizeof(_desc_str[0]) - 1; // -1 for string type
+ if (chr_count > max_count) {
+ chr_count = max_count;
+ }
// Convert ASCII string into UTF-16
- for ( size_t i = 0; i < chr_count; i++ ) {
+ for (size_t i = 0; i < chr_count; i++) {
_desc_str[1 + i] = str[i];
}
break;
+ }
}
// first byte is length (including header), second byte is string type
- _desc_str[0] = (uint16_t) ((TUSB_DESC_STRING << 8 ) | (2*chr_count + 2));
+ _desc_str[0] = (uint16_t)((TUSB_DESC_STRING << 8) | (2 * chr_count + 2));
return _desc_str;
}
diff --git a/examples/device/uac2_headset/Makefile b/examples/device/uac2_headset/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/uac2_headset/Makefile
+++ b/examples/device/uac2_headset/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/uac2_headset/src/main.c b/examples/device/uac2_headset/src/main.c
index 102a6eef1..96fa66f1e 100644
--- a/examples/device/uac2_headset/src/main.c
+++ b/examples/device/uac2_headset/src/main.c
@@ -73,7 +73,7 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
// Audio controls
// Current states
-int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
+uint8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1];// +1 for master channel 0
// Buffer for microphone data
@@ -141,18 +141,195 @@ void tud_resume_cb(void) {
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
}
+//--------------------------------------------------------------------+
+// Audio Callback Functions
+//--------------------------------------------------------------------+
+
+//--------------------------------------------------------------------+
+// UAC1 Helper Functions
+//--------------------------------------------------------------------+
+
+static bool audio10_set_req_ep(tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+
+ switch (ctrlSel) {
+ case AUDIO10_EP_CTRL_SAMPLING_FREQ:
+ if (p_request->bRequest == AUDIO10_CS_REQ_SET_CUR) {
+ // Request uses 3 bytes
+ TU_VERIFY(p_request->wLength == 3);
+
+ current_sample_rate = tu_unaligned_read32(pBuff) & 0x00FFFFFF;
+
+ TU_LOG2("EP set current freq: %" PRIu32 "\r\n", current_sample_rate);
+
+ return true;
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+
+ return false;
+}
+
+static bool audio10_get_req_ep(uint8_t rhport, tusb_control_request_t const *p_request) {
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+
+ switch (ctrlSel) {
+ case AUDIO10_EP_CTRL_SAMPLING_FREQ:
+ if (p_request->bRequest == AUDIO10_CS_REQ_GET_CUR) {
+ TU_LOG2("EP get current freq\r\n");
+
+ uint8_t freq[3];
+ freq[0] = (uint8_t) (current_sample_rate & 0xFF);
+ freq[1] = (uint8_t) ((current_sample_rate >> 8) & 0xFF);
+ freq[2] = (uint8_t) ((current_sample_rate >> 16) & 0xFF);
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, freq, sizeof(freq));
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+
+ return false;
+}
+
+static bool audio10_set_req_entity(tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ uint8_t channelNum = TU_U16_LOW(p_request->wValue);
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+ uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
+
+ // If request is for our speaker feature unit
+ if (entityID == UAC1_ENTITY_SPK_FEATURE_UNIT) {
+ switch (ctrlSel) {
+ case AUDIO10_FU_CTRL_MUTE:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_SET_CUR:
+ // Only 1st form is supported
+ TU_VERIFY(p_request->wLength == 1);
+
+ mute[channelNum] = pBuff[0];
+
+ TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
+ return true;
+
+ default:
+ return false; // not supported
+ }
+
+ case AUDIO10_FU_CTRL_VOLUME:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_SET_CUR:
+ // Only 1st form is supported
+ TU_VERIFY(p_request->wLength == 2);
+
+ volume[channelNum] = (int16_t)tu_unaligned_read16(pBuff) / 256;
+
+ TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
+ return true;
+
+ default:
+ return false; // not supported
+ }
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ }
+
+ return false;
+}
+
+static bool audio10_get_req_entity(uint8_t rhport, tusb_control_request_t const *p_request) {
+ uint8_t channelNum = TU_U16_LOW(p_request->wValue);
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+ uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
+
+ // If request is for our speaker feature unit
+ if (entityID == UAC1_ENTITY_SPK_FEATURE_UNIT) {
+ switch (ctrlSel) {
+ case AUDIO10_FU_CTRL_MUTE:
+ // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
+ // There does not exist a range parameter block for mute
+ TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &mute[channelNum], 1);
+
+ case AUDIO10_FU_CTRL_VOLUME:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_GET_CUR:
+ TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
+ {
+ int16_t vol = (int16_t) volume[channelNum];
+ vol = vol * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &vol, sizeof(vol));
+ }
+
+ case AUDIO10_CS_REQ_GET_MIN:
+ TU_LOG2(" Get Volume min of channel: %u\r\n", channelNum);
+ {
+ int16_t min = -90; // -90 dB
+ min = min * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &min, sizeof(min));
+ }
+
+ case AUDIO10_CS_REQ_GET_MAX:
+ TU_LOG2(" Get Volume max of channel: %u\r\n", channelNum);
+ {
+ int16_t max = 30; // +30 dB
+ max = max * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &max, sizeof(max));
+ }
+
+ case AUDIO10_CS_REQ_GET_RES:
+ TU_LOG2(" Get Volume res of channel: %u\r\n", channelNum);
+ {
+ int16_t res = 1; // 1 dB
+ res = res * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &res, sizeof(res));
+ }
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ }
+
+ return false;
+}
+
+//--------------------------------------------------------------------+
+// UAC2 Helper Functions
+//--------------------------------------------------------------------+
+
+#if TUD_OPT_HIGH_SPEED
+
// Helper for clock get requests
-static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t const *request) {
+static bool audio20_clock_get_request(uint8_t rhport, audio20_control_request_t const *request) {
TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ) {
- if (request->bRequest == AUDIO_CS_REQ_CUR) {
+ if (request->bControlSelector == AUDIO20_CS_CTRL_SAM_FREQ) {
+ if (request->bRequest == AUDIO20_CS_REQ_CUR) {
TU_LOG1("Clock get current freq %" PRIu32 "\r\n", current_sample_rate);
- audio_control_cur_4_t curf = {(int32_t) tu_htole32(current_sample_rate)};
+ audio20_control_cur_4_t curf = {(int32_t) tu_htole32(current_sample_rate)};
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &curf, sizeof(curf));
- } else if (request->bRequest == AUDIO_CS_REQ_RANGE) {
- audio_control_range_4_n_t(N_SAMPLE_RATES) rangef =
+ } else if (request->bRequest == AUDIO20_CS_REQ_RANGE) {
+ audio20_control_range_4_n_t(N_SAMPLE_RATES) rangef =
{
.wNumSubRanges = tu_htole16(N_SAMPLE_RATES)};
TU_LOG1("Clock get %d freq ranges\r\n", N_SAMPLE_RATES);
@@ -165,9 +342,9 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &rangef, sizeof(rangef));
}
- } else if (request->bControlSelector == AUDIO_CS_CTRL_CLK_VALID &&
- request->bRequest == AUDIO_CS_REQ_CUR) {
- audio_control_cur_1_t cur_valid = {.bCur = 1};
+ } else if (request->bControlSelector == AUDIO20_CS_CTRL_CLK_VALID &&
+ request->bRequest == AUDIO20_CS_REQ_CUR) {
+ audio20_control_cur_1_t cur_valid = {.bCur = 1};
TU_LOG1("Clock get is valid %u\r\n", cur_valid.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &cur_valid, sizeof(cur_valid));
}
@@ -177,16 +354,16 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
}
// Helper for clock set requests
-static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf) {
+static bool audio20_clock_set_request(uint8_t rhport, audio20_control_request_t const *request, uint8_t const *buf) {
(void) rhport;
TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(request->bRequest == AUDIO20_CS_REQ_CUR);
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ) {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_4_t));
+ if (request->bControlSelector == AUDIO20_CS_CTRL_SAM_FREQ) {
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_4_t));
- current_sample_rate = (uint32_t) ((audio_control_cur_4_t const *) buf)->bCur;
+ current_sample_rate = (uint32_t) ((audio20_control_cur_4_t const *) buf)->bCur;
TU_LOG1("Clock set current freq: %" PRIu32 "\r\n", current_sample_rate);
@@ -199,23 +376,23 @@ static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t
}
// Helper for feature unit get requests
-static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_request_t const *request) {
+static bool audio20_feature_unit_get_request(uint8_t rhport, audio20_control_request_t const *request) {
TU_ASSERT(request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT);
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE && request->bRequest == AUDIO_CS_REQ_CUR) {
- audio_control_cur_1_t mute1 = {.bCur = mute[request->bChannelNumber]};
+ if (request->bControlSelector == AUDIO20_FU_CTRL_MUTE && request->bRequest == AUDIO20_CS_REQ_CUR) {
+ audio20_control_cur_1_t mute1 = {.bCur = mute[request->bChannelNumber]};
TU_LOG1("Get channel %u mute %d\r\n", request->bChannelNumber, mute1.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &mute1, sizeof(mute1));
- } else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME) {
- if (request->bRequest == AUDIO_CS_REQ_RANGE) {
- audio_control_range_2_n_t(1) range_vol = {
+ } else if (request->bControlSelector == AUDIO20_FU_CTRL_VOLUME) {
+ if (request->bRequest == AUDIO20_CS_REQ_RANGE) {
+ audio20_control_range_2_n_t(1) range_vol = {
.wNumSubRanges = tu_htole16(1),
.subrange[0] = {.bMin = tu_htole16(-VOLUME_CTRL_50_DB), tu_htole16(VOLUME_CTRL_0_DB), tu_htole16(256)}};
TU_LOG1("Get channel %u volume range (%d, %d, %u) dB\r\n", request->bChannelNumber,
range_vol.subrange[0].bMin / 256, range_vol.subrange[0].bMax / 256, range_vol.subrange[0].bRes / 256);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &range_vol, sizeof(range_vol));
- } else if (request->bRequest == AUDIO_CS_REQ_CUR) {
- audio_control_cur_2_t cur_vol = {.bCur = tu_htole16(volume[request->bChannelNumber])};
+ } else if (request->bRequest == AUDIO20_CS_REQ_CUR) {
+ audio20_control_cur_2_t cur_vol = {.bCur = tu_htole16(volume[request->bChannelNumber])};
TU_LOG1("Get channel %u volume %d dB\r\n", request->bChannelNumber, cur_vol.bCur / 256);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &cur_vol, sizeof(cur_vol));
}
@@ -227,24 +404,24 @@ static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_req
}
// Helper for feature unit set requests
-static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf) {
+static bool audio20_feature_unit_set_request(uint8_t rhport, audio20_control_request_t const *request, uint8_t const *buf) {
(void) rhport;
TU_ASSERT(request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(request->bRequest == AUDIO20_CS_REQ_CUR);
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE) {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_1_t));
+ if (request->bControlSelector == AUDIO20_FU_CTRL_MUTE) {
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_1_t));
- mute[request->bChannelNumber] = ((audio_control_cur_1_t const *) buf)->bCur;
+ mute[request->bChannelNumber] = ((audio20_control_cur_1_t const *) buf)->bCur;
TU_LOG1("Set channel %d Mute: %d\r\n", request->bChannelNumber, mute[request->bChannelNumber]);
return true;
- } else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME) {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_2_t));
+ } else if (request->bControlSelector == AUDIO20_FU_CTRL_VOLUME) {
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_2_t));
- volume[request->bChannelNumber] = ((audio_control_cur_2_t const *) buf)->bCur;
+ volume[request->bChannelNumber] = ((audio20_control_cur_2_t const *) buf)->bCur;
TU_LOG1("Set channel %d volume: %d dB\r\n", request->bChannelNumber, volume[request->bChannelNumber] / 256);
@@ -256,18 +433,13 @@ static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_req
}
}
-//--------------------------------------------------------------------+
-// Application Callback API Implementations
-//--------------------------------------------------------------------+
-
-// Invoked when audio class specific get request received for an entity
-bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
- audio_control_request_t const *request = (audio_control_request_t const *) p_request;
+static bool audio20_get_req_entity(uint8_t rhport, tusb_control_request_t const *p_request) {
+ audio20_control_request_t const *request = (audio20_control_request_t const *) p_request;
if (request->bEntityID == UAC2_ENTITY_CLOCK)
- return tud_audio_clock_get_request(rhport, request);
+ return audio20_clock_get_request(rhport, request);
if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT)
- return tud_audio_feature_unit_get_request(rhport, request);
+ return audio20_feature_unit_get_request(rhport, request);
else {
TU_LOG1("Get request not handled, entity = %d, selector = %d, request = %d\r\n",
request->bEntityID, request->bControlSelector, request->bRequest);
@@ -275,20 +447,78 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
return false;
}
-// Invoked when audio class specific set request received for an entity
-bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf) {
- audio_control_request_t const *request = (audio_control_request_t const *) p_request;
+static bool audio20_set_req_entity(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf) {
+ audio20_control_request_t const *request = (audio20_control_request_t const *) p_request;
if (request->bEntityID == UAC2_ENTITY_SPK_FEATURE_UNIT)
- return tud_audio_feature_unit_set_request(rhport, request, buf);
+ return audio20_feature_unit_set_request(rhport, request, buf);
if (request->bEntityID == UAC2_ENTITY_CLOCK)
- return tud_audio_clock_set_request(rhport, request, buf);
+ return audio20_clock_set_request(rhport, request, buf);
TU_LOG1("Set request not handled, entity = %d, selector = %d, request = %d\r\n",
request->bEntityID, request->bControlSelector, request->bRequest);
return false;
}
+#endif // TUD_OPT_HIGH_SPEED
+
+// Invoked when audio class specific set request received for an EP
+bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ (void) rhport;
+ (void) pBuff;
+
+ if (tud_audio_version() == 1) {
+ return audio10_set_req_ep(p_request, pBuff);
+ } else if (tud_audio_version() == 2) {
+ // We do not support any requests here
+ }
+
+ return false;// Yet not implemented
+}
+
+// Invoked when audio class specific get request received for an EP
+bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_get_req_ep(rhport, p_request);
+ } else if (tud_audio_version() == 2) {
+ // We do not support any requests here
+ }
+
+ return false;// Yet not implemented
+}
+
+// Invoked when audio class specific get request received for an entity
+bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_get_req_entity(rhport, p_request);
+#if TUD_OPT_HIGH_SPEED
+ } else if (tud_audio_version() == 2) {
+ return audio20_get_req_entity(rhport, p_request);
+#endif
+ }
+
+ return false;
+}
+
+// Invoked when audio class specific set request received for an entity
+bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_set_req_entity(p_request, buf);
+#if TUD_OPT_HIGH_SPEED
+ } else if (tud_audio_version() == 2) {
+ return audio20_set_req_entity(rhport, p_request, buf);
+#endif
+ }
+
+ return false;
+}
+
bool tud_audio_set_itf_close_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
(void) rhport;
@@ -380,6 +610,10 @@ void audio_control_task(void) {
uint32_t btn = board_button_read();
+ // Even UAC1 spec have status interrupt support like UAC2, most host do not support it
+ // So you have to either use UAC2 or use old day HID volume control
+ TU_VERIFY((tud_audio_version() == 1),);
+
if (!btn_prev && btn) {
// Adjust volume between 0dB (100%) and -30dB (10%)
for (int i = 0; i < CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1; i++) {
@@ -387,14 +621,14 @@ void audio_control_task(void) {
}
// 6.1 Interrupt Data Message
- const audio_interrupt_data_t data = {
+ const audio_interrupt_data_t data = {.v2 = {
.bInfo = 0, // Class-specific interrupt, originated from an interface
- .bAttribute = AUDIO_CS_REQ_CUR, // Caused by current settings
+ .bAttribute = AUDIO20_CS_REQ_CUR, // Caused by current settings
.wValue_cn_or_mcn = 0, // CH0: master volume
- .wValue_cs = AUDIO_FU_CTRL_VOLUME, // Volume change
+ .wValue_cs = AUDIO20_FU_CTRL_VOLUME, // Volume change
.wIndex_ep_or_int = 0, // From the interface itself
.wIndex_entity_id = UAC2_ENTITY_SPK_FEATURE_UNIT,// From feature unit
- };
+ }};
tud_audio_int_write(&data);
}
diff --git a/examples/device/uac2_headset/src/tusb_config.h b/examples/device/uac2_headset/src/tusb_config.h
index e9165163b..a43a4bd25 100644
--- a/examples/device/uac2_headset/src/tusb_config.h
+++ b/examples/device/uac2_headset/src/tusb_config.h
@@ -24,8 +24,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -108,8 +108,6 @@ extern "C" {
// Allow volume controlled by on-baord button
#define CFG_TUD_AUDIO_ENABLE_INTERRUPT_EP 1
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_HEADSET_STEREO_DESC_LEN
-
// How many formats are used, need to adjust USB descriptor if changed
#define CFG_TUD_AUDIO_FUNC_1_N_FORMATS 2
@@ -126,43 +124,48 @@ extern "C" {
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX 2
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX 16
-#if defined(__RX__)
-// 8bit in 8bit slots
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX 8
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX 8
-#else
-// 24bit in 32bit slots
+// 24bit in 32bit slots (UAC2 only)
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX 4
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX 24
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX 4
#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX 24
-#endif
// EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+// UAC1 (Full-Speed) Endpoint size calculation
+#define CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(false, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+
+// UAC2 (High-Speed) Endpoint size calculation
+#define CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN TUD_AUDIO_EP_SIZE(true, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
+#define CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN TUD_AUDIO_EP_SIZE(true, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX)
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_IN) // Maximum EP IN size for all AS alternate settings used
-#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX // Example read FIFO every 1ms, so it should be 8 times larger for HS device
+// Maximum EP IN size for all AS alternate settings used
+#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TU_MAX(CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN, TU_MAX(CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN, CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN))
+
+// Tx flow control needs buffer size >= 4* EP size to work correctly
+// Example write FIFO every 1ms (8 HS frames), so buffer size should be 8 times larger for HS device
+#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ TU_MAX(4 * CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN, TU_MAX(32 * CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_IN, 32 * CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_IN))
// EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
#define CFG_TUD_AUDIO_ENABLE_EP_OUT 1
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_OUT TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
-#define CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_OUT TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
+// UAC1 (Full-Speed) Endpoint size calculation
+#define CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_OUT TUD_AUDIO_EP_SIZE(false, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
+
+// UAC2 (High-Speed) Endpoint size calculation
+#define CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_OUT TUD_AUDIO_EP_SIZE(true, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
+#define CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_OUT TUD_AUDIO_EP_SIZE(true, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
-#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_EP_SZ_OUT, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_EP_SZ_OUT) // Maximum EP IN size for all AS alternate settings used
-#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX // Example read FIFO every 1ms, so it should be 8 times larger for HS device
+// Maximum EP OUT size for all AS alternate settings used
+#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TU_MAX(CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_OUT, TU_MAX(CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_OUT, CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_OUT))
-// Size of control request buffer
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
+// Rx flow control needs buffer size >= 4* EP size to work correctly
+// Example read FIFO every 1ms (8 HS frames), so buffer size should be 8 times larger for HS device
+#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ TU_MAX(4 * CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_OUT, TU_MAX(32 * CFG_TUD_AUDIO20_FUNC_1_FORMAT_1_EP_SZ_OUT, 32 * CFG_TUD_AUDIO20_FUNC_1_FORMAT_2_EP_SZ_OUT))
#ifdef __cplusplus
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/uac2_headset/src/usb_descriptors.c b/examples/device/uac2_headset/src/usb_descriptors.c
index bc9160d5e..e4fbbf8a5 100644
--- a/examples/device/uac2_headset/src/usb_descriptors.c
+++ b/examples/device/uac2_headset/src/usb_descriptors.c
@@ -34,14 +34,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -87,9 +87,9 @@ uint8_t const * tud_descriptor_device_cb(void)
#elif CFG_TUSB_MCU == OPT_MCU_CXD56
// 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_AUDIO_IN 0x01
- // #define EPNUM_AUDIO_OUT 0x02
- // #define EPNUM_AUDIO_INT 0x03
+ #define EPNUM_AUDIO_IN 0x01
+ #define EPNUM_AUDIO_OUT 0x02
+ #define EPNUM_AUDIO_INT 0x03
#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
// ISO endpoints for NRF5x are fixed to 0x08 (0x88)
@@ -110,22 +110,93 @@ uint8_t const * tud_descriptor_device_cb(void)
#define EPNUM_AUDIO_INT 0x02
#endif
-uint8_t const desc_configuration[] =
+#define CONFIG_UAC1_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO10_HEADSET_STEREO_DESC_LEN(2))
+
+uint8_t const desc_uac1_configuration[] =
+{
+ // Config number, interface count, string index, total length, attribute, power in mA
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_UAC1_TOTAL_LEN, 0x00, 100),
+
+ // Interface number, string index, bytes per sample RX/TX, bits used per sample RX/TX, EP Out & EP In address, EP sizes, sample rate
+ TUD_AUDIO10_HEADSET_STEREO_DESCRIPTOR(ITF_NUM_AUDIO_CONTROL, 4, \
+ CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX, \
+ CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX, \
+ EPNUM_AUDIO_OUT, CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_OUT, \
+ EPNUM_AUDIO_IN | 0x80, CFG_TUD_AUDIO10_FUNC_1_FORMAT_1_EP_SZ_IN, \
+ 44100, 48000)
+};
+
+TU_VERIFY_STATIC(sizeof(desc_uac1_configuration) == CONFIG_UAC1_TOTAL_LEN, "Incorrect size");
+
+#if TUD_OPT_HIGH_SPEED
+
+#define CONFIG_UAC2_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO20_HEADSET_STEREO_DESC_LEN)
+
+uint8_t const desc_uac2_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_UAC2_TOTAL_LEN, 0x00, 100),
- // Interface number, string index, EP Out & EP In address, EP size
- TUD_AUDIO_HEADSET_STEREO_DESCRIPTOR(2, EPNUM_AUDIO_OUT, EPNUM_AUDIO_IN | 0x80, EPNUM_AUDIO_INT | 0x80)
+ // String index, EP Out & EP In address, EP Interrupt address
+ TUD_AUDIO20_HEADSET_STEREO_DESCRIPTOR(5, EPNUM_AUDIO_OUT, EPNUM_AUDIO_IN | 0x80, EPNUM_AUDIO_INT | 0x80)
};
+TU_VERIFY_STATIC(sizeof(desc_uac2_configuration) == CONFIG_UAC2_TOTAL_LEN, "Incorrect size");
+
+
+// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
+tusb_desc_device_qualifier_t const desc_device_qualifier =
+{
+ .bLength = sizeof(tusb_desc_device_qualifier_t),
+ .bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
+ .bcdUSB = 0x0200,
+
+ .bDeviceClass = TUSB_CLASS_MISC,
+ .bDeviceSubClass = MISC_SUBCLASS_COMMON,
+ .bDeviceProtocol = MISC_PROTOCOL_IAD,
+
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+ .bNumConfigurations = 0x01,
+ .bReserved = 0x00
+};
+
+// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
+// device_qualifier descriptor describes information about a high-speed capable device that would
+// change if the device were operating at the other speed. If not highspeed capable stall this request.
+uint8_t const *tud_descriptor_device_qualifier_cb(void)
+{
+ return (uint8_t const *) &desc_device_qualifier;
+}
+
+// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
+uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index)
+{
+ (void) index; // for multiple configurations
+
+ // if link speed is high return fullspeed config, and vice versa
+ return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_uac1_configuration : desc_uac2_configuration;
+}
+#endif
+
// Invoked when received GET CONFIGURATION DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
{
(void)index; // for multiple configurations
- return desc_configuration;
+#if TUD_OPT_HIGH_SPEED
+ // Although we are highspeed, host may be fullspeed.
+ if(tud_speed_get() == TUSB_SPEED_FULL) {
+ return desc_uac1_configuration;
+ } else {
+ return desc_uac2_configuration;
+ }
+#else
+ return desc_uac1_configuration;
+#endif
}
//--------------------------------------------------------------------+
@@ -141,14 +212,14 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
- "TinyUSB headset", // 2: Product
+ "TinyUSB Headset", // 2: Product
NULL, // 3: Serials will use unique ID if possible
- "TinyUSB Speakers", // 4: Audio Interface
- "TinyUSB Microphone", // 5: Audio Interface
+ "TinyUSB UAC1 Headset", // 4: Function
+ "TinyUSB UAC2 Headset", // 5: Function
};
static uint16_t _desc_str[32 + 1];
diff --git a/examples/device/uac2_headset/src/usb_descriptors.h b/examples/device/uac2_headset/src/usb_descriptors.h
index da0da83e8..47154626e 100644
--- a/examples/device/uac2_headset/src/usb_descriptors.h
+++ b/examples/device/uac2_headset/src/usb_descriptors.h
@@ -23,10 +23,20 @@
*
*/
-#ifndef _USB_DESCRIPTORS_H_
-#define _USB_DESCRIPTORS_H_
+#ifndef USB_DESCRIPTORS_H_
+#define USB_DESCRIPTORS_H_
-// #include "tusb.h"
+enum
+{
+ ITF_NUM_AUDIO_CONTROL = 0,
+ ITF_NUM_AUDIO_STREAMING_SPK,
+ ITF_NUM_AUDIO_STREAMING_MIC,
+ ITF_NUM_TOTAL
+};
+
+//--------------------------------------------------------------------+
+// UAC2 DESCRIPTOR TEMPLATES
+//--------------------------------------------------------------------+
// Unit numbers are arbitrary selected
#define UAC2_ENTITY_CLOCK 0x04
@@ -38,121 +48,192 @@
#define UAC2_ENTITY_MIC_INPUT_TERMINAL 0x11
#define UAC2_ENTITY_MIC_OUTPUT_TERMINAL 0x13
-enum
-{
- ITF_NUM_AUDIO_CONTROL = 0,
- ITF_NUM_AUDIO_STREAMING_SPK,
- ITF_NUM_AUDIO_STREAMING_MIC,
- ITF_NUM_TOTAL
-};
-
-#define TUD_AUDIO_HEADSET_STEREO_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
- + TUD_AUDIO_DESC_STD_AC_LEN\
- + TUD_AUDIO_DESC_CS_AC_LEN\
- + TUD_AUDIO_DESC_CLK_SRC_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- + TUD_AUDIO_DESC_STD_AC_INT_EP_LEN\
+#define TUD_AUDIO20_HEADSET_STEREO_DESC_LEN (TUD_AUDIO20_DESC_IAD_LEN\
+ + TUD_AUDIO20_DESC_STD_AC_LEN\
+ + TUD_AUDIO20_DESC_CS_AC_LEN\
+ + TUD_AUDIO20_DESC_CLK_SRC_LEN\
+ + TUD_AUDIO20_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(2)\
+ + TUD_AUDIO20_DESC_OUTPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_OUTPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_STD_AC_INT_EP_LEN\
/* Interface 1, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
/* Interface 1, Alternate 1 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
/* Interface 1, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
/* Interface 2, Alternate 0 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
/* Interface 2, Alternate 1 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
/* Interface 2, Alternate 2 */\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN)
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN)
-#define TUD_AUDIO_HEADSET_STEREO_DESCRIPTOR(_stridx, _epout, _epin, _epint) \
+#define TUD_AUDIO20_HEADSET_STEREO_DESCRIPTOR(_stridx, _epout, _epin, _epint) \
/* Standard Interface Association Descriptor (IAD) */\
- TUD_AUDIO_DESC_IAD(/*_firstitf*/ ITF_NUM_AUDIO_CONTROL, /*_nitfs*/ ITF_NUM_TOTAL, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_IAD(/*_firstitf*/ ITF_NUM_AUDIO_CONTROL, /*_nitfs*/ ITF_NUM_TOTAL, /*_stridx*/ 0x00),\
/* Standard AC Interface Descriptor(4.7.1) */\
- TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
+ TUD_AUDIO20_DESC_STD_AC(/*_itfnum*/ ITF_NUM_AUDIO_CONTROL, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
/* Class-Specific AC Interface Header Descriptor(4.7.2) */\
- TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_HEADSET, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
+ TUD_AUDIO20_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO20_FUNC_HEADSET, /*_totallen*/ TUD_AUDIO20_DESC_CLK_SRC_LEN+TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(2)+TUD_AUDIO20_DESC_INPUT_TERM_LEN+TUD_AUDIO20_DESC_OUTPUT_TERM_LEN+TUD_AUDIO20_DESC_INPUT_TERM_LEN+TUD_AUDIO20_DESC_OUTPUT_TERM_LEN, /*_ctrl*/ AUDIO20_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
/* Clock Source Descriptor(4.7.2.1) */\
- TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ 3, /*_ctrl*/ 7, /*_assocTerm*/ 0x00, /*_stridx*/ 0x00), \
+ TUD_AUDIO20_DESC_CLK_SRC(/*_clkid*/ UAC2_ENTITY_CLOCK, /*_attr*/ 3, /*_ctrl*/ 7, /*_assocTerm*/ 0x00, /*_stridx*/ 0x00), \
/* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x02, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x02, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO20_CTRL_R << AUDIO20_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
/* Feature Unit Descriptor(4.7.2.8) */\
- TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL(/*_unitid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_srcid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrlch0master*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch1*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch2*/ (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_FEATURE_UNIT(/*_unitid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_srcid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_stridx*/ 0x00, /*_ctrlch0master*/ (AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch1*/ (AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch2*/ (AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS)),\
/* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_OUT_HEADPHONES, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_SPK_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_OUT_HEADPHONES, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_SPK_FEATURE_UNIT, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
/* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_INPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x00, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO20_CTRL_R << AUDIO20_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
/* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_srcid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_OUTPUT_TERM(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_srcid*/ UAC2_ENTITY_MIC_INPUT_TERMINAL, /*_clkid*/ UAC2_ENTITY_CLOCK, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
/* Standard AC Interrupt Endpoint Descriptor(4.8.2.1) */\
- TUD_AUDIO_DESC_STD_AC_INT_EP(/*_ep*/ _epint, /*_interval*/ 0x01), \
+ TUD_AUDIO20_DESC_STD_AC_INT_EP(/*_ep*/ _epint, /*_interval*/ 0x01), \
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x05),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ADAPTIVE | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ADAPTIVE | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
/* Interface 1, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x05),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_SPK), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_SPK_INPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_RX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ADAPTIVE | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ADAPTIVE | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 2, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x04),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 2, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_RESOLUTION_TX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_1_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
/* Interface 2, Alternate 2 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ 0x04),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)(ITF_NUM_AUDIO_STREAMING_MIC), /*_altset*/ 0x02, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ UAC2_ENTITY_MIC_OUTPUT_TERMINAL, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_RESOLUTION_TX),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_FORMAT_2_N_BYTES_PER_SAMPLE_TX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX), /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
+
+//--------------------------------------------------------------------+
+// UAC1 DESCRIPTOR TEMPLATES
+//--------------------------------------------------------------------+
+
+// UAC1 entity IDs for speaker and microphone
+// Speaker path
+#define UAC1_ENTITY_SPK_INPUT_TERMINAL 0x01
+#define UAC1_ENTITY_SPK_FEATURE_UNIT 0x02
+#define UAC1_ENTITY_SPK_OUTPUT_TERMINAL 0x03
+// Microphone path
+#define UAC1_ENTITY_MIC_INPUT_TERMINAL 0x11
+#define UAC1_ENTITY_MIC_OUTPUT_TERMINAL 0x13
+
+#define TUD_AUDIO10_HEADSET_STEREO_DESC_LEN(_nfreqs) (\
+ +TUD_AUDIO10_DESC_STD_AC_LEN\
+ + TUD_AUDIO10_DESC_CS_AC_LEN(2)\
+ + TUD_AUDIO10_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO10_DESC_FEATURE_UNIT_LEN(2)\
+ + TUD_AUDIO10_DESC_OUTPUT_TERM_LEN\
+ + TUD_AUDIO10_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO10_DESC_OUTPUT_TERM_LEN\
+ /* Interface 1, Alternate 0 (speaker) */\
+ + TUD_AUDIO10_DESC_STD_AS_LEN\
+ /* Interface 1, Alternate 1 (speaker) */\
+ + TUD_AUDIO10_DESC_STD_AS_LEN\
+ + TUD_AUDIO10_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO10_DESC_TYPE_I_FORMAT_LEN(_nfreqs)\
+ + TUD_AUDIO10_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO10_DESC_CS_AS_ISO_EP_LEN\
+ /* Interface 2, Alternate 0 (microphone) */\
+ + TUD_AUDIO10_DESC_STD_AS_LEN\
+ /* Interface 2, Alternate 1 (microphone) */\
+ + TUD_AUDIO10_DESC_STD_AS_LEN\
+ + TUD_AUDIO10_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO10_DESC_TYPE_I_FORMAT_LEN(_nfreqs)\
+ + TUD_AUDIO10_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO10_DESC_CS_AS_ISO_EP_LEN)
+
+
+#define TUD_AUDIO10_HEADSET_STEREO_DESCRIPTOR(_itfnum, _stridx, _nBytesPerSample_RX, _nBitsUsedPerSample_RX, _nBytesPerSample_TX, _nBitsUsedPerSample_TX, _epout, _epoutsize, _epin, _epinsize, ...) \
+ /* Standard AC Interface Descriptor(4.3.1) */\
+ TUD_AUDIO10_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
+ /* Class-Specific AC Interface Header Descriptor(4.3.2) */\
+ TUD_AUDIO10_DESC_CS_AC(/*_bcdADC*/ 0x0100, /*_totallen*/ (TUD_AUDIO10_DESC_INPUT_TERM_LEN+TUD_AUDIO10_DESC_FEATURE_UNIT_LEN(2)+TUD_AUDIO10_DESC_OUTPUT_TERM_LEN+TUD_AUDIO10_DESC_INPUT_TERM_LEN+TUD_AUDIO10_DESC_FEATURE_UNIT_LEN(1)+TUD_AUDIO10_DESC_OUTPUT_TERM_LEN), /*_itf*/ ((_itfnum)+1), ((_itfnum)+2)),\
+ /* Speaker Input Terminal Descriptor(4.3.2.1) */\
+ TUD_AUDIO10_DESC_INPUT_TERM(/*_termid*/ UAC1_ENTITY_SPK_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ UAC1_ENTITY_MIC_OUTPUT_TERMINAL, /*_nchannels*/ 0x02, /*_channelcfg*/ AUDIO10_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_stridx*/ 0x00),\
+ /* Speaker Feature Unit Descriptor(4.3.2.5) */\
+ TUD_AUDIO10_DESC_FEATURE_UNIT(/*_unitid*/ UAC1_ENTITY_SPK_FEATURE_UNIT, /*_srcid*/ UAC1_ENTITY_SPK_INPUT_TERMINAL, /*_stridx*/ 0x00, /*_ctrlmaster*/ (AUDIO10_FU_CONTROL_BM_MUTE | AUDIO10_FU_CONTROL_BM_VOLUME), /*_ctrlch1*/ (AUDIO10_FU_CONTROL_BM_MUTE | AUDIO10_FU_CONTROL_BM_VOLUME), /*_ctrlch2*/ (AUDIO10_FU_CONTROL_BM_MUTE | AUDIO10_FU_CONTROL_BM_VOLUME)),\
+ /* Speaker Output Terminal Descriptor(4.3.2.2) */\
+ TUD_AUDIO10_DESC_OUTPUT_TERM(/*_termid*/ UAC1_ENTITY_SPK_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_OUT_HEADPHONES, /*_assocTerm*/ 0x00, /*_srcid*/ UAC1_ENTITY_SPK_FEATURE_UNIT, /*_stridx*/ 0x00),\
+ /* Microphone Input Terminal Descriptor(4.3.2.1) */\
+ TUD_AUDIO10_DESC_INPUT_TERM(/*_termid*/ UAC1_ENTITY_MIC_INPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x00, /*_nchannels*/ 0x01, /*_channelcfg*/ AUDIO10_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_stridx*/ 0x00),\
+ /* Microphone Output Terminal Descriptor(4.3.2.2) */\
+ TUD_AUDIO10_DESC_OUTPUT_TERM(/*_termid*/ UAC1_ENTITY_MIC_OUTPUT_TERMINAL, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ UAC1_ENTITY_SPK_INPUT_TERMINAL, /*_srcid*/ UAC1_ENTITY_MIC_INPUT_TERMINAL, /*_stridx*/ 0x00),\
+ /* Standard AS Interface Descriptor(4.5.1) - Speaker Interface 1, Alternate 0 */\
+ TUD_AUDIO10_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
+ /* Standard AS Interface Descriptor(4.5.1) - Speaker Interface 1, Alternate 1 */\
+ TUD_AUDIO10_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
+ /* Class-Specific AS Interface Descriptor(4.5.2) */\
+ TUD_AUDIO10_DESC_CS_AS_INT(/*_termid*/ UAC1_ENTITY_SPK_INPUT_TERMINAL, /*_delay*/ 0x01, /*_formattype*/ AUDIO10_DATA_FORMAT_TYPE_I_PCM),\
+ /* Type I Format Type Descriptor(2.2.5) */\
+ TUD_AUDIO10_DESC_TYPE_I_FORMAT(/*_nrchannels*/ 0x02, /*_subframesize*/ _nBytesPerSample_RX, /*_bitresolution*/ _nBitsUsedPerSample_RX, /*_freqs*/ __VA_ARGS__),\
+ /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.6.1.1) */\
+ TUD_AUDIO10_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ADAPTIVE), /*_maxEPsize*/ _epoutsize, /*_interval*/ 0x01, /*_syncep*/ 0x00),\
+ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.6.1.2) */\
+ TUD_AUDIO10_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO10_CS_AS_ISO_DATA_EP_ATT_SAMPLING_FRQ, /*_lockdelayunits*/ AUDIO10_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
+ /* Standard AS Interface Descriptor(4.5.1) - Microphone Interface 2, Alternate 0 */\
+ TUD_AUDIO10_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+2), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
+ /* Standard AS Interface Descriptor(4.5.1) - Microphone Interface 2, Alternate 1 */\
+ TUD_AUDIO10_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+2), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ _stridx),\
+ /* Class-Specific AS Interface Descriptor(4.5.2) */\
+ TUD_AUDIO10_DESC_CS_AS_INT(/*_termid*/ UAC1_ENTITY_MIC_OUTPUT_TERMINAL, /*_delay*/ 0x01, /*_formattype*/ AUDIO10_DATA_FORMAT_TYPE_I_PCM),\
+ /* Type I Format Type Descriptor(2.2.5) */\
+ TUD_AUDIO10_DESC_TYPE_I_FORMAT(/*_nrchannels*/ 0x01, /*_subframesize*/ _nBytesPerSample_TX, /*_bitresolution*/ _nBitsUsedPerSample_TX, /*_freqs*/ __VA_ARGS__),\
+ /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.6.1.1) */\
+ TUD_AUDIO10_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS), /*_maxEPsize*/ _epinsize, /*_interval*/ 0x01, /*_syncep*/ 0x00),\
+ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.6.1.2) */\
+ TUD_AUDIO10_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO10_CS_AS_ISO_DATA_EP_ATT_SAMPLING_FRQ, /*_lockdelayunits*/ AUDIO10_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001)
#endif
diff --git a/examples/device/uac2_speaker_fb/CMakeLists.txt b/examples/device/uac2_speaker_fb/CMakeLists.txt
index 0ed3db646..ced98a909 100644
--- a/examples/device/uac2_speaker_fb/CMakeLists.txt
+++ b/examples/device/uac2_speaker_fb/CMakeLists.txt
@@ -21,7 +21,6 @@ add_executable(${PROJECT})
target_sources(${PROJECT} PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c
${CMAKE_CURRENT_SOURCE_DIR}/src/usb_descriptors.c
- ${CMAKE_CURRENT_SOURCE_DIR}/src/quirk_os_guessing.c
)
# Example include
diff --git a/examples/device/uac2_speaker_fb/Makefile b/examples/device/uac2_speaker_fb/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/uac2_speaker_fb/Makefile
+++ b/examples/device/uac2_speaker_fb/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/uac2_speaker_fb/src/common_types.h b/examples/device/uac2_speaker_fb/src/common_types.h
index 174e26671..b79ae2fd0 100644
--- a/examples/device/uac2_speaker_fb/src/common_types.h
+++ b/examples/device/uac2_speaker_fb/src/common_types.h
@@ -41,7 +41,7 @@ typedef struct
{
uint32_t sample_rate;
uint8_t alt_settings;
- int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1];
+ uint8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1];
int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1];
uint16_t fifo_size;
uint16_t fifo_count;
diff --git a/examples/device/uac2_speaker_fb/src/main.c b/examples/device/uac2_speaker_fb/src/main.c
index ed9e7716d..7b4e2d64c 100644
--- a/examples/device/uac2_speaker_fb/src/main.c
+++ b/examples/device/uac2_speaker_fb/src/main.c
@@ -31,25 +31,10 @@
#include "tusb.h"
#include "usb_descriptors.h"
-#ifdef CFG_QUIRK_OS_GUESSING
- #include "quirk_os_guessing.h"
-#endif
-
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTOTYPES
//--------------------------------------------------------------------+
-// List of supported sample rates
-#if defined(__RX__)
-const uint32_t sample_rates[] = {44100, 48000};
-#else
-const uint32_t sample_rates[] = {44100, 48000, 88200, 96000};
-#endif
-
-uint32_t current_sample_rate = 44100;
-
-#define N_SAMPLE_RATES TU_ARRAY_SIZE(sample_rates)
-
/* Blink pattern
* - 25 ms : streaming data
* - 250 ms : device not mounted
@@ -82,8 +67,9 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
// Audio controls
// Current states
-int8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
+uint8_t mute[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1]; // +1 for master channel 0
int16_t volume[CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX + 1];// +1 for master channel 0
+uint32_t current_sample_rate = 44100;
// Buffer for speaker data
uint16_t i2s_dummy_buffer[CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ / 2];
@@ -153,18 +139,193 @@ void tud_resume_cb(void) {
// Application Callback API Implementations
//--------------------------------------------------------------------+
-// Helper for clock get requests
-static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t const *request) {
+//--------------------------------------------------------------------+
+// UAC1 Helper Functions
+//--------------------------------------------------------------------+
+
+static bool audio10_set_req_ep(tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+
+ switch (ctrlSel) {
+ case AUDIO10_EP_CTRL_SAMPLING_FREQ:
+ if (p_request->bRequest == AUDIO10_CS_REQ_SET_CUR) {
+ // Request uses 3 bytes
+ TU_VERIFY(p_request->wLength == 3);
+
+ current_sample_rate = tu_unaligned_read32(pBuff) & 0x00FFFFFF;
+
+ TU_LOG2("EP set current freq: %" PRIu32 "\r\n", current_sample_rate);
+
+ return true;
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+
+ return false;
+}
+
+static bool audio10_get_req_ep(uint8_t rhport, tusb_control_request_t const *p_request) {
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+
+ switch (ctrlSel) {
+ case AUDIO10_EP_CTRL_SAMPLING_FREQ:
+ if (p_request->bRequest == AUDIO10_CS_REQ_GET_CUR) {
+ TU_LOG2("EP get current freq\r\n");
+
+ uint8_t freq[3];
+ freq[0] = (uint8_t) (current_sample_rate & 0xFF);
+ freq[1] = (uint8_t) ((current_sample_rate >> 8) & 0xFF);
+ freq[2] = (uint8_t) ((current_sample_rate >> 16) & 0xFF);
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, freq, sizeof(freq));
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+
+ return false;
+}
+
+static bool audio10_set_req_entity(tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ uint8_t channelNum = TU_U16_LOW(p_request->wValue);
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+ uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
+
+ // If request is for our feature unit
+ if (entityID == UAC1_ENTITY_FEATURE_UNIT) {
+ switch (ctrlSel) {
+ case AUDIO10_FU_CTRL_MUTE:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_SET_CUR:
+ // Only 1st form is supported
+ TU_VERIFY(p_request->wLength == 1);
+
+ mute[channelNum] = pBuff[0];
+
+ TU_LOG2(" Set Mute: %d of channel: %u\r\n", mute[channelNum], channelNum);
+ return true;
+
+ default:
+ return false; // not supported
+ }
+
+ case AUDIO10_FU_CTRL_VOLUME:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_SET_CUR:
+ // Only 1st form is supported
+ TU_VERIFY(p_request->wLength == 2);
+
+ volume[channelNum] = (int16_t)tu_unaligned_read16(pBuff) / 256;
+
+ TU_LOG2(" Set Volume: %d dB of channel: %u\r\n", volume[channelNum], channelNum);
+ return true;
+
+ default:
+ return false; // not supported
+ }
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ }
+
+ return false;
+}
+
+static bool audio10_get_req_entity(uint8_t rhport, tusb_control_request_t const *p_request) {
+ uint8_t channelNum = TU_U16_LOW(p_request->wValue);
+ uint8_t ctrlSel = TU_U16_HIGH(p_request->wValue);
+ uint8_t entityID = TU_U16_HIGH(p_request->wIndex);
+
+ // If request is for our feature unit
+ if (entityID == UAC1_ENTITY_FEATURE_UNIT) {
+ switch (ctrlSel) {
+ case AUDIO10_FU_CTRL_MUTE:
+ // Audio control mute cur parameter block consists of only one byte - we thus can send it right away
+ // There does not exist a range parameter block for mute
+ TU_LOG2(" Get Mute of channel: %u\r\n", channelNum);
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &mute[channelNum], 1);
+
+ case AUDIO10_FU_CTRL_VOLUME:
+ switch (p_request->bRequest) {
+ case AUDIO10_CS_REQ_GET_CUR:
+ TU_LOG2(" Get Volume of channel: %u\r\n", channelNum);
+ {
+ int16_t vol = (int16_t) volume[channelNum];
+ vol = vol * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &vol, sizeof(vol));
+ }
+
+ case AUDIO10_CS_REQ_GET_MIN:
+ TU_LOG2(" Get Volume min of channel: %u\r\n", channelNum);
+ {
+ int16_t min = -90; // -90 dB
+ min = min * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &min, sizeof(min));
+ }
+
+ case AUDIO10_CS_REQ_GET_MAX:
+ TU_LOG2(" Get Volume max of channel: %u\r\n", channelNum);
+ {
+ int16_t max = 30; // +30 dB
+ max = max * 256; // convert to 1/256 dB units
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &max, sizeof(max));
+ }
+
+ case AUDIO10_CS_REQ_GET_RES:
+ TU_LOG2(" Get Volume res of channel: %u\r\n", channelNum);
+ {
+ int16_t res = 128; // 0.5 dB
+ return tud_audio_buffer_and_schedule_control_xfer(rhport, p_request, &res, sizeof(res));
+ }
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ break;
+
+ // Unknown/Unsupported control
+ default:
+ TU_BREAKPOINT();
+ return false;
+ }
+ }
+
+ return false;
+}
+
+//--------------------------------------------------------------------+
+// UAC2 Helper Functions
+//--------------------------------------------------------------------+
+
+#if TUD_OPT_HIGH_SPEED
+// List of supported sample rates for UAC2
+const uint32_t sample_rates[] = {44100, 48000, 88200, 96000};
+
+#define N_SAMPLE_RATES TU_ARRAY_SIZE(sample_rates)
+
+static bool audio20_clock_get_request(uint8_t rhport, audio20_control_request_t const *request) {
TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ) {
- if (request->bRequest == AUDIO_CS_REQ_CUR) {
- TU_LOG1("Clock get current freq %lu\r\n", current_sample_rate);
+ if (request->bControlSelector == AUDIO20_CS_CTRL_SAM_FREQ) {
+ if (request->bRequest == AUDIO20_CS_REQ_CUR) {
+ TU_LOG1("Clock get current freq %" PRIu32 "\r\n", current_sample_rate);
- audio_control_cur_4_t curf = {(int32_t) tu_htole32(current_sample_rate)};
+ audio20_control_cur_4_t curf = {(int32_t) tu_htole32(current_sample_rate)};
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &curf, sizeof(curf));
- } else if (request->bRequest == AUDIO_CS_REQ_RANGE) {
- audio_control_range_4_n_t(N_SAMPLE_RATES) rangef =
+ } else if (request->bRequest == AUDIO20_CS_REQ_RANGE) {
+ audio20_control_range_4_n_t(N_SAMPLE_RATES) rangef =
{
.wNumSubRanges = tu_htole16(N_SAMPLE_RATES)};
TU_LOG1("Clock get %d freq ranges\r\n", N_SAMPLE_RATES);
@@ -177,9 +338,9 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &rangef, sizeof(rangef));
}
- } else if (request->bControlSelector == AUDIO_CS_CTRL_CLK_VALID &&
- request->bRequest == AUDIO_CS_REQ_CUR) {
- audio_control_cur_1_t cur_valid = {.bCur = 1};
+ } else if (request->bControlSelector == AUDIO20_CS_CTRL_CLK_VALID &&
+ request->bRequest == AUDIO20_CS_REQ_CUR) {
+ audio20_control_cur_1_t cur_valid = {.bCur = 1};
TU_LOG1("Clock get is valid %u\r\n", cur_valid.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &cur_valid, sizeof(cur_valid));
}
@@ -188,19 +349,16 @@ static bool tud_audio_clock_get_request(uint8_t rhport, audio_control_request_t
return false;
}
-// Helper for clock set requests
-static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf) {
- (void) rhport;
-
+static bool audio20_clock_set_request(audio20_control_request_t const *request, uint8_t const *buf) {
TU_ASSERT(request->bEntityID == UAC2_ENTITY_CLOCK);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(request->bRequest == AUDIO20_CS_REQ_CUR);
- if (request->bControlSelector == AUDIO_CS_CTRL_SAM_FREQ) {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_4_t));
+ if (request->bControlSelector == AUDIO20_CS_CTRL_SAM_FREQ) {
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_4_t));
- current_sample_rate = (uint32_t) ((audio_control_cur_4_t const *) buf)->bCur;
+ current_sample_rate = (uint32_t) ((audio20_control_cur_4_t const *) buf)->bCur;
- TU_LOG1("Clock set current freq: %ld\r\n", current_sample_rate);
+ TU_LOG1("Clock set current freq: %" PRIu32 "\r\n", current_sample_rate);
return true;
} else {
@@ -210,24 +368,23 @@ static bool tud_audio_clock_set_request(uint8_t rhport, audio_control_request_t
}
}
-// Helper for feature unit get requests
-static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_request_t const *request) {
+static bool audio20_feature_unit_get_request(uint8_t rhport, audio20_control_request_t const *request) {
TU_ASSERT(request->bEntityID == UAC2_ENTITY_FEATURE_UNIT);
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE && request->bRequest == AUDIO_CS_REQ_CUR) {
- audio_control_cur_1_t mute1 = {.bCur = mute[request->bChannelNumber]};
+ if (request->bControlSelector == AUDIO20_FU_CTRL_MUTE && request->bRequest == AUDIO20_CS_REQ_CUR) {
+ audio20_control_cur_1_t mute1 = {.bCur = mute[request->bChannelNumber]};
TU_LOG1("Get channel %u mute %d\r\n", request->bChannelNumber, mute1.bCur);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &mute1, sizeof(mute1));
- } else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME) {
- if (request->bRequest == AUDIO_CS_REQ_RANGE) {
- audio_control_range_2_n_t(1) range_vol = {
+ } else if (request->bControlSelector == AUDIO20_FU_CTRL_VOLUME) {
+ if (request->bRequest == AUDIO20_CS_REQ_RANGE) {
+ audio20_control_range_2_n_t(1) range_vol = {
.wNumSubRanges = tu_htole16(1),
.subrange[0] = {.bMin = tu_htole16(-VOLUME_CTRL_50_DB), tu_htole16(VOLUME_CTRL_0_DB), tu_htole16(256)}};
TU_LOG1("Get channel %u volume range (%d, %d, %u) dB\r\n", request->bChannelNumber,
range_vol.subrange[0].bMin / 256, range_vol.subrange[0].bMax / 256, range_vol.subrange[0].bRes / 256);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &range_vol, sizeof(range_vol));
- } else if (request->bRequest == AUDIO_CS_REQ_CUR) {
- audio_control_cur_2_t cur_vol = {.bCur = tu_htole16(volume[request->bChannelNumber])};
+ } else if (request->bRequest == AUDIO20_CS_REQ_CUR) {
+ audio20_control_cur_2_t cur_vol = {.bCur = tu_htole16(volume[request->bChannelNumber])};
TU_LOG1("Get channel %u volume %d dB\r\n", request->bChannelNumber, cur_vol.bCur / 256);
return tud_audio_buffer_and_schedule_control_xfer(rhport, (tusb_control_request_t const *) request, &cur_vol, sizeof(cur_vol));
}
@@ -238,25 +395,22 @@ static bool tud_audio_feature_unit_get_request(uint8_t rhport, audio_control_req
return false;
}
-// Helper for feature unit set requests
-static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_request_t const *request, uint8_t const *buf) {
- (void) rhport;
-
+static bool audio20_feature_unit_set_request(audio20_control_request_t const *request, uint8_t const *buf) {
TU_ASSERT(request->bEntityID == UAC2_ENTITY_FEATURE_UNIT);
- TU_VERIFY(request->bRequest == AUDIO_CS_REQ_CUR);
+ TU_VERIFY(request->bRequest == AUDIO20_CS_REQ_CUR);
- if (request->bControlSelector == AUDIO_FU_CTRL_MUTE) {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_1_t));
+ if (request->bControlSelector == AUDIO20_FU_CTRL_MUTE) {
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_1_t));
- mute[request->bChannelNumber] = ((audio_control_cur_1_t const *) buf)->bCur;
+ mute[request->bChannelNumber] = ((audio20_control_cur_1_t const *) buf)->bCur;
TU_LOG1("Set channel %d Mute: %d\r\n", request->bChannelNumber, mute[request->bChannelNumber]);
return true;
- } else if (request->bControlSelector == AUDIO_FU_CTRL_VOLUME) {
- TU_VERIFY(request->wLength == sizeof(audio_control_cur_2_t));
+ } else if (request->bControlSelector == AUDIO20_FU_CTRL_VOLUME) {
+ TU_VERIFY(request->wLength == sizeof(audio20_control_cur_2_t));
- volume[request->bChannelNumber] = ((audio_control_cur_2_t const *) buf)->bCur;
+ volume[request->bChannelNumber] = ((audio20_control_cur_2_t const *) buf)->bCur;
TU_LOG1("Set channel %d volume: %d dB\r\n", request->bChannelNumber, volume[request->bChannelNumber] / 256);
@@ -268,14 +422,13 @@ static bool tud_audio_feature_unit_set_request(uint8_t rhport, audio_control_req
}
}
-// Invoked when audio class specific get request received for an entity
-bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
- audio_control_request_t const *request = (audio_control_request_t const *) p_request;
+static bool audio20_get_req_entity(uint8_t rhport, tusb_control_request_t const *p_request) {
+ audio20_control_request_t const *request = (audio20_control_request_t const *) p_request;
if (request->bEntityID == UAC2_ENTITY_CLOCK)
- return tud_audio_clock_get_request(rhport, request);
+ return audio20_clock_get_request(rhport, request);
if (request->bEntityID == UAC2_ENTITY_FEATURE_UNIT)
- return tud_audio_feature_unit_get_request(rhport, request);
+ return audio20_feature_unit_get_request(rhport, request);
else {
TU_LOG1("Get request not handled, entity = %d, selector = %d, request = %d\r\n",
request->bEntityID, request->bControlSelector, request->bRequest);
@@ -283,31 +436,24 @@ bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p
return false;
}
-// Invoked when audio class specific set request received for an entity
-bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf) {
- audio_control_request_t const *request = (audio_control_request_t const *) p_request;
+static bool audio20_set_req_entity(tusb_control_request_t const *p_request, uint8_t *buf) {
+ audio20_control_request_t const *request = (audio20_control_request_t const *) p_request;
if (request->bEntityID == UAC2_ENTITY_FEATURE_UNIT)
- return tud_audio_feature_unit_set_request(rhport, request, buf);
+ return audio20_feature_unit_set_request(request, buf);
if (request->bEntityID == UAC2_ENTITY_CLOCK)
- return tud_audio_clock_set_request(rhport, request, buf);
+ return audio20_clock_set_request(request, buf);
TU_LOG1("Set request not handled, entity = %d, selector = %d, request = %d\r\n",
request->bEntityID, request->bControlSelector, request->bRequest);
return false;
}
-bool tud_audio_set_itf_close_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
- (void) rhport;
-
- uint8_t const itf = tu_u16_low(tu_le16toh(p_request->wIndex));
- uint8_t const alt = tu_u16_low(tu_le16toh(p_request->wValue));
-
- if (ITF_NUM_AUDIO_STREAMING == itf && alt == 0)
- blink_interval_ms = BLINK_MOUNTED;
+#endif // TUD_OPT_HIGH_SPEED
- return true;
-}
+//--------------------------------------------------------------------+
+// Main Callback Functions
+//--------------------------------------------------------------------+
bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
(void) rhport;
@@ -325,12 +471,92 @@ bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const *p_reques
return true;
}
+// Invoked when audio class specific set request received for an EP
+bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *pBuff) {
+ (void) rhport;
+ (void) pBuff;
+
+ if (tud_audio_version() == 1) {
+ return audio10_set_req_ep(p_request, pBuff);
+ } else if (tud_audio_version() == 2) {
+ // We do not support any requests here
+ }
+
+ return false;// Yet not implemented
+}
+
+// Invoked when audio class specific get request received for an EP
+bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_get_req_ep(rhport, p_request);
+ } else if (tud_audio_version() == 2) {
+ // We do not support any requests here
+ }
+
+ return false;// Yet not implemented
+}
+
+// Invoked when audio class specific set request received for an entity
+bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request, uint8_t *buf) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_set_req_entity(p_request, buf);
+#if TUD_OPT_HIGH_SPEED
+ } else if (tud_audio_version() == 2) {
+ return audio20_set_req_entity(p_request, buf);
+#endif
+ }
+
+ return false;
+}
+
+// Invoked when audio class specific get request received for an entity
+bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+
+ if (tud_audio_version() == 1) {
+ return audio10_get_req_entity(rhport, p_request);
+#if TUD_OPT_HIGH_SPEED
+ } else if (tud_audio_version() == 2) {
+ return audio20_get_req_entity(rhport, p_request);
+#endif
+ }
+
+ return false;
+}
+
+bool tud_audio_set_itf_close_ep_cb(uint8_t rhport, tusb_control_request_t const *p_request) {
+ (void) rhport;
+
+ uint8_t const itf = tu_u16_low(tu_le16toh(p_request->wIndex));
+ uint8_t const alt = tu_u16_low(tu_le16toh(p_request->wValue));
+
+ if (ITF_NUM_AUDIO_STREAMING == itf && alt == 0)
+ blink_interval_ms = BLINK_MOUNTED;
+
+ return true;
+}
+
void tud_audio_feedback_params_cb(uint8_t func_id, uint8_t alt_itf, audio_feedback_params_t *feedback_param) {
(void) func_id;
(void) alt_itf;
// Set feedback method to fifo counting
feedback_param->method = AUDIO_FEEDBACK_METHOD_FIFO_COUNT;
feedback_param->sample_freq = current_sample_rate;
+
+ // About FIFO threshold:
+ //
+ // By default the threshold is set to half FIFO size, which works well in most cases,
+ // you can reduce the threshold to have less latency.
+ //
+ // For example, here we could set the threshold to 2 ms of audio data, as audio_task() read audio data every 1 ms,
+ // having 2 ms threshold allows some margin and a quick response:
+ //
+ // feedback_param->fifo_count.fifo_threshold =
+ // current_sample_rate * CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX * CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX / 1000 * 2;
}
#if CFG_AUDIO_DEBUG
@@ -349,16 +575,6 @@ bool tud_audio_rx_done_isr(uint8_t rhport, uint16_t n_bytes_received, uint8_t fu
}
#endif
-#if CFG_QUIRK_OS_GUESSING
-bool tud_audio_feedback_format_correction_cb(uint8_t func_id) {
- (void) func_id;
- if (tud_speed_get() == TUSB_SPEED_FULL && quirk_os_guessing_get() == QUIRK_OS_GUESSING_OSX) {
- return true;
- } else {
- return false;
- }
-}
-#endif
//--------------------------------------------------------------------+
// AUDIO Task
//--------------------------------------------------------------------+
diff --git a/examples/device/uac2_speaker_fb/src/quirk_os_guessing.c b/examples/device/uac2_speaker_fb/src/quirk_os_guessing.c
deleted file mode 100644
index 92b9ab6ee..000000000
--- a/examples/device/uac2_speaker_fb/src/quirk_os_guessing.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2024 HiFiPhile
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#include "quirk_os_guessing.h"
-
-static tusb_desc_type_t desc_req_buf[2];
-static int desc_req_idx = 0;
-
-// Place at the start of tud_descriptor_device_cb()
-void quirk_os_guessing_desc_device_cb(void) {
- desc_req_idx = 0;
-}
-
-// Place at the start of tud_descriptor_configuration_cb()
-void quirk_os_guessing_desc_configuration_cb(void) {
- // Skip redundant request
- if (desc_req_idx == 0 || (desc_req_idx == 1 && desc_req_buf[0] != TUSB_DESC_CONFIGURATION)) {
- desc_req_buf[desc_req_idx++] = TUSB_DESC_CONFIGURATION;
- }
-}
-
-// Place at the start of tud_descriptor_bos_cb()
-void quirk_os_guessing_desc_bos_cb(void) {
- // Skip redundant request
- if (desc_req_idx == 0 || (desc_req_idx == 1 && desc_req_buf[0] != TUSB_DESC_BOS)) {
- desc_req_buf[desc_req_idx++] = TUSB_DESC_BOS;
- }
-}
-
-// Place at the start of tud_descriptor_string_cb()
-void quirk_os_guessing_desc_string_cb(void) {
- // Skip redundant request
- if (desc_req_idx == 0 || (desc_req_idx == 1 && desc_req_buf[0] != TUSB_DESC_STRING)) {
- desc_req_buf[desc_req_idx++] = TUSB_DESC_STRING;
- }
-}
-
-// Each OS request descriptors differently:
-// Windows 10 - 11
-// Device Desc
-// Config Desc
-// BOS Desc
-// String Desc
-// Linux 3.16 - 6.8
-// Device Desc
-// BOS Desc
-// Config Desc
-// String Desc
-// OS X Ventura - Sonoma
-// Device Desc
-// String Desc
-// Config Desc || BOS Desc
-// BOS Desc || Config Desc
-quirk_os_guessing_t quirk_os_guessing_get(void) {
- if (desc_req_idx < 2) {
- return QUIRK_OS_GUESSING_UNKNOWN;
- }
-
- if (desc_req_buf[0] == TUSB_DESC_BOS && desc_req_buf[1] == TUSB_DESC_CONFIGURATION) {
- return QUIRK_OS_GUESSING_LINUX;
- } else if (desc_req_buf[0] == TUSB_DESC_CONFIGURATION && desc_req_buf[1] == TUSB_DESC_BOS) {
- return QUIRK_OS_GUESSING_WINDOWS;
- } else if (desc_req_buf[0] == TUSB_DESC_STRING && (desc_req_buf[1] == TUSB_DESC_BOS || desc_req_buf[1] == TUSB_DESC_CONFIGURATION)) {
- return QUIRK_OS_GUESSING_OSX;
- }
-
- return QUIRK_OS_GUESSING_UNKNOWN;
-}
diff --git a/examples/device/uac2_speaker_fb/src/quirk_os_guessing.h b/examples/device/uac2_speaker_fb/src/quirk_os_guessing.h
deleted file mode 100644
index 1120355c9..000000000
--- a/examples/device/uac2_speaker_fb/src/quirk_os_guessing.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2024 HiFiPhile
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#ifndef _QUIRK_OS_GUESSING_H_
-#define _QUIRK_OS_GUESSING_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-#include "tusb.h"
-
-//================================== !!! WARNING !!! ====================================
-// This quirk operate out of USB specification in order to workaround specific issues.
-// It may not work on your platform.
-//=======================================================================================
-//
-// Prerequisites:
-// - Set USB version to at least 2.01 in Device Descriptor
-// - Has a valid BOS Descriptor, refer to webusb_serial example
-//
-// Attention:
-// Windows detection result comes out after Configuration Descriptor request,
-// meaning it will be too late to do descriptor adjustment. It's advised to make
-// Windows as default configuration and adjust to other OS accordingly.
-
-typedef enum {
- QUIRK_OS_GUESSING_UNKNOWN,
- QUIRK_OS_GUESSING_LINUX,
- QUIRK_OS_GUESSING_OSX,
- QUIRK_OS_GUESSING_WINDOWS,
-} quirk_os_guessing_t;
-
-// Get Host OS type
-quirk_os_guessing_t quirk_os_guessing_get(void);
-
-// Place at the start of tud_descriptor_device_cb()
-void quirk_os_guessing_desc_device_cb(void);
-
-// Place at the start of tud_descriptor_configuration_cb()
-void quirk_os_guessing_desc_configuration_cb(void);
-
-// Place at the start of tud_descriptor_bos_cb()
-void quirk_os_guessing_desc_bos_cb(void);
-
-// Place at the start of tud_descriptor_string_cb()
-void quirk_os_guessing_desc_string_cb(void);
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _QUIRK_OS_GUESSING_H_ */
diff --git a/examples/device/uac2_speaker_fb/src/tusb_config.h b/examples/device/uac2_speaker_fb/src/tusb_config.h
index 18ab2ff96..46f5703c8 100644
--- a/examples/device/uac2_speaker_fb/src/tusb_config.h
+++ b/examples/device/uac2_speaker_fb/src/tusb_config.h
@@ -24,8 +24,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -87,14 +87,6 @@ extern "C" {
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
-/* (Needed for Full-Speed only)
- * Enable host OS guessing to workaround UAC2 compatibility issues between Windows and OS X
- * The default configuration only support Windows and Linux, enable this option for OS X
- * support. Otherwise if you don't need Windows support you can make OS X's configuration as
- * default.
- */
-#define CFG_QUIRK_OS_GUESSING 1
-
//--------------------------------------------------------------------
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
@@ -128,38 +120,33 @@ extern "C" {
// AUDIO CLASS DRIVER CONFIGURATION
//--------------------------------------------------------------------
-#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN TUD_AUDIO_SPEAKER_STEREO_FB_DESC_LEN
-
-// Can be enabled with Full-Speed device on OSX, which forces feedback EP size to 3, in this case CFG_QUIRK_OS_GUESSING can be disabled
-#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION 0
+#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX 2
-// Audio format type I specifications
-#if defined(__RX__)
-#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE 48000
-#else
-#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE 96000
-#endif
+// 16bit data in 16bit slots
+#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX 2
+#define CFG_TUD_AUDIO_FUNC_1_RESOLUTION_RX 16
-#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX 2
+// UAC1 Full-Speed endpoint size
+#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE_FS 48000
+#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_FS TUD_AUDIO_EP_SIZE(false, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE_FS, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
+// UAC2 High-Speed endpoint size
+#define CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE_HS 96000
+#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_HS TUD_AUDIO_EP_SIZE(true, CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE_HS, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
-// 16bit in 16bit slots
-#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX 2
-#define CFG_TUD_AUDIO_FUNC_1_RESOLUTION_RX 16
+#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TU_MAX(CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_FS, CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_HS)
-// EP and buffer size - for isochronous EP´s, the buffer and EP size are equal (different sizes would not make sense)
-#define CFG_TUD_AUDIO_ENABLE_EP_OUT 1
+// AUDIO_FEEDBACK_METHOD_FIFO_COUNT needs buffer size >= 4* EP size to work correctly
+// Example read FIFO every 1ms (8 HS frames), so buffer size should be 8 times larger for HS device
+#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ TU_MAX(4 * CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_FS, 32 * CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_HS)
-#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TUD_AUDIO_EP_SIZE(CFG_TUD_AUDIO_FUNC_1_MAX_SAMPLE_RATE, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX)
-#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ (TUD_OPT_HIGH_SPEED ? 32 : 4) * CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX // Example read FIFO every 1ms, so it should be 8 times larger for HS device
+// Enable OUT EP
+#define CFG_TUD_AUDIO_ENABLE_EP_OUT 1
// Enable feedback EP
-#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP 1
-
-// Size of control request buffer
-#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
+#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP 1
#ifdef __cplusplus
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/uac2_speaker_fb/src/usb_descriptors.c b/examples/device/uac2_speaker_fb/src/usb_descriptors.c
index ee1b92225..697e51483 100644
--- a/examples/device/uac2_speaker_fb/src/usb_descriptors.c
+++ b/examples/device/uac2_speaker_fb/src/usb_descriptors.c
@@ -28,28 +28,24 @@
#include "usb_descriptors.h"
#include "common_types.h"
-#ifdef CFG_QUIRK_OS_GUESSING
-#include "quirk_os_guessing.h"
-#endif
-
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
*
* Auto ProductID layout's Bitmap:
* [MSB] AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VENDOR, 5) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VENDOR, 5) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
- .bcdUSB = 0x0201,
+ .bcdUSB = 0x0200,
// Use Interface Association Descriptor (IAD) for Audio
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
@@ -71,12 +67,8 @@ tusb_desc_device_t const desc_device =
// Invoked when received GET DEVICE DESCRIPTOR
// Application return pointer to descriptor
-uint8_t const * tud_descriptor_device_cb(void)
-{
-#if CFG_QUIRK_OS_GUESSING
- quirk_os_guessing_desc_device_cb();
-#endif
- return (uint8_t const *)&desc_device;
+uint8_t const * tud_descriptor_device_cb(void) {
+ return (uint8_t const *) &desc_device;
}
#if CFG_AUDIO_DEBUG
@@ -84,8 +76,7 @@ uint8_t const * tud_descriptor_device_cb(void)
// HID Report Descriptor
//--------------------------------------------------------------------+
-uint8_t const desc_hid_report[] =
-{
+uint8_t const desc_hid_report[] = {
HID_USAGE_PAGE_N ( HID_USAGE_PAGE_VENDOR, 2 ),\
HID_USAGE ( 0x01 ),\
HID_COLLECTION ( HID_COLLECTION_APPLICATION ),\
@@ -101,8 +92,7 @@ uint8_t const desc_hid_report[] =
// Invoked when received GET HID REPORT DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf)
-{
+uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf) {
(void) itf;
return desc_hid_report;
}
@@ -112,109 +102,126 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf)
// Configuration Descriptor
//--------------------------------------------------------------------+
-#if CFG_AUDIO_DEBUG
- #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO_SPEAKER_STEREO_FB_DESC_LEN + TUD_HID_DESC_LEN)
-#else
- #define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO_SPEAKER_STEREO_FB_DESC_LEN)
-#endif
-
#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
#define EPNUM_AUDIO_FB 0x03
- #define EPNUM_AUDIO_OUT 0x03
#define EPNUM_DEBUG 0x04
-#elif CFG_TUSB_MCU == OPT_MCU_NRF5X
- // ISO endpoints for NRF5x are fixed to 0x08 (0x88)
+#elif TU_CHECK_MCU(OPT_MCU_NRF5X)
+ // nRF5x ISO can only be endpoint 8
+ #define EPNUM_AUDIO 0x08
#define EPNUM_AUDIO_FB 0x08
- #define EPNUM_AUDIO_OUT 0x08
#define EPNUM_DEBUG 0x01
#elif defined(TUD_ENDPOINT_ONE_DIRECTION_ONLY)
// MCUs that don't support a same endpoint number with different direction IN and OUT defined in tusb_mcu.h
// e.g EP1 OUT & EP1 IN cannot exist together
+ #define EPNUM_AUDIO 0x02
#define EPNUM_AUDIO_FB 0x01
- #define EPNUM_AUDIO_OUT 0x02
#define EPNUM_DEBUG 0x03
#else
+ #define EPNUM_AUDIO 0x01
#define EPNUM_AUDIO_FB 0x01
- #define EPNUM_AUDIO_OUT 0x01
#define EPNUM_DEBUG 0x02
#endif
-uint8_t const desc_configuration_default[] =
-{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
+#if CFG_AUDIO_DEBUG
+ #define CONFIG_UAC1_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO10_SPEAKER_STEREO_FB_DESC_LEN(2) + TUD_HID_DESC_LEN)
+#else
+ #define CONFIG_UAC1_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO10_SPEAKER_STEREO_FB_DESC_LEN(2))
+#endif
+
+uint8_t const desc_uac1_configuration[] = {
+ // Config number, interface count, string index, total length, attribute, power in mA
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_UAC1_TOTAL_LEN, 0x00, 100),
- // Interface number, string index, byte per sample, bit per sample, EP Out, EP size, EP feedback, feedback EP size,
- TUD_AUDIO_SPEAKER_STEREO_FB_DESCRIPTOR(0, 4, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_RESOLUTION_RX, EPNUM_AUDIO_OUT, CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX, EPNUM_AUDIO_FB | 0x80, 4),
+ // Interface number, string index, byte per sample, bit per sample, EP Out, EP size, EP feedback, sample rates (44.1kHz, 48kHz)
+ TUD_AUDIO10_SPEAKER_STEREO_FB_DESCRIPTOR(ITF_NUM_AUDIO_CONTROL, 5, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_RESOLUTION_RX, EPNUM_AUDIO, CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_FS, EPNUM_AUDIO_FB | 0x80, 44100, 48000),
#if CFG_AUDIO_DEBUG
- // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
- TUD_HID_DESCRIPTOR(ITF_NUM_DEBUG, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_DEBUG | 0x80, CFG_TUD_HID_EP_BUFSIZE, 7)
+ // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
+ TUD_HID_DESCRIPTOR(ITF_NUM_DEBUG, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_DEBUG | 0x80, CFG_TUD_HID_EP_BUFSIZE, 7)
#endif
};
-#if CFG_QUIRK_OS_GUESSING
-// OS X needs 3 bytes feedback endpoint on FS
-uint8_t const desc_configuration_osx_fs[] =
-{
- // Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
+TU_VERIFY_STATIC(sizeof(desc_uac1_configuration) == CONFIG_UAC1_TOTAL_LEN, "Incorrect size");
- // Interface number, string index, byte per sample, bit per sample, EP Out, EP size, EP feedback, feedback EP size,
- TUD_AUDIO_SPEAKER_STEREO_FB_DESCRIPTOR(0, 4, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_RESOLUTION_RX, EPNUM_AUDIO_OUT, CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX, EPNUM_AUDIO_FB | 0x80, 3),
+#if TUD_OPT_HIGH_SPEED
#if CFG_AUDIO_DEBUG
- // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
- TUD_HID_DESCRIPTOR(ITF_NUM_DEBUG, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_DEBUG | 0x80, CFG_TUD_HID_EP_BUFSIZE, 7)
-#endif
-};
+ #define CONFIG_UAC2_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO20_SPEAKER_STEREO_FB_DESC_LEN + TUD_HID_DESC_LEN)
+#else
+ #define CONFIG_UAC2_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_AUDIO20_SPEAKER_STEREO_FB_DESC_LEN)
#endif
-// Invoked when received GET CONFIGURATION DESCRIPTOR
-// Application return pointer to descriptor
-// Descriptor contents must exist long enough for transfer to complete
-uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
-{
- (void)index; // for multiple configurations
+uint8_t const desc_uac2_configuration[] = {
+ // Config number, interface count, string index, total length, attribute, power in mA
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_UAC2_TOTAL_LEN, 0x00, 100),
-#if CFG_QUIRK_OS_GUESSING
- quirk_os_guessing_desc_configuration_cb();
- if(tud_speed_get() == TUSB_SPEED_FULL && quirk_os_guessing_get() == QUIRK_OS_GUESSING_OSX) {
- return desc_configuration_osx_fs;
- }
-#endif
- return desc_configuration_default;
-}
+ // Interface number, string index, byte per sample, bit per sample, EP Out, EP size, EP feedback, feedback EP size,
+ TUD_AUDIO20_SPEAKER_STEREO_FB_DESCRIPTOR(ITF_NUM_AUDIO_CONTROL, 4, CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX, CFG_TUD_AUDIO_FUNC_1_RESOLUTION_RX, EPNUM_AUDIO, CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_HS, EPNUM_AUDIO_FB | 0x80, 4),
-//--------------------------------------------------------------------+
-// BOS Descriptor, required for OS guessing quirk
-//--------------------------------------------------------------------+
+#if CFG_AUDIO_DEBUG
+ // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
+ TUD_HID_DESCRIPTOR(ITF_NUM_DEBUG, 0, HID_ITF_PROTOCOL_NONE, sizeof(desc_hid_report), EPNUM_DEBUG | 0x80, CFG_TUD_HID_EP_BUFSIZE, 7)
+#endif
+};
-#define TUD_BOS_USB20_EXT_DESC_LEN 7
+TU_VERIFY_STATIC(sizeof(desc_uac2_configuration) == CONFIG_UAC2_TOTAL_LEN, "Incorrect size");
-#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_USB20_EXT_DESC_LEN)
+// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
+tusb_desc_device_qualifier_t const desc_device_qualifier = {
+ .bLength = sizeof(tusb_desc_device_t),
+ .bDescriptorType = TUSB_DESC_DEVICE,
+ .bcdUSB = 0x0200,
-// BOS Descriptor is required for webUSB
-uint8_t const desc_bos[] =
-{
- // total length, number of device caps
- TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 1),
+ .bDeviceClass = TUSB_CLASS_MISC,
+ .bDeviceSubClass = MISC_SUBCLASS_COMMON,
+ .bDeviceProtocol = MISC_PROTOCOL_IAD,
- // USB 2.0 Extension Descriptor
- 0x07, TUSB_DESC_DEVICE_CAPABILITY, DEVICE_CAPABILITY_USB20_EXTENSION, 0x00, 0x00, 0x00,0x00
+ .bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
+ .bNumConfigurations = 0x01,
+ .bReserved = 0x00
};
-uint8_t const * tud_descriptor_bos_cb(void)
-{
-#if CFG_QUIRK_OS_GUESSING
- quirk_os_guessing_desc_bos_cb();
+// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
+// device_qualifier descriptor describes information about a high-speed capable device that would
+// change if the device were operating at the other speed. If not highspeed capable stall this request.
+uint8_t const *tud_descriptor_device_qualifier_cb(void) {
+ return (uint8_t const *) &desc_device_qualifier;
+}
+
+// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
+uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index) {
+ (void) index;// for multiple configurations
+
+ // if link speed is high return fullspeed config, and vice versa
+ return (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_uac1_configuration : desc_uac2_configuration;
+}
+
+#endif // highspeed
+
+// Invoked when received GET CONFIGURATION DESCRIPTOR
+// Application return pointer to descriptor
+// Descriptor contents must exist long enough for transfer to complete
+uint8_t const * tud_descriptor_configuration_cb(uint8_t index) {
+ (void) index; // for multiple configurations
+#if TUD_OPT_HIGH_SPEED
+ // Although we are highspeed, host may be fullspeed.
+ if(tud_speed_get() == TUSB_SPEED_FULL) {
+ return desc_uac1_configuration;
+ } else {
+ return desc_uac2_configuration;
+ }
+#else
+ return desc_uac1_configuration;
#endif
- return desc_bos;
}
//--------------------------------------------------------------------+
@@ -230,13 +237,14 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
"TinyUSB Speaker", // 2: Product
NULL, // 3: Serials will use unique ID if possible
"UAC2 Speaker", // 4: Audio Interface
+ "UAC1 Speaker", // 5: UAC1 Audio Interface
};
static uint16_t _desc_str[32 + 1];
@@ -247,10 +255,6 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
(void) langid;
size_t chr_count;
-#if CFG_QUIRK_OS_GUESSING
- quirk_os_guessing_desc_string_cb();
-#endif
-
switch ( index ) {
case STRID_LANGID:
memcpy(&_desc_str[1], string_desc_arr[0], 2);
diff --git a/examples/device/uac2_speaker_fb/src/usb_descriptors.h b/examples/device/uac2_speaker_fb/src/usb_descriptors.h
index 9511bf797..79f25bbfa 100644
--- a/examples/device/uac2_speaker_fb/src/usb_descriptors.h
+++ b/examples/device/uac2_speaker_fb/src/usb_descriptors.h
@@ -23,60 +23,148 @@
*
*/
-#ifndef _USB_DESCRIPTORS_H_
-#define _USB_DESCRIPTORS_H_
+#ifndef USB_DESCRIPTORS_H_
+#define USB_DESCRIPTORS_H_
-// Defined in TUD_AUDIO_SPEAKER_STEREO_FB_DESCRIPTOR
+//--------------------------------------------------------------------+
+// UAC2 DESCRIPTOR TEMPLATES
+//--------------------------------------------------------------------+
+
+// Defined in TUD_AUDIO20_SPEAKER_STEREO_FB_DESCRIPTOR
#define UAC2_ENTITY_CLOCK 0x04
#define UAC2_ENTITY_INPUT_TERMINAL 0x01
#define UAC2_ENTITY_FEATURE_UNIT 0x02
#define UAC2_ENTITY_OUTPUT_TERMINAL 0x03
-#define TUD_AUDIO_SPEAKER_STEREO_FB_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
- + TUD_AUDIO_DESC_STD_AC_LEN\
- + TUD_AUDIO_DESC_CS_AC_LEN\
- + TUD_AUDIO_DESC_CLK_SRC_LEN\
- + TUD_AUDIO_DESC_INPUT_TERM_LEN\
- + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
- + TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_STD_AS_INT_LEN\
- + TUD_AUDIO_DESC_CS_AS_INT_LEN\
- + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
- + TUD_AUDIO_DESC_STD_AS_ISO_FB_EP_LEN)
+#define TUD_AUDIO20_SPEAKER_STEREO_FB_DESC_LEN (TUD_AUDIO20_DESC_IAD_LEN\
+ + TUD_AUDIO20_DESC_STD_AC_LEN\
+ + TUD_AUDIO20_DESC_CS_AC_LEN\
+ + TUD_AUDIO20_DESC_CLK_SRC_LEN\
+ + TUD_AUDIO20_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_OUTPUT_TERM_LEN\
+ + TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(2)\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO20_DESC_TYPE_I_FORMAT_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO20_DESC_STD_AS_ISO_FB_EP_LEN)
-#define TUD_AUDIO_SPEAKER_STEREO_FB_DESCRIPTOR(_itfnum, _stridx, _nBytesPerSample, _nBitsUsedPerSample, _epout, _epoutsize, _epfb, _epfbsize) \
+#define TUD_AUDIO20_SPEAKER_STEREO_FB_DESCRIPTOR(_itfnum, _stridx, _nBytesPerSample, _nBitsUsedPerSample, _epout, _epoutsize, _epfb, _epfbsize) \
/* Standard Interface Association Descriptor (IAD) */\
- TUD_AUDIO_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
/* Standard AC Interface Descriptor(4.7.1) */\
- TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
+ TUD_AUDIO20_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
/* Class-Specific AC Interface Header Descriptor(4.7.2) */\
- TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_DESKTOP_SPEAKER, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
+ TUD_AUDIO20_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO20_FUNC_DESKTOP_SPEAKER, /*_totallen*/ TUD_AUDIO20_DESC_CLK_SRC_LEN+TUD_AUDIO20_DESC_INPUT_TERM_LEN+TUD_AUDIO20_DESC_OUTPUT_TERM_LEN+TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(2), /*_ctrl*/ AUDIO20_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
/* Clock Source Descriptor(4.7.2.1) */\
- TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ 0x04, /*_attr*/ AUDIO_CLOCK_SOURCE_ATT_INT_PRO_CLK, /*_ctrl*/ (AUDIO_CTRL_RW << AUDIO_CLOCK_SOURCE_CTRL_CLK_FRQ_POS), /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CLK_SRC(/*_clkid*/ 0x04, /*_attr*/ AUDIO20_CLOCK_SOURCE_ATT_INT_PRO_CLK, /*_ctrl*/ (AUDIO20_CTRL_RW << AUDIO20_CLOCK_SOURCE_CTRL_CLK_FRQ_POS), /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
/* Input Terminal Descriptor(4.7.2.4) */\
- TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ 0x01, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_clkid*/ 0x04, /*_nchannelslogical*/ 0x02, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_INPUT_TERM(/*_termid*/ 0x01, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_clkid*/ 0x04, /*_nchannelslogical*/ 0x02, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO20_CTRL_R << AUDIO20_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
/* Output Terminal Descriptor(4.7.2.5) */\
- TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ 0x03, /*_termtype*/ AUDIO_TERM_TYPE_OUT_DESKTOP_SPEAKER, /*_assocTerm*/ 0x01, /*_srcid*/ 0x02, /*_clkid*/ 0x04, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_OUTPUT_TERM(/*_termid*/ 0x03, /*_termtype*/ AUDIO_TERM_TYPE_OUT_DESKTOP_SPEAKER, /*_assocTerm*/ 0x01, /*_srcid*/ 0x02, /*_clkid*/ 0x04, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
/* Feature Unit Descriptor(4.7.2.8) */\
- TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL(/*_unitid*/ 0x02, /*_srcid*/ 0x01, /*_ctrlch0master*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch1*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch2*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS,/*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_FEATURE_UNIT(/*_unitid*/ 0x02, /*_srcid*/ 0x01, /*_stridx*/ 0x00, /*_ctrlch0master*/ AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch1*/ AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch2*/ AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO20_CTRL_RW << AUDIO20_FEATURE_UNIT_CTRL_VOLUME_POS),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum) + 1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum) + 1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
/* Standard AS Interface Descriptor(4.9.1) */\
/* Interface 1, Alternate 1 - alternate interface for data streaming */\
- TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum) + 1), /*_altset*/ 0x01, /*_nEPs*/ 0x02, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum) + 1), /*_altset*/ 0x01, /*_nEPs*/ 0x02, /*_stridx*/ 0x00),\
/* Class-Specific AS Interface Descriptor(4.9.2) */\
- TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ 0x01, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x02, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
+ TUD_AUDIO20_DESC_CS_AS_INT(/*_termid*/ 0x01, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_formattype*/ AUDIO20_FORMAT_TYPE_I, /*_formats*/ AUDIO20_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x02, /*_channelcfg*/ AUDIO20_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
- TUD_AUDIO_DESC_TYPE_I_FORMAT(_nBytesPerSample, _nBitsUsedPerSample),\
+ TUD_AUDIO20_DESC_TYPE_I_FORMAT(_nBytesPerSample, _nBitsUsedPerSample),\
/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ _epoutsize, /*_interval*/ 0x01),\
+ TUD_AUDIO20_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ _epoutsize, /*_interval*/ 0x01),\
/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
- TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
+ TUD_AUDIO20_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO20_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO20_CTRL_NONE, /*_lockdelayunit*/ AUDIO20_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_MILLISEC, /*_lockdelay*/ 0x0001),\
/* Standard AS Isochronous Feedback Endpoint Descriptor(4.10.2.1) */\
- TUD_AUDIO_DESC_STD_AS_ISO_FB_EP(/*_ep*/ _epfb, /*_epsize*/ _epfbsize, /*_interval*/ TUD_OPT_HIGH_SPEED ? 4 : 1)\
+ TUD_AUDIO20_DESC_STD_AS_ISO_FB_EP(/*_ep*/ _epfb, /*_epsize*/ _epfbsize, /*_interval*/ TUD_OPT_HIGH_SPEED ? 4 : 1)
+
+//--------------------------------------------------------------------+
+// UAC1 DESCRIPTOR TEMPLATES
+//--------------------------------------------------------------------+
+
+// Defined in TUD_AUDIO10_SPEAKER_STEREO_FB_DESCRIPTOR
+#define UAC1_ENTITY_INPUT_TERMINAL 0x01
+#define UAC1_ENTITY_FEATURE_UNIT 0x02
+#define UAC1_ENTITY_OUTPUT_TERMINAL 0x03
+
+#define TUD_AUDIO10_SPEAKER_STEREO_FB_DESC_LEN(_nfreqs) (\
+ + TUD_AUDIO10_DESC_STD_AC_LEN\
+ + TUD_AUDIO10_DESC_CS_AC_LEN(1)\
+ + TUD_AUDIO10_DESC_INPUT_TERM_LEN\
+ + TUD_AUDIO10_DESC_OUTPUT_TERM_LEN\
+ + TUD_AUDIO10_DESC_FEATURE_UNIT_LEN(2)\
+ + TUD_AUDIO10_DESC_STD_AS_LEN\
+ + TUD_AUDIO10_DESC_STD_AS_LEN\
+ + TUD_AUDIO10_DESC_CS_AS_INT_LEN\
+ + TUD_AUDIO10_DESC_TYPE_I_FORMAT_LEN(_nfreqs)\
+ + TUD_AUDIO10_DESC_STD_AS_ISO_EP_LEN\
+ + TUD_AUDIO10_DESC_CS_AS_ISO_EP_LEN\
+ + TUD_AUDIO10_DESC_STD_AS_ISO_SYNC_EP_LEN)
+
+#define TUD_AUDIO10_SPEAKER_STEREO_FB_DESCRIPTOR(_itfnum, _stridx, _nBytesPerSample, _nBitsUsedPerSample, _epout, _epoutsize, _epfb, ...) \
+ /* Standard AC Interface Descriptor(4.3.1) */\
+ TUD_AUDIO10_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
+ /* Class-Specific AC Interface Header Descriptor(4.3.2) */\
+ TUD_AUDIO10_DESC_CS_AC(/*_bcdADC*/ 0x0100, /*_totallen*/ (TUD_AUDIO10_DESC_INPUT_TERM_LEN+TUD_AUDIO10_DESC_OUTPUT_TERM_LEN+TUD_AUDIO10_DESC_FEATURE_UNIT_LEN(2)), /*_itf*/ ((_itfnum)+1)),\
+ /* Input Terminal Descriptor(4.3.2.1) */\
+ TUD_AUDIO10_DESC_INPUT_TERM(/*_termid*/ 0x01, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_nchannels*/ 0x02, /*_channelcfg*/ AUDIO10_CHANNEL_CONFIG_LEFT_FRONT | AUDIO10_CHANNEL_CONFIG_RIGHT_FRONT, /*_idxchannelnames*/ 0x00, /*_stridx*/ 0x00),\
+ /* Output Terminal Descriptor(4.3.2.2) */\
+ TUD_AUDIO10_DESC_OUTPUT_TERM(/*_termid*/ 0x03, /*_termtype*/ AUDIO_TERM_TYPE_OUT_DESKTOP_SPEAKER, /*_assocTerm*/ 0x00, /*_srcid*/ 0x02, /*_stridx*/ 0x00),\
+ /* Feature Unit Descriptor(4.3.2.5) */\
+ TUD_AUDIO10_DESC_FEATURE_UNIT(/*_unitid*/ 0x02, /*_srcid*/ 0x01, /*_stridx*/ 0x00, /*_ctrlmaster*/ (AUDIO10_FU_CONTROL_BM_MUTE | AUDIO10_FU_CONTROL_BM_VOLUME), /*_ctrlch1*/ (AUDIO10_FU_CONTROL_BM_MUTE | AUDIO10_FU_CONTROL_BM_VOLUME), /*_ctrlch2*/ (AUDIO10_FU_CONTROL_BM_MUTE | AUDIO10_FU_CONTROL_BM_VOLUME)),\
+ /* Standard AS Interface Descriptor(4.5.1) */\
+ /* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
+ TUD_AUDIO10_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
+ /* Standard AS Interface Descriptor(4.5.1) */\
+ /* Interface 1, Alternate 1 - alternate interface for data streaming */\
+ TUD_AUDIO10_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x01, /*_nEPs*/ 0x02, /*_stridx*/ 0x00),\
+ /* Class-Specific AS Interface Descriptor(4.5.2) */\
+ TUD_AUDIO10_DESC_CS_AS_INT(/*_termid*/ 0x01, /*_delay*/ 0x00, /*_formattype*/ AUDIO10_DATA_FORMAT_TYPE_I_PCM),\
+ /* Type I Format Type Descriptor(2.2.5) */\
+ TUD_AUDIO10_DESC_TYPE_I_FORMAT(/*_nrchannels*/ 0x02, /*_subframesize*/ _nBytesPerSample, /*_bitresolution*/ _nBitsUsedPerSample, /*_freqs*/ __VA_ARGS__),\
+ /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.6.1.1) */\
+ TUD_AUDIO10_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) ((uint8_t)TUSB_XFER_ISOCHRONOUS | (uint8_t)TUSB_ISO_EP_ATT_ASYNCHRONOUS), /*_maxEPsize*/ _epoutsize, /*_interval*/ 0x01, /*_sync_ep*/ _epfb),\
+ /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.6.1.2) */\
+ TUD_AUDIO10_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO10_CS_AS_ISO_DATA_EP_ATT_SAMPLING_FRQ, /*_lockdelayunits*/ AUDIO10_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
+ /* Standard AS Isochronous Synch Endpoint Descriptor (4.6.2.1) */\
+ TUD_AUDIO10_DESC_STD_AS_ISO_SYNC_EP(/*_ep*/ _epfb, /*_bRefresh*/ 0)
+
+//---------------------------------------------------------------------------+
+// UAC1 Isochronous Synch Endpoint bRefresh Workaround
+//
+// bRefresh value is set to 0, while UAC1 spec requires it to be between
+// 1 (2 ms) and 9 (512 ms)
+//
+// This value has been tested to work with Windows, macOS and Linux.
+//
+// Rationale:
+// Some USB device controllers (e.g. Synopsys DWC2) require a known transfer
+// interval to manually schedule isochronous IN transfers. For data isochronous
+// endpoints, the bInterval field in the endpoint descriptor is used. However,
+// for synch endpoint it's unclear which field the host uses to determine the
+// transfer interval. Windows and macOS use bRefresh, while Linux uses bInterval.
+//
+// Since bInterval is fixed to 1, if bRefresh is set to 2 then Windows and macOS
+// will schedule the feedback transfer every 4 ms, but Linux will schedule it
+// every 1 ms. DWC2 controller cannot handle this discrepancy without knwowing
+// the actual interval, therefore we set bRefresh to 0 to let the transfer
+// execute every 1 ms, which is the same as bInterval.
+//
+// Rant:
+// WTF USB-IF? Why have two fields that mean the same thing? Why not just use
+// bInterval for both data and synch endpoints? Why is bRefresh even necessary?
+//
+// Note:
+// For the moment DWC2 driver doesn't have proper support for bInterval > 1
+// for isochronous IN endpoints. The implementation would be complex and CPU
+// intensive (cfr.
+// https://github.com/torvalds/linux/blob/master/drivers/usb/dwc2/gadget.c)
+// It MAY work in some cases if you are lucky, but it's not guaranteed.
+//---------------------------------------------------------------------------+
#endif
diff --git a/examples/device/usbtmc/Makefile b/examples/device/usbtmc/Makefile
index 1b4d398cf..1a4b428dc 100644
--- a/examples/device/usbtmc/Makefile
+++ b/examples/device/usbtmc/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/usbtmc/src/main.c b/examples/device/usbtmc/src/main.c
index f78cce91f..5cbbb85ef 100644
--- a/examples/device/usbtmc/src/main.c
+++ b/examples/device/usbtmc/src/main.c
@@ -29,6 +29,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "main.h"
#include "usbtmc_app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
diff --git a/examples/device/usbtmc/src/usb_descriptors.c b/examples/device/usbtmc/src/usb_descriptors.c
index 85acd990a..16bd176f8 100644
--- a/examples/device/usbtmc/src/usb_descriptors.c
+++ b/examples/device/usbtmc/src/usb_descriptors.c
@@ -34,9 +34,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xcafe
#define USB_BCD 0x0200
@@ -44,7 +44,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -112,7 +112,7 @@ enum
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_USBTMC_DESC_LEN)
-uint8_t const desc_fs_configuration[] =
+static uint8_t const desc_fs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -122,7 +122,7 @@ uint8_t const desc_fs_configuration[] =
#if TUD_OPT_HIGH_SPEED
-uint8_t const desc_hs_configuration[] =
+static uint8_t const desc_hs_configuration[] =
{
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -131,10 +131,10 @@ uint8_t const desc_hs_configuration[] =
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier =
+static tusb_desc_device_qualifier_t const desc_device_qualifier =
{
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
@@ -158,6 +158,23 @@ uint8_t const* tud_descriptor_device_qualifier_cb(void)
return (uint8_t const*) &desc_device_qualifier;
}
+// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
+// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
+uint8_t const *tud_descriptor_other_speed_configuration_cb(uint8_t index) {
+ (void) index; // for multiple configurations
+
+ // if link speed is high return fullspeed config, and vice versa
+ // Note: the descriptor type is OTHER_SPEED_CONFIG instead of CONFIG
+ memcpy(desc_other_speed_config,
+ (tud_speed_get() == TUSB_SPEED_HIGH) ? desc_fs_configuration : desc_hs_configuration,
+ CONFIG_TOTAL_LEN);
+
+ desc_other_speed_config[1] = TUSB_DESC_OTHER_SPEED_CONFIG;
+
+ return desc_other_speed_config;
+}
+
#endif
// Invoked when received GET CONFIGURATION DESCRIPTOR
@@ -187,7 +204,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
diff --git a/examples/device/usbtmc/src/usbtmc_app.c b/examples/device/usbtmc/src/usbtmc_app.c
index e738f1008..4c3724ac4 100644
--- a/examples/device/usbtmc/src/usbtmc_app.c
+++ b/examples/device/usbtmc/src/usbtmc_app.c
@@ -28,6 +28,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
#include "main.h"
+#include "usbtmc_app.h"
#if (CFG_TUD_USBTMC_ENABLE_488)
static usbtmc_response_capabilities_488_t const
diff --git a/examples/device/video_capture/Makefile b/examples/device/video_capture/Makefile
index d698a848d..6c248ab7b 100644
--- a/examples/device/video_capture/Makefile
+++ b/examples/device/video_capture/Makefile
@@ -1,4 +1,4 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
ifeq ($(DISABLE_MJPEG),1)
CFLAGS += -DCFG_EXAMPLE_VIDEO_DISABLE_MJPEG
@@ -9,10 +9,10 @@ endif
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/video_capture/skip.txt b/examples/device/video_capture/skip.txt
index 50302c544..cb0c7d2e6 100644
--- a/examples/device/video_capture/skip.txt
+++ b/examples/device/video_capture/skip.txt
@@ -1,6 +1,5 @@
mcu:CH32V103
mcu:CH32V20X
-mcu:MCXA15
mcu:MSP430x5xx
mcu:NUC121
mcu:SAMD11
diff --git a/examples/device/video_capture/src/main.c b/examples/device/video_capture/src/main.c
index 29656e944..ffa2a7afa 100644
--- a/examples/device/video_capture/src/main.c
+++ b/examples/device/video_capture/src/main.c
@@ -53,9 +53,23 @@ void usb_device_task(void *param);
void video_task(void* param);
#if CFG_TUSB_OS == OPT_OS_FREERTOS
-void freertos_init_task(void);
+void freertos_init(void);
#endif
+#if !defined(CFG_EXAMPLE_VIDEO_READONLY) || defined(CFG_EXAMPLE_VIDEO_BUFFERLESS)
+/* EBU color bars: https://stackoverflow.com/questions/6939422 */
+static uint8_t const bar_color[8][4] = {
+ /* Y, U, Y, V */
+ { 235, 128, 235, 128}, /* 100% White */
+ { 219, 16, 219, 138}, /* Yellow */
+ { 188, 154, 188, 16}, /* Cyan */
+ { 173, 42, 173, 26}, /* Green */
+ { 78, 214, 78, 230}, /* Magenta */
+ { 63, 102, 63, 240}, /* Red */
+ { 32, 240, 32, 118}, /* Blue */
+ { 16, 128, 16, 128}, /* Black */
+};
+#endif
//--------------------------------------------------------------------+
// Main
@@ -65,7 +79,7 @@ int main(void) {
// If using FreeRTOS: create blinky, tinyusb device, video task
#if CFG_TUSB_OS == OPT_OS_FREERTOS
- freertos_init_task();
+ freertos_init();
#else
// init device stack on configured roothub port
tusb_rhport_init_t dev_init = {
@@ -111,12 +125,43 @@ void tud_resume_cb(void) {
blink_interval_ms = tud_mounted() ? BLINK_MOUNTED : BLINK_NOT_MOUNTED;
}
+#ifdef CFG_EXAMPLE_VIDEO_BUFFERLESS
+
+#ifndef CFG_EXAMPLE_VIDEO_DISABLE_MJPEG
+ #error Demo only supports YUV2 please define CFG_EXAMPLE_VIDEO_DISABLE_MJPEG
+#endif
+
+void tud_video_prepare_payload_cb(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, tud_video_payload_request_t* request)
+{
+ static uint32_t frame_counter = 0;
+ (void)ctl_idx;
+ (void)stm_idx;
+
+ /* Offset will be zero at the start of a new frame */
+ if (!request->offset) frame_counter++;
+
+ for (size_t buf_pos = 0; buf_pos < request->length; buf_pos += 2) {
+
+ /* Position within the current line (pixel relative) */
+ int line_pos = ((request->offset + buf_pos)>>1) % FRAME_WIDTH;
+
+ /* Choose color based on the position and change the table offset every 4 frames */
+ const uint8_t* color = bar_color[(line_pos/(FRAME_WIDTH / 8) + (frame_counter>>2)) % 8];
+
+ /* Copy pixel data for odd or even pixels */
+ memcpy(&((uint8_t*)request->buf)[buf_pos], &color[(line_pos & 1) ? 2 : 0], 2);
+ }
+
+}
+#endif
+
//--------------------------------------------------------------------+
// USB Video
//--------------------------------------------------------------------+
static unsigned frame_num = 0;
static unsigned tx_busy = 0;
static unsigned interval_ms = 1000 / FRAME_RATE;
+#ifndef CFG_EXAMPLE_VIDEO_BUFFERLESS
#ifdef CFG_EXAMPLE_VIDEO_READONLY
// For mcus that does not have enough SRAM for frame buffer, we use fixed frame data.
@@ -145,18 +190,6 @@ static struct {
static uint8_t frame_buffer[FRAME_WIDTH * FRAME_HEIGHT * 16 / 8];
static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
- /* EBU color bars: https://stackoverflow.com/questions/6939422 */
- static uint8_t const bar_color[8][4] = {
- /* Y, U, Y, V */
- { 235, 128, 235, 128}, /* 100% White */
- { 219, 16, 219, 138}, /* Yellow */
- { 188, 154, 188, 16}, /* Cyan */
- { 173, 42, 173, 26}, /* Green */
- { 78, 214, 78, 230}, /* Magenta */
- { 63, 102, 63, 240}, /* Red */
- { 32, 240, 32, 118}, /* Blue */
- { 16, 128, 16, 128}, /* Black */
- };
uint8_t* p;
/* Generate the 1st line */
@@ -183,6 +216,8 @@ static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
#endif
+#endif /* NDEF CFG_EXAMPLE_VIDEO_BUFFERLESS */
+
static void video_send_frame(void) {
static unsigned start_ms = 0;
static unsigned already_sent = 0;
@@ -197,7 +232,9 @@ static void video_send_frame(void) {
already_sent = 1;
tx_busy = 1;
start_ms = board_millis();
-#ifdef CFG_EXAMPLE_VIDEO_READONLY
+#if defined(CFG_EXAMPLE_VIDEO_BUFFERLESS)
+ tud_video_n_frame_xfer(0, 0, NULL, FRAME_WIDTH * FRAME_HEIGHT * 16 / 8);
+#elif defined (CFG_EXAMPLE_VIDEO_READONLY)
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
@@ -211,12 +248,18 @@ static void video_send_frame(void) {
}
unsigned cur = board_millis();
- if (cur - start_ms < interval_ms) return; // not enough time
- if (tx_busy) return;
+ if (cur - start_ms < interval_ms) {
+ return; // not enough time
+ }
+ if (tx_busy) {
+ return;
+ }
start_ms += interval_ms;
tx_busy = 1;
-#ifdef CFG_EXAMPLE_VIDEO_READONLY
+#if defined(CFG_EXAMPLE_VIDEO_BUFFERLESS)
+ tud_video_n_frame_xfer(0, 0, NULL, FRAME_WIDTH * FRAME_HEIGHT * 16 / 8);
+#elif defined(CFG_EXAMPLE_VIDEO_READONLY)
#if defined(CFG_EXAMPLE_VIDEO_DISABLE_MJPEG)
tud_video_n_frame_xfer(0, 0, (void*)(uintptr_t)&frame_buffer[(frame_num % (FRAME_WIDTH / 2)) * 4],
FRAME_WIDTH * FRAME_HEIGHT * 16/8);
@@ -273,7 +316,9 @@ void led_blinking_task(void* param) {
#if CFG_TUSB_OS == OPT_OS_FREERTOS
vTaskDelay(blink_interval_ms / portTICK_PERIOD_MS);
#else
- if (board_millis() - start_ms < blink_interval_ms) return; // not enough time
+ if (board_millis() - start_ms < blink_interval_ms) {
+ return; // not enough time
+ }
#endif
start_ms += blink_interval_ms;
@@ -336,7 +381,7 @@ void usb_device_task(void *param) {
}
}
-void freertos_init_task(void) {
+void freertos_init(void) {
#if configSUPPORT_STATIC_ALLOCATION
xTaskCreateStatic(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, blinky_stack, &blinky_taskdef);
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
diff --git a/examples/device/video_capture/src/tusb_config.h b/examples/device/video_capture/src/tusb_config.h
index 4ba86ca65..1aa1a5ce7 100644
--- a/examples/device/video_capture/src/tusb_config.h
+++ b/examples/device/video_capture/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -110,9 +110,10 @@
//#define CFG_EXAMPLE_VIDEO_READONLY
//#define CFG_EXAMPLE_VIDEO_DISABLE_MJPEG
+//#define CFG_EXAMPLE_VIDEO_BUFFERLESS
#ifdef __cplusplus
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/video_capture/src/usb_descriptors.c b/examples/device/video_capture/src/usb_descriptors.c
index b3e19b0f0..114dd5722 100644
--- a/examples/device/video_capture/src/usb_descriptors.c
+++ b/examples/device/video_capture/src/usb_descriptors.c
@@ -33,9 +33,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] VIDEO | AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VIDEO, 5) | _PID_MAP(VENDOR, 6) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VIDEO, 5) | PID_MAP(VENDOR, 6) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -63,7 +63,7 @@ char const* string_desc_arr[] = {
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -384,7 +384,7 @@ static uint8_t * get_hs_configuration_desc(void) {
}
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
diff --git a/examples/device/video_capture_2ch/Makefile b/examples/device/video_capture_2ch/Makefile
index d698a848d..6c248ab7b 100644
--- a/examples/device/video_capture_2ch/Makefile
+++ b/examples/device/video_capture_2ch/Makefile
@@ -1,4 +1,4 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
ifeq ($(DISABLE_MJPEG),1)
CFLAGS += -DCFG_EXAMPLE_VIDEO_DISABLE_MJPEG
@@ -9,10 +9,10 @@ endif
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/video_capture_2ch/skip.txt b/examples/device/video_capture_2ch/skip.txt
index 0f6508226..af3b0de04 100644
--- a/examples/device/video_capture_2ch/skip.txt
+++ b/examples/device/video_capture_2ch/skip.txt
@@ -6,7 +6,6 @@ mcu:CH32V103
mcu:CH32V20X
mcu:CH32V307
mcu:STM32L0
-mcu:MCXA15
family:espressif
board:curiosity_nano
board:kuiic
diff --git a/examples/device/video_capture_2ch/src/main.c b/examples/device/video_capture_2ch/src/main.c
index f56738f67..79b149f2b 100644
--- a/examples/device/video_capture_2ch/src/main.c
+++ b/examples/device/video_capture_2ch/src/main.c
@@ -53,7 +53,7 @@ void usb_device_task(void *param);
void video_task(void* param);
#if CFG_TUSB_OS == OPT_OS_FREERTOS
-void freertos_init_task(void);
+void freertos_init(void);
#endif
@@ -65,7 +65,7 @@ int main(void) {
// If using FreeRTOS: create blinky, tinyusb device, video task
#if CFG_TUSB_OS == OPT_OS_FREERTOS
- freertos_init_task();
+ freertos_init();
#else
// init device stack on configured roothub port
tusb_rhport_init_t dev_init = {
@@ -180,7 +180,7 @@ static void fill_color_bar(uint8_t* buffer, unsigned start_position) {
}
#endif
-size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) {
+static size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, void **fb) {
uint32_t idx = ctl_idx + stm_idx;
if (idx == 0) {
@@ -205,8 +205,7 @@ size_t get_framebuf(uint_fast8_t ctl_idx, uint_fast8_t stm_idx, size_t fnum, voi
//--------------------------------------------------------------------+
//
//--------------------------------------------------------------------+
-
-void video_send_frame(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
+static void video_send_frame(uint_fast8_t ctl_idx, uint_fast8_t stm_idx) {
static unsigned start_ms[CFG_TUD_VIDEO_STREAMING] = {0, };
static unsigned already_sent = 0;
@@ -344,7 +343,7 @@ void usb_device_task(void *param) {
}
}
-void freertos_init_task(void) {
+void freertos_init(void) {
#if configSUPPORT_STATIC_ALLOCATION
xTaskCreateStatic(led_blinking_task, "blinky", BLINKY_STACK_SIZE, NULL, 1, blinky_stack, &blinky_taskdef);
xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
diff --git a/examples/device/video_capture_2ch/src/tusb_config.h b/examples/device/video_capture_2ch/src/tusb_config.h
index e84e49879..48ab4d20a 100644
--- a/examples/device/video_capture_2ch/src/tusb_config.h
+++ b/examples/device/video_capture_2ch/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -117,4 +117,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/video_capture_2ch/src/usb_descriptors.c b/examples/device/video_capture_2ch/src/usb_descriptors.c
index e78e452fc..024d16e07 100644
--- a/examples/device/video_capture_2ch/src/usb_descriptors.c
+++ b/examples/device/video_capture_2ch/src/usb_descriptors.c
@@ -33,9 +33,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] VIDEO | AUDIO | MIDI | HID | MSC | CDC [LSB]
*/
-#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(AUDIO, 4) | _PID_MAP(VIDEO, 5) | _PID_MAP(VENDOR, 6) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(AUDIO, 4) | PID_MAP(VIDEO, 5) | PID_MAP(VENDOR, 6) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -68,7 +68,7 @@ char const* string_desc_arr[] = {
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -551,7 +551,7 @@ static uint8_t * get_hs_configuration_desc(void) {
}
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
diff --git a/examples/device/webusb_serial/Makefile b/examples/device/webusb_serial/Makefile
index 7fa475da5..035e90308 100644
--- a/examples/device/webusb_serial/Makefile
+++ b/examples/device/webusb_serial/Makefile
@@ -1,11 +1,11 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/device/webusb_serial/src/main.c b/examples/device/webusb_serial/src/main.c
index 4a724f45e..0c2acd94e 100644
--- a/examples/device/webusb_serial/src/main.c
+++ b/examples/device/webusb_serial/src/main.c
@@ -107,7 +107,7 @@ int main(void) {
}
// send characters to both CDC and WebUSB
-void echo_all(const uint8_t buf[], uint32_t count) {
+static void echo_all(const uint8_t buf[], uint32_t count) {
// echo to web serial
if (web_serial_connected) {
tud_vendor_write(buf, count);
diff --git a/examples/device/webusb_serial/src/tusb_config.h b/examples/device/webusb_serial/src/tusb_config.h
index b86ad3752..b6cdf7e56 100644
--- a/examples/device/webusb_serial/src/tusb_config.h
+++ b/examples/device/webusb_serial/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -111,4 +111,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/device/webusb_serial/src/usb_descriptors.c b/examples/device/webusb_serial/src/usb_descriptors.c
index 2b69a5b56..0ef41a68e 100644
--- a/examples/device/webusb_serial/src/usb_descriptors.c
+++ b/examples/device/webusb_serial/src/usb_descriptors.c
@@ -33,14 +33,14 @@
* Auto ProductID layout's Bitmap:
* [MSB] MIDI | HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device =
+static tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
@@ -228,7 +228,7 @@ enum {
};
// array of pointer to string descriptors
-char const *string_desc_arr[] =
+static char const *string_desc_arr[] =
{
(const char[]) { 0x09, 0x04 }, // 0: is supported language is English (0x0409)
"TinyUSB", // 1: Manufacturer
diff --git a/examples/dual/host_hid_to_device_cdc/Makefile b/examples/dual/host_hid_to_device_cdc/Makefile
index 474ae9814..a51251bf9 100644
--- a/examples/dual/host_hid_to_device_cdc/Makefile
+++ b/examples/dual/host_hid_to_device_cdc/Makefile
@@ -1,12 +1,12 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
CFLAGS_GCC += -Wno-error=cast-align -Wno-error=null-dereference
@@ -15,4 +15,4 @@ SRC_C += \
src/host/hub.c \
src/host/usbh.c
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c b/examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c
index b7cffe23d..3efa30e20 100644
--- a/examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c
+++ b/examples/dual/host_hid_to_device_cdc/src/usb_descriptors.c
@@ -32,9 +32,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -42,7 +42,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -122,7 +122,7 @@ enum {
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
// full speed configuration
-uint8_t const desc_fs_configuration[] = {
+static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -134,7 +134,7 @@ uint8_t const desc_fs_configuration[] = {
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -143,10 +143,10 @@ uint8_t const desc_hs_configuration[] = {
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
diff --git a/examples/dual/host_info_to_device_cdc/CMakeLists.txt b/examples/dual/host_info_to_device_cdc/CMakeLists.txt
index 6ae5b5766..ad3c5ddf0 100644
--- a/examples/dual/host_info_to_device_cdc/CMakeLists.txt
+++ b/examples/dual/host_info_to_device_cdc/CMakeLists.txt
@@ -10,6 +10,11 @@ project(${PROJECT} C CXX ASM)
# Checks this example is valid for the family and initializes the project
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR})
+# Espressif has its own cmake build system
+if(FAMILY STREQUAL "espressif")
+ return()
+endif()
+
add_executable(${PROJECT})
# Example source
@@ -25,7 +30,7 @@ target_include_directories(${PROJECT} PUBLIC
# Configure compilation flags and libraries for the example without RTOS.
# See the corresponding function in hw/bsp/FAMILY/family.cmake for details.
-family_configure_dual_usb_example(${PROJECT} noos)
+family_configure_dual_usb_example(${PROJECT} ${RTOS})
# due to warnings from Pico-PIO-USB
if (FAMILY STREQUAL rp2040)
diff --git a/examples/dual/host_info_to_device_cdc/Makefile b/examples/dual/host_info_to_device_cdc/Makefile
index 083c9169a..659cf6ff9 100644
--- a/examples/dual/host_info_to_device_cdc/Makefile
+++ b/examples/dual/host_info_to_device_cdc/Makefile
@@ -1,12 +1,12 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
CFLAGS_GCC += -Wno-error=cast-align -Wno-error=null-dereference
@@ -14,4 +14,4 @@ SRC_C += \
src/host/hub.c \
src/host/usbh.c
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/dual/host_info_to_device_cdc/only.txt b/examples/dual/host_info_to_device_cdc/only.txt
index 35f896f1e..4431065ba 100644
--- a/examples/dual/host_info_to_device_cdc/only.txt
+++ b/examples/dual/host_info_to_device_cdc/only.txt
@@ -8,3 +8,4 @@ mcu:MAX3421
mcu:STM32F4
mcu:STM32F7
mcu:STM32H7
+mcu:ESP32P4
diff --git a/examples/dual/host_info_to_device_cdc/src/CMakeLists.txt b/examples/dual/host_info_to_device_cdc/src/CMakeLists.txt
new file mode 100644
index 000000000..cef2b46ee
--- /dev/null
+++ b/examples/dual/host_info_to_device_cdc/src/CMakeLists.txt
@@ -0,0 +1,4 @@
+# This file is for ESP-IDF only
+idf_component_register(SRCS "main.c" "usb_descriptors.c"
+ INCLUDE_DIRS "."
+ REQUIRES boards tinyusb_src)
diff --git a/examples/dual/host_info_to_device_cdc/src/main.c b/examples/dual/host_info_to_device_cdc/src/main.c
index 67e905b9d..00d059b66 100644
--- a/examples/dual/host_info_to_device_cdc/src/main.c
+++ b/examples/dual/host_info_to_device_cdc/src/main.c
@@ -69,14 +69,18 @@ enum {
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
-static bool is_print[CFG_TUH_DEVICE_MAX+1] = { 0 };
+static bool is_printable[CFG_TUH_DEVICE_MAX + 1] = {0};
static tusb_desc_device_t descriptor_device[CFG_TUH_DEVICE_MAX+1];
static void print_utf16(uint16_t *temp_buf, size_t buf_len);
static void print_device_info(uint8_t daddr, const tusb_desc_device_t* desc_device);
-void led_blinking_task(void);
-void cdc_task(void);
+static void led_blinking_task(void);
+static void cdc_task(void);
+
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
+static void freertos_init(void);
+#endif
#define cdc_printf(...) \
do { \
@@ -94,37 +98,90 @@ void cdc_task(void);
} \
} while(0)
-/*------------- MAIN -------------*/
-int main(void) {
- board_init();
-
- printf("TinyUSB Host Information -> Device CDC Example\r\n");
+static void usb_device_init(void) {
// init device and host stack on configured roothub port
tusb_rhport_init_t dev_init = {
.role = TUSB_ROLE_DEVICE,
.speed = TUSB_SPEED_AUTO
};
tusb_init(BOARD_TUD_RHPORT, &dev_init);
+ tud_cdc_configure_t cdc_cfg = TUD_CDC_CONFIGURE_DEFAULT();
+ cdc_cfg.tx_persistent = true;
+ cdc_cfg.tx_overwritabe_if_not_connected = false;
+ tud_cdc_configure(&cdc_cfg);
+ board_init_after_tusb();
+}
+static void usb_host_init(void) {
+ // init host stack on configured roothub port
tusb_rhport_init_t host_init = {
.role = TUSB_ROLE_HOST,
.speed = TUSB_SPEED_AUTO
};
tusb_init(BOARD_TUH_RHPORT, &host_init);
-
board_init_after_tusb();
+}
+
+//--------------------------------------------------------------------+
+// Main
+//--------------------------------------------------------------------+
+static void main_task(void* param) {
+ (void) param;
while (1) {
- tud_task(); // tinyusb device task
- tuh_task(); // tinyusb host task
cdc_task();
led_blinking_task();
+
+ // preempted RTOS run device/host stack in its own task
+#if CFG_TUSB_OS == OPT_OS_NONE || CFG_TUSB_OS == OPT_OS_PICO
+ tud_task(); // tinyusb device task
+ tuh_task(); // tinyusb host task
+#endif
}
+}
+
+int main(void) {
+ board_init();
+
+#if CFG_TUSB_OS == OPT_OS_NONE || CFG_TUSB_OS == OPT_OS_PICO
+ printf("TinyUSB Host Information -> Device CDC Example\r\n");
+
+ usb_device_init();
+ usb_host_init();
+
+ main_task(NULL);
+#elif CFG_TUSB_OS == OPT_OS_FREERTOS
+ freertos_init(); // create RTOS tasks for device, host stack and main_task()
+#else
+ #error RTOS not supported
+#endif
return 0;
}
+#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO
+// USB Device Driver task for RTOS
+static void usb_device_task(void *param) {
+ (void) param;
+ usb_device_init();
+ while (1) {
+ // put this thread to waiting state until there is new events
+ tud_task();
+ }
+}
+
+static void usb_host_task(void *param) {
+ (void) param;
+ usb_host_init();
+ while (1) {
+ // put this thread to waiting state until there is new events
+ tuh_task();
+ }
+}
+#endif
+
+
//--------------------------------------------------------------------+
// Device CDC
//--------------------------------------------------------------------+
@@ -153,17 +210,23 @@ void tud_resume_cb(void) {
}
void cdc_task(void) {
+ static uint32_t connected_ms = 0;
+
if (!tud_cdc_connected()) {
- // delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding.
- // If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop
- board_delay(20);
+ connected_ms = board_millis();
return;
}
+ // delay a bit otherwise we can outpace host's terminal. Linux will set LineState (DTR) then Line Coding.
+ // If we send data before Linux's terminal set Line Coding, it can be ignored --> missing data with hardware test loop
+ if (board_millis() - connected_ms < 100) {
+ return; // wait for stable connection
+ }
+
for (uint8_t daddr = 1; daddr <= CFG_TUH_DEVICE_MAX; daddr++) {
if (tuh_mounted(daddr)) {
- if (is_print[daddr]) {
- is_print[daddr] = false;
+ if (is_printable[daddr]) {
+ is_printable[daddr] = false;
print_device_info(daddr, &descriptor_device[daddr]);
tud_cdc_write_flush();
}
@@ -218,9 +281,7 @@ static void print_device_info(uint8_t daddr, const tusb_desc_device_t* desc_devi
cdc_printf("\r\n");
cdc_printf(" iSerialNumber %u " , desc_device->iSerialNumber);
- cdc_printf((char*)serial); // serial is already to UTF-8
- cdc_printf("\r\n");
-
+ cdc_printf("%s \r\n", (char*)serial); // serial is already to UTF-8
cdc_printf(" bNumConfigurations %u\r\n" , desc_device->bNumConfigurations);
}
@@ -232,13 +293,13 @@ void tuh_enum_descriptor_device_cb(uint8_t daddr, tusb_desc_device_t const* desc
void tuh_mount_cb(uint8_t daddr) {
cdc_printf("mounted device %u\r\n", daddr);
tud_cdc_write_flush();
- is_print[daddr] = true;
+ is_printable[daddr] = true;
}
void tuh_umount_cb(uint8_t daddr) {
cdc_printf("unmounted device %u\r\n", daddr);
tud_cdc_write_flush();
- is_print[daddr] = false;
+ is_printable[daddr] = false;
}
//--------------------------------------------------------------------+
@@ -261,7 +322,6 @@ void led_blinking_task(void) {
//--------------------------------------------------------------------+
// String Descriptor Helper
//--------------------------------------------------------------------+
-
static void _convert_utf16le_to_utf8(const uint16_t *utf16, size_t utf16_len, uint8_t *utf8, size_t utf8_len) {
// TODO: Check for runover.
(void)utf8_len;
@@ -310,5 +370,55 @@ static void print_utf16(uint16_t *temp_buf, size_t buf_len) {
_convert_utf16le_to_utf8(temp_buf + 1, utf16_len, (uint8_t *) temp_buf, sizeof(uint16_t) * buf_len);
((uint8_t*) temp_buf)[utf8_len] = '\0';
- cdc_printf((char*) temp_buf);
+ cdc_printf("%s", (char*) temp_buf);
}
+
+//--------------------------------------------------------------------+
+// FreeRTOS
+//--------------------------------------------------------------------+
+#if CFG_TUSB_OS == OPT_OS_FREERTOS
+
+#ifdef ESP_PLATFORM
+ #define USBD_STACK_SIZE 4096
+ #define USBH_STACK_SIZE 4096
+ void app_main(void) {
+ main();
+ }
+#else
+ // Increase stack size when debug log is enabled
+ #define USBD_STACK_SIZE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 4 : 2))
+ #define USBH_STACK_SIZE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 4 : 2))
+#endif
+
+#define MAIN_STACK_SIZE (configMINIMAL_STACK_SIZE*4)
+
+// static task
+#if configSUPPORT_STATIC_ALLOCATION
+StackType_t main_stack[MAIN_STACK_SIZE];
+StaticTask_t main_taskdef;
+
+StackType_t usb_device_stack[USBD_STACK_SIZE];
+StaticTask_t usb_device_taskdef;
+
+StackType_t usb_host_stack[USBH_STACK_SIZE];
+StaticTask_t usb_host_taskdef;
+#endif
+
+void freertos_init(void) {
+ #if configSUPPORT_STATIC_ALLOCATION
+ xTaskCreateStatic(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_device_stack, &usb_device_taskdef);
+ xTaskCreateStatic(usb_host_task, "usbh", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, usb_host_stack, &usb_host_taskdef);
+ xTaskCreateStatic(main_task, "main", MAIN_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, main_stack, &main_taskdef);
+ #else
+ xTaskCreate(usb_device_task, "usbd", USBD_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
+ xTaskCreate(usb_host_task, "usbh", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);
+ xTaskCreate(main_task, "main", MAIN_STACK_SIZE, NULL, configMAX_PRIORITIES - 2, NULL);
+ #endif
+
+ // only start scheduler for non-espressif mcu
+ #ifndef ESP_PLATFORM
+ vTaskStartScheduler();
+ #endif
+}
+
+#endif
diff --git a/examples/dual/host_info_to_device_cdc/src/tusb_config.h b/examples/dual/host_info_to_device_cdc/src/tusb_config.h
index bb47fbf4a..601c27dae 100644
--- a/examples/dual/host_info_to_device_cdc/src/tusb_config.h
+++ b/examples/dual/host_info_to_device_cdc/src/tusb_config.h
@@ -112,7 +112,7 @@
// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
-#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
+#define CFG_TUD_CDC_TX_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 256)
// CDC Endpoint transfer buffer size, more is faster
#define CFG_TUD_CDC_EP_BUFSIZE (TUD_OPT_HIGH_SPEED ? 512 : 64)
diff --git a/examples/dual/host_info_to_device_cdc/src/usb_descriptors.c b/examples/dual/host_info_to_device_cdc/src/usb_descriptors.c
index b7cffe23d..3efa30e20 100644
--- a/examples/dual/host_info_to_device_cdc/src/usb_descriptors.c
+++ b/examples/dual/host_info_to_device_cdc/src/usb_descriptors.c
@@ -32,9 +32,9 @@
* Auto ProductID layout's Bitmap:
* [MSB] HID | MSC | CDC [LSB]
*/
-#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) )
+#define PID_MAP(itf, n) ((CFG_TUD_##itf) ? (1 << (n)) : 0)
+#define USB_PID (0x4000 | PID_MAP(CDC, 0) | PID_MAP(MSC, 1) | PID_MAP(HID, 2) | \
+ PID_MAP(MIDI, 3) | PID_MAP(VENDOR, 4) )
#define USB_VID 0xCafe
#define USB_BCD 0x0200
@@ -42,7 +42,7 @@
//--------------------------------------------------------------------+
// Device Descriptors
//--------------------------------------------------------------------+
-tusb_desc_device_t const desc_device = {
+static tusb_desc_device_t const desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = USB_BCD,
@@ -122,7 +122,7 @@ enum {
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
// full speed configuration
-uint8_t const desc_fs_configuration[] = {
+static uint8_t const desc_fs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -134,7 +134,7 @@ uint8_t const desc_fs_configuration[] = {
// Per USB specs: high speed capable device must report device_qualifier and other_speed_configuration
// high speed configuration
-uint8_t const desc_hs_configuration[] = {
+static uint8_t const desc_hs_configuration[] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, 0x00, 100),
@@ -143,10 +143,10 @@ uint8_t const desc_hs_configuration[] = {
};
// other speed configuration
-uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
+static uint8_t desc_other_speed_config[CONFIG_TOTAL_LEN];
// device qualifier is mostly similar to device descriptor since we don't change configuration based on speed
-tusb_desc_device_qualifier_t const desc_device_qualifier = {
+static tusb_desc_device_qualifier_t const desc_device_qualifier = {
.bLength = sizeof(tusb_desc_device_qualifier_t),
.bDescriptorType = TUSB_DESC_DEVICE_QUALIFIER,
.bcdUSB = USB_BCD,
diff --git a/examples/host/bare_api/Makefile b/examples/host/bare_api/Makefile
index 0235e08c3..f8292385e 100644
--- a/examples/host/bare_api/Makefile
+++ b/examples/host/bare_api/Makefile
@@ -1,13 +1,13 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
src/main.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/host/cdc_msc_hid/Makefile b/examples/host/cdc_msc_hid/Makefile
index 213c02f9c..d72e91e74 100644
--- a/examples/host/cdc_msc_hid/Makefile
+++ b/examples/host/cdc_msc_hid/Makefile
@@ -1,8 +1,8 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
@@ -11,6 +11,6 @@ EXAMPLE_SOURCE = \
src/main.c \
src/msc_app.c \
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/host/cdc_msc_hid/src/app.h b/examples/host/cdc_msc_hid/src/app.h
new file mode 100644
index 000000000..49783b4ae
--- /dev/null
+++ b/examples/host/cdc_msc_hid/src/app.h
@@ -0,0 +1,34 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2025 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
+#define TUSB_TINYUSB_EXAMPLES_APP_H
+
+#include <stdio.h>
+
+void cdc_app_task(void);
+void hid_app_task(void);
+
+#endif
diff --git a/examples/host/cdc_msc_hid/src/cdc_app.c b/examples/host/cdc_msc_hid/src/cdc_app.c
index 97f1a96d6..4c2c5e807 100644
--- a/examples/host/cdc_msc_hid/src/cdc_app.c
+++ b/examples/host/cdc_msc_hid/src/cdc_app.c
@@ -26,6 +26,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
+#include "app.h"
static size_t get_console_inputs(uint8_t* buf, size_t bufsize) {
size_t count = 0;
@@ -50,7 +51,7 @@ void cdc_app_task(void) {
for (uint8_t idx = 0; idx < CFG_TUH_CDC; idx++) {
if (tuh_cdc_mounted(idx)) {
// console --> cdc interfaces
- if (count) {
+ if (count > 0) {
tuh_cdc_write(idx, buf, count);
tuh_cdc_write_flush(idx);
}
diff --git a/examples/host/cdc_msc_hid/src/hid_app.c b/examples/host/cdc_msc_hid/src/hid_app.c
index 6f01d6f45..eb20356cb 100644
--- a/examples/host/cdc_msc_hid/src/hid_app.c
+++ b/examples/host/cdc_msc_hid/src/hid_app.c
@@ -22,9 +22,9 @@
* THE SOFTWARE.
*
*/
-
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c
index e2dd6e5d2..c309a7cae 100644
--- a/examples/host/cdc_msc_hid/src/main.c
+++ b/examples/host/cdc_msc_hid/src/main.c
@@ -29,13 +29,12 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTOTYPES
//--------------------------------------------------------------------+
void led_blinking_task(void);
-extern void cdc_app_task(void);
-extern void hid_app_task(void);
/*------------- MAIN -------------*/
int main(void) {
diff --git a/examples/host/cdc_msc_hid/src/msc_app.c b/examples/host/cdc_msc_hid/src/msc_app.c
index 0e9c99766..dd4e22d7f 100644
--- a/examples/host/cdc_msc_hid/src/msc_app.c
+++ b/examples/host/cdc_msc_hid/src/msc_app.c
@@ -23,6 +23,7 @@
*
*/
+#include <stdio.h>
#include "tusb.h"
//--------------------------------------------------------------------+
diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h
index 2f8cb5e03..75de3511c 100644
--- a/examples/host/cdc_msc_hid/src/tusb_config.h
+++ b/examples/host/cdc_msc_hid/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -134,4 +134,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/host/cdc_msc_hid_freertos/Makefile b/examples/host/cdc_msc_hid_freertos/Makefile
index 178341f81..2e323ed56 100644
--- a/examples/host/cdc_msc_hid_freertos/Makefile
+++ b/examples/host/cdc_msc_hid_freertos/Makefile
@@ -1,9 +1,9 @@
RTOS = freertos
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE = \
@@ -12,6 +12,6 @@ EXAMPLE_SOURCE = \
src/main.c \
src/msc_app.c \
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/host/cdc_msc_hid_freertos/only.txt b/examples/host/cdc_msc_hid_freertos/only.txt
index 576271aff..ef0a1ac96 100644
--- a/examples/host/cdc_msc_hid_freertos/only.txt
+++ b/examples/host/cdc_msc_hid_freertos/only.txt
@@ -1,4 +1,3 @@
-mcu:ESP32P4
mcu:LPC175X_6X
mcu:LPC177X_8X
mcu:LPC18XX
@@ -15,5 +14,6 @@ mcu:STM32F7
mcu:STM32H7
mcu:STM32H7RS
mcu:STM32N6
+family:espressif
family:samd21
family:samd5x_e5x
diff --git a/examples/host/cdc_msc_hid_freertos/src/app.h b/examples/host/cdc_msc_hid_freertos/src/app.h
new file mode 100644
index 000000000..8892a1b6b
--- /dev/null
+++ b/examples/host/cdc_msc_hid_freertos/src/app.h
@@ -0,0 +1,35 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2025 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
+#define TUSB_TINYUSB_EXAMPLES_APP_H
+
+#include <stdio.h>
+
+void cdc_app_init(void);
+void hid_app_init(void);
+void msc_app_init(void);
+
+#endif
diff --git a/examples/host/cdc_msc_hid_freertos/src/cdc_app.c b/examples/host/cdc_msc_hid_freertos/src/cdc_app.c
index d99760a02..0e0105980 100644
--- a/examples/host/cdc_msc_hid_freertos/src/cdc_app.c
+++ b/examples/host/cdc_msc_hid_freertos/src/cdc_app.c
@@ -26,6 +26,7 @@
#include "tusb.h"
#include "bsp/board_api.h"
+#include "app.h"
#ifdef ESP_PLATFORM
#define CDC_STACK_SZIE 2048
@@ -45,9 +46,9 @@ static void cdc_app_task(void* param);
void cdc_app_init(void) {
#if configSUPPORT_STATIC_ALLOCATION
- xTaskCreateStatic(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
+ (void) xTaskCreateStatic(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, cdc_stack, &cdc_taskdef);
#else
- xTaskCreate(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
+ (void) xTaskCreate(cdc_app_task, "cdc", CDC_STACK_SZIE, NULL, configMAX_PRIORITIES-2, NULL);
#endif
}
@@ -56,7 +57,9 @@ static size_t get_console_inputs(uint8_t *buf, size_t bufsize) {
size_t count = 0;
while (count < bufsize) {
int ch = board_getchar();
- if (ch <= 0) break;
+ if (ch <= 0) {
+ break;
+ }
buf[count] = (uint8_t) ch;
count++;
diff --git a/examples/host/cdc_msc_hid_freertos/src/hid_app.c b/examples/host/cdc_msc_hid_freertos/src/hid_app.c
index 9ea5c1be0..79e0b5a28 100644
--- a/examples/host/cdc_msc_hid_freertos/src/hid_app.c
+++ b/examples/host/cdc_msc_hid_freertos/src/hid_app.c
@@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
@@ -160,7 +161,7 @@ static void process_kbd_report(hid_keyboard_report_t const *report) {
// Mouse
//--------------------------------------------------------------------+
-void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
+static void cursor_movement(int8_t x, int8_t y, int8_t wheel) {
#if USE_ANSI_ESCAPE
// Move X using ansi escape
if ( x < 0) {
@@ -210,6 +211,7 @@ static void process_mouse_report(hid_mouse_report_t const *report) {
//--------------------------------------------------------------------+
static void process_generic_report(uint8_t dev_addr, uint8_t instance, uint8_t const *report, uint16_t len) {
(void) dev_addr;
+ (void) len;
uint8_t const rpt_count = hid_info[instance].report_count;
tuh_hid_report_info_t *rpt_info_arr = hid_info[instance].report_info;
diff --git a/examples/host/cdc_msc_hid_freertos/src/main.c b/examples/host/cdc_msc_hid_freertos/src/main.c
index d498c1b57..a41de2769 100644
--- a/examples/host/cdc_msc_hid_freertos/src/main.c
+++ b/examples/host/cdc_msc_hid_freertos/src/main.c
@@ -29,12 +29,13 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
#ifdef ESP_PLATFORM
#define USBH_STACK_SIZE 4096
#else
// Increase stack size when debug log is enabled
- #define USBH_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1)
+ #define USBH_STACK_SIZE (configMINIMAL_STACK_SIZE * (CFG_TUSB_DEBUG ? 4 : 2))
#endif
@@ -65,9 +66,6 @@ TimerHandle_t blinky_tm;
static void led_blinky_cb(TimerHandle_t xTimer);
static void usb_host_task(void* param);
-extern void cdc_app_init(void);
-extern void hid_app_init(void);
-extern void msc_app_init(void);
/*------------- MAIN -------------*/
int main(void) {
diff --git a/examples/host/cdc_msc_hid_freertos/src/msc_app.c b/examples/host/cdc_msc_hid_freertos/src/msc_app.c
index 6439495a8..fa864c364 100644
--- a/examples/host/cdc_msc_hid_freertos/src/msc_app.c
+++ b/examples/host/cdc_msc_hid_freertos/src/msc_app.c
@@ -23,7 +23,10 @@
*
*/
+#include <stdio.h>
+
#include "tusb.h"
+#include "app.h"
// define the buffer to be place in USB/DMA memory with correct alignment/cache line size
CFG_TUH_MEM_SECTION static struct {
diff --git a/examples/host/cdc_msc_hid_freertos/src/tusb_config.h b/examples/host/cdc_msc_hid_freertos/src/tusb_config.h
index 3cdb227e2..8583e7176 100644
--- a/examples/host/cdc_msc_hid_freertos/src/tusb_config.h
+++ b/examples/host/cdc_msc_hid_freertos/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -139,4 +139,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/host/device_info/Makefile b/examples/host/device_info/Makefile
index 0235e08c3..f8292385e 100644
--- a/examples/host/device_info/Makefile
+++ b/examples/host/device_info/Makefile
@@ -1,13 +1,13 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
src/main.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/host/device_info/only.txt b/examples/host/device_info/only.txt
index 133a7c9a0..61a08f68d 100644
--- a/examples/host/device_info/only.txt
+++ b/examples/host/device_info/only.txt
@@ -1,7 +1,4 @@
mcu:CH32V20X
-mcu:ESP32S2
-mcu:ESP32S3
-mcu:ESP32P4
mcu:KINETIS_KL
mcu:LPC175X_6X
mcu:LPC177X_8X
@@ -21,5 +18,6 @@ mcu:STM32F7
mcu:STM32H7
mcu:STM32H7RS
mcu:STM32N6
+family:espressif
family:samd21
family:samd5x_e5x
diff --git a/examples/host/device_info/src/main.c b/examples/host/device_info/src/main.c
index 419806551..f71702efc 100644
--- a/examples/host/device_info/src/main.c
+++ b/examples/host/device_info/src/main.c
@@ -171,9 +171,7 @@ void tuh_mount_cb(uint8_t daddr) {
printf("\r\n");
printf(" iSerialNumber %u ", desc.device.iSerialNumber);
- printf((char*)desc.serial); // serial is already to UTF-8
- printf("\r\n");
-
+ printf("%s\r\n", (char*)desc.serial); // serial is already to UTF-8
printf(" bNumConfigurations %u\r\n", desc.device.bNumConfigurations);
}
diff --git a/examples/host/hid_controller/Makefile b/examples/host/hid_controller/Makefile
index 1377f1f90..732520c63 100644
--- a/examples/host/hid_controller/Makefile
+++ b/examples/host/hid_controller/Makefile
@@ -1,14 +1,14 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
src/hid_app.c \
src/main.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/host/hid_controller/src/app.h b/examples/host/hid_controller/src/app.h
new file mode 100644
index 000000000..b4d072668
--- /dev/null
+++ b/examples/host/hid_controller/src/app.h
@@ -0,0 +1,33 @@
+/*
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2025 Ha Thach (tinyusb.org)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * This file is part of the TinyUSB stack.
+ */
+#ifndef TUSB_TINYUSB_EXAMPLES_APP_H
+#define TUSB_TINYUSB_EXAMPLES_APP_H
+
+#include <stdio.h>
+
+void hid_app_task(void);
+
+#endif
diff --git a/examples/host/hid_controller/src/hid_app.c b/examples/host/hid_controller/src/hid_app.c
index 1d6ca8b07..f8c3d029b 100644
--- a/examples/host/hid_controller/src/hid_app.c
+++ b/examples/host/hid_controller/src/hid_app.c
@@ -25,6 +25,7 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
/* From https://www.kernel.org/doc/html/latest/input/gamepad.html
____________________________ __
diff --git a/examples/host/hid_controller/src/main.c b/examples/host/hid_controller/src/main.c
index f3244db95..fa70d7d1a 100644
--- a/examples/host/hid_controller/src/main.c
+++ b/examples/host/hid_controller/src/main.c
@@ -34,18 +34,15 @@
#include "bsp/board_api.h"
#include "tusb.h"
+#include "app.h"
//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF PROTYPES
//--------------------------------------------------------------------+
void led_blinking_task(void);
-extern void cdc_task(void);
-extern void hid_app_task(void);
-
/*------------- MAIN -------------*/
-int main(void)
-{
+int main(void) {
board_init();
printf("TinyUSB Host HID Controller Example\r\n");
@@ -60,19 +57,11 @@ int main(void)
board_init_after_tusb();
- while (1)
- {
+ while (1) {
// tinyusb host task
tuh_task();
led_blinking_task();
-
-#if CFG_TUH_CDC
- cdc_task();
-#endif
-
-#if CFG_TUH_HID
hid_app_task();
-#endif
}
}
@@ -83,8 +72,7 @@ int main(void)
//--------------------------------------------------------------------+
// Blinking Task
//--------------------------------------------------------------------+
-void led_blinking_task(void)
-{
+void led_blinking_task(void) {
const uint32_t interval_ms = 1000;
static uint32_t start_ms = 0;
diff --git a/examples/host/hid_controller/src/tusb_config.h b/examples/host/hid_controller/src/tusb_config.h
index 351fe0178..a5c202fda 100644
--- a/examples/host/hid_controller/src/tusb_config.h
+++ b/examples/host/hid_controller/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -119,4 +119,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/host/midi_rx/Makefile b/examples/host/midi_rx/Makefile
index 0235e08c3..f8292385e 100644
--- a/examples/host/midi_rx/Makefile
+++ b/examples/host/midi_rx/Makefile
@@ -1,13 +1,13 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
EXAMPLE_SOURCE += \
src/main.c
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/host/msc_file_explorer/CMakeLists.txt b/examples/host/msc_file_explorer/CMakeLists.txt
index 5ac75c04a..e9c15b7c1 100644
--- a/examples/host/msc_file_explorer/CMakeLists.txt
+++ b/examples/host/msc_file_explorer/CMakeLists.txt
@@ -27,10 +27,8 @@ target_sources(${PROJECT} PUBLIC
)
# Suppress warnings on fatfs
-if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- set_source_files_properties(
- ${TOP}/lib/fatfs/source/ff.c
- PROPERTIES
+if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
+ set_source_files_properties(${TOP}/lib/fatfs/source/ff.c PROPERTIES
COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual"
)
endif ()
diff --git a/examples/host/msc_file_explorer/Makefile b/examples/host/msc_file_explorer/Makefile
index f0872376f..39d00d982 100644
--- a/examples/host/msc_file_explorer/Makefile
+++ b/examples/host/msc_file_explorer/Makefile
@@ -1,10 +1,9 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
FATFS_PATH = lib/fatfs/source
INC += \
src \
- $(TOP)/hw \
$(TOP)/$(FATFS_PATH) \
$(TOP)/lib/embedded-cli \
@@ -13,7 +12,7 @@ EXAMPLE_SOURCE = \
src/main.c \
src/msc_app.c \
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
# FatFS source
SRC_C += \
@@ -24,4 +23,4 @@ SRC_C += \
# suppress warning caused by fatfs
CFLAGS_GCC += -Wno-error=cast-qual
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/host/msc_file_explorer/src/main.c b/examples/host/msc_file_explorer/src/main.c
index 506c3b015..f9ec0ff5f 100644
--- a/examples/host/msc_file_explorer/src/main.c
+++ b/examples/host/msc_file_explorer/src/main.c
@@ -56,7 +56,6 @@
*/
#include <stdlib.h>
-#include <stdio.h>
#include <string.h>
#include "bsp/board_api.h"
diff --git a/examples/host/msc_file_explorer/src/msc_app.h b/examples/host/msc_file_explorer/src/msc_app.h
index 3ba03d0dc..a99da5b5c 100644
--- a/examples/host/msc_file_explorer/src/msc_app.h
+++ b/examples/host/msc_file_explorer/src/msc_app.h
@@ -27,6 +27,7 @@
#define MSC_APP_H
#include <stdbool.h>
+#include <stdio.h>
bool msc_app_init(void);
void msc_app_task(void);
diff --git a/examples/host/msc_file_explorer/src/tusb_config.h b/examples/host/msc_file_explorer/src/tusb_config.h
index c1829c300..a9d24c89f 100644
--- a/examples/host/msc_file_explorer/src/tusb_config.h
+++ b/examples/host/msc_file_explorer/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -118,4 +118,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */
diff --git a/examples/typec/power_delivery/Makefile b/examples/typec/power_delivery/Makefile
index 7fa475da5..7f65c689a 100644
--- a/examples/typec/power_delivery/Makefile
+++ b/examples/typec/power_delivery/Makefile
@@ -1,11 +1,13 @@
-include ../../build_system/make/make.mk
+include ../../../hw/bsp/family_support.mk
INC += \
src \
- $(TOP)/hw \
+
# Example source
-EXAMPLE_SOURCE += $(wildcard src/*.c)
-SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
+EXAMPLE_SOURCE += \
+ src/main.c
+
+SRC_C += $(addprefix $(EXAMPLE_PATH)/, $(EXAMPLE_SOURCE))
-include ../../build_system/make/rules.mk
+include ../../../hw/bsp/family_rules.mk
diff --git a/examples/typec/power_delivery/src/tusb_config.h b/examples/typec/power_delivery/src/tusb_config.h
index f7cb3cc04..ee013d056 100644
--- a/examples/typec/power_delivery/src/tusb_config.h
+++ b/examples/typec/power_delivery/src/tusb_config.h
@@ -23,8 +23,8 @@
*
*/
-#ifndef _TUSB_CONFIG_H_
-#define _TUSB_CONFIG_H_
+#ifndef TUSB_CONFIG_H_
+#define TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
@@ -80,4 +80,4 @@
}
#endif
-#endif /* _TUSB_CONFIG_H_ */
+#endif /* TUSB_CONFIG_H_ */