@@ -632,6 +632,56 @@ static int hid_dev_submit_report(const struct device *dev,
632632 return 0 ;
633633}
634634
635+ static inline int hid_dev_set_out_polling (const struct device * dev ,
636+ const unsigned int period_us )
637+ {
638+ const struct hid_device_config * const dcfg = dev -> config ;
639+ struct hid_device_data * const ddata = dev -> data ;
640+ struct usbd_hid_descriptor * const desc = dcfg -> desc ;
641+
642+ if (atomic_test_bit (& ddata -> state , HID_DEV_CLASS_INITIALIZED )) {
643+ return - EBUSY ;
644+ }
645+
646+ if (USBD_SUPPORTS_HIGH_SPEED ) {
647+ if (desc -> hs_out_ep .bLength == 0 ) {
648+ /* This device does not have output reports. */
649+ return - ENOTSUP ;
650+ }
651+
652+ desc -> hs_out_ep .bInterval = USB_HS_INT_EP_INTERVAL (period_us );
653+ }
654+
655+ if (desc -> out_ep .bLength == 0 ) {
656+ /* This device does not have output reports. */
657+ return - ENOTSUP ;
658+ }
659+
660+ desc -> out_ep .bInterval = USB_FS_INT_EP_INTERVAL (period_us );
661+
662+ return 0 ;
663+ }
664+
665+ static inline int hid_dev_set_in_polling (const struct device * dev ,
666+ const unsigned int period_us )
667+ {
668+ const struct hid_device_config * const dcfg = dev -> config ;
669+ struct hid_device_data * const ddata = dev -> data ;
670+ struct usbd_hid_descriptor * const desc = dcfg -> desc ;
671+
672+ if (atomic_test_bit (& ddata -> state , HID_DEV_CLASS_INITIALIZED )) {
673+ return - EBUSY ;
674+ }
675+
676+ if (USBD_SUPPORTS_HIGH_SPEED ) {
677+ desc -> hs_in_ep .bInterval = USB_HS_INT_EP_INTERVAL (period_us );
678+ }
679+
680+ desc -> in_ep .bInterval = USB_FS_INT_EP_INTERVAL (period_us );
681+
682+ return 0 ;
683+ }
684+
635685static int hid_dev_register (const struct device * dev ,
636686 const uint8_t * const rdesc , const uint16_t rsize ,
637687 const struct hid_device_ops * const ops )
@@ -706,6 +756,10 @@ struct usbd_class_api usbd_hid_api = {
706756static const struct hid_device_driver_api hid_device_api = {
707757 .submit_report = hid_dev_submit_report ,
708758 .dev_register = hid_dev_register ,
759+ #if CONFIG_USBD_HID_SET_POLLING_PERIOD
760+ .set_out_polling = hid_dev_set_out_polling ,
761+ .set_in_polling = hid_dev_set_in_polling ,
762+ #endif
709763};
710764
711765#include "usbd_hid_macros.h"
0 commit comments