From b7a99614a10ce762d95580a6289e53c3697d432e Mon Sep 17 00:00:00 2001 From: jincheng Date: Fri, 24 Dec 2021 15:21:48 +0800 Subject: [PATCH 1/5] fix on esp_hidh report map length checking function Closes https://github.com/espressif/esp-idf/issues/7586 --- components/esp_hid/src/esp_hidh.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_hid/src/esp_hidh.c b/components/esp_hid/src/esp_hidh.c index 484092c885f..49ff9c9cf31 100644 --- a/components/esp_hid/src/esp_hidh.c +++ b/components/esp_hid/src/esp_hidh.c @@ -639,7 +639,7 @@ esp_hidh_dev_report_t *esp_hidh_dev_get_input_report_by_proto_and_data(esp_hidh_ } r = dev->reports; while (r) { - if (r->value_len == len + 1 && r->report_id == *data && (r->report_type & 1) && + if (r->value_len == len - 1 && r->report_id == *data && (r->report_type & 1) && r->protocol_mode == protocol_mode) { *has_report_id = true; break; From ba5f19e5b1e19c4dd20a7186f24df2ce1404a026 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Sat, 30 May 2020 20:54:26 +0200 Subject: [PATCH 2/5] esp_hid: fix output report char declaration Current issue: output reports sent by Windows not received. The report characteristic declaration should also support write without response as specified by HIDS profile: See https://www.bluetooth.com/specifications/GATT/ (page 14) --- components/esp_hid/src/ble_hidd.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index 85b49bcf228..958b89d554c 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -57,6 +57,7 @@ static const uint8_t s_char_prop_write_nr = ESP_GATT_CHAR_PROP_BIT_WRITE_NR; static const uint8_t s_char_prop_read_notify = ESP_GATT_CHAR_PROP_BIT_READ | ESP_GATT_CHAR_PROP_BIT_NOTIFY; static const uint8_t s_char_prop_read_write = ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_READ; static const uint8_t s_char_prop_read_write_nr = ESP_GATT_CHAR_PROP_BIT_WRITE_NR | ESP_GATT_CHAR_PROP_BIT_READ; +static const uint8_t s_char_prop_read_write_write_nr = ESP_GATT_CHAR_PROP_BIT_WRITE | ESP_GATT_CHAR_PROP_BIT_WRITE_NR | ESP_GATT_CHAR_PROP_BIT_READ; //static const uint8_t s_char_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_WRITE|ESP_GATT_CHAR_PROP_BIT_NOTIFY; // Service UUIDs @@ -309,8 +310,15 @@ static esp_err_t create_hid_db(esp_ble_hidd_dev_t *dev, int device_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_character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, 2, 0, NULL); - } else { - //Output or Feature Report + } + else if (report->report_type == ESP_HID_REPORT_TYPE_OUTPUT) { + //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); + report->index = index; + add_db_record(_last_db, index++, (uint8_t *)&s_hid_report_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, report->value_len, 0, NULL); + } + else { + //Feature 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); report->index = index; add_db_record(_last_db, index++, (uint8_t *)&s_hid_report_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, report->value_len, 0, NULL); @@ -327,7 +335,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_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, 2, 0, NULL); } else { //Boot Keyboard Output - 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); + 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); report->index = index; add_db_record(_last_db, index++, (uint8_t *)&s_hid_boot_kb_output_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, HIDD_LE_BOOT_REPORT_MAX_LEN, 0, NULL); } From 8d5a823a411c253b8fe4f688e3b16652c3cad927 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Mon, 1 Jun 2020 12:22:38 +0200 Subject: [PATCH 3/5] minor styling changes --- components/esp_hid/src/ble_hidd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index 958b89d554c..1fbfc815a0b 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -310,14 +310,12 @@ static esp_err_t create_hid_db(esp_ble_hidd_dev_t *dev, int device_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_character_client_config_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, 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 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); report->index = index; add_db_record(_last_db, index++, (uint8_t *)&s_hid_report_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, report->value_len, 0, NULL); - } - else { + } else { //Feature 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); report->index = index; From 08acf7979bce9cecf3576cc1cfc45b8d8f486fa2 Mon Sep 17 00:00:00 2001 From: Robin Krens Date: Mon, 1 Jun 2020 12:37:02 +0200 Subject: [PATCH 4/5] spacing styling correction --- components/esp_hid/src/ble_hidd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index 1fbfc815a0b..1410e102898 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -315,7 +315,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_write_write_nr); report->index = index; add_db_record(_last_db, index++, (uint8_t *)&s_hid_report_uuid, ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE, report->value_len, 0, NULL); - } else { + } else { //Feature 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); report->index = index; From 00a23ec544c00c0cbe58e460cf4d6899bb2d699d Mon Sep 17 00:00:00 2001 From: Murray Fordyce Date: Sun, 26 Jan 2020 10:28:45 -0600 Subject: [PATCH 5/5] Fixed left right key confusion in comments. "Left" and "Right" were swapped in some comments. --- components/esp_hid/src/ble_hidd.c | 18 ++++--------- components/esp_hid/src/esp_hidh.c | 26 +++++++------------ .../ble/ble_hid_device_demo/main/hid_dev.h | 8 +++--- tools/ci/check_copyright_ignore.txt | 2 -- 4 files changed, 18 insertions(+), 36 deletions(-) diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index 1410e102898..de2211c77fd 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -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-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include diff --git a/components/esp_hid/src/esp_hidh.c b/components/esp_hid/src/esp_hidh.c index 49ff9c9cf31..beeca38668c 100644 --- a/components/esp_hid/src/esp_hidh.c +++ b/components/esp_hid/src/esp_hidh.c @@ -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-2022 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include "sys/queue.h" #include "esp_hidh_private.h" @@ -591,7 +583,7 @@ esp_hidh_dev_report_t *esp_hidh_dev_get_input_report_by_id_and_proto(esp_hidh_de { esp_hidh_dev_report_t *r = dev->reports; while (r) { - if (r->report_id == report_id && (r->report_type & 1) && r->protocol_mode == protocol_mode) { + if (r->report_id == report_id && (r->report_type & ESP_HID_REPORT_TYPE_INPUT) && r->protocol_mode == protocol_mode) { return r; } r = r->next; @@ -603,7 +595,7 @@ esp_hidh_dev_report_t *esp_hidh_dev_get_input_report_by_len_and_proto(esp_hidh_d { esp_hidh_dev_report_t *r = dev->reports; while (r) { - if (r->value_len == len && (r->report_type & 1) && r->protocol_mode == protocol_mode) { + if (r->value_len == len && (r->report_type & ESP_HID_REPORT_TYPE_INPUT) && r->protocol_mode == protocol_mode) { return r; } r = r->next; @@ -623,7 +615,7 @@ esp_hidh_dev_report_t *esp_hidh_dev_get_input_report_by_proto_and_data(esp_hidh_ *has_report_id = false; // first, assume data not include report id while (r) { - if (r->value_len == len && r->report_id == 0 && (r->report_type & 1) && + if (r->value_len == len && r->report_id == 0 && (r->report_type & ESP_HID_REPORT_TYPE_INPUT) && r->protocol_mode == protocol_mode) { *has_report_id = false; break; @@ -639,7 +631,7 @@ esp_hidh_dev_report_t *esp_hidh_dev_get_input_report_by_proto_and_data(esp_hidh_ } r = dev->reports; while (r) { - if (r->value_len == len - 1 && r->report_id == *data && (r->report_type & 1) && + if (r->value_len == len - 1 && r->report_id == *data && (r->report_type & ESP_HID_REPORT_TYPE_INPUT) && r->protocol_mode == protocol_mode) { *has_report_id = true; break; diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_dev.h b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_dev.h index 7922fb49732..8208c48b088 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_dev.h +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_dev.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -124,9 +124,9 @@ extern "C" { #define HID_KEY_LEFT_SHIFT 225 // Keyboard LeftShift #define HID_KEY_LEFT_ALT 226 // Keyboard LeftAlt #define HID_KEY_LEFT_GUI 227 // Keyboard LeftGUI -#define HID_KEY_RIGHT_CTRL 228 // Keyboard LeftContorl -#define HID_KEY_RIGHT_SHIFT 229 // Keyboard LeftShift -#define HID_KEY_RIGHT_ALT 230 // Keyboard LeftAlt +#define HID_KEY_RIGHT_CTRL 228 // Keyboard RightContorl +#define HID_KEY_RIGHT_SHIFT 229 // Keyboard RightShift +#define HID_KEY_RIGHT_ALT 230 // Keyboard RightAlt #define HID_KEY_RIGHT_GUI 231 // Keyboard RightGUI typedef uint8_t keyboard_cmd_t; diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 0c530d842ea..5d5ab251391 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -507,13 +507,11 @@ components/esp_hid/private/bt_hidd.h components/esp_hid/private/bt_hidh.h components/esp_hid/private/esp_hidd_private.h components/esp_hid/private/esp_hidh_private.h -components/esp_hid/src/ble_hidd.c components/esp_hid/src/ble_hidh.c components/esp_hid/src/bt_hidd.c components/esp_hid/src/bt_hidh.c components/esp_hid/src/esp_hid_common.c components/esp_hid/src/esp_hidd.c -components/esp_hid/src/esp_hidh.c components/esp_hid/test/hid_descriptor.h components/esp_hid/test/test_esp_hid.c components/esp_https_ota/include/esp_https_ota.h