Skip to content

Commit 6f0b9dd

Browse files
committed
Convert NIMBLE_CPP macros to MYNEWT.
1 parent 8f9e85a commit 6f0b9dd

11 files changed

+122
-59
lines changed

src/NimBLEAddress.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,29 @@
2222

2323
# include <algorithm>
2424

25-
# ifdef CONFIG_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER
25+
# ifndef MYNEWT_VAL_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER
26+
# ifndef CONFIG_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER
27+
# define MYNEWT_VAL_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER (0)
28+
# else
29+
# define MYNEWT_VAL_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER CONFIG_NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER
30+
# endif
31+
# endif
32+
33+
# ifndef MYNEWT_VAL_NIMBLE_CPP_ADDR_FMT_UPPERCASE
34+
# ifndef CONFIG_NIMBLE_CPP_ADDR_FMT_UPPERCASE
35+
# define MYNEWT_VAL_NIMBLE_CPP_ADDR_FMT_UPPERCASE (1)
36+
# else
37+
# define MYNEWT_VAL_NIMBLE_CPP_ADDR_FMT_UPPERCASE CONFIG_NIMBLE_CPP_ADDR_FMT_UPPERCASE
38+
# endif
39+
# endif
40+
41+
# if MYNEWT_VAL(NIMBLE_CPP_ADDR_FMT_EXCLUDE_DELIMITER)
2642
# define NIMBLE_CPP_ADDR_DELIMITER ""
2743
# else
2844
# define NIMBLE_CPP_ADDR_DELIMITER ":"
2945
# endif
3046

31-
# ifdef CONFIG_NIMBLE_CPP_ADDR_FMT_UPPERCASE
47+
# if MYNEWT_VAL(NIMBLE_CPP_ADDR_FMT_UPPERCASE)
3248
# define NIMBLE_CPP_ADDR_FMT "%02X%s%02X%s%02X%s%02X%s%02X%s%02X"
3349
# else
3450
# define NIMBLE_CPP_ADDR_FMT "%02x%s%02x%s%02x%s%02x%s%02x%s%02x"

src/NimBLEAttValue.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ NimBLEAttValue::NimBLEAttValue(uint16_t init_len, uint16_t max_len)
3535
m_attr_max_len{std::min<uint16_t>(BLE_ATT_ATTR_MAX_LEN, max_len)},
3636
m_attr_len{},
3737
m_capacity{init_len}
38-
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
38+
# if MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED)
3939
,
4040
m_timestamp{}
4141
# endif
@@ -134,7 +134,7 @@ NimBLEAttValue& NimBLEAttValue::append(const uint8_t* value, uint16_t len) {
134134
return *this;
135135
}
136136

137-
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
137+
# if MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED)
138138
time_t t = time(nullptr);
139139
# else
140140
time_t t = 0;

src/NimBLEAttValue.h

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,30 @@
3131
# include <cstring>
3232
# include <cstdint>
3333

34-
# ifndef CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
35-
# define CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED 0
34+
# ifndef MYNEWT_VAL_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
35+
# ifndef CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
36+
# define MYNEWT_VAL_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED 0
37+
# else
38+
# define MYNEWT_VAL_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
39+
# endif
3640
# endif
3741

3842
# ifndef BLE_ATT_ATTR_MAX_LEN
3943
# define BLE_ATT_ATTR_MAX_LEN 512
4044
# endif
4145

42-
# if !defined(CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH)
43-
# define CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH 20
44-
# elif CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH > BLE_ATT_ATTR_MAX_LEN
45-
# error CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH cannot be larger than 512 (BLE_ATT_ATTR_MAX_LEN)
46-
# elif CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH < 1
47-
# error CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH cannot be less than 1; Range = 1 : 512
46+
# ifndef MYNEWT_VAL_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH
47+
# ifndef CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH
48+
# define MYNEWT_VAL_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH 20
49+
# else
50+
# define MYNEWT_VAL_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH
51+
# endif
52+
# endif
53+
54+
# if MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH) > BLE_ATT_ATTR_MAX_LEN
55+
# error NIMBLE_CPP_ATT_VALUE_INIT_LENGTH cannot be larger than 512 (BLE_ATT_ATTR_MAX_LEN)
56+
# elif MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH) < 1
57+
# error NIMBLE_CPP_ATT_VALUE_INIT_LENGTH cannot be less than 1; Range = 1 : 512
4858
# endif
4959

5060
/* Used to determine if the type passed to a template has a data() and size() method. */
@@ -74,7 +84,7 @@ class NimBLEAttValue {
7484
uint16_t m_attr_max_len{};
7585
uint16_t m_attr_len{};
7686
uint16_t m_capacity{};
77-
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
87+
# if MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED)
7888
time_t m_timestamp{};
7989
# endif
8090
void deepCopy(const NimBLEAttValue& source);
@@ -85,7 +95,7 @@ class NimBLEAttValue {
8595
* @param[in] init_len The initial size in bytes.
8696
* @param[in] max_len The max size in bytes that the value can be.
8797
*/
88-
NimBLEAttValue(uint16_t init_len = CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH, uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
98+
NimBLEAttValue(uint16_t init_len = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH), uint16_t max_len = BLE_ATT_ATTR_MAX_LEN);
8999

90100
/**
91101
* @brief Construct with an initial value from a buffer.
@@ -170,7 +180,7 @@ class NimBLEAttValue {
170180
/** @brief Iterator end */
171181
const uint8_t* end() const { return m_attr_value + m_attr_len; }
172182

173-
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
183+
# if MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED)
174184
/** @brief Returns a timestamp of when the value was last updated */
175185
time_t getTimeStamp() const { return m_timestamp; }
176186

@@ -210,7 +220,7 @@ class NimBLEAttValue {
210220

211221
const NimBLEAttValue& getValue(time_t* timestamp = nullptr) const {
212222
if (timestamp != nullptr) {
213-
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
223+
# if MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED)
214224
*timestamp = m_timestamp;
215225
# else
216226
*timestamp = 0;
@@ -307,7 +317,7 @@ class NimBLEAttValue {
307317
template <typename T>
308318
T getValue(time_t* timestamp = nullptr, bool skipSizeCheck = false) const {
309319
if (timestamp != nullptr) {
310-
# if CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED
320+
# if MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED)
311321
*timestamp = m_timestamp;
312322
# else
313323
*timestamp = 0;

src/NimBLEDevice.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,7 +1325,7 @@ std::string NimBLEDevice::toString() {
13251325
return getAddress().toString();
13261326
} // toString
13271327

1328-
# if CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED || __DOXYGEN__
1328+
# if MYNEWT_VAL(NIMBLE_CPP_DEBUG_ASSERT_ENABLED) || __DOXYGEN__
13291329
/**
13301330
* @brief Debug assert - weak function.
13311331
* @param [in] file The file where the assert occurred.
@@ -1336,7 +1336,7 @@ void nimble_cpp_assert(const char* file, unsigned line) {
13361336
ble_npl_time_delay(10);
13371337
abort();
13381338
}
1339-
# endif // CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED
1339+
# endif // MYNEWT_VAL(NIMBLE_CPP_DEBUG_ASSERT_ENABLED)
13401340

13411341
void NimBLEDevice::setDeviceCallbacks(NimBLEDeviceCallbacks* cb) {
13421342
m_pDeviceCallbacks = cb ? cb : &defaultDeviceCallbacks;

src/NimBLELocalValueAttribute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class NimBLELocalValueAttribute : public NimBLELocalAttribute, public NimBLEValu
101101
NimBLELocalValueAttribute(const NimBLEUUID& uuid,
102102
uint16_t handle,
103103
uint16_t maxLen,
104-
uint16_t initLen = CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH)
104+
uint16_t initLen = MYNEWT_VAL(NIMBLE_CPP_ATT_VALUE_INIT_LENGTH))
105105
: NimBLELocalAttribute(uuid, handle), NimBLEValueAttribute(maxLen, initLen) {}
106106
/**
107107
* @brief Destroy the NimBLELocalValueAttribute object.

src/NimBLELog.h

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@
2121
#include "syscfg/syscfg.h"
2222
#if CONFIG_BT_NIMBLE_ENABLED
2323

24+
# ifndef MYNEWT_VAL_NIMBLE_CPP_LOG_LEVEL
25+
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
26+
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
27+
# define MYNEWT_VAL_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
28+
# else
29+
# define MYNEWT_VAL_NIMBLE_CPP_LOG_LEVEL 0
30+
# endif
31+
# else
32+
# define MYNEWT_VAL_NIMBLE_CPP_LOG_LEVEL CONFIG_NIMBLE_CPP_LOG_LEVEL
33+
# endif
34+
# endif
35+
2436
# if defined(CONFIG_NIMBLE_CPP_IDF)
2537
# include "esp_log.h"
2638
# include "console/console.h"
27-
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
28-
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
29-
# endif
3039

3140
# if defined(CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR)
3241
# if CONFIG_LOG_COLORS
@@ -120,13 +129,13 @@
120129

121130
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
122131
do { \
123-
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) NIMBLE_CPP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
132+
if (MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= level) NIMBLE_CPP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
124133
} while (0)
125134

126135
# else
127136
# define NIMBLE_CPP_LOG_PRINT(level, tag, format, ...) \
128137
do { \
129-
if (CONFIG_NIMBLE_CPP_LOG_LEVEL >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
138+
if (MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= level) ESP_LOG_LEVEL_LOCAL(level, tag, format, ##__VA_ARGS__); \
130139
} while (0)
131140

132141
# endif /* CONFIG_NIMBLE_CPP_LOG_OVERRIDE_COLOR */
@@ -137,35 +146,27 @@
137146
# define NIMBLE_LOGE(tag, format, ...) NIMBLE_CPP_LOG_PRINT(ESP_LOG_ERROR, tag, format, ##__VA_ARGS__)
138147

139148
# else
140-
# include "syscfg/syscfg.h"
141149
# include "nimble/console/console.h"
142-
# ifndef CONFIG_NIMBLE_CPP_LOG_LEVEL
143-
# if defined(ARDUINO_ARCH_ESP32) && defined(CORE_DEBUG_LEVEL)
144-
# define CONFIG_NIMBLE_CPP_LOG_LEVEL CORE_DEBUG_LEVEL
145-
# else
146-
# define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
147-
# endif
148-
# endif
149150

150-
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
151+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 4
151152
# define NIMBLE_LOGD(tag, format, ...) console_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
152153
# else
153154
# define NIMBLE_LOGD(tag, format, ...) (void)tag
154155
# endif
155156

156-
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
157+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 3
157158
# define NIMBLE_LOGI(tag, format, ...) console_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
158159
# else
159160
# define NIMBLE_LOGI(tag, format, ...) (void)tag
160161
# endif
161162

162-
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 2
163+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 2
163164
# define NIMBLE_LOGW(tag, format, ...) console_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
164165
# else
165166
# define NIMBLE_LOGW(tag, format, ...) (void)tag
166167
# endif
167168

168-
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 1
169+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 1
169170
# define NIMBLE_LOGE(tag, format, ...) console_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
170171
# else
171172
# define NIMBLE_LOGE(tag, format, ...) (void)tag

src/NimBLEScan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int NimBLEScan::handleGapEvent(ble_gap_event* event, void* arg) {
126126
}
127127
}
128128

129-
#if MYNEWT_VAL(BLE_EXT_ADV)
129+
# if MYNEWT_VAL(BLE_EXT_ADV)
130130
if (advertisedDevice->getDataStatus() == BLE_GAP_EXT_ADV_DATA_STATUS_INCOMPLETE) {
131131
NIMBLE_LOGD(LOG_TAG, "EXT ADV data incomplete, waiting for more");
132132
return 0;
@@ -498,7 +498,7 @@ void NimBLEScan::clearResults() {
498498
* @brief Dump the scan results to the log.
499499
*/
500500
void NimBLEScanResults::dump() const {
501-
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 3
501+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 3
502502
for (const auto& dev : m_deviceVec) {
503503
NIMBLE_LOGI(LOG_TAG, "- %s", dev->toString().c_str());
504504
}

src/NimBLEServer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void NimBLEServer::start() {
189189
return;
190190
}
191191

192-
# if CONFIG_NIMBLE_CPP_LOG_LEVEL >= 4
192+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 4
193193
ble_gatts_show_local();
194194
# endif
195195

0 commit comments

Comments
 (0)