From 4459865257577b9557da005cb5cf6f6c551f0dcf Mon Sep 17 00:00:00 2001 From: liqigan Date: Fri, 30 Aug 2024 14:59:02 +0800 Subject: [PATCH 1/2] feat(bt/bluedroid): Added definition of minor class of COD for peripheral major class Closes https://github.com/espressif/esp-idf/issues/13622 --- .../api/include/api/esp_gap_bt_api.h | 22 +++++++++++++++++++ .../bt_hid_mouse_device/main/main.c | 5 +++-- .../esp_hid_device/main/esp_hid_device_main.c | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h index 7509e0210a..1b2fc71829 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_bt_api.h @@ -206,6 +206,28 @@ typedef enum { ESP_BT_COD_MAJOR_DEV_UNCATEGORIZED = 31, /*!< Uncategorized: device not specified */ } esp_bt_cod_major_dev_t; +/// Minor device class field of Class of Device for Peripheral Major Class +typedef enum { + ESP_BT_COD_MINOR_PERIPHERAL_KEYBOARD = 0x10, /*!< Keyboard */ + ESP_BT_COD_MINOR_PERIPHERAL_POINTING = 0x20, /*!< Pointing */ + ESP_BT_COD_MINOR_PERIPHERAL_COMBO = 0x30, /*!< Combo + ESP_BT_COD_MINOR_PERIPHERAL_KEYBOARD, ESP_BT_COD_MINOR_PERIPHERAL_POINTING + and ESP_BT_COD_MINOR_PERIPHERAL_COMBO can be OR'd with one of the + following values to identify a multifunctional device. e.g. + ESP_BT_COD_MINOR_PERIPHERAL_KEYBOARD | ESP_BT_COD_MINOR_PERIPHERAL_GAMEPAD + ESP_BT_COD_MINOR_PERIPHERAL_POINTING | ESP_BT_COD_MINOR_PERIPHERAL_SENSING_DEVICE + */ + ESP_BT_COD_MINOR_PERIPHERAL_JOYSTICK = 0x01, /*!< Joystick */ + ESP_BT_COD_MINOR_PERIPHERAL_GAMEPAD = 0x02, /*!< Gamepad */ + ESP_BT_COD_MINOR_PERIPHERAL_REMOTE_CONTROL = 0x03, /*!< Remote Control */ + ESP_BT_COD_MINOR_PERIPHERAL_SENSING_DEVICE = 0x04, /*!< Sensing Device */ + ESP_BT_COD_MINOR_PERIPHERAL_DIGITIZING_TABLET = 0x05, /*!< Digitizing Tablet */ + ESP_BT_COD_MINOR_PERIPHERAL_CARD_READER = 0x06, /*!< Card Reader */ + ESP_BT_COD_MINOR_PERIPHERAL_DIGITAL_PAN = 0x07, /*!< Digital Pan */ + ESP_BT_COD_MINOR_PERIPHERAL_HAND_SCANNER = 0x08, /*!< Hand Scanner */ + ESP_BT_COD_MINOR_PERIPHERAL_HAND_GESTURAL_INPUT = 0x09, /*!< Hand Gestural Input */ +} esp_bt_cod_minor_peripheral_t; + /// Bits of major device class field #define ESP_BT_COD_MAJOR_DEV_BIT_MASK (0x1f00) /*!< Major device bit mask */ #define ESP_BT_COD_MAJOR_DEV_BIT_OFFSET (8) /*!< Major device bit offset */ diff --git a/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c index 5ca12dea97..6cafc1c0ba 100644 --- a/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c +++ b/examples/bluetooth/bluedroid/classic_bt/bt_hid_mouse_device/main/main.c @@ -439,8 +439,9 @@ void app_main(void) esp_bt_gap_set_device_name(local_device_name); ESP_LOGI(TAG, "setting cod major, peripheral"); - esp_bt_cod_t cod; + esp_bt_cod_t cod = {0}; cod.major = ESP_BT_COD_MAJOR_DEV_PERIPHERAL; + cod.minor = ESP_BT_COD_MINOR_PERIPHERAL_POINTING; esp_bt_gap_set_cod(cod, ESP_BT_SET_COD_MAJOR_MINOR); vTaskDelay(2000 / portTICK_PERIOD_MS); @@ -451,7 +452,7 @@ void app_main(void) s_local_param.app_param.name = "Mouse"; s_local_param.app_param.description = "Mouse Example"; s_local_param.app_param.provider = "ESP32"; - s_local_param.app_param.subclass = ESP_HID_CLASS_MIC; + s_local_param.app_param.subclass = ESP_HID_CLASS_MIC; // keep same with minor class of COD s_local_param.app_param.desc_list = hid_mouse_descriptor; s_local_param.app_param.desc_list_len = hid_mouse_descriptor_len; diff --git a/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c b/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c index d3574bb5e5..b44e2e259b 100644 --- a/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c +++ b/examples/bluetooth/esp_hid_device/main/esp_hid_device_main.c @@ -903,8 +903,9 @@ void app_main(void) ESP_LOGI(TAG, "setting device name"); esp_bt_gap_set_device_name(bt_hid_config.device_name); ESP_LOGI(TAG, "setting cod major, peripheral"); - esp_bt_cod_t cod; + esp_bt_cod_t cod = {0}; cod.major = ESP_BT_COD_MAJOR_DEV_PERIPHERAL; + cod.minor = ESP_BT_COD_MINOR_PERIPHERAL_POINTING; esp_bt_gap_set_cod(cod, ESP_BT_SET_COD_MAJOR_MINOR); vTaskDelay(1000 / portTICK_PERIOD_MS); ESP_LOGI(TAG, "setting bt device"); From 7f297af892181e6d81fd068756543a99ab3b34ff Mon Sep 17 00:00:00 2001 From: liqigan Date: Fri, 30 Aug 2024 15:01:25 +0800 Subject: [PATCH 2/2] fix(esp_hid): Fixed protocol mode mapping bug Closes https://github.com/espressif/esp-idf/issues/14232 --- components/esp_hid/src/bt_hidd.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/components/esp_hid/src/bt_hidd.c b/components/esp_hid/src/bt_hidd.c index 08e7209a36..85527518e0 100644 --- a/components/esp_hid/src/bt_hidd.c +++ b/components/esp_hid/src/bt_hidd.c @@ -716,11 +716,9 @@ void bt_hidd_cb(esp_hidd_cb_event_t event, esp_hidd_cb_param_t *param) } case ESP_HIDD_SET_PROTOCOL_EVT: { if (param->set_protocol.protocol_mode != ESP_HIDD_UNSUPPORTED_MODE) { - if (s_hidd_param.dev->protocol_mode == param->set_protocol.protocol_mode) { - break; - } osi_mutex_lock(&s_hidd_param.mutex, OSI_MUTEX_MAX_TIMEOUT); - s_hidd_param.dev->protocol_mode = param->set_protocol.protocol_mode; + s_hidd_param.dev->protocol_mode = + param->set_protocol.protocol_mode ? ESP_HID_PROTOCOL_MODE_BOOT : ESP_HID_PROTOCOL_MODE_REPORT; osi_mutex_unlock(&s_hidd_param.mutex); cb_param.protocol_mode.dev = s_hidd_param.dev->dev; cb_param.protocol_mode.protocol_mode = s_hidd_param.dev->protocol_mode;