a2dp_sink.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "esp_err.h"
  3. #include <stdbool.h>
  4. /**
  5. * Bluetooth A2DP Sink - receive audio from phones/tablets via Bluetooth.
  6. *
  7. * Supports SBC codec (built-in Bluedroid decoder).
  8. * Only available on ESP32 (original) which supports Classic Bluetooth.
  9. *
  10. * When a Bluetooth device connects, AirPlay services are disabled.
  11. * When it disconnects, AirPlay services are re-enabled.
  12. */
  13. /**
  14. * Callback invoked when A2DP connection state changes.
  15. * @param connected true on connect, false on disconnect
  16. */
  17. typedef void (*bt_a2dp_state_cb_t)(bool connected);
  18. /**
  19. * Initialize and start the Bluetooth A2DP Sink.
  20. *
  21. * Sets up BT controller, Bluedroid, GAP (discoverable/connectable),
  22. * A2DP sink profile with SBC decoder, and AVRCP controller + target.
  23. *
  24. * @param device_name Bluetooth device name visible to phones
  25. * @param state_cb Callback for connection state changes (may be NULL)
  26. * @return ESP_OK on success
  27. */
  28. esp_err_t bt_a2dp_sink_init(const char *device_name,
  29. bt_a2dp_state_cb_t state_cb);
  30. /**
  31. * Check if a Bluetooth A2DP audio session is active.
  32. */
  33. bool bt_a2dp_sink_is_connected(void);
  34. /**
  35. * Force disconnect the current A2DP connection if one is active.
  36. */
  37. void bt_a2dp_sink_disconnect_current(void);
  38. /**
  39. * Enable or disable Bluetooth discoverability/connectability.
  40. * Saves the desired state — applied immediately if BT is running,
  41. * or deferred until the next bt_a2dp_sink_start().
  42. *
  43. * @param discoverable true to allow new BT connections, false to block them
  44. */
  45. void bt_a2dp_sink_set_discoverable(bool discoverable);
  46. /**
  47. * AVRCP passthrough commands for hardware button control.
  48. * These send commands to the connected BT source device.
  49. */
  50. void bt_a2dp_send_playpause(void);
  51. void bt_a2dp_send_next(void);
  52. void bt_a2dp_send_prev(void);
  53. void bt_a2dp_send_volume_up(void);
  54. void bt_a2dp_send_volume_down(void);
  55. void bt_a2dp_set_volume(uint8_t volume);
  56. /**
  57. * Report battery level to iOS devices (0-100 percent).
  58. */
  59. void bt_a2dp_send_battery_level(uint8_t percent);