From d804ec0b97ce4e2f509edce272f91ade521ca424 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 29 Nov 2024 14:41:14 +0530 Subject: [PATCH] fix(nimble): Fix compilation issue in esp_hid_host example --- .../esp_hid_host/main/esp_hid_host_main.c | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c b/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c index 681d86e1d087..bda84d8993a4 100644 --- a/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c +++ b/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c @@ -55,7 +55,8 @@ static const char *TAG = "ESP_HIDH_DEMO"; static const char * remote_device_name = CONFIG_EXAMPLE_PEER_DEVICE_NAME; #endif // CONFIG_BT_HID_HOST_ENABLED -static char *bda2str(esp_bd_addr_t bda, char *str, size_t size) +#if !CONFIG_BT_NIMBLE_ENABLED +static char *bda2str(uint8_t *bda, char *str, size_t size) { if (bda == NULL || str == NULL || size < 18) { return NULL; @@ -66,6 +67,7 @@ static char *bda2str(esp_bd_addr_t bda, char *str, size_t size) p[0], p[1], p[2], p[3], p[4], p[5]); return str; } +#endif void hidh_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) { @@ -191,7 +193,6 @@ void ble_store_config_init(void); #endif void app_main(void) { - char bda_str[18] = {0}; esp_err_t ret; #if HID_HOST_MODE == HIDH_IDLE_MODE ESP_LOGE(TAG, "Please turn on BT HID host or BLE!"); @@ -215,7 +216,12 @@ void app_main(void) }; ESP_ERROR_CHECK( esp_hidh_init(&config) ); +#if !CONFIG_BT_NIMBLE_ENABLED + char bda_str[18] = {0}; ESP_LOGI(TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str))); +#endif + + #if CONFIG_BT_NIMBLE_ENABLED /* XXX Need to have template for store */ ble_store_config_init(); @@ -226,6 +232,28 @@ void app_main(void) if (ret) { ESP_LOGE(TAG, "esp_nimble_enable failed: %d", ret); } + + vTaskDelay(200); + + uint8_t own_addr_type = 0; + int rc; + uint8_t addr_val[6] = {0}; + + rc = ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, NULL, NULL); + + rc = ble_hs_id_infer_auto(0, &own_addr_type); + + if (rc != 0) { + ESP_LOGI(TAG, "error determining address type; rc=%d\n", rc); + return; + } + + rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL); + + ESP_LOGI(TAG, "Device Address: "); + ESP_LOGI(TAG, "%02x:%02x:%02x:%02x:%02x:%02x \n", addr_val[5], addr_val[4], addr_val[3], + addr_val[2], addr_val[1], addr_val[0]); + #endif xTaskCreate(&hid_demo_task, "hid_task", 6 * 1024, NULL, 2, NULL); }