From 9c630b759f3b0f5be4abf556fef509592818a3f0 Mon Sep 17 00:00:00 2001 From: Tian Hao Date: Fri, 6 Jan 2017 21:19:58 +0800 Subject: [PATCH] component/bt : add bt device api 1. add get bd_addr function --- components/bt/bluedroid/api/esp_bt_device.c | 22 +++++++++ .../bt/bluedroid/api/include/esp_bt_defs.h | 3 ++ .../bt/bluedroid/api/include/esp_bt_device.h | 38 +++++++++++++++ docs/api/bt_common.rst | 1 + docs/api/esp_bt_device.rst | 48 +++++++++++++++++++ examples/12_blufi/main/blufi_main.c | 3 ++ 6 files changed, 115 insertions(+) create mode 100644 components/bt/bluedroid/api/esp_bt_device.c create mode 100644 components/bt/bluedroid/api/include/esp_bt_device.h create mode 100644 docs/api/esp_bt_device.rst diff --git a/components/bt/bluedroid/api/esp_bt_device.c b/components/bt/bluedroid/api/esp_bt_device.c new file mode 100644 index 000000000..745e446c2 --- /dev/null +++ b/components/bt/bluedroid/api/esp_bt_device.c @@ -0,0 +1,22 @@ +// Copyright 2015-2016 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. + + +#include "esp_bt_device.h" +#include "controller.h" + +const uint8_t *esp_bt_dev_get_address(void) +{ + return controller_get_interface()->get_address()->address; +} diff --git a/components/bt/bluedroid/api/include/esp_bt_defs.h b/components/bt/bluedroid/api/include/esp_bt_defs.h index cba8fbe74..cdb56a49b 100644 --- a/components/bt/bluedroid/api/include/esp_bt_defs.h +++ b/components/bt/bluedroid/api/include/esp_bt_defs.h @@ -96,6 +96,9 @@ typedef enum { /// Maximum of the application id #define ESP_APP_ID_MAX 0x7fff +#define ESP_BD_ADDR_STR "%02x:%02x:%02x:%02x:%02x:%02x" +#define ESP_BD_ADDR_HEX(addr) addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] + #ifdef __cplusplus } #endif diff --git a/components/bt/bluedroid/api/include/esp_bt_device.h b/components/bt/bluedroid/api/include/esp_bt_device.h new file mode 100644 index 000000000..51c24f288 --- /dev/null +++ b/components/bt/bluedroid/api/include/esp_bt_device.h @@ -0,0 +1,38 @@ +// Copyright 2015-2016 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. + +#ifndef __ESP_BT_DEVICE_H__ +#define __ESP_BT_DEVICE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * + * @brief Get bluetooth device address. Must use after "esp_bluedroid_enable". + * + * @return bluetooth device address (six bytes) + */ +const uint8_t *esp_bt_dev_get_address(void); + +#ifdef __cplusplus +} +#endif + + +#endif /* __ESP_BT_DEVICE_H__ */ diff --git a/docs/api/bt_common.rst b/docs/api/bt_common.rst index eaa6b8d31..f2ce6bae9 100644 --- a/docs/api/bt_common.rst +++ b/docs/api/bt_common.rst @@ -6,3 +6,4 @@ BT COMMON Bluetooth DEFINE Bluetooth MAIN + Bluetooth DEVICE diff --git a/docs/api/esp_bt_device.rst b/docs/api/esp_bt_device.rst new file mode 100644 index 000000000..c344a5e63 --- /dev/null +++ b/docs/api/esp_bt_device.rst @@ -0,0 +1,48 @@ +BT DEVICE APIs +=============== + +Overview +-------- + +Bluetooth device reference APIs. + +`Instructions`_ + +Application Example +------------------- + +`Instructions`_ + +.. _Instructions: template.html + + +API Reference +------------- + +Header Files +^^^^^^^^^^^^ + + * `bt/bluedroid/api/include/esp_bt_device.h `_ + + +Macros +^^^^^^ + + +Type Definitions +^^^^^^^^^^^^^^^^ + + +Enumerations +^^^^^^^^^^^^ + + +Structures +^^^^^^^^^^ + + +Functions +^^^^^^^^^ + +.. doxygenfunction:: esp_bt_dev_get_address + diff --git a/examples/12_blufi/main/blufi_main.c b/examples/12_blufi/main/blufi_main.c index 9e2b1da0a..a95db66eb 100644 --- a/examples/12_blufi/main/blufi_main.c +++ b/examples/12_blufi/main/blufi_main.c @@ -29,6 +29,7 @@ #include "esp_bt_defs.h" #include "esp_gap_ble_api.h" #include "esp_bt_main.h" +#include "esp_bt_device.h" #include "blufi_demo.h" static void blufi_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t *param); @@ -328,6 +329,8 @@ void app_main() return; } + BLUFI_INFO("BD ADDR: "ESP_BD_ADDR_STR"\n", ESP_BD_ADDR_HEX(esp_bt_dev_get_address())); + BLUFI_INFO("BLUFI VERSION %04x\n", esp_blufi_get_version()); blufi_security_init();