2017-02-23 00:11:57 +01:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "esp32-hal-bt.h"
|
|
|
|
|
2018-06-27 09:01:06 +02:00
|
|
|
#ifdef CONFIG_BT_ENABLED
|
2017-09-21 13:08:18 +02:00
|
|
|
|
2018-06-27 09:01:06 +02:00
|
|
|
bool btInUse(){ return true; }
|
2017-05-06 17:40:23 +02:00
|
|
|
|
2018-06-27 09:01:06 +02:00
|
|
|
#ifdef CONFIG_BLUEDROID_ENABLED
|
2018-01-17 23:56:58 +01:00
|
|
|
#include "esp_bt.h"
|
2018-06-27 09:01:06 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_CLASSIC_BT_ENABLED
|
|
|
|
#define BT_MODE ESP_BT_MODE_BTDM
|
|
|
|
#else
|
|
|
|
#define BT_MODE ESP_BT_MODE_BLE
|
|
|
|
#endif
|
2017-02-23 00:11:57 +01:00
|
|
|
|
|
|
|
bool btStarted(){
|
|
|
|
return (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool btStart(){
|
2017-04-22 15:33:07 +02:00
|
|
|
esp_bt_controller_config_t cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
2017-02-23 00:11:57 +01:00
|
|
|
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){
|
2017-04-12 19:53:21 +02:00
|
|
|
esp_bt_controller_init(&cfg);
|
2017-02-23 00:11:57 +01:00
|
|
|
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){}
|
|
|
|
}
|
|
|
|
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
|
2018-06-27 09:01:06 +02:00
|
|
|
if (esp_bt_controller_enable(BT_MODE)) {
|
2017-02-23 00:11:57 +01:00
|
|
|
log_e("BT Enable failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
log_e("BT Start failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool btStop(){
|
|
|
|
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
|
2017-09-22 11:28:54 +02:00
|
|
|
if (esp_bt_controller_disable()) {
|
2017-02-23 00:11:57 +01:00
|
|
|
log_e("BT Disable failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
|
|
|
|
}
|
|
|
|
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
log_e("BT Stop failed");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-06 17:50:20 +02:00
|
|
|
#else
|
|
|
|
bool btStarted()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool btStart()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool btStop()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-06 17:27:03 +02:00
|
|
|
#endif
|
2018-06-27 09:01:06 +02:00
|
|
|
#endif
|
2017-02-23 00:11:57 +01:00
|
|
|
|