Skip to content

Commit ce1b8bc

Browse files
committed
Fix build with non-esp devices
1 parent dadbc0d commit ce1b8bc

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

src/NimBLEDevice.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,13 @@ bool NimBLEDevice::setPower(int8_t dbm, NimBLETxPowerType type) {
522522
# else
523523
(void)type; // unused
524524
NIMBLE_LOGD(LOG_TAG, ">> setPower: %d", dbm);
525-
ble_hci_vs_set_tx_pwr_cp cmd{dbm};
526-
ble_hci_vs_set_tx_pwr_rp rsp{0};
527-
int rc = ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_TX_PWR, &cmd, sizeof(cmd), &rsp, sizeof(rsp));
525+
int rc = ble_phy_tx_power_set(dbm);
528526
if (rc) {
529527
NIMBLE_LOGE(LOG_TAG, "failed to set TX power, rc: %04x\n", rc);
530528
return false;
531529
}
532530

533-
NIMBLE_LOGD(LOG_TAG, "TX power set to %d dBm\n", rsp.tx_power);
531+
NIMBLE_LOGD(LOG_TAG, "TX power set to %d dBm\n", dbm);
534532
return true;
535533
# endif
536534
} // setPower
@@ -566,7 +564,7 @@ int NimBLEDevice::getPower(NimBLETxPowerType type) {
566564
# endif
567565
# else
568566
(void)type; // unused
569-
return ble_phy_txpwr_get();
567+
return ble_phy_tx_power_get();
570568
# endif
571569
} // getPower
572570

src/NimBLEL2CAPChannel.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#define CEIL_DIVIDE(a, b) (((a) + (b) - 1) / (b))
1717
#define ROUND_DIVIDE(a, b) (((a) + (b) / 2) / (b))
1818
// Retry
19-
constexpr TickType_t RetryTimeout = pdMS_TO_TICKS(50);
19+
constexpr uint32_t RetryTimeout = 50;
2020
constexpr int RetryCounter = 3;
2121

2222
NimBLEL2CAPChannel::NimBLEL2CAPChannel(uint16_t psm, uint16_t mtu, NimBLEL2CAPChannelCallbacks* callbacks)
@@ -65,8 +65,6 @@ bool NimBLEL2CAPChannel::setupMemPool() {
6565
return false;
6666
}
6767

68-
this->stalledSemaphore = xSemaphoreCreateBinary();
69-
7068
return true;
7169
}
7270

@@ -83,7 +81,10 @@ int NimBLEL2CAPChannel::writeFragment(std::vector<uint8_t>::const_iterator begin
8381

8482
if (stalled) {
8583
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel waiting for unstall...");
86-
xSemaphoreTake(this->stalledSemaphore, portMAX_DELAY);
84+
NimBLETaskData taskData;
85+
m_pTaskData = &taskData;
86+
NimBLEUtils::taskWait(m_pTaskData, BLE_NPL_TIME_FOREVER);
87+
m_pTaskData = nullptr;
8788
stalled = false;
8889
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel unstalled!");
8990
}
@@ -125,7 +126,7 @@ int NimBLEL2CAPChannel::writeFragment(std::vector<uint8_t>::const_iterator begin
125126
case BLE_HS_EBUSY:
126127
NIMBLE_LOGD(LOG_TAG, "ble_l2cap_send returned %d. Retrying shortly...", res);
127128
os_mbuf_free_chain(txd);
128-
vTaskDelay(RetryTimeout);
129+
ble_npl_time_delay(ble_npl_time_ms_to_ticks32(RetryTimeout));
129130
continue;
130131

131132
case ESP_OK:
@@ -247,8 +248,11 @@ int NimBLEL2CAPChannel::handleDataReceivedEvent(struct ble_l2cap_event* event) {
247248
}
248249

249250
int NimBLEL2CAPChannel::handleTxUnstalledEvent(struct ble_l2cap_event* event) {
251+
if (m_pTaskData != nullptr) {
252+
NimBLEUtils::taskRelease(*m_pTaskData, event->tx_unstalled.status);
253+
}
254+
250255
NIMBLE_LOGI(LOG_TAG, "L2CAP COC 0x%04X transmit unstalled.", psm);
251-
xSemaphoreGive(this->stalledSemaphore);
252256
return 0;
253257
}
254258

@@ -268,7 +272,7 @@ int NimBLEL2CAPChannel::handleL2capEvent(struct ble_l2cap_event *event, void *ar
268272
int returnValue = 0;
269273

270274
switch (event->type) {
271-
case BLE_L2CAP_EVENT_COC_CONNECTED:
275+
case BLE_L2CAP_EVENT_COC_CONNECTED:
272276
returnValue = self->handleConnectionEvent(event);
273277
break;
274278

src/NimBLEL2CAPChannel.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020

2121
class NimBLEClient;
2222
class NimBLEL2CAPChannelCallbacks;
23+
struct NimBLETaskData;
2324

2425
/**
2526
* @brief Encapsulates a L2CAP channel.
26-
*
27+
*
2728
* This class is used to encapsulate a L2CAP connection oriented channel, both
2829
* from the "server" (which waits for the connection to be opened) and the "client"
2930
* (which opens the connection) point of view.
@@ -80,7 +81,7 @@ class NimBLEL2CAPChannel {
8081

8182
// Runtime handling
8283
std::atomic<bool> stalled{false};
83-
SemaphoreHandle_t stalledSemaphore = nullptr;
84+
NimBLETaskData* m_pTaskData{nullptr};
8485

8586
// Allocate / deallocate NimBLE memory pool
8687
bool setupMemPool();

0 commit comments

Comments
 (0)