esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
+esp_err_t esp_bt_gap_set_device_name(const char *name);
#endif /* __ESP_GAP_BT_API_H__ */
#include "esp_gap_bt_api.h"
#include "bta_api.h"
#include "bt_trace.h"
+#include <string.h>
esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode)
{
return ESP_OK;
}
+
+esp_err_t esp_bt_gap_set_device_name(const char *name)
+{
+ if (name == NULL || *name == '\0') {
+ return ESP_ERR_INVALID_ARG;
+ }
+ #define ESP_GAP_DEVICE_NAME_MAX (32)
+ char dev_name[ESP_GAP_DEVICE_NAME_MAX+1];
+ strncpy(dev_name, name, ESP_GAP_DEVICE_NAME_MAX);
+ dev_name[ESP_GAP_DEVICE_NAME_MAX] = '\0';
+ BTA_DmSetDeviceName(dev_name);
+ return ESP_OK;
+}
#define BTM_DEFAULT_DISC_INTERVAL 0x0800
#endif
-/* Default class of device
+/*
* {SERVICE_CLASS, MAJOR_CLASS, MINOR_CLASS}
*
* SERVICE_CLASS:0x5A (Bit17 -Networking,Bit19 - Capturing,Bit20 -Object Transfer,Bit22 -Telephony)
* MINOR_CLASS:0x0C - SMART_PHONE
*
*/
+#define BTA_DM_COD_SMARTPHONE {0x5A, 0x02, 0x0C}
+
+/*
+* {SERVICE_CLASS, MAJOR_CLASS, MINOR_CLASS}
+*
+* SERVICE_CLASS:0x2C (Bit21 - Audio, Bit19 - Capturing)
+* MAJOR_CLASS:0x04 - Audio/Video
+* MINOR_CLASS:0x05 - LoudSpeaker
+*/
+#define BTA_DM_COD_LOUDSPEAKER {0x2C, 0x04, 0x14}
+
+/* Default class of device */
#ifndef BTA_DM_COD
-#define BTA_DM_COD {0x5A, 0x02, 0x0C}
+#define BTA_DM_COD BTA_DM_COD_LOUDSPEAKER
#endif
/* The number of SCO links. */
#include "EspAudioCom.h"
#include "bt_app_common.h"
-#include "btif_stack_manager.h"
+#include "esp_bt_stack_manager.h"
#include "esp_gap_bt_api.h"
#include "bta_api.h"
#include "esp_a2dp_api.h"
-/* utl_set_device_class() */
-#include "utl.h"
-
typedef enum {
BT_APP_EVT_STACK_ON = 0xa0,
BT_APP_EVT_MAX
static void bt_app_a2d_data_cb(uint8_t *data, uint32_t len)
{
- // uint32_t t_now = system_get_time();
- // printf("t: %u, l %d\n", t_now, len);
- EspAudioPlayerStreamWrite(data, len);
+ EspAudioPlayerStreamWrite(data, len, 10);
}
-static void btav_set_device_class(void)
-{
- tBTA_UTL_COD cod;
- memset(&cod, 0, sizeof(tBTA_UTL_COD));
- cod.major = BTM_COD_MAJOR_AUDIO;
- cod.minor = BTM_COD_MINOR_LOUDSPEAKER;
- cod.service = BTM_COD_SERVICE_CAPTURING | BTM_COD_SERVICE_AUDIO;
- utl_set_device_class(&cod, BTA_UTL_SET_COD_ALL);
- BT_APP_TRACE_ERROR("set class of device: major 0x%x, minor 0x%x, service 0x%x\n",
- cod.major, cod.minor, cod.service);
-}
-
static void bt_app_handle_evt(UINT16 event, void *p_param)
{
BT_APP_TRACE_EVENT("bt_app_handle_evt 0x%x\n", event);
switch (event) {
case BT_APP_EVT_STACK_ON: {
char *dev_name = "ESP_SPEAKER";
- BTM_SetTraceLevel(BT_TRACE_LEVEL_WARNING);
- btav_set_device_class();
- BTA_DmSetDeviceName(dev_name);
+ // BTM_SetTraceLevel(BT_TRACE_LEVEL_WARNING);
+ esp_bt_gap_set_device_name(dev_name);
esp_a2d_register_callback(bt_app_a2d_cb);
esp_a2d_register_data_callback(bt_app_a2d_data_cb);
void app_main_entry(void)
{
bt_status_t init, enable;
- init = BTIF_InitStack();
- if (init != BT_STATUS_SUCCESS) {
+ init = esp_bt_init_stack();
+ if (init != ESP_OK) {
return;
}
- enable = BTIF_EnableStack();
- if (enable != BT_STATUS_SUCCESS) {
+ enable = esp_bt_enable_stack();
+ if (enable != ESP_OK) {
return;
}
#include <stdbool.h>
#include <stdint.h>
-#include "btif_stack_manager.h"
+#include "esp_bt_stack_manager.h"
#include "stack_manager.h"
#include "bt_defs.h"
#include "bt_trace.h"
return BT_STATUS_SUCCESS;
}
-bt_status_t BTIF_InitStack(void)
+esp_err_t esp_bt_init_stack(void)
{
- return event_init_stack();
+ bt_status_t status;
+ status = event_init_stack();
+ switch (status) {
+ case BT_STATUS_SUCCESS: return ESP_OK;
+ case BT_STATUS_DONE: return ESP_ERR_INVALID_STATE;
+ default: return ESP_FAIL;
+ }
}
-bt_status_t BTIF_EnableStack(void)
+esp_err_t esp_bt_deinit_stack(void)
{
- return event_start_up_stack();
+ bt_status_t status;
+ status = event_clean_up_stack();
+ switch (status) {
+ case BT_STATUS_SUCCESS: return ESP_OK;
+ default: return ESP_ERR_INVALID_STATE;
+ }
}
-bt_status_t BTIF_DisableStack(void)
+esp_err_t esp_bt_enable_stack(void)
{
- return event_shut_down_stack();
+ bt_status_t status;
+ status = event_start_up_stack();
+ switch (status) {
+ case BT_STATUS_SUCCESS: return ESP_OK;
+ case BT_STATUS_NOT_READY:
+ case BT_STATUS_DONE:
+ return ESP_ERR_INVALID_STATE;
+ default: return ESP_FAIL;
+ }
}
-bt_status_t BTIF_CleanUpStack(void)
+esp_err_t esp_bt_disable_stack(void)
{
- return event_clean_up_stack();
+ bt_status_t status;
+ status = event_shut_down_stack();
+ switch (status) {
+ case BT_STATUS_SUCCESS: return ESP_OK;
+ case BT_STATUS_DONE: return ESP_ERR_INVALID_STATE;
+ default: return ESP_FAIL;
+ }
}
bool stack_manager_is_stack_running(void)
--- /dev/null
+#ifndef __ESP_BT_STACK_MANAGER_H__
+#define __ESP_BT_STACK_MANAGER_H__
+
+#include "esp_err.h"
+
+esp_err_t esp_bt_init_stack(void);
+
+esp_err_t esp_bt_deinit_stack(void);
+
+esp_err_t esp_bt_enable_stack(void);
+
+esp_err_t esp_bt_disable_stack(void);
+
+#endif /* __ESP_BT_STACK_MANAGER_H__ */