Skip to content

Commit

Permalink
examples: fix ble hid led output report
Browse files Browse the repository at this point in the history
  • Loading branch information
esp-cjh committed Dec 19, 2022
1 parent c97df72 commit e8fef19
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -22,6 +22,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
Expand Down Expand Up @@ -96,6 +97,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;


Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -80,11 +80,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
Expand Down Expand Up @@ -283,6 +283,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;
Expand Down Expand Up @@ -425,7 +426,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,
Expand Down Expand Up @@ -585,8 +586,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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -40,7 +40,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
Expand Down

0 comments on commit e8fef19

Please sign in to comment.