I have a project am I working on which is 3 HID devices and 1 CDC device. That is working just fine. It is a composite device so everything has its own interface(3 for HID, and 2 for CDC) however the problem I have been having is that I need a specific order of these devices. I need the CDC device to come after the 3 hid devices but it seems no matter what I do, the CDC device makes itself use interface 0 and 1. I have tried unregistering and registering after the HID setup but that does work. I tried changing the INIT priorities, I've tried a bunch of weird stuff in the device tree overlay and I am at a loss. Has anyone done this before successfully? I am using the new USB stack btw.
// Initialize USB HID composite device
int usb_hid_composite_init(void)
{
struct usbd_context *sample_usbd;
int err;
sample_usbd = sample_usbd_init_device(NULL);
if (sample_usbd == NULL)
{
// LOG_ERR("Failed to initialize USB device");
return -ENODEV;
}
LOG_INF("Waiting 5 seconds for serial monitor connection...");
k_sleep(K_SECONDS(5));
LOG_INF("Attempting to unregister CDC ACM before USB enable");
err = usbd_unregister_class(sample_usbd, "cdc_acm_uart0", USBD_SPEED_FS, 1);
if (err == 0) {
LOG_INF("Successfully unregistered cdc_acm_uart0 before enable");
} else {
LOG_WRN("Failed to unregister cdc_acm_uart0 before enable: %d", err);
}
// reset_usb();
hid_mouse = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(hid_mouse));
hid_keyboard = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(hid_keyboard));
hid_gamepad = DEVICE_DT_GET_OR_NULL(DT_NODELABEL(hid_gamepad));
if (hid_mouse == NULL)
{
// LOG_ERR("Cannot get USB HID Device");
return -ENODEV;
}
hid_device_register(hid_mouse,
mouse_report_desc, sizeof(mouse_report_desc),
&ops);
hid_device_register(hid_keyboard,
keyboard_report_desc, sizeof(keyboard_report_desc),
&ops);
hid_device_register(hid_gamepad,
gamepad_report_desc, sizeof(gamepad_report_desc),
&ops);
err = usbd_register_class(sample_usbd, "cdc_acm_uart0", USBD_SPEED_FS, 1);
usbd_device_set_vid(sample_usbd, 0x1234); // xxxx VID
usbd_device_set_pid(sample_usbd, 0x1234); // xxxx PID
err = usbd_enable(sample_usbd);
if (err)
{
// LOG_ERR("Failed to enable device support");
return err;
}
// LOG_ERR("*** USB HID composite device initialized - DS4 Feature Reports Ready ***");
return 0;
}