forked from espressif/arduino-esp32
Major IDF and Arduino Update
WiFi and BlueTooth can now be started and stopped at will. basic functions added to esp32-hal to start and stop the BT radio SimpleBLE class added to show the most basic functionality Example to show how to switch between BT, WiFi or Both
This commit is contained in:
65
cores/esp32/esp32-hal-bt.c
Normal file
65
cores/esp32/esp32-hal-bt.c
Normal file
@ -0,0 +1,65 @@
|
||||
// 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"
|
||||
|
||||
#include "bt.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
bool btStarted(){
|
||||
return (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
|
||||
}
|
||||
|
||||
bool btStart(){
|
||||
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
|
||||
return true;
|
||||
}
|
||||
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){
|
||||
esp_bt_controller_init();
|
||||
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(ESP_BT_MODE_BTDM)) {
|
||||
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){
|
||||
if (esp_bt_controller_disable(ESP_BT_MODE_BTDM)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
32
cores/esp32/esp32-hal-bt.h
Normal file
32
cores/esp32/esp32-hal-bt.h
Normal file
@ -0,0 +1,32 @@
|
||||
// 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.
|
||||
|
||||
#ifndef _ESP32_ESP32_HAL_BT_H_
|
||||
#define _ESP32_ESP32_HAL_BT_H_
|
||||
|
||||
#include "esp32-hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
bool btStarted();
|
||||
bool btStart();
|
||||
bool btStop();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP32_ESP32_HAL_BT_H_ */
|
@ -19,49 +19,6 @@
|
||||
#include "esp_attr.h"
|
||||
#include "nvs_flash.h"
|
||||
|
||||
#if !CONFIG_ESP32_PHY_AUTO_INIT
|
||||
#include "esp_phy_init.h"
|
||||
#include "rom/rtc.h"
|
||||
void arduino_phy_init()
|
||||
{
|
||||
static bool initialized = false;
|
||||
if(initialized){
|
||||
return;
|
||||
}
|
||||
esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
|
||||
if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
|
||||
calibration_mode = PHY_RF_CAL_NONE;
|
||||
}
|
||||
const esp_phy_init_data_t* init_data = esp_phy_get_init_data();
|
||||
if (init_data == NULL) {
|
||||
printf("failed to obtain PHY init data\n");
|
||||
abort();
|
||||
}
|
||||
esp_phy_calibration_data_t* cal_data =
|
||||
(esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1);
|
||||
if (cal_data == NULL) {
|
||||
printf("failed to allocate memory for RF calibration data\n");
|
||||
abort();
|
||||
}
|
||||
esp_err_t err = esp_phy_load_cal_data_from_nvs(cal_data);
|
||||
if (err != ESP_OK) {
|
||||
printf("failed to load RF calibration data, falling back to full calibration\n");
|
||||
calibration_mode = PHY_RF_CAL_FULL;
|
||||
}
|
||||
|
||||
esp_phy_init(init_data, calibration_mode, cal_data);
|
||||
|
||||
if (calibration_mode != PHY_RF_CAL_NONE) {
|
||||
err = esp_phy_store_cal_data_to_nvs(cal_data);
|
||||
} else {
|
||||
err = ESP_OK;
|
||||
}
|
||||
esp_phy_release_init_data(init_data);
|
||||
free(cal_data); // PHY maintains a copy of calibration data, so we can free this
|
||||
initialized = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void yield()
|
||||
{
|
||||
vPortYield();
|
||||
@ -106,18 +63,10 @@ void initVariant() {}
|
||||
void init() __attribute__((weak));
|
||||
void init() {}
|
||||
|
||||
void initWiFi() __attribute__((weak));
|
||||
void initWiFi() {}
|
||||
|
||||
void initBT() __attribute__((weak));
|
||||
void initBT() {}
|
||||
|
||||
void initArduino(){
|
||||
nvs_flash_init();
|
||||
init();
|
||||
initVariant();
|
||||
initWiFi();
|
||||
initBT();
|
||||
}
|
||||
|
||||
//used by hal log
|
||||
|
@ -58,6 +58,7 @@ void yield(void);
|
||||
#include "esp32-hal-ledc.h"
|
||||
#include "esp32-hal-sigmadelta.h"
|
||||
#include "esp32-hal-timer.h"
|
||||
#include "esp32-hal-bt.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
uint32_t micros();
|
||||
|
Reference in New Issue
Block a user