Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 62 additions & 13 deletions components/esp_hid/include/esp_hidd.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/*
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

Expand Down Expand Up @@ -221,6 +213,63 @@ esp_err_t esp_hidd_dev_event_handler_register(esp_hidd_dev_t *dev, esp_event_han
*/
esp_err_t esp_hidd_dev_event_handler_unregister(esp_hidd_dev_t *dev, esp_event_handler_t callback, esp_hidd_event_t event);

/**
* @brief Connection information structure for querying connections
*/
typedef struct {
uint16_t conn_id; /*!< Connection ID */
uint8_t remote_bda[6]; /*!< Remote device address */
} esp_hidd_conn_info_t;

/**
* @brief Set the active connection for unicast mode
* @param dev : pointer to the device
* @param conn_id : connection ID to set as active (sends to this connection only)
*
* @return: ESP_OK on success, ESP_ERR_NOT_FOUND if connection not found
* @note: This disables broadcast mode automatically
*/
esp_err_t esp_hidd_dev_set_active_conn(esp_hidd_dev_t *dev, uint16_t conn_id);

/**
* @brief Query all active connections
* @param dev : pointer to the device
* @param conn_list : pointer to array to store connection info
* @param max_count : maximum number of connections that can be stored
* @param[out] count : actual number of connections returned
*
* @return: ESP_OK on success
*/
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);

/**
* @brief Enable or disable broadcast mode
* @param dev : pointer to the device
* @param enable : true to broadcast to all connections, false for unicast to active connection
*
* @return: ESP_OK on success
* @note: In broadcast mode, all connected devices receive the events
*/
esp_err_t esp_hidd_dev_set_broadcast_mode(esp_hidd_dev_t *dev, bool enable);

/**
* @brief Get the currently active connection (unicast) when not in broadcast mode
* @param dev : pointer to the device
* @param[out] conn_id : connection ID of the active connection
*
* @return: ESP_OK on success, ESP_ERR_NOT_FOUND if no active connection, ESP_ERR_NOT_SUPPORTED if transport doesn't support multi-connection
*/
esp_err_t esp_hidd_dev_get_active_conn(esp_hidd_dev_t *dev, uint16_t *conn_id);

/**
* @brief Query whether the device is in broadcast mode
* @param dev : pointer to the device
* @param[out] enabled : true if broadcast mode is enabled, false otherwise
*
* @return: ESP_OK on success, ESP_ERR_NOT_SUPPORTED if transport doesn't support multi-connection
*/
esp_err_t esp_hidd_dev_is_broadcast_mode(esp_hidd_dev_t *dev, bool *enabled);

#ifdef __cplusplus
}
#endif
9 changes: 8 additions & 1 deletion components/esp_hid/private/ble_hidd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -18,6 +18,13 @@ extern "C" {

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);

// Multi-connection management functions
esp_err_t esp_ble_hidd_dev_set_active_conn(void *devp, uint16_t conn_id);
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);
esp_err_t esp_ble_hidd_dev_set_broadcast_mode(void *devp, bool enable);
esp_err_t esp_ble_hidd_dev_get_active_conn(void *devp, uint16_t *conn_id);
esp_err_t esp_ble_hidd_dev_is_broadcast_mode(void *devp, bool *enabled);

#endif /* CONFIG_GATTS_ENABLE */

#ifdef __cplusplus
Expand Down
Loading