Skip to content

Commit 600010c

Browse files
Thalleykartben
authored andcommitted
Bluetooth: BAP: Switch to new USB stack for BAP shell
Modify the BAP shell to use the new USB stack, as the current one used is now deprecated. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 287d3a1 commit 600010c

File tree

11 files changed

+388
-74
lines changed

11 files changed

+388
-74
lines changed

subsys/bluetooth/audio/Kconfig.bap

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Bluetooth Audio - Basic Audio Profile configuration options
22
#
33
# Copyright (c) 2020 Intel Corporation
4-
# Copyright (c) 2022-2023 Nordic Semiconductor ASA
4+
# Copyright (c) 2022-2025 Nordic Semiconductor ASA
55

66
# SPDX-License-Identifier: Apache-2.0
77
#
@@ -283,5 +283,51 @@ config BT_BAP_DEBUG_STREAM_SEQ_NUM
283283
config BT_BAP_BASE
284284
def_bool BT_BAP_BROADCAST_SINK || BT_BAP_BROADCAST_ASSISTANT || BT_BAP_SCAN_DELEGATOR
285285

286+
# We use BT_BAP_STREAM as a common ground for audio, as that is set whenever
287+
# any audio stream functionality is enabled.
288+
if LIBLC3 && USBD_AUDIO2_CLASS && BT_SHELL && BT_BAP_STREAM
289+
config BT_BAP_SHELL_USB_PRODUCT
290+
string "USB device sample product string"
291+
default "Zephyr Audio Shell"
292+
help
293+
USB device sample product string.
294+
295+
config BT_BAP_SHELL_USB_VID
296+
hex "USB device sample Vendor ID"
297+
default 0x2fe3
298+
help
299+
USB device sample Vendor ID. Defaults to the Zephyr Project.
300+
301+
config BT_BAP_SHELL_USB_PID
302+
hex "USB device sample Product ID"
303+
default 0x0001
304+
help
305+
USB device sample Product ID.
306+
307+
config BT_BAP_SHELL_USB_SELF_POWERED
308+
bool "USB device sample Self-powered attribute"
309+
default y
310+
help
311+
Set the Self-powered attribute in the sample configuration.
312+
313+
config BT_BAP_SHELL_USB_REMOTE_WAKEUP
314+
bool "USB device sample Remote Wakeup attribute"
315+
help
316+
Set the Remote Wakeup attribute in the sample configuration.
317+
318+
config BT_BAP_SHELL_USB_MAX_POWER
319+
int "USB device sample bMaxPower value"
320+
default 125
321+
range 0 250
322+
help
323+
bMaxPower value in the sample configuration in 2 mA units.
324+
325+
config BT_BAP_SHELL_USB_20_EXTENSION_DESC
326+
bool "Use default USB 2.0 Extension Descriptor"
327+
depends on USBD_BOS_SUPPORT
328+
help
329+
Set bcdUSB value to 0201 and use default USB 2.0 Extension Descriptor.
330+
endif # LIBLC3 && USBD_AUDIO2_CLASS && BT_SHELL && BT_BAP_STREAM
331+
286332
rsource "Kconfig.pacs"
287333
rsource "Kconfig.ascs"

subsys/bluetooth/audio/shell/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ zephyr_library_sources_ifdef(
8989
CONFIG_BT_BAP_STREAM
9090
bap.c
9191
)
92-
if (CONFIG_LIBLC3 AND CONFIG_USB_DEVICE_AUDIO)
92+
if (CONFIG_LIBLC3 AND CONFIG_USBD_AUDIO2_CLASS)
9393
zephyr_library_sources(bap_usb.c)
9494
endif()
9595
zephyr_library_sources_ifdef(

subsys/bluetooth/audio/shell/audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@ struct shell_stream {
115115
size_t lc3_sdu_cnt;
116116
lc3_encoder_mem_48k_t lc3_encoder_mem;
117117
lc3_encoder_t lc3_encoder;
118-
#if defined(CONFIG_USB_DEVICE_AUDIO)
118+
#if defined(CONFIG_USBD_AUDIO2_CLASS)
119119
/* Indicates where to read left USB data in the ring buffer */
120120
size_t left_read_idx;
121121
/* Indicates where to read right USB data in the ring buffer */
122122
size_t right_read_idx;
123123
size_t right_ring_buf_fail_cnt;
124-
#endif /* CONFIG_USB_DEVICE_AUDIO */
124+
#endif /* CONFIG_USBD_AUDIO2_CLASS */
125125
#endif /* CONFIG_LIBLC3 */
126126
} tx;
127127
#endif /* CONFIG_BT_AUDIO_TX */

subsys/bluetooth/audio/shell/bap.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#define IS_BAP_INITIATOR \
5858
(IS_ENABLED(CONFIG_BT_BAP_BROADCAST_SOURCE) || IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT))
5959

60-
#define GENERATE_SINE_SUPPORTED (IS_ENABLED(CONFIG_LIBLC3) && !IS_ENABLED(CONFIG_USB_DEVICE_AUDIO))
60+
#define GENERATE_SINE_SUPPORTED (IS_ENABLED(CONFIG_LIBLC3) && !IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS))
6161

6262
#if defined(CONFIG_BT_BAP_UNICAST)
6363

@@ -318,7 +318,7 @@ static int init_lc3_encoder(struct shell_stream *sh_stream)
318318
return -EINVAL;
319319
}
320320

321-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO)) {
321+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
322322
const size_t frame_size = bap_usb_get_frame_size(sh_stream);
323323

324324
if (frame_size > sizeof(lc3_tx_buf)) {
@@ -337,7 +337,7 @@ static int init_lc3_encoder(struct shell_stream *sh_stream)
337337

338338
sh_stream->tx.lc3_encoder =
339339
lc3_setup_encoder(sh_stream->lc3_frame_duration_us, sh_stream->lc3_freq_hz,
340-
IS_ENABLED(CONFIG_USB_DEVICE_AUDIO) ? USB_SAMPLE_RATE : 0,
340+
IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS) ? USB_SAMPLE_RATE : 0,
341341
&sh_stream->tx.lc3_encoder_mem);
342342
if (sh_stream->tx.lc3_encoder == NULL) {
343343
bt_shell_error("Failed to setup LC3 encoder - wrong parameters?\n");
@@ -375,7 +375,7 @@ static bool encode_frame(struct shell_stream *sh_stream, uint8_t index, size_t f
375375
const uint16_t octets_per_frame = sh_stream->lc3_octets_per_frame;
376376
int lc3_ret;
377377

378-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO)) {
378+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
379379
enum bt_audio_location chan_alloc;
380380
int err;
381381

@@ -432,7 +432,7 @@ static size_t encode_frame_block(struct shell_stream *sh_stream, size_t frame_cn
432432

433433
static void do_lc3_encode(struct shell_stream *sh_stream, struct net_buf *out_buf)
434434
{
435-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO) && !bap_usb_can_get_full_sdu(sh_stream)) {
435+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS) && !bap_usb_can_get_full_sdu(sh_stream)) {
436436
/* No op - Will just send empty SDU */
437437
} else {
438438
size_t frame_cnt = 0U;
@@ -2633,7 +2633,7 @@ static int init_lc3_decoder(struct shell_stream *sh_stream)
26332633
/* Create the decoder instance. This shall complete before stream_started() is called. */
26342634
sh_stream->rx.lc3_decoder =
26352635
lc3_setup_decoder(sh_stream->lc3_frame_duration_us, sh_stream->lc3_freq_hz,
2636-
IS_ENABLED(CONFIG_USB_DEVICE_AUDIO) ? USB_SAMPLE_RATE : 0,
2636+
IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS) ? USB_SAMPLE_RATE : 0,
26372637
&sh_stream->rx.lc3_decoder_mem);
26382638
if (sh_stream->rx.lc3_decoder == NULL) {
26392639
bt_shell_error("Failed to setup LC3 decoder - wrong parameters?\n");
@@ -2694,7 +2694,7 @@ static size_t decode_frame_block(struct lc3_data *data, size_t frame_cnt)
26942694
if (decode_frame(data, frame_cnt + decoded_frames)) {
26952695
decoded_frames++;
26962696

2697-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO)) {
2697+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
26982698
enum bt_audio_location chan_alloc;
26992699
int err;
27002700

@@ -2722,7 +2722,7 @@ static size_t decode_frame_block(struct lc3_data *data, size_t frame_cnt)
27222722
/* If decoding failed, we clear the data to USB as it would contain
27232723
* invalid data
27242724
*/
2725-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO)) {
2725+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
27262726
bap_usb_clear_frames_to_usb();
27272727
}
27282728

@@ -3008,7 +3008,7 @@ static void stream_started_cb(struct bt_bap_stream *bap_stream)
30083008
return;
30093009
}
30103010

3011-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO)) {
3011+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
30123012
/* Always mark as active when using USB */
30133013
sh_stream->tx.active = true;
30143014
}
@@ -3029,7 +3029,7 @@ static void stream_started_cb(struct bt_bap_stream *bap_stream)
30293029

30303030
sh_stream->rx.decoded_cnt = 0U;
30313031

3032-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO)) {
3032+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
30333033
if ((sh_stream->lc3_chan_allocation &
30343034
BT_AUDIO_LOCATION_FRONT_LEFT) != 0) {
30353035
if (usb_left_stream == NULL) {
@@ -3148,7 +3148,7 @@ static void clear_stream_data(struct shell_stream *sh_stream)
31483148
sh_stream->is_rx = sh_stream->is_tx = false;
31493149

31503150
#if defined(CONFIG_LIBLC3)
3151-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO)) {
3151+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)) {
31523152
update_usb_streams(sh_stream);
31533153
}
31543154
#endif /* CONFIG_LIBLC3 */
@@ -3931,7 +3931,7 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[])
39313931

39323932
#endif /* CONFIG_BT_AUDIO_TX */
39333933

3934-
if (IS_ENABLED(CONFIG_USB_DEVICE_AUDIO) &&
3934+
if (IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS) &&
39353935
(IS_ENABLED(CONFIG_BT_AUDIO_RX) || IS_ENABLED(CONFIG_BT_AUDIO_TX))) {
39363936
err = bap_usb_init();
39373937
__ASSERT(err == 0, "Failed to enable USB: %d", err);

0 commit comments

Comments
 (0)