Skip to content

Commit 7c7383c

Browse files
tmon-nordicdleach02
authored andcommitted
tests: usb: uac2: Test Feature Unit descriptor
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ń <[email protected]>
1 parent 1dde8e2 commit 7c7383c

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

tests/subsys/usb/uac2/app.overlay

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,19 @@
2929
front-right;
3030
};
3131

32+
out_feature_unit: out_feature_unit {
33+
compatible = "zephyr,uac2-feature-unit";
34+
data-source = <&out_terminal>;
35+
mute-control = "host-programmable";
36+
automatic-gain-control =
37+
"host-programmable" /* Primary */,
38+
"host-programmable" /* Channel 1 */,
39+
"host-programmable" /* Channel 2 */;
40+
};
41+
3242
headphones_output: headphones {
3343
compatible = "zephyr,uac2-output-terminal";
34-
data-source = <&out_terminal>;
44+
data-source = <&out_feature_unit>;
3545
clock-source = <&uac_aclk>;
3646
terminal-type = <BIDIRECTIONAL_TERMINAL_HEADSET>;
3747
assoc-terminal = <&mic_input>;
@@ -50,9 +60,18 @@
5060
front-left;
5161
};
5262

63+
in_feature_unit: in_feature_unit {
64+
compatible = "zephyr,uac2-feature-unit";
65+
data-source = <&mic_input>;
66+
mute-control = "host-programmable";
67+
automatic-gain-control =
68+
"not-present" /* Primary */,
69+
"host-programmable" /* Channel 1 */;
70+
};
71+
5372
in_terminal: in_terminal {
5473
compatible = "zephyr,uac2-output-terminal";
55-
data-source = <&mic_input>;
74+
data-source = <&in_feature_unit>;
5675
clock-source = <&uac_aclk>;
5776
terminal-type = <USB_TERMINAL_STREAMING>;
5877
};

tests/subsys/usb/uac2/src/uac2_desc.c

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static const uint8_t reference_ac_interface_descriptor[] = {
1818
0x01, /* bDescriptorSubtype = HEADER */
1919
0x00, 0x02, /* bcdADC = 02.00 */
2020
0x04, /* bCategory = HEADSET */
21-
0x4b, 0x00, /* wTotalLength = 0x4b = 75 */
21+
0x6b, 0x00, /* wTotalLength = 0x6b = 107 */
2222
0x00, /* bmControls = Latency Control not present */
2323
};
2424

@@ -50,15 +50,28 @@ static const uint8_t reference_ac_hp_input_terminal_descriptor[] = {
5050
0x00, /* iTerminal = 0 (no string descriptor) */
5151
};
5252

53+
static const uint8_t reference_ac_hp_feature_unit_descriptor[] = {
54+
/* 4.7.2.8 Feature Unit Descriptor */
55+
0x12, /* bLength = 18 */
56+
0x24, /* bDescriptorType = CS_INTERFACE */
57+
0x06, /* bDescriptorSubtype = FEATURE_UNIT */
58+
0x03, /* bUnitID = 3 */
59+
0x02, /* bSourceID = 2 (streaming input) */
60+
0x03, 0x30, 0x00, 0x00, /* bmaControls(0): Mute and Auto Gain */
61+
0x00, 0x30, 0x00, 0x00, /* bmaControls(1): Auto Gain */
62+
0x00, 0x30, 0x00, 0x00, /* bmaControls(2): Auto Gain */
63+
0x00, /* iFeature = 0 (no string descriptor)*/
64+
};
65+
5366
static const uint8_t reference_ac_hp_output_terminal_descriptor[] = {
5467
/* 4.7.2.5 Output Terminal Descriptor */
5568
0x0c, /* bLength = 12 */
5669
0x24, /* bDescriptorType = CS_INTERFACE */
5770
0x03, /* bDescriptorSubtype = OUTPUT_TERMINAL */
58-
0x03, /* bTerminalID = 3 */
71+
0x04, /* bTerminalID = 4 */
5972
0x02, 0x04, /* wTerminalType = 0x0402 (Headset) */
60-
0x04, /* bAssocTerminal = 4 (headset input) */
61-
0x02, /* bSourceID = 2 (streaming input) */
73+
0x05, /* bAssocTerminal = 5 (headset input) */
74+
0x03, /* bSourceID = 3 (headphones feature unit) */
6275
0x01, /* bCSourceID = 1 (main clock) */
6376
0x00, 0x00, /* bmControls = none present */
6477
0x00, /* iTerminal = 0 (no string descriptor) */
@@ -69,9 +82,9 @@ static const uint8_t reference_ac_mic_input_terminal_descriptor[] = {
6982
0x11, /* bLength = 17 */
7083
0x24, /* bDescriptorType = CS_INTERFACE */
7184
0x02, /* bDescriptorSubtype = INPUT_TERMINAL */
72-
0x04, /* bTerminalID = 4 */
85+
0x05, /* bTerminalID = 5 */
7386
0x02, 0x04, /* wTerminalType = 0x0402 (Headset) */
74-
0x03, /* bAssocTerminal = 3 (headset output) */
87+
0x04, /* bAssocTerminal = 4 (headset output) */
7588
0x01, /* bCSourceID = 1 (main clock) */
7689
0x01, /* bNrChannels = 1 */
7790
0x01, 0x00, 0x00, 0x00, /* bmChannelConfig = Front Left */
@@ -80,15 +93,27 @@ static const uint8_t reference_ac_mic_input_terminal_descriptor[] = {
8093
0x00, /* iTerminal = 0 (no string descriptor) */
8194
};
8295

96+
static const uint8_t reference_ac_mic_feature_unit_descriptor[] = {
97+
/* 4.7.2.8 Feature Unit Descriptor */
98+
0x0e, /* bLength = 14 */
99+
0x24, /* bDescriptorType = CS_INTERFACE */
100+
0x06, /* bDescriptorSubtype = FEATURE_UNIT */
101+
0x06, /* bUnitID = 6 */
102+
0x05, /* bSourceID = 5 (headset input) */
103+
0x03, 0x00, 0x00, 0x00, /* bmaControls(0): Mute */
104+
0x00, 0x30, 0x00, 0x00, /* bmaControls(1): Auto Gain */
105+
0x00, /* iFeature = 0 (no string descriptor)*/
106+
};
107+
83108
static const uint8_t reference_ac_mic_output_terminal_descriptor[] = {
84109
/* 4.7.2.5 Output Terminal Descriptor */
85110
0x0c, /* bLength = 12 */
86111
0x24, /* bDescriptorType = CS_INTERFACE */
87112
0x03, /* bDescriptorSubtype = OUTPUT_TERMINAL */
88-
0x05, /* bTerminalID = 5 */
113+
0x07, /* bTerminalID = 7 */
89114
0x01, 0x01, /* wTerminalType = 0x0101 (USB streaming) */
90115
0x00, /* bAssocTerminal = 0 (not associated) */
91-
0x04, /* bSourceID = 4 (headset input) */
116+
0x06, /* bSourceID = 6 (mic feature unit) */
92117
0x01, /* bCSourceID = 1 (main clock) */
93118
0x00, 0x00, /* bmControls = none present */
94119
0x00, /* iTerminal = 0 (no string descriptor) */
@@ -100,7 +125,7 @@ static const uint8_t reference_as_in_cs_general_descriptor[] = {
100125
0x10, /* bLength = 16 */
101126
0x24, /* bDescriptorType = CS_INTERFACE */
102127
0x01, /* bDescriptorSubtype = AS_GENERAL */
103-
0x05, /* bTerminalLink = 5 (USB streaming output) */
128+
0x07, /* bTerminalLink = 7 (USB streaming output) */
104129
0x00, /* bmControls = non present */
105130
0x01, /* bFormatType = 1 */
106131
0x01, 0x00, 0x00, 0x00, /* bmFormats = PCM */
@@ -308,12 +333,18 @@ static void test_uac2_descriptors(const struct usb_desc_header **descriptors,
308333
zassert_mem_equal(reference_ac_hp_input_terminal_descriptor, *ptr,
309334
ARRAY_SIZE(reference_ac_hp_input_terminal_descriptor));
310335
ptr++;
336+
zassert_mem_equal(reference_ac_hp_feature_unit_descriptor, *ptr,
337+
ARRAY_SIZE(reference_ac_hp_feature_unit_descriptor));
338+
ptr++;
311339
zassert_mem_equal(reference_ac_hp_output_terminal_descriptor, *ptr,
312340
ARRAY_SIZE(reference_ac_hp_output_terminal_descriptor));
313341
ptr++;
314342
zassert_mem_equal(reference_ac_mic_input_terminal_descriptor, *ptr,
315343
ARRAY_SIZE(reference_ac_mic_input_terminal_descriptor));
316344
ptr++;
345+
zassert_mem_equal(reference_ac_mic_feature_unit_descriptor, *ptr,
346+
ARRAY_SIZE(reference_ac_mic_feature_unit_descriptor));
347+
ptr++;
317348
zassert_mem_equal(reference_ac_mic_output_terminal_descriptor, *ptr,
318349
ARRAY_SIZE(reference_ac_mic_output_terminal_descriptor));
319350
ptr++;

0 commit comments

Comments
 (0)