diff --git a/class/audio/usbh_audio.c b/class/audio/usbh_audio.c index 1da958d5..8687e9a4 100644 --- a/class/audio/usbh_audio.c +++ b/class/audio/usbh_audio.c @@ -469,8 +469,7 @@ CLASS_INFO_DEFINE const struct usbh_class_info audio_ctrl_intf_class_info = { .class = USB_DEVICE_CLASS_AUDIO, .subclass = AUDIO_SUBCLASS_AUDIOCONTROL, .protocol = 0x00, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &audio_ctrl_class_driver }; @@ -479,7 +478,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info audio_streaming_intf_class_info = .class = USB_DEVICE_CLASS_AUDIO, .subclass = AUDIO_SUBCLASS_AUDIOSTREAMING, .protocol = 0x00, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &audio_streaming_class_driver }; diff --git a/class/cdc/usbh_cdc_acm.c b/class/cdc/usbh_cdc_acm.c index 0f472c2a..05184af8 100644 --- a/class/cdc/usbh_cdc_acm.c +++ b/class/cdc/usbh_cdc_acm.c @@ -249,8 +249,7 @@ CLASS_INFO_DEFINE const struct usbh_class_info cdc_acm_class_info = { .class = USB_DEVICE_CLASS_CDC, .subclass = CDC_ABSTRACT_CONTROL_MODEL, .protocol = CDC_COMMON_PROTOCOL_AT_COMMANDS, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &cdc_acm_class_driver }; @@ -259,7 +258,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info cdc_data_class_info = { .class = USB_DEVICE_CLASS_CDC_DATA, .subclass = 0x00, .protocol = 0x00, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &cdc_data_class_driver }; diff --git a/class/cdc/usbh_cdc_ecm.c b/class/cdc/usbh_cdc_ecm.c index 7e63e654..73ef45f3 100644 --- a/class/cdc/usbh_cdc_ecm.c +++ b/class/cdc/usbh_cdc_ecm.c @@ -176,7 +176,7 @@ get_mac: } } - /* bit0 Promiscuous + /* bit0 Promiscuous * bit1 ALL Multicast * bit2 Directed * bit3 Broadcast @@ -333,7 +333,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info cdc_ecm_class_info = { .class = USB_DEVICE_CLASS_CDC, .subclass = CDC_ETHERNET_NETWORKING_CONTROL_MODEL, .protocol = CDC_COMMON_PROTOCOL_NONE, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &cdc_ecm_class_driver }; \ No newline at end of file diff --git a/class/cdc/usbh_cdc_ncm.c b/class/cdc/usbh_cdc_ncm.c index dd3e0d92..5970f8c8 100644 --- a/class/cdc/usbh_cdc_ncm.c +++ b/class/cdc/usbh_cdc_ncm.c @@ -410,7 +410,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info cdc_ncm_class_info = { .class = USB_DEVICE_CLASS_CDC, .subclass = CDC_NETWORK_CONTROL_MODEL, .protocol = CDC_COMMON_PROTOCOL_NONE, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &cdc_ncm_class_driver }; diff --git a/class/hid/usbh_hid.c b/class/hid/usbh_hid.c index f6b28ee0..f3b2546f 100644 --- a/class/hid/usbh_hid.c +++ b/class/hid/usbh_hid.c @@ -226,7 +226,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info hid_custom_class_info = { .class = USB_DEVICE_CLASS_HID, .subclass = 0x00, .protocol = 0x00, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &hid_class_driver }; diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index 116492dd..6755b859 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -705,8 +705,7 @@ CLASS_INFO_DEFINE const struct usbh_class_info hub_class_info = { .class = USB_DEVICE_CLASS_HUB, .subclass = 0, .protocol = 0, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &hub_class_driver }; #endif diff --git a/class/msc/usbh_msc.c b/class/msc/usbh_msc.c index b3937944..71e8e533 100644 --- a/class/msc/usbh_msc.c +++ b/class/msc/usbh_msc.c @@ -431,7 +431,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info msc_class_info = { .class = USB_DEVICE_CLASS_MASS_STORAGE, .subclass = MSC_SUBCLASS_SCSI, .protocol = MSC_PROTOCOL_BULK_ONLY, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &msc_class_driver }; diff --git a/class/template/usbh_xxx.c b/class/template/usbh_xxx.c index 1f792ae2..22b3636d 100644 --- a/class/template/usbh_xxx.c +++ b/class/template/usbh_xxx.c @@ -92,7 +92,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info xxx_class_info = { .class = 0, .subclass = 0, .protocol = 0, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &xxx_class_driver }; diff --git a/class/vendor/net/usbh_asix.c b/class/vendor/net/usbh_asix.c index 39ab4a93..3d5ce355 100644 --- a/class/vendor/net/usbh_asix.c +++ b/class/vendor/net/usbh_asix.c @@ -770,28 +770,23 @@ __WEAK void usbh_asix_stop(struct usbh_asix *asix_class) { } +static const uint16_t asix_id_table[][2] = { + { 0x0B95, 0x772B }, + { 0x0B95, 0x7720 }, + { 0, 0 }, +}; + static const struct usbh_class_driver asix_class_driver = { .driver_name = "asix", .connect = usbh_asix_connect, .disconnect = usbh_asix_disconnect }; -CLASS_INFO_DEFINE const struct usbh_class_info ax88772b_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, +CLASS_INFO_DEFINE const struct usbh_class_info asix_class_info = { + .match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS, .class = 0xff, .subclass = 0x00, .protocol = 0x00, - .vid = 0x0B95, - .pid = 0x772B, + .id_table = asix_id_table, .class_driver = &asix_class_driver -}; - -CLASS_INFO_DEFINE const struct usbh_class_info ax88772_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, - .class = 0xff, - .subclass = 0x00, - .protocol = 0x00, - .vid = 0x0B95, - .pid = 0x7720, - .class_driver = &asix_class_driver -}; +}; \ No newline at end of file diff --git a/class/vendor/net/usbh_rtl8152.c b/class/vendor/net/usbh_rtl8152.c index 73fdd740..1bad4378 100644 --- a/class/vendor/net/usbh_rtl8152.c +++ b/class/vendor/net/usbh_rtl8152.c @@ -2248,6 +2248,11 @@ __WEAK void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class) { } +static const uint16_t rtl_id_table[][2] = { + { 0x0BDA, 0x8152 }, + { 0, 0 }, +}; + static const struct usbh_class_driver rtl8152_class_driver = { .driver_name = "rtl8152", .connect = usbh_rtl8152_connect, @@ -2255,11 +2260,10 @@ static const struct usbh_class_driver rtl8152_class_driver = { }; CLASS_INFO_DEFINE const struct usbh_class_info rtl8152_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, + .match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS, .class = 0xff, .subclass = 0x00, .protocol = 0x00, - .vid = 0x0BDA, - .pid = 0x8152, + .id_table = rtl_id_table, .class_driver = &rtl8152_class_driver }; diff --git a/class/vendor/serial/usbh_ch34x.c b/class/vendor/serial/usbh_ch34x.c index 1effdba8..6321d813 100644 --- a/class/vendor/serial/usbh_ch34x.c +++ b/class/vendor/serial/usbh_ch34x.c @@ -335,6 +335,11 @@ __WEAK void usbh_ch34x_stop(struct usbh_ch34x *ch34x_class) { } +static const uint16_t ch34x_id_table[][2] = { + { 0x1A86, 0x7523 }, + { 0, 0 }, +}; + const struct usbh_class_driver ch34x_class_driver = { .driver_name = "ch34x", .connect = usbh_ch34x_connect, @@ -342,11 +347,10 @@ const struct usbh_class_driver ch34x_class_driver = { }; CLASS_INFO_DEFINE const struct usbh_class_info ch34x_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, + .match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS, .class = 0xff, - .subclass = 0xff, - .protocol = 0xff, - .vid = 0x1A86, - .pid = 0x7523, + .subclass = 0x00, + .protocol = 0x00, + .id_table = ch34x_id_table, .class_driver = &ch34x_class_driver }; \ No newline at end of file diff --git a/class/vendor/serial/usbh_cp210x.c b/class/vendor/serial/usbh_cp210x.c index 7dc45e64..e27161bd 100644 --- a/class/vendor/serial/usbh_cp210x.c +++ b/class/vendor/serial/usbh_cp210x.c @@ -274,6 +274,11 @@ __WEAK void usbh_cp210x_stop(struct usbh_cp210x *cp210x_class) { } +static const uint16_t cp210x_id_table[][2] = { + { 0x10C4, 0xEA60 }, + { 0, 0 }, +}; + const struct usbh_class_driver cp210x_class_driver = { .driver_name = "cp210x", .connect = usbh_cp210x_connect, @@ -281,11 +286,10 @@ const struct usbh_class_driver cp210x_class_driver = { }; CLASS_INFO_DEFINE const struct usbh_class_info cp210x_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, + .match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS, .class = 0xff, - .subclass = 0xff, - .protocol = 0xff, - .vid = 0x10C4, - .pid = 0xEA60, + .subclass = 0x00, + .protocol = 0x00, + .id_table = cp210x_id_table, .class_driver = &cp210x_class_driver }; \ No newline at end of file diff --git a/class/vendor/serial/usbh_ftdi.c b/class/vendor/serial/usbh_ftdi.c index 48d1c1bd..c84d2d8c 100644 --- a/class/vendor/serial/usbh_ftdi.c +++ b/class/vendor/serial/usbh_ftdi.c @@ -120,7 +120,7 @@ static int usbh_ftdi_set_data_format(struct usbh_ftdi *ftdi_class, uint8_t datab /** * D0-D7 databits BITS_7=7, BITS_8=8 * D8-D10 parity NONE=0, ODD=1, EVEN=2, MARK=3, SPACE=4 - * D11-D12 STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2 + * D11-D12 STOP_BIT_1=0, STOP_BIT_15=1, STOP_BIT_2=2 * D14 BREAK_OFF=0, BREAK_ON=1 **/ @@ -341,28 +341,23 @@ __WEAK void usbh_ftdi_stop(struct usbh_ftdi *ftdi_class) { } +static const uint16_t ftdi_id_table[][2] = { + { 0x0403, 0x6001 }, + { 0x0403, 0x6010 }, + { 0, 0 }, +}; + const struct usbh_class_driver ftdi_class_driver = { .driver_name = "ftdi", .connect = usbh_ftdi_connect, .disconnect = usbh_ftdi_disconnect }; -CLASS_INFO_DEFINE const struct usbh_class_info ftdi1_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, +CLASS_INFO_DEFINE const struct usbh_class_info ftdi_class_info = { + .match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS, .class = 0xff, - .subclass = 0xff, - .protocol = 0xff, - .vid = 0x0403, - .pid = 0x6001, - .class_driver = &ftdi_class_driver -}; - -CLASS_INFO_DEFINE const struct usbh_class_info ftdi2_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, - .class = 0xff, - .subclass = 0xff, - .protocol = 0xff, - .vid = 0x0403, - .pid = 0x6010, + .subclass = 0x00, + .protocol = 0x00, + .id_table = ftdi_id_table, .class_driver = &ftdi_class_driver }; \ No newline at end of file diff --git a/class/video/usbh_video.c b/class/video/usbh_video.c index 4a7bfe48..06910668 100644 --- a/class/video/usbh_video.c +++ b/class/video/usbh_video.c @@ -180,7 +180,7 @@ int usbh_video_open(struct usbh_video *video_class, * Get MIN request (probe) * Get CUR request (probe) * Set CUR request (commit) - * + * */ step = 0; ret = usbh_videostreaming_get_cur_probe(video_class); @@ -508,8 +508,7 @@ CLASS_INFO_DEFINE const struct usbh_class_info video_ctrl_class_info = { .class = USB_DEVICE_CLASS_VIDEO, .subclass = VIDEO_SC_VIDEOCONTROL, .protocol = VIDEO_PC_PROTOCOL_UNDEFINED, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &video_ctrl_class_driver }; @@ -518,7 +517,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info video_streaming_class_info = { .class = USB_DEVICE_CLASS_VIDEO, .subclass = VIDEO_SC_VIDEOSTREAMING, .protocol = VIDEO_PC_PROTOCOL_UNDEFINED, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &video_streaming_class_driver }; diff --git a/class/wireless/usbh_bluetooth.c b/class/wireless/usbh_bluetooth.c index a4b1c838..4c223dbf 100644 --- a/class/wireless/usbh_bluetooth.c +++ b/class/wireless/usbh_bluetooth.c @@ -224,7 +224,7 @@ void usbh_bluetooth_hci_rx_thread(void *argument) } } // clang-format off -delete : +delete : USB_LOG_INFO("Delete hc acl rx thread\r\n"); usb_osal_thread_delete(NULL); // clang-format on @@ -309,7 +309,7 @@ void usbh_bluetooth_hci_evt_rx_thread(void *argument) usb_osal_msleep(interval); } // clang-format off -delete : +delete : USB_LOG_INFO("Delete hc event rx thread\r\n"); usb_osal_thread_delete(NULL); // clang-format on @@ -351,7 +351,7 @@ void usbh_bluetooth_hci_acl_rx_thread(void *argument) } } // clang-format off -delete : +delete : USB_LOG_INFO("Delete hc acl rx thread\r\n"); usb_osal_thread_delete(NULL); // clang-format on @@ -377,13 +377,17 @@ static const struct usbh_class_driver bluetooth_class_driver = { }; #ifdef CONFIG_USBHOST_BLUETOOTH_HCI_H4 +static const uint16_t bluetooth_id_table[][2] = { + { 0x2fe3, 0x000c }, + { 0, 0 }, +}; + CLASS_INFO_DEFINE const struct usbh_class_info bluetooth_h4_nrf_class_info = { - .match_flags = USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT | USB_CLASS_MATCH_INTF_CLASS, + .match_flags = USB_CLASS_MATCH_VID_PID | USB_CLASS_MATCH_INTF_CLASS, .class = 0xff, .subclass = 0x00, .protocol = 0x00, - .vid = 0x2fe3, - .pid = 0x000c, + .id_table = bluetooth_id_table, .class_driver = &bluetooth_class_driver }; #else @@ -392,8 +396,7 @@ CLASS_INFO_DEFINE const struct usbh_class_info bluetooth_class_info = { .class = USB_DEVICE_CLASS_WIRELESS, .subclass = 0x01, .protocol = 0x01, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &bluetooth_class_driver }; #endif diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c index bc0e71f5..f4d2577d 100644 --- a/class/wireless/usbh_rndis.c +++ b/class/wireless/usbh_rndis.c @@ -579,7 +579,6 @@ CLASS_INFO_DEFINE const struct usbh_class_info rndis_class_info = { .class = USB_DEVICE_CLASS_WIRELESS, .subclass = 0x01, .protocol = 0x03, - .vid = 0x00, - .pid = 0x00, + .id_table = NULL, .class_driver = &rndis_class_driver }; diff --git a/core/usbh_core.c b/core/usbh_core.c index 521ea451..ca07730a 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -85,12 +85,6 @@ static const struct usbh_class_driver *usbh_find_class_driver(uint8_t class, uin struct usbh_class_info *index = NULL; for (index = usbh_class_info_table_begin; index < usbh_class_info_table_end; index++) { - if ((index->match_flags & USB_CLASS_MATCH_VENDOR) && !(index->vid == vid)) { - continue; - } - if ((index->match_flags & USB_CLASS_MATCH_PRODUCT) && !(index->pid == pid)) { - continue; - } if ((index->match_flags & USB_CLASS_MATCH_INTF_CLASS) && !(index->class == class)) { continue; } @@ -100,6 +94,16 @@ static const struct usbh_class_driver *usbh_find_class_driver(uint8_t class, uin if ((index->match_flags & USB_CLASS_MATCH_INTF_PROTOCOL) && !(index->protocol == protocol)) { continue; } + if (index->match_flags & USB_CLASS_MATCH_VID_PID && index->id_table) { + /* scan id table */ + uint32_t i; + for (i = 0; index->id_table[i][0] && index->id_table[i][0] != vid && index->id_table[i][1] != pid; i++) { + } + /* do not match, continue next */ + if (!index->id_table[i][0]) { + continue; + } + } return index->class_driver; } return NULL; diff --git a/core/usbh_core.h b/core/usbh_core.h index 369d8b6a..9ce081fc 100644 --- a/core/usbh_core.h +++ b/core/usbh_core.h @@ -30,6 +30,7 @@ extern "C" { #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_VID_PID (USB_CLASS_MATCH_VENDOR | USB_CLASS_MATCH_PRODUCT) #define CLASS_CONNECT(hport, i) ((hport)->config.intf[i].class_driver->connect(hport, i)) #define CLASS_DISCONNECT(hport, i) ((hport)->config.intf[i].class_driver->disconnect(hport, i)) @@ -43,7 +44,7 @@ extern "C" { #define CLASS_INFO_DEFINE __attribute__((section(".usbh_class_info"))) __USED __ALIGNED(1) #endif -#define USBH_GET_URB_INTERVAL(interval, speed) (speed < USB_SPEED_HIGH ? interval: (1 << (interval - 1))) +#define USBH_GET_URB_INTERVAL(interval, speed) (speed < USB_SPEED_HIGH ? interval : (1 << (interval - 1))) #define USBH_EP_INIT(ep, ep_desc) \ do { \ @@ -57,12 +58,11 @@ extern "C" { } while (0) struct usbh_class_info { - uint8_t match_flags; /* Used for product specific matches; range is inclusive */ - uint8_t class; /* Base device class code */ - uint8_t subclass; /* Sub-class, depends on base class. Eg. */ - uint8_t protocol; /* Protocol, depends on base class. Eg. */ - uint16_t vid; /* Vendor ID (for vendor/product specific devices) */ - uint16_t pid; /* Product ID (for vendor/product specific devices) */ + uint8_t match_flags; /* Used for product specific matches; range is inclusive */ + uint8_t class; /* Base device class code */ + uint8_t subclass; /* Sub-class, depends on base class. Eg. */ + uint8_t protocol; /* Protocol, depends on base class. Eg. */ + const uint16_t (*id_table)[2]; /* List of Vendor/Product ID pairs */ const struct usbh_class_driver *class_driver; }; @@ -239,11 +239,11 @@ int usbh_control_transfer(struct usbh_hubport *hport, struct usb_setup_packet *s /** * @brief Retrieves a USB string descriptor from a specific hub port. - * + * * This function is responsible for retrieving the USB string descriptor * with the specified index from the USB device connected to the given hub port. * The retrieved descriptor is stored in the output buffer provided. - * + * * @param hport Pointer to the USB hub port structure. * @param index Index of the string descriptor to retrieve. * @param output Pointer to the buffer where the retrieved descriptor will be stored. @@ -253,11 +253,11 @@ int usbh_get_string_desc(struct usbh_hubport *hport, uint8_t index, uint8_t *out /** * @brief Sets the alternate setting for a USB interface on a specific hub port. - * + * * This function is responsible for setting the alternate setting of the * specified USB interface on the USB device connected to the given hub port. * The interface and alternate setting are identified by the respective parameters. - * + * * @param hport Pointer to the USB hub port structure. * @param intf Interface number to set the alternate setting for. * @param altsetting Alternate setting value to set for the interface.