Browse Source

ftdi: Split most of ft232r_open into a ftdi_common_open function

Luke Dashjr 11 years ago
parent
commit
8b35240dc5
1 changed files with 17 additions and 5 deletions
  1. 17 5
      ft232r.c

+ 17 - 5
ft232r.c

@@ -89,7 +89,8 @@ struct ft232r_device_handle {
 	uint16_t obufsz;
 };
 
-struct ft232r_device_handle *ft232r_open(const struct lowlevel_device_info * const info)
+static
+struct ft232r_device_handle *ftdi_common_open(const struct lowlevel_device_info * const info)
 {
 	libusb_device * const dev = info->lowl_data;
 	
@@ -111,10 +112,6 @@ struct ft232r_device_handle *ft232r_open(const struct lowlevel_device_info * con
 		applog(LOG_ERR, "ft232r_open: Error claiming interface");
 		return NULL;
 	}
-	if (libusb_control_transfer(devh, FTDI_REQTYPE_OUT, FTDI_REQUEST_SET_BAUDRATE, FTDI_BAUDRATE_3M, NULL, 0, FTDI_TIMEOUT) < 0) {
-		applog(LOG_ERR, "ft232r_open: Error performing control transfer");
-		return NULL;
-	}
 
 	struct libusb_config_descriptor *cfg;
 	if (libusb_get_config_descriptor(dev, 0, &cfg)) {
@@ -138,6 +135,21 @@ struct ft232r_device_handle *ft232r_open(const struct lowlevel_device_info * con
 	return ftdi;
 }
 
+struct ft232r_device_handle *ft232r_open(const struct lowlevel_device_info * const info)
+{
+	struct ft232r_device_handle * const ftdi = ftdi_common_open(info);
+	if (!ftdi)
+		return NULL;
+	
+	if (libusb_control_transfer(ftdi->h, FTDI_REQTYPE_OUT, FTDI_REQUEST_SET_BAUDRATE, FTDI_BAUDRATE_3M, NULL, 0, FTDI_TIMEOUT) < 0) {
+		applog(LOG_ERR, "ft232r_open: Error performing control transfer");
+		ft232r_close(ftdi);
+		return NULL;
+	}
+	
+	return ftdi;
+}
+
 void ft232r_close(struct ft232r_device_handle *dev)
 {
 	libusb_release_interface(dev->h, 0);