Nimble: Added return value (success / failure ) to nimble_port_init

This commit is contained in:
Rahul Tank
2022-12-20 14:11:52 +05:30
parent 1195b6cb2b
commit 826495a145
23 changed files with 144 additions and 49 deletions
@@ -273,7 +273,7 @@ void app_main(void)
#endif // CONFIG_EXAMPLE_CONNECT_WIFI
#if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED
esp_ble_helper_init();
ESP_ERROR_CHECK(esp_ble_helper_init());
#endif
xTaskCreate(&advanced_ota_example_task, "advanced_ota_example_task", 1024 * 8, NULL, 5, NULL);
@@ -16,13 +16,11 @@
#include "bluedroid_gatts.h"
#endif
#if CONFIG_BT_BLE_ENABLED
static const char *TAG = "BLE_API";
#endif
void esp_ble_helper_init(void)
esp_err_t esp_ble_helper_init(void)
{
esp_err_t err;
esp_err_t err = ESP_OK;
#if CONFIG_BT_BLE_ENABLED
ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
@@ -30,48 +28,54 @@ void esp_ble_helper_init(void)
err = esp_bt_controller_init(&bt_cfg);
if (err) {
ESP_LOGE(TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(err));
return;
return err;
}
err = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (err) {
ESP_LOGE(TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(err));
return;
return err;
}
err = esp_bluedroid_init();
if (err) {
ESP_LOGE(TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(err));
return;
return err;
}
err = esp_bluedroid_enable();
if (err) {
ESP_LOGE(TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(err));
return;
return err;
}
err = esp_ble_gatts_register_callback(gatts_event_handler);
if (err) {
ESP_LOGE(TAG, "gatts register error, error code = %x", err);
return;
return err;
}
err = esp_ble_gap_register_callback(gap_event_handler);
if (err) {
ESP_LOGE(TAG, "gap register error, error code = %x", err);
return;
return err;
}
err = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
if (err) {
ESP_LOGE(TAG, "gatts app register error, error code = %x", err);
return;
return err;
}
esp_err_t local_mtu_err = esp_ble_gatt_set_local_mtu(500);
if (local_mtu_err) {
ESP_LOGE(TAG, "set local MTU failed, error code = %x", local_mtu_err);
return local_mtu_err;
}
#elif CONFIG_BT_NIMBLE_ENABLED
nimble_port_init();
err = nimble_port_init();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to init nimble %d ", err);
return err;
}
/* Initialize the NimBLE host configuration. */
ble_hs_cfg.reset_cb = bleprph_on_reset;
ble_hs_cfg.sync_cb = bleprph_on_sync;
@@ -90,6 +94,8 @@ void esp_ble_helper_init(void)
nimble_port_freertos_init(bleprph_host_task);
#endif
return ESP_OK;
}
#endif
@@ -1,25 +1,19 @@
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
#if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED
void esp_ble_helper_init(void);
esp_err_t esp_ble_helper_init(void);
#endif