Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/zephyr/usb/class/usbd_hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ struct hid_device_ops {
*/
void (*iface_ready)(const struct device *dev, const bool ready);

/**
* This callback is called when the HID interface is suspended by the
* host. This callback is optional.
*/
void (*iface_suspended)(const struct device *dev, const bool suspended);

Comment on lines +106 to +111
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interface cannot be suspended, and there is nothing like that in the HID specification. To get notifications when a USB device is suspended, please use USBD_MSG_SUSPEND and USBD_MSG_RESUME. There is no reason to have additional callbacks in each function/class implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interface cannot be suspended, and there is nothing like that in the HID specification. To get notifications when a USB device is suspended, please use USBD_MSG_SUSPEND and USBD_MSG_RESUME. There is no reason to have additional callbacks in each function/class implementation.

Ok, looked more into my application and yeah actually I managed to get it working with those two messages, the culprit may or may not have been a if (!usbd_can_detect_vbus(usbd_ctx)) {return;} in my code that was causing all messages to be ignored. :-)

Nevermind then thanks for the pointer, guess then these placeholder callback could go? Anyway closing this down.

/**
* This callback is called for the HID Get Report request to get a
* feature, input, or output report, which is specified by the argument
Expand Down
12 changes: 12 additions & 0 deletions subsys/usb/device_next/class/usbd_hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,25 @@ static void usbd_hid_disable(struct usbd_class_data *const c_data)
static void usbd_hid_suspended(struct usbd_class_data *const c_data)
{
const struct device *dev = usbd_class_get_private(c_data);
struct hid_device_data *ddata = dev->data;
const struct hid_device_ops *const ops = ddata->ops;

if (ops->iface_suspended) {
ops->iface_suspended(dev, true);
}

LOG_DBG("Configuration suspended, device %s", dev->name);
}

static void usbd_hid_resumed(struct usbd_class_data *const c_data)
{
const struct device *dev = usbd_class_get_private(c_data);
struct hid_device_data *ddata = dev->data;
const struct hid_device_ops *const ops = ddata->ops;

if (ops->iface_suspended) {
ops->iface_suspended(dev, false);
}

LOG_DBG("Configuration resumed, device %s", dev->name);
}
Expand Down