mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-06-06 05:14:45 +00:00
Added return value (success / failure ) to nimble_port_init
This commit is contained in:
committed by
Abhinav Kudnar
parent
9b6c19b398
commit
6336a6de85
@@ -21,7 +21,7 @@
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
nimble_port_init();
|
||||
int ret = nimble_port_init();
|
||||
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ int main(int argc, char *argv[])
|
||||
ble_hci_sock_set_device(atoi(argv[1]));
|
||||
}
|
||||
|
||||
nimble_port_init();
|
||||
ble_hci_sock_init();
|
||||
ret = nimble_port_init();
|
||||
|
||||
/* This example provides GATT Alert service */
|
||||
ble_svc_gap_init();
|
||||
|
||||
@@ -79,8 +79,8 @@ int main(int argc, char *argv[])
|
||||
ble_hci_sock_set_device(atoi(argv[1]));
|
||||
}
|
||||
|
||||
nimble_port_init();
|
||||
ble_hci_sock_init();
|
||||
ret = nimble_port_init();
|
||||
|
||||
ble_svc_gap_init();
|
||||
ble_svc_gatt_init();
|
||||
|
||||
@@ -87,7 +87,12 @@ int main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
printf("port init\n");
|
||||
nimble_port_init();
|
||||
|
||||
ret = nimble_port_init();
|
||||
if (ret != 0) {
|
||||
printf(" Failed to init nimble %d \n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
printf("hci init\n");
|
||||
ble_hci_sock_init();
|
||||
|
||||
@@ -35,8 +35,21 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void nimble_port_init(void);
|
||||
void nimble_port_deinit(void);
|
||||
/**
|
||||
* @brief nimble_port_init - Initialize controller and NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t - ESP_OK ( if success)
|
||||
* Error code in case of failure
|
||||
*/
|
||||
esp_err_t nimble_port_init(void);
|
||||
|
||||
/**
|
||||
* @brief nimble_port_deinit - Deinitialize controller and NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t - ESP_OK ( if success)
|
||||
* Error code in case of failure
|
||||
*/
|
||||
esp_err_t nimble_port_deinit(void);
|
||||
|
||||
void nimble_port_run(void);
|
||||
int nimble_port_stop(void);
|
||||
|
||||
@@ -136,47 +136,76 @@ esp_err_t esp_nimble_deinit(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void
|
||||
/**
|
||||
* @brief nimble_port_init - Initialize controller and NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t
|
||||
nimble_port_init(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT);
|
||||
#endif
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
|
||||
if(esp_bt_controller_init(&config_opts) != ESP_OK) {
|
||||
|
||||
ret = esp_bt_controller_init(&config_opts);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller init failed\n");
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
if(esp_bt_controller_enable(ESP_BT_MODE_BLE) != ESP_OK) {
|
||||
|
||||
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller enable failed\n");
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(esp_nimble_init() != 0) {
|
||||
ret = esp_nimble_init();
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host init failed\n");
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void
|
||||
/**
|
||||
* @brief nimble_port_deinit - Deinitialize controller and NimBLE host stack
|
||||
*
|
||||
* @return esp_err_t
|
||||
*/
|
||||
|
||||
esp_err_t
|
||||
nimble_port_deinit(void)
|
||||
{
|
||||
if(esp_nimble_deinit() != 0) {
|
||||
esp_err_t ret;
|
||||
|
||||
ret = esp_nimble_deinit();
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host deinit failed\n");
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
if(esp_bt_controller_disable() != ESP_OK) {
|
||||
ret = esp_bt_controller_disable();
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller disable failed\n");
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
if(esp_bt_controller_deinit() != ESP_OK) {
|
||||
|
||||
ret = esp_bt_controller_deinit();
|
||||
if(ret != ESP_OK) {
|
||||
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller deinit failed\n");
|
||||
return;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user