From 9be660b9cc0481485d26a49d27a221cfb092f982 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Wed, 14 May 2025 14:50:58 -0700 Subject: [PATCH] usbd_hid: Add .suspend/.resume callbacks Add .suspend/.resume callbacks to pass those events to the users, so they can react accordingly. Signed-off-by: Andrey Smirnov --- include/zephyr/usb/class/usbd_hid.h | 3 +++ subsys/usb/device_next/class/usbd_hid.c | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/zephyr/usb/class/usbd_hid.h b/include/zephyr/usb/class/usbd_hid.h index 79b52dd8fd9d3..c2e4c381c3fed 100644 --- a/include/zephyr/usb/class/usbd_hid.h +++ b/include/zephyr/usb/class/usbd_hid.h @@ -178,6 +178,9 @@ struct hid_device_ops { * and the execution time should be quite short. */ void (*sof)(const struct device *dev); + + void (*suspend)(const struct device *dev); + void (*resume)(const struct device *dev); }; /** diff --git a/subsys/usb/device_next/class/usbd_hid.c b/subsys/usb/device_next/class/usbd_hid.c index 2ea3a08db763a..54363fb58cb3c 100644 --- a/subsys/usb/device_next/class/usbd_hid.c +++ b/subsys/usb/device_next/class/usbd_hid.c @@ -474,15 +474,27 @@ 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; LOG_DBG("Configuration suspended, device %s", dev->name); + + if (ops->suspend) { + ops->suspend(dev); + } } 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; LOG_DBG("Configuration resumed, device %s", dev->name); + + if (ops->resume) { + ops->resume(dev); + } } static void *usbd_hid_get_desc(struct usbd_class_data *const c_data,