Skip to content

Commit

Permalink
Add API support for LIBUSB_SPEED_SUPER_PLUS_X2 20Gbps USB 3.2 gen 2x2
Browse files Browse the repository at this point in the history
Implement detection on darwin and linux_usbfs, and report it in xusb.

Closes #1477
  • Loading branch information
hjmallon authored and tormodvolden committed May 7, 2024
1 parent f00f06e commit 5b17c38
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions android/examples/unrooted_android.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ static void print_device(libusb_device *dev, libusb_device_handle *handle)
case LIBUSB_SPEED_HIGH: speed = "480M"; break;
case LIBUSB_SPEED_SUPER: speed = "5G"; break;
case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break;
case LIBUSB_SPEED_SUPER_PLUS_X2: speed = "20G"; break;
default: speed = "Unknown";
}

Expand Down
1 change: 1 addition & 0 deletions examples/testlibusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static void print_device(libusb_device *dev, libusb_device_handle *handle)
case LIBUSB_SPEED_HIGH: speed = "480M"; break;
case LIBUSB_SPEED_SUPER: speed = "5G"; break;
case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break;
case LIBUSB_SPEED_SUPER_PLUS_X2: speed = "20G"; break;
default: speed = "Unknown";
}

Expand Down
12 changes: 9 additions & 3 deletions examples/xusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
// in libusb_config_descriptor => catter for that
#define usb_interface interface

#ifndef ARRAYSIZE
#define ARRAYSIZE(array) (sizeof(array) / sizeof(array[0]))
#endif

// Global variables
static bool binary_dump = false;
static bool extra_info = false;
Expand Down Expand Up @@ -856,8 +860,9 @@ static int test_device(uint16_t vid, uint16_t pid)
int i, j, k, r;
int iface, nb_ifaces, first_iface = -1;
struct libusb_device_descriptor dev_desc;
const char* const speed_name[6] = { "Unknown", "1.5 Mbit/s (USB LowSpeed)", "12 Mbit/s (USB FullSpeed)",
"480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)", "10000 Mbit/s (USB SuperSpeedPlus)" };
const char* const speed_name[] = { "Unknown", "1.5 Mbit/s (USB LowSpeed)", "12 Mbit/s (USB FullSpeed)",
"480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)", "10000 Mbit/s (USB SuperSpeedPlus)",
"20000 Mbit/s (USB SuperSpeedPlus x2)" };
unsigned char string[128];
uint8_t string_index[3]; // indexes of the string descriptors
uint8_t endpoint_in = 0, endpoint_out = 0; // default IN and OUT endpoints
Expand All @@ -884,7 +889,8 @@ static int test_device(uint16_t vid, uint16_t pid)
printf(" (from root hub)\n");
}
r = libusb_get_device_speed(dev);
if ((r<0) || (r>5)) r=0;
if ((r < 0) || ((size_t)r >= ARRAYSIZE(speed_name)))
r = 0;
printf(" speed: %s\n", speed_name[r]);
}

Expand Down
5 changes: 4 additions & 1 deletion libusb/libusb.h
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,10 @@ enum libusb_speed {
LIBUSB_SPEED_SUPER = 4,

/** The device is operating at super speed plus (10000MBit/s). */
LIBUSB_SPEED_SUPER_PLUS = 5
LIBUSB_SPEED_SUPER_PLUS = 5,

/** The device is operating at super speed plus x2 (20000MBit/s). */
LIBUSB_SPEED_SUPER_PLUS_X2 = 6,
};

/** \ingroup libusb_misc
Expand Down
3 changes: 3 additions & 0 deletions libusb/os/darwin_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,9 @@ static enum libusb_error process_new_device (struct libusb_context *ctx, struct
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101200
case kUSBDeviceSpeedSuperPlus: dev->speed = LIBUSB_SPEED_SUPER_PLUS; break;
#endif
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101500
case kUSBDeviceSpeedSuperPlusBy2: dev->speed = LIBUSB_SPEED_SUPER_PLUS_X2; break;
#endif
default:
usbi_warn (ctx, "Got unknown device speed %d", devSpeed);
Expand Down
1 change: 1 addition & 0 deletions libusb/os/linux_usbfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,7 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
case 480: dev->speed = LIBUSB_SPEED_HIGH; break;
case 5000: dev->speed = LIBUSB_SPEED_SUPER; break;
case 10000: dev->speed = LIBUSB_SPEED_SUPER_PLUS; break;
case 20000: dev->speed = LIBUSB_SPEED_SUPER_PLUS_X2; break;
default:
usbi_warn(ctx, "unknown device speed: %d Mbps", speed);
}
Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LIBUSB_NANO 11897
#define LIBUSB_NANO 11898

0 comments on commit 5b17c38

Please sign in to comment.