Skip to content

Commit 7f379fb

Browse files
Thalleykartben
authored andcommitted
samples: Bluetooth: BAP: Broadcast sink use new USB stack
Refactor the USB of the BAP broadcast sink to use the new USB stack. Signed-off-by: Emil Gydesen <[email protected]>
1 parent e420b21 commit 7f379fb

17 files changed

+192
-122
lines changed

samples/bluetooth/bap_broadcast_sink/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

33
cmake_minimum_required(VERSION 3.20.0)
44
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5-
project(bap_unicast_server)
5+
project(bap_unicast_sink)
66

77
target_sources(app PRIVATE
88
src/main.c
99
src/stream_rx.c
1010
)
1111

12-
zephyr_sources_ifdef(CONFIG_LIBLC3 src/lc3.c)
13-
zephyr_sources_ifdef(CONFIG_USB_DEVICE_AUDIO src/usb.c)
12+
target_sources_ifdef(CONFIG_ENABLE_LC3 app PRIVATE src/lc3.c)
1413

15-
zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
14+
if (CONFIG_USE_USB_AUDIO_OUTPUT)
15+
include(${ZEPHYR_BASE}/samples/subsys/usb/common/common.cmake)
16+
target_sources(app PRIVATE src/usb.c)
17+
endif()

samples/bluetooth/bap_broadcast_sink/Kconfig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ config ENABLE_LC3
5555
config USE_USB_AUDIO_OUTPUT
5656
bool "Use USB Audio as output"
5757
depends on ENABLE_LC3
58-
select USB_DEVICE_STACK
59-
select USB_DEVICE_AUDIO
58+
select USB_DEVICE_STACK_NEXT
59+
select USBD_AUDIO2_CLASS
6060
select RING_BUFFER
6161
help
6262
Enables USB audio as output as a USB peripheral. This does not support providing USB
@@ -87,4 +87,9 @@ config INFO_REPORTING_INTERVAL
8787
Determines how often information about received data is logged.
8888
Set to 0 to disable reporting.
8989

90+
# Source common USB sample options used to initialize new experimental USB device stack.
91+
# The scope of these options is limited to USB samples in project tree,
92+
# you cannot use them in your own application.
93+
source "samples/subsys/usb/common/Kconfig.sample_usbd"
94+
9095
source "Kconfig.zephyr"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <dt-bindings/usb/audio.h>
8+
9+
/ {
10+
uac2_microphone: usb_audio2 {
11+
compatible = "zephyr,uac2";
12+
status = "okay";
13+
full-speed;
14+
audio-function = <AUDIO_FUNCTION_MICROPHONE>;
15+
16+
/* Clock supporting 48KHz
17+
*
18+
* Since the incoming audio may be between 8 and 48 KHz, we always upsample to 48KHz
19+
*/
20+
uac_aclk: aclk {
21+
compatible = "zephyr,uac2-clock-source";
22+
clock-type = "internal-programmable";
23+
frequency-control = "read-only";
24+
sampling-frequencies = <48000>;
25+
/* Falsely claim synchronous audio because we
26+
* currently don't calculate feedback value
27+
*/
28+
sof-synchronized;
29+
};
30+
31+
/* The out_terminal supports the incoming Bluetooth LE Audio over ISO
32+
* and treats it as a microphone towards the USB host
33+
*/
34+
out_terminal: out_terminal {
35+
compatible = "zephyr,uac2-input-terminal";
36+
clock-source = <&uac_aclk>;
37+
terminal-type = <INPUT_TERMINAL_MICROPHONE>;
38+
front-left;
39+
front-right;
40+
};
41+
42+
/* USB Audio terminal from USB device to USB host */
43+
in_terminal: in_terminal {
44+
compatible = "zephyr,uac2-output-terminal";
45+
data-source = <&out_terminal>;
46+
clock-source = <&uac_aclk>;
47+
terminal-type = <USB_TERMINAL_STREAMING>;
48+
};
49+
50+
as_iso_in: in_interface {
51+
compatible = "zephyr,uac2-audio-streaming";
52+
linked-terminal = <&in_terminal>;
53+
subslot-size = <2>;
54+
bit-resolution = <16>;
55+
};
56+
};
57+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Use USB Audio as audio sink
22
CONFIG_USE_USB_AUDIO_OUTPUT=y
3-
CONFIG_USB_DEVICE_PRODUCT="USB Broadcast Sink"
3+
CONFIG_SAMPLE_USBD_PRODUCT="USB Broadcast Sink sample"
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
zephyr_udc0: &usbd {
2-
compatible = "nordic,nrf-usbd";
3-
status = "okay";
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
46

5-
hs_0: hs_0 {
6-
compatible = "usb-audio-hs";
7-
mic-feature-mute;
8-
mic-channel-l;
9-
mic-channel-r;
10-
11-
hp-feature-mute;
12-
hp-channel-l;
13-
hp-channel-r;
14-
};
15-
};
7+
#include "../app.overlay"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Use USB Audio as audio sink
2+
CONFIG_USE_USB_AUDIO_OUTPUT=y
3+
CONFIG_SAMPLE_USBD_PRODUCT="USB Broadcast Sink sample"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include "../app.overlay"
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Use USB Audio as audio sink
22
CONFIG_USE_USB_AUDIO_OUTPUT=y
3-
CONFIG_USB_DEVICE_PRODUCT="USB Broadcast Sink"
3+
CONFIG_SAMPLE_USBD_PRODUCT="USB Broadcast Sink sample"
4+
5+
CONFIG_BOARD_SERIAL_BACKEND_CDC_ACM=n
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
zephyr_udc0: &usbd {
2-
compatible = "nordic,nrf-usbd";
3-
status = "okay";
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
46

5-
hs_0: hs_0 {
6-
compatible = "usb-audio-hs";
7-
mic-feature-mute;
8-
mic-channel-l;
9-
mic-channel-r;
10-
11-
hp-feature-mute;
12-
hp-channel-l;
13-
hp-channel-r;
14-
};
15-
};
7+
#include "../app.overlay"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Use USB Audio as audio sink
22
CONFIG_USE_USB_AUDIO_OUTPUT=y
3-
CONFIG_USB_DEVICE_PRODUCT="USB Broadcast Sink"
3+
CONFIG_SAMPLE_USBD_PRODUCT="USB Broadcast Sink sample"

0 commit comments

Comments
 (0)