/* This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this software is
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/#include<stdio.h>#include<stdlib.h>#include<string.h>#include"freertos/FreeRTOS.h"#include"freertos/task.h"#include"freertos/event_groups.h"#include"esp_system.h"#include"esp_wifi.h"#include"esp_event.h"#include"esp_log.h"#include"nvs_flash.h"#include"esp_bt.h"#include"esp_hidd_prf_api.h"#include"esp_bt_defs.h"#include"esp_gap_ble_api.h"#include"esp_gatts_api.h"#include"esp_gatt_defs.h"#include"esp_bt_main.h"#include"esp_bt_device.h"#include"driver/gpio.h"#include"hid_dev.h"#include"esp_vfs.h"#include"esp_vfs_dev.h"#include"driver/uart.h"#include"breath_led.h"#include"driver/ledc.h"#include"esp_err.h"voidled4_trg(void);voidled4_off(void);voidled5_on();voidled5_off();#defineBUTTON_PIN9/**
* Brief:
* This example Implemented BLE HID device profile related functions, in which the HID device
* has 4 Reports (1 is mouse, 2 is keyboard and LED, 3 is Consumer Devices, 4 is Vendor devices).
* Users can choose different reports according to their own application scenarios.
* BLE HID profile inheritance and USB HID class.
*//**
* Note:
* 1. Win10 does not support vendor report , So SUPPORT_REPORT_VENDOR is always set to FALSE, it defines in hidd_le_prf_int.h
* 2. Update connection parameters are not allowed during iPhone HID encryption, slave turns
* off the ability to automatically update connection parameters during encryption.
* 3. After our HID device is connected, the iPhones write 1 to the Report Characteristic Configuration Descriptor,
* even if the HID encryption is not completed. This should actually be written 1 after the HID encryption is completed.
* we modify the permissions of the Report Characteristic Configuration Descriptor to `ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE_ENCRYPTED`.
* if you got `GATT_INSUF_ENCRYPTION` error, please ignore.
*/#defineHID_DEMO_TAG"HID_DEMO"staticuint16_t hid_conn_id =0;static bool sec_conn = false;static bool send_volum_up = false;#defineCHAR_DECLARATION_SIZE(sizeof(uint8_t))staticvoidhidd_event_callback(esp_hidd_cb_event_t event,esp_hidd_cb_param_t*param);#defineHIDD_DEVICE_NAME"test-Keyboard"staticuint8_t hidd_service_uuid128[]={
/* LSB <--------------------------------------------------------------------------------> MSB *///first uuid, 16bit, [12],[13] is the value0xfb,0x34,0x9b,0x5f,0x80,0x00,0x00,0x80,0x00,0x10,0x00,0x00,0x12,0x18,0x00,0x00,};staticesp_ble_adv_data_t hidd_adv_data ={
.set_scan_rsp = false,.include_name = true,.include_txpower = true,.min_interval =0x0002,//slave connection min interval, Time = min_interval * 1.25 msec.max_interval =0x0006,//slave connection max interval, Time = max_interval * 1.25 msec.appearance =0x03c0,//HID Generic,.manufacturer_len