diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c index 808de7a435..636c159a57 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/ble_hidd_demo_main.c @@ -122,6 +122,12 @@ static void hidd_event_callback(esp_hidd_cb_event_t event, esp_hidd_cb_param_t * case ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT: { 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); + break; + } + case ESP_HIDD_EVENT_BLE_LED_REPORT_WRITE_EVT: { + ESP_LOGI(HID_DEMO_TAG, "ESP_HIDD_EVENT_BLE_LED_REPORT_WRITE_EVT"); + ESP_LOG_BUFFER_HEX(HID_DEMO_TAG, param->led_write.data, param->led_write.length); + break; } default: break; diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/esp_hidd_prf_api.h b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/esp_hidd_prf_api.h index e7a1932f5c..3713aad3af 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/esp_hidd_prf_api.h +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/esp_hidd_prf_api.h @@ -30,6 +30,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_REPORT_WRITE_EVT, } esp_hidd_cb_event_t; /// HID config status @@ -104,6 +105,15 @@ typedef union { uint8_t *data; /*!< The pointer to the data */ } vendor_write; /*!< HID callback param of ESP_HIDD_EVENT_BLE_VENDOR_REPORT_WRITE_EVT */ + /** + * @brief ESP_HIDD_EVENT_BLE_LED_REPORT_WRITE_EVT + */ + struct hidd_led_write_evt_param { + uint16_t conn_id; + uint8_t report_id; + uint8_t length; + uint8_t *data; + } led_write; } esp_hidd_cb_param_t; diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_device_le_prf.c b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_device_le_prf.c index db697b04be..263eebaf2e 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_device_le_prf.c +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hid_device_le_prf.c @@ -88,11 +88,11 @@ static const uint8_t hidReportMap[] = { 0x81, 0x01, // Input: (Constant) // // LED report - 0x95, 0x05, // Report Count (5) - 0x75, 0x01, // Report Size (1) 0x05, 0x08, // Usage Pg (LEDs) 0x19, 0x01, // Usage Min (1) 0x29, 0x05, // Usage Max (5) + 0x95, 0x05, // Report Count (5) + 0x75, 0x01, // Report Size (1) 0x91, 0x02, // Output: (Data, Variable, Absolute) // // LED report padding @@ -291,6 +291,7 @@ 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_READ|ESP_GATT_CHAR_PROP_BIT_WRITE|ESP_GATT_CHAR_PROP_BIT_WRITE_NR; /// battary Service static const uint16_t battary_svc = ESP_GATT_UUID_BATTERY_SERVICE_SVC; @@ -433,7 +434,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, @@ -593,8 +594,15 @@ 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_LED_OUT_VAL]) { + cb_param.led_write.conn_id = param->write.conn_id; + cb_param.led_write.report_id = HID_RPT_ID_LED_OUT; + cb_param.led_write.length = param->write.len; + cb_param.led_write.data = param->write.value; + (hidd_le_env.hidd_cb)(ESP_HIDD_EVENT_BLE_LED_REPORT_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; diff --git a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hidd_le_prf_int.h b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hidd_le_prf_int.h index 7f81e3f48f..f70d2b9e72 100644 --- a/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hidd_le_prf_int.h +++ b/examples/bluetooth/bluedroid/ble/ble_hid_device_demo/main/hidd_le_prf_int.h @@ -48,7 +48,7 @@ #define HID_RPT_ID_KEY_IN 2 // Keyboard input report ID #define HID_RPT_ID_CC_IN 3 //Consumer Control 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 2 // LED output report ID #define HID_RPT_ID_FEATURE 0 // Feature report ID #define HIDD_APP_ID 0x1812//ATT_SVC_HID