Fix build with non-esp devices

This commit is contained in:
h2zero
2025-05-04 15:24:09 -06:00
parent dadbc0d423
commit ce1b8bc2ec
3 changed files with 17 additions and 14 deletions

View File

@ -522,15 +522,13 @@ bool NimBLEDevice::setPower(int8_t dbm, NimBLETxPowerType type) {
# else
(void)type; // unused
NIMBLE_LOGD(LOG_TAG, ">> setPower: %d", dbm);
ble_hci_vs_set_tx_pwr_cp cmd{dbm};
ble_hci_vs_set_tx_pwr_rp rsp{0};
int rc = ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_TX_PWR, &cmd, sizeof(cmd), &rsp, sizeof(rsp));
int rc = ble_phy_tx_power_set(dbm);
if (rc) {
NIMBLE_LOGE(LOG_TAG, "failed to set TX power, rc: %04x\n", rc);
return false;
}
NIMBLE_LOGD(LOG_TAG, "TX power set to %d dBm\n", rsp.tx_power);
NIMBLE_LOGD(LOG_TAG, "TX power set to %d dBm\n", dbm);
return true;
# endif
} // setPower
@ -566,7 +564,7 @@ int NimBLEDevice::getPower(NimBLETxPowerType type) {
# endif
# else
(void)type; // unused
return ble_phy_txpwr_get();
return ble_phy_tx_power_get();
# endif
} // getPower

View File

@ -16,7 +16,7 @@
#define CEIL_DIVIDE(a, b) (((a) + (b) - 1) / (b))
#define ROUND_DIVIDE(a, b) (((a) + (b) / 2) / (b))
// Retry
constexpr TickType_t RetryTimeout = pdMS_TO_TICKS(50);
constexpr uint32_t RetryTimeout = 50;
constexpr int RetryCounter = 3;
NimBLEL2CAPChannel::NimBLEL2CAPChannel(uint16_t psm, uint16_t mtu, NimBLEL2CAPChannelCallbacks* callbacks)
@ -65,8 +65,6 @@ bool NimBLEL2CAPChannel::setupMemPool() {
return false;
}
this->stalledSemaphore = xSemaphoreCreateBinary();
return true;
}
@ -83,7 +81,10 @@ int NimBLEL2CAPChannel::writeFragment(std::vector<uint8_t>::const_iterator begin
if (stalled) {
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel waiting for unstall...");
xSemaphoreTake(this->stalledSemaphore, portMAX_DELAY);
NimBLETaskData taskData;
m_pTaskData = &taskData;
NimBLEUtils::taskWait(m_pTaskData, BLE_NPL_TIME_FOREVER);
m_pTaskData = nullptr;
stalled = false;
NIMBLE_LOGD(LOG_TAG, "L2CAP Channel unstalled!");
}
@ -125,7 +126,7 @@ int NimBLEL2CAPChannel::writeFragment(std::vector<uint8_t>::const_iterator begin
case BLE_HS_EBUSY:
NIMBLE_LOGD(LOG_TAG, "ble_l2cap_send returned %d. Retrying shortly...", res);
os_mbuf_free_chain(txd);
vTaskDelay(RetryTimeout);
ble_npl_time_delay(ble_npl_time_ms_to_ticks32(RetryTimeout));
continue;
case ESP_OK:
@ -247,8 +248,11 @@ int NimBLEL2CAPChannel::handleDataReceivedEvent(struct ble_l2cap_event* event) {
}
int NimBLEL2CAPChannel::handleTxUnstalledEvent(struct ble_l2cap_event* event) {
if (m_pTaskData != nullptr) {
NimBLEUtils::taskRelease(*m_pTaskData, event->tx_unstalled.status);
}
NIMBLE_LOGI(LOG_TAG, "L2CAP COC 0x%04X transmit unstalled.", psm);
xSemaphoreGive(this->stalledSemaphore);
return 0;
}
@ -268,7 +272,7 @@ int NimBLEL2CAPChannel::handleL2capEvent(struct ble_l2cap_event *event, void *ar
int returnValue = 0;
switch (event->type) {
case BLE_L2CAP_EVENT_COC_CONNECTED:
case BLE_L2CAP_EVENT_COC_CONNECTED:
returnValue = self->handleConnectionEvent(event);
break;

View File

@ -20,10 +20,11 @@
class NimBLEClient;
class NimBLEL2CAPChannelCallbacks;
struct NimBLETaskData;
/**
* @brief Encapsulates a L2CAP channel.
*
*
* This class is used to encapsulate a L2CAP connection oriented channel, both
* from the "server" (which waits for the connection to be opened) and the "client"
* (which opens the connection) point of view.
@ -80,7 +81,7 @@ private:
// Runtime handling
std::atomic<bool> stalled{false};
SemaphoreHandle_t stalledSemaphore = nullptr;
NimBLETaskData* m_pTaskData{nullptr};
// Allocate / deallocate NimBLE memory pool
bool setupMemPool();