ESPHome 2026.8.0b4
Loading...
Searching...
No Matches
bluetooth_connection_gatt_backend.h
Go to the documentation of this file.
1// bluetooth_connection_gatt_backend.h
2//
3// Binds ble_device_base::BLEGattConnection to the build's one GATT backend.
4// Backend and consumer both live in this component, so the ladder does too;
5// backends implement ble_gatt_client.h (the neutral contract).
6
7#pragma once
8
10
11#ifdef USE_BLE_GATT_CLIENT
12
14
15#if defined(USE_RP2040_BLE)
17#define ESPHOME_BLE_GATT_CONNECTION_TYPE bluetooth_connection::RP2GattClient
18#elif defined(USE_ESP32_BLE)
20#define ESPHOME_BLE_GATT_CONNECTION_TYPE bluetooth_connection::BluedroidGattClient
21#elif defined(USE_BLE_GATT_CLIENT_STUB_BACKEND)
22// Emitted only by the host unit-test manifest: the tests compile the hub
23// wrapper standalone, so bind a do-nothing backend. Every other backend-less
24// build hits the #error below.
26
28 public:
30 int connect(uint64_t address, uint8_t addr_type) { return ble_device_base::GATT_ERR_NOT_CONNECTED; }
31 int gatt_disconnect() { return ble_device_base::GATT_ERR_NOT_CONNECTED; }
32 bool cancel_gatt_disconnect() { return false; }
33 int discover_services() { return ble_device_base::GATT_ERR_NOT_CONNECTED; }
34 int read_characteristic(uint16_t handle) { return ble_device_base::GATT_ERR_NOT_CONNECTED; }
35 int write_characteristic(uint16_t handle, const uint8_t *data, uint16_t len, bool response) {
36 return ble_device_base::GATT_ERR_NOT_CONNECTED;
37 }
38 int read_descriptor(uint16_t handle) { return ble_device_base::GATT_ERR_NOT_CONNECTED; }
39 int write_descriptor(uint16_t handle, const uint8_t *data, uint16_t len) {
40 return ble_device_base::GATT_ERR_NOT_CONNECTED;
41 }
42 int notify_characteristic(uint16_t handle, bool enable) { return ble_device_base::GATT_ERR_NOT_CONNECTED; }
43 int pair() { return ble_device_base::GATT_ERR_NOT_CONNECTED; }
44 int update_connection_params(uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t timeout) {
45 return ble_device_base::GATT_ERR_NOT_CONNECTED;
46 }
50};
51
52} // namespace esphome::bluetooth_connection
53#define ESPHOME_BLE_GATT_CONNECTION_TYPE bluetooth_connection::StubGattBackend
54#else
55#error "USE_BLE_GATT_CLIENT is set but this build has no GATT backend; add an alias arm here"
56#endif
57
59
60using BLEGattConnection = ESPHOME_BLE_GATT_CONNECTION_TYPE;
62 "The build's GATT backend is missing part of the BLEGattConnection surface (ble_gatt_client.h)");
63#undef ESPHOME_BLE_GATT_CONNECTION_TYPE
64
65} // namespace esphome::ble_device_base
66
67#endif // USE_BLE_GATT_CLIENT
uint8_t address
Definition bl0906.h:4
The event surface a backend delivers completions through - the one place with genuine runtime polymor...
void set_connection_type(ble_device_base::ConnectionType ct)
void set_listener(ble_device_base::GattClientListener *listener)
int update_connection_params(uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t timeout)
int write_descriptor(uint16_t handle, const uint8_t *data, uint16_t len)
int write_characteristic(uint16_t handle, const uint8_t *data, uint16_t len, bool response)
ESPHOME_BLE_GATT_CONNECTION_TYPE BLEGattConnection
const void size_t len
Definition hal.h:64
Borrowed view of the backend-owned service table.
spi_device_handle_t handle