diff --git a/sys/include/usb/usbus.h b/sys/include/usb/usbus.h index 090f969d9c..9ce0563ccc 100644 --- a/sys/include/usb/usbus.h +++ b/sys/include/usb/usbus.h @@ -427,6 +427,24 @@ uint16_t usbus_add_string_descriptor(usbus_t *usbus, usbus_string_t *desc, */ uint16_t usbus_add_interface(usbus_t *usbus, usbus_interface_t *iface); +/** + * @brief Find an endpoint from an interface based on the endpoint properties + * + * This iterates over the endpoints in an interface and will return the first + * endpoint from the interface matching the @p type and @p dir. It will return + * NULL when no matching endpoint is found. + * + * @param[in] interface interface to look in + * @param[in] type endpoint type to match + * @param[in] dir endpoint direction to match + * + * @return ptr to the first matching endpoint + * @return NULL when no endpoint is found + */ +usbus_endpoint_t *usbus_interface_find_endpoint(usbus_interface_t *interface, + usb_ep_type_t type, + usb_ep_dir_t dir); + /** * @brief Add an endpoint to the specified interface * diff --git a/sys/usb/usbus/usbus.c b/sys/usb/usbus/usbus.c index a39b9d2ca3..8006f81252 100644 --- a/sys/usb/usbus/usbus.c +++ b/sys/usb/usbus/usbus.c @@ -127,6 +127,18 @@ void usbus_register_event_handler(usbus_t *usbus, usbus_handler_t *handler) *last = handler; } +usbus_endpoint_t *usbus_interface_find_endpoint(usbus_interface_t *interface, + usb_ep_type_t type, + usb_ep_dir_t dir) +{ + for (usbus_endpoint_t *uep = interface->ep; uep; uep = uep->next) { + if (uep->ep->type == type && uep->ep->dir == dir) { + return uep; + } + } + return NULL; +} + usbus_endpoint_t *usbus_add_endpoint(usbus_t *usbus, usbus_interface_t *iface, usb_ep_type_t type, usb_ep_dir_t dir, size_t len)