Skip to content

Commit 5fadaf0

Browse files
author
yeliao
committed
[int][new][bt] A2DP relay
Project: Bluetooth redmine: #5539, REDMINE-5539 ext-redmine: bug|feat#id [Description in detail] Affected branch: [master] Change-Id: Id43175af6275864da555d0d33623ff1125be6cef
1 parent 20b3535 commit 5fadaf0

File tree

11 files changed

+3156
-317
lines changed

11 files changed

+3156
-317
lines changed

Kconfig

Lines changed: 311 additions & 307 deletions
Large diffs are not rendered by default.

include/a2dp_relay.h

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/**
2+
******************************************************************************
3+
* @file a2dp_relay.h
4+
* @author Sifli software development team
5+
* @brief A2DP relay service internal header file.
6+
*
7+
******************************************************************************
8+
*/
9+
/**
10+
* @attention
11+
* Copyright (c) 2025 - 2025, Sifli Technology
12+
*
13+
* All rights reserved.
14+
*
15+
* Redistribution and use in source and binary forms, with or without modification,
16+
* are permitted provided that the following conditions are met:
17+
*
18+
* 1. Redistributions of source code must retain the above copyright notice, this
19+
* list of conditions and the following disclaimer.
20+
*
21+
* 2. Redistributions in binary form, except as embedded into a Sifli integrated circuit
22+
* in a product or a software update for such product, must reproduce the above
23+
* copyright notice, this list of conditions and the following disclaimer in the
24+
* documentation and/or other materials provided with the distribution.
25+
*
26+
* 3. Neither the name of Sifli nor the names of its contributors may be used to endorse
27+
* or promote products derived from this software without specific prior written permission.
28+
*
29+
* 4. This software, with or without modification, must only be used with a
30+
* Sifli integrated circuit.
31+
*
32+
* 5. Any software provided in binary form under this license must not be reverse
33+
* engineered, decompiled, modified and/or disassembled.
34+
*
35+
* THIS SOFTWARE IS PROVIDED BY SIFLI TECHNOLOGY "AS IS" AND ANY EXPRESS
36+
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37+
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
38+
* DISCLAIMED. IN NO EVENT SHALL SIFLI TECHNOLOGY OR CONTRIBUTORS BE
39+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45+
*
46+
*/
47+
48+
49+
#ifndef A2DP_RELAY_H_
50+
#define A2DP_RELAY_H_
51+
52+
#include <rtthread.h>
53+
#include <rtdevice.h>
54+
#include <board.h>
55+
#include <string.h>
56+
#include <stdlib.h>
57+
#include "bf0_sibles.h"
58+
59+
#define A2DP_RELAY_ID 0x26
60+
#define A2DP_RELAY_INVALID_HDL 0xFF
61+
#define RELAY_INTERVAL (20)
62+
63+
#define A2DP_RELAY_SVC_UUID { \
64+
0x73, 0x69, 0x66, 0x6c, \
65+
0x69, 0x5f, 0x72, 0x26, \
66+
0x00, 0x00, 0x00, 0x00, \
67+
0x00, 0x00, 0x00, 0x00 \
68+
}
69+
70+
/* media codecs */
71+
#define CODEC_SBC ((U8)0x00)
72+
#define CODEC_AAC ((U8)0x02)
73+
74+
#define PLAYBACK_GETDATA_EVENT_FLAG (1 << 0)
75+
#define PLAYBACK_START_EVENT_FLAG (1 << 1)
76+
#define PLAYBACK_STOPPING_EVENT_FLAG (1 << 2)
77+
#define PLAYBACK_STOPPED_EVENT_FLAG (1 << 3)
78+
79+
#define DEPLAYBACK_STACK_SIZE 2048
80+
81+
#define A2DP_RELAY_SRC_SEARCH_DURATION (60) // 60s
82+
#define A2DP_RELAY_SRC_SEARCH_INTERVAL (60) // 60ms
83+
#define A2DP_RELAY_SRC_SEARCH_WINDOW (30) // 30ms
84+
85+
typedef enum
86+
{
87+
A2DP_RELAY_START,
88+
A2DP_RELAY_DATA,
89+
A2DP_RELAY_STOP,
90+
A2DP_RELAY_VOL,
91+
} A2DP_RELAY_TYPE_t;
92+
93+
typedef enum
94+
{
95+
A2DP_RELAY_NO_ROLE,
96+
A2DP_RELAY_SINK,
97+
A2DP_RELAY_SRC,
98+
} A2DP_RELAY_ROLE_t;
99+
100+
typedef enum
101+
{
102+
A2DP_RELAY_ERR_NO_ERROR,
103+
A2DP_RELAY_ERR_GENERAL,
104+
A2DP_RELAY_ERR_ALREADY_CONN,
105+
A2DP_RELAY_ERR_UNDER_RUN,
106+
A2DP_RELAY_ERR_INVALID,
107+
} A2DP_RELAY_ERR_t;
108+
109+
typedef enum
110+
{
111+
A2DP_RELAY_EVT_ENABLED,
112+
A2DP_RELAY_EVT_PAIRED,
113+
A2DP_RELAY_EVT_DISABLED,
114+
} A2DP_RELAY_EVT_t;
115+
116+
typedef struct
117+
{
118+
uint8_t blocks;
119+
uint8_t subbands;
120+
uint8_t chnl_mode;
121+
uint8_t alloc_method;
122+
uint8_t bitpool;
123+
uint16_t sample_freq;
124+
} a2dp_relay_sbc_para_t;
125+
126+
typedef struct
127+
{
128+
uint8_t type;
129+
uint16_t len;
130+
uint8_t data[__ARRAY_EMPTY];
131+
} a2dp_relay_data_t;
132+
133+
typedef struct
134+
{
135+
uint8_t blocks;
136+
uint8_t frms_per_payload;
137+
uint8_t subbands;
138+
uint8_t codec;
139+
uint16_t sample_freq;
140+
} a2dp_relay_start_para_t;
141+
142+
typedef uint8_t (*a2dp_relay_callback)(A2DP_RELAY_EVT_t evt, uint8_t *data, uint16_t len);
143+
144+
// A2DP RELAY SRC APIs
145+
void a2dp_relay_src_init(a2dp_relay_callback callback);
146+
uint8_t a2dp_relay_src_enable(void);
147+
uint8_t a2dp_relay_src_disable(void);
148+
uint8_t a2dp_relay_vol_set(uint8_t vol);
149+
uint8_t a2dp_relay_src_channel_set(uint8_t channel);
150+
151+
// A2DP RELAY SINK APIs
152+
void a2dp_relay_sink_init(a2dp_relay_callback callback);
153+
uint8_t a2dp_relay_sink_disable(void);
154+
uint8_t a2dp_relay_sink_enable(void);
155+
156+
#endif // A2DP_RELAY_H_
157+
158+
/************************ (C) COPYRIGHT Sifli Technology *******END OF FILE****/
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
******************************************************************************
3+
* @file bf0_sibles_serial_trans_client.h
4+
* @author Sifli software development team
5+
* @brief Header file - Sibles serial transfer service.
6+
*
7+
******************************************************************************
8+
*/
9+
/*
10+
* @attention
11+
* Copyright (c) 2025 - 2025, Sifli Technology
12+
*
13+
* All rights reserved.
14+
*
15+
* Redistribution and use in source and binary forms, with or without modification,
16+
* are permitted provided that the following conditions are met:
17+
*
18+
* 1. Redistributions of source code must retain the above copyright notice, this
19+
* list of conditions and the following disclaimer.
20+
*
21+
* 2. Redistributions in binary form, except as embedded into a Sifli integrated circuit
22+
* in a product or a software update for such product, must reproduce the above
23+
* copyright notice, this list of conditions and the following disclaimer in the
24+
* documentation and/or other materials provided with the distribution.
25+
*
26+
* 3. Neither the name of Sifli nor the names of its contributors may be used to endorse
27+
* or promote products derived from this software without specific prior written permission.
28+
*
29+
* 4. This software, with or without modification, must only be used with a
30+
* Sifli integrated circuit.
31+
*
32+
* 5. Any software provided in binary form under this license must not be reverse
33+
* engineered, decompiled, modified and/or disassembled.
34+
*
35+
* THIS SOFTWARE IS PROVIDED BY SIFLI TECHNOLOGY "AS IS" AND ANY EXPRESS
36+
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37+
* OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
38+
* DISCLAIMED. IN NO EVENT SHALL SIFLI TECHNOLOGY OR CONTRIBUTORS BE
39+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
40+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41+
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
42+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
43+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45+
*
46+
*/
47+
48+
#ifdef BSP_BLE_SERIAL_TRANSMISSION
49+
50+
#ifndef _BF0_SIBLES_SERIAL_TRANS_CLIENT_H
51+
#define _BF0_SIBLES_SERIAL_TRANS_CLIENT_H
52+
53+
#include "bf0_sibles_serial_trans_service.h"
54+
55+
/**
56+
* @defgroup Serial_tran Serial transmission client
57+
* @ingroup profile
58+
* @{
59+
*/
60+
61+
#if defined(_MSC_VER)
62+
#pragma section("SerialTranClientExport$f",read)
63+
/**
64+
* @brief The macro that register user categoryID and callback.
65+
* @param[in] cate_id categoryID.
66+
* @param[in] callback user callback.
67+
*/
68+
#define BLE_SERIAL_CLIENT_EXPORT(cate_id, callback) \
69+
__declspec(allocate("SerialTranClientExport$f"))const ble_serial_tran_export_t _serial_client_export= \
70+
{ \
71+
callback, \
72+
cate_id, \
73+
}
74+
#pragma comment(linker, "/merge:RSerialTranClientExport=mytext")
75+
#else
76+
/**
77+
* @brief The macro that register user categoryID and callback.
78+
* @param[in] cate_id categoryID.
79+
* @param[in] callback user callback.
80+
*/
81+
#define BLE_SERIAL_CLIENT_EXPORT(cate_id, callback) \
82+
RT_USED static const ble_serial_tran_export_t _serial_client_export \
83+
SECTION("SerialTranClientExport") = \
84+
{ \
85+
callback, \
86+
cate_id, \
87+
}
88+
#endif
89+
90+
/**
91+
* @brief Enable serial transmission client.
92+
*/
93+
void ble_serial_client_init(void);
94+
95+
/**
96+
* @brief Open serial transmission client.
97+
* @param[in] conn_idx .
98+
* @retval result BLE_SERIAL_TRAN_ERROR_NO_ERROR is successful, others are failed.
99+
*/
100+
ble_serial_tran_error_event_t ble_serial_client_open(uint8_t conn_idx);
101+
102+
/**
103+
* @brief Send serial transmission client data.
104+
* @param[in] data serial transmission data.
105+
* @param[in] is_retry if retry send data when gatt queue is full.
106+
* @retval result BLE_SERIAL_TRAN_ERROR_NO_ERROR is successful, others are failed.
107+
*/
108+
ble_serial_tran_error_event_t ble_serial_client_send_data(ble_serial_tran_data_t *data, uint8_t is_retry);
109+
110+
111+
/**
112+
* @}
113+
*/
114+
115+
116+
117+
#endif // _BF0_SIBLES_SERIAL_TRANS_CLIENT_H
118+
#endif //BSP_BLE_SERIAL_TRANSMISSION
119+
120+
/************************ (C) COPYRIGHT Sifli Technology *******END OF FILE****/

include/bf0_sibles_serial_trans_service.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,18 @@ typedef enum
116116
BLE_SERIAL_TRAN_SEND_AVAILABLE, /**< BLE serial transmission can try send data if last send failed. */
117117
BLE_SERIAL_TRAN_CLOSE, /**< BLE serial transmission channel closed. */
118118
BLE_SERIAL_TRAN_ERROR, /**< BLE serial transmission error due to packet lose or other reason */
119+
BLE_SERIAL_TRAN_OPEN_FAILED, /**< BLE serial transmission open failed for seriral transmission client */
119120
} ble_serial_tran_event_t;
120121

121122
typedef enum
122123
{
124+
BLE_SERIAL_TRAN_ERROR_NO_ERROR,
123125
BLE_SERIAL_TRAN_ERROR_CATE_ID,
124126
BLE_SERIAL_TRAN_ERROR_LACK_OF_MEMORY,
125127
BLE_SERIAL_TRAN_ERROR_ASSEMBLE_OVER_LEN,
126128
BLE_SERIAL_TRAN_ERROR_ASSEMBLE_ERROR,
129+
BLE_SERIAL_TRAN_ERROR_INVALID_PARA,
130+
BLE_SERIAL_TRAN_ERROR_COMMON_ERROR,
127131
} ble_serial_tran_error_event_t;
128132

129133

service/ble/bf0_sibles.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void sibles_check_wr_list_msg(void)
411411
g_sibles.num_of_tx_pkt++;
412412
rt_exit_critical();
413413
RT_ASSERT(g_sibles.num_of_tx_pkt <= MAX_NUM_OF_TX_PKT);
414-
LOG_I("rev wr rsp:left_txnum %d\n", g_sibles.num_of_tx_pkt);
414+
LOG_D("rev wr rsp:left_txnum %d\n", g_sibles.num_of_tx_pkt);
415415
return;
416416
}
417417
#ifdef BLE_GATT_CLIENT
@@ -1655,15 +1655,17 @@ int8_t sibles_write_remote_value(uint16_t remote_handle, uint8_t conn_idx, sible
16551655
return SIBLES_WRITE_HANDLE_ERR;
16561656

16571657
acq_tx = sibles_acquire_tx_pkts();
1658-
LOG_I("send:acq_tx, buffer tx_num t_pkt %d %d %d\n", acq_tx, buffer_num, g_sibles.num_of_tx_pkt);
1658+
LOG_D("send:acq_tx, buffer tx_num t_pkt %d %d %d\n", acq_tx, buffer_num, g_sibles.num_of_tx_pkt);
16591659
if ((0 == acq_tx) && (20 == buffer_num))
16601660
{
1661+
LOG_W("no buff for sibles write!");
16611662
return SIBLES_WIRTE_TX_FLOWCTRL_ERR;
16621663
}
16631664
if (0 == acq_tx)
16641665
{
16651666
struct sibles_rte_wr_info *node;
16661667
struct sibles_value_write_req_content_t *wr_req;
1668+
LOG_I("use cache buf %d", buffer_num);
16671669
//the size of struct + the length of value[__ARRAY_EMPTY];
16681670
wr_req = bt_mem_alloc(sizeof(struct sibles_value_write_req_content_t) + value->len);
16691671
node = bt_mem_alloc(sizeof(struct sibles_rte_wr_info));

0 commit comments

Comments
 (0)