From 7c7383cabf6019b7e85348b8cf5b30bc5bff27f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Tue, 8 Oct 2024 15:05:24 +0200 Subject: [PATCH] tests: usb: uac2: Test Feature Unit descriptor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Insert Feature Units in between: * USB Streaming Input Terminal and Headphones Output Terminal * Microphone Input Terminal and USB Streaming Output Terminal The Feature Units have Mute control only on the Primary channel 0. The headphones Feature Unit also has Automatic Gain control on all channels while microphone Feature Unit has Automatic Gain control only on the Logichal channel 1. Signed-off-by: Tomasz Moń --- tests/subsys/usb/uac2/app.overlay | 23 +++++++++++-- tests/subsys/usb/uac2/src/uac2_desc.c | 49 ++++++++++++++++++++++----- 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/tests/subsys/usb/uac2/app.overlay b/tests/subsys/usb/uac2/app.overlay index 7b7585209a9..52db720a29c 100644 --- a/tests/subsys/usb/uac2/app.overlay +++ b/tests/subsys/usb/uac2/app.overlay @@ -29,9 +29,19 @@ front-right; }; + out_feature_unit: out_feature_unit { + compatible = "zephyr,uac2-feature-unit"; + data-source = <&out_terminal>; + mute-control = "host-programmable"; + automatic-gain-control = + "host-programmable" /* Primary */, + "host-programmable" /* Channel 1 */, + "host-programmable" /* Channel 2 */; + }; + headphones_output: headphones { compatible = "zephyr,uac2-output-terminal"; - data-source = <&out_terminal>; + data-source = <&out_feature_unit>; clock-source = <&uac_aclk>; terminal-type = ; assoc-terminal = <&mic_input>; @@ -50,9 +60,18 @@ front-left; }; + in_feature_unit: in_feature_unit { + compatible = "zephyr,uac2-feature-unit"; + data-source = <&mic_input>; + mute-control = "host-programmable"; + automatic-gain-control = + "not-present" /* Primary */, + "host-programmable" /* Channel 1 */; + }; + in_terminal: in_terminal { compatible = "zephyr,uac2-output-terminal"; - data-source = <&mic_input>; + data-source = <&in_feature_unit>; clock-source = <&uac_aclk>; terminal-type = ; }; diff --git a/tests/subsys/usb/uac2/src/uac2_desc.c b/tests/subsys/usb/uac2/src/uac2_desc.c index 77474649c4c..c0c76efabba 100644 --- a/tests/subsys/usb/uac2/src/uac2_desc.c +++ b/tests/subsys/usb/uac2/src/uac2_desc.c @@ -18,7 +18,7 @@ static const uint8_t reference_ac_interface_descriptor[] = { 0x01, /* bDescriptorSubtype = HEADER */ 0x00, 0x02, /* bcdADC = 02.00 */ 0x04, /* bCategory = HEADSET */ - 0x4b, 0x00, /* wTotalLength = 0x4b = 75 */ + 0x6b, 0x00, /* wTotalLength = 0x6b = 107 */ 0x00, /* bmControls = Latency Control not present */ }; @@ -50,15 +50,28 @@ static const uint8_t reference_ac_hp_input_terminal_descriptor[] = { 0x00, /* iTerminal = 0 (no string descriptor) */ }; +static const uint8_t reference_ac_hp_feature_unit_descriptor[] = { + /* 4.7.2.8 Feature Unit Descriptor */ + 0x12, /* bLength = 18 */ + 0x24, /* bDescriptorType = CS_INTERFACE */ + 0x06, /* bDescriptorSubtype = FEATURE_UNIT */ + 0x03, /* bUnitID = 3 */ + 0x02, /* bSourceID = 2 (streaming input) */ + 0x03, 0x30, 0x00, 0x00, /* bmaControls(0): Mute and Auto Gain */ + 0x00, 0x30, 0x00, 0x00, /* bmaControls(1): Auto Gain */ + 0x00, 0x30, 0x00, 0x00, /* bmaControls(2): Auto Gain */ + 0x00, /* iFeature = 0 (no string descriptor)*/ +}; + static const uint8_t reference_ac_hp_output_terminal_descriptor[] = { /* 4.7.2.5 Output Terminal Descriptor */ 0x0c, /* bLength = 12 */ 0x24, /* bDescriptorType = CS_INTERFACE */ 0x03, /* bDescriptorSubtype = OUTPUT_TERMINAL */ - 0x03, /* bTerminalID = 3 */ + 0x04, /* bTerminalID = 4 */ 0x02, 0x04, /* wTerminalType = 0x0402 (Headset) */ - 0x04, /* bAssocTerminal = 4 (headset input) */ - 0x02, /* bSourceID = 2 (streaming input) */ + 0x05, /* bAssocTerminal = 5 (headset input) */ + 0x03, /* bSourceID = 3 (headphones feature unit) */ 0x01, /* bCSourceID = 1 (main clock) */ 0x00, 0x00, /* bmControls = none present */ 0x00, /* iTerminal = 0 (no string descriptor) */ @@ -69,9 +82,9 @@ static const uint8_t reference_ac_mic_input_terminal_descriptor[] = { 0x11, /* bLength = 17 */ 0x24, /* bDescriptorType = CS_INTERFACE */ 0x02, /* bDescriptorSubtype = INPUT_TERMINAL */ - 0x04, /* bTerminalID = 4 */ + 0x05, /* bTerminalID = 5 */ 0x02, 0x04, /* wTerminalType = 0x0402 (Headset) */ - 0x03, /* bAssocTerminal = 3 (headset output) */ + 0x04, /* bAssocTerminal = 4 (headset output) */ 0x01, /* bCSourceID = 1 (main clock) */ 0x01, /* bNrChannels = 1 */ 0x01, 0x00, 0x00, 0x00, /* bmChannelConfig = Front Left */ @@ -80,15 +93,27 @@ static const uint8_t reference_ac_mic_input_terminal_descriptor[] = { 0x00, /* iTerminal = 0 (no string descriptor) */ }; +static const uint8_t reference_ac_mic_feature_unit_descriptor[] = { + /* 4.7.2.8 Feature Unit Descriptor */ + 0x0e, /* bLength = 14 */ + 0x24, /* bDescriptorType = CS_INTERFACE */ + 0x06, /* bDescriptorSubtype = FEATURE_UNIT */ + 0x06, /* bUnitID = 6 */ + 0x05, /* bSourceID = 5 (headset input) */ + 0x03, 0x00, 0x00, 0x00, /* bmaControls(0): Mute */ + 0x00, 0x30, 0x00, 0x00, /* bmaControls(1): Auto Gain */ + 0x00, /* iFeature = 0 (no string descriptor)*/ +}; + static const uint8_t reference_ac_mic_output_terminal_descriptor[] = { /* 4.7.2.5 Output Terminal Descriptor */ 0x0c, /* bLength = 12 */ 0x24, /* bDescriptorType = CS_INTERFACE */ 0x03, /* bDescriptorSubtype = OUTPUT_TERMINAL */ - 0x05, /* bTerminalID = 5 */ + 0x07, /* bTerminalID = 7 */ 0x01, 0x01, /* wTerminalType = 0x0101 (USB streaming) */ 0x00, /* bAssocTerminal = 0 (not associated) */ - 0x04, /* bSourceID = 4 (headset input) */ + 0x06, /* bSourceID = 6 (mic feature unit) */ 0x01, /* bCSourceID = 1 (main clock) */ 0x00, 0x00, /* bmControls = none present */ 0x00, /* iTerminal = 0 (no string descriptor) */ @@ -100,7 +125,7 @@ static const uint8_t reference_as_in_cs_general_descriptor[] = { 0x10, /* bLength = 16 */ 0x24, /* bDescriptorType = CS_INTERFACE */ 0x01, /* bDescriptorSubtype = AS_GENERAL */ - 0x05, /* bTerminalLink = 5 (USB streaming output) */ + 0x07, /* bTerminalLink = 7 (USB streaming output) */ 0x00, /* bmControls = non present */ 0x01, /* bFormatType = 1 */ 0x01, 0x00, 0x00, 0x00, /* bmFormats = PCM */ @@ -308,12 +333,18 @@ static void test_uac2_descriptors(const struct usb_desc_header **descriptors, zassert_mem_equal(reference_ac_hp_input_terminal_descriptor, *ptr, ARRAY_SIZE(reference_ac_hp_input_terminal_descriptor)); ptr++; + zassert_mem_equal(reference_ac_hp_feature_unit_descriptor, *ptr, + ARRAY_SIZE(reference_ac_hp_feature_unit_descriptor)); + ptr++; zassert_mem_equal(reference_ac_hp_output_terminal_descriptor, *ptr, ARRAY_SIZE(reference_ac_hp_output_terminal_descriptor)); ptr++; zassert_mem_equal(reference_ac_mic_input_terminal_descriptor, *ptr, ARRAY_SIZE(reference_ac_mic_input_terminal_descriptor)); ptr++; + zassert_mem_equal(reference_ac_mic_feature_unit_descriptor, *ptr, + ARRAY_SIZE(reference_ac_mic_feature_unit_descriptor)); + ptr++; zassert_mem_equal(reference_ac_mic_output_terminal_descriptor, *ptr, ARRAY_SIZE(reference_ac_mic_output_terminal_descriptor)); ptr++;