Skip to content

Commit 1d75938

Browse files
committed
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
1 parent b5ac95b commit 1d75938

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1074
-303
lines changed

component.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARDUINO_LIB_DIRS := libraries/WiFi/src libraries/SPI/src libraries/Wire/src libraries/Preferences/src
1+
ARDUINO_LIB_DIRS := libraries/WiFi/src libraries/SPI/src libraries/Wire/src libraries/Preferences/src libraries/SimpleBLE/src libraries/WiFiClientSecure/src
22

33
COMPONENT_ADD_INCLUDEDIRS := cores/esp32 variants/esp32 $(ARDUINO_LIB_DIRS)
44
COMPONENT_PRIV_INCLUDEDIRS := cores/esp32/libb64

cores/esp32/esp32-hal-bt.c

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "esp32-hal-bt.h"
16+
17+
#include "bt.h"
18+
#include "esp_bt_defs.h"
19+
#include "esp_bt_main.h"
20+
21+
bool btStarted(){
22+
return (esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
23+
}
24+
25+
bool btStart(){
26+
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
27+
return true;
28+
}
29+
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){
30+
esp_bt_controller_init();
31+
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){}
32+
}
33+
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
34+
if (esp_bt_controller_enable(ESP_BT_MODE_BTDM)) {
35+
log_e("BT Enable failed");
36+
return false;
37+
}
38+
}
39+
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
40+
return true;
41+
}
42+
log_e("BT Start failed");
43+
return false;
44+
}
45+
46+
bool btStop(){
47+
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_IDLE){
48+
return true;
49+
}
50+
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED){
51+
if (esp_bt_controller_disable(ESP_BT_MODE_BTDM)) {
52+
log_e("BT Disable failed");
53+
return false;
54+
}
55+
while(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_ENABLED);
56+
}
57+
if(esp_bt_controller_get_status() == ESP_BT_CONTROLLER_STATUS_INITED){
58+
return true;
59+
}
60+
log_e("BT Stop failed");
61+
return false;
62+
}
63+
64+
65+

cores/esp32/esp32-hal-bt.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef _ESP32_ESP32_HAL_BT_H_
16+
#define _ESP32_ESP32_HAL_BT_H_
17+
18+
#include "esp32-hal.h"
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
bool btStarted();
25+
bool btStart();
26+
bool btStop();
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
32+
#endif /* _ESP32_ESP32_HAL_BT_H_ */

cores/esp32/esp32-hal-misc.c

-51
Original file line numberDiff line numberDiff line change
@@ -19,49 +19,6 @@
1919
#include "esp_attr.h"
2020
#include "nvs_flash.h"
2121

22-
#if !CONFIG_ESP32_PHY_AUTO_INIT
23-
#include "esp_phy_init.h"
24-
#include "rom/rtc.h"
25-
void arduino_phy_init()
26-
{
27-
static bool initialized = false;
28-
if(initialized){
29-
return;
30-
}
31-
esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
32-
if (rtc_get_reset_reason(0) == DEEPSLEEP_RESET) {
33-
calibration_mode = PHY_RF_CAL_NONE;
34-
}
35-
const esp_phy_init_data_t* init_data = esp_phy_get_init_data();
36-
if (init_data == NULL) {
37-
printf("failed to obtain PHY init data\n");
38-
abort();
39-
}
40-
esp_phy_calibration_data_t* cal_data =
41-
(esp_phy_calibration_data_t*) calloc(sizeof(esp_phy_calibration_data_t), 1);
42-
if (cal_data == NULL) {
43-
printf("failed to allocate memory for RF calibration data\n");
44-
abort();
45-
}
46-
esp_err_t err = esp_phy_load_cal_data_from_nvs(cal_data);
47-
if (err != ESP_OK) {
48-
printf("failed to load RF calibration data, falling back to full calibration\n");
49-
calibration_mode = PHY_RF_CAL_FULL;
50-
}
51-
52-
esp_phy_init(init_data, calibration_mode, cal_data);
53-
54-
if (calibration_mode != PHY_RF_CAL_NONE) {
55-
err = esp_phy_store_cal_data_to_nvs(cal_data);
56-
} else {
57-
err = ESP_OK;
58-
}
59-
esp_phy_release_init_data(init_data);
60-
free(cal_data); // PHY maintains a copy of calibration data, so we can free this
61-
initialized = true;
62-
}
63-
#endif
64-
6522
void yield()
6623
{
6724
vPortYield();
@@ -106,18 +63,10 @@ void initVariant() {}
10663
void init() __attribute__((weak));
10764
void init() {}
10865

109-
void initWiFi() __attribute__((weak));
110-
void initWiFi() {}
111-
112-
void initBT() __attribute__((weak));
113-
void initBT() {}
114-
11566
void initArduino(){
11667
nvs_flash_init();
11768
init();
11869
initVariant();
119-
initWiFi();
120-
initBT();
12170
}
12271

12372
//used by hal log

cores/esp32/esp32-hal.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void yield(void);
5858
#include "esp32-hal-ledc.h"
5959
#include "esp32-hal-sigmadelta.h"
6060
#include "esp32-hal-timer.h"
61+
#include "esp32-hal-bt.h"
6162
#include "esp_system.h"
6263

6364
uint32_t micros();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Sketch shows how SimpleBLE to advertise the name of the device and change it on button press
16+
// Usefull if you want to advertise some short message
17+
// Button is attached between GPIO 0 and GND and modes are switched with each press
18+
19+
#include "SimpleBLE.h"
20+
SimpleBLE ble;
21+
22+
void onButton(){
23+
String out = "BLE32 at: ";
24+
out += String(millis() / 1000);
25+
Serial.println(out);
26+
ble.begin(out);
27+
}
28+
29+
void setup() {
30+
Serial.begin(115200);
31+
Serial.setDebugOutput(true);
32+
pinMode(0, INPUT_PULLUP);
33+
Serial.print("ESP32 SDK: ");
34+
Serial.println(ESP.getSdkVersion());
35+
ble.begin("ESP32 SimpleBLE");
36+
Serial.println("Press the button to change the device name");
37+
}
38+
39+
void loop() {
40+
static uint8_t lastPinState = 1;
41+
uint8_t pinState = digitalRead(0);
42+
if(!pinState && lastPinState){
43+
onButton();
44+
}
45+
lastPinState = pinState;
46+
while(Serial.available()) Serial.write(Serial.read());
47+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=SimpleBLE
2+
version=1.0
3+
author=Hristo Gochkov
4+
maintainer=Hristo Gochkov <hristo@espressif.com>
5+
sentence=Provides really simple BLE advertizer with just on and off
6+
paragraph=
7+
category=Communication
8+
url=
9+
architectures=esp32

0 commit comments

Comments
 (0)