Skip to content

Commit

Permalink
Merge branch 'uac_quirk' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
HiFiPhile committed May 12, 2024
2 parents 1b8d22c + eb43d1e commit 299285a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 3 deletions.
12 changes: 12 additions & 0 deletions examples/device/uac2_speaker_fb/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,18 @@ bool tud_audio_rx_done_post_read_cb(uint8_t rhport, uint16_t n_bytes_received, u
return true;
}
#endif

#if CFG_TUD_QUIRK_HOST_OS_HINT
bool tud_audio_feedback_format_correction_cb(uint8_t func_id)
{
(void)func_id;
if(tud_speed_get() == TUSB_SPEED_FULL && tud_quirk_host_os_hint() == TUD_QUIRK_OS_HINT_OSX) {
return true;
} else {
return false;
}
}
#endif
//--------------------------------------------------------------------+
// AUDIO Task
//--------------------------------------------------------------------+
Expand Down
6 changes: 6 additions & 0 deletions examples/device/uac2_speaker_fb/src/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ extern "C" {
// Size of control request buffer
#define CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ 64

//--------------------------------------------------------------------
// QUIRKS
//--------------------------------------------------------------------

#define CFG_TUD_QUIRK_HOST_OS_HINT 1

#ifdef __cplusplus
}
#endif
Expand Down
49 changes: 46 additions & 3 deletions examples/device/uac2_speaker_fb/src/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bcdUSB = 0x0201,

// 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)
Expand Down Expand Up @@ -144,7 +144,7 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf)
#define EPNUM_DEBUG 0x02
#endif

uint8_t const desc_configuration[] =
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),
Expand All @@ -158,13 +158,56 @@ uint8_t const desc_configuration[] =
#endif
};

#if CFG_TUD_QUIRK_HOST_OS_HINT
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),

// 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 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
};
#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 CFG_TUD_QUIRK_HOST_OS_HINT
if(tud_speed_get() == TUSB_SPEED_FULL && tud_quirk_host_os_hint() == TUD_QUIRK_OS_HINT_OSX) {
return desc_configuration_osx_fs;
}
#endif
return desc_configuration_default;
}

//--------------------------------------------------------------------+
// BOS Descriptor, required for OS detection quirk
//--------------------------------------------------------------------+

#define TUD_BOS_USB20_EXT_DESC_LEN 7

#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_USB20_EXT_DESC_LEN)

// BOS Descriptor is required for webUSB
uint8_t const desc_bos[] =
{
// total length, number of device caps
TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 1),

// USB 2.0 Extension Descriptor
0x07, TUSB_DESC_DEVICE_CAPABILITY, DEVICE_CAPABILITY_USB20_EXTENSION, 0x00, 0x00, 0x00,0x00
};

uint8_t const * tud_descriptor_bos_cb(void)
{
return desc_bos;
}

//--------------------------------------------------------------------+
Expand Down

0 comments on commit 299285a

Please sign in to comment.