update nimble library to version 1.40
This commit is contained in:
@@ -125,6 +125,7 @@ void NukiWrapper::update()
|
||||
_lastRssi = rssi;
|
||||
}
|
||||
}
|
||||
|
||||
if(_hasKeypad && _keypadEnabled && (_nextKeypadUpdateTs == 0 || ts > _nextKeypadUpdateTs))
|
||||
{
|
||||
_nextKeypadUpdateTs = ts + _intervalKeypad * 1000;
|
||||
|
||||
@@ -2,18 +2,20 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [Unreleased]
|
||||
## [1.4.0] - 2022-07-10
|
||||
|
||||
### Fixed
|
||||
- Fixed missing data from long notification values.
|
||||
- Fixed NimbleCharacteristicCallbacks::onRead not being called when a non-long read command is received.
|
||||
|
||||
### Changed
|
||||
- Updated NimBLE core to use the v1.4.0 branch of esp-nimble
|
||||
- Updated NimBLE core to use the v1.4.0 branch of esp-nimble.
|
||||
- AD flags are no longer set in the advertisements of non-connectable beacons, freeing up 3 bytes of advertisement room.
|
||||
|
||||
### Added
|
||||
- Preliminary support for non-esp devices, NRF51 and NRF52 devices supported with [n-able arduino core](https://github.com/h2zero/n-able)
|
||||
- Preliminary support for non-esp devices, NRF51 and NRF52 devices supported with [n-able arduino core](https://github.com/h2zero/n-able-Arduino)
|
||||
- Alias added for `NimBLEServerCallbacks::onMTUChange` to `onMtuChanged` in order to support porting code from original library.
|
||||
- `NimBLEAttValue` Class added to reduce and control RAM footprint of characteristic/descriptor values and support conversions from Arduio Strings and many other data types.
|
||||
- `NimBLEAttValue` Class added to reduce and control RAM footprint of characteristic/descriptor values and support conversions from Arduino Strings and many other data types.
|
||||
- Bluetooth 5 extended advertising support for capable devices. CODED Phy, 2M Phy, extended advertising data, and multi-advertising are supported, periodic advertising will be implemented in the future.
|
||||
|
||||
## [1.3.8] - 2022-04-27
|
||||
@@ -44,7 +46,7 @@ All notable changes to this project will be documented in this file.
|
||||
- Memory leak when services are changed on server devices.
|
||||
- Rare crashing that occurs when BLE commands are sent from ISR context using IPC.
|
||||
- Crashing caused by uninitialized disconnect timer in client.
|
||||
- Potential crash due to unintialized advertising callback pointer.
|
||||
- Potential crash due to uninitialized advertising callback pointer.
|
||||
|
||||
## [1.3.5] - 2022-01-14
|
||||
|
||||
@@ -81,7 +83,7 @@ All notable changes to this project will be documented in this file.
|
||||
## [1.3.0] - 2021-08-02
|
||||
|
||||
### Added
|
||||
- `NimBLECharacteristic::removeDescriptor`: Dynamically remove a descriptor from a characterisic. Takes effect after all connections are closed and sends a service changed indication.
|
||||
- `NimBLECharacteristic::removeDescriptor`: Dynamically remove a descriptor from a characteristic. Takes effect after all connections are closed and sends a service changed indication.
|
||||
- `NimBLEService::removeCharacteristic`: Dynamically remove a characteristic from a service. Takes effect after all connections are closed and sends a service changed indication
|
||||
- `NimBLEServerCallbacks::onMTUChange`: This is callback is called when the MTU is updated after connection with a client.
|
||||
- ESP32C3 support
|
||||
@@ -112,12 +114,12 @@ All notable changes to this project will be documented in this file.
|
||||
### Fixed
|
||||
- `NimBLECharacteristicCallbacks::onSubscribe` Is now called after the connection is added to the vector.
|
||||
- Corrected bonding failure when reinitializing the BLE stack.
|
||||
- Writing to a characterisic with a std::string value now correctly writes values with null characters.
|
||||
- Retrieving remote descriptors now uses the characterisic end handle correctly.
|
||||
- Writing to a characteristic with a std::string value now correctly writes values with null characters.
|
||||
- Retrieving remote descriptors now uses the characteristic end handle correctly.
|
||||
- Missing data in long writes to remote descriptors.
|
||||
- Hanging on task notification when sending an indication from the characteristic callback.
|
||||
- BLE controller memory could be released when using Arduino as a component.
|
||||
- Complile errors with NimBLE release 1.3.0.
|
||||
- Compile errors with NimBLE release 1.3.0.
|
||||
|
||||
## [1.2.0] - 2021-02-08
|
||||
|
||||
@@ -172,7 +174,7 @@ Overloads to get a vector containing pointers to all the characteristics in a se
|
||||
|
||||
- `NimBLEAdvertising` Transmission power is no longer advertised by default and can be added to the advertisement by calling `NimBLEAdvertising::addTxPower`
|
||||
|
||||
- `NimBLEAdvertising` Custom scan response data can now be used without custom advertisment.
|
||||
- `NimBLEAdvertising` Custom scan response data can now be used without custom advertisement.
|
||||
|
||||
- `NimBLEScan` Now uses the controller duplicate filter.
|
||||
|
||||
@@ -214,7 +216,7 @@ to obtain information about the disconnected client.
|
||||
- If a host reset event occurs, scanning and advertising will now only be restarted if their previous duration was indefinite.
|
||||
|
||||
- `NimBLERemoteCharacteristic::subscribe` and `NimBLERemoteCharacteristic::registerForNotify` will now set the callback
|
||||
regardless of the existance of the CCCD and return true unless the descriptor write operation failed.
|
||||
regardless of the existence of the CCCD and return true unless the descriptor write operation failed.
|
||||
|
||||
- Advertising tx power level is now sent in the advertisement packet instead of scan response.
|
||||
|
||||
@@ -225,7 +227,7 @@ this allows the starting of a new scan from the callback function.
|
||||
- Sometimes `NimBLEClient::connect` would hang on the task block if no event arrived to unblock.
|
||||
A time limit has been added to timeout appropriately.
|
||||
|
||||
- When getting descriptors for a characterisic the end handle of the service was used as a proxy for the characteristic end
|
||||
- When getting descriptors for a characteristic the end handle of the service was used as a proxy for the characteristic end
|
||||
handle. This would be rejected by some devices and has been changed to use the next characteristic handle as the end when possible.
|
||||
|
||||
- An exception could occur when deleting a client instance if a notification arrived while the attribute vectors were being
|
||||
@@ -242,7 +244,7 @@ and would be unable to reconnect. A timer has been added to reset the host/contr
|
||||
- 16bit and 32bit UUID's in some cases were not discovered or compared correctly if the device
|
||||
advertised them as 16/32bit but resolved them to 128bits. Both are now checked.
|
||||
|
||||
- `FreeRTOS` compile errors resolved in latest Ardruino core and IDF v3.3.
|
||||
- `FreeRTOS` compile errors resolved in latest Arduino core and IDF v3.3.
|
||||
|
||||
- Multiple instances of `time()` called inside critical sections caused sporadic crashes, these have been moved out of critical regions.
|
||||
|
||||
@@ -258,7 +260,7 @@ advertised them as 16/32bit but resolved them to 128bits. Both are now checked.
|
||||
### Changed
|
||||
|
||||
- `NimBLEAdvertising::start` Now takes 2 optional parameters, the first is the duration to advertise for (in seconds), the second is a
|
||||
callback that is invoked when advertsing ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API).
|
||||
callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API).
|
||||
|
||||
- (Arduino) Maximum BLE connections can now be altered by only changing the value of `CONFIG_BT_NIMBLE_MAX_CONNECTIONS` in `nimconfig.h`.
|
||||
Any changes to the controller max connection settings in `sdkconfig.h` will now have no effect when using this library.
|
||||
|
||||
@@ -1,63 +1,50 @@
|
||||
[Latest release 
|
||||
](https://github.com/h2zero/NimBLE-Arduino/releases/latest/)
|
||||
](https://github.com/h2zero/NimBLE-Arduino/releases/latest/)
|
||||
|
||||
Need help? Have questions or suggestions? Join the [](https://gitter.im/NimBLE-Arduino/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
Need help? Have questions or suggestions? Join the [](https://gitter.im/NimBLE-Arduino/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
<br/>
|
||||
|
||||
# NimBLE-Arduino
|
||||
A fork of the NimBLE stack restructured for compilation in the Ardruino IDE with a CPP library for use with ESP32.
|
||||
A fork of the NimBLE stack refactored for compilation in the Ardruino IDE.
|
||||
|
||||
**Note for IDF users: This repo will not compile correctly in ESP-IDF. An ESP-IDF component version of this library can be [found here.](https://github.com/h2zero/esp-nimble-cpp)**
|
||||
**As of release 1.4.0 Nordic Semiconductor nRF51 and nRF52 series devices are now supported**
|
||||
|
||||
This library **significantly** reduces resource usage and improves performance for ESP32 BLE applications as compared
|
||||
with the bluedroid based library. The goal is to maintain, as much as reasonable, compatibility with the original
|
||||
library but refactored to use the NimBLE stack. In addition, this library will be more actively developed and maintained
|
||||
to provide improved capabilites and stability over the original.
|
||||
## Supported MCU's
|
||||
- Espressif: ESP32, ESP32C3, ESP32S3
|
||||
- Nordic: nRF51, nRF52 series (**Requires** using [n-able arduino core](https://github.com/h2zero/n-able-Arduino))
|
||||
|
||||
**Note for ESP-IDF users: This repo will not compile correctly in ESP-IDF. An ESP-IDF component version of this library can be [found here.](https://github.com/h2zero/esp-nimble-cpp)**
|
||||
|
||||
This library **significantly** reduces resource usage and improves performance for ESP32 BLE applications as compared with the bluedroid based library. The goal is to maintain, as much as reasonable, compatibility with the original library but refactored to use the NimBLE stack. In addition, this library will be more actively developed and maintained to provide improved capabilities and stability over the original.
|
||||
<br/>
|
||||
|
||||
## Resource use improvement
|
||||
For Nordic devices, this library provides access to a completely open source and configurable BLE stack. No softdevice to work around, allowing for full debugging and resource management, continuous updates, with a cross platform API.
|
||||
|
||||
### (Original) BLE_client example comparison (Debug):
|
||||
#### Arduino BLE Library
|
||||
Sketch uses **1216377** bytes (58%) of program storage space.
|
||||
Memory after connection: Free Heap: **171548**
|
||||
|
||||
#### NimBLE-Arduino library
|
||||
Sketch uses **617256** bytes (29%) of program storage space.
|
||||
Memory after connection: Free Heap: **270336**
|
||||
***
|
||||
### (Original) BLE_notify example comparison (Debug):
|
||||
#### Arduino BLE Library
|
||||
Sketch uses **1208409** bytes (57%) of program storage space.
|
||||
Memory after connection: Free Heap: **173300**
|
||||
|
||||
#### NimBLE-Arduino library
|
||||
Sketch uses **603432** bytes (28%) of program storage space.
|
||||
Memory after connection: Free Heap: **269792**
|
||||
|
||||
**As shown: there is nearly a 50% reduction in flash use and approx. 100kB less ram consumed!**
|
||||
<br/>
|
||||
|
||||
# Installation
|
||||
**Arduino Library manager:** Go to `sketch` -> `Include Library` -> `Manage Libraries` and search for NimBLE and install.
|
||||
# Arduino installation
|
||||
**Arduino Library manager:** Go to `sketch` -> `Include Library` -> `Manage Libraries`, search for NimBLE and install.
|
||||
|
||||
**Alternatively:** Download as .zip and extract to Arduino/libraries folder, or in Arduino IDE from Sketch menu -> Include library -> Add .Zip library.
|
||||
|
||||
`#include "NimBLEDevice.h"` at the beginning of your sketch.
|
||||
|
||||
Tested and working with esp32-arduino in Arduino IDE and platform IO.
|
||||
<br/>
|
||||
# Platformio installation
|
||||
* Open platformio.ini, a project configuration file located in the root of PlatformIO project.
|
||||
* Add the following line to the lib_deps option of [env:] section:
|
||||
```
|
||||
h2zero/NimBLE-Arduino@^1.4.0
|
||||
```
|
||||
* Build a project, PlatformIO will automatically install dependencies.
|
||||
|
||||
# Using
|
||||
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.
|
||||
This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes.
|
||||
|
||||
If you have not used the original Bluedroid library please refer to the [New user guide](docs/New_user_guide.md).
|
||||
If you have not used the original Bluedroid library please refer to the [New user guide](docs/New_user_guide.md).
|
||||
|
||||
If you are familiar with the original library, see: [The migration guide](docs/Migration_guide.md) for details about breaking changes and migration.
|
||||
If you are familiar with the original library, see: [The migration guide](docs/Migration_guide.md) for details about breaking changes and migration.
|
||||
|
||||
Also see [Improvements_and_updates](docs/Improvements_and_updates.md) for information about non-breaking changes.
|
||||
|
||||
[Full API documentation and class list can be found here.](https://h2zero.github.io/NimBLE-Arduino/)
|
||||
[Full API documentation and class list can be found here.](https://h2zero.github.io/NimBLE-Arduino/)
|
||||
|
||||
For added performance and optimizations see [Usage tips](docs/Usage_tips.md).
|
||||
|
||||
@@ -65,21 +52,21 @@ Check the Refactored_original_examples in the examples folder for highlights of
|
||||
|
||||
More advanced examples highlighting many available features are in examples/ NimBLE_Server, NimBLE_Client.
|
||||
|
||||
Beacon examples provided by @beegee-tokyo are in examples/ BLE_Beacon_Scanner, BLE_EddystoneTLM_Beacon, BLE_EddystoneURL_Beacon.
|
||||
Beacon examples provided by @beegee-tokyo are in examples/ BLE_Beacon_Scanner, BLE_EddystoneTLM_Beacon, BLE_EddystoneURL_Beacon.
|
||||
|
||||
Change the settings in the `src/nimconfig.h` file to customize NimBLE to your project,
|
||||
such as increasing max connections, default is 3, absolute maximum connections is 9.
|
||||
Change the settings in the `src/nimconfig.h` file to customize NimBLE to your project,
|
||||
such as increasing max connections, default is 3, absolute maximum connections is 9.
|
||||
<br/>
|
||||
|
||||
# Development Status
|
||||
This Library is tracking the esp-nimble repo, nimble-1.4.0-idf branch, currently [@3c2e1d4.](https://github.com/espressif/esp-nimble)
|
||||
This Library is tracking the esp-nimble repo, nimble-1.4.0-idf branch, currently [@3df0d20.](https://github.com/espressif/esp-nimble)
|
||||
|
||||
Also tracking the NimBLE related changes in ESP-IDF, master branch, currently [@95db4bb.](https://github.com/espressif/esp-idf/tree/master/components/bt/host/nimble)
|
||||
Also tracking the NimBLE related changes in ESP-IDF, master branch, currently [@95db4bb.](https://github.com/espressif/esp-idf/tree/master/components/bt/host/nimble)
|
||||
<br/>
|
||||
|
||||
# Acknowledgments
|
||||
* [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from.
|
||||
* [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples.
|
||||
* [Jeroen88](https://github.com/Jeroen88) for the amazing help debugging and improving the client code.
|
||||
<br/>
|
||||
|
||||
* [Jeroen88](https://github.com/Jeroen88) for the amazing help debugging and improving the client code.
|
||||
<br/>
|
||||
|
||||
|
||||
2673
lib/NimBLE-Arduino/docs/Doxyfile
Normal file
2673
lib/NimBLE-Arduino/docs/Doxyfile
Normal file
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@ For more information on the improvements and additions please refer to the [clas
|
||||
* [Remote characteristics](#remote-characteristics)
|
||||
* [Security](#client-security)
|
||||
* [General Security](#security-api)
|
||||
* [Configuration](#arduino-configuration)
|
||||
* [Configuration](#arduino-configuration)
|
||||
<br/>
|
||||
|
||||
<a name="general-information"></a>
|
||||
@@ -27,25 +27,25 @@ For more information on the improvements and additions please refer to the [clas
|
||||
### Header Files
|
||||
All classes are accessible by including `NimBLEDevice.h` in your application, no further headers need to be included.
|
||||
|
||||
(Mainly for Arduino) You may choose to include `NimBLELog.h` in your appplication if you want to use the `NIMBLE_LOGx` macros for debugging. These macros are used the same way as the `ESP_LOGx` macros.
|
||||
(Mainly for Arduino) You may choose to include `NimBLELog.h` in your application if you want to use the `NIMBLE_LOGx` macros for debugging. These macros are used the same way as the `ESP_LOGx` macros.
|
||||
<br/>
|
||||
|
||||
### Class Names
|
||||
Class names remain the same as the original with the addition of a "Nim" prefix.
|
||||
For example `BLEDevice` is now `NimBLEDevice` and `BLEServer` is now `NimBLEServer` etc.
|
||||
|
||||
For convienience definitions have been added to allow applications to use either name for all classes this means **no class names need to be changed in existing code** and makes migrating easier.
|
||||
For convenience definitions have been added to allow applications to use either name for all classes this means **no class names need to be changed in existing code** and makes migrating easier.
|
||||
<br/>
|
||||
|
||||
### BLE Addresses
|
||||
`BLEAddress` (`NimBLEAddress`) When constructing an address the constructor now takes an *(optional)* `uint8_t type` paramameter to specify the address type. Default is (0) Public static address.
|
||||
`BLEAddress` (`NimBLEAddress`) When constructing an address the constructor now takes an *(optional)* `uint8_t type` parameter to specify the address type. Default is (0) Public static address.
|
||||
|
||||
For example `BLEAddress addr(11:22:33:44:55:66, 1)` will create the address object with an address type of: 1 (Random).
|
||||
|
||||
As this paramameter is optional no changes to existing code are needed, it is mentioned here for information.
|
||||
As this parameter is optional no changes to existing code are needed, it is mentioned here for information.
|
||||
|
||||
`BLEAddress::getNative` (`NimBLEAddress::getNative`) returns a uint8_t pointer to the native address byte array. In this library the address bytes are stored in reverse order from the original library. This is due to the way the NimBLE stack expects addresses to be presented to it. All other functions such as `toString` are
|
||||
not affected as the endian change is made within them.
|
||||
not affected as the endian change is made within them.
|
||||
<br/>
|
||||
|
||||
<a name="server-api"></a>
|
||||
@@ -53,8 +53,8 @@ not affected as the endian change is made within them.
|
||||
Creating a `BLEServer` instance is the same as original, no changes required.
|
||||
For example `BLEDevice::createServer()` will work just as it did before.
|
||||
|
||||
`BLEServerCallbacks` (`NimBLEServerCallbacks`) has new methods for handling security operations.
|
||||
**Note:** All callback methods have default implementations which allows the application to implement only the methods applicable.
|
||||
`BLEServerCallbacks` (`NimBLEServerCallbacks`) has new methods for handling security operations.
|
||||
**Note:** All callback methods have default implementations which allows the application to implement only the methods applicable.
|
||||
<br/>
|
||||
|
||||
<a name="services"></a>
|
||||
@@ -69,26 +69,26 @@ For example `BLEServer::createService(SERVICE_UUID)` will work just as it did be
|
||||
When creating a characteristic the properties are now set with `NIMBLE_PROPERTY::XXXX` instead of `BLECharacteristic::XXXX`.
|
||||
|
||||
#### Originally
|
||||
> BLECharacteristic::PROPERTY_READ |
|
||||
> BLECharacteristic::PROPERTY_WRITE
|
||||
> BLECharacteristic::PROPERTY_READ |
|
||||
> BLECharacteristic::PROPERTY_WRITE
|
||||
|
||||
#### Is Now
|
||||
> NIMBLE_PROPERTY::READ |
|
||||
> NIMBLE_PROPERTY::READ |
|
||||
> NIMBLE_PROPERTY::WRITE
|
||||
<br/>
|
||||
|
||||
#### The full list of properties
|
||||
> NIMBLE_PROPERTY::READ
|
||||
> NIMBLE_PROPERTY::READ_ENC
|
||||
> NIMBLE_PROPERTY::READ_AUTHEN
|
||||
> NIMBLE_PROPERTY::READ_AUTHOR
|
||||
> NIMBLE_PROPERTY::WRITE
|
||||
> NIMBLE_PROPERTY::WRITE_NR
|
||||
> NIMBLE_PROPERTY::WRITE_ENC
|
||||
> NIMBLE_PROPERTY::WRITE_AUTHEN
|
||||
> NIMBLE_PROPERTY::WRITE_AUTHOR
|
||||
> NIMBLE_PROPERTY::BROADCAST
|
||||
> NIMBLE_PROPERTY::NOTIFY
|
||||
> NIMBLE_PROPERTY::READ
|
||||
> NIMBLE_PROPERTY::READ_ENC
|
||||
> NIMBLE_PROPERTY::READ_AUTHEN
|
||||
> NIMBLE_PROPERTY::READ_AUTHOR
|
||||
> NIMBLE_PROPERTY::WRITE
|
||||
> NIMBLE_PROPERTY::WRITE_NR
|
||||
> NIMBLE_PROPERTY::WRITE_ENC
|
||||
> NIMBLE_PROPERTY::WRITE_AUTHEN
|
||||
> NIMBLE_PROPERTY::WRITE_AUTHOR
|
||||
> NIMBLE_PROPERTY::BROADCAST
|
||||
> NIMBLE_PROPERTY::NOTIFY
|
||||
> NIMBLE_PROPERTY::INDICATE
|
||||
|
||||
<br/>
|
||||
@@ -114,7 +114,7 @@ BLECharacteristic *pCharacteristic = pService->createCharacteristic(
|
||||
|
||||
`BLECharacteristicCallbacks` (`NimBLECharacteristicCallbacks`) has a new method `NimBLECharacteristicCallbacks::onSubscribe` which is called when a client subscribes to notifications/indications.
|
||||
|
||||
**Note:** All callback methods have default implementations which allows the application to implement only the methods applicable.
|
||||
**Note:** All callback methods have default implementations which allows the application to implement only the methods applicable.
|
||||
<br/>
|
||||
|
||||
> BLECharacteristic::getData
|
||||
@@ -172,7 +172,7 @@ pDescriptor = pCharacteristic->createDescriptor("ABCD",
|
||||
NIMBLE_PROPERTY::WRITE_ENC,
|
||||
25);
|
||||
```
|
||||
Would create a descriptor with the UUID 0xABCD, publicly readable but only writable if paired/bonded (encrypted) and has a max value length of 25 bytes.
|
||||
Would create a descriptor with the UUID 0xABCD, publicly readable but only writable if paired/bonded (encrypted) and has a max value length of 25 bytes.
|
||||
<br/>
|
||||
|
||||
For the 0x2904, there is a special class that is created when you call `createDescriptor("2904").
|
||||
@@ -189,18 +189,18 @@ p2904 = (NimBLE2904*)pCharacteristic->createDescriptor("2904");
|
||||
<a name="server-security"></a>
|
||||
### Server Security
|
||||
Security is set on the characteristic or descriptor properties by applying one of the following:
|
||||
> NIMBLE_PROPERTY::READ_ENC
|
||||
> NIMBLE_PROPERTY::READ_AUTHEN
|
||||
> NIMBLE_PROPERTY::READ_AUTHOR
|
||||
> NIMBLE_PROPERTY::WRITE_ENC
|
||||
> NIMBLE_PROPERTY::WRITE_AUTHEN
|
||||
> NIMBLE_PROPERTY::READ_ENC
|
||||
> NIMBLE_PROPERTY::READ_AUTHEN
|
||||
> NIMBLE_PROPERTY::READ_AUTHOR
|
||||
> NIMBLE_PROPERTY::WRITE_ENC
|
||||
> NIMBLE_PROPERTY::WRITE_AUTHEN
|
||||
> NIMBLE_PROPERTY::WRITE_AUTHOR
|
||||
|
||||
<br/>
|
||||
|
||||
When a peer wants to read or write a characteristic or descriptor with any of these properties applied it will trigger the pairing process. By default the "just-works" pairing will be performed automatically.
|
||||
|
||||
This can be changed to use passkey authentication or numeric comparison. See [Security API](#security-api) for details.
|
||||
This can be changed to use passkey authentication or numeric comparison. See [Security API](#security-api) for details.
|
||||
<br/>
|
||||
|
||||
<a name="advertising-api"></a>
|
||||
@@ -208,13 +208,13 @@ This can be changed to use passkey authentication or numeric comparison. See [Se
|
||||
Advertising works the same as the original API except:
|
||||
|
||||
Calling `NimBLEAdvertising::setAdvertisementData` will entirely replace any data set with `NimBLEAdvertising::addServiceUUID`, or
|
||||
`NimBLEAdvertising::setAppearance` or similar methods. You should set all the data you wish to advertise within the `NimBLEAdvertisementData` instead.
|
||||
`NimBLEAdvertising::setAppearance` or similar methods. You should set all the data you wish to advertise within the `NimBLEAdvertisementData` instead.
|
||||
<br/>
|
||||
|
||||
> BLEAdvertising::start (NimBLEAdvertising::start)
|
||||
|
||||
Now takes 2 optional parameters, the first is the duration to advertise for (in seconds), the second is a callback that is invoked when advertsing ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API).
|
||||
This provides an opportunity to update the advertisment data if desired.
|
||||
Now takes 2 optional parameters, the first is the duration to advertise for (in seconds), the second is a callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API).
|
||||
This provides an opportunity to update the advertisement data if desired.
|
||||
<br/>
|
||||
|
||||
<a name="client-api"></a>
|
||||
@@ -226,26 +226,26 @@ Multiple client instances can be created, up to the maximum number of connection
|
||||
|
||||
`BLEClient::connect`(`NimBLEClient::connect`) Has had it's parameters altered.
|
||||
Defined as:
|
||||
> NimBLEClient::connect(bool deleteServices = true);
|
||||
> NimBLEClient::connect(NimBLEAdvertisedDevice\* device, bool deleteServices = true);
|
||||
> NimBLEClient::connect(bool deleteServices = true);
|
||||
> NimBLEClient::connect(NimBLEAdvertisedDevice\* device, bool deleteServices = true);
|
||||
> NimBLEClient::connect(NimBLEAddress address, bool deleteServices = true);
|
||||
|
||||
The type parameter has been removed and a new bool parameter has been added to indicate if the client should delete the attribute database previously retrieved (if applicable) for the peripheral, default value is true.
|
||||
|
||||
If set to false the client will use the attribute database it retrieved from the peripheral when previously connected.
|
||||
|
||||
This allows for faster connections and power saving if the devices dropped connection and are reconnecting.
|
||||
This allows for faster connections and power saving if the devices dropped connection and are reconnecting.
|
||||
<br/>
|
||||
|
||||
> `BLEClient::getServices` (`NimBLEClient::getServices`)
|
||||
|
||||
This method now takes an optional (bool) parameter to indicate if the services should be retrieved from the server (true) or the currently known database returned (false : default).
|
||||
Also now returns a pointer to `std::vector` instead of `std::map`.
|
||||
This method now takes an optional (bool) parameter to indicate if the services should be retrieved from the server (true) or the currently known database returned (false : default).
|
||||
Also now returns a pointer to `std::vector` instead of `std::map`.
|
||||
<br/>
|
||||
|
||||
**Removed:** the automatic discovery of all peripheral attributes as they consumed time and resources for data the user may not be interested in.
|
||||
|
||||
**Added:** `NimBLEClient::discoverAttributes` for the user to discover all the peripheral attributes to replace the the removed automatic functionality.
|
||||
**Added:** `NimBLEClient::discoverAttributes` for the user to discover all the peripheral attributes to replace the the removed automatic functionality.
|
||||
<br/>
|
||||
|
||||
<a name="remote-services"></a>
|
||||
@@ -254,50 +254,50 @@ Also now returns a pointer to `std::vector` instead of `std::map`.
|
||||
|
||||
> BLERemoteService::getCharacteristicsByHandle
|
||||
|
||||
This method has been removed.
|
||||
This method has been removed.
|
||||
<br/>
|
||||
|
||||
> `BLERemoteService::getCharacteristics` (`NimBLERemoteService::getCharacteristics`)
|
||||
|
||||
This method now takes an optional (bool) parameter to indicate if the characteristics should be retrieved from the server (true) or
|
||||
the currently known database returned (false : default).
|
||||
Also now returns a pointer to `std::vector` instead of `std::map`.
|
||||
the currently known database returned (false : default).
|
||||
Also now returns a pointer to `std::vector` instead of `std::map`.
|
||||
<br/>
|
||||
|
||||
<a name="remote-characteristics"></a>
|
||||
### Remote Characteristics
|
||||
`BLERemoteCharacteristic` (`NimBLERemoteCharacteristic`)
|
||||
`BLERemoteCharacteristic` (`NimBLERemoteCharacteristic`)
|
||||
There have been a few changes to the methods in this class:
|
||||
|
||||
> `BLERemoteCharacteristic::writeValue` (`NimBLERemoteCharacteristic::writeValue`)
|
||||
> `BLERemoteCharacteristic::writeValue` (`NimBLERemoteCharacteristic::writeValue`)
|
||||
> `BLERemoteCharacteristic::registerForNotify` (`NimBLERemoteCharacteristic::registerForNotify`)
|
||||
|
||||
Now return true or false to indicate success or failure so you can choose to disconnect or try again.
|
||||
Now return true or false to indicate success or failure so you can choose to disconnect or try again.
|
||||
<br/>
|
||||
|
||||
> `BLERemoteCharacteristic::registerForNotify` (`NimBLERemoteCharacteristic::registerForNotify`)
|
||||
|
||||
Is now **deprecated**.
|
||||
> `NimBLERemoteCharacteristic::subscribe`
|
||||
> `NimBLERemoteCharacteristic::subscribe`
|
||||
> `NimBLERemoteCharacteristic::unsubscribe`
|
||||
|
||||
Are the new methods added to replace it.
|
||||
Are the new methods added to replace it.
|
||||
<br/>
|
||||
|
||||
> `BLERemoteCharacteristic::readUInt8` (`NimBLERemoteCharacteristic::readUInt8`)
|
||||
> `BLERemoteCharacteristic::readUInt16` (`NimBLERemoteCharacteristic::readUInt16`)
|
||||
> `BLERemoteCharacteristic::readUInt32` (`NimBLERemoteCharacteristic::readUInt32`)
|
||||
> `BLERemoteCharacteristic::readUInt8` (`NimBLERemoteCharacteristic::readUInt8`)
|
||||
> `BLERemoteCharacteristic::readUInt16` (`NimBLERemoteCharacteristic::readUInt16`)
|
||||
> `BLERemoteCharacteristic::readUInt32` (`NimBLERemoteCharacteristic::readUInt32`)
|
||||
> `BLERemoteCharacteristic::readFloat` (`NimBLERemoteCharacteristic::readFloat`)
|
||||
|
||||
Are **deprecated** a template: `NimBLERemoteCharacteristic::readValue<type\>(time_t\*, bool)` has been added to replace them.
|
||||
Are **deprecated** a template: `NimBLERemoteCharacteristic::readValue<type\>(time_t\*, bool)` has been added to replace them.
|
||||
<br/>
|
||||
|
||||
> `BLERemoteCharacteristic::readRawData`
|
||||
|
||||
**Has been removed from the API**
|
||||
Originally it stored an unnecessary copy of the data and was returning a `uint8_t` pointer to volatile internal data.
|
||||
Originally it stored an unnecessary copy of the data and was returning a `uint8_t` pointer to volatile internal data.
|
||||
The user application should use `NimBLERemoteCharacteristic::readValue` or `NimBLERemoteCharacteristic::getValue`.
|
||||
To obatain a copy of the data, then cast the returned std::string to the type required such as:
|
||||
To obtain a copy of the data, then cast the returned std::string to the type required such as:
|
||||
```
|
||||
std::string value = pChr->readValue();
|
||||
uint8_t *data = (uint8_t*)value.data();
|
||||
@@ -311,61 +311,61 @@ my_struct_t myStruct = pChr->readValue<my_struct_t>();
|
||||
> `BLERemoteCharacteristic::getDescriptors` (`NimBLERemoteCharacteristic::getDescriptors`)
|
||||
|
||||
This method now takes an optional (bool) parameter to indicate if the descriptors should be retrieved from the server (true) or
|
||||
the currently known database returned (false : default).
|
||||
Also now returns a pointer to `std::vector` instead of `std::map`.
|
||||
the currently known database returned (false : default).
|
||||
Also now returns a pointer to `std::vector` instead of `std::map`.
|
||||
<br/>
|
||||
|
||||
<a name="client-security"></a>
|
||||
### Client Security
|
||||
The client will automatically initiate security when the peripheral responds that it's required.
|
||||
The default configuration will use "just-works" pairing with no bonding, if you wish to enable bonding see below.
|
||||
The client will automatically initiate security when the peripheral responds that it's required.
|
||||
The default configuration will use "just-works" pairing with no bonding, if you wish to enable bonding see below.
|
||||
<br/>
|
||||
|
||||
<a name="security-api"></a>
|
||||
## Security API
|
||||
Security operations have been moved to `BLEDevice` (`NimBLEDevice`).
|
||||
|
||||
Also security callback methods are now incorporated in the `NimBLEServerCallbacks` / `NimBLEClientCallbacks` classes.
|
||||
Also security callback methods are now incorporated in the `NimBLEServerCallbacks` / `NimBLEClientCallbacks` classes.
|
||||
However backward compatibility with the original `BLESecurity` (`NimBLESecurity`) class is retained to minimize application code changes.
|
||||
|
||||
The callback methods are:
|
||||
|
||||
> `bool onConfirmPIN(uint32_t pin)`
|
||||
|
||||
Receives the pin when using numeric comparison authentication, `return true;` to accept.
|
||||
Receives the pin when using numeric comparison authentication, `return true;` to accept.
|
||||
<br/>
|
||||
|
||||
> `uint32_t onPassKeyRequest()`
|
||||
|
||||
For server callback; return the passkey expected from the client.
|
||||
For client callback; return the passkey to send to the server.
|
||||
For server callback; return the passkey expected from the client.
|
||||
For client callback; return the passkey to send to the server.
|
||||
<br/>
|
||||
|
||||
> `void onAuthenticationComplete(ble_gap_conn_desc\* desc)`
|
||||
|
||||
Authentication complete, success or failed information is in `desc`.
|
||||
Authentication complete, success or failed information is in `desc`.
|
||||
<br/>
|
||||
|
||||
Security settings and IO capabilities are now set by the following methods of NimBLEDevice.
|
||||
> `NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc)`
|
||||
> `NimBLEDevice::setSecurityAuth(bool bonding, bool mitm, bool sc)`
|
||||
> `NimBLEDevice::setSecurityAuth(uint8_t auth_req)`
|
||||
|
||||
Sets the authorization mode for this device.
|
||||
Sets the authorization mode for this device.
|
||||
<br/>
|
||||
|
||||
> `NimBLEDevice::setSecurityIOCap(uint8_t iocap)`
|
||||
|
||||
Sets the Input/Output capabilities of this device.
|
||||
Sets the Input/Output capabilities of this device.
|
||||
<br/>
|
||||
|
||||
> `NimBLEDevice::setSecurityInitKey(uint8_t init_key)`
|
||||
|
||||
If we are the initiator of the security procedure this sets the keys we will distribute.
|
||||
If we are the initiator of the security procedure this sets the keys we will distribute.
|
||||
<br/>
|
||||
|
||||
> `NimBLEDevice::setSecurityRespKey(uint8_t resp_key)`
|
||||
|
||||
Sets the keys we are willing to accept from the peer during pairing.
|
||||
Sets the keys we are willing to accept from the peer during pairing.
|
||||
<br/>
|
||||
|
||||
<a name="arduino-configuration"></a>
|
||||
@@ -375,5 +375,5 @@ Unlike the original library pre-packaged in the esp32-arduino, this library has
|
||||
|
||||
This allows Arduino users to fully customize the build, such as increasing max connections or loading the BLE stack into external PSRAM.
|
||||
|
||||
For details on the options, they are fully commented in *nimconfig.h*
|
||||
For details on the options, they are fully commented in *nimconfig.h*
|
||||
<br/>
|
||||
|
||||
70
lib/NimBLE-Arduino/docs/index.md
Normal file
70
lib/NimBLE-Arduino/docs/index.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Overview
|
||||
|
||||
This is a C++ BLE library for Espressif ESP32 and Nordic nRF51/nRF52 devices that uses the NimBLE BLE stack.
|
||||
The aim is to maintain, as much as reasonable, the original ESP32 Arduino BLE API by while adding new features and making improvements in performance, resource use, and stability.
|
||||
<br/>
|
||||
|
||||
# What is NimBLE?
|
||||
NimBLE is a completely open source Bluetooth Low Energy stack produced by [Apache](https://github.com/apache/mynewt-nimble).
|
||||
<br/>
|
||||
|
||||
# Arduino installation
|
||||
**NOTE:** Nordic devices require using [n-able arduino core](https://github.com/h2zero/n-able-Arduino)
|
||||
|
||||
**Arduino Library manager:** Go to `sketch` -> `Include Library` -> `Manage Libraries` and search for NimBLE and install.
|
||||
|
||||
**Alternatively:** Download as .zip and extract to Arduino/libraries folder, or in Arduino IDE from Sketch menu -> Include library -> Add .Zip library.
|
||||
|
||||
`#include "NimBLEDevice.h"` at the beginning of your sketch.
|
||||
|
||||
Call `NimBLEDevice::init` in `setup`.
|
||||
<br/>
|
||||
|
||||
# Platformio installation
|
||||
* Open platformio.ini, a project configuration file located in the root of PlatformIO project.
|
||||
* Add the following line to the lib_deps option of [env:] section:
|
||||
```
|
||||
h2zero/NimBLE-Arduino@^1.4.0
|
||||
```
|
||||
* Build a project, PlatformIO will automatically install dependencies.
|
||||
<br/>
|
||||
|
||||
# Using
|
||||
This library is intended to be compatible with the original ESP32 BLE library functions and types with minor changes.
|
||||
|
||||
If you have not used the original BLE library please refer to the [New user guide](New_user_guide.md).
|
||||
|
||||
If you are familiar with the original library, see: [The migration guide](Migration_guide.md) for details.
|
||||
|
||||
Also see [Improvements and updates](Improvements_and_updates.md) for information about non-breaking changes.
|
||||
|
||||
For more advanced usage see [Usage tips](Usage_tips.md) for more performance and optimization.
|
||||
<br/>
|
||||
|
||||
## Examples
|
||||
See the Refactored_original_examples in the examples folder for highlights of the differences with the original library.
|
||||
|
||||
More advanced examples highlighting many available features are in examples/NimBLE_Server, NimBLE_Client.
|
||||
|
||||
Beacon examples provided by [beegee-tokyo](https://github.com/beegee-tokyo) are in examples/BLE_Beacon_Scanner, BLE_EddystoneTLM_Beacon, BLE_EddystoneURL_Beacon.
|
||||
|
||||
Change the settings in the nimconfig.h file to customize NimBLE to your project, such as increasing max connections (default is 3).
|
||||
<br/>
|
||||
|
||||
## Arduino command line and platformio
|
||||
As an alternative to changing the configuration in nimconfig.h, Arduino command line and platformio.ini options are available.
|
||||
|
||||
See the command line configuration options available in [Command line config](Command_line_config.md).
|
||||
<br/>
|
||||
|
||||
# Need help? Have a question or suggestion?
|
||||
Come chat on [gitter](https://gitter.im/NimBLE-Arduino/community?utm_source=share-link&utm_medium=link&utm_campaign=share-link) or open an issue at [NimBLE-Arduino](https://github.com/h2zero/NimBLE-Arduino/issues) or [esp-nimble-cpp](https://github.com/h2zero/esp-nimble-cpp/issues)
|
||||
<br/>
|
||||
|
||||
# Acknowledgments
|
||||
|
||||
* [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from.
|
||||
* [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples.
|
||||
* [Jeroen88](https://github.com/Jeroen88) for the amazing help debugging and improving the client code.
|
||||
<br/>
|
||||
|
||||
@@ -347,7 +347,11 @@ void setup (){
|
||||
NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
|
||||
|
||||
/** Optional: set the transmit power, default is 3db */
|
||||
#ifdef ESP_PLATFORM
|
||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9); /** +9db */
|
||||
#else
|
||||
NimBLEDevice::setPower(9); /** +9db */
|
||||
#endif
|
||||
|
||||
/** Optional: set any devices you don't want to get advertisments from */
|
||||
// NimBLEDevice::addIgnored(NimBLEAddress ("aa:bb:cc:dd:ee:ff"));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** NimBLE_Secure_Client Demo:
|
||||
*
|
||||
*
|
||||
* This example demonstrates the secure passkey protected conenction and communication between an esp32 server and an esp32 client.
|
||||
* Please note that esp32 stores auth info in nvs memory. After a successful connection it is possible that a passkey change will be ineffective.
|
||||
* To avoid this clear the memory of the esp32's between security testings. esptool.py is capable of this, example: esptool.py --port /dev/ttyUSB0 erase_flash.
|
||||
@@ -7,7 +7,7 @@
|
||||
* Created: on Jan 08 2021
|
||||
* Author: mblasee
|
||||
*/
|
||||
|
||||
|
||||
#include <NimBLEDevice.h>
|
||||
|
||||
class ClientCallbacks : public NimBLEClientCallbacks
|
||||
@@ -28,7 +28,11 @@ void setup()
|
||||
Serial.println("Starting NimBLE Client");
|
||||
|
||||
NimBLEDevice::init("");
|
||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
||||
#ifdef ESP_PLATFORM
|
||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9); /** +9db */
|
||||
#else
|
||||
NimBLEDevice::setPower(9); /** +9db */
|
||||
#endif
|
||||
NimBLEDevice::setSecurityAuth(true, true, true);
|
||||
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_KEYBOARD_ONLY);
|
||||
NimBLEScan *pScan = NimBLEDevice::getScan();
|
||||
@@ -53,7 +57,7 @@ void setup()
|
||||
if (pService != nullptr)
|
||||
{
|
||||
NimBLERemoteCharacteristic *pNonSecureCharacteristic = pService->getCharacteristic("1234");
|
||||
|
||||
|
||||
if (pNonSecureCharacteristic != nullptr)
|
||||
{
|
||||
// Testing to read a non secured characteristic, you should be able to read this even if you have mismatching passkeys.
|
||||
@@ -68,11 +72,11 @@ void setup()
|
||||
{
|
||||
// Testing to read a secured characteristic, you should be able to read this only if you have matching passkeys, otherwise you should
|
||||
// get an error like this. E NimBLERemoteCharacteristic: "<< readValue rc=261"
|
||||
// This means you are trying to do something without the proper permissions.
|
||||
// This means you are trying to do something without the proper permissions.
|
||||
std::string value = pSecureCharacteristic->readValue();
|
||||
// print or do whatever you need with the value
|
||||
Serial.println(value.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** NimBLE_Secure_Server Demo:
|
||||
*
|
||||
*
|
||||
* This example demonstrates the secure passkey protected conenction and communication between an esp32 server and an esp32 client.
|
||||
* Please note that esp32 stores auth info in nvs memory. After a successful connection it is possible that a passkey change will be ineffective.
|
||||
* To avoid this clear the memory of the esp32's between security testings. esptool.py is capable of this, example: esptool.py --port /dev/ttyUSB0 erase_flash.
|
||||
@@ -14,7 +14,11 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println("Starting NimBLE Server");
|
||||
NimBLEDevice::init("NimBLE");
|
||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9);
|
||||
#ifdef ESP_PLATFORM
|
||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9); /** +9db */
|
||||
#else
|
||||
NimBLEDevice::setPower(9); /** +9db */
|
||||
#endif
|
||||
|
||||
NimBLEDevice::setSecurityAuth(true, true, true);
|
||||
NimBLEDevice::setSecurityPasskey(123456);
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
/** NimBLE_Server Demo:
|
||||
*
|
||||
* Demonstrates many of the available features of the NimBLE server library.
|
||||
*
|
||||
*
|
||||
* Created: on March 22 2020
|
||||
* Author: H2zero
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <NimBLEDevice.h>
|
||||
@@ -13,16 +13,16 @@
|
||||
static NimBLEServer* pServer;
|
||||
|
||||
/** None of these are required as they will be handled by the library with defaults. **
|
||||
** Remove as you see fit for your needs */
|
||||
** Remove as you see fit for your needs */
|
||||
class ServerCallbacks: public NimBLEServerCallbacks {
|
||||
void onConnect(NimBLEServer* pServer) {
|
||||
Serial.println("Client connected");
|
||||
Serial.println("Multi-connect support: start advertising");
|
||||
NimBLEDevice::startAdvertising();
|
||||
};
|
||||
/** Alternative onConnect() method to extract details of the connection.
|
||||
/** Alternative onConnect() method to extract details of the connection.
|
||||
* See: src/ble_gap.h for the details of the ble_gap_conn_desc struct.
|
||||
*/
|
||||
*/
|
||||
void onConnect(NimBLEServer* pServer, ble_gap_conn_desc* desc) {
|
||||
Serial.print("Client address: ");
|
||||
Serial.println(NimBLEAddress(desc->peer_ota_addr).toString().c_str());
|
||||
@@ -31,7 +31,7 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
||||
* latency, supervision timeout.
|
||||
* Units; Min/Max Intervals: 1.25 millisecond increments.
|
||||
* Latency: number of intervals allowed to skip.
|
||||
* Timeout: 10 millisecond increments, try for 5x interval time for best results.
|
||||
* Timeout: 10 millisecond increments, try for 5x interval time for best results.
|
||||
*/
|
||||
pServer->updateConnParams(desc->conn_handle, 24, 48, 0, 60);
|
||||
};
|
||||
@@ -42,25 +42,25 @@ class ServerCallbacks: public NimBLEServerCallbacks {
|
||||
void onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc) {
|
||||
Serial.printf("MTU updated: %u for connection ID: %u\n", MTU, desc->conn_handle);
|
||||
};
|
||||
|
||||
|
||||
/********************* Security handled here **********************
|
||||
****** Note: these are the same return values as defaults ********/
|
||||
uint32_t onPassKeyRequest(){
|
||||
Serial.println("Server Passkey Request");
|
||||
/** This should return a random 6 digit number for security
|
||||
/** This should return a random 6 digit number for security
|
||||
* or make your own static passkey as done here.
|
||||
*/
|
||||
return 123456;
|
||||
return 123456;
|
||||
};
|
||||
|
||||
bool onConfirmPIN(uint32_t pass_key){
|
||||
Serial.print("The passkey YES/NO number: ");Serial.println(pass_key);
|
||||
/** Return false if passkeys don't match. */
|
||||
return true;
|
||||
return true;
|
||||
};
|
||||
|
||||
void onAuthenticationComplete(ble_gap_conn_desc* desc){
|
||||
/** Check that encryption was successful, if not we disconnect the client */
|
||||
/** Check that encryption was successful, if not we disconnect the client */
|
||||
if(!desc->sec_state.encrypted) {
|
||||
NimBLEDevice::getServer()->disconnect(desc->conn_handle);
|
||||
Serial.println("Encrypt connection failed - disconnecting client");
|
||||
@@ -83,7 +83,7 @@ class CharacteristicCallbacks: public NimBLECharacteristicCallbacks {
|
||||
Serial.print(": onWrite(), value: ");
|
||||
Serial.println(pCharacteristic->getValue().c_str());
|
||||
};
|
||||
/** Called before notification or indication is sent,
|
||||
/** Called before notification or indication is sent,
|
||||
* the value can be changed here before sending if desired.
|
||||
*/
|
||||
void onNotify(NimBLECharacteristic* pCharacteristic) {
|
||||
@@ -99,7 +99,7 @@ class CharacteristicCallbacks: public NimBLECharacteristicCallbacks {
|
||||
str += status;
|
||||
str += ", return code: ";
|
||||
str += code;
|
||||
str += ", ";
|
||||
str += ", ";
|
||||
str += NimBLEUtils::returnCodeToString(code);
|
||||
Serial.println(str);
|
||||
};
|
||||
@@ -123,8 +123,8 @@ class CharacteristicCallbacks: public NimBLECharacteristicCallbacks {
|
||||
Serial.println(str);
|
||||
};
|
||||
};
|
||||
|
||||
/** Handler class for descriptor actions */
|
||||
|
||||
/** Handler class for descriptor actions */
|
||||
class DescriptorCallbacks : public NimBLEDescriptorCallbacks {
|
||||
void onWrite(NimBLEDescriptor* pDescriptor) {
|
||||
std::string dscVal = pDescriptor->getValue();
|
||||
@@ -139,7 +139,7 @@ class DescriptorCallbacks : public NimBLEDescriptorCallbacks {
|
||||
};
|
||||
|
||||
|
||||
/** Define callback instances globally to use for multiple Charateristics \ Descriptors */
|
||||
/** Define callback instances globally to use for multiple Charateristics \ Descriptors */
|
||||
static DescriptorCallbacks dscCallbacks;
|
||||
static CharacteristicCallbacks chrCallbacks;
|
||||
|
||||
@@ -152,8 +152,12 @@ void setup() {
|
||||
NimBLEDevice::init("NimBLE-Arduino");
|
||||
|
||||
/** Optional: set the transmit power, default is 3db */
|
||||
#ifdef ESP_PLATFORM
|
||||
NimBLEDevice::setPower(ESP_PWR_LVL_P9); /** +9db */
|
||||
|
||||
#else
|
||||
NimBLEDevice::setPower(9); /** +9db */
|
||||
#endif
|
||||
|
||||
/** Set the IO capabilities of the device, each option will trigger a different pairing method.
|
||||
* BLE_HS_IO_DISPLAY_ONLY - Passkey pairing
|
||||
* BLE_HS_IO_DISPLAY_YESNO - Numeric comparison pairing
|
||||
@@ -164,10 +168,10 @@ void setup() {
|
||||
|
||||
/** 2 different ways to set security - both calls achieve the same result.
|
||||
* no bonding, no man in the middle protection, secure connections.
|
||||
*
|
||||
* These are the default values, only shown here for demonstration.
|
||||
*/
|
||||
//NimBLEDevice::setSecurityAuth(false, false, true);
|
||||
*
|
||||
* These are the default values, only shown here for demonstration.
|
||||
*/
|
||||
//NimBLEDevice::setSecurityAuth(false, false, true);
|
||||
NimBLEDevice::setSecurityAuth(/*BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM |*/ BLE_SM_PAIR_AUTHREQ_SC);
|
||||
|
||||
pServer = NimBLEDevice::createServer();
|
||||
@@ -182,7 +186,7 @@ void setup() {
|
||||
NIMBLE_PROPERTY::READ_ENC | // only allow reading if paired / encrypted
|
||||
NIMBLE_PROPERTY::WRITE_ENC // only allow writing if paired / encrypted
|
||||
);
|
||||
|
||||
|
||||
pBeefCharacteristic->setValue("Burger");
|
||||
pBeefCharacteristic->setCallbacks(&chrCallbacks);
|
||||
|
||||
@@ -191,10 +195,10 @@ void setup() {
|
||||
* However we must cast the returned reference to the correct type as the method
|
||||
* only returns a pointer to the base NimBLEDescriptor class.
|
||||
*/
|
||||
NimBLE2904* pBeef2904 = (NimBLE2904*)pBeefCharacteristic->createDescriptor("2904");
|
||||
NimBLE2904* pBeef2904 = (NimBLE2904*)pBeefCharacteristic->createDescriptor("2904");
|
||||
pBeef2904->setFormat(NimBLE2904::FORMAT_UTF8);
|
||||
pBeef2904->setCallbacks(&dscCallbacks);
|
||||
|
||||
|
||||
|
||||
NimBLEService* pBaadService = pServer->createService("BAAD");
|
||||
NimBLECharacteristic* pFoodCharacteristic = pBaadService->createCharacteristic(
|
||||
@@ -214,7 +218,7 @@ void setup() {
|
||||
/** Custom descriptor: Arguments are UUID, Properties, max length in bytes of the value */
|
||||
NimBLEDescriptor* pC01Ddsc = pFoodCharacteristic->createDescriptor(
|
||||
"C01D",
|
||||
NIMBLE_PROPERTY::READ |
|
||||
NIMBLE_PROPERTY::READ |
|
||||
NIMBLE_PROPERTY::WRITE|
|
||||
NIMBLE_PROPERTY::WRITE_ENC, // only allow writing if paired / encrypted
|
||||
20
|
||||
@@ -222,7 +226,7 @@ void setup() {
|
||||
pC01Ddsc->setValue("Send it back!");
|
||||
pC01Ddsc->setCallbacks(&dscCallbacks);
|
||||
|
||||
/** Start the services when finished creating all Characteristics and Descriptors */
|
||||
/** Start the services when finished creating all Characteristics and Descriptors */
|
||||
pDeadService->start();
|
||||
pBaadService->start();
|
||||
|
||||
@@ -251,6 +255,6 @@ void loop() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
name=NimBLE-Arduino
|
||||
version=1.3.9
|
||||
version=1.4.0
|
||||
author=h2zero
|
||||
maintainer=h2zero <powellperalta@gmail.com>
|
||||
sentence=Bluetooth low energy (BLE) library for arduino-esp32 based on NimBLE.
|
||||
paragraph=This is a more updated and lower resource alternative to the original bluedroid BLE library for esp32. Uses 50% less flash space and approximately 100KB less ram with the same functionality. Nearly 100% compatible with existing application code, migration guide included.
|
||||
url=https://github.com/h2zero/NimBLE-Arduino
|
||||
category=Communication
|
||||
architectures=esp32
|
||||
architectures=esp32,arm-ble
|
||||
includes=NimBLEDevice.h
|
||||
@@ -22,11 +22,11 @@
|
||||
#include "NimBLE2904.h"
|
||||
|
||||
|
||||
NimBLE2904::NimBLE2904(NimBLECharacteristic* pCharacterisitic)
|
||||
NimBLE2904::NimBLE2904(NimBLECharacteristic* pCharacteristic)
|
||||
: NimBLEDescriptor(NimBLEUUID((uint16_t) 0x2904),
|
||||
BLE_GATT_CHR_F_READ,
|
||||
sizeof(BLE2904_Data),
|
||||
pCharacterisitic)
|
||||
pCharacteristic)
|
||||
{
|
||||
m_data.m_format = 0;
|
||||
m_data.m_exponent = 0;
|
||||
|
||||
@@ -156,7 +156,7 @@ std::string NimBLEAddress::toString() const {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convienience operator to check if this address is equal to another.
|
||||
* @brief Convenience operator to check if this address is equal to another.
|
||||
*/
|
||||
bool NimBLEAddress::operator ==(const NimBLEAddress & rhs) const {
|
||||
return memcmp(rhs.m_address, m_address, sizeof m_address) == 0;
|
||||
@@ -164,7 +164,7 @@ bool NimBLEAddress::operator ==(const NimBLEAddress & rhs) const {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convienience operator to check if this address is not equal to another.
|
||||
* @brief Convenience operator to check if this address is not equal to another.
|
||||
*/
|
||||
bool NimBLEAddress::operator !=(const NimBLEAddress & rhs) const {
|
||||
return !this->operator==(rhs);
|
||||
@@ -186,7 +186,7 @@ NimBLEAddress::operator std::string() const {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convienience operator to convert the native address representation to uint_64.
|
||||
* @brief Convenience operator to convert the native address representation to uint_64.
|
||||
*/
|
||||
NimBLEAddress::operator uint64_t() const {
|
||||
uint64_t address = 0;
|
||||
|
||||
@@ -52,9 +52,9 @@ NimBLEAddress NimBLEAdvertisedDevice::getAddress() {
|
||||
* @brief Get the advertisement type.
|
||||
* @return The advertising type the device is reporting:
|
||||
* * BLE_HCI_ADV_TYPE_ADV_IND (0) - indirect advertising
|
||||
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) - direct advertisng - high duty cycle
|
||||
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) - direct advertising - high duty cycle
|
||||
* * BLE_HCI_ADV_TYPE_ADV_SCAN_IND (2) - indirect scan response
|
||||
* * BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) - indirect advertisng - not connectable
|
||||
* * BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) - indirect advertising - not connectable
|
||||
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD (4) - direct advertising - low duty cycle
|
||||
*/
|
||||
uint8_t NimBLEAdvertisedDevice::getAdvType() {
|
||||
@@ -66,7 +66,7 @@ uint8_t NimBLEAdvertisedDevice::getAdvType() {
|
||||
* @brief Get the appearance.
|
||||
*
|
||||
* A %BLE device can declare its own appearance. The appearance is how it would like to be shown to an end user
|
||||
* typcially in the form of an icon.
|
||||
* typically in the form of an icon.
|
||||
*
|
||||
* @return The appearance of the advertised device.
|
||||
*/
|
||||
@@ -308,7 +308,7 @@ std::string NimBLEAdvertisedDevice::getServiceData(const NimBLEUUID &uuid) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the UUID of the serice data at the index.
|
||||
* @brief Get the UUID of the service data at the index.
|
||||
* @param [in] index The index of the service data UUID requested.
|
||||
* @return The advertised service data UUID or an empty UUID if not found.
|
||||
*/
|
||||
@@ -448,7 +448,7 @@ uint8_t NimBLEAdvertisedDevice::getServiceUUIDCount() {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Check advertised services for existance of the required UUID
|
||||
* @brief Check advertised services for existence of the required UUID
|
||||
* @param [in] uuid The service uuid to look for in the advertisement.
|
||||
* @return Return true if service is advertised
|
||||
*/
|
||||
@@ -794,7 +794,7 @@ void NimBLEAdvertisedDevice::setPayload(const uint8_t *payload, uint8_t length,
|
||||
|
||||
/**
|
||||
* @brief Get the length of the advertisement data in the payload.
|
||||
* @return The number of bytes in the payload that is from the advertisment.
|
||||
* @return The number of bytes in the payload that is from the advertisement.
|
||||
*/
|
||||
uint8_t NimBLEAdvertisedDevice::getAdvLength() {
|
||||
return m_advLength;
|
||||
|
||||
@@ -434,15 +434,16 @@ bool NimBLEAdvertising::start(uint32_t duration, void (*advCompleteCB)(NimBLEAdv
|
||||
if(m_advParams.conn_mode == BLE_GAP_CONN_MODE_NON) {
|
||||
if(!m_scanResp) {
|
||||
m_advParams.disc_mode = BLE_GAP_DISC_MODE_NON;
|
||||
m_advData.flags = BLE_HS_ADV_F_BREDR_UNSUP;
|
||||
// non-connectable advertising does not require AD flags.
|
||||
m_advData.flags = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
|
||||
if (!m_customAdvData && !m_advDataSet) {
|
||||
//start with 3 bytes for the flags data
|
||||
uint8_t payloadLen = (2 + 1);
|
||||
//start with 3 bytes for the flags data if required
|
||||
uint8_t payloadLen = (m_advData.flags > 0) ? (2 + 1) : 0;
|
||||
if(m_advData.mfg_data_len > 0)
|
||||
payloadLen += (2 + m_advData.mfg_data_len);
|
||||
|
||||
@@ -757,7 +758,7 @@ int NimBLEAdvertising::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
||||
*/
|
||||
void NimBLEAdvertisementData::addData(const std::string &data) {
|
||||
if ((m_payload.length() + data.length()) > BLE_HS_ADV_MAX_SZ) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Advertisement data length exceded");
|
||||
NIMBLE_LOGE(LOG_TAG, "Advertisement data length exceeded");
|
||||
return;
|
||||
}
|
||||
m_payload.append(data);
|
||||
|
||||
@@ -54,7 +54,7 @@ struct Has_c_str_len<T, decltype(void(std::declval<T &>().c_str())),
|
||||
/**
|
||||
* @brief A specialized container class to hold BLE attribute values.
|
||||
* @details This class is designed to be more memory efficient than using\n
|
||||
* standard container types for value storage, while being convertable to\n
|
||||
* standard container types for value storage, while being convertible to\n
|
||||
* many different container classes.
|
||||
*/
|
||||
class NimBLEAttValue
|
||||
|
||||
@@ -130,7 +130,7 @@ void NimBLEBeacon::setManufacturerId(uint16_t manufacturerId) {
|
||||
*/
|
||||
void NimBLEBeacon::setMinor(uint16_t minor) {
|
||||
m_beaconData.minor = ENDIAN_CHANGE_U16(minor);
|
||||
} // setMinior
|
||||
} // setMinor
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,8 +126,8 @@ void NimBLECharacteristic::addDescriptor(NimBLEDescriptor *pDescriptor) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Remove a descriptor from the characterisitc.
|
||||
* @param[in] pDescriptor A pointer to the descriptor instance to remove from the characterisitc.
|
||||
* @brief Remove a descriptor from the characteristic.
|
||||
* @param[in] pDescriptor A pointer to the descriptor instance to remove from the characteristic.
|
||||
* @param[in] deleteDsc If true it will delete the descriptor instance and free it's resources.
|
||||
*/
|
||||
void NimBLECharacteristic::removeDescriptor(NimBLEDescriptor *pDescriptor, bool deleteDsc) {
|
||||
@@ -273,11 +273,13 @@ int NimBLECharacteristic::handleGapEvent(uint16_t conn_handle, uint16_t attr_han
|
||||
if(ble_uuid_cmp(uuid, &pCharacteristic->getUUID().getNative()->u) == 0){
|
||||
switch(ctxt->op) {
|
||||
case BLE_GATT_ACCESS_OP_READ_CHR: {
|
||||
// If the packet header is only 8 bytes this is a follow up of a long read
|
||||
// so we don't want to call the onRead() callback again.
|
||||
if(ctxt->om->om_pkthdr_len > 8) {
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
|
||||
// If the packet header is only 8 bytes this is a follow up of a long read
|
||||
// so we don't want to call the onRead() callback again.
|
||||
if(ctxt->om->om_pkthdr_len > 8 ||
|
||||
pCharacteristic->m_value.size() <= (ble_att_mtu(desc.conn_handle) - 3)) {
|
||||
pCharacteristic->m_pCallbacks->onRead(pCharacteristic);
|
||||
pCharacteristic->m_pCallbacks->onRead(pCharacteristic, &desc);
|
||||
}
|
||||
@@ -440,7 +442,7 @@ void NimBLECharacteristic::notify(const uint8_t* value, size_t length, bool is_n
|
||||
!(m_properties & NIMBLE_PROPERTY::INDICATE))
|
||||
{
|
||||
NIMBLE_LOGE(LOG_TAG,
|
||||
"<< notify-Error; Notify/indicate not enabled for characterisitc: %s",
|
||||
"<< notify-Error; Notify/indicate not enabled for characteristic: %s",
|
||||
std::string(getUUID()).c_str());
|
||||
}
|
||||
|
||||
|
||||
@@ -157,35 +157,35 @@ size_t NimBLEClient::deleteService(const NimBLEUUID &uuid) {
|
||||
|
||||
/**
|
||||
* @brief Connect to the BLE Server.
|
||||
* @param [in] deleteAttibutes If true this will delete any attribute objects this client may already\n
|
||||
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
|
||||
* have created and clears the vectors after successful connection.
|
||||
* @return True on success.
|
||||
*/
|
||||
bool NimBLEClient::connect(bool deleteAttibutes) {
|
||||
return connect(m_peerAddress, deleteAttibutes);
|
||||
bool NimBLEClient::connect(bool deleteAttributes) {
|
||||
return connect(m_peerAddress, deleteAttributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Connect to an advertising device.
|
||||
* @param [in] device The device to connect to.
|
||||
* @param [in] deleteAttibutes If true this will delete any attribute objects this client may already\n
|
||||
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
|
||||
* have created and clears the vectors after successful connection.
|
||||
* @return True on success.
|
||||
*/
|
||||
bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes) {
|
||||
bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttributes) {
|
||||
NimBLEAddress address(device->getAddress());
|
||||
return connect(address, deleteAttibutes);
|
||||
return connect(address, deleteAttributes);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to the BLE Server.
|
||||
* @param [in] address The address of the server.
|
||||
* @param [in] deleteAttibutes If true this will delete any attribute objects this client may already\n
|
||||
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
|
||||
* have created and clears the vectors after successful connection.
|
||||
* @return True on success.
|
||||
*/
|
||||
bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
||||
bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str());
|
||||
|
||||
if(!NimBLEDevice::m_synced) {
|
||||
@@ -259,7 +259,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
||||
break;
|
||||
|
||||
case BLE_HS_EALREADY:
|
||||
// Already attemting to connect to this device, cancel the previous
|
||||
// Already attempting to connect to this device, cancel the previous
|
||||
// attempt and report failure here so we don't get 2 connections.
|
||||
NIMBLE_LOGE(LOG_TAG, "Already attempting to connect to %s - cancelling",
|
||||
std::string(m_peerAddress).c_str());
|
||||
@@ -317,7 +317,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
||||
NIMBLE_LOGI(LOG_TAG, "Connection established");
|
||||
}
|
||||
|
||||
if(deleteAttibutes) {
|
||||
if(deleteAttributes) {
|
||||
deleteServices();
|
||||
}
|
||||
|
||||
@@ -390,8 +390,8 @@ int NimBLEClient::disconnect(uint8_t reason) {
|
||||
// We use a timer to detect a controller error in the event that it does
|
||||
// not inform the stack when disconnection is complete.
|
||||
// This is a common error in certain esp-idf versions.
|
||||
// The disconnect timeout time is the supervison timeout time + 1 second.
|
||||
// In the case that the event happenss shortly after the supervision timeout
|
||||
// The disconnect timeout time is the supervision timeout time + 1 second.
|
||||
// In the case that the event happens shortly after the supervision timeout
|
||||
// we don't want to prematurely reset the host.
|
||||
ble_npl_time_t ticks;
|
||||
ble_npl_time_ms_to_ticks((desc.supervision_timeout + 100) * 10, &ticks);
|
||||
@@ -431,7 +431,7 @@ void NimBLEClient::setConnectPhy(uint8_t mask) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the connection paramaters to use when connecting to a server.
|
||||
* @brief Set the connection parameters to use when connecting to a server.
|
||||
* @param [in] minInterval The minimum connection interval in 1.25ms units.
|
||||
* @param [in] maxInterval The maximum connection interval in 1.25ms units.
|
||||
* @param [in] latency The number of packets allowed to skip (extends max interval).
|
||||
|
||||
@@ -38,9 +38,9 @@ class NimBLEAdvertisedDevice;
|
||||
*/
|
||||
class NimBLEClient {
|
||||
public:
|
||||
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes = true);
|
||||
bool connect(const NimBLEAddress &address, bool deleteAttibutes = true);
|
||||
bool connect(bool deleteAttibutes = true);
|
||||
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttributes = true);
|
||||
bool connect(const NimBLEAddress &address, bool deleteAttributes = true);
|
||||
bool connect(bool deleteAttributes = true);
|
||||
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
|
||||
NimBLEAddress getPeerAddress();
|
||||
void setPeerAddress(const NimBLEAddress &address);
|
||||
@@ -137,7 +137,7 @@ public:
|
||||
* @brief Called when server requests to update the connection parameters.
|
||||
* @param [in] pClient A pointer to the calling client object.
|
||||
* @param [in] params A pointer to the struct containing the connection parameters requested.
|
||||
* @return True to accept the parmeters.
|
||||
* @return True to accept the parameters.
|
||||
*/
|
||||
virtual bool onConnParamsUpdateRequest(NimBLEClient* pClient, const ble_gap_upd_params* params);
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
|
||||
|
||||
const ble_uuid_t *uuid;
|
||||
int rc;
|
||||
struct ble_gap_conn_desc desc;
|
||||
NimBLEDescriptor* pDescriptor = (NimBLEDescriptor*)arg;
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "Descriptor %s %s event", pDescriptor->getUUID().toString().c_str(),
|
||||
@@ -164,9 +165,13 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
|
||||
if(ble_uuid_cmp(uuid, &pDescriptor->getUUID().getNative()->u) == 0){
|
||||
switch(ctxt->op) {
|
||||
case BLE_GATT_ACCESS_OP_READ_DSC: {
|
||||
// If the packet header is only 8 bytes this is a follow up of a long read
|
||||
// so we don't want to call the onRead() callback again.
|
||||
if(ctxt->om->om_pkthdr_len > 8) {
|
||||
rc = ble_gap_conn_find(conn_handle, &desc);
|
||||
assert(rc == 0);
|
||||
|
||||
// If the packet header is only 8 bytes this is a follow up of a long read
|
||||
// so we don't want to call the onRead() callback again.
|
||||
if(ctxt->om->om_pkthdr_len > 8 ||
|
||||
pDescriptor->m_value.size() <= (ble_att_mtu(desc.conn_handle) - 3)) {
|
||||
pDescriptor->m_pCallbacks->onRead(pDescriptor);
|
||||
}
|
||||
|
||||
@@ -256,7 +261,7 @@ void NimBLEDescriptor::setValue(const std::vector<uint8_t>& vec) {
|
||||
|
||||
/**
|
||||
* @brief Set the characteristic this descriptor belongs to.
|
||||
* @param [in] pChar A pointer to the characteristic this descriptior belongs to.
|
||||
* @param [in] pChar A pointer to the characteristic this descriptor belongs to.
|
||||
*/
|
||||
void NimBLEDescriptor::setCharacteristic(NimBLECharacteristic* pChar) {
|
||||
m_pCharacteristic = pChar;
|
||||
|
||||
@@ -802,7 +802,7 @@ void NimBLEDevice::onSync(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Yield for houskeeping before returning to operations.
|
||||
// Yield for housekeeping before returning to operations.
|
||||
// Occasionally triggers exception without.
|
||||
taskYIELD();
|
||||
|
||||
@@ -851,7 +851,7 @@ void NimBLEDevice::init(const std::string &deviceName) {
|
||||
esp_err_t errRc = ESP_OK;
|
||||
|
||||
#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS
|
||||
// make sure the linker includes esp32-hal-bt.c so ardruino init doesn't release BLE memory.
|
||||
// make sure the linker includes esp32-hal-bt.c so Arduino init doesn't release BLE memory.
|
||||
btStarted();
|
||||
#endif
|
||||
|
||||
|
||||
@@ -85,8 +85,8 @@ float NimBLEEddystoneTLM::getTemp() {
|
||||
} // getTemp
|
||||
|
||||
/**
|
||||
* @brief Get the count of advertisments sent.
|
||||
* @return The number of advertisments.
|
||||
* @brief Get the count of advertisements sent.
|
||||
* @return The number of advertisements.
|
||||
*/
|
||||
uint32_t NimBLEEddystoneTLM::getCount() {
|
||||
return ENDIAN_CHANGE_U32(m_eddystoneData.advCount);
|
||||
@@ -94,8 +94,8 @@ uint32_t NimBLEEddystoneTLM::getCount() {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the advertisment time.
|
||||
* @return The advertisment time.
|
||||
* @brief Get the advertisement time.
|
||||
* @return The advertisement time.
|
||||
*/
|
||||
uint32_t NimBLEEddystoneTLM::getTime() {
|
||||
return (ENDIAN_CHANGE_U32(m_eddystoneData.tmil)) / 10;
|
||||
@@ -158,7 +158,7 @@ std::string NimBLEEddystoneTLM::toString() {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the raw data for the beacon advertisment.
|
||||
* @brief Set the raw data for the beacon advertisement.
|
||||
* @param [in] data The raw data to advertise.
|
||||
*/
|
||||
void NimBLEEddystoneTLM::setData(const std::string &data) {
|
||||
@@ -208,8 +208,8 @@ void NimBLEEddystoneTLM::setTemp(float temp) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the advertisment count.
|
||||
* @param [in] advCount The advertisment number.
|
||||
* @brief Set the advertisement count.
|
||||
* @param [in] advCount The advertisement number.
|
||||
*/
|
||||
void NimBLEEddystoneTLM::setCount(uint32_t advCount) {
|
||||
m_eddystoneData.advCount = advCount;
|
||||
@@ -217,8 +217,8 @@ void NimBLEEddystoneTLM::setCount(uint32_t advCount) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the advertisment time.
|
||||
* @param [in] tmil The advertisment time in milliseconds.
|
||||
* @brief Set the advertisement time.
|
||||
* @param [in] tmil The advertisement time in milliseconds.
|
||||
*/
|
||||
void NimBLEEddystoneTLM::setTime(uint32_t tmil) {
|
||||
m_eddystoneData.tmil = tmil;
|
||||
|
||||
@@ -152,7 +152,7 @@ std::string NimBLEEddystoneURL::getDecodedURL() {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the raw data for the beacon advertisment.
|
||||
* @brief Set the raw data for the beacon advertisement.
|
||||
* @param [in] data The raw data to advertise.
|
||||
*/
|
||||
void NimBLEEddystoneURL::setData(const std::string &data) {
|
||||
|
||||
@@ -272,7 +272,7 @@ bool NimBLEExtAdvertising::stop() {
|
||||
|
||||
/**
|
||||
* @brief Set a callback to call when the advertisement stops.
|
||||
* @param [in] pCallbacks A pointer to a callback to be invoked when an advertisment stops.
|
||||
* @param [in] pCallbacks A pointer to a callback to be invoked when an advertisement stops.
|
||||
* @param [in] deleteCallbacks if true callback class will be deleted when advertising is destructed.
|
||||
*/
|
||||
void NimBLEExtAdvertising::setCallbacks(NimBLEExtAdvertisingCallbacks* pCallbacks,
|
||||
|
||||
@@ -99,7 +99,7 @@ void NimBLEHIDDevice::manufacturer(std::string name) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the Plug n Play characterisc value.
|
||||
* @brief Sets the Plug n Play characteristic value.
|
||||
* @param [in] sig The vendor ID source number.
|
||||
* @param [in] vid The vendor ID number.
|
||||
* @param [in] pid The product ID number.
|
||||
|
||||
@@ -165,7 +165,7 @@ std::vector<NimBLERemoteCharacteristic*>* NimBLERemoteService::getCharacteristic
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback for Characterisic discovery.
|
||||
* @brief Callback for Characteristic discovery.
|
||||
* @return success == 0 or error code.
|
||||
*/
|
||||
int NimBLERemoteService::characteristicDiscCB(uint16_t conn_handle,
|
||||
|
||||
@@ -164,7 +164,7 @@ NimBLEScan::~NimBLEScan() {
|
||||
NIMBLE_LOGD(LOG_TAG, "discovery complete; reason=%d",
|
||||
event->disc_complete.reason);
|
||||
|
||||
// If a device advertised with scan reponse available and it was not received
|
||||
// If a device advertised with scan response available and it was not received
|
||||
// the callback would not have been invoked, so do it here.
|
||||
if(pScan->m_pAdvertisedDeviceCallbacks) {
|
||||
for(auto &it : pScan->m_scanResults.m_advertisedDevicesVector) {
|
||||
@@ -211,7 +211,7 @@ void NimBLEScan::setActiveScan(bool active) {
|
||||
* from devices it has not already seen.
|
||||
* @param [in] enabled If true, scanned devices will only be reported once.
|
||||
* @details The controller has a limited buffer and will start reporting
|
||||
* dupicate devices once the limit is reached.
|
||||
* duplicate devices once the limit is reached.
|
||||
*/
|
||||
void NimBLEScan::setDuplicateFilter(bool enabled) {
|
||||
m_scan_params.filter_duplicates = enabled;
|
||||
@@ -236,7 +236,7 @@ void NimBLEScan::setLimitedOnly(bool enabled) {
|
||||
* directed, connectable advertising packets not sent to the scanner.
|
||||
* * BLE_HCI_SCAN_FILT_USE_WL (1)
|
||||
* Scanner processes advertisements from white list only. A connectable,\n
|
||||
* directed advertisment is ignored unless it contains scanners address.
|
||||
* directed advertisement is ignored unless it contains scanners address.
|
||||
* * BLE_HCI_SCAN_FILT_NO_WL_INITA (2)
|
||||
* Scanner process all advertising packets (white list not used). A\n
|
||||
* connectable, directed advertisement shall not be ignored if the InitA
|
||||
|
||||
@@ -61,8 +61,8 @@ void NimBLESecurity::setCapability(esp_ble_io_cap_t iocap) {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sets the keys we will distibute during encryption.
|
||||
* @param [in] init_key A bitmask of the keys we will distibute.\n
|
||||
* @brief Sets the keys we will distribute during encryption.
|
||||
* @param [in] init_key A bitmask of the keys we will distribute.\n
|
||||
* Can be one or more of:
|
||||
* * ESP_BLE_ENC_KEY_MASK (1 << 0)
|
||||
* * ESP_BLE_ID_KEY_MASK (1 << 1)
|
||||
|
||||
@@ -373,7 +373,7 @@ int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg) {
|
||||
|
||||
case BLE_GAP_EVENT_DISCONNECT: {
|
||||
// If Host reset tell the device now before returning to prevent
|
||||
// any errors caused by calling host functions before resyncing.
|
||||
// any errors caused by calling host functions before resync.
|
||||
switch(event->disconnect.reason) {
|
||||
case BLE_HS_ETIMEOUT_HCI:
|
||||
case BLE_HS_EOS:
|
||||
@@ -636,7 +636,7 @@ void NimBLEServer::setCallbacks(NimBLEServerCallbacks* pCallbacks, bool deleteCa
|
||||
* @brief Remove a service from the server.
|
||||
*
|
||||
* @details Immediately removes access to the service by clients, sends a service changed indication,
|
||||
* and removes the service (if applicable) from the advertisments.
|
||||
* and removes the service (if applicable) from the advertisements.
|
||||
* The service is not deleted unless the deleteSvc parameter is true, otherwise the service remains
|
||||
* available and can be re-added in the future. If desired a removed but not deleted service can
|
||||
* be deleted later by calling this method with deleteSvc set to true.
|
||||
|
||||
@@ -151,7 +151,7 @@ public:
|
||||
* @brief Handle a client disconnection.
|
||||
* This is called when a client discconnects.
|
||||
* @param [in] pServer A pointer to the %BLE server that received the client disconnection.
|
||||
* @param [in] desc A pointer to the connection description structure containig information
|
||||
* @param [in] desc A pointer to the connection description structure containing information
|
||||
* about the connection.
|
||||
*/
|
||||
virtual void onDisconnect(NimBLEServer* pServer, ble_gap_conn_desc* desc);
|
||||
@@ -159,7 +159,7 @@ public:
|
||||
/**
|
||||
* @brief Called when the connection MTU changes.
|
||||
* @param [in] MTU The new MTU value.
|
||||
* @param [in] desc A pointer to the connection description structure containig information
|
||||
* @param [in] desc A pointer to the connection description structure containing information
|
||||
* about the connection.
|
||||
*/
|
||||
virtual void onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc);
|
||||
|
||||
@@ -297,7 +297,7 @@ std::string NimBLEUUID::toString() const {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convienience operator to check if this UUID is equal to another.
|
||||
* @brief Convenience operator to check if this UUID is equal to another.
|
||||
*/
|
||||
bool NimBLEUUID::operator ==(const NimBLEUUID & rhs) const {
|
||||
if(m_valueSet && rhs.m_valueSet) {
|
||||
@@ -336,7 +336,7 @@ bool NimBLEUUID::operator ==(const NimBLEUUID & rhs) const {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convienience operator to check if this UUID is not equal to another.
|
||||
* @brief Convenience operator to check if this UUID is not equal to another.
|
||||
*/
|
||||
bool NimBLEUUID::operator !=(const NimBLEUUID & rhs) const {
|
||||
return !this->operator==(rhs);
|
||||
@@ -344,7 +344,7 @@ bool NimBLEUUID::operator !=(const NimBLEUUID & rhs) const {
|
||||
|
||||
|
||||
/**
|
||||
* @brief Convienience operator to convert this UUID to string representation.
|
||||
* @brief Convenience operator to convert this UUID to string representation.
|
||||
* @details This allows passing NimBLEUUID to functions
|
||||
* that accept std::string and/or or it's methods as a parameter.
|
||||
*/
|
||||
|
||||
@@ -355,7 +355,7 @@ const char* NimBLEUtils::returnCodeToString(int rc) {
|
||||
* @return A string representation of the advertising flags.
|
||||
*/
|
||||
const char* NimBLEUtils::advTypeToString(uint8_t advType) {
|
||||
#if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
|
||||
#if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
|
||||
switch(advType) {
|
||||
case BLE_HCI_ADV_TYPE_ADV_IND : //0
|
||||
return "Undirected - Connectable / Scannable";
|
||||
@@ -370,10 +370,10 @@ const char* NimBLEUtils::advTypeToString(uint8_t advType) {
|
||||
default:
|
||||
return "Unknown flag";
|
||||
}
|
||||
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
|
||||
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
|
||||
(void)advType;
|
||||
return "";
|
||||
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
|
||||
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
|
||||
} // adFlagsToString
|
||||
|
||||
|
||||
|
||||
@@ -1508,7 +1508,7 @@ ble_phy_resolv_list_disable(void)
|
||||
void
|
||||
ble_phy_rfclk_enable(void)
|
||||
{
|
||||
#if MYNEWT
|
||||
#if MYNEWT || ARDUINO
|
||||
nrf51_clock_hfxo_request();
|
||||
#else
|
||||
NRF_CLOCK->TASKS_HFCLKSTART = 1;
|
||||
@@ -1518,7 +1518,7 @@ ble_phy_rfclk_enable(void)
|
||||
void
|
||||
ble_phy_rfclk_disable(void)
|
||||
{
|
||||
#if MYNEWT
|
||||
#if MYNEWT || ARDUINO
|
||||
nrf51_clock_hfxo_release();
|
||||
#else
|
||||
NRF_CLOCK->TASKS_HFCLKSTOP = 1;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_NRF5) && defined(NRF52_SERIES)
|
||||
|
||||
#include <stdint.h>
|
||||
@@ -2100,7 +2100,7 @@ void ble_phy_disable_dtm(void)
|
||||
void
|
||||
ble_phy_rfclk_enable(void)
|
||||
{
|
||||
#if MYNEWT
|
||||
#if MYNEWT || ARDUINO
|
||||
nrf52_clock_hfxo_request();
|
||||
#else
|
||||
NRF_CLOCK->TASKS_HFCLKSTART = 1;
|
||||
@@ -2110,7 +2110,7 @@ ble_phy_rfclk_enable(void)
|
||||
void
|
||||
ble_phy_rfclk_disable(void)
|
||||
{
|
||||
#if MYNEWT
|
||||
#if MYNEWT || ARDUINO
|
||||
nrf52_clock_hfxo_release();
|
||||
#else
|
||||
NRF_CLOCK->TASKS_HFCLKSTOP = 1;
|
||||
|
||||
@@ -1162,6 +1162,38 @@ int ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields);
|
||||
int ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
|
||||
uint16_t tx_time);
|
||||
|
||||
/**
|
||||
* Read host's suggested values for the controller's maximum transmitted number of payload octets
|
||||
* and maximum packet transmission time (OGF = 0x08, OCF = 0x0024).
|
||||
*
|
||||
* @param out_sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
|
||||
* number of payload octets in LL Data PDUs to be used for new
|
||||
* connections. (Range 0x001B-0x00FB).
|
||||
* @param out_sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
|
||||
* transmission time for packets containing LL Data PDUs to be used
|
||||
* for new connections. (Range 0x0148-0x4290).
|
||||
*
|
||||
* @return 0 on success,
|
||||
* other error code on failure.
|
||||
*/
|
||||
int ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
|
||||
uint16_t *out_sugg_max_tx_time);
|
||||
/**
|
||||
* Configure host's suggested maximum transmitted number of payload octets and maximum packet
|
||||
* transmission time in controller (OGF = 0x08, OCF = 0x0024).
|
||||
*
|
||||
* @param sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
|
||||
* number of payload octets in LL Data PDUs to be used for new
|
||||
* connections. (Range 0x001B-0x00FB).
|
||||
* @param sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
|
||||
* transmission time for packets containing LL Data PDUs to be used
|
||||
* for new connections. (Range 0x0148-0x4290).
|
||||
*
|
||||
* @return 0 on success,
|
||||
* other error code on failure.
|
||||
*/
|
||||
int ble_hs_hci_util_write_sugg_def_data_len(uint16_t sugg_max_tx_octets, uint16_t sugg_max_tx_time);
|
||||
|
||||
#if MYNEWT_VAL(BLE_EXT_ADV)
|
||||
/** @brief Extended advertising parameters */
|
||||
struct ble_gap_ext_adv_params {
|
||||
@@ -1843,6 +1875,37 @@ int ble_gap_update_params(uint16_t conn_handle,
|
||||
*/
|
||||
int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time);
|
||||
|
||||
/**
|
||||
* Read LE Suggested Default Data Length in controller (OGF = 0x08, OCF = 0x0024).
|
||||
*
|
||||
* @param out_sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
|
||||
* number of payload octets in LL Data PDUs to be used for new
|
||||
* connections. (Range 0x001B-0x00FB).
|
||||
* @param out_sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
|
||||
* transmission time for packets containing LL Data PDUs to be used
|
||||
* for new connections. (Range 0x0148-0x4290).
|
||||
*
|
||||
* @return 0 on success,
|
||||
* other error code on failure.
|
||||
*/
|
||||
int ble_gap_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
|
||||
uint16_t *out_sugg_max_tx_time);
|
||||
|
||||
/**
|
||||
* Configure LE Suggested Default Data Length in controller (OGF = 0x08, OCF = 0x0024).
|
||||
*
|
||||
* @param sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
|
||||
* number of payload octets in LL Data PDUs to be used for new
|
||||
* connections. (Range 0x001B-0x00FB).
|
||||
* @param sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
|
||||
* transmission time for packets containing LL Data PDUs to be used
|
||||
* for new connections. (Range 0x0148-0x4290).
|
||||
*
|
||||
* @return 0 on success,
|
||||
* other error code on failure.
|
||||
*/
|
||||
int ble_gap_write_sugg_def_data_len(uint16_t sugg_max_tx_octets, uint16_t sugg_max_tx_time);
|
||||
|
||||
/**
|
||||
* Initiates the GAP security procedure.
|
||||
*
|
||||
|
||||
@@ -796,7 +796,7 @@ void bt_mesh_net_recv(struct os_mbuf *data, int8_t rssi,
|
||||
* it again in the future.
|
||||
*/
|
||||
if (bt_mesh_trans_recv(buf, &rx) == -EAGAIN) {
|
||||
BT_WARN("Removing rejected message from NetworkMessage Cache");
|
||||
BT_WARN("Removing rejected message from Network Message Cache");
|
||||
msg_cache[rx.msg_cache_idx].src = BT_MESH_ADDR_UNASSIGNED;
|
||||
/* Rewind the next index now that we're not using this entry */
|
||||
msg_cache_next = rx.msg_cache_idx;
|
||||
|
||||
@@ -5860,6 +5860,16 @@ int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_t
|
||||
return ble_hs_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
|
||||
}
|
||||
|
||||
int ble_gap_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets, uint16_t *out_sugg_max_tx_time)
|
||||
{
|
||||
return ble_hs_hci_util_read_sugg_def_data_len(out_sugg_max_tx_octets, out_sugg_max_tx_time);
|
||||
}
|
||||
|
||||
int ble_gap_write_sugg_def_data_len(uint16_t sugg_max_tx_octets, uint16_t sugg_max_tx_time)
|
||||
{
|
||||
return ble_hs_hci_util_write_sugg_def_data_len(sugg_max_tx_octets, sugg_max_tx_time);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* $security *
|
||||
*****************************************************************************/
|
||||
|
||||
@@ -157,6 +157,60 @@ ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
|
||||
uint16_t *out_sugg_max_tx_time)
|
||||
{
|
||||
struct ble_hci_le_rd_sugg_def_data_len_rp rsp;
|
||||
int rc;
|
||||
|
||||
rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
|
||||
BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN),
|
||||
NULL, 0, &rsp, sizeof(rsp));
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
*out_sugg_max_tx_octets = le16toh(rsp.max_tx_octets);
|
||||
*out_sugg_max_tx_time = le16toh(rsp.max_tx_time);
|
||||
|
||||
if (*out_sugg_max_tx_octets < BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN ||
|
||||
*out_sugg_max_tx_octets > BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX) {
|
||||
BLE_HS_LOG(WARN, "received suggested maximum tx octets is out of range\n");
|
||||
}
|
||||
|
||||
if (*out_sugg_max_tx_time < BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN ||
|
||||
*out_sugg_max_tx_time > BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX) {
|
||||
BLE_HS_LOG(WARN, "received suggested maximum tx time is out of range\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ble_hs_hci_util_write_sugg_def_data_len(uint16_t sugg_max_tx_octets,
|
||||
uint16_t sugg_max_tx_time)
|
||||
{
|
||||
struct ble_hci_le_wr_sugg_def_data_len_cp cmd;
|
||||
|
||||
if (sugg_max_tx_octets < BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN ||
|
||||
sugg_max_tx_octets > BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX) {
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
if (sugg_max_tx_time < BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN ||
|
||||
sugg_max_tx_time > BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX) {
|
||||
return BLE_HS_EINVAL;
|
||||
}
|
||||
|
||||
cmd.max_tx_octets = htole16(sugg_max_tx_octets);
|
||||
cmd.max_tx_time = htole16(sugg_max_tx_time);
|
||||
|
||||
return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
|
||||
BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN),
|
||||
&cmd, sizeof(cmd), NULL, 0);
|
||||
}
|
||||
|
||||
int
|
||||
ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
|
||||
struct hci_data_hdr *out_hdr)
|
||||
|
||||
@@ -43,7 +43,6 @@ ble_hs_periodic_sync_alloc(void)
|
||||
memset(psync, 0, sizeof(*psync));
|
||||
}
|
||||
|
||||
ble_npl_event_init(&psync->lost_ev, ble_gap_npl_sync_lost, psync);
|
||||
return psync;
|
||||
}
|
||||
|
||||
@@ -56,7 +55,9 @@ ble_hs_periodic_sync_free(struct ble_hs_periodic_sync *psync)
|
||||
return;
|
||||
}
|
||||
|
||||
ble_npl_event_deinit(&psync->lost_ev);
|
||||
if((psync->lost_ev).event != NULL)
|
||||
ble_npl_event_deinit(&psync->lost_ev);
|
||||
|
||||
#if MYNEWT_VAL(BLE_HS_DEBUG)
|
||||
memset(psync, 0xff, sizeof *psync);
|
||||
#endif
|
||||
|
||||
@@ -97,6 +97,7 @@ ble_rpa_remove_peer_dev_rec(struct ble_hs_dev_records *p_dev_rec)
|
||||
if ((i != ble_store_num_peer_dev_rec) && (ble_store_num_peer_dev_rec != 0)) {
|
||||
memmove(&peer_dev_rec[i], &peer_dev_rec[i + 1],
|
||||
(ble_store_num_peer_dev_rec - i) * sizeof(struct ble_hs_dev_records ));
|
||||
memset(&peer_dev_rec[ble_store_num_peer_dev_rec], 0, sizeof(struct ble_hs_dev_records));
|
||||
}
|
||||
|
||||
BLE_HS_LOG(DEBUG, " RPA: removed device at index = %d, no. of peer records"
|
||||
|
||||
@@ -643,6 +643,10 @@ mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
|
||||
/* Free the previously allocate keypair */
|
||||
mbedtls_ecp_keypair_free(&keypair);
|
||||
|
||||
mbedtls_ecp_keypair_init(&keypair);
|
||||
|
||||
if (( rc = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
|
||||
@@ -679,6 +683,11 @@ exit:
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mbedtls_free_keypair(void)
|
||||
{
|
||||
mbedtls_ecp_keypair_free(&keypair);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ ble_hs_util_load_rand_addr(ble_addr_t *addr)
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER
|
||||
int rc;
|
||||
|
||||
rc = esp_ble_hw_get_static_addr(addr);
|
||||
rc = esp_ble_hw_get_static_addr((esp_ble_addr_t *)addr);
|
||||
if (rc == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ struct os_mbuf;
|
||||
typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg);
|
||||
typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg);
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32H2
|
||||
#if CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2
|
||||
struct ble_hci_trans_funcs_t {
|
||||
int(*_ble_hci_trans_hs_acl_tx)(struct os_mbuf *om);
|
||||
int(*_ble_hci_trans_hs_cmd_tx)(uint8_t *cmd);
|
||||
|
||||
@@ -1215,6 +1215,12 @@ struct ble_hci_vs_rd_static_addr_rp {
|
||||
#define BLE_HCI_SET_DATALEN_TX_TIME_MIN (0x0148)
|
||||
#define BLE_HCI_SET_DATALEN_TX_TIME_MAX (0x4290)
|
||||
|
||||
/* --- LE read/write suggested default data length (OCF 0x0023 and 0x0024) */
|
||||
#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN (0x001b)
|
||||
#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX (0x00fb)
|
||||
#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN (0x0148)
|
||||
#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX (0x4290)
|
||||
|
||||
/* --- LE read maximum default PHY (OCF 0x0030) */
|
||||
#define BLE_HCI_LE_PHY_1M (1)
|
||||
#define BLE_HCI_LE_PHY_2M (2)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "nimble/nimble/include/nimble/nimble_npl.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_err.h"
|
||||
#include "nimconfig.h"
|
||||
#define NIMBLE_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY)
|
||||
#define NIMBLE_HS_STACK_SIZE CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE
|
||||
@@ -31,8 +32,8 @@
|
||||
#define NIMBLE_HS_STACK_SIZE (CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE / 4)
|
||||
#endif
|
||||
|
||||
#if (CONFIG_IDF_TARGET_ESP32H2)
|
||||
#define NIMBLE_LL_STACK_SIZE CONFIG_BT_NIMBLE_CONTROLLER_TASK_STACK_SIZE
|
||||
#if (CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2)
|
||||
#define NIMBLE_LL_STACK_SIZE CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -45,6 +46,22 @@ void nimble_port_deinit(void);
|
||||
void nimble_port_run(void);
|
||||
int nimble_port_stop(void);
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/**
|
||||
* @brief esp_nimble_init - Initialize the NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_init(void);
|
||||
|
||||
/**
|
||||
* @brief esp_nimble_deinit - Deinitialize the NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_deinit(void);
|
||||
#endif // ESP_PLATFORM
|
||||
|
||||
struct ble_npl_eventq *nimble_port_get_dflt_eventq(void);
|
||||
|
||||
#if NIMBLE_CFG_CONTROLLER
|
||||
|
||||
@@ -6,9 +6,12 @@
|
||||
#define H_SYSCFG_
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "nimble/esp_port/port/include/esp_nimble_cfg.h"
|
||||
# include "nimble/esp_port/port/include/esp_nimble_cfg.h"
|
||||
#else
|
||||
#include "ext_nimble_config.h"
|
||||
# include "ext_nimble_config.h"
|
||||
# ifndef CONFIG_BT_NIMBLE_ENABLED
|
||||
# define CONFIG_BT_NIMBLE_ENABLED 1
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
|
||||
388
lib/NimBLE-Arduino/src/nimble/porting/nimble/src/hal_uart.c
Normal file
388
lib/NimBLE-Arduino/src/nimble/porting/nimble/src/hal_uart.c
Normal file
@@ -0,0 +1,388 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "os/os.h"
|
||||
#include "hal/hal_uart.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/system_reg.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "riscv/interrupt.h"
|
||||
#include "hal/uart_ll.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "driver/uart.h"
|
||||
#include "driver/periph_ctrl.h"
|
||||
|
||||
struct hal_uart {
|
||||
uint8_t u_open:1;
|
||||
uint8_t u_rx_stall:1;
|
||||
uint8_t u_tx_started:1;
|
||||
uint8_t u_tx_buf;
|
||||
hal_uart_rx_char u_rx_func;
|
||||
hal_uart_tx_char u_tx_func;
|
||||
hal_uart_tx_done u_tx_done;
|
||||
SemaphoreHandle_t u_rx_sem;
|
||||
void *u_func_arg;
|
||||
};
|
||||
static struct hal_uart uart;
|
||||
|
||||
#define UART_FIFO_LEN (128)
|
||||
|
||||
uint8_t rxbuffer[256];
|
||||
static uint16_t rd_ptr = 0;
|
||||
static uint16_t wr_ptr = 0;
|
||||
#define BUFFER_MASK (0xff)
|
||||
|
||||
static TaskHandle_t hci_uart_task_h;
|
||||
|
||||
void uart_init(uint32_t baud);
|
||||
void uart0_init(uint32_t baud);
|
||||
void uart0_tout_isr(void);
|
||||
void uart_tout_isr(void);
|
||||
void
|
||||
hal_uart_blocking_tx(int port, uint8_t data){
|
||||
|
||||
}
|
||||
int hal_uart_init(int uart_no, void *cfg)
|
||||
{
|
||||
// Uart_Init(uart_no, UART_CLK_FREQ_ROM);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hal_uart_start_rx(int uart)
|
||||
{
|
||||
ets_printf("rx support???\n");
|
||||
}
|
||||
int hal_uart_init_cbs(int uart_no, hal_uart_tx_char tx_func,
|
||||
hal_uart_tx_done tx_done, hal_uart_rx_char rx_func, void *arg)
|
||||
{
|
||||
struct hal_uart *u;
|
||||
|
||||
u = &uart;
|
||||
|
||||
if (u->u_open) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
u->u_rx_func = rx_func;
|
||||
u->u_tx_func = tx_func;
|
||||
u->u_tx_done = tx_done;
|
||||
u->u_func_arg = arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hal_uart_config(int uart_no, int32_t speed, uint8_t databits, uint8_t stopbits,
|
||||
enum hal_uart_parity parity, enum hal_uart_flow_ctl flow_ctl)
|
||||
{
|
||||
struct hal_uart *u;
|
||||
u = &uart;
|
||||
|
||||
if (u->u_open) {
|
||||
return -1;
|
||||
}
|
||||
if (uart_no) {
|
||||
uart_init(speed);
|
||||
} else {
|
||||
uart0_init(speed);
|
||||
}
|
||||
u->u_open = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
IRAM_ATTR_64MCPU hal_uart_tx_fill_buf(struct hal_uart *u, int uart_no)
|
||||
{
|
||||
int data;
|
||||
int i;
|
||||
uart_dev_t *hw = &UART1;
|
||||
if(!uart_no){
|
||||
hw = &UART0;
|
||||
}
|
||||
i = 0;
|
||||
while(hw->status.txfifo_cnt < UART_FIFO_LEN){
|
||||
data = u->u_tx_func(u->u_func_arg);
|
||||
if (data >= 0) {
|
||||
hw->ahb_fifo.rw_byte = data;
|
||||
i++;
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
void hal_uart_start_tx(int uart_no)
|
||||
{
|
||||
struct hal_uart *u;
|
||||
os_sr_t sr;
|
||||
uart_dev_t *hw = &UART1;
|
||||
if(!uart_no){
|
||||
hw = &UART0;
|
||||
}
|
||||
u = &uart;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
if (u->u_tx_started == 0) {
|
||||
u->u_tx_started = 1;
|
||||
hw->int_ena.tx_done = 1;
|
||||
hal_uart_tx_fill_buf(u,uart_no);
|
||||
}
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
}
|
||||
|
||||
int hal_uart0_close(int uart_no)
|
||||
{
|
||||
struct hal_uart *u;
|
||||
u = &uart;
|
||||
u->u_open = 0;
|
||||
|
||||
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART_CLK_EN);
|
||||
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART_RST);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int hal_uart_close(int uart_no)
|
||||
{
|
||||
struct hal_uart *u;
|
||||
u = &uart;
|
||||
u->u_open = 0;
|
||||
|
||||
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART1_CLK_EN);
|
||||
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART1_RST);
|
||||
return 0;
|
||||
}
|
||||
|
||||
IRAM_ATTR_64MCPU void uart0_tout_isr(void)
|
||||
{
|
||||
struct hal_uart *u;
|
||||
int rc;
|
||||
uint32_t ch;
|
||||
uart_dev_t *hw = &UART0;
|
||||
|
||||
u = &uart;
|
||||
uint32_t uart_int_st = hw->int_st.val;
|
||||
//clear
|
||||
hw->int_clr.val = uart_int_st;
|
||||
if (uart_int_st&UART_TX_DONE_INT_ST_M) {
|
||||
rc = hal_uart_tx_fill_buf(u,0);
|
||||
if (rc == 0) {
|
||||
if (u->u_tx_done) {
|
||||
u->u_tx_done(u->u_func_arg);
|
||||
}
|
||||
u->u_tx_started = 0;
|
||||
hw->int_ena.tx_done = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while (hw->status.rxfifo_cnt) {
|
||||
int rd_len = hw->status.rxfifo_cnt;
|
||||
for (int i = 0; i < rd_len; i++) {
|
||||
ch = hw->ahb_fifo.rw_byte;
|
||||
rc = u->u_rx_func(u->u_func_arg, ch);
|
||||
if (rc < 0) {
|
||||
u->u_rx_stall = 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
IRAM_ATTR_64MCPU void uart_tout_isr(void)
|
||||
{
|
||||
struct hal_uart *u;
|
||||
int rc;
|
||||
bool rx_update = false;
|
||||
uart_dev_t *hw = &UART1;
|
||||
u = &uart;
|
||||
uint32_t uart_int_st = hw->int_st.val;
|
||||
//clear
|
||||
hw->int_clr.val = uart_int_st;
|
||||
if (uart_int_st&UART_TX_DONE_INT_ST_M) {
|
||||
rc = hal_uart_tx_fill_buf(u,1);
|
||||
if (rc == 0) {
|
||||
if (u->u_tx_done) {
|
||||
u->u_tx_done(u->u_func_arg);
|
||||
}
|
||||
u->u_tx_started = 0;
|
||||
hw->int_ena.tx_done = 0;
|
||||
}
|
||||
}
|
||||
while (hw->status.rxfifo_cnt) {
|
||||
rxbuffer[(wr_ptr++)&BUFFER_MASK] = hw->ahb_fifo.rw_byte;
|
||||
rx_update = true;
|
||||
}
|
||||
if (rx_update) {
|
||||
xSemaphoreGiveFromISR(u->u_rx_sem, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
IRAM_ATTR uart_rx_task(void *arg){
|
||||
int rc;
|
||||
struct hal_uart *u;
|
||||
u = &uart;
|
||||
while (1) {
|
||||
xSemaphoreTake(u->u_rx_sem, portMAX_DELAY);
|
||||
while (rd_ptr != wr_ptr){
|
||||
rc = u->u_rx_func(u->u_func_arg, rxbuffer[(rd_ptr++)&BUFFER_MASK]);
|
||||
if (rc < 0) {
|
||||
u->u_rx_stall = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void uart0_init(uint32_t baud)
|
||||
{
|
||||
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART_RST);
|
||||
REG_CLR_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART_RST);
|
||||
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART_CLK_EN_M);
|
||||
REG_SET_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART_CLK_EN_M);
|
||||
|
||||
const int sclk_div = 1;
|
||||
uint32_t sclk_freq = XTAL_CLK_FREQ;
|
||||
uint32_t clk_div = ((sclk_freq) << 4) / baud;
|
||||
uart_dev_t *hw = &UART0;
|
||||
hw->clk_conf.sclk_en = 0;
|
||||
hw->clk_conf.rx_sclk_en = 0;
|
||||
hw->clk_conf.tx_sclk_en = 0;
|
||||
|
||||
|
||||
hw->clk_conf.sclk_en = 1;
|
||||
hw->clk_conf.rx_sclk_en = 1;
|
||||
hw->clk_conf.tx_sclk_en = 1;
|
||||
|
||||
hw->clk_div.div_int = clk_div >> 4;
|
||||
hw->clk_div.div_frag = clk_div & 0xf;
|
||||
hw->clk_conf.sclk_div_num = sclk_div - 1;//7;//255;
|
||||
|
||||
hw->conf0.parity_en = 0;
|
||||
|
||||
hw->conf0.irda_en = 0;
|
||||
hw->rs485_conf.en = 0;
|
||||
hw->rs485_conf.tx_rx_en = 0;
|
||||
hw->rs485_conf.rx_busy_tx_en = 0;
|
||||
|
||||
hw->conf0.bit_num = 3;
|
||||
hw->conf0.stop_bit_num = 1;
|
||||
|
||||
hw->conf1.rxfifo_full_thrhd = 80;
|
||||
|
||||
hw->mem_conf.rx_tout_thrhd = 20;
|
||||
hw->conf1.rx_tout_en = 1;
|
||||
|
||||
hw->conf1.rx_flow_en = 0;
|
||||
hw->conf0.tx_flow_en = 0;
|
||||
|
||||
hw->conf0.rxfifo_rst = 1;
|
||||
hw->conf0.rxfifo_rst = 0;
|
||||
hw->conf0.txfifo_rst = 1;
|
||||
hw->conf0.txfifo_rst = 0;
|
||||
hw->int_ena.rxfifo_full = 1;
|
||||
//enable rx fifo timeout interrupt
|
||||
hw->int_ena.rxfifo_tout = 1;
|
||||
|
||||
uint8_t tx_pin = 21, rx_pin = 20, ISR_ID = ETS_UART0_INUM;
|
||||
|
||||
ets_isr_mask((1<<ISR_ID)); //ETS_INTR_DISABLE
|
||||
|
||||
intr_handler_set(ISR_ID, (intr_handler_t)&uart0_tout_isr, NULL);
|
||||
intr_matrix_route(ETS_UART0_INTR_SOURCE, ISR_ID);
|
||||
esprv_intc_int_enable(BIT(ISR_ID));
|
||||
esprv_intc_int_set_type(BIT(ISR_ID), INTR_TYPE_LEVEL);
|
||||
esprv_intc_int_set_priority(ISR_ID, 1);
|
||||
|
||||
esp_intr_reserve(ISR_ID, xPortGetCoreID());
|
||||
|
||||
ESP_ERROR_CHECK(uart_set_pin(0, tx_pin, rx_pin, -1, -1));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void uart_init(uint32_t baud)
|
||||
{
|
||||
periph_module_enable(PERIPH_UART1_MODULE);
|
||||
|
||||
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART1_RST);
|
||||
REG_CLR_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART1_RST);
|
||||
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART1_CLK_EN_M);
|
||||
REG_SET_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART1_CLK_EN_M);
|
||||
|
||||
const int sclk_div = 1;
|
||||
uint32_t sclk_freq = XTAL_CLK_FREQ;
|
||||
|
||||
uint32_t clk_div = ((sclk_freq) << 4) / baud;
|
||||
struct hal_uart *u = &uart;
|
||||
|
||||
uart_dev_t *hw = &UART1;
|
||||
hw->clk_conf.sclk_en = 0;
|
||||
hw->clk_conf.rx_sclk_en = 0;
|
||||
hw->clk_conf.tx_sclk_en = 0;
|
||||
|
||||
|
||||
hw->clk_conf.sclk_en = 1;
|
||||
hw->clk_conf.rx_sclk_en = 1;
|
||||
hw->clk_conf.tx_sclk_en = 1;
|
||||
|
||||
hw->clk_div.div_int = clk_div >> 4;
|
||||
hw->clk_div.div_frag = clk_div & 0xf;
|
||||
hw->clk_conf.sclk_div_num = sclk_div - 1;//7;//255;
|
||||
|
||||
hw->conf0.parity_en = 0;
|
||||
|
||||
hw->conf0.irda_en = 0;
|
||||
hw->rs485_conf.en = 0;
|
||||
hw->rs485_conf.tx_rx_en = 0;
|
||||
hw->rs485_conf.rx_busy_tx_en = 0;
|
||||
|
||||
hw->conf0.bit_num = 3;
|
||||
hw->conf0.stop_bit_num = 1;
|
||||
|
||||
//set full threshold to (2/3)*FIFO_LEN
|
||||
hw->conf1.rxfifo_full_thrhd = 80;
|
||||
hw->mem_conf.rx_tout_thrhd = 20;
|
||||
|
||||
hw->conf1.rx_tout_en = 1;
|
||||
|
||||
hw->conf0.rxfifo_rst = 1;
|
||||
hw->conf0.rxfifo_rst = 0;
|
||||
hw->conf0.txfifo_rst = 1;
|
||||
hw->conf0.txfifo_rst = 0;
|
||||
hw->int_ena.rxfifo_full = 1;
|
||||
//enable rx fifo timeout interrupt
|
||||
hw->int_ena.rxfifo_tout = 1;
|
||||
|
||||
u->u_rx_sem = xSemaphoreCreateBinary();
|
||||
|
||||
uint8_t TX_IO = CONFIG_BT_LE_HCI_UART_TX_PIN, RX_IO = CONFIG_BT_LE_HCI_UART_RX_PIN, ISR_ID = ETS_UART1_INUM;
|
||||
printf("set nimble port tx:%d, rx:%d.\n", TX_IO, RX_IO);
|
||||
printf("set baud:%d.\n", baud);
|
||||
intr_handler_set(ISR_ID, (intr_handler_t)&uart_tout_isr, NULL);
|
||||
intr_matrix_route(ETS_UART1_INTR_SOURCE, ISR_ID);
|
||||
esprv_intc_int_enable(BIT(ISR_ID));
|
||||
esprv_intc_int_set_type(BIT(ISR_ID), INTR_TYPE_LEVEL);
|
||||
esprv_intc_int_set_priority(ISR_ID, 1);
|
||||
// TODO ESP32-C3 IDF-2126, maybe can use interrupt allocation API for all of the above? unsure...
|
||||
esp_intr_reserve(ISR_ID, xPortGetCoreID());
|
||||
|
||||
ESP_ERROR_CHECK(uart_set_pin(1, TX_IO, RX_IO, -1, -1));
|
||||
|
||||
//Enable hw flow control of UART1 for BQB test, which if not enabled, the tester takes quite long time to send a byte to DUT
|
||||
|
||||
|
||||
// uart_ll_set_hw_flow_ctrl(hw, UART_HW_FLOWCTRL_CTS_RTS, 110);
|
||||
|
||||
xTaskCreate(uart_rx_task, "uart_rx", CONFIG_BT_LE_HCI_UART_TASK_STACK_SIZE,
|
||||
NULL, 1, &hci_uart_task_h);
|
||||
}
|
||||
|
||||
#endif // CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2
|
||||
@@ -20,7 +20,11 @@
|
||||
#include <stddef.h>
|
||||
#include "../include/os/os.h"
|
||||
#include "../include/sysinit/sysinit.h"
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "nimble/nimble/host/include/host/ble_hs.h"
|
||||
#endif //CONFIG_BT_NIMBLE_ENABLED
|
||||
|
||||
#include "../include/nimble/nimble_port.h"
|
||||
#include "../../npl/freertos/include/nimble/nimble_port_freertos.h"
|
||||
#if NIMBLE_CFG_CONTROLLER
|
||||
@@ -43,91 +47,31 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_CONTROL_USE_UART_HCI
|
||||
#include "transport/uart/ble_hci_uart.h"
|
||||
#else
|
||||
#include "nimble/nimble/transport/ram/include/transport/ram/ble_hci_ram.h"
|
||||
#endif
|
||||
#include "nimble/nimble/include/nimble/ble_hci_trans.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_intr_alloc.h"
|
||||
#include "esp_bt.h"
|
||||
#include "nimble/esp_port/esp-hci/include/esp_nimble_hci.h"
|
||||
#endif
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
extern void ble_hs_deinit(void);
|
||||
#define NIMBLE_PORT_LOG_TAG "BLE_INIT"
|
||||
|
||||
extern void os_msys_init(void);
|
||||
|
||||
static struct ble_npl_eventq g_eventq_dflt;
|
||||
#if CONFIG_BT_NIMBLE_ENABLED
|
||||
|
||||
extern void ble_hs_deinit(void);
|
||||
static struct ble_hs_stop_listener stop_listener;
|
||||
|
||||
#endif //CONFIG_BT_NIMBLE_ENABLED
|
||||
|
||||
static struct ble_npl_eventq g_eventq_dflt;
|
||||
static struct ble_npl_sem ble_hs_stop_sem;
|
||||
static struct ble_npl_event ble_hs_ev_stop;
|
||||
|
||||
void
|
||||
nimble_port_init(void)
|
||||
{
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER
|
||||
struct esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
if(esp_bt_controller_init(&config_opts) != 0) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller init failed\n");
|
||||
return;
|
||||
}
|
||||
/* Initialize the host */
|
||||
ble_hs_init();
|
||||
|
||||
#else //SOC_ESP_NIMBLE_CONTROLLER
|
||||
|
||||
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
|
||||
/* Initialize the function pointers for OS porting */
|
||||
npl_freertos_funcs_init();
|
||||
|
||||
npl_freertos_mempool_init();
|
||||
#endif
|
||||
/* Initialize default event queue */
|
||||
|
||||
ble_npl_eventq_init(&g_eventq_dflt);
|
||||
|
||||
#if NIMBLE_CFG_CONTROLLER
|
||||
void ble_hci_ram_init(void);
|
||||
#endif
|
||||
|
||||
os_msys_init();
|
||||
|
||||
ble_hs_init();
|
||||
#endif
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
# if NIMBLE_CFG_CONTROLLER
|
||||
ble_hci_ram_init();
|
||||
hal_timer_init(5, NULL);
|
||||
os_cputime_init(32768);
|
||||
ble_ll_init();
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
nimble_port_deinit(void)
|
||||
{
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER
|
||||
ble_hs_deinit();
|
||||
|
||||
esp_bt_controller_deinit();
|
||||
|
||||
/* Delete the host task */
|
||||
nimble_port_freertos_deinit();
|
||||
#else
|
||||
ble_npl_eventq_deinit(&g_eventq_dflt);
|
||||
|
||||
ble_hs_deinit();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the host stop procedure has completed.
|
||||
*/
|
||||
@@ -143,12 +87,150 @@ nimble_port_stop_cb(struct ble_npl_event *ev)
|
||||
ble_npl_sem_release(&ble_hs_stop_sem);
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/**
|
||||
* @brief esp_nimble_init - Initialize the NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_init(void)
|
||||
{
|
||||
#if !SOC_ESP_NIMBLE_CONTROLLER
|
||||
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
|
||||
/* Initialize the function pointers for OS porting */
|
||||
npl_freertos_funcs_init();
|
||||
|
||||
npl_freertos_mempool_init();
|
||||
#endif
|
||||
#if false //need delete esp_nimble_hci_and_controller_init then can be use
|
||||
if(esp_nimble_hci_init() != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "hci inits failed\n");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
printf("esp_nimble_hci_init\n");
|
||||
#endif
|
||||
|
||||
/* Initialize default event queue */
|
||||
ble_npl_eventq_init(&g_eventq_dflt);
|
||||
|
||||
os_msys_init();
|
||||
|
||||
#endif
|
||||
|
||||
/* Initialize the host */
|
||||
ble_hs_init();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief esp_nimble_deinit - Deinitialize the NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_deinit(void)
|
||||
{
|
||||
#if false && !SOC_ESP_NIMBLE_CONTROLLER //need delete esp_nimble_hci_and_controller_init then can be use
|
||||
if(esp_nimble_hci_deinit() != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "hci deinit failed\n");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
#endif
|
||||
#if !(SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED)
|
||||
ble_npl_eventq_deinit(&g_eventq_dflt);
|
||||
#endif
|
||||
ble_hs_deinit();
|
||||
return ESP_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
nimble_port_init(void)
|
||||
{
|
||||
#ifdef ESP_PLATFORM
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
|
||||
esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
if(esp_bt_controller_init(&config_opts) != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller init failed\n");
|
||||
return;
|
||||
}
|
||||
if(esp_bt_controller_enable(ESP_BT_MODE_BLE) != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller enable failed\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(esp_nimble_init() != 0) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host init failed\n");
|
||||
return;
|
||||
}
|
||||
#else
|
||||
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
|
||||
/* Initialize the function pointers for OS porting */
|
||||
npl_freertos_funcs_init();
|
||||
|
||||
npl_freertos_mempool_init();
|
||||
#endif
|
||||
/* Initialize default event queue */
|
||||
|
||||
ble_npl_eventq_init(&g_eventq_dflt);
|
||||
|
||||
os_msys_init();
|
||||
|
||||
ble_hs_init();
|
||||
|
||||
#if NIMBLE_CFG_CONTROLLER
|
||||
ble_hci_ram_init();
|
||||
hal_timer_init(5, NULL);
|
||||
os_cputime_init(32768);
|
||||
ble_ll_init();
|
||||
#endif
|
||||
#endif // ESP_PLATFORM
|
||||
}
|
||||
|
||||
void
|
||||
nimble_port_deinit(void)
|
||||
{
|
||||
#ifdef ESP_PLATFORM
|
||||
if(esp_nimble_deinit() != 0) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host deinit failed\n");
|
||||
return;
|
||||
}
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
if(esp_bt_controller_disable() != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller disable failed\n");
|
||||
return;
|
||||
}
|
||||
if(esp_bt_controller_deinit() != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller deinit failed\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
ble_npl_eventq_deinit(&g_eventq_dflt);
|
||||
ble_hs_deinit();
|
||||
#endif // ESP_PLATFORM
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
nimble_port_stop(void)
|
||||
{
|
||||
int rc;
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_err_t err = ESP_OK;
|
||||
ble_npl_sem_init(&ble_hs_stop_sem, 0);
|
||||
|
||||
/* Initiate a host stop procedure. */
|
||||
err = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
|
||||
NULL);
|
||||
if (err != 0) {
|
||||
ble_npl_sem_deinit(&ble_hs_stop_sem);
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
int rc = 0;
|
||||
|
||||
ble_npl_sem_init(&ble_hs_stop_sem, 0);
|
||||
|
||||
/* Initiate a host stop procedure. */
|
||||
rc = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
|
||||
NULL);
|
||||
@@ -156,12 +238,13 @@ nimble_port_stop(void)
|
||||
ble_npl_sem_deinit(&ble_hs_stop_sem);
|
||||
return rc;
|
||||
}
|
||||
#endif // ESP_PLATFORM
|
||||
|
||||
/* Wait till the host stop procedure is complete */
|
||||
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);
|
||||
|
||||
ble_npl_event_init(&ble_hs_ev_stop, nimble_port_stop_cb,
|
||||
NULL);
|
||||
NULL);
|
||||
ble_npl_eventq_put(&g_eventq_dflt, &ble_hs_ev_stop);
|
||||
|
||||
/* Wait till the event is serviced */
|
||||
@@ -169,7 +252,11 @@ nimble_port_stop(void)
|
||||
|
||||
ble_npl_sem_deinit(&ble_hs_stop_sem);
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
return ESP_OK;
|
||||
#else
|
||||
return rc;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -30,11 +30,25 @@
|
||||
static STAILQ_HEAD(, os_mbuf_pool) g_msys_pool_list =
|
||||
STAILQ_HEAD_INITIALIZER(g_msys_pool_list);
|
||||
|
||||
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
|
||||
#if CONFIG_BT_NIMBLE_ENABLED
|
||||
#define OS_MSYS_1_BLOCK_COUNT MYNEWT_VAL(MSYS_1_BLOCK_COUNT)
|
||||
#define OS_MSYS_1_BLOCK_SIZE MYNEWT_VAL(MSYS_1_BLOCK_SIZE)
|
||||
#define OS_MSYS_2_BLOCK_COUNT MYNEWT_VAL(MSYS_2_BLOCK_COUNT)
|
||||
#define OS_MSYS_2_BLOCK_SIZE MYNEWT_VAL(MSYS_2_BLOCK_SIZE)
|
||||
#else
|
||||
#define OS_MSYS_1_BLOCK_COUNT CONFIG_BT_LE_MSYS_1_BLOCK_COUNT
|
||||
#define OS_MSYS_1_BLOCK_SIZE CONFIG_BT_LE_MSYS_1_BLOCK_SIZE
|
||||
#define OS_MSYS_2_BLOCK_COUNT CONFIG_BT_LE_MSYS_2_BLOCK_COUNT
|
||||
#define OS_MSYS_2_BLOCK_SIZE CONFIG_BT_LE_MSYS_2_BLOCK_SIZE
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if OS_MSYS_1_BLOCK_COUNT > 0
|
||||
#define SYSINIT_MSYS_1_MEMBLOCK_SIZE \
|
||||
OS_ALIGN(MYNEWT_VAL(MSYS_1_BLOCK_SIZE), 4)
|
||||
OS_ALIGN(OS_MSYS_1_BLOCK_SIZE, 4)
|
||||
#define SYSINIT_MSYS_1_MEMPOOL_SIZE \
|
||||
OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_1_BLOCK_COUNT), \
|
||||
OS_MEMPOOL_SIZE(OS_MSYS_1_BLOCK_COUNT, \
|
||||
SYSINIT_MSYS_1_MEMBLOCK_SIZE)
|
||||
#ifdef ESP_PLATFORM
|
||||
static os_membuf_t *os_msys_init_1_data;
|
||||
@@ -45,11 +59,11 @@ static struct os_mbuf_pool os_msys_init_1_mbuf_pool;
|
||||
static struct os_mempool os_msys_init_1_mempool;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
|
||||
#if OS_MSYS_2_BLOCK_COUNT > 0
|
||||
#define SYSINIT_MSYS_2_MEMBLOCK_SIZE \
|
||||
OS_ALIGN(MYNEWT_VAL(MSYS_2_BLOCK_SIZE), 4)
|
||||
OS_ALIGN(OS_MSYS_2_BLOCK_SIZE, 4)
|
||||
#define SYSINIT_MSYS_2_MEMPOOL_SIZE \
|
||||
OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_2_BLOCK_COUNT), \
|
||||
OS_MEMPOOL_SIZE(OS_MSYS_2_BLOCK_COUNT, \
|
||||
SYSINIT_MSYS_2_MEMBLOCK_SIZE)
|
||||
#ifdef ESP_PLATFORM
|
||||
static os_membuf_t *os_msys_init_2_data;
|
||||
@@ -135,14 +149,14 @@ os_msys_init_once(void *data, struct os_mempool *mempool,
|
||||
int
|
||||
os_msys_buf_alloc(void)
|
||||
{
|
||||
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
|
||||
#if OS_MSYS_1_BLOCK_COUNT > 0
|
||||
os_msys_init_1_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_1_MEMPOOL_SIZE));
|
||||
if (!os_msys_init_1_data) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
|
||||
#if OS_MSYS_2_BLOCK_COUNT > 0
|
||||
os_msys_init_2_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE));
|
||||
if (!os_msys_init_2_data) {
|
||||
return ESP_FAIL;
|
||||
@@ -155,12 +169,12 @@ os_msys_buf_alloc(void)
|
||||
void
|
||||
os_msys_buf_free(void)
|
||||
{
|
||||
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
|
||||
#if OS_MSYS_1_BLOCK_COUNT > 0
|
||||
nimble_platform_mem_free(os_msys_init_1_data);
|
||||
os_msys_init_1_data = NULL;
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
|
||||
#if OS_MSYS_2_BLOCK_COUNT > 0
|
||||
nimble_platform_mem_free(os_msys_init_2_data);
|
||||
os_msys_init_2_data = NULL;
|
||||
#endif
|
||||
@@ -176,20 +190,20 @@ void os_msys_init(void)
|
||||
|
||||
os_msys_reset();
|
||||
|
||||
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
|
||||
#if OS_MSYS_1_BLOCK_COUNT > 0
|
||||
os_msys_init_once(os_msys_init_1_data,
|
||||
&os_msys_init_1_mempool,
|
||||
&os_msys_init_1_mbuf_pool,
|
||||
MYNEWT_VAL(MSYS_1_BLOCK_COUNT),
|
||||
OS_MSYS_1_BLOCK_COUNT,
|
||||
SYSINIT_MSYS_1_MEMBLOCK_SIZE,
|
||||
"msys_1");
|
||||
#endif
|
||||
|
||||
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
|
||||
#if OS_MSYS_2_BLOCK_COUNT > 0
|
||||
os_msys_init_once(os_msys_init_2_data,
|
||||
&os_msys_init_2_mempool,
|
||||
&os_msys_init_2_mbuf_pool,
|
||||
MYNEWT_VAL(MSYS_2_BLOCK_COUNT),
|
||||
OS_MSYS_2_BLOCK_COUNT,
|
||||
SYSINIT_MSYS_2_MEMBLOCK_SIZE,
|
||||
"msys_2");
|
||||
#endif
|
||||
|
||||
@@ -23,22 +23,45 @@
|
||||
#include "nimble/nimble/include/nimble/nimble_npl.h"
|
||||
#include "nimble/porting/nimble/include/syscfg/syscfg.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "esp_err.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/**
|
||||
* @brief esp_nimble_enable - Initialize the NimBLE host task
|
||||
*
|
||||
* @param host_task
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_enable(void *host_task);
|
||||
|
||||
/**
|
||||
* @brief esp_nimble_disable - Disable the NimBLE host task
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_disable(void);
|
||||
#endif
|
||||
|
||||
void nimble_port_freertos_init(TaskFunction_t host_task_fn);
|
||||
void nimble_port_freertos_deinit(void);
|
||||
|
||||
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
|
||||
void npl_freertos_funcs_init(void);
|
||||
void npl_freertos_funcs_deinit(void);
|
||||
int npl_freertos_mempool_init(void);
|
||||
struct npl_funcs_t * npl_freertos_funcs_get(void);
|
||||
#endif
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
UBaseType_t nimble_port_freertos_get_ll_hwm(void);
|
||||
#endif
|
||||
UBaseType_t nimble_port_freertos_get_hs_hwm(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -41,7 +41,51 @@ static StackType_t hs_xStack[ NIMBLE_HS_STACK_SIZE ];
|
||||
static StaticTask_t hs_xTaskBuffer;
|
||||
#endif
|
||||
|
||||
static TaskHandle_t host_task_h;
|
||||
static TaskHandle_t host_task_h = NULL;
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
/**
|
||||
* @brief esp_nimble_enable - Initialize the NimBLE host
|
||||
*
|
||||
* @param host_task
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_enable(void *host_task)
|
||||
{
|
||||
/*
|
||||
* Create task where NimBLE host will run. It is not strictly necessary to
|
||||
* have separate task for NimBLE host, but since something needs to handle
|
||||
* default queue it is just easier to make separate task which does this.
|
||||
*/
|
||||
xTaskCreatePinnedToCore(host_task, "nimble_host", NIMBLE_HS_STACK_SIZE,
|
||||
NULL, (configMAX_PRIORITIES - 4), &host_task_h, NIMBLE_CORE);
|
||||
return ESP_OK;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief esp_nimble_disable - Disable the NimBLE host
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t esp_nimble_disable(void)
|
||||
{
|
||||
if (host_task_h) {
|
||||
vTaskDelete(host_task_h);
|
||||
host_task_h = NULL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
// Compatibility wrappers for new functions
|
||||
void nimble_port_freertos_init(TaskFunction_t host_task_fn) {
|
||||
esp_nimble_enable((void*)host_task_fn);
|
||||
}
|
||||
void nimble_port_freertos_deinit(void) {
|
||||
esp_nimble_disable();
|
||||
}
|
||||
|
||||
#else // ESP_PLATFORM
|
||||
|
||||
void
|
||||
nimble_port_freertos_init(TaskFunction_t host_task_fn)
|
||||
@@ -53,26 +97,16 @@ nimble_port_freertos_init(TaskFunction_t host_task_fn)
|
||||
* provided by NimBLE and in case of FreeRTOS it does not need to be wrapped
|
||||
* since it has compatible prototype.
|
||||
*/
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
#else
|
||||
ll_task_h = xTaskCreateStatic(nimble_port_ll_task_func, "ll", NIMBLE_LL_STACK_SIZE,
|
||||
NULL, configMAX_PRIORITIES, ll_xStack, &ll_xTaskBuffer);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
* Create task where NimBLE host will run. It is not strictly necessary to
|
||||
* have separate task for NimBLE host, but since something needs to handle
|
||||
* default queue it is just easier to make separate task which does this.
|
||||
*/
|
||||
#ifdef ESP_PLATFORM
|
||||
xTaskCreatePinnedToCore(host_task_fn, "ble", NIMBLE_HS_STACK_SIZE,
|
||||
NULL, (configMAX_PRIORITIES - 4), &host_task_h, NIMBLE_CORE);
|
||||
#else
|
||||
host_task_h = xTaskCreateStatic(host_task_fn, "ble", NIMBLE_HS_STACK_SIZE,
|
||||
NULL, (configMAX_PRIORITIES - 1), hs_xStack, &hs_xTaskBuffer);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -81,12 +115,8 @@ nimble_port_freertos_deinit(void)
|
||||
if (host_task_h) {
|
||||
vTaskDelete(host_task_h);
|
||||
}
|
||||
#ifdef ESP_PLATFORM
|
||||
esp_bt_controller_disable();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef ESP_PLATFORM
|
||||
#if NIMBLE_CFG_CONTROLLER
|
||||
UBaseType_t
|
||||
nimble_port_freertos_get_ll_hwm(void)
|
||||
@@ -94,10 +124,11 @@ nimble_port_freertos_get_ll_hwm(void)
|
||||
return uxTaskGetStackHighWaterMark(ll_task_h);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
UBaseType_t
|
||||
nimble_port_freertos_get_hs_hwm(void)
|
||||
{
|
||||
return uxTaskGetStackHighWaterMark(host_task_h);
|
||||
}
|
||||
|
||||
#endif //ESP_PLATFORM
|
||||
|
||||
@@ -60,14 +60,28 @@ static const char *TAG = "Timer";
|
||||
|
||||
#define OS_MEM_ALLOC (1)
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLED
|
||||
#define BT_LE_HCI_EVT_HI_BUF_COUNT MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT)
|
||||
#define BT_LE_HCI_EVT_LO_BUF_COUNT MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT)
|
||||
#define BT_LE_MAX_EXT_ADV_INSTANCES MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES)
|
||||
#define BT_LE_MAX_CONNECTIONS MYNEWT_VAL(BLE_MAX_CONNECTIONS)
|
||||
#else
|
||||
#include "esp_bt.h"
|
||||
#define BT_LE_HCI_EVT_HI_BUF_COUNT DEFAULT_BT_LE_HCI_EVT_HI_BUF_COUNT
|
||||
#define BT_LE_HCI_EVT_LO_BUF_COUNT DEFAULT_BT_LE_HCI_EVT_LO_BUF_COUNT
|
||||
#define BT_LE_MAX_EXT_ADV_INSTANCES DEFAULT_BT_LE_MAX_EXT_ADV_INSTANCES
|
||||
#define BT_LE_MAX_CONNECTIONS DEFAULT_BT_LE_MAX_CONNECTIONS
|
||||
#endif
|
||||
|
||||
#define BLE_HS_HCI_EVT_COUNT \
|
||||
(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + \
|
||||
MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
|
||||
(BT_LE_HCI_EVT_HI_BUF_COUNT + \
|
||||
BT_LE_HCI_EVT_LO_BUF_COUNT)
|
||||
|
||||
|
||||
#define LL_NPL_BASE_EVENT_COUNT (11)
|
||||
#define LL_SCAN_EXT_AUX_EVT_CNT (MYNEWT_VAL(BLE_LL_EXT_ADV_AUX_PTR_CNT))
|
||||
#define HCI_LL_NPL_EVENT_COUNT (1)
|
||||
#define ADV_LL_NPL_EVENT_COUNT ((MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES)+1)*3)
|
||||
#define ADV_LL_NPL_EVENT_COUNT ((BT_LE_MAX_EXT_ADV_INSTANCES+1)*3)
|
||||
#define SCAN_LL_NPL_EVENT_COUNT (2)
|
||||
#define RL_LL_NPL_EVENT_COUNT (1)
|
||||
#define SYNC_LL_NPL_EVENT_COUNT (7)
|
||||
@@ -84,7 +98,8 @@ static const char *TAG = "Timer";
|
||||
#define LL_CFG_FEAT_LE_PING_EVT (0)
|
||||
#endif
|
||||
|
||||
#define CONN_MODULE_NPL_EVENT_COUNT (((LL_CFG_FEAT_LE_PING_EVT+2)*MYNEWT_VAL(BLE_MAX_CONNECTIONS))+LL_CTRL_TO_HOST_FLOW_CTRL_EVT)
|
||||
#define CONN_MODULE_NPL_EVENT_COUNT (((LL_CFG_FEAT_LE_PING_EVT+2)*BT_LE_MAX_CONNECTIONS)+LL_CTRL_TO_HOST_FLOW_CTRL_EVT)
|
||||
|
||||
|
||||
#define BLE_LL_EV_COUNT (LL_NPL_BASE_EVENT_COUNT + \
|
||||
LL_SCAN_EXT_AUX_EVT_CNT + \
|
||||
@@ -99,7 +114,7 @@ static const char *TAG = "Timer";
|
||||
|
||||
#define BLE_TOTAL_EVQ_COUNT (10)
|
||||
|
||||
#define BLE_TOTAL_CO_COUNT (20)
|
||||
#define BLE_TOTAL_CO_COUNT (40)
|
||||
|
||||
#define BLE_TOTAL_SEM_COUNT (10)
|
||||
|
||||
@@ -1013,15 +1028,22 @@ IRAM_ATTR npl_freertos_callout_set_arg(struct ble_npl_callout *co, void *arg)
|
||||
uint32_t
|
||||
IRAM_ATTR npl_freertos_time_get(void)
|
||||
{
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
return esp_timer_get_time() / 1000;
|
||||
#else
|
||||
return xTaskGetTickCountFromISR();
|
||||
#endif
|
||||
}
|
||||
|
||||
ble_npl_error_t
|
||||
IRAM_ATTR npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
|
||||
{
|
||||
uint64_t ticks;
|
||||
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
ticks = (uint64_t)ms;
|
||||
#else
|
||||
ticks = ((uint64_t)ms * configTICK_RATE_HZ) / 1000;
|
||||
#endif
|
||||
if (ticks > UINT32_MAX) {
|
||||
return BLE_NPL_EINVAL;
|
||||
}
|
||||
@@ -1035,8 +1057,11 @@ ble_npl_error_t
|
||||
IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
|
||||
{
|
||||
uint64_t ms;
|
||||
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
ms = ((uint64_t)ticks);
|
||||
#else
|
||||
ms = ((uint64_t)ticks * 1000) / configTICK_RATE_HZ;
|
||||
#endif
|
||||
if (ms > UINT32_MAX) {
|
||||
return BLE_NPL_EINVAL;
|
||||
}
|
||||
@@ -1049,19 +1074,31 @@ IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
|
||||
ble_npl_time_t
|
||||
IRAM_ATTR npl_freertos_time_ms_to_ticks32(uint32_t ms)
|
||||
{
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
return ms;
|
||||
#else
|
||||
return ms * configTICK_RATE_HZ / 1000;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t
|
||||
IRAM_ATTR npl_freertos_time_ticks_to_ms32(ble_npl_time_t ticks)
|
||||
{
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
return ticks;
|
||||
#else
|
||||
return ticks * 1000 / configTICK_RATE_HZ;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
IRAM_ATTR npl_freertos_time_delay(ble_npl_time_t ticks)
|
||||
{
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
vTaskDelay(ticks / portTICK_PERIOD_MS);
|
||||
#else
|
||||
vTaskDelay(ticks);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@@ -1734,6 +1771,10 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
||||
void
|
||||
npl_freertos_callout_deinit(struct ble_npl_callout *co)
|
||||
{
|
||||
if (!co->handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
if(esp_timer_stop(co->handle))
|
||||
ESP_LOGW(TAG, "Timer not stopped");
|
||||
@@ -1741,9 +1782,8 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
|
||||
if(esp_timer_delete(co->handle))
|
||||
ESP_LOGW(TAG, "Timer not deleted");
|
||||
#else
|
||||
if (co->handle) {
|
||||
xTimerDelete(co->handle, portMAX_DELAY);
|
||||
}
|
||||
xTimerDelete(co->handle, portMAX_DELAY);
|
||||
ble_npl_event_deinit(&co->ev);
|
||||
#endif
|
||||
memset(co, 0, sizeof(struct ble_npl_callout));
|
||||
}
|
||||
@@ -1787,6 +1827,9 @@ npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
|
||||
void
|
||||
npl_freertos_callout_stop(struct ble_npl_callout *co)
|
||||
{
|
||||
if (!co->handle) {
|
||||
return;
|
||||
}
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
esp_timer_stop(co->handle);
|
||||
#else
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
/** @brief Uncomment to set the default allocation size (bytes) for each attribute if\n
|
||||
* not specified when the constructor is called. This is also the size used when a remote\n
|
||||
* characteristic or descriptor is constructed before a value is read/notifed.\n
|
||||
* characteristic or descriptor is constructed before a value is read/notified.\n
|
||||
* Increasing this will reduce reallocations but increase memory footprint.\n
|
||||
* Default value is 20. Range: 1 : 512 (BLE_ATT_ATTR_MAX_LEN)
|
||||
*/
|
||||
@@ -75,11 +75,6 @@
|
||||
*/
|
||||
// #define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
|
||||
|
||||
/** @brief Un-comment to use timestamps with characteristic / descriptor values
|
||||
* If not enabled the `::get/readValue()` calls with a timestamp parameter will set the timestamp to 0.
|
||||
*/
|
||||
// #define NIMBLE_ATT_VALUE_TIMESTAMP_ENABLED
|
||||
|
||||
/** @brief Un-comment to see NimBLE host return codes as text debug log messages.
|
||||
* Uses approx. 7kB of flash memory.
|
||||
*/
|
||||
@@ -90,10 +85,10 @@
|
||||
*/
|
||||
// #define CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT
|
||||
|
||||
/** @brief Un-comment to see advertisment types as text while scanning in debug log messages.
|
||||
/** @brief Un-comment to see advertisement types as text while scanning in debug log messages.
|
||||
* Uses approx. 250 bytes of flash memory.
|
||||
*/
|
||||
// #define CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT
|
||||
// #define CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT
|
||||
|
||||
/** @brief Un-comment to change the default GAP appearance */
|
||||
// #define CONFIG_BT_NIMBLE_SVC_GAP_APPEARANCE 0x0
|
||||
@@ -268,6 +263,10 @@
|
||||
#define CONFIG_BT_ENABLED
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_BT_NIMBLE_ENABLED
|
||||
#define CONFIG_BT_NIMBLE_ENABLED 1
|
||||
#endif
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#ifndef CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY
|
||||
#define CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY
|
||||
|
||||
Reference in New Issue
Block a user