Skip to content

Commit 040e5bf

Browse files
authored
Platform Event when ble is deinitialized (#33186)
* 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.
1 parent 34cc8b8 commit 040e5bf

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

examples/platform/esp32/common/CommonDeviceCallbacks.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i
4141
{
4242
switch (event->Type)
4343
{
44+
case DeviceEventType::kBLEDeinitialized:
45+
ESP_LOGI(TAG, "BLE is deinitialized");
46+
break;
47+
4448
case DeviceEventType::kInternetConnectivityChange:
4549
OnInternetConnectivityChange(event);
4650
break;

src/include/platform/CHIPDeviceEvent.h

+5
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ enum PublicEventTypes
245245
* sending messages to other nodes.
246246
*/
247247
kServerReady,
248+
249+
/**
250+
* Signals that BLE is deinitialized.
251+
*/
252+
kBLEDeinitialized,
248253
};
249254

250255
/**

src/platform/ESP32/nimble/BLEManagerImpl.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1021,17 +1021,20 @@ void BLEManagerImpl::ClaimBLEMemory(System::Layer *, void *)
10211021

10221022
VerifyOrReturn(err == ESP_OK, ChipLogError(DeviceLayer, "BLE deinit failed"));
10231023
ChipLogProgress(DeviceLayer, "BLE deinit successful and memory reclaimed");
1024-
// TODO: post an event when ble is deinitialized and memory is added to heap
1024+
1025+
ChipDeviceEvent event;
1026+
event.Type = DeviceEventType::kBLEDeinitialized;
1027+
VerifyOrDo(CHIP_NO_ERROR == PlatformMgr().PostEvent(&event), ChipLogError(DeviceLayer, "Failed to post BLE deinit event"));
10251028
}
10261029
}
10271030

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

1033-
esp_err_t err = nimble_port_deinit();
1034-
VerifyOrReturnError(err == ESP_OK, MapBLEError(err));
1037+
nimble_port_deinit();
10351038

10361039
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
10371040
err = esp_nimble_hci_and_controller_deinit();

0 commit comments

Comments
 (0)