From 24b0f8d91d4e75b4e16470129152e1f5653485ae Mon Sep 17 00:00:00 2001 From: Benjamin Aigner Date: Mon, 20 Jul 2020 14:37:07 +0200 Subject: [PATCH] Fixed the Keyboard Output Report for receiving Caps&Num Lock updates (LED report), closing #38 : - Added report ID for LEDs - Added callback event type for LED - Fixed the characteristic & added write no response (according to https://github.com/espressif/esp-idf/pull/5369 THX @robinkrens for the hint!) --- main/ble_hidd_demo_main.c | 3 +++ main/esp_hidd_prf_api.h | 1 + main/hid_device_le_prf.c | 24 +++++++++++++++++------- main/hidd_le_prf_int.h | 2 +- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/main/ble_hidd_demo_main.c b/main/ble_hidd_demo_main.c index 4bfda25..4e9eb04 100644 --- a/main/ble_hidd_demo_main.c +++ b/main/ble_hidd_demo_main.c @@ -263,6 +263,9 @@ static void hidd_event_callback(esp_hidd_cb_event_t event, esp_hidd_cb_param_t * ESP_LOGI(HID_DEMO_TAG, "%s, ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT", __func__); ESP_LOG_BUFFER_HEX(HID_DEMO_TAG, param->vendor_write.data, param->vendor_write.length); } + case ESP_HIDD_EVENT_BLE_LED_OUT_WRITE_EVT: { + ESP_LOGI(HID_DEMO_TAG, "%s, ESP_HIDD_EVENT_BLE_LED_OUT_WRITE_EVT, keyboard LED value: %d", __func__, param->vendor_write.data[0]); + } default: break; } diff --git a/main/esp_hidd_prf_api.h b/main/esp_hidd_prf_api.h index 34bb956..76ad24f 100644 --- a/main/esp_hidd_prf_api.h +++ b/main/esp_hidd_prf_api.h @@ -31,6 +31,7 @@ typedef enum { ESP_HIDD_EVENT_BLE_CONNECT, ESP_HIDD_EVENT_BLE_DISCONNECT, ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT, + ESP_HIDD_EVENT_BLE_LED_OUT_WRITE_EVT, } esp_hidd_cb_event_t; /// HID config status diff --git a/main/hid_device_le_prf.c b/main/hid_device_le_prf.c index 9a5208d..4698186 100644 --- a/main/hid_device_le_prf.c +++ b/main/hid_device_le_prf.c @@ -285,13 +285,14 @@ static const uint16_t hid_kb_output_uuid = ESP_GATT_UUID_HID_BT_KB_OUTPUT; static const uint16_t hid_mouse_input_uuid = ESP_GATT_UUID_HID_BT_MOUSE_INPUT; static const uint16_t hid_repot_map_ext_desc_uuid = ESP_GATT_UUID_EXT_RPT_REF_DESCR; static const uint16_t hid_report_ref_descr_uuid = ESP_GATT_UUID_RPT_REF_DESCR; -///the propoty definition +///the property definition static const uint8_t char_prop_notify = ESP_GATT_CHAR_PROP_BIT_NOTIFY; static const uint8_t char_prop_read = ESP_GATT_CHAR_PROP_BIT_READ; static const uint8_t char_prop_write_nr = ESP_GATT_CHAR_PROP_BIT_WRITE_NR; static const uint8_t char_prop_read_write = ESP_GATT_CHAR_PROP_BIT_WRITE|ESP_GATT_CHAR_PROP_BIT_READ; static const uint8_t char_prop_read_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_NOTIFY; static const uint8_t char_prop_read_write_notify = ESP_GATT_CHAR_PROP_BIT_READ|ESP_GATT_CHAR_PROP_BIT_WRITE|ESP_GATT_CHAR_PROP_BIT_NOTIFY; +static const uint8_t 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; /// battary Service static const uint16_t battary_svc = ESP_GATT_UUID_BATTERY_SERVICE_SVC; @@ -415,7 +416,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] = [HIDD_LE_IDX_REPORT_LED_OUT_CHAR] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, - (uint8_t *)&char_prop_read_write}}, + (uint8_t *)&char_prop_read_write_write_nr}}, [HIDD_LE_IDX_REPORT_LED_OUT_VAL] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&hid_report_uuid, ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE, @@ -501,7 +502,7 @@ static esp_gatts_attr_db_t hidd_le_gatt_db[HIDD_LE_IDX_NB] = [HIDD_LE_IDX_BOOT_KB_OUT_REPORT_CHAR] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, CHAR_DECLARATION_SIZE, CHAR_DECLARATION_SIZE, - (uint8_t *)&char_prop_read_write}}, + (uint8_t *)&char_prop_read_write_write_nr}}, // Boot Keyboard Output Report Characteristic Value [HIDD_LE_IDX_BOOT_KB_OUT_REPORT_VAL] = {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&hid_kb_output_uuid, (ESP_GATT_PERM_READ|ESP_GATT_PERM_WRITE), @@ -595,11 +596,19 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, case ESP_GATTS_CLOSE_EVT: break; case ESP_GATTS_WRITE_EVT: { -#if (SUPPORT_REPORT_VENDOR == true) esp_hidd_cb_param_t cb_param = {0}; - if (param->write.handle == hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_VENDOR_OUT_VAL] && + if (param->write.handle == hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_LED_OUT_VAL] && hidd_le_env.hidd_cb != NULL) { cb_param.vendor_write.conn_id = param->write.conn_id; + cb_param.vendor_write.report_id = HID_RPT_ID_LED_OUT; + cb_param.vendor_write.length = param->write.len; + cb_param.vendor_write.data = param->write.value; + (hidd_le_env.hidd_cb)(ESP_HIDD_EVENT_BLE_LED_OUT_WRITE_EVT, &cb_param); + } +#if (SUPPORT_REPORT_VENDOR == true) + if (param->write.handle == hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_VENDOR_OUT_VAL] && + hidd_le_env.hidd_cb != NULL) {; + cb_param.vendor_write.conn_id = param->write.conn_id; cb_param.vendor_write.report_id = HID_RPT_ID_VENDOR_OUT; cb_param.vendor_write.length = param->write.len; cb_param.vendor_write.data = param->write.value; @@ -632,6 +641,7 @@ void esp_hidd_prf_cb_hdl(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, } default: + ESP_LOGI(HID_LE_PRF_TAG,"GATT EVT %d",event); break; } } @@ -758,14 +768,14 @@ static void hid_add_id_tbl(void) hid_rpt_map[0].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_KEY_IN_VAL]; hid_rpt_map[0].cccdHandle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_KEY_IN_CCC]; hid_rpt_map[0].mode = HID_PROTOCOL_MODE_REPORT; - + // Consumer Control input report hid_rpt_map[1].id = hidReportRefCCIn[0]; hid_rpt_map[1].type = hidReportRefCCIn[1]; hid_rpt_map[1].handle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_CC_IN_VAL]; hid_rpt_map[1].cccdHandle = hidd_le_env.hidd_inst.att_tbl[HIDD_LE_IDX_REPORT_CC_IN_CCC]; hid_rpt_map[1].mode = HID_PROTOCOL_MODE_REPORT; - + // LED output report hid_rpt_map[2].id = hidReportRefLedOut[0]; hid_rpt_map[2].type = hidReportRefLedOut[1]; diff --git a/main/hidd_le_prf_int.h b/main/hidd_le_prf_int.h index 3dad46a..5fb74ed 100644 --- a/main/hidd_le_prf_int.h +++ b/main/hidd_le_prf_int.h @@ -48,7 +48,7 @@ #define HID_RPT_ID_CC_IN 2 //Consumer Control input report ID #define HID_RPT_ID_MOUSE_IN 3 // Mouse input report ID #define HID_RPT_ID_VENDOR_OUT 4 // Vendor output report ID -#define HID_RPT_ID_LED_OUT 0 // LED output report ID +#define HID_RPT_ID_LED_OUT 1 // LED output report ID #define HID_RPT_ID_FEATURE 0 // Feature report ID #define HIDD_APP_ID 0x1812//ATT_SVC_HID