Skip to content

Commit 62d7ffa

Browse files
committed
USBAudio: handle not being the first plugged interface
1 parent 1741f72 commit 62d7ffa

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

libraries/USBAudio/USBAudio.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
using namespace arduino;
2828

29+
#warning "USBAudio library is EXTREMELY EXPERIMENTAL, expect crashes"
30+
2931
#define SAMPLE_SIZE 2
3032
#define XFER_FREQUENCY_HZ 1000
3133
#define WRITE_READY_UNBLOCK (1 << 0)
@@ -639,7 +641,7 @@ void USBAudio::_build_configuration_desc()
639641
// Interface 0, Alternate Setting 0, Audio Control
640642
INTERFACE_DESCRIPTOR_LENGTH, // bLength
641643
INTERFACE_DESCRIPTOR, // bDescriptorType
642-
0x00, // bInterfaceNumber
644+
uint8_t(pluggedInterface), // bInterfaceNumber
643645
0x00, // bAlternateSetting
644646
0x00, // bNumEndpoints
645647
AUDIO_CLASS, // bInterfaceClass
@@ -657,8 +659,8 @@ void USBAudio::_build_configuration_desc()
657659
LSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength
658660
MSB(TOTAL_CONTROL_INTF_LENGTH), // wTotalLength
659661
0x02, // bInCollection
660-
0x01, // baInterfaceNr
661-
0x02, // baInterfaceNr
662+
uint8_t(pluggedInterface+1), // baInterfaceNr
663+
uint8_t(pluggedInterface+2), // baInterfaceNr
662664

663665
// Audio Input Terminal (Speaker)
664666
INPUT_TERMINAL_DESCRIPTOR_LENGTH, // bLength
@@ -731,7 +733,7 @@ void USBAudio::_build_configuration_desc()
731733
// Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith
732734
INTERFACE_DESCRIPTOR_LENGTH, // bLength
733735
INTERFACE_DESCRIPTOR, // bDescriptorType
734-
0x01, // bInterfaceNumber
736+
uint8_t(pluggedInterface+1), // bInterfaceNumber
735737
0x00, // bAlternateSetting
736738
0x00, // bNumEndpoints
737739
AUDIO_CLASS, // bInterfaceClass
@@ -742,7 +744,7 @@ void USBAudio::_build_configuration_desc()
742744
// Interface 1, Alternate Setting 1, Audio Streaming - Operational
743745
INTERFACE_DESCRIPTOR_LENGTH, // bLength
744746
INTERFACE_DESCRIPTOR, // bDescriptorType
745-
0x01, // bInterfaceNumber
747+
uint8_t(pluggedInterface+1), // bInterfaceNumber
746748
0x01, // bAlternateSetting
747749
0x01, // bNumEndpoints
748750
AUDIO_CLASS, // bInterfaceClass
@@ -796,7 +798,7 @@ void USBAudio::_build_configuration_desc()
796798
// Interface 1, Alternate Setting 0, Audio Streaming - Zero Bandwith
797799
INTERFACE_DESCRIPTOR_LENGTH, // bLength
798800
INTERFACE_DESCRIPTOR, // bDescriptorType
799-
0x02, // bInterfaceNumber
801+
uint8_t(pluggedInterface+2), // bInterfaceNumber
800802
0x00, // bAlternateSetting
801803
0x00, // bNumEndpoints
802804
AUDIO_CLASS, // bInterfaceClass
@@ -807,7 +809,7 @@ void USBAudio::_build_configuration_desc()
807809
// Interface 1, Alternate Setting 1, Audio Streaming - Operational
808810
INTERFACE_DESCRIPTOR_LENGTH, // bLength
809811
INTERFACE_DESCRIPTOR, // bDescriptorType
810-
0x02, // bInterfaceNumber
812+
uint8_t(pluggedInterface+2), // bInterfaceNumber
811813
0x01, // bAlternateSetting
812814
0x01, // bNumEndpoints
813815
AUDIO_CLASS, // bInterfaceClass

0 commit comments

Comments
 (0)