Skip to content

Commit fc51760

Browse files
committed
samples: Bluetooth: CAP: Handover central sample
Add CAP handover central sample that exercises the CAP handover API. It is compatible with the CAP acceptor sample assuming that the CAP acceptor sample is built with both unicast and broadcast support. It will continously switch between unicast and broadcast. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 1a49b41 commit fc51760

File tree

13 files changed

+1858
-0
lines changed

13 files changed

+1858
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
5+
project(cap_handover)
6+
7+
target_sources(app PRIVATE
8+
src/main.c
9+
src/cap_stream_tx.c
10+
)
11+
12+
zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "Bluetooth: Common Audio Profile initiator sample"
5+
6+
config SAMPLE_STATIC_BROADCAST_ID
7+
bool "Use static broadcast ID"
8+
default y
9+
help
10+
Enabling this option will make the application use static broadcast ID, as opposed to a
11+
randomly generated one.
12+
13+
config SAMPLE_BROADCAST_ID
14+
hex "The static broadcast ID to use"
15+
range 0x000000 0xFFFFFF
16+
depends on SAMPLE_STATIC_BROADCAST_ID
17+
default 0x123456
18+
help
19+
This is the 3-octet broadcast ID advertised if static broadcast IDs are enabled.
20+
21+
source "Kconfig.zephyr"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
source "share/sysbuild/Kconfig"
5+
6+
config NET_CORE_BOARD
7+
string
8+
default "nrf5340dk/nrf5340/cpunet" if "$(BOARD)" = "nrf5340dk"
9+
default "nrf5340_audio_dk/nrf5340/cpunet" if "$(BOARD)" = "nrf5340_audio_dk"
10+
default "nrf5340bsim/nrf5340/cpunet" if $(BOARD_TARGET_STRING) = "NRF5340BSIM_NRF5340_CPUAPP"
11+
12+
config NET_CORE_IMAGE_HCI_IPC
13+
bool "HCI IPC image on network core"
14+
default y
15+
depends on NET_CORE_BOARD != ""
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.. zephyr:code-sample:: bluetooth_cap_handover
2+
:name: Common Audio Profile (CAP) Handover
3+
:relevant-api: bluetooth bt_bap bt_cap bt_conn
4+
5+
Connect to a CAP acceptor and perform CAP handover procedures
6+
7+
Overview
8+
********
9+
10+
Application demonstrating the CAP handover functionality.
11+
Starts by scanning for a CAP Acceptor then sets up unicast audio, and then switches between unicast
12+
and broadcast using the CAP handover procedures.
13+
14+
Check the :zephyr:code-sample-category:`bluetooth` samples for general information.
15+
16+
Requirements
17+
************
18+
19+
* BlueZ running on the host, or
20+
* A board with Bluetooth Low Energy 5.2 support
21+
22+
Building and Running
23+
********************
24+
25+
When building targeting an nrf52 series board with the Zephyr Bluetooth Controller,
26+
use ``-DEXTRA_CONF_FILE=overlay-bt_ll_sw_split.conf`` to enable the required ISO
27+
feature support.
28+
29+
Building for an nrf5340dk
30+
-------------------------
31+
32+
You can build both the application core image and an appropriate controller image for the network
33+
core with:
34+
35+
.. zephyr-app-commands::
36+
:zephyr-app: samples/bluetooth/cap_handover/
37+
:board: nrf5340dk/nrf5340/cpuapp
38+
:goals: build
39+
:west-args: --sysbuild
40+
41+
If you prefer to only build the application core image, you can do so by doing instead:
42+
43+
.. zephyr-app-commands::
44+
:zephyr-app: samples/bluetooth/cap_handover/
45+
:board: nrf5340dk/nrf5340/cpuapp
46+
:goals: build
47+
48+
In that case you can pair this application core image with the
49+
:zephyr:code-sample:`bluetooth_hci_ipc` sample
50+
:zephyr_file:`samples/bluetooth/hci_ipc/nrf5340_cpunet_iso-bt_ll_sw_split.conf` configuration.
51+
52+
Building for a simulated nrf5340bsim
53+
------------------------------------
54+
55+
Similarly to how you would for real HW, you can do:
56+
57+
.. zephyr-app-commands::
58+
:zephyr-app: samples/bluetooth/cap_handover/
59+
:board: nrf5340bsim/nrf5340/cpuapp
60+
:goals: build
61+
:west-args: --sysbuild
62+
63+
Note this will produce a Linux executable in :file:`./build/zephyr/zephyr.exe`.
64+
For more information, check :ref:`this board documentation <nrf5340bsim>`.
65+
66+
Building for a simulated nrf52_bsim
67+
-----------------------------------
68+
69+
.. zephyr-app-commands::
70+
:zephyr-app: samples/bluetooth/cap_handover/
71+
:board: nrf52_bsim
72+
:goals: build
73+
:gen-args: -DEXTRA_CONF_FILE=overlay-bt_ll_sw_split.conf
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_BT_BUF_EVT_RX_SIZE=255
2+
CONFIG_BT_BUF_ACL_RX_SIZE=255
3+
CONFIG_BT_BUF_ACL_TX_SIZE=251
4+
CONFIG_BT_BUF_CMD_TX_SIZE=255
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_BT_BUF_EVT_RX_SIZE=255
2+
CONFIG_BT_BUF_ACL_RX_SIZE=255
3+
CONFIG_BT_BUF_ACL_TX_SIZE=251
4+
CONFIG_BT_BUF_CMD_TX_SIZE=255
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Zephyr Bluetooth Controller
2+
CONFIG_BT_LL_SW_SPLIT=y
3+
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y
4+
CONFIG_LTO=y
5+
6+
CONFIG_BT_MAX_CONN=1
7+
CONFIG_BT_BROADCASTER=y
8+
CONFIG_BT_OBSERVER=y
9+
CONFIG_BT_EXT_ADV=y
10+
CONFIG_BT_PER_ADV=y
11+
CONFIG_BT_PER_ADV_SYNC=y
12+
CONFIG_BT_CENTRAL=y
13+
CONFIG_BT_MAX_CONN=1
14+
CONFIG_BT_CTLR_PHY_CODED=y
15+
16+
# Zephyr Controller tested maximum advertising data that can be set in a single HCI command
17+
CONFIG_BT_CTLR_SCAN_DATA_LEN_MAX=191
18+
CONFIG_BT_CTLR_ADV_DATA_LEN_MAX=191
19+
20+
CONFIG_BT_ISO_BROADCASTER=y
21+
CONFIG_BT_ISO_SYNC_RECEIVER=y
22+
CONFIG_BT_ISO_CENTRAL=y
23+
CONFIG_BT_ISO_TX_MTU=310
24+
CONFIG_BT_ISO_RX_MTU=310
25+
CONFIG_BT_ISO_MAX_CHAN=2
26+
27+
CONFIG_BT_CTLR_ADV_ISO_STREAM_COUNT=2
28+
CONFIG_BT_CTLR_CONN_ISO_GROUPS=1
29+
CONFIG_BT_CTLR_CONN_ISO_STREAMS=2
30+
CONFIG_BT_CTLR_CONN_ISO_STREAMS_PER_GROUP=2
31+
32+
# In theory, CONFIG_BT_ISO_TX_BUF_COUNT=1, should be sufficient but this count
33+
# is used in the context of IPC which falls into a "Newton's Cradle" effect
34+
# where probably (CONFIG_BT_CTLR_ISO_TX_BUFFERS - CONFIG_BT_ISO_TX_BUF_COUNT)
35+
# buffers get throttled. Hence, always have the value equal or greater.
36+
CONFIG_BT_ISO_TX_BUF_COUNT=12
37+
CONFIG_BT_ISO_RX_BUF_COUNT=1
38+
39+
# Support the highest SDU size required by any BAP LC3 presets (310) + 8 bytes of HCI ISO Data
40+
# packet overhead (the Packet_Sequence_Number, ISO_SDU_Length, Packet_Status_Flag fields; and
41+
# the optional Time_Stamp field, if supplied)
42+
CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE=318
43+
CONFIG_BT_CTLR_ISO_TX_SDU_LEN_MAX=310
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
CONFIG_LOG=y
2+
CONFIG_ASSERT=y
3+
4+
CONFIG_BT=y
5+
CONFIG_BT_BROADCASTER=y
6+
CONFIG_BT_CENTRAL=y
7+
CONFIG_BT_GATT_CLIENT=y
8+
CONFIG_BT_GATT_AUTO_DISCOVER_CCC=y
9+
CONFIG_BT_GATT_AUTO_UPDATE_MTU=y
10+
CONFIG_BT_GATT_DYNAMIC_DB=y
11+
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
12+
CONFIG_BT_SMP=y
13+
CONFIG_BT_EXT_ADV=y
14+
CONFIG_BT_PER_ADV=y
15+
CONFIG_BT_PER_ADV_SYNC=y
16+
CONFIG_BT_DEVICE_NAME="CAP handover central"
17+
CONFIG_BT_AUDIO=y
18+
19+
# ISO configs
20+
CONFIG_BT_ISO_MAX_CHAN=2
21+
CONFIG_BT_ISO_CENTRAL=y
22+
CONFIG_BT_ISO_BROADCASTER=y
23+
CONFIG_BT_ISO_SYNC_RECEIVER=y
24+
25+
# BAP configs
26+
CONFIG_BT_BAP_BROADCAST_ASSISTANT=y
27+
28+
CONFIG_BT_BAP_UNICAST_CLIENT=y
29+
CONFIG_BT_BAP_UNICAST_CLIENT_GROUP_STREAM_COUNT=2
30+
CONFIG_BT_BAP_UNICAST_CLIENT_ASE_SNK_COUNT=2
31+
32+
CONFIG_BT_BAP_SCAN_DELEGATOR=y
33+
34+
CONFIG_BT_BAP_BROADCAST_SOURCE=y
35+
CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT=1
36+
CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT=1
37+
38+
CONFIG_BT_BAP_BROADCAST_ASSISTANT=y
39+
40+
# CAP configs
41+
CONFIG_BT_CAP_INITIATOR=y
42+
CONFIG_BT_CAP_COMMANDER=y
43+
CONFIG_BT_CAP_HANDOVER=y
44+
45+
# CSIP configs
46+
CONFIG_BT_CSIP_SET_COORDINATOR=y
47+
48+
CONFIG_BT_CAP_ACCEPTOR_LOG_LEVEL_DBG=y
49+
CONFIG_BT_CAP_COMMANDER_LOG_LEVEL_DBG=y
50+
CONFIG_BT_CAP_COMMON_LOG_LEVEL_DBG=y
51+
CONFIG_BT_CAP_HANDOVER_LOG_LEVEL_DBG=y
52+
CONFIG_BT_BAP_BROADCAST_ASSISTANT_LOG_LEVEL_DBG=y
53+
CONFIG_BT_BAP_STREAM_LOG_LEVEL_DBG=y
54+
CONFIG_LOG_FUNC_NAME_PREFIX_ERR=y
55+
CONFIG_LOG_FUNC_NAME_PREFIX_WRN=y
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
sample:
2+
description: Bluetooth Low Energy Common Audio Profile Handover sample
3+
name: Bluetooth Low Energy Common Audio Profile Handover sample
4+
tests:
5+
sample.bluetooth.cap_handover:
6+
harness: bluetooth
7+
platform_allow:
8+
- qemu_cortex_m3
9+
- qemu_x86
10+
- nrf5340dk/nrf5340/cpuapp
11+
- nrf5340bsim/nrf5340/cpuapp
12+
integration_platforms:
13+
- qemu_x86
14+
- nrf5340dk/nrf5340/cpuapp
15+
tags: bluetooth
16+
sysbuild: true
17+
sample.bluetooth.cap_handover.bt_ll_sw_split:
18+
harness: bluetooth
19+
platform_allow:
20+
- nrf52_bsim
21+
- nrf52833dk/nrf52833
22+
- nrf52840dk/nrf52840
23+
- nrf52840dongle/nrf52840
24+
integration_platforms:
25+
- nrf52_bsim
26+
- nrf52833dk/nrf52833
27+
- nrf52840dk/nrf52840
28+
- nrf52840dongle/nrf52840
29+
extra_args: EXTRA_CONF_FILE=overlay-bt_ll_sw_split.conf
30+
tags: bluetooth

0 commit comments

Comments
 (0)