diff options
-rw-r--r-- | libusb/core.c | 12 | ||||
-rw-r--r-- | libusb/libusb.h | 20 | ||||
-rw-r--r-- | libusb/libusbi.h | 1 |
3 files changed, 33 insertions, 0 deletions
diff --git a/libusb/core.c b/libusb/core.c index 840ab0c..3969fd5 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -524,6 +524,7 @@ struct libusb_device *usbi_alloc_device(struct libusb_context *ctx, dev->ctx = ctx; dev->refcnt = 1; dev->session_data = session_id; + dev->speed = LIBUSB_SPEED_UNKNOWN; memset(&dev->os_priv, 0, priv_size); usbi_mutex_lock(&ctx->usb_devs_lock); @@ -737,6 +738,17 @@ uint8_t API_EXPORTED libusb_get_device_address(libusb_device *dev) return dev->device_address; } +/** \ingroup dev + * Get the negotiated speed of the device. + * \param dev a device + * \returns the device speed or LIBUSB_SPEED_UNKNOWN if the OS doesn't know or + * support returning the negotiated speed. + */ +enum libusb_speed API_EXPORTED libusb_get_device_speed(libusb_device *dev) +{ + return dev->speed; +} + static const struct libusb_endpoint_descriptor *find_endpoint( struct libusb_config_descriptor *config, unsigned char endpoint) { diff --git a/libusb/libusb.h b/libusb/libusb.h index d466109..9e97b16 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -675,6 +675,25 @@ typedef struct libusb_device libusb_device; */ typedef struct libusb_device_handle libusb_device_handle; +/** \ingroup dev + * Speed codes. Indicates the speed at which the device is operating. + */ +enum libusb_speed { + /** The OS doesn't report or know the device speed. */ + LIBUSB_SPEED_UNKNOWN = 0, + + /** The device is operating at low speed (1.5MBit/s). */ + LIBUSB_SPEED_LOW = 1, + + /** The device is operating at full speed (12MBit/s). */ + LIBUSB_SPEED_FULL = 2, + + /** The device is operating at high speed (480MBit/s). */ + LIBUSB_SPEED_HIGH = 3, + + /** The device is operating at super speed (5000MBit/s). */ + LIBUSB_SPEED_SUPER = 4, +}; /** \ingroup misc * Error codes. Most libusb functions return 0 on success or one of these @@ -892,6 +911,7 @@ uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev); libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev); int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length); uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev); +enum libusb_speed LIBUSB_CALL libusb_get_device_speed(libusb_device *dev); int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev, unsigned char endpoint); int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev, diff --git a/libusb/libusbi.h b/libusb/libusbi.h index c7cf83b..0ea4878 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -279,6 +279,7 @@ struct libusb_device { struct libusb_device* parent_dev; uint8_t device_address; uint8_t num_configurations; + enum libusb_speed speed; struct list_head list; unsigned long session_data; |