Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4d95e3a

Browse filesBrowse files
committed
Fix BT not starting correctly and SPP Coex not working
Fixes: espressif#4912
1 parent 7dc769d commit 4d95e3a
Copy full SHA for 4d95e3a

File tree

Expand file treeCollapse file tree

2 files changed

+38
-22
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+38
-22
lines changed

‎cores/esp32/esp32-hal-bt.c

Copy file name to clipboardExpand all lines: cores/esp32/esp32-hal-bt.c
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ bool btInUse(){ return true; }
2020

2121
#include "esp_bt.h"
2222

23-
#ifdef CONFIG_BT_CLASSIC_ENABLED
23+
#ifdef CONFIG_BTDM_CONTROLLER_MODE_BTDM
2424
#define BT_MODE ESP_BT_MODE_BTDM
25+
#elif defined(CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY)
26+
#define BT_MODE ESP_BT_MODE_CLASSIC_BT
2527
#else
2628
#define BT_MODE ESP_BT_MODE_BLE
2729
#endif

‎libraries/BluetoothSerial/src/BluetoothSerial.cpp

Copy file name to clipboardExpand all lines: libraries/BluetoothSerial/src/BluetoothSerial.cpp
+35-21Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,34 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
235235
break;
236236

237237
case ESP_SPP_SRV_OPEN_EVT://Server connection open
238-
log_i("ESP_SPP_SRV_OPEN_EVT");
239-
if (!_spp_client){
240-
_spp_client = param->open.handle;
238+
if (param->srv_open.status == ESP_SPP_SUCCESS) {
239+
log_i("ESP_SPP_SRV_OPEN_EVT");
240+
if (!_spp_client){
241+
_spp_client = param->srv_open.handle;
242+
} else {
243+
secondConnectionAttempt = true;
244+
esp_spp_disconnect(param->srv_open.handle);
245+
}
246+
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
247+
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
241248
} else {
242-
secondConnectionAttempt = true;
243-
esp_spp_disconnect(param->open.handle);
249+
log_e("ESP_SPP_SRV_OPEN_EVT Failed!, status:%d", param->srv_open.status);
244250
}
245-
xEventGroupClearBits(_spp_event_group, SPP_DISCONNECTED);
246-
xEventGroupSetBits(_spp_event_group, SPP_CONNECTED);
247251
break;
248252

249253
case ESP_SPP_CLOSE_EVT://Client connection closed
250-
log_i("ESP_SPP_CLOSE_EVT");
251-
if(secondConnectionAttempt) {
252-
secondConnectionAttempt = false;
254+
if ((param->close.async == false && param->close.status == ESP_SPP_SUCCESS) || param->close.async) {
255+
log_i("ESP_SPP_CLOSE_EVT");
256+
if(secondConnectionAttempt) {
257+
secondConnectionAttempt = false;
258+
} else {
259+
_spp_client = 0;
260+
xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED);
261+
}
262+
xEventGroupClearBits(_spp_event_group, SPP_CONNECTED);
253263
} else {
254-
_spp_client = 0;
255-
xEventGroupSetBits(_spp_event_group, SPP_DISCONNECTED);
256-
}
257-
xEventGroupClearBits(_spp_event_group, SPP_CONNECTED);
264+
log_e("ESP_SPP_CLOSE_EVT failed!, status:%d", param->close.status);
265+
}
258266
break;
259267

260268
case ESP_SPP_CONG_EVT://connection congestion status changed
@@ -267,11 +275,15 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
267275
break;
268276

269277
case ESP_SPP_WRITE_EVT://write operation completed
270-
if(param->write.cong){
271-
xEventGroupClearBits(_spp_event_group, SPP_CONGESTED);
278+
if (param->write.status == ESP_SPP_SUCCESS) {
279+
if(param->write.cong){
280+
xEventGroupClearBits(_spp_event_group, SPP_CONGESTED);
281+
}
282+
xSemaphoreGive(_spp_tx_done);//we can try to send another packet
283+
log_v("ESP_SPP_WRITE_EVT: %u %s", param->write.len, param->write.cong?"CONGESTED":"");
284+
} else {
285+
log_e("ESP_SPP_WRITE_EVT failed!, status:%d", param->write.status);
272286
}
273-
xSemaphoreGive(_spp_tx_done);//we can try to send another packet
274-
log_v("ESP_SPP_WRITE_EVT: %u %s", param->write.len, param->write.cong?"CONGESTED":"FREE");
275287
break;
276288

277289
case ESP_SPP_DATA_IND_EVT://connection received data
@@ -296,6 +308,8 @@ static void esp_spp_cb(esp_spp_cb_event_t event, esp_spp_cb_param_t *param)
296308
if (param->disc_comp.status == ESP_SPP_SUCCESS) {
297309
log_i("ESP_SPP_DISCOVERY_COMP_EVT: spp connect to remote");
298310
esp_spp_connect(ESP_SPP_SEC_AUTHENTICATE, ESP_SPP_ROLE_MASTER, param->disc_comp.scn[0], _peer_bd_addr);
311+
} else {
312+
log_e("ESP_SPP_DISCOVERY_COMP_EVT failed!, status:%d", param->disc_comp.status);
299313
}
300314
break;
301315

@@ -532,9 +546,9 @@ static bool _init_bt(const char *deviceName)
532546
return false;
533547
}
534548

535-
if (esp_bt_sleep_disable() != ESP_OK){
536-
log_e("esp_bt_sleep_disable failed");
537-
}
549+
// if (esp_bt_sleep_disable() != ESP_OK){
550+
// log_e("esp_bt_sleep_disable failed");
551+
// }
538552

539553
log_i("device name set");
540554
esp_bt_dev_set_device_name(deviceName);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.