summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2025-11-20 22:49:41 +0800
committersakumisu <[email protected]>2025-11-20 22:49:41 +0800
commit449ea2664ec18342d5c948e1877cc4a3062f4fbc (patch)
tree11a6f840d293d636e080a62c02597de602a07f86
parent21633d2138db892f88b12629dfcb1a89b6af6d90 (diff)
feat(core/usbh_core): support interfacenum match flag
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--core/usbh_core.c14
-rw-r--r--core/usbh_core.h2
2 files changed, 14 insertions, 2 deletions
diff --git a/core/usbh_core.c b/core/usbh_core.c
index 05d10b86..1f670952 100644
--- a/core/usbh_core.c
+++ b/core/usbh_core.c
@@ -94,7 +94,7 @@ static int usbh_free_devaddr(struct usbh_hubport *hport)
return 0;
}
-static const struct usbh_class_driver *usbh_find_class_driver(uint8_t class, uint8_t subclass, uint8_t protocol,
+static const struct usbh_class_driver *usbh_find_class_driver(uint8_t class, uint8_t subclass, uint8_t protocol, uint8_t intf,
uint16_t vid, uint16_t pid)
{
struct usbh_class_info *index = NULL;
@@ -109,6 +109,9 @@ static const struct usbh_class_driver *usbh_find_class_driver(uint8_t class, uin
if ((index->match_flags & USB_CLASS_MATCH_INTF_PROTOCOL) && !(index->bInterfaceProtocol == protocol)) {
continue;
}
+ if ((index->match_flags & USB_CLASS_MATCH_INTF_NUM) && !(index->bInterfaceNumber == intf)) {
+ continue;
+ }
if (index->match_flags & USB_CLASS_MATCH_VID_PID && index->id_table) {
/* scan id table */
uint32_t i;
@@ -553,7 +556,14 @@ int usbh_enumerate(struct usbh_hubport *hport)
for (uint8_t i = 0; i < hport->config.config_desc.bNumInterfaces; i++) {
intf_desc = &hport->config.intf[i].altsetting[0].intf_desc;
- struct usbh_class_driver *class_driver = (struct usbh_class_driver *)usbh_find_class_driver(intf_desc->bInterfaceClass, intf_desc->bInterfaceSubClass, intf_desc->bInterfaceProtocol, hport->device_desc.idVendor, hport->device_desc.idProduct);
+ USB_ASSERT_MSG(intf_desc->bInterfaceNumber == i, "Interface number mismatch, do not support non-standard device\r\n");
+
+ struct usbh_class_driver *class_driver = (struct usbh_class_driver *)usbh_find_class_driver(intf_desc->bInterfaceClass,
+ intf_desc->bInterfaceSubClass,
+ intf_desc->bInterfaceProtocol,
+ intf_desc->bInterfaceNumber,
+ hport->device_desc.idVendor,
+ hport->device_desc.idProduct);
if (class_driver == NULL) {
USB_LOG_ERR("Do not support Class:0x%02x, Subclass:0x%02x, Protocl:0x%02x on interface %u\r\n",
diff --git a/core/usbh_core.h b/core/usbh_core.h
index f5cca270..0fde3fcf 100644
--- a/core/usbh_core.h
+++ b/core/usbh_core.h
@@ -62,6 +62,7 @@ enum usbh_event_type {
#define USB_CLASS_MATCH_INTF_CLASS 0x0004
#define USB_CLASS_MATCH_INTF_SUBCLASS 0x0008
#define USB_CLASS_MATCH_INTF_PROTOCOL 0x0010
+#define USB_CLASS_MATCH_INTF_NUM 0x0020
#define USB_CLASS_MATCH_VID_PID (USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT)
#define CLASS_CONNECT(hport, i) ((hport)->config.intf[i].class_driver->connect(hport, i))
@@ -96,6 +97,7 @@ struct usbh_class_info {
uint8_t bInterfaceClass; /* Base device class code */
uint8_t bInterfaceSubClass; /* Sub-class, depends on base class. Eg. */
uint8_t bInterfaceProtocol; /* Protocol, depends on base class. Eg. */
+ uint8_t bInterfaceNumber; /* Interface number */
const uint16_t (*id_table)[2]; /* List of Vendor/Product ID pairs */
const struct usbh_class_driver *class_driver;
};