fix(bt/bluedroid): Optimize compatibility with Android 10 and later devices

pull/10827/merge
zhanghaipeng 2023-10-23 15:47:13 +08:00
rodzic 69f482f911
commit 8cd82305d1
2 zmienionych plików z 25 dodań i 42 usunięć

Wyświetl plik

@ -485,7 +485,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);
esp_ble_gatts_start_service(dev->devices[device_index].hid_svc.handle);
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;
}

Wyświetl plik

@ -28,28 +28,17 @@
#include "esp_hid_gap.h"
static const char *TAG = "HID_DEV_DEMO";
#define HIDD_BLE_MODE 0x01
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
typedef struct
{
TaskHandle_t task_hdl;
esp_hidd_dev_t *hid_dev;
uint8_t protocol_mode;
uint8_t *buffer;
} local_param_t;
// 38 bytes
};
static local_param_t s_ble_hid_param = {0};
const unsigned char mediaReportMap[] = {
0x05, 0x0C, // Usage Page (Consumer)
@ -111,29 +100,24 @@ const unsigned char mediaReportMap[] = {
0xC0, // End Collection
};
static esp_hid_raw_report_map_t report_maps[] = {
{
.data = hidapiReportMap,
.len = sizeof(hidapiReportMap)
},
static esp_hid_raw_report_map_t ble_report_maps[] = {
{
.data = mediaReportMap,
.len = sizeof(mediaReportMap)
}
};
static esp_hid_device_config_t hid_config = {
static esp_hid_device_config_t ble_hid_config = {
.vendor_id = 0x16C0,
.product_id = 0x05DF,
.version = 0x0100,
.device_name = "ESP BLE HID2",
.manufacturer_name = "Espressif",
.serial_number = "1234567890",
.report_maps = report_maps,
.report_maps_len = 2
.report_maps = ble_report_maps,
.report_maps_len = 1
};
static esp_hidd_dev_t *hid_dev = NULL;
#define HID_CC_RPT_MUTE 1
#define HID_CC_RPT_POWER 2
@ -282,7 +266,7 @@ void esp_hidd_send_consumer_value(uint8_t key_cmd, bool key_pressed)
break;
}
}
esp_hidd_dev_input_set(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;
}
@ -327,6 +311,7 @@ static void ble_hidd_event_callback(void *handler_args, esp_event_base_t base, i
{
esp_hidd_event_t event = (esp_hidd_event_t)id;
esp_hidd_event_data_t *param = (esp_hidd_event_data_t *)event_data;
static const char *TAG = "HID_DEV_BLE";
switch (event) {
case ESP_HIDD_START_EVENT: {
@ -408,24 +393,22 @@ void app_main(void)
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
#if CONFIG_BT_CLASSIC_ENABLED
ret = esp_hid_gap_init(ESP_BT_MODE_BTDM);
#else
ret = esp_hid_gap_init(ESP_BT_MODE_BLE);
#endif
#if CONFIG_BT_BLE_ENABLED
// only BLE mode is supported in this version.
ESP_LOGI(TAG, "setting hid gap, mode:%d", HIDD_BLE_MODE);
ret = esp_hid_gap_init(HIDD_BLE_MODE);
ESP_ERROR_CHECK( ret );
ret = esp_hid_ble_gap_adv_init(ESP_HID_APPEARANCE_GENERIC, hid_config.device_name);
ret = esp_hid_ble_gap_adv_init(ESP_HID_APPEARANCE_GENERIC, ble_hid_config.device_name);
ESP_ERROR_CHECK( ret );
if ((ret = esp_ble_gatts_register_callback(esp_hidd_gatts_event_handler)) != ESP_OK) {
ESP_LOGE(TAG, "GATTS register callback failed: %d", ret);
return;
}
ESP_ERROR_CHECK( esp_hidd_dev_init(&hid_config, ESP_HID_TRANSPORT_BLE, hidd_event_callback, &hid_dev) );
xTaskCreate(&hid_demo_task, "hid_task", 2048, NULL, 2, NULL);
ESP_LOGI(TAG, "setting ble device");
ESP_ERROR_CHECK(
esp_hidd_dev_init(&ble_hid_config, ESP_HID_TRANSPORT_BLE, ble_hidd_event_callback, &s_ble_hid_param.hid_dev));
#endif
}