Skip to content

Commit 817f484

Browse files
authored
Platform Event when ble is deinitialized (#33186) (#33210)
* 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 4e149f5 commit 817f484

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
@@ -239,6 +239,11 @@ enum PublicEventTypes
239239
* sending messages to other nodes.
240240
*/
241241
kServerReady,
242+
243+
/**
244+
* Signals that BLE is deinitialized.
245+
*/
246+
kBLEDeinitialized,
242247
};
243248

244249
/**

src/platform/ESP32/nimble/BLEManagerImpl.cpp

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

980980
VerifyOrReturn(err == ESP_OK, ChipLogError(DeviceLayer, "BLE deinit failed"));
981981
ChipLogProgress(DeviceLayer, "BLE deinit successful and memory reclaimed");
982-
// TODO: post an event when ble is deinitialized and memory is added to heap
982+
983+
ChipDeviceEvent event;
984+
event.Type = DeviceEventType::kBLEDeinitialized;
985+
VerifyOrDo(CHIP_NO_ERROR == PlatformMgr().PostEvent(&event), ChipLogError(DeviceLayer, "Failed to post BLE deinit event"));
983986
}
984987
}
985988

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

991-
esp_err_t err = nimble_port_deinit();
992-
VerifyOrReturnError(err == ESP_OK, MapBLEError(err));
995+
nimble_port_deinit();
993996

994997
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
995998
err = esp_nimble_hci_and_controller_deinit();

0 commit comments

Comments
 (0)