drivers: Rename 'libusb1_common' to 'libusb_helper'
[fw/openocd] / src / jtag / drivers / ft232r.c
index 0389427d881fe553658177cd0d2b3ea6de930903..4812362a375ef2bc0cd86b5af97f8e77f7485a84 100644 (file)
@@ -29,7 +29,7 @@
 #include <jtag/interface.h>
 #include <jtag/commands.h>
 #include <helper/time_support.h>
-#include "libusb1_common.h"
+#include "libusb_helper.h"
 
 /* system includes */
 #include <string.h>
@@ -71,7 +71,7 @@
 static char *ft232r_serial_desc;
 static uint16_t ft232r_vid = 0x0403; /* FTDI */
 static uint16_t ft232r_pid = 0x6001; /* FT232R */
-static jtag_libusb_device_handle *adapter;
+static struct libusb_device_handle *adapter;
 
 static uint8_t *ft232r_output;
 static size_t ft232r_output_len;
@@ -132,11 +132,11 @@ static int ft232r_send_recv(void)
                        bytes_to_write = rxfifo_free;
 
                if (bytes_to_write) {
-                       int n = jtag_libusb_bulk_write(adapter, IN_EP,
-                               (char *) ft232r_output + total_written,
-                               bytes_to_write, 1000);
+                       int n;
 
-                       if (n == 0) {
+                       if (jtag_libusb_bulk_write(adapter, IN_EP,
+                                                  (char *) ft232r_output + total_written,
+                                                  bytes_to_write, 1000, &n) != ERROR_OK) {
                                LOG_ERROR("usb bulk write failed");
                                return ERROR_JTAG_DEVICE_ERROR;
                        }
@@ -147,12 +147,10 @@ static int ft232r_send_recv(void)
 
                /* Read */
                uint8_t reply[64];
+               int n;
 
-               int n = jtag_libusb_bulk_read(adapter, OUT_EP,
-                       (char *) reply,
-                       sizeof(reply), 1000);
-
-               if (n == 0) {
+               if (jtag_libusb_bulk_read(adapter, OUT_EP, (char *) reply,
+                                         sizeof(reply), 1000, &n) != ERROR_OK) {
                        LOG_ERROR("usb bulk read failed");
                        return ERROR_JTAG_DEVICE_ERROR;
                }
@@ -270,7 +268,7 @@ static int ft232r_init(void)
        else /* serial port will be restored after jtag: */
                libusb_set_auto_detach_kernel_driver(adapter, 1); /* 1: DONT_DETACH_SIO_MODULE */
 
-       if (jtag_libusb_claim_interface(adapter, 0)) {
+       if (libusb_claim_interface(adapter, 0)) {
                LOG_ERROR("unable to claim interface");
                return ERROR_JTAG_INIT_FAILED;
        }
@@ -332,7 +330,7 @@ static int ft232r_quit(void)
                }
        }
 
-       if (jtag_libusb_release_interface(adapter, 0) != 0)
+       if (libusb_release_interface(adapter, 0) != 0)
                LOG_ERROR("usb release interface failed");
 
        jtag_libusb_close(adapter);
@@ -675,7 +673,7 @@ static int syncbb_execute_tms(struct jtag_command *cmd)
        unsigned num_bits = cmd->cmd.tms->num_bits;
        const uint8_t *bits = cmd->cmd.tms->bits;
 
-       DEBUG_JTAG_IO("TMS: %d bits", num_bits);
+       LOG_DEBUG_IO("TMS: %d bits", num_bits);
 
        int tms = 0;
        for (unsigned i = 0; i < num_bits; i++) {
@@ -914,17 +912,21 @@ static int syncbb_execute_queue(void)
        return retval;
 }
 
-struct jtag_interface ft232r_interface = {
-       .name = "ft232r",
-       .commands = ft232r_command_handlers,
-       .transports = jtag_only,
+static struct jtag_interface ft232r_interface = {
        .supported = DEBUG_CAP_TMS_SEQ,
-
        .execute_queue = syncbb_execute_queue,
+};
+
+struct adapter_driver ft232r_adapter_driver = {
+       .name = "ft232r",
+       .transports = jtag_only,
+       .commands = ft232r_command_handlers,
 
-       .speed = ft232r_speed,
        .init = ft232r_init,
        .quit = ft232r_quit,
-       .speed_div = ft232r_speed_div,
+       .speed = ft232r_speed,
        .khz = ft232r_khz,
+       .speed_div = ft232r_speed_div,
+
+       .jtag_ops = &ft232r_interface,
 };