@@ -855,39 +855,13 @@ esp_err_t chip_stack_unlock()
855
855
}
856
856
} /* lock */
857
857
858
- static void deinit_ble_if_commissioned (void )
858
+ static void deinit_ble_if_commissioned (intptr_t unused )
859
859
{
860
- #if CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
861
- if (chip::Server::GetInstance ().GetFabricTable ().FabricCount () > 0 ) {
862
- esp_err_t err = ESP_OK;
863
- #if CONFIG_BT_NIMBLE_ENABLED
864
- if (!ble_hs_is_enabled ()) {
865
- ESP_LOGI (TAG, " BLE already deinited" );
866
- return ;
867
- }
868
-
869
- if (nimble_port_stop () != 0 ) {
870
- ESP_LOGE (TAG, " nimble_port_stop() failed" );
871
- return ;
872
- }
873
- nimble_port_deinit ();
874
- #if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0)
875
- err = esp_nimble_hci_and_controller_deinit ();
876
- #endif
877
- #endif /* CONFIG_BT_NIMBLE_ENABLED */
878
- #if CONFIG_IDF_TARGET_ESP32
879
- err |= esp_bt_mem_release (ESP_BT_MODE_BTDM);
880
- #elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32H2
881
- err |= esp_bt_mem_release (ESP_BT_MODE_BLE);
882
- #endif
883
- if (err != ESP_OK) {
884
- ESP_LOGE (TAG, " BLE deinit failed" );
885
- return ;
886
- }
887
- ESP_LOGI (TAG, " BLE deinit successful and memory reclaimed" );
888
- PostEvent (chip::DeviceLayer::DeviceEventType::kBLEDeinitialized );
889
- }
890
- #endif /* CONFIG_BT_ENABLED && CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
860
+ #if CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING
861
+ if (chip::Server::GetInstance ().GetFabricTable ().FabricCount () > 0 ) {
862
+ chip::DeviceLayer::Internal::BLEMgr ().Shutdown ();
863
+ }
864
+ #endif /* CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING */
891
865
}
892
866
893
867
static void esp_matter_chip_init_task (intptr_t context)
@@ -937,7 +911,7 @@ static void esp_matter_chip_init_task(intptr_t context)
937
911
sEthernetNetworkCommissioningInstance .Init ();
938
912
}
939
913
#endif
940
- deinit_ble_if_commissioned ( );
914
+ PlatformMgr (). ScheduleWork ( deinit_ble_if_commissioned, reinterpret_cast < intptr_t >( nullptr ) );
941
915
xTaskNotifyGive (task_to_notify);
942
916
}
943
917
@@ -962,11 +936,11 @@ static void device_callback_internal(const ChipDeviceEvent * event, intptr_t arg
962
936
963
937
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete :
964
938
ESP_LOGI (TAG, " Commissioning Complete" );
939
+ PlatformMgr ().ScheduleWork (deinit_ble_if_commissioned, reinterpret_cast <intptr_t >(nullptr ));
965
940
break ;
966
941
967
942
case chip::DeviceLayer::DeviceEventType::kCHIPoBLEConnectionClosed :
968
943
ESP_LOGI (TAG, " BLE Disconnected" );
969
- deinit_ble_if_commissioned ();
970
944
break ;
971
945
default :
972
946
break ;
@@ -985,8 +959,7 @@ static esp_err_t chip_init(event_callback_t callback, intptr_t callback_arg)
985
959
}
986
960
987
961
setup_providers ();
988
- ConnectivityMgr ().SetBLEAdvertisingEnabled (true );
989
- // ConnectivityMgr().SetWiFiAPMode(ConnectivityManager::kWiFiAPMode_Enabled);
962
+
990
963
if (PlatformMgr ().StartEventLoopTask () != CHIP_NO_ERROR) {
991
964
chip::Platform::MemoryShutdown ();
992
965
ESP_LOGE (TAG, " Failed to launch Matter main task" );
0 commit comments