網頁

2019年1月17日 星期四

DIY - ESP32:ESP32 藍牙(Bluetooth)A2DP API 函數(七十三)

DIY - ESP32:ESP32 藍牙(Bluetooth)A2DP API 函數(七十三):

在 ESP32 藍牙(Bluetooth)的內置了 A2DP(藍牙立體聲音訊傳輸規範 / Advanced Audio Distribution Profile)的 API 函數,只要連接雙方支援 A2DP 協定都能以 16 bits,44.1 kHz 的質素傳輸聲音訊號。

功能 - esp_a2d_register_callback
原型:esp_err_t esp_a2d_register_callback(esp_a2d_cb_t callback)
參數:callback: A2DP event callback function
返回:ESP_OK: success
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: if callback is a NULL function pointer
說明:Register application callback function to A2DP module. This function should be called only after esp_bluedroid_enable() completes successfully, used by both A2DP source and sink.
範例:esp_a2d_register_callback(&bt_app_a2d_cb);

功能 - esp_a2d_sink_register_data_callback
原型:esp_err_t esp_a2d_sink_register_data_callback(esp_a2d_sink_data_cb_t callback)
參數:callback: A2DP sink data callback function
返回:ESP_OK: success
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: if callback is a NULL function pointer
說明:Register A2DP sink data output function; For now the output is PCM data stream decoded from SBC format. This function should be called only after esp_bluedroid_enable() completes successfully, used only by A2DP sink. The callback is invoked in the context of A2DP sink task whose stack size is configurable through menuconfig.
範例:esp_a2d_sink_register_data_callback(bt_app_a2d_data_cb);

功能 - esp_a2d_sink_init
原型:esp_err_t esp_a2d_sink_init(void)
參數:
返回:ESP_OK: if the initialization request is sent successfully
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:Initialize the bluetooth A2DP sink module. This function should be called after esp_bluedroid_enable() completes successfully.
範例:esp_a2d_sink_init();

功能 - esp_a2d_sink_deinit
原型:esp_err_t esp_a2d_sink_deinit(void)
參數:
返回:ESP_OK: success
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:De-initialize for A2DP sink module. This function should be called only after esp_bluedroid_enable() completes successfully.
範例:esp_a2d_sink_deinit()

功能 - esp_a2d_sink_connect
原型:esp_err_t esp_a2d_sink_connect(esp_bd_addr_t remote_bda)
參數:remote_bda: remote bluetooth device address
返回:ESP_OK: connect request is sent to lower layer
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:Connect to remote bluetooth A2DP source device, must after esp_a2d_sink_init()
範例:

功能 - esp_a2d_sink_disconnect
原型:esp_err_t esp_a2d_sink_disconnect(esp_bd_addr_t remote_bda)
參數:remote_bda: remote bluetooth device address
返回:ESP_OK: disconnect request is sent to lower layer
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:Disconnect from the remote A2DP source device.
範例:

功能 - esp_a2d_media_ctrl
原型:esp_err_t esp_a2d_media_ctrl(esp_a2d_media_ctrl_t ctrl)
參數:ctrl: control commands for A2DP data channel
返回:ESP_OK: control command is sent to lower layer
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:media control commands; this API can be used for both A2DP sink and source
範例:esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_CHECK_SRC_RDY);
            esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_START);
            esp_a2d_media_ctrl(ESP_A2D_MEDIA_CTRL_STOP);

功能 - esp_a2d_source_init
原型:esp_err_t esp_a2d_source_init(void)
參數:
返回:ESP_OK: if the initialization request is sent successfully
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:Initialize the bluetooth A2DP source module. This function should be called after esp_bluedroid_enable() completes successfully.
範例:esp_a2d_source_init();

功能 - esp_a2d_source_deinit
原型:esp_err_t esp_a2d_source_deinit(void)
參數:
返回:ESP_OK: success
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:De-initialize for A2DP source module. This function should be called only after esp_bluedroid_enable() completes successfully.
範例:esp_a2d_source_deinit();

功能 - esp_a2d_source_register_data_callback
原型:esp_err_t esp_a2d_source_register_data_callback(esp_a2d_source_data_cb_t callback
參數:callback: A2DP source data callback function
返回:ESP_OK: success
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: if callback is a NULL function pointer
說明:Register A2DP source data input function; For now the input is PCM data stream. This function should be called only after esp_bluedroid_enable() completes successfully. The callback is invoked in the context of A2DP source task whose stack size is configurable through menuconfig.
範例:esp_a2d_source_register_data_callback(bt_app_a2d_data_cb);

功能 - esp_a2d_source_connect
原型:esp_err_t esp_a2d_source_connect(esp_bd_addr_t remote_bda)
參數:remote_bda: remote bluetooth device address
返回:ESP_OK: connect request is sent to lower layer
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:Connect to remote A2DP sink device, must after esp_a2d_source_init()
範例:static esp_bd_addr_t s_peer_bda = {0};
            esp_a2d_source_connect(s_peer_bda);

功能 - esp_a2d_source_disconnect
原型:esp_err_t esp_a2d_source_disconnect(esp_bd_addr_t remote_bda)
參數:remote_bda: remote bluetooth device address
返回:ESP_OK: disconnect request is sent to lower layer
            ESP_INVALID_STATE: if bluetooth stack is not yet enabled
            ESP_FAIL: others
說明:Disconnect from the remote A2DP sink device.
範例:static esp_bd_addr_t s_peer_bda = {0};
            esp_a2d_source_disconnect(s_peer_bda);

Header File: bt/bluedroid/api/include/api/esp_a2dp_api.h
參考網址:https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/bluetooth/esp_a2dp.html

2019年 1月 17日 天氣報告
氣溫:16.5@ 22:00
相對濕度:百分之 98%
天氣:天色大致良好

沒有留言:

張貼留言