Skip to content

Commit cc9902d

Browse files
committed
feat(esp_hid): Enahcne esp_hid to support multiple BLE connections. Add interfaces to allow users to select which connection to use or boradcast events to all connections.
1 parent 80ed209 commit cc9902d

File tree

4 files changed

+486
-44
lines changed

4 files changed

+486
-44
lines changed

components/esp_hid/include/esp_hidd.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,45 @@ esp_err_t esp_hidd_dev_event_handler_register(esp_hidd_dev_t *dev, esp_event_han
221221
*/
222222
esp_err_t esp_hidd_dev_event_handler_unregister(esp_hidd_dev_t *dev, esp_event_handler_t callback, esp_hidd_event_t event);
223223

224+
/**
225+
* @brief Connection information structure for querying connections
226+
*/
227+
typedef struct {
228+
uint16_t conn_id; /*!< Connection ID */
229+
uint8_t remote_bda[6]; /*!< Remote device address */
230+
} esp_hidd_conn_info_t;
231+
232+
/**
233+
* @brief Set the active connection for unicast mode
234+
* @param dev : pointer to the device
235+
* @param conn_id : connection ID to set as active (sends to this connection only)
236+
*
237+
* @return: ESP_OK on success, ESP_ERR_NOT_FOUND if connection not found
238+
* @note: This disables broadcast mode automatically
239+
*/
240+
esp_err_t esp_hidd_dev_set_active_conn(esp_hidd_dev_t *dev, uint16_t conn_id);
241+
242+
/**
243+
* @brief Query all active connections
244+
* @param dev : pointer to the device
245+
* @param conn_list : pointer to array to store connection info
246+
* @param max_count : maximum number of connections that can be stored
247+
* @param[out] count : actual number of connections returned
248+
*
249+
* @return: ESP_OK on success
250+
*/
251+
esp_err_t esp_hidd_dev_get_connections(esp_hidd_dev_t *dev, esp_hidd_conn_info_t *conn_list, size_t max_count, size_t *count);
252+
253+
/**
254+
* @brief Enable or disable broadcast mode
255+
* @param dev : pointer to the device
256+
* @param enable : true to broadcast to all connections, false for unicast to active connection
257+
*
258+
* @return: ESP_OK on success
259+
* @note: In broadcast mode, all connected devices receive the events
260+
*/
261+
esp_err_t esp_hidd_dev_set_broadcast_mode(esp_hidd_dev_t *dev, bool enable);
262+
224263
#ifdef __cplusplus
225264
}
226265
#endif

components/esp_hid/private/ble_hidd.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ extern "C" {
1818

1919
esp_err_t esp_ble_hidd_dev_init(esp_hidd_dev_t *dev, const esp_hid_device_config_t *config, esp_event_handler_t callback);
2020

21+
// Multi-connection management functions
22+
esp_err_t esp_ble_hidd_dev_set_active_conn(void *devp, uint16_t conn_id);
23+
esp_err_t esp_ble_hidd_dev_get_connections(void *devp, esp_hidd_conn_info_t *conn_list, size_t max_count, size_t *count);
24+
esp_err_t esp_ble_hidd_dev_set_broadcast_mode(void *devp, bool enable);
25+
2126
#endif /* CONFIG_GATTS_ENABLE */
2227

2328
#ifdef __cplusplus

0 commit comments

Comments
 (0)