-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth-classic: release BLE memory when BT classic only is requested #8051
Changes from 4 commits
68d385e
8fafe6a
7d176db
1bf5106
a7d9795
7b715f1
853b6d2
83ec18d
cdf224f
e813e6d
8d4975d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,30 +20,44 @@ bool btInUse(){ return true; } | |
|
||
#include "esp_bt.h" | ||
|
||
#ifndef BT_MODE | ||
#ifdef CONFIG_BTDM_CONTROLLER_MODE_BTDM | ||
#define BT_MODE ESP_BT_MODE_BTDM | ||
#elif defined(CONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY) | ||
#define BT_MODE ESP_BT_MODE_CLASSIC_BT | ||
#else | ||
#define BT_MODE ESP_BT_MODE_BLE | ||
#endif | ||
#endif | ||
|
||
bool btStarted(){ | ||
return (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED); | ||
} | ||
|
||
bool btStart(){ | ||
esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); | ||
#if BT_MODE == ESP_BT_MODE_CLASSIC_BT | ||
// esp_bt_controller_enable(MODE) This mode must be equal as the mode in “cfg” of esp_bt_controller_init(). | ||
esp_bt_controller_mem_release(ESP_BT_MODE_BLE); | ||
#elif BT_MODE == ESP_BT_MODE_BLE | ||
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT); | ||
#endif | ||
cfg.mode=BT_MODE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, you were too fast.
tomorrow.... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #if CONFIG_IDF_TARGET_ESP32
cfg.mode=BT_MODE;
if(cfg.mode == ESP_BT_MODE_CLASSIC_BT) {
esp_bt_controller_mem_release(ESP_BT_MODE_BLE);
}
#endif Looks like a good plan 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @me-no-dev Is it not possible to clear memory used by BT_CLASSIC if I'm using only BLE? In the case of Rainmaker, we often run into low memory since both Classic BT and BLE are on during WiFi provisioning. Tagging @shahpiyushv. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sanketwadekar as far as I remember and it seems that @ferbar confirms it above, it is not possible to release classic memory even if you are using just BLE |
||
|
||
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){ | ||
return true; | ||
} | ||
esp_err_t ret; | ||
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){ | ||
esp_bt_controller_init(&cfg); | ||
if((ret = esp_bt_controller_init(&cfg)) != ESP_OK) { | ||
log_e("initialize controller failed: %s", esp_err_to_name(ret)); | ||
return false; | ||
} | ||
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){} | ||
} | ||
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){ | ||
if (esp_bt_controller_enable(BT_MODE)) { | ||
log_e("BT Enable failed"); | ||
if((ret = esp_bt_controller_enable(BT_MODE)) != ESP_OK) { | ||
log_e("BT Enable mode=%d failed %s", BT_MODE, esp_err_to_name(ret)); | ||
return false; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does switching defines do anything here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intention is to tell btStart() that I want to use bluetooth-classic only. CONFIG_BTDM_CONTROLLER_MODE_BTDM is defined in a default aduino-esp32 configuration, so it is the first #if that matches and can not be overridden. When we switch the defines BR_EDR_ONLY can be forced with a -DCONFIG_BTDM_CONTROLLER_MODE_BR_EDR_ONLY.
If you prefer an other #define like ARDUINO_BLUETOOTH_EDR_ONLY or a new function for BT-classic initialization please let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about you instead
-DBT_MODE=ESP_BT_MODE_CLASSIC_BT
yourself and only#ifndef BT_MODE
do the config check.