From 8ec94418def6a80cde0d38cc32d7dfc757b74a36 Mon Sep 17 00:00:00 2001 From: wangmengyang Date: Sat, 18 Mar 2017 14:55:31 +0800 Subject: [PATCH] component/bt: clean up the API header and generate documentation files --- .../bt/bluedroid/api/include/esp_a2dp_api.h | 65 +++---- .../bt/bluedroid/api/include/esp_avrc_api.h | 26 +-- .../bluedroid/btc/profile/std/a2dp/btc_avk.c | 64 +++---- .../btc/profile/std/a2dp/btc_media_task.c | 27 +-- .../bluedroid/btc/profile/std/avrc/btc_avrc.c | 166 ++++++++---------- .../btc/profile/std/include/btc_media.h | 2 +- docs/api/bluetooth/bt_le.rst | 2 +- docs/api/bluetooth/classic_bt.rst | 9 + docs/api/bluetooth/esp_a2dp.rst | 82 +++++++++ docs/api/bluetooth/esp_avrc.rst | 65 +++++++ docs/api/bluetooth/esp_bt_device.rst | 1 + docs/api/bluetooth/esp_gap_bt.rst | 47 +++++ docs/api/bluetooth/index.rst | 1 + 13 files changed, 360 insertions(+), 197 deletions(-) create mode 100644 docs/api/bluetooth/classic_bt.rst create mode 100644 docs/api/bluetooth/esp_a2dp.rst create mode 100644 docs/api/bluetooth/esp_avrc.rst create mode 100644 docs/api/bluetooth/esp_gap_bt.rst diff --git a/components/bt/bluedroid/api/include/esp_a2dp_api.h b/components/bt/bluedroid/api/include/esp_a2dp_api.h index 2f65986987..7f6868dde1 100755 --- a/components/bt/bluedroid/api/include/esp_a2dp_api.h +++ b/components/bt/bluedroid/api/include/esp_a2dp_api.h @@ -28,52 +28,23 @@ extern "C" { #define ESP_A2D_MCT_M24 (0x02) /*!< MPEG-2, 4 AAC */ #define ESP_A2D_MCT_ATRAC (0x04) /*!< ATRAC family */ #define ESP_A2D_MCT_NON_A2DP (0xff) + typedef uint8_t esp_a2d_mct_t; -/** - * @brief SBC codec specific information as defined in A2DP spec - */ +/// A2DP media codec capabilities union typedef struct { + esp_a2d_mct_t type; /*!< A2DP media codec type */ #define ESP_A2D_CIE_LEN_SBC (4) - uint8_t oct[ESP_A2D_CIE_LEN_SBC]; -} esp_a2d_cie_sbc_t; - -/** - * @brief MPEG-1,2 Audio codec specific information as defined in A2DP spec - */ -typedef struct { #define ESP_A2D_CIE_LEN_M12 (4) - uint8_t oct[ESP_A2D_CIE_LEN_M12]; -} esp_a2d_cie_m12_t; - -/** - * @brief MPEG-2,4 AAC codec specific information as defined in A2DP spec - */ -typedef struct { #define ESP_A2D_CIE_LEN_M24 (6) - uint8_t oct[ESP_A2D_CIE_LEN_M24]; -} esp_a2d_cie_m24_t; - -/** - * @brief ATRAC family codec specific information as defined in A2DP spec - */ -typedef struct { #define ESP_A2D_CIE_LEN_ATRAC (7) - uint8_t oct[ESP_A2D_CIE_LEN_ATRAC]; -} esp_a2d_cie_atrac_t; - -/** - * @brief A2DP media codec capabilities union - */ -typedef struct { - esp_a2d_mct_t type; /*!< A2DP media codec type */ union { - esp_a2d_cie_sbc_t sbc; - esp_a2d_cie_m12_t m12; - esp_a2d_cie_m24_t m24; - esp_a2d_cie_atrac_t atrac; - } cie; -} esp_a2d_mcc_t; + uint8_t sbc[ESP_A2D_CIE_LEN_SBC]; + uint8_t m12[ESP_A2D_CIE_LEN_M12]; + uint8_t m24[ESP_A2D_CIE_LEN_M24]; + uint8_t atrac[ESP_A2D_CIE_LEN_ATRAC]; + } cie; /*!< A2DP codec information element */ +} __attribute__((packed)) esp_a2d_mcc_t; /// Bluetooth A2DP connection states typedef enum { @@ -105,24 +76,30 @@ typedef enum { /// A2DP state callback parameters typedef union { - /*< ESP_A2D_CONNECTION_STATE_EVT */ + /** + * @brief ESP_A2D_CONNECTION_STATE_EVT + */ struct a2d_conn_stat_param { esp_a2d_connection_state_t state; /*!< one of values from esp_a2d_connection_state_t */ esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */ esp_a2d_disc_rsn_t disc_rsn; /*!< reason of disconnection for "DISCONNECTED" */ - } conn_stat; + } conn_stat; /*!< A2DP connection status */ - /*< ESP_A2D_AUDIO_STATE_EVT */ + /** + * @brief ESP_A2D_AUDIO_STATE_EVT + */ struct a2d_audio_stat_param { esp_a2d_audio_state_t state; /*!< one of the values from esp_a2d_audio_state_t */ esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */ - } audio_stat; + } audio_stat; /*!< audio stream playing state */ - /*< ESP_A2D_AUDIO_CFG_EVT */ + /** + * @brief ESP_A2D_AUDIO_CFG_EVT + */ struct a2d_audio_cfg_param { esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */ esp_a2d_mcc_t mcc; /*!< A2DP media codec capability information */ - } audio_cfg; + } audio_cfg; /*!< media codec configuration infomation */ } esp_a2d_cb_param_t; /** diff --git a/components/bt/bluedroid/api/include/esp_avrc_api.h b/components/bt/bluedroid/api/include/esp_avrc_api.h index 053ebbdea3..719a19f19c 100755 --- a/components/bt/bluedroid/api/include/esp_avrc_api.h +++ b/components/bt/bluedroid/api/include/esp_avrc_api.h @@ -35,19 +35,19 @@ typedef enum { } esp_avrc_features_t; /// AVRC passthrough command code -enum { +typedef enum { ESP_AVRC_PT_CMD_PLAY = 0x44, /*!< play */ ESP_AVRC_PT_CMD_STOP = 0x45, /*!< stop */ ESP_AVRC_PT_CMD_PAUSE = 0x46, /*!< pause */ ESP_AVRC_PT_CMD_FORWARD = 0x4B, /*!< forward */ ESP_AVRC_PT_CMD_BACKWARD = 0x4C /*!< backward */ -}; +} esp_avrc_pt_cmd_t; /// AVRC passthrough command state -enum { +typedef enum { ESP_AVRC_PT_CMD_STATE_PRESSED = 0, /*!< key pressed */ ESP_AVRC_PT_CMD_STATE_RELEASED = 1 /*!< key released */ -}; +} esp_avrc_pt_cmd_state_t; /// AVRC Controller callback events typedef enum { @@ -58,19 +58,23 @@ typedef enum { /// AVRC controller callback parameters typedef union { - /*< ESP_AVRC_CT_CONNECTION_STATE_EVT */ + /** + * @brief ESP_AVRC_CT_CONNECTION_STATE_EVT + */ struct avrc_ct_conn_stat_param { - bool connected; - uint32_t feat_mask; - esp_bd_addr_t remote_bda; - } conn_stat; + bool connected; /*!< whether AVRC connection is set up */ + uint32_t feat_mask; /*!< AVRC feature mask of remote device */ + esp_bd_addr_t remote_bda; /*!< remote bluetooth device address */ + } conn_stat; /*!< AVRC connection status */ - /*< ESP_AVRC_CT_PASSTHROUGH_RSP_EVT */ + /** + * @brief ESP_AVRC_CT_PASSTHROUGH_RSP_EVT + */ struct avrc_ct_psth_rsp_param { uint8_t tl; /*!< transaction label, 0 to 15 */ uint8_t key_code; /*!< passthrough command code */ uint8_t key_state; /*!< 0 for PRESSED, 1 for RELEASED */ - } psth_rsp; + } psth_rsp; /*!< passthrough command response */ } esp_avrc_ct_cb_param_t; diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c index d9872e7ade..966f8d6ff3 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_avk.c @@ -139,7 +139,7 @@ static inline void btc_a2d_cb_to_app(esp_a2d_cb_event_t event, esp_a2d_cb_param_ { esp_a2d_cb_t btc_a2d_cb = (esp_a2d_cb_t)btc_profile_cb_get(BTC_PID_A2DP); if (btc_a2d_cb) { - btc_a2d_cb(event, param); + btc_a2d_cb(event, param); } } @@ -229,14 +229,14 @@ static void btc_report_connection_state(esp_a2d_connection_state_t state, bt_bda { esp_a2d_cb_param_t param; memset(¶m, 0, sizeof(esp_a2d_cb_param_t)); - + param.conn_stat.state = state; if (bd_addr) { memcpy(param.conn_stat.remote_bda, bd_addr, sizeof(esp_bd_addr_t)); } if (state == ESP_A2D_CONNECTION_STATE_DISCONNECTED) { param.conn_stat.disc_rsn = (disc_rsn == 0) ? ESP_A2D_DISC_RSN_NORMAL : - ESP_A2D_DISC_RSN_ABNORMAL; + ESP_A2D_DISC_RSN_ABNORMAL; } btc_a2d_cb_to_app(ESP_A2D_CONNECTION_STATE_EVT, ¶m); } @@ -266,7 +266,7 @@ static void btc_report_audio_state(esp_a2d_audio_state_t state, bt_bdaddr_t *bd_ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) { LOG_DEBUG("%s event:%s flags %x\n", __FUNCTION__, - dump_av_sm_event_name(event), btc_av_cb.flags); + dump_av_sm_event_name(event), btc_av_cb.flags); switch (event) { case BTC_SM_ENTER_EVT: @@ -339,7 +339,7 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) default: LOG_WARN("%s : unhandled event:%s\n", __FUNCTION__, - dump_av_sm_event_name(event)); + dump_av_sm_event_name(event)); return FALSE; } @@ -360,7 +360,7 @@ static BOOLEAN btc_av_state_idle_handler(btc_sm_event_t event, void *p_data) static BOOLEAN btc_av_state_opening_handler(btc_sm_event_t event, void *p_data) { LOG_DEBUG("%s event:%s flags %x\n", __FUNCTION__, - dump_av_sm_event_name(event), btc_av_cb.flags); + dump_av_sm_event_name(event), btc_av_cb.flags); switch (event) { case BTC_SM_ENTER_EVT: @@ -382,7 +382,7 @@ static BOOLEAN btc_av_state_opening_handler(btc_sm_event_t event, void *p_data) esp_a2d_connection_state_t state; btc_sm_state_t av_state; LOG_DEBUG("status:%d, edr 0x%x\n", p_bta_data->open.status, - p_bta_data->open.edr); + p_bta_data->open.edr); if (p_bta_data->open.status == BTA_AV_SUCCESS) { state = ESP_A2D_CONNECTION_STATE_CONNECTED; @@ -393,7 +393,7 @@ static BOOLEAN btc_av_state_opening_handler(btc_sm_event_t event, void *p_data) btc_a2dp_set_peer_sep(p_bta_data->open.sep); } else { LOG_WARN("BTA_AV_OPEN_EVT::FAILED status: %d\n", - p_bta_data->open.status ); + p_bta_data->open.status ); state = ESP_A2D_CONNECTION_STATE_DISCONNECTED; av_state = BTC_AV_STATE_IDLE; } @@ -448,7 +448,7 @@ static BOOLEAN btc_av_state_opening_handler(btc_sm_event_t event, void *p_data) default: LOG_WARN("%s : unhandled event:%s\n", __FUNCTION__, - dump_av_sm_event_name(event)); + dump_av_sm_event_name(event)); return FALSE; } @@ -470,7 +470,7 @@ static BOOLEAN btc_av_state_opening_handler(btc_sm_event_t event, void *p_data) static BOOLEAN btc_av_state_closing_handler(btc_sm_event_t event, void *p_data) { LOG_DEBUG("%s event:%s flags %x\n", __FUNCTION__, - dump_av_sm_event_name(event), btc_av_cb.flags); + dump_av_sm_event_name(event), btc_av_cb.flags); switch (event) { case BTC_SM_ENTER_EVT: @@ -495,7 +495,7 @@ static BOOLEAN btc_av_state_closing_handler(btc_sm_event_t event, void *p_data) tBTA_AV_CLOSE *close = (tBTA_AV_CLOSE *)p_data; /* inform the application that we are disconnecting */ btc_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btc_av_cb.peer_bda), - close->disc_rsn); + close->disc_rsn); btc_sm_change_state(btc_av_cb.sm_handle, BTC_AV_STATE_IDLE); break; @@ -508,7 +508,7 @@ static BOOLEAN btc_av_state_closing_handler(btc_sm_event_t event, void *p_data) default: LOG_WARN("%s : unhandled event:%s\n", __FUNCTION__, - dump_av_sm_event_name(event)); + dump_av_sm_event_name(event)); return FALSE; } return TRUE; @@ -530,7 +530,7 @@ static BOOLEAN btc_av_state_opened_handler(btc_sm_event_t event, void *p_data) tBTA_AV *p_av = (tBTA_AV *)p_data; LOG_DEBUG("%s event:%s flags %x\n", __FUNCTION__, - dump_av_sm_event_name(event), btc_av_cb.flags); + dump_av_sm_event_name(event), btc_av_cb.flags); if ( (event == BTA_AV_REMOTE_CMD_EVT) && (btc_av_cb.flags & BTC_AV_FLAG_REMOTE_SUSPEND) && (p_av->remote_cmd.rc_id == BTA_AV_RC_PLAY) ) { @@ -555,7 +555,7 @@ static BOOLEAN btc_av_state_opened_handler(btc_sm_event_t event, void *p_data) case BTA_AV_START_EVT: { LOG_INFO("BTA_AV_START_EVT status %d, suspending %d, init %d\n", - p_av->start.status, p_av->start.suspending, p_av->start.initiator); + p_av->start.status, p_av->start.suspending, p_av->start.initiator); if ((p_av->start.status == BTA_SUCCESS) && (p_av->start.suspending == TRUE)) { return TRUE; @@ -596,7 +596,7 @@ static BOOLEAN btc_av_state_opened_handler(btc_sm_event_t event, void *p_data) tBTA_AV_CLOSE *close = (tBTA_AV_CLOSE *)p_data; /* inform the application that we are disconnected */ btc_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btc_av_cb.peer_bda), - close->disc_rsn); + close->disc_rsn); /* change state to idle, send acknowledgement if start is pending */ if (btc_av_cb.flags & BTC_AV_FLAG_PENDING_START) { @@ -623,7 +623,7 @@ static BOOLEAN btc_av_state_opened_handler(btc_sm_event_t event, void *p_data) } else { LOG_DEBUG("%s: Moved to opened by Other Incoming Conn req\n", __func__); btc_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, - (bt_bdaddr_t *)p_data, ESP_A2D_DISC_RSN_NORMAL); + (bt_bdaddr_t *)p_data, ESP_A2D_DISC_RSN_NORMAL); } btc_queue_advance(); break; @@ -632,7 +632,7 @@ static BOOLEAN btc_av_state_opened_handler(btc_sm_event_t event, void *p_data) default: LOG_WARN("%s : unhandled event:%s\n", __FUNCTION__, - dump_av_sm_event_name(event)); + dump_av_sm_event_name(event)); return FALSE; } @@ -654,7 +654,7 @@ static BOOLEAN btc_av_state_started_handler(btc_sm_event_t event, void *p_data) tBTA_AV *p_av = (tBTA_AV *)p_data; LOG_DEBUG("%s event:%s flags %x\n", __FUNCTION__, - dump_av_sm_event_name(event), btc_av_cb.flags); + dump_av_sm_event_name(event), btc_av_cb.flags); switch (event) { case BTC_SM_ENTER_EVT: @@ -717,7 +717,7 @@ static BOOLEAN btc_av_state_started_handler(btc_sm_event_t event, void *p_data) case BTA_AV_SUSPEND_EVT: LOG_INFO("BTA_AV_SUSPEND_EVT status %d, init %d\n", - p_av->suspend.status, p_av->suspend.initiator); + p_av->suspend.status, p_av->suspend.initiator); /* a2dp suspended, stop media task until resumed */ btc_a2dp_on_suspended(&p_av->suspend); @@ -770,21 +770,21 @@ static BOOLEAN btc_av_state_started_handler(btc_sm_event_t event, void *p_data) /* avdtp link is closed */ btc_a2dp_on_stopped(NULL); - + tBTA_AV_CLOSE *close = (tBTA_AV_CLOSE *)p_data; /* inform the application that we are disconnected */ btc_report_connection_state(ESP_A2D_CONNECTION_STATE_DISCONNECTED, &(btc_av_cb.peer_bda), - close->disc_rsn); + close->disc_rsn); btc_sm_change_state(btc_av_cb.sm_handle, BTC_AV_STATE_IDLE); break; } - + CHECK_RC_EVENT(event, p_data); default: LOG_WARN("%s : unhandled event:%s\n", __FUNCTION__, - dump_av_sm_event_name(event)); + dump_av_sm_event_name(event)); return FALSE; } @@ -893,19 +893,19 @@ static void bte_av_media_callback(tBTA_AV_EVT event, tBTA_AV_MEDIA *p_data) /* send a command to BT Media Task */ btc_reset_decoder((UINT8 *)p_data); - /* currently only supportes SBC */ + /* currently only supportes SBC */ a2d_status = A2D_ParsSbcInfo(&sbc_cie, (UINT8 *)p_data, FALSE); if (a2d_status == A2D_SUCCESS) { btc_msg_t msg; btc_av_args_t arg; - + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_A2DP; msg.act = BTC_AV_SINK_CONFIG_REQ_EVT; memset(&arg, 0, sizeof(btc_av_args_t)); arg.mcc.type = ESP_A2D_MCT_SBC; - memcpy(&(arg.mcc.cie), (uint8_t *)p_data + 3, ESP_A2D_CIE_LEN_SBC); + memcpy(arg.mcc.cie.sbc, (uint8_t *)p_data + 3, ESP_A2D_CIE_LEN_SBC); btc_transfer_context(&msg, &arg, sizeof(btc_av_args_t), NULL); } else { LOG_ERROR("ERROR dump_codec_info A2D_ParsSbcInfo fail:%d\n", a2d_status); @@ -982,7 +982,7 @@ static bt_status_t connect_int(bt_bdaddr_t *bd_addr, uint16_t uuid) return BT_STATUS_SUCCESS; } -bt_status_t btc_a2d_sink_connect(bt_bdaddr_t* remote_bda) +bt_status_t btc_a2d_sink_connect(bt_bdaddr_t *remote_bda) { LOG_DEBUG("%s\n", __FUNCTION__); CHECK_BTAV_INIT(); @@ -1045,7 +1045,7 @@ BOOLEAN btc_av_stream_ready(void) btc_sm_state_t state = btc_sm_get_state(btc_av_cb.sm_handle); LOG_DEBUG("btc_av_stream_ready : sm hdl %d, state %d, flags %x\n", - (int)btc_av_cb.sm_handle, state, btc_av_cb.flags); + (int)btc_av_cb.sm_handle, state, btc_av_cb.flags); /* check if we are remotely suspended or stop is pending */ if (btc_av_cb.flags & (BTC_AV_FLAG_REMOTE_SUSPEND | BTC_AV_FLAG_PENDING_STOP)) { @@ -1070,11 +1070,11 @@ BOOLEAN btc_av_stream_started_ready(void) btc_sm_state_t state = btc_sm_get_state(btc_av_cb.sm_handle); LOG_DEBUG("btc_av_stream_started : sm hdl %d, state %d, flags %x\n", - (int)btc_av_cb.sm_handle, state, btc_av_cb.flags); + (int)btc_av_cb.sm_handle, state, btc_av_cb.flags); /* disallow media task to start if we have pending actions */ if (btc_av_cb.flags & (BTC_AV_FLAG_LOCAL_SUSPEND_PENDING | BTC_AV_FLAG_REMOTE_SUSPEND - | BTC_AV_FLAG_PENDING_STOP)) { + | BTC_AV_FLAG_PENDING_STOP)) { return FALSE; } @@ -1121,8 +1121,8 @@ bt_status_t btc_av_execute_service(BOOLEAN b_enable) * auto-suspend av streaming on AG events(SCO or Call). The suspend shall * be initiated by the app/audioflinger layers */ BTA_AvEnable(BTA_SEC_AUTHENTICATE, (BTA_AV_FEAT_NO_SCO_SSPD) - // | BTA_AV_FEAT_RCTG | BTA_AV_FEAT_METADATA | BTA_AV_FEAT_VENDOR - | BTA_AV_FEAT_RCCT | BTA_AV_FEAT_ADV_CTRL, + // | BTA_AV_FEAT_RCTG | BTA_AV_FEAT_METADATA | BTA_AV_FEAT_VENDOR + | BTA_AV_FEAT_RCCT | BTA_AV_FEAT_ADV_CTRL, bte_av_callback); BTA_AvRegister(BTA_AV_CHNL_AUDIO, BTC_AV_SERVICE_NAME, 0, bte_av_media_callback, &bta_av_a2d_cos); } else { diff --git a/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c b/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c index aba25fd747..95e4830985 100644 --- a/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c +++ b/components/bt/bluedroid/btc/profile/std/a2dp/btc_media_task.c @@ -231,8 +231,9 @@ static void btc_media_data_post(void) static void btc_media_ctrl_handler(BtTaskEvt_t *e) { - if (e == NULL) + if (e == NULL) { return; + } switch (e->sig) { case SIG_MEDIA_TASK_CMD_READY: fixed_queue_process(btc_media_cmd_msg_queue); @@ -280,15 +281,15 @@ bool btc_a2dp_start_media_task(void) xBtcMediaDataQueue = xQueueCreate(MEDIA_DATA_Q_LEN, sizeof(void *)); configASSERT(xBtcMediaDataQueue); xQueueAddToSet(xBtcMediaDataQueue, xBtcMediaQueueSet); - + xBtcMediaCtrlQueue = xQueueCreate(MEDIA_CTRL_Q_LEN, sizeof(void *)); configASSERT(xBtcMediaCtrlQueue); xQueueAddToSet(xBtcMediaCtrlQueue, xBtcMediaQueueSet); - + if (!xBtcMediaDataQueue || !xBtcMediaCtrlQueue || !xBtcMediaQueueSet ) { goto error_exit; } - + xTaskCreatePinnedToCore(btc_media_task_handler, "BtcMediaT\n", 2048, NULL, configMAX_PRIORITIES - 1, &xBtcMediaTaskHandle, 0); if (xBtcMediaTaskHandle == NULL) { goto error_exit; @@ -321,7 +322,7 @@ error_exit:; vQueueDelete(xBtcMediaCtrlQueue); xBtcMediaCtrlQueue = NULL; } - + fixed_queue_free(btc_media_cmd_msg_queue, NULL); btc_media_cmd_msg_queue = NULL; return false; @@ -336,13 +337,13 @@ void btc_a2dp_stop_media_task(void) // TODO: wait until CLEAN up is done, then do task delete vTaskDelete(xBtcMediaTaskHandle); xBtcMediaTaskHandle = NULL; - + vQueueDelete(xBtcMediaDataQueue); xBtcMediaDataQueue = NULL; vQueueDelete(xBtcMediaCtrlQueue); xBtcMediaCtrlQueue = NULL; - + fixed_queue_free(btc_media_cmd_msg_queue, NULL); btc_media_cmd_msg_queue = NULL; } @@ -452,8 +453,8 @@ void btc_reset_decoder(UINT8 *p_av) { APPL_TRACE_EVENT("btc_reset_decoder"); APPL_TRACE_DEBUG("btc_reset_decoder p_codec_info[%x:%x:%x:%x:%x:%x]\n", - p_av[1], p_av[2], p_av[3], - p_av[4], p_av[5], p_av[6]); + p_av[1], p_av[2], p_av[3], + p_av[4], p_av[5], p_av[6]); tBTC_MEDIA_SINK_CFG_UPDATE *p_buf; if (NULL == (p_buf = GKI_getbuf(sizeof(tBTC_MEDIA_SINK_CFG_UPDATE)))) { @@ -584,7 +585,7 @@ static void btc_media_thread_handle_cmd(fixed_queue_t *queue) while (!fixed_queue_is_empty(queue)) { p_msg = (BT_HDR *)fixed_queue_dequeue(queue); APPL_TRACE_VERBOSE("btc_media_thread_handle_cmd : %d %s\n", p_msg->event, - dump_media_event(p_msg->event)); + dump_media_event(p_msg->event)); switch (p_msg->event) { case BTC_MEDIA_AUDIO_SINK_CFG_UPDATE: @@ -766,8 +767,8 @@ static void btc_media_task_aa_handle_decoder_reset(BT_HDR *p_msg) UINT32 num_subbands = 8; APPL_TRACE_EVENT("btc_media_task_aa_handle_decoder_reset p_codec_info[%x:%x:%x:%x:%x:%x]\n", - p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3], - p_buf->codec_info[4], p_buf->codec_info[5], p_buf->codec_info[6]); + p_buf->codec_info[1], p_buf->codec_info[2], p_buf->codec_info[3], + p_buf->codec_info[4], p_buf->codec_info[5], p_buf->codec_info[6]); a2d_status = A2D_ParsSbcInfo(&sbc_cie, p_buf->codec_info, FALSE); if (a2d_status != A2D_SUCCESS) { @@ -897,7 +898,7 @@ UINT8 btc_media_sink_enque_buf(BT_HDR *p_pkt) if (btc_media_cb.rx_flush == TRUE) { /* Flush enabled, do not enque*/ return GKI_queue_length(&btc_media_cb.RxSbcQ); } - + if (GKI_queue_length(&btc_media_cb.RxSbcQ) >= MAX_OUTPUT_A2DP_FRAME_QUEUE_SZ) { APPL_TRACE_WARNING("Pkt dropped\n"); } diff --git a/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c b/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c index 0c20b66424..083cb876bb 100644 --- a/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c +++ b/components/bt/bluedroid/btc/profile/std/avrc/btc_avrc.c @@ -48,7 +48,7 @@ LOG_DEBUG("## %s ##", __FUNCTION__); \ if (btc_rc_vb.rc_connected == FALSE) { \ LOG_WARN("Function %s() called when RC is not connected", __FUNCTION__); \ - return ESP_ERR_INVALID_STATE; \ + return ESP_ERR_INVALID_STATE; \ } \ } while (0) @@ -60,8 +60,7 @@ typedef struct { UINT8 label; } btc_rc_reg_notifications_t; -typedef struct -{ +typedef struct { UINT8 label; UINT8 ctype; BOOLEAN is_rsp_pending; @@ -86,8 +85,7 @@ typedef struct { UINT8 handle; } rc_transaction_t; -typedef struct -{ +typedef struct { pthread_mutex_t lbllock; rc_transaction_t transaction[MAX_TRANSACTIONS_PER_SESSION]; } rc_device_t; @@ -113,7 +111,7 @@ static inline void btc_avrc_ct_cb_to_app(esp_avrc_ct_cb_event_t event, esp_avrc_ { esp_avrc_ct_cb_t btc_avrc_cb = (esp_avrc_ct_cb_t)btc_profile_cb_get(BTC_PID_AVRC); if (btc_avrc_cb) { - btc_avrc_cb(event, param); + btc_avrc_cb(event, param); } } @@ -129,19 +127,16 @@ static void handle_rc_features(void) // the following bit here: // btc_rc_vb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL; - if (btc_rc_vb.rc_features & BTA_AV_FEAT_BROWSE) - { + if (btc_rc_vb.rc_features & BTA_AV_FEAT_BROWSE) { rc_features |= BTRC_FEAT_BROWSE; } if ( (btc_rc_vb.rc_features & BTA_AV_FEAT_ADV_CTRL) && - (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG)) - { + (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG)) { rc_features |= BTRC_FEAT_ABSOLUTE_VOLUME; } - if (btc_rc_vb.rc_features & BTA_AV_FEAT_METADATA) - { + if (btc_rc_vb.rc_features & BTA_AV_FEAT_METADATA) { rc_features |= BTRC_FEAT_METADATA; } @@ -164,16 +159,13 @@ static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open) bt_bdaddr_t rc_addr; #endif - if(p_rc_open->status == BTA_AV_SUCCESS) - { + if (p_rc_open->status == BTA_AV_SUCCESS) { //check if already some RC is connected - if (btc_rc_vb.rc_connected) - { + if (btc_rc_vb.rc_connected) { LOG_ERROR("Got RC OPEN in connected state, Connected RC: %d \ - and Current RC: %d", btc_rc_vb.rc_handle,p_rc_open->rc_handle ); + and Current RC: %d", btc_rc_vb.rc_handle, p_rc_open->rc_handle ); if ((btc_rc_vb.rc_handle != p_rc_open->rc_handle) - && (bdcmp(btc_rc_vb.rc_addr, p_rc_open->peer_addr))) - { + && (bdcmp(btc_rc_vb.rc_addr, p_rc_open->peer_addr))) { LOG_DEBUG("Got RC connected for some other handle"); BTA_AvCloseRc(p_rc_open->rc_handle); return; @@ -188,25 +180,24 @@ static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open) btc_rc_vb.rc_handle = p_rc_open->rc_handle; /* on locally initiated connection we will get remote features as part of connect */ - if (btc_rc_vb.rc_features != 0) + if (btc_rc_vb.rc_features != 0) { handle_rc_features(); + } #if (AVRC_CTLR_INCLUDED == TRUE) bdcpy(rc_addr.address, btc_rc_vb.rc_addr); /* report connection state if device is AVRCP target */ if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG) { - esp_avrc_ct_cb_param_t param; - memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t)); - param.conn_stat.connected = true; - param.conn_stat.feat_mask = btc_rc_vb.rc_features; - memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t)); - btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m); + esp_avrc_ct_cb_param_t param; + memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t)); + param.conn_stat.connected = true; + param.conn_stat.feat_mask = btc_rc_vb.rc_features; + memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t)); + btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m); } #endif - } - else - { + } else { LOG_ERROR("%s Connect failed with error code: %d", - __FUNCTION__, p_rc_open->status); + __FUNCTION__, p_rc_open->status); btc_rc_vb.rc_connected = FALSE; } } @@ -227,8 +218,7 @@ static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close) #endif LOG_DEBUG("%s: rc_handle: %d", __FUNCTION__, p_rc_close->rc_handle); if ((p_rc_close->rc_handle != btc_rc_vb.rc_handle) - && (bdcmp(btc_rc_vb.rc_addr, p_rc_close->peer_addr))) - { + && (bdcmp(btc_rc_vb.rc_addr, p_rc_close->peer_addr))) { LOG_ERROR("Got disconnect of unknown device"); return; } @@ -241,8 +231,8 @@ static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close) features = btc_rc_vb.rc_features; #endif btc_rc_vb.rc_features = 0; - btc_rc_vb.rc_vol_label=MAX_LABEL; - btc_rc_vb.rc_volume=MAX_VOLUME; + btc_rc_vb.rc_vol_label = MAX_LABEL; + btc_rc_vb.rc_volume = MAX_VOLUME; #if (AVRC_CTLR_INCLUDED == TRUE) bdcpy(rc_addr.address, btc_rc_vb.rc_addr); #endif @@ -250,11 +240,11 @@ static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close) #if (AVRC_CTLR_INCLUDED == TRUE) /* report connection state if device is AVRCP target */ if (features & BTA_AV_FEAT_RCTG) { - esp_avrc_ct_cb_param_t param; - memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t)); - param.conn_stat.connected = false; - memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t)); - btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m); + esp_avrc_ct_cb_param_t param; + memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t)); + param.conn_stat.connected = false; + memcpy(param.conn_stat.remote_bda, &rc_addr, sizeof(esp_bd_addr_t)); + btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m); } #endif } @@ -271,33 +261,27 @@ static void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp) { #if (AVRC_CTLR_INCLUDED == TRUE) const char *status; - if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG) - { + if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG) { int key_state; - if (p_remote_rsp->key_state == AVRC_STATE_RELEASE) - { + if (p_remote_rsp->key_state == AVRC_STATE_RELEASE) { status = "released"; key_state = 1; - } - else - { + } else { status = "pressed"; key_state = 0; } LOG_DEBUG("%s: rc_id=%d status=%s", __FUNCTION__, p_remote_rsp->rc_id, status); - do { - esp_avrc_ct_cb_param_t param; - memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t)); + do { + esp_avrc_ct_cb_param_t param; + memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t)); param.psth_rsp.tl = p_remote_rsp->label; - param.psth_rsp.key_code = p_remote_rsp->rc_id; - param.psth_rsp.key_state = key_state; - btc_avrc_ct_cb_to_app(ESP_AVRC_CT_PASSTHROUGH_RSP_EVT, ¶m); - } while (0); - } - else - { + param.psth_rsp.key_code = p_remote_rsp->rc_id; + param.psth_rsp.key_state = key_state; + btc_avrc_ct_cb_to_app(ESP_AVRC_CT_PASSTHROUGH_RSP_EVT, ¶m); + } while (0); + } else { LOG_ERROR("%s DUT does not support AVRCP controller role", __FUNCTION__); } #else @@ -316,41 +300,36 @@ static void handle_rc_passthrough_rsp ( tBTA_AV_REMOTE_RSP *p_remote_rsp) void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data) { LOG_DEBUG ("%s event:%s", __FUNCTION__, dump_rc_event(event)); - switch (event) - { - case BTA_AV_RC_OPEN_EVT: - { - LOG_DEBUG("Peer_features:%x", p_data->rc_open.peer_features); - handle_rc_connect( &(p_data->rc_open) ); - }break; + switch (event) { + case BTA_AV_RC_OPEN_EVT: { + LOG_DEBUG("Peer_features:%x", p_data->rc_open.peer_features); + handle_rc_connect( &(p_data->rc_open) ); + } break; - case BTA_AV_RC_CLOSE_EVT: - { - handle_rc_disconnect( &(p_data->rc_close) ); - }break; + case BTA_AV_RC_CLOSE_EVT: { + handle_rc_disconnect( &(p_data->rc_close) ); + } break; #if (AVRC_CTLR_INCLUDED == TRUE) - case BTA_AV_REMOTE_RSP_EVT: - { - LOG_DEBUG("RSP: rc_id:0x%x key_state:%d", p_data->remote_rsp.rc_id, - p_data->remote_rsp.key_state); - handle_rc_passthrough_rsp( (&p_data->remote_rsp) ); - } - break; + case BTA_AV_REMOTE_RSP_EVT: { + LOG_DEBUG("RSP: rc_id:0x%x key_state:%d", p_data->remote_rsp.rc_id, + p_data->remote_rsp.key_state); + handle_rc_passthrough_rsp( (&p_data->remote_rsp) ); + } + break; #endif - case BTA_AV_RC_FEAT_EVT: - { - LOG_DEBUG("Peer_features:%x", p_data->rc_feat.peer_features); - btc_rc_vb.rc_features = p_data->rc_feat.peer_features; - handle_rc_features(); - } - break; + case BTA_AV_RC_FEAT_EVT: { + LOG_DEBUG("Peer_features:%x", p_data->rc_feat.peer_features); + btc_rc_vb.rc_features = p_data->rc_feat.peer_features; + handle_rc_features(); + } + break; - // below events are not handled for now - case BTA_AV_META_MSG_EVT: - case BTA_AV_REMOTE_CMD_EVT: - default: - LOG_DEBUG("Unhandled RC event : 0x%x", event); + // below events are not handled for now + case BTA_AV_META_MSG_EVT: + case BTA_AV_REMOTE_CMD_EVT: + default: + LOG_DEBUG("Unhandled RC event : 0x%x", event); } } @@ -388,8 +367,8 @@ static void btc_avrc_ct_init(void) LOG_DEBUG("## %s ##", __FUNCTION__); memset (&btc_rc_vb, 0, sizeof(btc_rc_vb)); - btc_rc_vb.rc_vol_label=MAX_LABEL; - btc_rc_vb.rc_volume=MAX_VOLUME; + btc_rc_vb.rc_vol_label = MAX_LABEL; + btc_rc_vb.rc_volume = MAX_VOLUME; } @@ -414,22 +393,19 @@ static bt_status_t btc_avrc_ct_send_passthrough_cmd(uint8_t tl, uint8_t key_code { tAVRC_STS status = BT_STATUS_UNSUPPORTED; if (tl >= 16 || - key_state > ESP_AVRC_PT_CMD_STATE_RELEASED) { + key_state > ESP_AVRC_PT_CMD_STATE_RELEASED) { return ESP_ERR_INVALID_ARG; } #if (AVRC_CTLR_INCLUDED == TRUE) CHECK_ESP_RC_CONNECTED; LOG_DEBUG("%s: key-code: %d, key-state: %d", __FUNCTION__, - key_code, key_state); - if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG) - { + key_code, key_state); + if (btc_rc_vb.rc_features & BTA_AV_FEAT_RCTG) { BTA_AvRemoteCmd(btc_rc_vb.rc_handle, tl, (tBTA_AV_RC)key_code, (tBTA_AV_STATE)key_state); status = BT_STATUS_SUCCESS; LOG_INFO("%s: succesfully sent passthrough command to BTA", __FUNCTION__); - } - else - { + } else { status = BT_STATUS_FAIL; LOG_DEBUG("%s: feature not supported", __FUNCTION__); } diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_media.h b/components/bt/bluedroid/btc/profile/std/include/btc_media.h index 983bebe968..3ff0d1e108 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_media.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_media.h @@ -214,7 +214,7 @@ extern void btc_media_aa_writebuf(BT_HDR *pBuf, UINT32 timestamp, UINT16 seq_num ** *******************************************************************************/ extern BOOLEAN btc_media_av_writebuf(UINT8 *p_media, UINT32 media_len, - UINT32 timestamp, UINT16 seq_num); + UINT32 timestamp, UINT16 seq_num); #if (BTA_AV_INCLUDED == TRUE) /******************************************************************************* diff --git a/docs/api/bluetooth/bt_le.rst b/docs/api/bluetooth/bt_le.rst index 11d09809fe..9535c01da7 100644 --- a/docs/api/bluetooth/bt_le.rst +++ b/docs/api/bluetooth/bt_le.rst @@ -1,4 +1,4 @@ -BT COMMON +BT LE ========= .. toctree:: diff --git a/docs/api/bluetooth/classic_bt.rst b/docs/api/bluetooth/classic_bt.rst new file mode 100644 index 0000000000..59dac87f1b --- /dev/null +++ b/docs/api/bluetooth/classic_bt.rst @@ -0,0 +1,9 @@ +CLASSIC BT +========== + +.. toctree:: + :caption: Classic BT + + BT GAP + BT A2DP + BT AVRC diff --git a/docs/api/bluetooth/esp_a2dp.rst b/docs/api/bluetooth/esp_a2dp.rst new file mode 100644 index 0000000000..24fe4c9535 --- /dev/null +++ b/docs/api/bluetooth/esp_a2dp.rst @@ -0,0 +1,82 @@ +Bluetooth A2DP API +================== + +Overview +-------- + +`Instructions`_ + +.. _Instructions: ../template.html + +Application Example +------------------- + +Check :example:`bluetooth` folder in ESP-IDF examples, which contains the following examples: + +:example:`bluetooth/a2dp_sink` + + This is a A2DP sink client demo. This demo can be discovered and connected by A2DP source device and receive the audio stream from remote device. + + +API Reference +------------- + +Header Files +^^^^^^^^^^^^ + + * :component_file:`bt/bluedroid/api/include/esp_a2dp_api.h` + +Macros +^^^^^^ + +.. doxygendefine:: ESP_A2D_MCT_SBC +.. doxygendefine:: ESP_A2D_MCT_M12 +.. doxygendefine:: ESP_A2D_MCT_M24 +.. doxygendefine:: ESP_A2D_MCT_ATRAC +.. doxygendefine:: ESP_A2D_MCT_NON_A2DP +.. doxygendefine:: ESP_A2D_CIE_LEN_SBC +.. doxygendefine:: ESP_A2D_CIE_LEN_M12 +.. doxygendefine:: ESP_A2D_CIE_LEN_M24 +.. doxygendefine:: ESP_A2D_CIE_LEN_ATRAC + +Type Definitions +^^^^^^^^^^^^^^^^ + +.. doxygentypedef:: esp_a2d_mct_t +.. doxygentypedef:: esp_a2d_cb_t +.. doxygentypedef:: esp_a2d_data_cb_t + +Enumerations +^^^^^^^^^^^^ + +.. doxygenenum:: esp_a2d_connection_state_t +.. doxygenenum:: esp_a2d_disc_rsn_t +.. doxygenenum:: esp_a2d_audio_state_t +.. doxygenenum:: esp_a2d_cb_event_t + +Structures +^^^^^^^^^^ + +.. doxygenstruct:: esp_a2d_cb_param_t + :members: + +.. doxygenstruct:: esp_a2d_cb_param_t::a2d_conn_stat_param + :members: + +.. doxygenstruct:: esp_a2d_cb_param_t::a2d_audio_stat_param + :members: + +.. doxygenstruct:: esp_a2d_cb_param_t::a2d_audio_cfg_param + :members: + + +Functions +^^^^^^^^^ + +.. doxygenfunction:: esp_a2d_register_callback +.. doxygenfunction:: esp_a2d_register_data_callback +.. doxygenfunction:: esp_a2d_sink_init +.. doxygenfunction:: esp_a2d_sink_deinit +.. doxygenfunction:: esp_a2d_sink_connect +.. doxygenfunction:: esp_a2d_sink_disconnect + diff --git a/docs/api/bluetooth/esp_avrc.rst b/docs/api/bluetooth/esp_avrc.rst new file mode 100644 index 0000000000..8e6be37192 --- /dev/null +++ b/docs/api/bluetooth/esp_avrc.rst @@ -0,0 +1,65 @@ +BT AVRCP APIs +============= + +Overview +-------- + +Bluetooth AVRCP reference APIs. + +`Instructions`_ + +Application Example +------------------- + +`Instructions`_ + +.. _Instructions: ../template.html + + +API Reference +------------- + +Header Files +^^^^^^^^^^^^ + + * :component_file:`bt/bluedroid/api/include/esp_avrc_api.h` + + +Macros +^^^^^^ + + +Type Definitions +^^^^^^^^^^^^^^^^ + +.. doxygentypedef:: esp_avrc_ct_cb_t + +Enumerations +^^^^^^^^^^^^ + +.. doxygenenum:: esp_avrc_features_t +.. doxygenenum:: esp_avrc_pt_cmd_t +.. doxygenenum:: esp_avrc_pt_cmd_state_t +.. doxygenenum:: esp_avrc_ct_cb_event_t + +Structures +^^^^^^^^^^ + +.. doxygenstruct:: esp_avrc_ct_cb_param_t + :members: + +.. doxygenstruct:: esp_avrc_ct_cb_param_t::avrc_ct_conn_stat_param + :members: + +.. doxygenstruct:: esp_avrc_ct_cb_param_t::avrc_ct_psth_rsp_param + :members: + + +Functions +^^^^^^^^^ + +.. doxygenfunction:: esp_avrc_ct_register_callback +.. doxygenfunction:: esp_avrc_ct_init +.. doxygenfunction:: esp_avrc_ct_deinit +.. doxygenfunction:: esp_avrc_ct_send_passthrough_cmd + diff --git a/docs/api/bluetooth/esp_bt_device.rst b/docs/api/bluetooth/esp_bt_device.rst index 50e9dcf1a0..8f5a8a4c72 100644 --- a/docs/api/bluetooth/esp_bt_device.rst +++ b/docs/api/bluetooth/esp_bt_device.rst @@ -45,4 +45,5 @@ Functions ^^^^^^^^^ .. doxygenfunction:: esp_bt_dev_get_address +.. doxygenfunction:: esp_bt_dev_set_device_name diff --git a/docs/api/bluetooth/esp_gap_bt.rst b/docs/api/bluetooth/esp_gap_bt.rst new file mode 100644 index 0000000000..8f5314e107 --- /dev/null +++ b/docs/api/bluetooth/esp_gap_bt.rst @@ -0,0 +1,47 @@ +CLASSIC BLUETOOTH GAP API +========================= + +Overview +-------- + +`Instructions`_ + +Application Example +------------------- + +`Instructions`_ + +.. _Instructions: ../template.html + + +API Reference +------------- + +Header Files +^^^^^^^^^^^^ + + * :component_file:`bt/bluedroid/api/include/esp_gap_bt_api.h` + + +Macros +^^^^^^ + + +Type Definitions +^^^^^^^^^^^^^^^^ + + +Enumerations +^^^^^^^^^^^^ + +.. doxygenenum:: esp_bt_scan_mode_t + +Structures +^^^^^^^^^^ + + +Functions +^^^^^^^^^ + +.. doxygenfunction:: esp_bt_gap_set_scan_mode + diff --git a/docs/api/bluetooth/index.rst b/docs/api/bluetooth/index.rst index 996a26e138..db92ee8c2b 100644 --- a/docs/api/bluetooth/index.rst +++ b/docs/api/bluetooth/index.rst @@ -7,6 +7,7 @@ Bluetooth API Bluetooth Controller && VHCI Bluetooth Common Bluetooth LE + Bluetooth Classic BT Example code for this API section is provided in :example:`bluetooth` directory of ESP-IDF examples.