Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions doc/connectivity/bluetooth/api/a2dp.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _bt_a2dp:

Advanced Audio Distribution Profile (A2DP)
###########################################


API Reference
*************

.. doxygengroup:: bt_a2dp
1 change: 1 addition & 0 deletions doc/connectivity/bluetooth/api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Bluetooth Classic Host and profiles
hfp.rst
rfcomm.rst
sdp.rst
a2dp.rst

Bluetooth LE Audio
==================
Expand Down
12 changes: 12 additions & 0 deletions include/zephyr/bluetooth/classic/a2dp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_
#define ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_

/**
* @file
* @brief Advanced Audio Distribution Profile (A2DP)
* @defgroup bt_a2dp Advanced Audio Distribution Profile (A2DP)
* @ingroup bluetooth
* @{
*/

#include <stdint.h>

#include <zephyr/bluetooth/bluetooth.h>
Expand Down Expand Up @@ -872,4 +880,8 @@ struct net_buf *bt_a2dp_stream_create_pdu(struct net_buf_pool *pool, k_timeout_t
}
#endif

/**
* @}
*/

#endif /* ZEPHYR_INCLUDE_BLUETOOTH_A2DP_H_ */
32 changes: 32 additions & 0 deletions include/zephyr/bluetooth/classic/a2dp_codec_sbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ struct bt_a2dp_codec_sbc_params {
*/
uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get channel mode of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the channel mode.
*/
enum sbc_ch_mode bt_a2dp_sbc_get_channel_mode(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get sample rate of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
Expand All @@ -119,6 +127,30 @@ uint8_t bt_a2dp_sbc_get_channel_num(struct bt_a2dp_codec_sbc_params *sbc_codec);
*/
uint32_t bt_a2dp_sbc_get_sampling_frequency(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get subband num of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the subband num.
*/
uint8_t bt_a2dp_sbc_get_subband_num(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get block length of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the block length.
*/
uint8_t bt_a2dp_sbc_get_block_length(struct bt_a2dp_codec_sbc_params *sbc_codec);

/** @brief get allocation method of a2dp sbc config.
*
* @param sbc_codec The a2dp sbc parameter.
*
* @return the allocation method.
*/
enum sbc_alloc_mthd bt_a2dp_sbc_get_allocation_method(struct bt_a2dp_codec_sbc_params *sbc_codec);

#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 18 additions & 0 deletions samples/bluetooth/classic/a2dp_sink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(a2dp_sink)


if(CONFIG_BT_A2DP_SINK_BOARD_CODEC_ENABLE)
FILE(GLOB app_sources src/*.c)
else()
FILE(GLOB app_sources src/main.c)
endif()
target_sources(app PRIVATE ${app_sources})

zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
if(CONFIG_BT_A2DP_SINK_BOARD_CODEC_ENABLE)
target_include_directories(app PRIVATE src)
endif()
36 changes: 36 additions & 0 deletions samples/bluetooth/classic/a2dp_sink/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Copyright 2025 NXP
#
# SPDX-License-Identifier: Apache-2.0
#

mainmenu "Bluetooth: A2DP Sink"

config BT_A2DP_SINK_BOARD_CODEC_ENABLE
bool "play audio data to board's codec when enabled"

if BT_A2DP_SINK_BOARD_CODEC_ENABLE

config USE_CODEC_CLOCK
bool "I2S BCK is generated by a selected codec device"
help
If selected, the I2S selected peripheral will be configured to consume
(receive) the I2S BCK and WS signals and the codec will be configured
to generate those. If not selected, the I2S peripheral will generate
them and the codec will be expected to consume them.

config A2DP_SBC_PCM_BUFFER_PLAY_COUNT
int "The buffer count that every size is 480*2*2 bytes"
default 50

config A2DP_BOARD_CODEC_PLAY_COUNT
int "The play count of the board codec interface (i2s)"
default 4

config A2DP_BOARD_CODEC_PLAY_THRESHOLD
int "The threshold of pcm buffer when playing data to codec (n%)"
default 20

endif # BT_A2DP_SINK_BOARD_CODEC_ENABLE

source "Kconfig.zephyr"
24 changes: 24 additions & 0 deletions samples/bluetooth/classic/a2dp_sink/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.. zephyr:code-sample:: bluetooth_a2dp_sink
:name: a2dp-sink
:relevant-api: bt_a2dp bluetooth

Use the A2DP APIs.

Overview
********

Application demonstrating usage of the A2DP APIs.

Requirements
************

* BlueZ running on the host, or
* A board with Bluetooth BR/EDR (Classic) support

Building and Running
********************

This sample can be found under :zephyr_file:`samples/bluetooth/classic/a2dp_sink` in
the Zephyr tree.

See :zephyr:code-sample-category:`bluetooth` samples for details.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#select NXP NW612 Chipset
CONFIG_BT_NXP_NW612=y

CONFIG_I2S=y
CONFIG_AUDIO=y
CONFIG_AUDIO_CODEC=y
CONFIG_DMA_TCD_QUEUE_SIZE=4
CONFIG_BT_A2DP_SINK_BOARD_CODEC_ENABLE=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,sram = &ocram1;
};
};

&sai1 {
mclk-output;
podf = <32>;
pll-clocks = <&anatop 0 0 0>,
<&anatop 0 0 30>,
<&anatop 0 0 1>,
<&anatop 0 0 106>,
<&anatop 0 0 1000>;
};
10 changes: 10 additions & 0 deletions samples/bluetooth/classic/a2dp_sink/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CONFIG_BT=y
CONFIG_BT_CLASSIC=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_AVDTP=y
CONFIG_BT_A2DP=y
CONFIG_BT_A2DP_SINK=y
CONFIG_LIBSBC_DECODER=y
CONFIG_BT_DEVICE_NAME="a2dp_sink"
CONFIG_BT_COD=0x200404
CONFIG_BT_BUF_ACL_RX_SIZE=1300
11 changes: 11 additions & 0 deletions samples/bluetooth/classic/a2dp_sink/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sample:
name: Bluetooth A2DP Sink
tests:
sample.bluetooth.a2dp.sink:
harness: bluetooth
platform_allow:
- qemu_cortex_m3
- qemu_x86
tags: bluetooth
integration_platforms:
- qemu_cortex_m3
Loading
Loading