Skip to content
Closed
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 samples/bluetooth/a2dp_source/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.13.1)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(a2dp_source)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources})

zephyr_library_include_directories(${ZEPHYR_BASE}/samples/bluetooth)
40 changes: 40 additions & 0 deletions samples/bluetooth/a2dp_source/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _bt_a2dp_source:

Bluetooth: A2DP
####################

Overview
********

Application demonstrating usage of the A2dp Profile APIs.

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

Check :ref:`bluetooth samples section <bluetooth-samples>` for details.

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

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

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

When building targeting mimxrt1060_evk board with the murata 1xk Controller.

Building for an mimxrt1060_evk + murata 1xk
-------------------------------------------

.. zephyr-app-commands::
:zephyr-app: samples/bluetooth/a2dp_source/
:board: mimxrt1060_evk
:goals: build

Building for the sample
-----------------------

1. input `bt discover` to discover BT devices.
2. input `bt connect <index>` to connect the found BT device, the <index> is the result of step 1.
3. `bt disconnect` can be used to disconnect connection.
17 changes: 17 additions & 0 deletions samples/bluetooth/a2dp_source/boards/mimxrt1060_evk.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright 2023 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

/ {
chosen {
zephyr,bt-uart = &lpuart3;
};
};

&lpuart3 {
status = "okay";
current-speed = <3000000>;
hw-flow-control;
};
15 changes: 15 additions & 0 deletions samples/bluetooth/a2dp_source/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CONFIG_BT=y
CONFIG_BT_L2CAP_TX_MTU=1000
CONFIG_BT_BREDR=y
CONFIG_BT_AVDTP=y
CONFIG_BT_A2DP=y
CONFIG_BT_A2DP_SOURCE=y
CONFIG_LIBSBC_ENCODER=y
CONFIG_BT_DEVICE_NAME="a2dp-source-sample"
CONFIG_HEAP_MEM_POOL_SIZE=4096
CONFIG_SHELL=y
CONFIG_SHELL_HELP=y
CONFIG_SHELL_MINIMAL=y
CONFIG_SHELL_BACKEND_SERIAL=y
CONFIG_BT_BUF_EVT_RX_SIZE=255
CONFIG_BT_BUF_EVT_RX_COUNT=12
7 changes: 7 additions & 0 deletions samples/bluetooth/a2dp_source/sample.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sample:
name: Bluetooth A2dp Source
tests:
sample.bluetooth.a2dp_source:
harness: bluetooth
platform_allow: mimxrt1060_evk
tags: bluetooth
136 changes: 136 additions & 0 deletions samples/bluetooth/a2dp_source/src/a2dp_media_48KHz_1ksin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright (c) 2021 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
static const uint8_t beethoven[] = {
0x0, 0x0, 0x0, 0x0, 0xb5, 0x10, 0xb5, 0x10, 0x21, 0x21, 0x21, 0x21, 0xfb, 0x30, 0xfb, 0x30,
0xff, 0x3f, 0xff, 0x3f, 0xeb, 0x4d, 0xeb, 0x4d, 0x82, 0x5a, 0x82, 0x5a, 0x8c, 0x65, 0x8c, 0x65,
0xd9, 0x6e, 0xd9, 0x6e, 0x41, 0x76, 0x41, 0x76, 0xa2, 0x7b, 0xa2, 0x7b, 0xe7, 0x7e, 0xe7, 0x7e,
0xff, 0x7f, 0xff, 0x7f, 0xe7, 0x7e, 0xe7, 0x7e, 0xa2, 0x7b, 0xa2, 0x7b, 0x41, 0x76, 0x41, 0x76,
0xd9, 0x6e, 0x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0x3f, 0xeb, 0x4d, 0xeb, 0x4d, 0x82, 0x5a, 0x82, 0x5a, 0x8c, 0x65, 0x8c, 0x65,
0xd9, 0x6e, 0xd9, 0x6e, 0x41, 0x76, 0x41, 0x76, 0xa2, 0x7b, 0xa2, 0x7b, 0xe7, 0x7e, 0xe7, 0x7e,
0xff, 0x7f, 0xff, 0x7f, 0xe7, 0x7e, 0xe7, 0x7e, 0xa2, 0x7b, 0xa2, 0x7b, 0x41, 0x76, 0x41, 0x76,
0xd9, 0x6e, 0xd9, 0x6e, 0x8c, 0x65, 0x8c, 0x65, 0x82, 0x5a, 0x82, 0x5a, 0xeb, 0x4d, 0xeb, 0x4d,
0xff, 0x3f, 0xff, 0x3f, 0xfb, 0x30, 0xfb, 0x30, 0x21, 0x21, 0x21, 0x21, 0xb5, 0x10, 0xb5, 0x10,
0x0, 0x0, 0x0, 0x0, 0x4b, 0xef, 0x4b, 0xef, 0xdf, 0xde, 0xdf, 0xde, 0x5, 0xcf, 0x5, 0xcf,
0x0, 0xc0, 0x0, 0xc0, 0x15, 0xb2, 0x15, 0xb2, 0x7e, 0xa5, 0x7e, 0xa5, 0x74, 0x9a, 0x74, 0x9a,
0x27, 0x91, 0x27, 0x91, 0xbf, 0x89, 0xbf, 0x89, 0x5e, 0x84, 0x5e, 0x84, 0x19, 0x81, 0x19, 0x81,
0x1, 0x80, 0x1, 0x80, 0x19, 0x81, 0x19, 0x81, 0x5e, 0x84, 0x5e, 0x84, 0xbf, 0x89, 0xbf, 0x89,
0x27, 0x91, 0x27, 0x91, 0x74, 0x9a, 0x74, 0x9a, 0x7e, 0xa5, 0x7e, 0xa5, 0x15, 0xb2, 0x15, 0xb2,
0x0, 0xc0, 0x0, 0xc0, 0x5, 0xcf, 0x5, 0xcf, 0xdf, 0xde, 0xdf, 0xde, 0x4b, 0xef, 0x4b, 0xef,
};
132 changes: 132 additions & 0 deletions samples/bluetooth/a2dp_source/src/app_connect.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright 2020 - 2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <zephyr/sys/printk.h>
#include <zephyr/sys/byteorder.h>
#include <zephyr/kernel.h>
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/l2cap.h>
#include <zephyr/bluetooth/a2dp.h>
#include "app_connect.h"

extern void app_sdp_discover_a2dp_sink(void);
static void connected(struct bt_conn *conn, uint8_t err);
static void disconnected(struct bt_conn *conn, uint8_t reason);
static void security_changed(struct bt_conn *conn, bt_security_t level,
enum bt_security_err err);

struct bt_conn *default_conn;
bt_addr_t default_peer_addr;
static uint8_t default_connect_initialized;

static struct bt_conn_cb conn_callbacks = {
.connected = connected,
.disconnected = disconnected,
.security_changed = security_changed,
};
extern struct bt_a2dp *default_a2dp;
static void connected(struct bt_conn *conn, uint8_t err)
{
if (err) {
if (default_conn != NULL) {
bt_conn_unref(default_conn);
default_conn = NULL;
}
printk("Connection failed (err 0x%02x)\n", err);
} else {
if (1U == default_connect_initialized) {
struct bt_conn_info info;

default_connect_initialized = 0U;
bt_conn_get_info(conn, &info);
if (info.type == BT_CONN_TYPE_LE) {
return;
}

default_conn = bt_conn_ref(conn);
/*
* Do an SDP Query on Successful ACL connection complete with the
* required device
*/
if (0 == memcmp(info.br.dst, &default_peer_addr, 6U)) {
app_sdp_discover_a2dp_sink();
}
printk("Connected\n");
}
}
}

static void disconnected(struct bt_conn *conn, uint8_t reason)
{
printk("Disconnected (reason 0x%02x)\n", reason);

if (default_conn != conn) {
return;
}

if (default_conn) {
bt_conn_unref(default_conn);
default_conn = NULL;
} else {
return;
}
}

static void security_changed(struct bt_conn *conn, bt_security_t level,
enum bt_security_err err)
{
char addr[BT_ADDR_LE_STR_LEN];

bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));

if (!err) {
printk("Security changed: %s level %u\n", addr, level);
} else {
if (err == BT_SECURITY_ERR_PIN_OR_KEY_MISSING) {
printk("\n");

printk("___________________________________________________________\n");
printk("The peer device seems to have lost the bonding information.\n");
printk("Kindly delete the bonding information of the peer from the\n");
printk("and try again.\n\n");

printk("\n");
}
printk("Security failed: %s level %u err %d\n", addr, level, err);
}
}

void app_connect(uint8_t *addr)
{
default_connect_initialized = 1U;
memcpy(&default_peer_addr, addr, 6U);
default_conn = bt_conn_create_br(&default_peer_addr, BT_BR_CONN_PARAM_DEFAULT);
if (!default_conn) {
default_connect_initialized = 0U;
printk("Connection failed\r\n");
} else {
/* unref connection obj in advance as app user */
bt_conn_unref(default_conn);
printk("Connection pending\r\n");
}
}

void app_disconnect(void)
{
if (bt_conn_disconnect(default_conn, 0x13U)) {
printk("Disconnection failed\r\n");
}
}

void app_connect_init(void)
{
bt_conn_cb_register(&conn_callbacks);
}
27 changes: 27 additions & 0 deletions samples/bluetooth/a2dp_source/src/app_connect.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2020 - 2021 NXP
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __APP_CONNECT_H__
#define __APP_CONNECT_H__

/*******************************************************************************
* Definitions
******************************************************************************/

extern struct bt_conn *default_conn;
extern bt_addr_t default_peer_addr;

/*******************************************************************************
* API
******************************************************************************/

void app_connect_init(void);

void app_connect(uint8_t *addr);

void app_disconnect(void);

#endif /* __APP_CONNECT_H__ */
Loading