Skip to content

Commit

Permalink
Platform Event when ble is deinitialized (#33186)
Browse files Browse the repository at this point in the history
* Platform Event when ble is deinitialized

* [ESP32] remove error check on nimble_port_deinit()
IDF prior to v5.0, nimble_port_deinit() have a return type as void.
  • Loading branch information
shubhamdp authored Apr 29, 2024
1 parent 34cc8b8 commit 040e5bf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 4 additions & 0 deletions examples/platform/esp32/common/CommonDeviceCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i
{
switch (event->Type)
{
case DeviceEventType::kBLEDeinitialized:
ESP_LOGI(TAG, "BLE is deinitialized");
break;

case DeviceEventType::kInternetConnectivityChange:
OnInternetConnectivityChange(event);
break;
Expand Down
5 changes: 5 additions & 0 deletions src/include/platform/CHIPDeviceEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ enum PublicEventTypes
* sending messages to other nodes.
*/
kServerReady,

/**
* Signals that BLE is deinitialized.
*/
kBLEDeinitialized,
};

/**
Expand Down
9 changes: 6 additions & 3 deletions src/platform/ESP32/nimble/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,17 +1021,20 @@ void BLEManagerImpl::ClaimBLEMemory(System::Layer *, void *)

VerifyOrReturn(err == ESP_OK, ChipLogError(DeviceLayer, "BLE deinit failed"));
ChipLogProgress(DeviceLayer, "BLE deinit successful and memory reclaimed");
// TODO: post an event when ble is deinitialized and memory is added to heap

ChipDeviceEvent event;
event.Type = DeviceEventType::kBLEDeinitialized;
VerifyOrDo(CHIP_NO_ERROR == PlatformMgr().PostEvent(&event), ChipLogError(DeviceLayer, "Failed to post BLE deinit event"));
}
}

CHIP_ERROR BLEManagerImpl::DeinitBLE()
{
esp_err_t err = ESP_OK;
VerifyOrReturnError(ble_hs_is_enabled(), CHIP_ERROR_INCORRECT_STATE, ChipLogProgress(DeviceLayer, "BLE already deinited"));
VerifyOrReturnError(0 == nimble_port_stop(), MapBLEError(ESP_FAIL), ChipLogError(DeviceLayer, "nimble_port_stop() failed"));

esp_err_t err = nimble_port_deinit();
VerifyOrReturnError(err == ESP_OK, MapBLEError(err));
nimble_port_deinit();

#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
err = esp_nimble_hci_and_controller_deinit();
Expand Down

0 comments on commit 040e5bf

Please sign in to comment.