usb-device: Can't implement CDC with HID

I created a CDC and HID classes with one device

let mut hid = HIDClass::new_with_settings(
    &bus_allocator,
    KeyboardReport::desc(),
    10,
    HidClassSettings {  
        subclass: HidSubClass::NoSubClass,
        protocol: HidProtocol::Keyboard,
        config: ProtocolModeConfig::ForceReport,
        locale: HidCountryCode::NotSupported
    }
);
let mut serial = SerialPort::new(&bus_allocator);

let mut dev = UsbDeviceBuilder::new(&bus_allocator, vid_pid)
    .manufacturer("xkbd")
    .product("Prism80")
    .serial_number("000")
    .device_class(USB_CLASS_CDC)
    .build();

And the loop code:

loop {
    dev.poll(&mut [&mut serial, &mut hid]);
    if button_pin.is_high().unwrap() {
        hid.push_input(&report_struct).ok();
        led_pin.set_high().ok();
        serial.write(b"Pressed").ok();
    } else {
        hid.push_input(&null_report_struct).ok();
        led_pin.set_low().ok();
        serial.write(b"Released").ok();
    }

    // drop received data
    hid.pull_raw_output(&mut [0; 64]).ok();
}

However the USB device is not recognized by my PC, I tried the solution from #85 but it does not fix the issue and the device keep being unrecognized, how do I implement the HID with CDC?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Hmm, could you check if it works in Windows without .device_class(USB_CLASS_CDC)? Also it would be interesting to see USB capture (for example, gathered with Wireshark) which contains packets transferred when you connect to the device with screen.