Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 1534 files
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ CIRCUITPY_WIFI = 1

CIRCUITPY_PICODVI = 1

# No room: this board fills FLASH_FIRMWARE. Frees ~9kB. Not the board's I2S
# line-out/HDMI audio, which audiobusio still provides.
CIRCUITPY_USB_AUDIO = 0

CFLAGS += \
-DCYW43_PIN_WL_DYNAMIC=0 \
-DCYW43_DEFAULT_PIN_WL_HOST_WAKE=24 \
Expand Down
1 change: 1 addition & 0 deletions ports/stm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ endif
ifneq ($(CIRCUITPY_USB),0)
ifeq ($(MCU_VARIANT),$(filter $(MCU_VARIANT),STM32L433xx))
SRC_C += lib/tinyusb/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
SRC_C += lib/tinyusb/src/portable/st/stm32_fsdev/fsdev_common.c
else
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dcd_dwc2.c
SRC_C += lib/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c
Expand Down
2 changes: 2 additions & 0 deletions shared-module/usb/core/Device.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ static bool _wait_for_callback(void) {
switch (result) {
case XFER_RESULT_SUCCESS:
return true;
case XFER_RESULT_ABORTED:
case XFER_RESULT_FAILED:
mp_raise_usb_core_USBError(NULL);
break;
Expand Down Expand Up @@ -201,6 +202,7 @@ static size_t _handle_timed_transfer_callback(tuh_xfer_t *xfer, mp_int_t timeout
switch (result) {
case XFER_RESULT_SUCCESS:
return _actual_len;
case XFER_RESULT_ABORTED:
case XFER_RESULT_FAILED:
mp_raise_usb_core_USBError(NULL);
break;
Expand Down
122 changes: 61 additions & 61 deletions shared-module/usb_audio/__init__.c

Large diffs are not rendered by default.

95 changes: 47 additions & 48 deletions shared-module/usb_audio/usb_audio_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
// (to size the IN endpoint) as well as from the descriptor/binding code.

// Actual length, in bytes, of the audio function descriptor emitted for the
// current direction (mic, speaker, or headset). Declared here -- in the
// dependency-free header tusb_config.h already includes -- because TinyUSB's
// audio class driver reads CFG_TUD_AUDIO_FUNC_1_DESC_LEN at enumeration time and
// returns it to the device core as the number of configuration-descriptor bytes
// the function owns. That value MUST equal the descriptor we actually emitted:
// the three directions differ in length, so a compile-time maximum would over-
// report for the shorter ones and make the core swallow the interfaces that
// follow audio (CDC/MSC), breaking their enumeration. The full definition lives
// in __init__.c (also declared in __init__.h for the descriptor builder).
// current direction (mic, speaker, or headset). usb_desc.c reads this while
// assembling the configuration descriptor, adding it to total_descriptor_length
// so wTotalLength covers the exact bytes the audio function emits. That value
// MUST equal the descriptor we actually emitted: the three directions differ in
// length, so a compile-time maximum would over-report for the shorter ones and
// make the host swallow the interfaces that follow audio (CDC/MSC), breaking
// their enumeration. The full definition lives in __init__.c (also declared in
// __init__.h for the descriptor builder).
size_t usb_audio_descriptor_length(void);

// The isochronous IN endpoint's wMaxPacketSize in the USB descriptor is computed
Expand All @@ -45,7 +44,7 @@ size_t usb_audio_descriptor_length(void);
#define USB_AUDIO_ISO_EP_NUM (0)
#endif

// Fixed UAC2 entity IDs baked into TUD_AUDIO_MIC_ONE_CH_DESCRIPTOR and the
// Fixed UAC2 entity IDs baked into TUD_AUDIO20_MIC_ONE_CH_DESCRIPTOR and the
// hand-rolled speaker descriptor (USB_AUDIO_SPEAKER_DESCRIPTOR in __init__.c).
// The speaker reuses the same IDs as the mic; only the terminal roles reverse
// (input terminal = USB streaming, output terminal = desktop speaker).
Expand All @@ -69,26 +68,26 @@ size_t usb_audio_descriptor_length(void);
#define USB_AUDIO_HS_ENTITY_MIC_OUTPUT_TERMINAL (0x07) // USB streaming out to host

// Length of the no-feedback mono speaker descriptor. It uses the same set of
// sub-descriptors as TUD_AUDIO_MIC_ONE_CH_DESCRIPTOR (one isochronous data
// sub-descriptors as TUD_AUDIO20_MIC_ONE_CH_DESCRIPTOR (one isochronous data
// endpoint, no feedback endpoint), so this is identical to
// TUD_AUDIO_MIC_ONE_CH_DESC_LEN -- but spell it out independently so the two
// TUD_AUDIO20_MIC_ONE_CH_DESC_LEN -- but spell it out independently so the two
// can diverge later (e.g. stereo) without silently mis-sizing the descriptor.
// These TUD_AUDIO_DESC_*_LEN macros come from TinyUSB's usbd.h; this expression
// These TUD_AUDIO20_DESC_*_LEN macros come from TinyUSB's usbd.h; this expression
// is only expanded where that header is already included (never at the point
// tusb_config.h includes us), so the header stays dependency-free.
#define USB_AUDIO_SPEAKER_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 \
+ 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)
#define USB_AUDIO_SPEAKER_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) \
+ 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)

// Length of the combined headset descriptor (microphone + speaker both enabled): one IAD
// wrapping a single AudioControl interface plus two AudioStreaming interfaces
Expand All @@ -99,29 +98,29 @@ size_t usb_audio_descriptor_length(void);
// single-direction descriptors). See USB_AUDIO_HEADSET_DESCRIPTOR in __init__.c.
// Expanded only where TinyUSB's usbd.h is already included (never at the point
// tusb_config.h includes us), so this header stays dependency-free.
#define USB_AUDIO_HEADSET_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 \
#define USB_AUDIO_HEADSET_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 \
/* speaker chain: USB-streaming input terminal -> feature unit -> speaker */ \
+ TUD_AUDIO_DESC_INPUT_TERM_LEN \
+ TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN \
+ TUD_AUDIO_DESC_OUTPUT_TERM_LEN \
+ TUD_AUDIO20_DESC_INPUT_TERM_LEN \
+ TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(1) \
+ TUD_AUDIO20_DESC_OUTPUT_TERM_LEN \
/* mic chain: microphone input terminal -> feature unit -> USB-streaming out */ \
+ TUD_AUDIO_DESC_INPUT_TERM_LEN \
+ TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN \
+ TUD_AUDIO_DESC_OUTPUT_TERM_LEN \
+ TUD_AUDIO20_DESC_INPUT_TERM_LEN \
+ TUD_AUDIO20_DESC_FEATURE_UNIT_LEN(1) \
+ TUD_AUDIO20_DESC_OUTPUT_TERM_LEN \
/* speaker AudioStreaming interface (alt 0 + alt 1 with OUT endpoint) */ \
+ 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_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 \
/* mic AudioStreaming interface (alt 0 + alt 1 with IN endpoint) */ \
+ 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_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)
25 changes: 3 additions & 22 deletions supervisor/shared/usb/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,12 @@ extern "C" {
#if CIRCUITPY_USB_AUDIO
#include "shared-module/usb_audio/usb_audio_descriptors.h"

// Single audio function. The emitted descriptor is chosen at boot from the
// stored direction: a mic (1 AS interface, IN endpoint), a speaker (1 AS
// interface, OUT endpoint), or a combined headset (2 AS interfaces, one IN and
// one OUT endpoint). The class driver returns this length to the device core as
// the span of config descriptor the function owns, so it must equal the
// descriptor we actually emitted -- the three directions differ in length, so a
// compile-time maximum would over-report for the shorter ones and make the core
// skip the interfaces that follow audio. usb_audio_descriptor_length() returns
// the live length for the stored direction; it is only read at enumeration time
// (audiod_open), by which point usb_audio.enable() has fixed the direction.
#define CFG_TUD_AUDIO_FUNC_1_DESC_LEN usb_audio_descriptor_length()
// The headset presents two AudioStreaming interfaces; the single-direction
// descriptors use only the first. The class driver sizes its per-interface alt
// tracking from this, so it must cover the largest case.
#define CFG_TUD_AUDIO_FUNC_1_N_AS_INT 2
// EP0 buffer for class-specific control requests (sample-freq range, volume range, ...).
#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64
#define CFG_TUD_AUDIO_CTRL_BUF_SZ 64

#define CFG_TUD_AUDIO_ENABLE_EP_IN 1
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_TX USB_AUDIO_N_BYTES_PER_SAMPLE
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_TX USB_AUDIO_N_CHANNELS
// wMaxPacketSize, sized for the highest supported sample rate.
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TUD_AUDIO_EP_SIZE(USB_AUDIO_MAX_SAMPLE_RATE, USB_AUDIO_N_BYTES_PER_SAMPLE, USB_AUDIO_N_CHANNELS)
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, USB_AUDIO_MAX_SAMPLE_RATE, USB_AUDIO_N_BYTES_PER_SAMPLE, USB_AUDIO_N_CHANNELS)
// Deep software FIFO so the 1 ms refill keeps clear of the underrun floor.
#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ (16 * CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX)

Expand All @@ -153,10 +136,8 @@ extern "C" {
// descriptor (still mic-only until the speaker descriptor lands). Mirrors the
// IN sizing above.
#define CFG_TUD_AUDIO_ENABLE_EP_OUT 1
#define CFG_TUD_AUDIO_FUNC_1_N_BYTES_PER_SAMPLE_RX USB_AUDIO_N_BYTES_PER_SAMPLE
#define CFG_TUD_AUDIO_FUNC_1_N_CHANNELS_RX USB_AUDIO_N_CHANNELS
// wMaxPacketSize, sized for the highest supported sample rate.
#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TUD_AUDIO_EP_SIZE(USB_AUDIO_MAX_SAMPLE_RATE, USB_AUDIO_N_BYTES_PER_SAMPLE, USB_AUDIO_N_CHANNELS)
#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX TUD_AUDIO_EP_SIZE(TUD_OPT_HIGH_SPEED, USB_AUDIO_MAX_SAMPLE_RATE, USB_AUDIO_N_BYTES_PER_SAMPLE, USB_AUDIO_N_CHANNELS)
// Deep software FIFO so the 1 ms drain keeps clear of the overrun ceiling.
#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ (16 * CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX)
#endif
Expand Down
2 changes: 1 addition & 1 deletion supervisor/shared/usb/usb_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ
// size. Setting CFG_TUD_CDC_RX_BUFSIZE to the endpoint size and then sending
// any character will prevent ctrl-c from working. Require at least a 64
// character buffer.
#if CFG_TUD_CDC_RX_BUFSIZE < CFG_TUD_CDC_EP_BUFSIZE + 64
#if CFG_TUD_CDC_RX_BUFSIZE < CFG_TUD_CDC_RX_EPSIZE + 64
#error "CFG_TUD_CDC_RX_BUFSIZE must be 64 bytes bigger than endpoint size."
#endif

Expand Down
1 change: 0 additions & 1 deletion supervisor/supervisor.mk
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ ifeq ($(CIRCUITPY_TINYUSB),1)
SRC_SUPERVISOR += \
lib/tinyusb/src/class/cdc/cdc_device.c \
lib/tinyusb/src/device/usbd.c \
lib/tinyusb/src/device/usbd_control.c \
supervisor/shared/usb/usb_desc.c \
supervisor/shared/usb/usb_device.c \

Expand Down
Loading