Skip to content

Commit 7898ac5

Browse files
lucasssvazh2zero
andcommitted
feat(NimBLE): Add support for NimBLE
Co-authored-by: h2zero <[email protected]>
1 parent a6bba43 commit 7898ac5

Some content is hidden

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

67 files changed

+9704
-3094
lines changed

cores/esp32/esp32-hal-bt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "esp32-hal-bt.h"
1616

1717
#if SOC_BT_SUPPORTED
18-
#ifdef CONFIG_BT_BLUEDROID_ENABLED
18+
#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
1919

2020
#if CONFIG_IDF_TARGET_ESP32
2121
bool btInUse() {
@@ -116,7 +116,7 @@ bool btStop() {
116116
return false;
117117
}
118118

119-
#else // CONFIG_BT_ENABLED
119+
#else // !defined(CONFIG_BLUEDROID_ENABLED) && !defined(CONFIG_NIMBLE_ENABLED)
120120
bool btStarted() {
121121
return false;
122122
}
@@ -129,6 +129,6 @@ bool btStop() {
129129
return false;
130130
}
131131

132-
#endif /* CONFIG_BT_ENABLED */
132+
#endif /* !defined(CONFIG_BLUEDROID_ENABLED) && !defined(CONFIG_NIMBLE_ENABLED) */
133133

134134
#endif /* SOC_BT_SUPPORTED */

libraries/BLE/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# ESP32 BLE for Arduino
22
The Arduino IDE provides an excellent library package manager where versions of libraries can be downloaded and installed. This Github project provides the repository for the ESP32 BLE support for Arduino.
33

4-
The original source of the project, **which is not maintained anymore**, can be found here: https://github.com/nkolban/esp32-snippets
4+
The original source of the Bluedroid project, **which is not maintained anymore**, can be found here: https://github.com/nkolban/esp32-snippets
55

6-
Issues and questions should be raised here: https://github.com/espressif/arduino-esp32/issues <br> (please don't use https://github.com/nkolban/esp32-snippets/issues!)
6+
Some parts of the NimBLE implementation are based on the work of h2zero, which can be found here: https://github.com/h2zero/NimBLE-Arduino
7+
8+
Issues and questions should be raised here: https://github.com/espressif/arduino-esp32/issues <br> (please don't use https://github.com/nkolban/esp32-snippets/issues or https://github.com/h2zero/NimBLE-Arduino/issues!)
79

810
Documentation for using the library can be found here: https://github.com/nkolban/esp32-snippets/tree/master/Documentation
11+
12+
For a more customizable and feature-rich implementation of the NimBLE stack, you can use the [NimBLE-Arduino](https://github.com/h2zero/NimBLE-Arduino) library.

libraries/BLE/examples/BLE5_extended_scan/BLE5_extended_scan.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
88
author: chegewara
99
*/
10-
#ifndef SOC_BLE_50_SUPPORTED
11-
#warning "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
10+
#ifndef CONFIG_BLUEDROID_ENABLED
11+
#error "NimBLE does not support extended scan yet. Try using Bluedroid."
12+
#elif !defined(SOC_BLE_50_SUPPORTED)
13+
#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
1214
#else
1315

1416
#include <BLEDevice.h>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
33
"requires": [
4-
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
"CONFIG_SOC_BLE_50_SUPPORTED=y",
5+
"CONFIG_BLUEDROID_ENABLED=y"
56
]
67
}

libraries/BLE/examples/BLE5_multi_advertising/BLE5_multi_advertising.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
author: chegewara
77
*/
88

9-
#ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
9+
#ifndef CONFIG_BLUEDROID_ENABLED
10+
#error "NimBLE does not support multi advertising yet. Try using Bluedroid."
11+
#elif !defined(CONFIG_BT_BLE_50_FEATURES_SUPPORTED)
1012
#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
1113
#else
1214

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
33
"requires": [
4-
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
"CONFIG_SOC_BLE_50_SUPPORTED=y",
5+
"CONFIG_BLUEDROID_ENABLED=y"
56
]
67
}

libraries/BLE/examples/BLE5_periodic_advertising/BLE5_periodic_advertising.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
author: chegewara
66
*/
77

8-
#ifndef CONFIG_BT_BLE_50_FEATURES_SUPPORTED
8+
#ifndef CONFIG_BLUEDROID_ENABLED
9+
#error "NimBLE does not support periodic advertising yet. Try using Bluedroid."
10+
#elif !defined(CONFIG_BT_BLE_50_FEATURES_SUPPORTED)
911
#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
1012
#else
1113
#include <BLEDevice.h>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
33
"requires": [
4-
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
"CONFIG_SOC_BLE_50_SUPPORTED=y",
5+
"CONFIG_BLUEDROID_ENABLED=y"
56
]
67
}

libraries/BLE/examples/BLE5_periodic_sync/BLE5_periodic_sync.ino

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
88
author: chegewara
99
*/
10-
#ifndef SOC_BLE_50_SUPPORTED
11-
#warning "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
10+
#ifndef CONFIG_BLUEDROID_ENABLED
11+
#error "NimBLE does not support periodic sync yet. Try using Bluedroid."
12+
#elif !defined(SOC_BLE_50_SUPPORTED)
13+
#error "This SoC does not support BLE5. Try using ESP32-C3, or ESP32-S3"
1214
#else
1315
#include <BLEDevice.h>
1416
#include <BLEUtils.h>
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
33
"requires": [
4-
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
"CONFIG_SOC_BLE_50_SUPPORTED=y",
5+
"CONFIG_BLUEDROID_ENABLED=y"
56
]
67
}

libraries/BLE/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name=BLE
22
version=3.2.0
33
author=Neil Kolban <[email protected]>
4-
maintainer=Dariusz Krempa <[email protected]>
4+
maintainer=lucasssvaz
55
sentence=BLE functions for ESP32
66
paragraph=This library provides an implementation Bluetooth Low Energy support for the ESP32 using the Arduino platform.
77
category=Communication

libraries/BLE/src/BLE2901.cpp

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
11
/*
2-
BLE2901.h
2+
BLE2901.h
33
4-
GATT Descriptor 0x2901 Characteristic User Description
4+
GATT Descriptor 0x2901 Characteristic User Description
55
6-
The value of this description is a user-readable string
7-
describing the characteristic.
6+
The value of this description is a user-readable string
7+
describing the characteristic.
88
9-
The Characteristic User Description descriptor
10-
provides a textual user description for a characteristic
11-
value.
12-
If the Writable Auxiliary bit of the Characteristics
13-
Properties is set then this descriptor is written. Only one
14-
User Description descriptor exists in a characteristic
15-
definition.
9+
The Characteristic User Description descriptor
10+
provides a textual user description for a characteristic
11+
value.
12+
If the Writable Auxiliary bit of the Characteristics
13+
Properties is set then this descriptor is written. Only one
14+
User Description descriptor exists in a characteristic
15+
definition.
1616
*/
1717

1818
#include "soc/soc_caps.h"
1919
#if SOC_BLE_SUPPORTED
2020

2121
#include "sdkconfig.h"
22-
#if defined(CONFIG_BLUEDROID_ENABLED)
22+
#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
23+
24+
/***************************************************************************
25+
* Common includes and definitions *
26+
***************************************************************************/
2327

2428
#include "BLE2901.h"
2529

26-
BLE2901::BLE2901() : BLEDescriptor(BLEUUID((uint16_t)0x2901)) {} // BLE2901
30+
#define BLE2901_UUID 0x2901
31+
32+
/***************************************************************************
33+
* NimBLE includes and definitions *
34+
***************************************************************************/
35+
36+
#if defined(CONFIG_NIMBLE_ENABLED)
37+
#include "host/ble_att.h"
38+
#define ESP_GATT_MAX_ATTR_LEN BLE_ATT_ATTR_MAX_LEN
39+
#endif
40+
41+
/***************************************************************************
42+
* Common functions *
43+
***************************************************************************/
44+
45+
BLE2901::BLE2901() : BLEDescriptor(BLEUUID((uint16_t)BLE2901_UUID)) {}
2746

2847
/**
2948
* @brief Set the Characteristic User Description
@@ -36,5 +55,5 @@ void BLE2901::setDescription(String userDesc) {
3655
setValue(userDesc);
3756
}
3857

39-
#endif
58+
#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
4059
#endif /* SOC_BLE_SUPPORTED */

libraries/BLE/src/BLE2901.h

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,48 @@
11
/*
2-
BLE2901.h
2+
BLE2901.h
33
4-
GATT Descriptor 0x2901 Characteristic User Description
4+
GATT Descriptor 0x2901 Characteristic User Description
55
6-
The value of this description is a user-readable string
7-
describing the characteristic.
8-
9-
The Characteristic User Description descriptor
10-
provides a textual user description for a characteristic
11-
value.
12-
If the Writable Auxiliary bit of the Characteristics
13-
Properties is set then this descriptor is written. Only one
14-
User Description descriptor exists in a characteristic
15-
definition.
6+
The value of this description is a user-readable string
7+
describing the characteristic.
168
9+
The Characteristic User Description descriptor
10+
provides a textual user description for a characteristic
11+
value.
12+
If the Writable Auxiliary bit of the Characteristics
13+
Properties is set then this descriptor is written. Only one
14+
User Description descriptor exists in a characteristic
15+
definition.
1716
*/
1817

1918
#ifndef COMPONENTS_CPP_UTILS_BLE2901_H_
2019
#define COMPONENTS_CPP_UTILS_BLE2901_H_
20+
2121
#include "soc/soc_caps.h"
2222
#if SOC_BLE_SUPPORTED
2323

2424
#include "sdkconfig.h"
25-
#if defined(CONFIG_BLUEDROID_ENABLED)
25+
#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
26+
27+
/***************************************************************************
28+
* Common includes *
29+
***************************************************************************/
2630

2731
#include "BLEDescriptor.h"
2832

33+
/**
34+
* @brief GATT Descriptor 0x2901 Characteristic User Description
35+
*/
2936
class BLE2901 : public BLEDescriptor {
3037
public:
38+
/***************************************************************************
39+
* Common public functions *
40+
***************************************************************************/
41+
3142
BLE2901();
3243
void setDescription(String desc);
3344
}; // BLE2901
3445

35-
#endif /* CONFIG_BLUEDROID_ENABLED */
46+
#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
3647
#endif /* SOC_BLE_SUPPORTED */
3748
#endif /* COMPONENTS_CPP_UTILS_BLE2901_H_ */

0 commit comments

Comments
 (0)