nimble to windows10 22h2
esp_hid_device 的keyboardReportMap在win10 22h2 csr4.0 下好像识别不了,
Windows(和大多数 BIOS/UEFI)只认 6-byte key array 的 HID Keyboard 描述符。如果不是 6 个字节,Windows HID 驱动就会认为这不是标准键盘 → 不会加载通用键盘驱动。
关键的一行 0x95, 0x06, // Report Count (6)
可行的keyboardReportMap 如下
// HID Report Map characteristic value
static const uint8_t keyboardReportMap[] = {0x05, 0x01, // Usage Pg (Generic Desktop)0x09, 0x06, // Usage (Keyboard)0xA1, 0x01, // Collection: (Application)//0x05, 0x07, // Usage Pg (Key Codes)0x19, 0xE0, // Usage Min (224)0x29, 0xE7, // Usage Max (231)0x15, 0x00, // Log Min (0)0x25, 0x01, // Log Max (1)//// Modifier byte0x75, 0x01, // Report Size (1)0x95, 0x08, // Report Count (8)0x81, 0x02, // Input: (Data, Variable, Absolute)//// Reserved byte0x95, 0x01, // Report Count (1)0x75, 0x08, // Report Size (8)0x81, 0x01, // Input: (Constant)//// LED report0x95, 0x05, // Report Count (5)0x75, 0x01, // Report Size (1)0x05, 0x08, // Usage Pg (LEDs)0x19, 0x01, // Usage Min (1)0x29, 0x05, // Usage Max (5)0x91, 0x02, // Output: (Data, Variable, Absolute)//// LED report padding0x95, 0x01, // Report Count (1)0x75, 0x03, // Report Size (3)0x91, 0x01, // Output: (Constant)//// Key arrays (6 bytes)0x95, 0x06, // Report Count (6)0x75, 0x08, // Report Size (8)0x15, 0x00, // Log Min (0)0x25, 0x65, // Log Max (101)0x05, 0x07, // Usage Pg (Key Codes)0x19, 0x00, // Usage Min (0)0x29, 0x65, // Usage Max (101)0x81, 0x00, // Input: (Data, Array)//0xC0 // End Collection
};
//report id 使用 0esp_hidd_dev_input_set(s_ble_hid_param.hid_dev, 0, 0, buffer, 8);
HID报告描述符中的Report ID其取值范围为0-255(1字节),具体规则如下:
当未在报告描述符中显式声明Report ID时,系统默认使用0作为隐式ID
显式声明Report ID的语法为0x85, 0x01(其中0x01为ID值)
典型应用场景
0值Report ID常用于单报告设备,简化数据传输
多报告设备(如复合设备)必须使用非零ID区分不同报告
键盘/鼠标等标准HID设备通常不使用Report ID,此时默认为0
nimble to ios18
nimble hid_device 配对过程不触发输入Pin,连上了也会输入无反应。
原因在于 iOS 对 BLE 安全性要求严格,尤其是 HID(键盘/鼠标)类设备。
在 NimBLE 中:
sdkconfig默认 NIMBLE_SM_LVL=0 时,ESP32 允许 低安全级别配对。
iOS 对 HID 设备要求 至少 MITM 保护,否则它不会弹出 Passkey 或 Numeric Comparison,连接后键盘输入无反应。
修改sdkconfig中nimble项的sm lvl 为2 (默认为0)
提升到 SM_LVL=2 → iOS 认为安全性满足要求 → 才会显示 Passkey/Numeric Comparison 对话框。
因为 iOS HID 要求至少 加密 + MITM,SM_LVL=2 正好满足这个条件。
nimble to android
fields.appearance 改为ESP_HID_APPEARANCE_KEYBOARD时, android 手机配对时闪退(s7edge android 8.0.0)
// fields.appearance = ESP_HID_APPEARANCE_GENERIC;fields.appearance = ESP_HID_APPEARANCE_KEYBOARD;