Skip to content

Refactor config to use MYNEWT macros #1004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ jobs:

[env:esp32c3]
board = esp32-c3-devkitm-1
build_flags = '-DCONFIG_BT_NIMBLE_EXT_ADV=1'
build_flags = '-DMYNEWT_VAL_BLE_EXT_ADV=1'

[env:esp32s3]
board = esp32-s3-devkitc-1
build_flags = '-DCONFIG_BT_NIMBLE_EXT_ADV=1'
build_flags = '-DMYNEWT_VAL_BLE_EXT_ADV=1'
EOF
cp ${{ matrix.example }}/* example/src/
platformio run -d example
Expand Down Expand Up @@ -163,19 +163,19 @@ jobs:

[env:esp32c3]
board = esp32-c3-devkitm-1
build_flags = '-DCONFIG_BT_NIMBLE_EXT_ADV=1'
build_flags = '-DMYNEWT_VAL_BLE_EXT_ADV=1'

[env:esp32s3]
board = esp32-s3-devkitc-1
build_flags = '-DCONFIG_BT_NIMBLE_EXT_ADV=1'
build_flags = '-DMYNEWT_VAL_BLE_EXT_ADV=1'

[env:esp32c6]
board = esp32-c6-devkitc-1
build_flags = '-DCONFIG_BT_NIMBLE_EXT_ADV=1'
build_flags = '-DMYNEWT_VAL_BLE_EXT_ADV=1'

[env:esp32h2]
board = esp32-h2-devkitm-1
build_flags = '-DCONFIG_BT_NIMBLE_EXT_ADV=1'
build_flags = '-DMYNEWT_VAL_BLE_EXT_ADV=1'
EOF
cp ${{ matrix.example }}/* example/src/
platformio run -d example
Expand Down Expand Up @@ -224,7 +224,7 @@ jobs:
- uses: actions/checkout@v4
- name: Set config for BT5
run: |
sed -i '0,/#include \"nimconfig_rename.h\"/a #define CONFIG_BT_NIMBLE_EXT_ADV 1' ./src/nimconfig.h
sed -i '0,/#include \"nimconfig_rename.h\"/a #define MYNEWT_VAL_BLE_EXT_ADV 1' ./src/nimconfig.h
- name: Build BT5 arduino-esp32
uses: arduino/compile-sketches@v1.1.0
with:
Expand Down Expand Up @@ -276,7 +276,7 @@ jobs:
- uses: actions/checkout@v4
- name: Set config for BT5
run: |
echo "-DCONFIG_BT_NIMBLE_EXT_ADV=1" > ${{ matrix.example }}/build_opt.h
echo "-DMYNEWT_VAL_BLE_EXT_ADV=1" > ${{ matrix.example }}/build_opt.h
- name: Build BT5 n-able Arduino
uses: arduino/compile-sketches@v1.1.0
with:
Expand Down
2 changes: 1 addition & 1 deletion docs/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -2416,7 +2416,7 @@ INCLUDE_FILE_PATTERNS =
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = _DOXYGEN_ \
CONFIG_BT_ENABLED \
CONFIG_BT_NIMBLE_ENABLED \
CONFIG_BT_NIMBLE_ROLE_CENTRAL \
CONFIG_BT_NIMBLE_ROLE_OBSERVER \
CONFIG_BT_NIMBLE_ROLE_PERIPHERAL \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <Arduino.h>
#include <NimBLEDevice.h>
#if !CONFIG_BT_NIMBLE_EXT_ADV
#if !MYNEWT_VAL(BLE_EXT_ADV)
# error Must enable extended advertising, see nimconfig.h file.
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <Arduino.h>
#include <NimBLEDevice.h>
#if !CONFIG_BT_NIMBLE_EXT_ADV
#if !MYNEWT_VAL(BLE_EXT_ADV)
# error Must enable extended advertising, see nimconfig.h file.
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <Arduino.h>
#include <NimBLEDevice.h>
#if !CONFIG_BT_NIMBLE_EXT_ADV
#if !MYNEWT_VAL(BLE_EXT_ADV)
# error Must enable extended advertising, see nimconfig.h file.
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <Arduino.h>
#include <NimBLEDevice.h>
#if !CONFIG_BT_NIMBLE_EXT_ADV
#if !MYNEWT_VAL(BLE_EXT_ADV)
# error Must enable extended advertising, see nimconfig.h file.
#endif

Expand Down
4 changes: 2 additions & 2 deletions examples/L2CAP/L2CAP_Client/L2CAP_Client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <Arduino.h>
#include <NimBLEDevice.h>

#if CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM <= 0
# error "CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM must be set to 1 or greater"
#if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) < 1
# error "MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM must be set to 1 or greater"
#endif

// See the following for generating UUIDs:
Expand Down
2 changes: 1 addition & 1 deletion examples/NimBLE_Client/NimBLE_Client.ino
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool connectToServer() {

/** No client to reuse? Create a new one. */
if (!pClient) {
if (NimBLEDevice::getCreatedClientCount() >= NIMBLE_MAX_CONNECTIONS) {
if (NimBLEDevice::getCreatedClientCount() >= MYNEWT_VAL(BLE_MAX_CONNECTIONS)) {
Serial.printf("Max clients reached - no more connections available\n");
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/NimBLE2904.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "NimBLE2904.h"
#if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
#if CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_PERIPHERAL)

NimBLE2904::NimBLE2904(NimBLECharacteristic* pChr)
: NimBLEDescriptor(NimBLEUUID((uint16_t)0x2904), BLE_GATT_CHR_F_READ, sizeof(NimBLE2904Data), pChr) {
Expand Down Expand Up @@ -69,4 +69,4 @@ void NimBLE2904::setUnit(uint16_t unit) {
setValue(m_data);
} // setUnit

#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
#endif // CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
6 changes: 3 additions & 3 deletions src/NimBLE2904.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef NIMBLE_CPP_2904_H_
#define NIMBLE_CPP_2904_H_

#include "nimconfig.h"
#if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
#include "syscfg/syscfg.h"
#if CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_PERIPHERAL)

# include "NimBLEDescriptor.h"

Expand Down Expand Up @@ -79,5 +79,5 @@ class NimBLE2904 : public NimBLEDescriptor {
NimBLE2904Data m_data{};
}; // NimBLE2904

#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
#endif // CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
#endif // NIMBLE_CPP_2904_H_
2 changes: 1 addition & 1 deletion src/NimBLEAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "NimBLEAddress.h"
#if CONFIG_BT_ENABLED
#if CONFIG_BT_NIMBLE_ENABLED

# include "NimBLELog.h"

Expand Down
6 changes: 3 additions & 3 deletions src/NimBLEAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef NIMBLE_CPP_ADDRESS_H_
#define NIMBLE_CPP_ADDRESS_H_

#include "nimconfig.h"
#if CONFIG_BT_ENABLED
#include "syscfg/syscfg.h"
#if CONFIG_BT_NIMBLE_ENABLED

# if defined(CONFIG_NIMBLE_CPP_IDF)
# include "nimble/ble.h"
Expand Down Expand Up @@ -67,5 +67,5 @@ class NimBLEAddress : private ble_addr_t {
operator uint64_t() const;
};

#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BT_NIMBLE_ENABLED
#endif // NIMBLE_CPP_ADDRESS_H_
14 changes: 7 additions & 7 deletions src/NimBLEAdvertisedDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "NimBLEAdvertisedDevice.h"
#if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_OBSERVER
#if CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_OBSERVER)

# include "NimBLEDevice.h"
# include "NimBLEUtils.h"
Expand All @@ -31,7 +31,7 @@ static const char* LOG_TAG = "NimBLEAdvertisedDevice";
* @param [in] event The advertisement event data.
*/
NimBLEAdvertisedDevice::NimBLEAdvertisedDevice(const ble_gap_event* event, uint8_t eventType)
# if CONFIG_BT_NIMBLE_EXT_ADV
# if MYNEWT_VAL(BLE_EXT_ADV)
: m_address{event->ext_disc.addr},
m_advType{eventType},
m_rssi{event->ext_disc.rssi},
Expand All @@ -58,7 +58,7 @@ NimBLEAdvertisedDevice::NimBLEAdvertisedDevice(const ble_gap_event* event, uint8
* @param [in] event The advertisement event data.
*/
void NimBLEAdvertisedDevice::update(const ble_gap_event* event, uint8_t eventType) {
# if CONFIG_BT_NIMBLE_EXT_ADV
# if MYNEWT_VAL(BLE_EXT_ADV)
const auto& disc = event->ext_disc;
m_isLegacyAdv = disc.props & BLE_HCI_ADV_LEGACY_MASK;
# else
Expand Down Expand Up @@ -580,7 +580,7 @@ bool NimBLEAdvertisedDevice::haveTXPower() const {
return findAdvField(BLE_HS_ADV_TYPE_TX_PWR_LVL) > 0;
} // haveTXPower

# if CONFIG_BT_NIMBLE_EXT_ADV
# if MYNEWT_VAL(BLE_EXT_ADV)
/**
* @brief Get the set ID of the extended advertisement.
* @return The set ID.
Expand Down Expand Up @@ -751,7 +751,7 @@ uint8_t NimBLEAdvertisedDevice::getAddressType() const {
* @return True if the device is connectable.
*/
bool NimBLEAdvertisedDevice::isConnectable() const {
# if CONFIG_BT_NIMBLE_EXT_ADV
# if MYNEWT_VAL(BLE_EXT_ADV)
if (m_isLegacyAdv) {
return m_advType == BLE_HCI_ADV_RPT_EVTYPE_ADV_IND || m_advType == BLE_HCI_ADV_RPT_EVTYPE_DIR_IND;
}
Expand All @@ -772,7 +772,7 @@ bool NimBLEAdvertisedDevice::isScannable() const {
* @return True if legacy (Bluetooth 4.x), false if extended (bluetooth 5.x).
*/
bool NimBLEAdvertisedDevice::isLegacyAdvertisement() const {
# if CONFIG_BT_NIMBLE_EXT_ADV
# if MYNEWT_VAL(BLE_EXT_ADV)
return m_isLegacyAdv;
# else
return true;
Expand Down Expand Up @@ -813,4 +813,4 @@ const std::vector<uint8_t>::const_iterator NimBLEAdvertisedDevice::end() const {
return m_payload.cend();
}

#endif // CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_OBSERVER
#endif // CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_OBSERVER)
10 changes: 5 additions & 5 deletions src/NimBLEAdvertisedDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef NIMBLE_CPP_ADVERTISED_DEVICE_H_
#define NIMBLE_CPP_ADVERTISED_DEVICE_H_

#include "nimconfig.h"
#if CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_OBSERVER
#include "syscfg/syscfg.h"
#if CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_OBSERVER)

# include "NimBLEAddress.h"
# include "NimBLEScan.h"
Expand Down Expand Up @@ -87,7 +87,7 @@ class NimBLEAdvertisedDevice {
bool isConnectable() const;
bool isScannable() const;
bool isLegacyAdvertisement() const;
# if CONFIG_BT_NIMBLE_EXT_ADV
# if MYNEWT_VAL(BLE_EXT_ADV)
uint8_t getSetId() const;
uint8_t getPrimaryPhy() const;
uint8_t getSecondaryPhy() const;
Expand Down Expand Up @@ -163,7 +163,7 @@ class NimBLEAdvertisedDevice {
uint8_t m_callbackSent{};
uint8_t m_advLength{};

# if CONFIG_BT_NIMBLE_EXT_ADV
# if MYNEWT_VAL(BLE_EXT_ADV)
bool m_isLegacyAdv{};
uint8_t m_sid{};
uint8_t m_primPhy{};
Expand All @@ -174,5 +174,5 @@ class NimBLEAdvertisedDevice {
std::vector<uint8_t> m_payload;
};

#endif /* CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_OBSERVER */
#endif /* CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_OBSERVER) */
#endif /* NIMBLE_CPP_ADVERTISED_DEVICE_H_ */
4 changes: 2 additions & 2 deletions src/NimBLEAdvertisementData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "NimBLEAdvertisementData.h"
#if (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#if (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)

# include "NimBLEDevice.h"
# include "NimBLEUtils.h"
Expand Down Expand Up @@ -583,4 +583,4 @@ std::string NimBLEAdvertisementData::toString() const {
return str;
} // toString

#endif // (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#endif // (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)
6 changes: 3 additions & 3 deletions src/NimBLEAdvertisementData.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef NIMBLE_CPP_ADVERTISEMENT_DATA_H_
#define NIMBLE_CPP_ADVERTISEMENT_DATA_H_

#include "nimconfig.h"
#if (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#include "syscfg/syscfg.h"
#if (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)

# include <cstdint>
# include <string>
Expand Down Expand Up @@ -74,5 +74,5 @@ class NimBLEAdvertisementData {
std::vector<uint8_t> m_payload{};
}; // NimBLEAdvertisementData

#endif // (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#endif // (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)
#endif // NIMBLE_CPP_ADVERTISEMENT_DATA_H_
10 changes: 5 additions & 5 deletions src/NimBLEAdvertising.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

#include "NimBLEAdvertising.h"
#if (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#if (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)

# if defined(CONFIG_NIMBLE_CPP_IDF)
# include "services/gap/ble_svc_gap.h"
Expand All @@ -42,7 +42,7 @@ NimBLEAdvertising::NimBLEAdvertising()
m_duration{BLE_HS_FOREVER},
m_scanResp{false},
m_advDataSet{false} {
# if !CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
# if !MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
m_advParams.conn_mode = BLE_GAP_CONN_MODE_NON;
# else
m_advParams.conn_mode = BLE_GAP_CONN_MODE_UND;
Expand Down Expand Up @@ -195,7 +195,7 @@ bool NimBLEAdvertising::start(uint32_t duration, const NimBLEAddress* dirAddr) {
return true;
}

# if CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
NimBLEServer* pServer = NimBLEDevice::getServer();
if (pServer != nullptr) {
pServer->start(); // make sure the GATT server is ready before advertising
Expand All @@ -220,7 +220,7 @@ bool NimBLEAdvertising::start(uint32_t duration, const NimBLEAddress* dirAddr) {
duration = BLE_HS_FOREVER;
}

# if CONFIG_BT_NIMBLE_ROLE_PERIPHERAL
# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
int rc = ble_gap_adv_start(NimBLEDevice::m_ownAddrType,
(dirAddr != nullptr) ? dirAddr->getBase() : NULL,
duration,
Expand Down Expand Up @@ -620,4 +620,4 @@ bool NimBLEAdvertising::setServiceData(const NimBLEUUID& uuid, const std::string
return setServiceData(uuid, reinterpret_cast<const uint8_t*>(data.data()), data.length());
} // setServiceData

#endif // (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#endif // (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)
6 changes: 3 additions & 3 deletions src/NimBLEAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#ifndef NIMBLE_CPP_ADVERTISING_H_
#define NIMBLE_CPP_ADVERTISING_H_

#include "nimconfig.h"
#if (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#include "syscfg/syscfg.h"
#if (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)

# if defined(CONFIG_NIMBLE_CPP_IDF)
# include "host/ble_gap.h"
Expand Down Expand Up @@ -105,5 +105,5 @@ class NimBLEAdvertising {
bool m_advDataSet : 1;
};

#endif // (CONFIG_BT_ENABLED && CONFIG_BT_NIMBLE_ROLE_BROADCASTER && !CONFIG_BT_NIMBLE_EXT_ADV) || defined(_DOXYGEN_)
#endif // (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)
#endif // NIMBLE_CPP_ADVERTISING_H_
5 changes: 3 additions & 2 deletions src/NimBLEAttValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
*/

#include "NimBLEAttValue.h"
#if CONFIG_BT_ENABLED
#if CONFIG_BT_NIMBLE_ENABLED

# if defined(CONFIG_NIMBLE_CPP_IDF)
# include "nimble/nimble_npl.h"
# else
# include "nimble/nimble/include/nimble/nimble_npl.h"
# endif

# include "NimBLEUtils.h"
# include "NimBLELog.h"

static const char* LOG_TAG = "NimBLEAttValue";
Expand Down Expand Up @@ -159,4 +160,4 @@ uint8_t NimBLEAttValue::operator[](int pos) const {
return m_attr_value[pos];
}

#endif // CONFIG_BT_ENABLED
#endif // CONFIG_BT_NIMBLE_ENABLED
Loading
Loading