Skip to content

Commit 0ac02ea

Browse files
authored
Platform Event when ble is deinitialized (#33186) (#33211)
* 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 5524d5b commit 0ac02ea

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
@@ -1027,17 +1027,20 @@ void BLEManagerImpl::ClaimBLEMemory(System::Layer *, void *)
10271027

10281028
VerifyOrReturn(err == ESP_OK, ChipLogError(DeviceLayer, "BLE deinit failed"));
10291029
ChipLogProgress(DeviceLayer, "BLE deinit successful and memory reclaimed");
1030-
// TODO: post an event when ble is deinitialized and memory is added to heap
1030+
1031+
ChipDeviceEvent event;
1032+
event.Type = DeviceEventType::kBLEDeinitialized;
1033+
VerifyOrDo(CHIP_NO_ERROR == PlatformMgr().PostEvent(&event), ChipLogError(DeviceLayer, "Failed to post BLE deinit event"));
10311034
}
10321035
}
10331036

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

1039-
esp_err_t err = nimble_port_deinit();
1040-
VerifyOrReturnError(err == ESP_OK, MapBLEError(err));
1043+
nimble_port_deinit();
10411044

10421045
#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
10431046
err = esp_nimble_hci_and_controller_deinit();

0 commit comments

Comments
 (0)