diff --git a/examples/bluetooth/blufi/main/blufi_example.h b/examples/bluetooth/blufi/main/blufi_example.h index d8b92f5d9e..a80e273e67 100644 --- a/examples/bluetooth/blufi/main/blufi_example.h +++ b/examples/bluetooth/blufi/main/blufi_example.h @@ -13,3 +13,4 @@ int blufi_security_init(void); void blufi_security_deinit(void); int esp_blufi_gap_register_callback(void); esp_err_t esp_blufi_host_init(void); +esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *callbacks); diff --git a/examples/bluetooth/blufi/main/blufi_example_main.c b/examples/bluetooth/blufi/main/blufi_example_main.c index 67ff42cb29..4256d00de6 100644 --- a/examples/bluetooth/blufi/main/blufi_example_main.c +++ b/examples/bluetooth/blufi/main/blufi_example_main.c @@ -385,23 +385,11 @@ void app_main(void) return; } - ret = esp_blufi_host_init(); + ret = esp_blufi_host_and_cb_init(&example_callbacks); if (ret) { - BLUFI_ERROR("%s initialise host failed: %s\n", __func__, esp_err_to_name(ret)); + BLUFI_ERROR("%s initialise failed: %s\n", __func__, esp_err_to_name(ret)); return; } BLUFI_INFO("BLUFI VERSION %04x\n", esp_blufi_get_version()); - - ret = esp_blufi_register_callbacks(&example_callbacks); - if(ret){ - BLUFI_ERROR("%s blufi register failed, error code = %x\n", __func__, ret); - return; - } - - ret = esp_blufi_gap_register_callback(); - if(ret){ - BLUFI_ERROR("%s gap register failed, error code = %x\n", __func__, ret); - return; - } } diff --git a/examples/bluetooth/blufi/main/blufi_init.c b/examples/bluetooth/blufi/main/blufi_init.c index 052739b055..04dc13f4eb 100644 --- a/examples/bluetooth/blufi/main/blufi_init.c +++ b/examples/bluetooth/blufi/main/blufi_init.c @@ -3,10 +3,10 @@ #include "esp_blufi_api.h" #include "esp_log.h" #include "esp_blufi.h" +#include "blufi_example.h" #ifdef CONFIG_BT_BLUEDROID_ENABLED #include "esp_bt.h" #include "esp_bt_main.h" -#include "blufi_example.h" #include "esp_bt_device.h" #endif @@ -42,15 +42,40 @@ esp_err_t esp_blufi_host_init(void) } -int esp_blufi_gap_register_callback(void) +esp_err_t esp_blufi_gap_register_callback(void) { int rc; rc = esp_ble_gap_register_callback(esp_blufi_gap_event_handler); if(rc){ return rc; } - esp_blufi_profile_init(); - return 0; + return esp_blufi_profile_init(); +} + +esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *example_callbacks) +{ + esp_err_t ret = ESP_OK; + + ret = esp_blufi_host_init(); + if (ret) { + BLUFI_ERROR("%s initialise host failed: %s\n", __func__, esp_err_to_name(ret)); + return ret; + } + + ret = esp_blufi_register_callbacks(example_callbacks); + if(ret){ + BLUFI_ERROR("%s blufi register failed, error code = %x\n", __func__, ret); + return ret; + } + + ret = esp_blufi_gap_register_callback(); + if(ret){ + BLUFI_ERROR("%s gap register failed, error code = %x\n", __func__, ret); + return ret; + } + + return ESP_OK; + } #endif /* CONFIG_BT_BLUEDROID_ENABLED */ @@ -115,14 +140,42 @@ esp_err_t esp_blufi_host_init(void) /* XXX Need to have template for store */ ble_store_config_init(); - nimble_port_freertos_init(bleprph_host_task); esp_blufi_btc_init(); + + nimble_port_freertos_init(bleprph_host_task); + return ESP_OK; } -int esp_blufi_gap_register_callback(void) +esp_err_t esp_blufi_gap_register_callback(void) { - return 0; + return ESP_OK; } +esp_err_t esp_blufi_host_and_cb_init(esp_blufi_callbacks_t *example_callbacks) +{ + esp_err_t ret = ESP_OK; + + ret = esp_blufi_register_callbacks(example_callbacks); + if(ret){ + BLUFI_ERROR("%s blufi register failed, error code = %x\n", __func__, ret); + return ret; + } + + ret = esp_blufi_gap_register_callback(); + if(ret){ + BLUFI_ERROR("%s gap register failed, error code = %x\n", __func__, ret); + return ret; + } + + ret = esp_blufi_host_init(); + if (ret) { + BLUFI_ERROR("%s initialise host failed: %s\n", __func__, esp_err_to_name(ret)); + return ret; + } + + return ret; +} + + #endif /* CONFIG_BT_NIMBLE_ENABLED */