Allow phy to be initialized only if WiFi/BLE is used/enabled

fixes: https://github.com/espressif/arduino-esp32/issues/72
This commit is contained in:
me-no-dev
2016-12-01 13:23:17 +02:00
parent 57c3650ea2
commit 8904f52c39
5 changed files with 53 additions and 1 deletions

View File

@ -18,6 +18,51 @@
#include "freertos/task.h"
#include "esp_attr.h"
#if !CONFIG_ESP32_PHY_AUTO_INIT
#include "nvs_flash.h"
#include "esp_phy_init.h"
#include "rom/rtc.h"
void arduino_phy_init()
{
static bool initialized = false;
if(initialized){
return;
}
nvs_flash_init();
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
uint32_t IRAM_ATTR micros()
{
uint32_t ccount;