diff options
author | Richard Hughes <richard@hughsie.com> | 2015-11-10 11:48:46 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2015-11-10 11:49:23 +0000 |
commit | 6cdb5bd7fd82d3ec3b5ef06b7f849d1269a95069 (patch) | |
tree | c874384a31b75c376e6079eef8761f6b308be710 | |
parent | 04a67639662ed0988877a051945f3b0cd4ef431f (diff) | |
download | gusb-6cdb5bd7fd82d3ec3b5ef06b7f849d1269a95069.tar.gz |
Add g_usb_device_set_interface_alt()
I did think of adding this as g_usb_interface_set_alt_setting() but the other
claim() and release() methods are already on the the device object.
This lets us set an alternate setting after we've claimed an interface which
allows us to select non-default targets when flashing DFU-capable devices.
-rw-r--r-- | gusb/gusb-device.c | 32 | ||||
-rw-r--r-- | gusb/gusb-device.h | 4 |
2 files changed, 36 insertions, 0 deletions
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c index cd49e16..a13e092 100644 --- a/gusb/gusb-device.c +++ b/gusb/gusb-device.c @@ -809,6 +809,38 @@ g_usb_device_release_interface (GUsbDevice *device, } /** + * g_usb_device_set_interface_alt: + * @device: a #GUsbDevice + * @interface: bInterfaceNumber of the interface you wish to release + * @alt: alternative setting number + * @error: a #GError, or %NULL + * + * Sets an alternate setting on an interface. + * + * Return value: %TRUE on success + * + * Since: 0.2.8 + **/ +gboolean +g_usb_device_set_interface_alt (GUsbDevice *device, gint interface, + guint8 alt, GError **error) +{ + gint rc; + + g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE); + g_return_val_if_fail (error == NULL || *error == NULL, FALSE); + + if (device->priv->handle == NULL) + return g_usb_device_not_open_error (device, error); + + rc = libusb_set_interface_alt_setting (device->priv->handle, interface, (gint) alt); + if (rc != LIBUSB_SUCCESS) + return g_usb_device_libusb_error_to_gerror (device, rc, error); + + return TRUE; +} + +/** * g_usb_device_get_string_descriptor: * @desc_index: the index for the string descriptor to retreive * @error: a #GError, or %NULL diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h index 545def5..91300af 100644 --- a/gusb/gusb-device.h +++ b/gusb/gusb-device.h @@ -206,6 +206,10 @@ gboolean g_usb_device_release_interface (GUsbDevice *device, gint interface, GUsbDeviceClaimInterfaceFlags flags, GError **error); +gboolean g_usb_device_set_interface_alt (GUsbDevice *device, + gint interface, + guint8 alt, + GError **error); gchar *g_usb_device_get_string_descriptor (GUsbDevice *device, guint8 desc_index, |