Skip to content

Instantly share code, notes, and snippets.

@maagmirror
Created March 20, 2024 04:14
Show Gist options
  • Save maagmirror/ee415b9fd8f3aa5bad143b4b931ba995 to your computer and use it in GitHub Desktop.
Save maagmirror/ee415b9fd8f3aa5bad143b4b931ba995 to your computer and use it in GitHub Desktop.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "esp_bt.h"
#include "esp_bt_main.h"
#include "esp_bt_device.h"
#include "nvs_flash.h"
#include "esp_a2dp_api.h"
#include "esp_avrc_api.h"
#define ESP_BT_DEVICE_NAME "ESP32_A2DP_SOURCE"
void app_main(void)
{
esp_err_t ret;
// Inicializa NVS.
ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);
// Inicializa el stack Bluetooth.
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
ret = esp_bt_controller_init(&bt_cfg);
if (ret) {
ESP_LOGE(ESP_BT_DEVICE_NAME, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
ret = esp_bt_controller_enable(ESP_BT_MODE_CLASSIC_BT);
if (ret) {
ESP_LOGE(ESP_BT_DEVICE_NAME, "%s enable controller failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
ret = esp_bluedroid_init();
if (ret) {
ESP_LOGE(ESP_BT_DEVICE_NAME, "%s initialize bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
ret = esp_bluedroid_enable();
if (ret) {
ESP_LOGE(ESP_BT_DEVICE_NAME, "%s enable bluedroid failed: %s\n", __func__, esp_err_to_name(ret));
return;
}
// Aquí se debe agregar la configuración adicional para A2DP source,
// como la inicialización del perfil A2DP y la configuración de callbacks.
// Consulta los ejemplos de ESP-IDF para ver cómo configurar un source A2DP.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment