// HID device whose report descriptor declares Report ID (1) before the first // Collection item. Repro firmware for crbug.com/574273446. // // Board: ESP32-S3 (or S2) devkit, Arduino-ESP32 core 3.x, native USB port. // Tools -> USB Mode: "USB-OTG (TinyUSB)", USB CDC On Boot: "Enabled". #include "USB.h" #include "USBHID.h" // Report ID (1) precedes Collection (Application). A vendor-defined usage page // keeps the reports outside the WebHID blocklist so a page can read them. static const uint8_t kHidReportDescriptor[] = { 0x85, 0x01, // Report ID (1) 0x06, 0x00, 0xFF, // Usage Page (Vendor 0xFF00) 0x09, 0x01, // Usage (0x01) 0xA1, 0x01, // Collection (Application) 0x15, 0x00, // Logical Minimum (0) 0x26, 0xFF, 0x00, // Logical Maximum (255) 0x75, 0x08, // Report Size (8) 0x95, 0x02, // Report Count (2) 0x09, 0x02, // Usage (0x02) 0x81, 0x02, // Input (Data,Var,Abs) 0x09, 0x03, // Usage (0x03) 0x91, 0x02, // Output (Data,Var,Abs) 0xC0, // End Collection }; constexpr uint8_t kReportId = 1; constexpr uint32_t kSendIntervalMs = 500; USBHID HID; class RawHidDevice : public USBHIDDevice { public: RawHidDevice() { HID.addDevice(this, sizeof(kHidReportDescriptor)); } void begin() { HID.begin(); } uint16_t _onGetDescriptor(uint8_t* buffer) override { memcpy(buffer, kHidReportDescriptor, sizeof(kHidReportDescriptor)); return sizeof(kHidReportDescriptor); } void _onOutput(uint8_t report_id, const uint8_t* buffer, uint16_t len) override { Serial.printf("OUT report id=%u len=%u data=", report_id, len); for (uint16_t i = 0; i < len; i++) { Serial.printf("%02X ", buffer[i]); } Serial.println(); } bool sendCounterReport(uint8_t counter) { uint8_t report[2] = {counter, 0x5A}; return HID.SendReport(kReportId, report, sizeof(report)); } }; RawHidDevice raw_hid; void setup() { Serial.begin(115200); raw_hid.begin(); USB.manufacturerName("januschka.com"); USB.productName("HID ReportID Repro"); USB.begin(); Serial.println("HID ReportID Repro ready: input report id 1, 2 bytes"); } void loop() { static uint32_t last_send_ms = 0; static uint8_t counter = 0; if (millis() - last_send_ms < kSendIntervalMs) { return; } last_send_ms = millis(); if (HID.ready()) { raw_hid.sendCounterReport(counter++); } }