// HID device whose report descriptor declares Report ID (1) before the first // Collection item. Repro firmware for crbug.com/574273446. // // Board: Adafruit Feather nRF52840 Express (Adafruit nRF52 core, TinyUSB). #include // Report ID (1) precedes Collection (Application). A vendor-defined usage page // keeps the reports outside the WebHID blocklist so a page can read them. uint8_t const 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 uint8_t kReportSizeBytes = 2; constexpr uint32_t kSendIntervalMs = 500; Adafruit_USBD_HID usb_hid(kHidReportDescriptor, sizeof(kHidReportDescriptor), HID_ITF_PROTOCOL_NONE, /*interval_ms=*/2, /*has_out_endpoint=*/true); void HandleSetReport(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { // Reports arriving on the OUT endpoint carry the report ID in the first // payload byte instead of in |report_id|. if (report_id == 0 && bufsize > 0) { report_id = buffer[0]; buffer++; bufsize--; } Serial.printf("OUT report id=%u type=%u len=%u data=", report_id, static_cast(report_type), bufsize); for (uint16_t i = 0; i < bufsize; i++) { Serial.printf("%02X ", buffer[i]); } Serial.println(); } void setup() { TinyUSBDevice.setManufacturerDescriptor("januschka.com"); TinyUSBDevice.setProductDescriptor("HID ReportID Repro"); usb_hid.setStringDescriptor("Report ID before collection"); usb_hid.setReportCallback(/*get_report=*/nullptr, HandleSetReport); usb_hid.begin(); Serial.begin(115200); while (!TinyUSBDevice.mounted()) { delay(10); } 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 (!usb_hid.ready()) { return; } uint8_t report[kReportSizeBytes] = {counter++, 0x5A}; usb_hid.sendReport(kReportId, report, sizeof(report)); }