Skip to content

Commit 7f112f6

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

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
-3093
lines changed

cores/esp32/esp32-hal-bt.c

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

1717
#if SOC_BT_SUPPORTED
18+
#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
1819
#if defined(CONFIG_BT_BLUEDROID_ENABLED) && __has_include("esp_bt.h")
1920

2021
#if CONFIG_IDF_TARGET_ESP32
@@ -116,7 +117,7 @@ bool btStop() {
116117
return false;
117118
}
118119

119-
#else // CONFIG_BT_ENABLED
120+
#else // !defined(CONFIG_BLUEDROID_ENABLED) && !defined(CONFIG_NIMBLE_ENABLED)
120121
bool btStarted() {
121122
return false;
122123
}
@@ -129,6 +130,6 @@ bool btStop() {
129130
return false;
130131
}
131132

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

134135
#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_ */

libraries/BLE/src/BLE2902.cpp

Lines changed: 66 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,127 @@
33
*
44
* Created on: Jun 25, 2017
55
* Author: kolban
6+
*
7+
* Modified on: Feb 18, 2025
8+
* Author: lucasssvaz (based on kolban's and h2zero's work)
9+
* Description: Added support for NimBLE
610
*/
711

812
/*
913
* See also:
1014
* https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.descriptor.gatt.client_characteristic_configuration.xml
1115
*/
16+
1217
#include "soc/soc_caps.h"
1318
#if SOC_BLE_SUPPORTED
1419

1520
#include "sdkconfig.h"
16-
#if defined(CONFIG_BLUEDROID_ENABLED)
21+
#if defined(CONFIG_BLUEDROID_ENABLED) || defined(CONFIG_NIMBLE_ENABLED)
22+
23+
/***************************************************************************
24+
* Common includes and definitions *
25+
***************************************************************************/
1726

1827
#include "BLE2902.h"
1928

20-
BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t)0x2902)) {
29+
#define BLE2902_UUID 0x2902
30+
31+
/***************************************************************************
32+
* Common functions *
33+
***************************************************************************/
34+
35+
BLE2902::BLE2902() : BLEDescriptor(BLEUUID((uint16_t)BLE2902_UUID)) {
36+
#if defined(CONFIG_BLUEDROID_ENABLED)
2137
uint8_t data[2] = {0, 0};
2238
setValue(data, 2);
23-
} // BLE2902
39+
#endif
40+
}
2441

2542
/**
2643
* @brief Get the notifications value.
2744
* @return The notifications value. True if notifications are enabled and false if not.
2845
*/
2946
bool BLE2902::getNotifications() {
47+
#if defined(CONFIG_BLUEDROID_ENABLED)
3048
return (getValue()[0] & (1 << 0)) != 0;
31-
} // getNotifications
49+
#endif
50+
51+
#if defined(CONFIG_NIMBLE_ENABLED)
52+
if (m_pCharacteristic != nullptr) {
53+
return (m_pCharacteristic->getProperties() & BLECharacteristic::PROPERTY_NOTIFY) != 0;
54+
} else {
55+
log_w("BLE2902::getNotifications() called on an uninitialized descriptor");
56+
return false;
57+
}
58+
#endif
59+
}
3260

3361
/**
3462
* @brief Get the indications value.
3563
* @return The indications value. True if indications are enabled and false if not.
3664
*/
3765
bool BLE2902::getIndications() {
66+
#if defined(CONFIG_BLUEDROID_ENABLED)
3867
return (getValue()[0] & (1 << 1)) != 0;
39-
} // getIndications
68+
#endif
69+
70+
#if defined(CONFIG_NIMBLE_ENABLED)
71+
if (m_pCharacteristic != nullptr) {
72+
return (m_pCharacteristic->getProperties() & BLECharacteristic::PROPERTY_INDICATE) != 0;
73+
} else {
74+
log_w("BLE2902::getIndications() called on an uninitialized descriptor");
75+
return false;
76+
}
77+
#endif
78+
}
4079

4180
/**
4281
* @brief Set the indications flag.
4382
* @param [in] flag The indications flag.
4483
*/
4584
void BLE2902::setIndications(bool flag) {
85+
#if defined(CONFIG_BLUEDROID_ENABLED)
4686
uint8_t *pValue = getValue();
4787
if (flag) {
4888
pValue[0] |= 1 << 1;
4989
} else {
5090
pValue[0] &= ~(1 << 1);
5191
}
5292
setValue(pValue, 2);
53-
} // setIndications
93+
#endif
94+
95+
#if defined(CONFIG_NIMBLE_ENABLED)
96+
if (m_pCharacteristic != nullptr) {
97+
m_pCharacteristic->setIndicateProperty(flag);
98+
} else {
99+
log_w("BLE2902::setIndications() called on an uninitialized descriptor");
100+
}
101+
#endif
102+
}
54103

55104
/**
56105
* @brief Set the notifications flag.
57106
* @param [in] flag The notifications flag.
58107
*/
59108
void BLE2902::setNotifications(bool flag) {
109+
#if defined(CONFIG_BLUEDROID_ENABLED)
60110
uint8_t *pValue = getValue();
61111
if (flag) {
62112
pValue[0] |= 1 << 0;
63113
} else {
64114
pValue[0] &= ~(1 << 0);
65115
}
66116
setValue(pValue, 2);
67-
} // setNotifications
117+
#endif
68118

119+
#if defined(CONFIG_NIMBLE_ENABLED)
120+
if (m_pCharacteristic != nullptr) {
121+
m_pCharacteristic->setNotifyProperty(flag);
122+
} else {
123+
log_w("BLE2902::setNotifications() called on an uninitialized descriptor");
124+
}
69125
#endif
126+
}
127+
128+
#endif /* CONFIG_BLUEDROID_ENABLED || CONFIG_NIMBLE_ENABLED */
70129
#endif /* SOC_BLE_SUPPORTED */

0 commit comments

Comments
 (0)