TB2026-YDS Firmware
Loading...
Searching...
No Matches
bluetooth.h File Reference

Classic Bluetooth A2DP source: bring up the stack and connect to a speaker. More...

#include "esp_err.h"
#include "esp_a2dp_api.h"
#include "esp_gap_bt_api.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  bluetooth_device_t
 One device found during a scan; the unit the UI lists and selects from. More...
struct  bt_known_device_t
 The identity of a remembered device, enough to reconnect without scanning again. More...

Macros

#define BLUETOOTH_MAX_DEVICES   16
 Maximum number of devices retained from a single scan.
#define BLUETOOTH_MAX_KNOWN   8
 Maximum number of paired devices remembered and persisted across reboots (LRU).

Enumerations

enum  bluetooth_conn_state_t { BLUETOOTH_CONN_IDLE , BLUETOOTH_CONN_CONNECTING , BLUETOOTH_CONN_CONNECTED , BLUETOOTH_CONN_FAILED }
 Coarse connection state for the UI to render (connecting / connected / failure). More...

Functions

esp_err_t bluetooth_init (void)
 Bring up the Bluetooth stack in A2DP source mode.
esp_err_t bluetooth_shutdown (void)
 Power the radio down: deinit A2DP/AVRCP, Bluedroid and the BR/EDR controller.
void bluetooth_set_auto_shutdown (bool enable)
 Enable/disable the automatic radio power-down when the A2DP link drops.
esp_err_t bluetooth_load_known (void)
 Load the persisted known-device list without powering the radio up.
esp_err_t bluetooth_scan_start (void)
 Start an inquiry that collects nearby devices into a list (does not auto-connect).
esp_err_t bluetooth_scan_stop (void)
 Stop an inquiry started by bluetooth_scan_start(). No-op if not scanning.
bool bluetooth_is_scanning (void)
 Report whether an inquiry is currently running.
bool bluetooth_is_powered (void)
 Report whether the radio (controller + Bluedroid) is currently powered up.
size_t bluetooth_get_devices (bluetooth_device_t *out, size_t cap)
 Copy the current scan results into out (thread-safe snapshot).
esp_err_t bluetooth_connect (const esp_bd_addr_t bda)
 Connect the A2DP source to a device chosen by address (e.g. a scan result).
esp_err_t bluetooth_connect_by_name (const char *name_substr)
 TEST ONLY — scan and connect to the first device whose name contains name_substr.
esp_err_t bluetooth_disconnect (void)
 Disconnect the current A2DP link, if any.
bool bluetooth_is_connected (void)
 Report whether an A2DP source connection is currently established.
bluetooth_conn_state_t bluetooth_get_conn_state (void)
 Read the current connection state.
size_t bluetooth_get_known_devices (bt_known_device_t *out, size_t cap)
 Copy the persisted list of known (paired) devices into out, most-recent-first.
bool bluetooth_get_last_device (bt_known_device_t *out)
 Read the last successfully connected device (the one to offer for quick reconnect).
void bluetooth_set_last_device (const bt_known_device_t *dev)
 Remember a device as the most-recent one and persist it to NVS.
esp_err_t bluetooth_reconnect_last (void)
 Reconnect to the remembered device by address, without scanning.
esp_err_t bluetooth_forget_device (const esp_bd_addr_t bda)
 Forget a known device: drop it from the persisted list and remove its bond from NVS.
esp_err_t bluetooth_audio_start (esp_a2d_source_data_cb_t pcm_cb)
 Start streaming PCM to the connected sink through the A2DP source data path.
esp_err_t bluetooth_audio_stop (void)
 Suspend the media stream started by bluetooth_audio_start().
esp_err_t bluetooth_set_absolute_volume (uint8_t volume)
 Set the connected speaker's absolute volume over AVRCP (controller role).
bool bluetooth_is_avrc_connected (void)
 Report whether the AVRCP control channel is established.
bool bluetooth_volume_acked (void)
 Report whether the speaker has confirmed the most recent absolute-volume set.

Detailed Description

Classic Bluetooth A2DP source: bring up the stack and connect to a speaker.

Owns the Bluedroid stack and the A2DP source role: it powers the radio up, advertises an SBC stream endpoint, discovers nearby devices and connects to one matched by name. It stays codec-agnostic: it does not encode audio. SBC encoding and link pacing are done by the stack, which pulls raw PCM from a callback the caller registers via bluetooth_audio_start(); the Audio sink interface Bluetooth backend (sink_bluetooth) supplies that PCM from the pipeline.

The controller is configured BR/EDR-only (see sdkconfig.defaults); BLE is off.

Note
Développé avec l'assistance de Claude Opus 4.8 (Anthropic), sous la direction de Y. Dos Santos : spécification, revue et validation sur cible par l'auteur.