BR/EDR Audio

The purpose of this document is to provide an overview of the BR/EDR audio demo application. The BR/EDR audio project gives a simple example on how to use A2DP and HFP. This project implements SRC and SNK role for A2DP. And for HFP, AG and HF unit are implemented.

Requirements

The sample supports the following development kits:

Hardware Platforms

Board Name

Build Target

RTL87x3E HDK

RTL87x3E EVB

bt_audio_demo_4M_bank0
bt_audio_demo_16M_bank0

RTL87x3D HDK

RTL87x3D EVB

bt_audio_demo_16M_bank0

When built for an xxx_4M_xxx build target, the sample is configured to compile and run with a 4M flash map.

When built for an xxx_16M_xxx build target, the sample is configured to compile and run with a 16M flash map.

To quickly set up the development environment, you can refer to Hardware Development Environment.

The TX and RX PINMUX of console is defined in app_audio_demo_main.c. It is important to note that the pinmuxes need to be wired in reverse, which means that the TX of console should be connected to P3_0, and the RX should be connected to P3_1 in order to establish a connection with the serial port.

#define BT_AUDIO_UART_TX          P3_1
#define BT_AUDIO_UART_RX          P3_0

Configurations

APP configurable functions are defined in app_flags.h.

/* ROLE: 1-DUT1(A2DP SRC or HFP AG), 2-DUT2(A2DP SNK or HFP HF) */
#define BT_AUDIO_DEMO_ROLE  1

#define A2DP_DEMO_SUPPORT  1
#define HFP_DEMO_SUPPORT   1

The user can easily change the value of the macro definition to switch the function.

Building and Downloading

The detailed information about Building and Downloading can be found in Building and Downloading.

This sample can be found under sdk\board\evb\bt_audio_demo in SDK folder structure. Take the project rtl87x3e_bt_audio_demo.uvprojx and target bt_audio_demo_4M_bank0 as an example, to build and run the sample with Keil development environment, follow the steps listed below:

  1. Open rtl87x3e_bt_audio_demo.uvprojx.

  2. Choose the build target bt_audio_demo_4M_bank0.

  3. Building the target.

    After a successful compilation, the APP bin file bt_audio_demo_bank0_MP-v0.0.0.0-xxx.bin will be generated in the directory bin\rtl87x3e\flash_4M_dualbank\bank0.

  4. Download APP bin into EVB board.

Experimental Verification

This section introduces the console commands and test procedure during the experimental process.

BR/EDR Commands

BR/EDR Address Set

Users can use this command to congifure bredr address of local device or remote device which be connected to.

Information

Description

Command

Input command: bredr addr_set local 0x01 0x02 0x03 0x 04 0x 05 0x06

Usage

Set local device bredr address.

Command

Input command: bredr addr_set remote 0x01 0x02 0x03 0x 04 0x 05 0x06

Usage

Set remote device bredr address which be connected to.

BR/EDR Inquiry

The description of inquiry command can be divided into the following information:

Information

Description

Command

Input command: bredr inquiry

Usage

Start general inquiry.

BR/EDR Name Set

The description of bredr name set command can be divided into the following information:

Information

Description

Command

Input command: bredr name_set

Usage

Set local device bredr name.

BR/EDR Device Mode Set

The description of device mode set command can be divided into the following information:

Information

Description

Command

Input command: bredr device_mode_set idle

Command

Input command: bredr device_mode_set discoverable

Command

Input command: bredr device_mode_set connectable

Command

Input command: bredr device_mode_set discoverable_connectable

Usage

Set local device discoverable or undiscoverable and connectable or unconnectable.

A2DP Commands

A2DP Connect

The description of A2DP connect can be divided into the following information:

Information

Description

Command

Input command: a2dp connect

Usage

Connect A2DP with remote device.

The reference API can be found in bt_a2dp_connect_req, and the A2DP connect flow is shown in Figure below.

A2DP Disconnect

The description of A2DP disconnect can be divided into the following information:

Information

Description

Command

Input command: a2dp disconnect

Usage

Disconnect A2DP with remote device.

The reference API can be found in bt_a2dp_disconnect_req, and the A2DP disconnect flow is shown in Figure below.

A2DP Start

The description of A2DP start can be divided into the following information:

Information

Description

Command

Input command: a2dp start

Usage

Start audio streaming.

The reference API can be found in bt_a2dp_stream_start_req, and the A2DP start flow is shown in Figure below.

A2DP Suspend

The description of A2DP suspend can be divided into the following information:

Information

Description

Command

Input command: a2dp suspend

Usage

Suspend audio streaming.

The reference API can be found in bt_a2dp_stream_suspend_req, and the A2DP suspend flow is shown in Figure below.

A2DP Volume Up

The description of A2DP volume up can be divided into the following information:

Information

Description

Command

Input command: a2dp vol+

Usage

Increase A2DP volume.

A2DP Volume Down

The description of A2DP volume down can be divided into the following information:

Information

Description

Command

Input command: a2dp vol-

Usage

Decrease A2DP volume.

The reference API can be found in bt_avrcp_absolute_volume_set, and the A2DP volume control flow is shown in Figure below when absolute volume is supported by both sides.

AVRCP Commands

AVRCP Connect

The description of AVRCP cover art connect can be divided into the following information:

Information

Description

Command

Input command: avrcp cover_art_connect

Usage

Connect AVRCP cover art with remote device.

The reference API can be found in bt_avrcp_cover_art_connect_req, and the AVRCP cover art connect flow is shown in Figure below.

AVRCP Cover Art Get

The description of AVRCP cover art get can be divided into the following information:

Information

Description

Command

Input command: avrcp cover_art_get

Usage

Get cover art of current playing media.

The reference API can be found in bt_avrcp_cover_art_get, and the AVRCP cover art get flow is shown in Figure below.

AVRCP Cover Art Disconnect

The description of AVRCP cover art disconnect can be divided into the following information:

Information

Description

Command

Input command: avrcp cover_art_disconnect

Usage

Disconnect AVRCP cover art.

The reference API can be found in bt_avrcp_cover_art_disconnect_req, and the AVRCP cover art disconnect flow is shown in Figure below.

AVRCP Element Attribute Get

The description of AVRCP element attribute get can be divided into the following information:

Information

Description

Command

Input command: avrcp get_attr [attr_id]

Parameters

Attr ID, refer to T_BT_AVRCP_ELEM_ATTR.

Usage

Get element attribute of current playing media.

The reference API can be found in bt_avrcp_get_element_attr_req, and the AVRCP get element attribute flow is shown in Figure below.

HFP Commands

HFP Connect

The description of HFP connect can be divided into the following information:

Information

Description

Command

Input command: hfp connect

Usage

Connect HFP with remote device.

The reference API can be found in bt_hfp_connect_req, and the HFP connect flow is shown in Figure below.

HFP Disconnect

The description of HFP disconnect can be divided into the following information:

Information

Description

Command

Input command: hfp disconnect

Usage

Disconnect HFP with remote device.

The reference API can be found in bt_hfp_disconnect_req, and the HFP disconnect flow is shown in Figure below.

HFP SCO Connect

The description of HFP SCO connect can be divided into the following information:

Information

Description

Command

Input command: hfp sco_connect

Usage

Connect SCO with remote device.

The reference API can be found in bt_hfp_audio_connect_req, and the HFP SCO connect flow is shown in Figure below.

HFP SCO Disconnect

The description of HFP SCO disconnect can be divided into the following information:

Information

Description

Command

Input command: sco disconnect

Usage

Disconnect SCO with remote device.

The reference API can be found in bt_hfp_audio_disconnect_req, and the HFP SCO disconnect flow is shown in Figure below.

HFP Call Answer

The description of HFP call answer can be divided into the following information:

Information

Description

Command

Input command: hfp call_answer

Usage

Answer HFP incoming call.

The reference API can be found in bt_hfp_call_answer_req, and the HFP call_answer flow is shown in Figure below.

HFP Call Terminate

The description of HFP call terminate can be divided into the following information:

Information

Description

Command

Input command: hfp call_terminate

Usage

Terminate HFP incoming/active call.

The reference API can be found in bt_hfp_call_terminate_req, and the HFP call_terminate flow is shown in Figure below.

Test Procedure

This section describes the testing process and expected test results of BR/EDR Audio Demo.

A2DP Test

Follow the steps below to continue the test procedure.

  1. Modify configuration in app_flags.h for A2DP SRC, then build and download the BR/EDR audio demo application to EVB-1. According to the configuration below, EVB-1 acts as A2DP SRC.

    #define BT_AUDIO_DEMO_ROLE  1
    #define A2DP_DEMO_SUPPORT   1
    
  2. Modify configuration in app_flags.h for A2DP SINK, then build and download the BR/EDR audio demo application to EVB-2. According to the configuration below, EVB-2 acts as A2DP SINK.

    #define BT_AUDIO_DEMO_ROLE  2
    #define A2DP_DEMO_SUPPORT   1
    
  3. The user can input corresponding command referring to A2DP Commands.

    • Input CMD a2dp connect to connect A2DP with remote device.

    Uart Command to Input

    Output of Uart Response

    Description

    a2dp connect

    A2DP Connected!

    Connect A2DP withremote device.

    Uart Command to Input

    Output of Uart Response

    Description

    a2dp start

    A2DP Streaming Started!

    Start audio streaming.

    • Input CMD a2dp suspend to suspend audio streaming.

    Uart Command to Input

    Output of Uart Response

    Description

    a2dp suspend

    A2DP Streaming Suspended!

    Suspend audio streaming.

    • Input CMD a2dp vol+ to increase A2DP volume. If volume is set to maximum already, serial port assistant tool shows: A2DP Volume Max Level: [Level]

    Uart Command to Input

    Output of Uart Response

    Description

    a2dp vol+

    A2DP Volume Level: [Level]

    Increase A2DP volume.

    • Input CMD a2dp vol- to decrease A2DP volume. If volume is set to maximum already, serial port assistant tool shows: A2DP Volume Min Level: [Level]

    Uart Command to Input

    Output of Uart Response

    Description

    a2dp vol-

    A2DP Volume Level: [Level]

    Decrease A2DP volume.

    • Input CMD a2dp disconnect to disconnect A2DP with remote device.

    Uart Command to Input

    Output of Uart Response

    Description

    a2dp disconnect

    A2DP Disconnected!

    Disconnect A2DP with remote device.

AVRCP Test

Prepare one EVB as A2DP SINK, and a phone. Follow the steps below to continue the test procedure.

  1. Modify configuration in app_flags.h for A2DP SINK, then build and download the BR/EDR audio demo application. According to the configuration below, EVB acts as A2DP SINK.

    #define BT_AUDIO_DEMO_ROLE  2
    #define A2DP_DEMO_SUPPORT   1
    
  2. Power on EVB, turn on Bluetooth from phone setting, and pair to bt audio snk.

  3. Start playing music.

  4. Users can input corresponding command referring to AVRCP Commands.

    • Input CMD avrcp cover_art_connect to initiate AVRCP cover art connection.

    Uart Command to Input

    Output of Uart Response

    Description

    avrcp cover_art_connect

    AVRCP Cover Art Connected!

    Connect cover art with remote device.

    • Input CMD avrcp cover_art_get to get cover art of current playing media.

    Uart Command to Input

    Output of Uart Response

    Description

    avrcp cover_art_get

    AVRCP Cover Art Get Success!

    Get cover art of current playing media.

    • Input CMD avrcp get_attr to get element attribute of current playing media.

    Uart Command to Input

    Output of Uart Response

    Description

    avrcp get_attr

    [Attribute]: [Content]

    Get element attribute of current playing media.

    • Input CMD avrcp cover_art_disconnect to disconnect AVRCP cover art.

    Uart Command to Input

    Output of Uart Response

    Description

    avrcp cover_art_disconnect

    AVRCP Cover Art Disconnected!

    Disconnect AVRCP cover art.

HFP Test

To demonstrate the HFP of BR/EDR Audio Demo Application, need to prepare 2 sets of Evolution Boards, EVB-1 and EVB-2. Then follow the steps below to continue the test procedure.

  1. Modify configuration in app_flags.h for HFP AG, then build and download the BR/EDR audio demo application to EVB-1. According to the configuration below, EVB-1 acts as HFP AG.

    #define BT_AUDIO_DEMO_ROLE  1
    #define HFP_DEMO_SUPPORT    1
    
  2. Modify configuration in app_flags.h for HFP HF, then build and download the BR/EDR audio demo application to EVB-2. According to the configuration below, EVB-2 acts as HFP HF.

    #define BT_AUDIO_DEMO_ROLE  2
    #define HFP_DEMO_SUPPORT    1
    
  3. Reset and power on two EVBs.

  4. The user can input corresponding command referring to HFP Commands.

    • Input CMD hfp connect to initiate HFP connection.

    Uart Command to Input

    Output of Uart Response

    Description

    hfp connect

    HFP Connected!

    Connect HFP with remote demo EVB.

    • When HFP is connected, input CMD hfp call_incoming to inform application of a call is incoming.

    Uart Command to Input

    Output of Uart Response

    Description

    hfp call_incoming

    Call incoming!

    Inform application of a call is incoming.

    • When a call is incoming, input CMD hfp call_answer to answer HFP incoming call.

    Uart Command to Input

    Output of Uart Response

    Description

    hfp call_answer

    Call active!

    Answer HFP incoming call.

    • When a call is incoming or active, input CMD hfp call_terminate to terminate HFP incoming/active call.

    Uart Command to Input

    Output of Uart Response

    Description

    hfp call_terminate

    Call active!

    Terminate HFP incoming/active call.

    SCO Disconnected!

    Inform application of SCO disconnection complete.

  5. If another calll process need to be create, more command in HFP Commands can be used.

Code Overview

The main purpose of this chapter is to help APP developers familiarize with the development process related to BR/EDR Audio Demo. This chapter will be introduced according to the following several parts:

Source Code Directory

  • Project directory: sdk\board\evb\bt_audio_demo.

  • Source code directory: sdk\src\sample\bt_audio_demo.

Source files in the sample project are currently categorized into several groups as below.

└── Project: bt_audio_demo
   ├── include             
   └── cmsis                      		includes startup code
	   ├── startup_rtl87x3e.c
	   └── system_rtl87x3.c
   ├── Lib                      		includes all binary symbol files that user application is built on
   └── APP                      		includes the find my user application implementation
	   ├── console_uart.c
	   ├── app_dlps.c 
	   ├── app_io_msg.c
	   ├── app_console_msg.c
	   ├── app_bt_audio_console.c
	   ├── app_bt_audio_link.c 
	   ├── app_bt_audio_main.c
	   ├── app_bt_audio_gap.c
	   ├── app_bt_audio_avrcp.c
	   ├── app_sbc_data.c
	   ├── app_bt_audio_a2dp.c
	   └── app_bt_audio_hfp.c

Initialization

Main function is invoked when the application is powered on or the chip resets and performs the following initialization functions.

int main(void)
{
    board_init();
    driver_init();
    task_init();
    framework_init();
    app_bt_gap_init();
    app_bt_profile_init();
    app_bt_audio_gap_init();
    app_bt_audio_cmd_register();

    os_sched_start();

    return 0;
}

Please refer to app_bt_audio_mian.c for initialization function declaration. More information on Bluetooth Profiles initialization can be found in A2DP_Init of A2DP and HFP_Init of HFP.

Profile Message Callback

APP can register different callback functions to handle different profiles.

void app_bt_audio_a2dp_init(uint8_t role)
{
    ...

    bt_mgr_cback_register(app_bt_audio_a2dp_cback);
}

void app_bt_audio_avrcp_init(void)
{
    ...

    bt_mgr_cback_register(app_bt_audio_avrcp_cback);
}

void app_bt_audio_hfp_init(uint8_t role)
{
    ...

    bt_mgr_cback_register(app_bt_audio_hfp_cback);
}