include: usb_ch9: add macros to calculate endpoint bInterval

Add macros to calculate FS/HS endpoint bInterval.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
diff --git a/include/zephyr/usb/usb_ch9.h b/include/zephyr/usb/usb_ch9.h
index fa18b1c..239f3be 100644
--- a/include/zephyr/usb/usb_ch9.h
+++ b/include/zephyr/usb/usb_ch9.h
@@ -14,6 +14,7 @@
 
 #include <version.h>
 #include <zephyr/sys/util.h>
+#include <zephyr/math/ilog2.h>
 #include <zephyr/usb/class/usb_hub.h>
 
 #ifndef ZEPHYR_INCLUDE_USB_CH9_H_
@@ -321,6 +322,18 @@
 /** USB endpoint transfer type interrupt */
 #define USB_EP_TYPE_INTERRUPT		3U
 
+/** Calculate full speed interrupt endpoint bInterval from a value in microseconds */
+#define USB_FS_INT_EP_INTERVAL(us)	CLAMP(((us) / 1000U), 1U, 255U)
+
+/** Calculate high speed interrupt endpoint bInterval from a value in microseconds */
+#define USB_HS_INT_EP_INTERVAL(us)	CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U)
+
+/** Calculate high speed isochronous endpoint bInterval from a value in microseconds */
+#define USB_FS_ISO_EP_INTERVAL(us)	CLAMP(((us) / 1000U), 1U, 16U)
+
+/** Calculate high speed isochronous endpoint bInterval from a value in microseconds */
+#define USB_HS_ISO_EP_INTERVAL(us)	CLAMP((ilog2((us) / 125U) + 1U), 1U, 16U)
+
 #ifdef __cplusplus
 }
 #endif