@@ -47,6 +47,8 @@ typedef struct {
47
47
bool avrcp_conn_state ;
48
48
audio_stream_type_t stream_type ;
49
49
uint8_t trans_label ;
50
+ esp_bd_addr_t connected_bd_addr ;
51
+ uint8_t connected_flag ;
50
52
51
53
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL (4 , 0 , 0 ))
52
54
audio_hal_handle_t audio_hal ;
@@ -121,6 +123,8 @@ static void bt_a2d_sink_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
121
123
bda [0 ], bda [1 ], bda [2 ], bda [3 ], bda [4 ], bda [5 ]);
122
124
if (param -> conn_stat .state == ESP_A2D_CONNECTION_STATE_DISCONNECTED ) {
123
125
ESP_LOGI (TAG , "A2DP connection state = DISCONNECTED" );
126
+ s_aadp_handler .connected_flag = 0 ;
127
+ memset (s_aadp_handler .connected_bd_addr , 0x00 , ESP_BD_ADDR_LEN );
124
128
if (s_aadp_handler .sink_stream ) {
125
129
audio_element_report_status (s_aadp_handler .sink_stream , AEL_STATUS_INPUT_DONE );
126
130
}
@@ -129,6 +133,8 @@ static void bt_a2d_sink_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param)
129
133
}
130
134
} else if (param -> conn_stat .state == ESP_A2D_CONNECTION_STATE_CONNECTED ) {
131
135
ESP_LOGI (TAG , "A2DP connection state = CONNECTED" );
136
+ memcpy (s_aadp_handler .connected_bd_addr , bda , ESP_BD_ADDR_LEN );
137
+ s_aadp_handler .connected_flag = 1 ;
132
138
if (s_aadp_handler .bt_avrc_periph ) {
133
139
esp_periph_send_event (s_aadp_handler .bt_avrc_periph , PERIPH_BLUETOOTH_CONNECTED , NULL , 0 );
134
140
}
@@ -209,15 +215,20 @@ static void bt_a2d_source_cb(esp_a2d_cb_event_t event, esp_a2d_cb_param_t *param
209
215
}
210
216
switch (event ) {
211
217
case ESP_A2D_CONNECTION_STATE_EVT :
218
+ uint8_t * bda = param -> conn_stat .remote_bda ;
212
219
if (param -> conn_stat .state == ESP_A2D_CONNECTION_STATE_CONNECTED ) {
213
220
ESP_LOGI (TAG , "a2dp source connected" );
214
221
ESP_LOGI (TAG , "a2dp media ready checking ..." );
222
+ memcpy (s_aadp_handler .connected_bd_addr , bda , ESP_BD_ADDR_LEN );
223
+ s_aadp_handler .connected_flag = 1 ;
215
224
esp_a2d_media_ctrl (ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY );
216
225
if (s_aadp_handler .bt_avrc_periph ) {
217
226
esp_periph_send_event (s_aadp_handler .bt_avrc_periph , PERIPH_BLUETOOTH_CONNECTED , NULL , 0 );
218
227
}
219
228
} else if (param -> conn_stat .state == ESP_A2D_CONNECTION_STATE_DISCONNECTED ) {
220
229
ESP_LOGI (TAG , "a2dp source disconnected" );
230
+ s_aadp_handler .connected_flag = 0 ;
231
+ memset (s_aadp_handler .connected_bd_addr , 0x00 , ESP_BD_ADDR_LEN );
221
232
esp_bt_gap_start_discovery (ESP_BT_INQ_MODE_GENERAL_INQUIRY , 10 , 0 );
222
233
if (s_aadp_handler .bt_avrc_periph ) {
223
234
esp_periph_send_event (s_aadp_handler .bt_avrc_periph , PERIPH_BLUETOOTH_DISCONNECTED , NULL , 0 );
@@ -305,6 +316,8 @@ audio_element_handle_t a2dp_stream_init(a2dp_stream_config_t *config)
305
316
esp_avrc_tg_set_rn_evt_cap (& evt_set );
306
317
#endif
307
318
319
+ s_aadp_handler .connected_flag = 0 ;
320
+
308
321
if (config -> type == AUDIO_STREAM_READER ) {
309
322
// A2DP sink
310
323
s_aadp_handler .stream_type = AUDIO_STREAM_READER ;
@@ -352,6 +365,8 @@ esp_err_t a2dp_destroy()
352
365
} else if (s_aadp_handler .stream_type == AUDIO_STREAM_WRITER ) {
353
366
esp_a2d_source_deinit ();
354
367
}
368
+ s_aadp_handler .connected_flag = 0 ;
369
+
355
370
return ESP_OK ;
356
371
}
357
372
@@ -614,4 +629,14 @@ esp_err_t periph_bt_volume_down(esp_periph_handle_t periph)
614
629
}
615
630
#endif
616
631
632
+ esp_err_t periph_bt_get_connected_bd_addr (esp_periph_handle_t periph , uint8_t * dest )
633
+ {
634
+ if (!dest )
635
+ return ESP_ERR_INVALID_ARG ;
636
+ if (!s_aadp_handler .connected_flag )
637
+ return ESP_ERR_INVALID_STATE ;
638
+ memcpy (dest , s_aadp_handler .connected_bd_addr , ESP_BD_ADDR_LEN );
639
+ return ESP_OK ;
640
+ }
641
+
617
642
#endif
0 commit comments