Skip to content

Commit 1b7cb22

Browse files
committed
Fix builds
1 parent 2152bbd commit 1b7cb22

File tree

2 files changed

+64
-60
lines changed

2 files changed

+64
-60
lines changed

src/NimBLEStream.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include "NimBLEStream.h"
19-
#if CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
18+
#ifdef ESP_PLATFORM
19+
# include "NimBLEStream.h"
20+
# if CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
2021

21-
# include "NimBLEDevice.h"
22+
# include "NimBLEDevice.h"
23+
# include "rom/uart.h"
2224

2325
static const char* LOG_TAG = "NimBLEStream";
2426

2527
// Stub Print/Stream implementations when Arduino not available
26-
# if !NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
28+
# if !NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
2729
size_t Print::print(const char* s) {
2830
if (!s) return 0;
2931
return write(reinterpret_cast<const uint8_t*>(s), strlen(s));
@@ -68,7 +70,7 @@ size_t Print::printf(const char* fmt, ...) {
6870
free(buf);
6971
return ret;
7072
}
71-
# endif
73+
# endif
7274

7375
void NimBLEStream::txTask(void* arg) {
7476
NimBLEStream* pStream = static_cast<NimBLEStream*>(arg);
@@ -249,7 +251,7 @@ size_t NimBLEStream::pushRx(const uint8_t* data, size_t len) {
249251
return len;
250252
}
251253

252-
# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
254+
# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
253255
bool NimBLEStreamServer::init(const NimBLEUUID& svcUuid, const NimBLEUUID& chrUuid, bool canWrite, bool secure) {
254256
if (!NimBLEDevice::isInitialized()) {
255257
NIMBLE_UART_LOGE(LOG_TAG, "NimBLEDevice not initialized");
@@ -316,7 +318,7 @@ size_t NimBLEStreamServer::write(const uint8_t* data, size_t len) {
316318
return 0;
317319
}
318320

319-
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 4
321+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 4
320322
// Skip server gap events to avoid log recursion
321323
static const char filterStr[] = "handleGapEvent";
322324
constexpr size_t filterLen = sizeof(filterStr) - 1;
@@ -327,7 +329,7 @@ size_t NimBLEStreamServer::write(const uint8_t* data, size_t len) {
327329
}
328330
}
329331
}
330-
# endif
332+
# endif
331333

332334
return NimBLEStream::write(data, len);
333335
}
@@ -396,9 +398,9 @@ void NimBLEStreamServer::ChrCallbacks::onStatus(NimBLECharacteristic* pCharacter
396398
}
397399
}
398400

399-
# endif // MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
401+
# endif // MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
400402

401-
# if MYNEWT_VAL(BLE_ROLE_CENTRAL)
403+
# if MYNEWT_VAL(BLE_ROLE_CENTRAL)
402404
bool NimBLEStreamClient::init(NimBLERemoteCharacteristic* pChr, bool subscribe) {
403405
if (!pChr) {
404406
return false;
@@ -472,7 +474,7 @@ int uart_log_printfv(const char* format, va_list arg) {
472474

473475
int wlen = vsnprintf(temp, len + 1, format, arg);
474476
for (int i = 0; i < wlen; i++) {
475-
ets_write_char_uart(temp[i]);
477+
uart_tx_one_char(temp[i]);
476478
}
477479

478480
if (len >= sizeof(loc_buf)) {
@@ -491,5 +493,6 @@ int uart_log_printf(const char* format, ...) {
491493
return len;
492494
}
493495

494-
# endif // MYNEWT_VAL(BLE_ROLE_CENTRAL)
495-
#endif // CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
496+
# endif // MYNEWT_VAL(BLE_ROLE_CENTRAL)
497+
# endif // CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
498+
#endif // ESP_PLATFORM

src/NimBLEStream.h

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
* limitations under the License.
1616
*/
1717

18-
#ifndef NIMBLE_CPP_STREAM_H
19-
#define NIMBLE_CPP_STREAM_H
18+
#ifdef ESP_PLATFORM
19+
# ifndef NIMBLE_CPP_STREAM_H
20+
# define NIMBLE_CPP_STREAM_H
2021

21-
#include "syscfg/syscfg.h"
22-
#if CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
22+
# include "syscfg/syscfg.h"
23+
# if CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
2324

24-
# include "NimBLEUUID.h"
25-
# include <freertos/FreeRTOS.h>
26-
# include <freertos/ringbuf.h>
25+
# include "NimBLEUUID.h"
26+
# include <freertos/FreeRTOS.h>
27+
# include <freertos/ringbuf.h>
2728

28-
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
29-
# include <Stream.h>
30-
# else
29+
# if NIMBLE_CPP_ARDUINO_STRING_AVAILABLE
30+
# include <Stream.h>
31+
# else
3132
// Minimal Stream/Print stubs when Arduino not available
3233
class Print {
3334
public:
@@ -50,7 +51,7 @@ class Stream : public Print {
5051
protected:
5152
unsigned long m_timeout{0};
5253
};
53-
# endif
54+
# endif
5455

5556
class NimBLEStream : public Stream {
5657
public:
@@ -104,13 +105,13 @@ class NimBLEStream : public Stream {
104105
mutable bool m_hasPeek{false};
105106
};
106107

107-
# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
108-
# include "NimBLECharacteristic.h"
108+
# if MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
109+
# include "NimBLECharacteristic.h"
109110

110111
class NimBLEStreamServer : public NimBLEStream {
111112
public:
112113
NimBLEStreamServer() : m_charCallbacks(this) {}
113-
~NimBLEStreamServer() = default;
114+
~NimBLEStreamServer() = default;
114115
// non-copyable
115116
NimBLEStreamServer(const NimBLEStreamServer&) = delete;
116117
NimBLEStreamServer& operator=(const NimBLEStreamServer&) = delete;
@@ -152,15 +153,15 @@ class NimBLEStreamServer : public NimBLEStream {
152153
NimBLECharacteristic* m_pChr{nullptr};
153154
int m_rc{0};
154155
};
155-
# endif // BLE_ROLE_PERIPHERAL
156+
# endif // BLE_ROLE_PERIPHERAL
156157

157-
# if MYNEWT_VAL(BLE_ROLE_CENTRAL)
158-
# include "NimBLERemoteCharacteristic.h"
158+
# if MYNEWT_VAL(BLE_ROLE_CENTRAL)
159+
# include "NimBLERemoteCharacteristic.h"
159160

160161
class NimBLEStreamClient : public NimBLEStream {
161162
public:
162-
NimBLEStreamClient() = default;
163-
~NimBLEStreamClient() = default;
163+
NimBLEStreamClient() = default;
164+
~NimBLEStreamClient() = default;
164165
// non-copyable
165166
NimBLEStreamClient(const NimBLEStreamClient&) = delete;
166167
NimBLEStreamClient& operator=(const NimBLEStreamClient&) = delete;
@@ -182,38 +183,38 @@ class NimBLEStreamClient : public NimBLEStream {
182183
bool m_writeWithRsp{false};
183184
NimBLERemoteCharacteristic::notify_callback m_userNotifyCallback{nullptr};
184185
};
185-
# endif // BLE_ROLE_CENTRAL
186-
187-
#endif // CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
186+
# endif // BLE_ROLE_CENTRAL
188187

188+
# endif // CONFIG_BT_NIMBLE_ENABLED && (MYNEWT_VAL(BLE_ROLE_PERIPHERAL) || MYNEWT_VAL(BLE_ROLE_CENTRAL))
189189

190190
// These logging macros exist to provide log output over UART so that it stream classes can
191191
// be used to redirect logs without causing recursion issues.
192192
static int uart_log_printfv(const char* format, va_list arg);
193193
static int uart_log_printf(const char* format, ...);
194194

195-
#if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 4
196-
# define NIMBLE_UART_LOGD(tag, format, ...) uart_log_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
197-
#else
198-
# define NIMBLE_UART_LOGD(tag, format, ...) (void)tag
199-
#endif
200-
201-
#if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 3
202-
# define NIMBLE_UART_LOGI(tag, format, ...) uart_log_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
203-
#else
204-
# define NIMBLE_UART_LOGI(tag, format, ...) (void)tag
205-
#endif
206-
207-
#if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 2
208-
# define NIMBLE_UART_LOGW(tag, format, ...) uart_log_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
209-
#else
210-
# define NIMBLE_UART_LOGW(tag, format, ...) (void)tag
211-
#endif
212-
213-
#if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 1
214-
# define NIMBLE_UART_LOGE(tag, format, ...) uart_log_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
215-
#else
216-
# define NIMBLE_UART_LOGE(tag, format, ...) (void)tag
217-
#endif
218-
219-
#endif // NIMBLE_CPP_STREAM_H
195+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 4
196+
# define NIMBLE_UART_LOGD(tag, format, ...) uart_log_printf("D %s: " format "\n", tag, ##__VA_ARGS__)
197+
# else
198+
# define NIMBLE_UART_LOGD(tag, format, ...) (void)tag
199+
# endif
200+
201+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 3
202+
# define NIMBLE_UART_LOGI(tag, format, ...) uart_log_printf("I %s: " format "\n", tag, ##__VA_ARGS__)
203+
# else
204+
# define NIMBLE_UART_LOGI(tag, format, ...) (void)tag
205+
# endif
206+
207+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 2
208+
# define NIMBLE_UART_LOGW(tag, format, ...) uart_log_printf("W %s: " format "\n", tag, ##__VA_ARGS__)
209+
# else
210+
# define NIMBLE_UART_LOGW(tag, format, ...) (void)tag
211+
# endif
212+
213+
# if MYNEWT_VAL(NIMBLE_CPP_LOG_LEVEL) >= 1
214+
# define NIMBLE_UART_LOGE(tag, format, ...) uart_log_printf("E %s: " format "\n", tag, ##__VA_ARGS__)
215+
# else
216+
# define NIMBLE_UART_LOGE(tag, format, ...) (void)tag
217+
# endif
218+
219+
# endif // NIMBLE_CPP_STREAM_H
220+
#endif // ESP_PLATFORM

0 commit comments

Comments
 (0)