forked from espressif/esp-idf
Merge branch 'bugfix/fix_ble_hid' into 'master'
fix(bt/bluedroid): Fixed BLE hid example bugs Closes BLERP-190 See merge request espressif/esp-idf!26613
This commit is contained in:
@@ -356,7 +356,7 @@ void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap,
|
|||||||
*p_resp_key = bte_appl_cfg.ble_resp_key;
|
*p_resp_key = bte_appl_cfg.ble_resp_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bte_appl_cfg.ble_max_key_size > 7 && bte_appl_cfg.ble_max_key_size <= 16) {
|
if (bte_appl_cfg.ble_max_key_size >= 7 && bte_appl_cfg.ble_max_key_size <= 16) {
|
||||||
*p_max_key_size = bte_appl_cfg.ble_max_key_size;
|
*p_max_key_size = bte_appl_cfg.ble_max_key_size;
|
||||||
}
|
}
|
||||||
#endif ///SMP_INCLUDED == TRUE
|
#endif ///SMP_INCLUDED == TRUE
|
||||||
|
@@ -282,7 +282,7 @@ static esp_err_t create_hid_db(esp_ble_hidd_dev_t *dev, int device_index)
|
|||||||
add_db_record(_last_db, HIDD_LE_IDX_HID_INFO_VAL, (uint8_t *)&s_hid_info_char_uuid, ESP_GATT_PERM_READ, 4, 4, (uint8_t *)hidInfo);
|
add_db_record(_last_db, HIDD_LE_IDX_HID_INFO_VAL, (uint8_t *)&s_hid_info_char_uuid, ESP_GATT_PERM_READ, 4, 4, (uint8_t *)hidInfo);
|
||||||
|
|
||||||
add_db_record(_last_db, HIDD_LE_IDX_HID_CTNL_PT_CHAR, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_write_nr);
|
add_db_record(_last_db, HIDD_LE_IDX_HID_CTNL_PT_CHAR, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_write_nr);
|
||||||
add_db_record(_last_db, HIDD_LE_IDX_HID_CTNL_PT_VAL, (uint8_t *)&s_hid_control_point_uuid, ESP_GATT_PERM_READ, 1, 0, NULL);
|
add_db_record(_last_db, HIDD_LE_IDX_HID_CTNL_PT_VAL, (uint8_t *)&s_hid_control_point_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, 1, 0, NULL);
|
||||||
|
|
||||||
add_db_record(_last_db, HIDD_LE_IDX_PROTO_MODE_CHAR, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_read_write_nr);
|
add_db_record(_last_db, HIDD_LE_IDX_PROTO_MODE_CHAR, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_read_write_nr);
|
||||||
add_db_record(_last_db, HIDD_LE_IDX_PROTO_MODE_VAL, (uint8_t *)&s_hid_proto_mode_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, 1, 1, (uint8_t *)&dev->protocol);
|
add_db_record(_last_db, HIDD_LE_IDX_PROTO_MODE_VAL, (uint8_t *)&s_hid_proto_mode_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, 1, 1, (uint8_t *)&dev->protocol);
|
||||||
@@ -301,7 +301,7 @@ static esp_err_t create_hid_db(esp_ble_hidd_dev_t *dev, int device_index)
|
|||||||
add_db_record(_last_db, index++, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_read_notify);
|
add_db_record(_last_db, index++, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_read_notify);
|
||||||
report->index = index;
|
report->index = index;
|
||||||
add_db_record(_last_db, index++, (uint8_t *)&s_hid_report_uuid, ESP_GATT_PERM_READ, report->value_len, 0, NULL);
|
add_db_record(_last_db, index++, (uint8_t *)&s_hid_report_uuid, ESP_GATT_PERM_READ, report->value_len, 0, NULL);
|
||||||
add_db_record(_last_db, index++, (uint8_t *)&s_character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, 2, 0, NULL);
|
add_db_record(_last_db, index++, (uint8_t *)&s_character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE_ENCRYPTED, 2, 0, NULL);
|
||||||
} else if (report->report_type == ESP_HID_REPORT_TYPE_OUTPUT) {
|
} else if (report->report_type == ESP_HID_REPORT_TYPE_OUTPUT) {
|
||||||
//Output Report
|
//Output Report
|
||||||
add_db_record(_last_db, index++, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_read_write_write_nr);
|
add_db_record(_last_db, index++, (uint8_t *)&s_character_declaration_uuid, ESP_GATT_PERM_READ, 1, 1, (uint8_t *)&s_char_prop_read_write_write_nr);
|
||||||
@@ -463,7 +463,7 @@ static void hid_event_handler(esp_ble_hidd_dev_t *dev, int device_index, esp_gat
|
|||||||
link_report_handles(&dev->devices[device_index], param->add_attr_tab.handles);
|
link_report_handles(&dev->devices[device_index], param->add_attr_tab.handles);
|
||||||
esp_ble_gatts_start_service(dev->devices[device_index].hid_svc.handle);
|
esp_ble_gatts_start_service(dev->devices[device_index].hid_svc.handle);
|
||||||
if ((device_index + 1) < dev->devices_len) {
|
if ((device_index + 1) < dev->devices_len) {
|
||||||
create_hid_db(dev, device_index + 1);//add next device
|
create_hid_db(dev, device_index + 1);//add next device if support
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@@ -42,27 +42,6 @@ typedef struct
|
|||||||
|
|
||||||
#if CONFIG_BT_BLE_ENABLED
|
#if CONFIG_BT_BLE_ENABLED
|
||||||
static local_param_t s_ble_hid_param = {0};
|
static local_param_t s_ble_hid_param = {0};
|
||||||
const unsigned char hidapiReportMap[] = { //8 bytes input, 8 bytes feature
|
|
||||||
0x06, 0x00, 0xFF, // Usage Page (Vendor Defined 0xFF00)
|
|
||||||
0x0A, 0x00, 0x01, // Usage (0x0100)
|
|
||||||
0xA1, 0x01, // Collection (Application)
|
|
||||||
0x85, 0x01, // Report ID (1)
|
|
||||||
0x15, 0x00, // Logical Minimum (0)
|
|
||||||
0x26, 0xFF, 0x00, // Logical Maximum (255)
|
|
||||||
0x75, 0x08, // Report Size (8)
|
|
||||||
0x95, 0x08, // Report Count (8)
|
|
||||||
0x09, 0x01, // Usage (0x01)
|
|
||||||
0x82, 0x02, 0x01, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Buffered Bytes)
|
|
||||||
0x95, 0x08, // Report Count (8)
|
|
||||||
0x09, 0x02, // Usage (0x02)
|
|
||||||
0xB2, 0x02, 0x01, // Feature (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile,Buffered Bytes)
|
|
||||||
0x95, 0x08, // Report Count (8)
|
|
||||||
0x09, 0x03, // Usage (0x03)
|
|
||||||
0x91, 0x02, // Output (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position,Non-volatile)
|
|
||||||
0xC0, // End Collection
|
|
||||||
|
|
||||||
// 38 bytes
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned char mediaReportMap[] = {
|
const unsigned char mediaReportMap[] = {
|
||||||
0x05, 0x0C, // Usage Page (Consumer)
|
0x05, 0x0C, // Usage Page (Consumer)
|
||||||
@@ -125,10 +104,6 @@ const unsigned char mediaReportMap[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static esp_hid_raw_report_map_t ble_report_maps[] = {
|
static esp_hid_raw_report_map_t ble_report_maps[] = {
|
||||||
{
|
|
||||||
.data = hidapiReportMap,
|
|
||||||
.len = sizeof(hidapiReportMap)
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
.data = mediaReportMap,
|
.data = mediaReportMap,
|
||||||
.len = sizeof(mediaReportMap)
|
.len = sizeof(mediaReportMap)
|
||||||
@@ -143,7 +118,7 @@ static esp_hid_device_config_t ble_hid_config = {
|
|||||||
.manufacturer_name = "Espressif",
|
.manufacturer_name = "Espressif",
|
||||||
.serial_number = "1234567890",
|
.serial_number = "1234567890",
|
||||||
.report_maps = ble_report_maps,
|
.report_maps = ble_report_maps,
|
||||||
.report_maps_len = 2
|
.report_maps_len = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HID_CC_RPT_MUTE 1
|
#define HID_CC_RPT_MUTE 1
|
||||||
@@ -293,7 +268,7 @@ void esp_hidd_send_consumer_value(uint8_t key_cmd, bool key_pressed)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
esp_hidd_dev_input_set(s_ble_hid_param.hid_dev, 1, HID_RPT_ID_CC_IN, buffer, HID_CC_IN_RPT_LEN);
|
esp_hidd_dev_input_set(s_ble_hid_param.hid_dev, 0, HID_RPT_ID_CC_IN, buffer, HID_CC_IN_RPT_LEN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -318,6 +293,10 @@ void ble_hid_demo_task(void *pvParameters)
|
|||||||
|
|
||||||
void ble_hid_task_start_up(void)
|
void ble_hid_task_start_up(void)
|
||||||
{
|
{
|
||||||
|
if (s_ble_hid_param.task_hdl) {
|
||||||
|
// Task already exists
|
||||||
|
return;
|
||||||
|
}
|
||||||
xTaskCreate(ble_hid_demo_task, "ble_hid_demo_task", 2 * 1024, NULL, configMAX_PRIORITIES - 3,
|
xTaskCreate(ble_hid_demo_task, "ble_hid_demo_task", 2 * 1024, NULL, configMAX_PRIORITIES - 3,
|
||||||
&s_ble_hid_param.task_hdl);
|
&s_ble_hid_param.task_hdl);
|
||||||
}
|
}
|
||||||
@@ -344,7 +323,6 @@ static void ble_hidd_event_callback(void *handler_args, esp_event_base_t base, i
|
|||||||
}
|
}
|
||||||
case ESP_HIDD_CONNECT_EVENT: {
|
case ESP_HIDD_CONNECT_EVENT: {
|
||||||
ESP_LOGI(TAG, "CONNECT");
|
ESP_LOGI(TAG, "CONNECT");
|
||||||
ble_hid_task_start_up();//todo: this should be on auth_complete (in GAP)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_HIDD_PROTOCOL_MODE_EVENT: {
|
case ESP_HIDD_PROTOCOL_MODE_EVENT: {
|
||||||
@@ -353,6 +331,14 @@ static void ble_hidd_event_callback(void *handler_args, esp_event_base_t base, i
|
|||||||
}
|
}
|
||||||
case ESP_HIDD_CONTROL_EVENT: {
|
case ESP_HIDD_CONTROL_EVENT: {
|
||||||
ESP_LOGI(TAG, "CONTROL[%u]: %sSUSPEND", param->control.map_index, param->control.control ? "EXIT_" : "");
|
ESP_LOGI(TAG, "CONTROL[%u]: %sSUSPEND", param->control.map_index, param->control.control ? "EXIT_" : "");
|
||||||
|
if (param->control.control)
|
||||||
|
{
|
||||||
|
// exit suspend
|
||||||
|
ble_hid_task_start_up();
|
||||||
|
} else {
|
||||||
|
// suspend
|
||||||
|
ble_hid_task_shut_down();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ESP_HIDD_OUTPUT_EVENT: {
|
case ESP_HIDD_OUTPUT_EVENT: {
|
||||||
|
@@ -486,7 +486,7 @@ static esp_err_t start_bt_scan(uint32_t seconds)
|
|||||||
/*
|
/*
|
||||||
* BLE GAP
|
* BLE GAP
|
||||||
* */
|
* */
|
||||||
|
extern void ble_hid_task_start_up(void);
|
||||||
static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
|
static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param_t *param)
|
||||||
{
|
{
|
||||||
switch (event) {
|
switch (event) {
|
||||||
@@ -535,10 +535,12 @@ static void ble_gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_p
|
|||||||
* */
|
* */
|
||||||
case ESP_GAP_BLE_AUTH_CMPL_EVT:
|
case ESP_GAP_BLE_AUTH_CMPL_EVT:
|
||||||
if (!param->ble_security.auth_cmpl.success) {
|
if (!param->ble_security.auth_cmpl.success) {
|
||||||
|
// if AUTH ERROR,hid maybe don't work.
|
||||||
ESP_LOGE(TAG, "BLE GAP AUTH ERROR: 0x%x", param->ble_security.auth_cmpl.fail_reason);
|
ESP_LOGE(TAG, "BLE GAP AUTH ERROR: 0x%x", param->ble_security.auth_cmpl.fail_reason);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "BLE GAP AUTH SUCCESS");
|
ESP_LOGI(TAG, "BLE GAP AUTH SUCCESS");
|
||||||
}
|
}
|
||||||
|
ble_hid_task_start_up();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESP_GAP_BLE_KEY_EVT: //shows the ble key info share with peer device to the user.
|
case ESP_GAP_BLE_KEY_EVT: //shows the ble key info share with peer device to the user.
|
||||||
|
Reference in New Issue
Block a user