This is an automated email from Gerrit.

"Weijie Gao <hackpas...@gmail.com>" just uploaded a new patch set to Gerrit, 
which you can find at https://review.openocd.org/c/openocd/+/7588

-- gerrit

commit 1b3a9d61647274c9bcfdc5ede3605b31ee9d106b
Author: Weijie Gao <hackpas...@gmail.com>
Date:   Mon Apr 10 09:52:42 2023 +0800

    jtag/drivers/ftdi: make mpsse-libusb optional in build
    
    This is one of the patch series that will adding Windows D2XX driver
    support for ftdi mpsse-based jtag adapter drivers.
    
    The support for mpsse-libusb can be optional after add support for d2xx.
    So BUILD_FTDI macros are added to libusb-specific codes.
    
    mpsse_open/mpsse_close are also renamed by adding _libusb to the function
    name to match their purpose.
    
    Signed-off-by: Weijie Gao <hackpas...@gmail.com>
    Change-Id: I6a904ff03704e2930f4aeb17f72a5d4a2f1c892c

diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c
index 6356a4929b..618fc82645 100644
--- a/src/jtag/drivers/ftdi.c
+++ b/src/jtag/drivers/ftdi.c
@@ -79,15 +79,18 @@
 #define SWD_MODE (LSB_FIRST | POS_EDGE_IN | NEG_EDGE_OUT)
 
 static char *ftdi_device_desc;
-static uint8_t ftdi_channel;
 static uint8_t ftdi_jtag_mode = JTAG_MODE;
 
 static bool swd_mode;
 
+#if BUILD_FTDI == 1
+static uint8_t ftdi_channel;
+
 #define MAX_USB_IDS 8
 /* vid = pid = 0 marks the end of the list */
 static uint16_t ftdi_vid[MAX_USB_IDS + 1] = { 0 };
 static uint16_t ftdi_pid[MAX_USB_IDS + 1] = { 0 };
+#endif
 
 static struct mpsse_ctx *mpsse_ctx;
 
@@ -653,13 +656,15 @@ static int ftdi_initialize(void)
        else
                LOG_DEBUG("ftdi interface using shortest path jtag state 
transitions");
 
+#if BUILD_FTDI == 1
        if (!ftdi_vid[0] && !ftdi_pid[0]) {
                LOG_ERROR("Please specify ftdi vid_pid");
                return ERROR_JTAG_INIT_FAILED;
        }
 
-       mpsse_ctx = mpsse_open(ftdi_vid, ftdi_pid, ftdi_device_desc,
-                               adapter_get_required_serial(), 
adapter_usb_get_location(), ftdi_channel);
+       mpsse_ctx = mpsse_libusb_open(ftdi_vid, ftdi_pid, ftdi_device_desc,
+                                       adapter_get_required_serial(), 
adapter_usb_get_location(), ftdi_channel);
+#endif
        if (!mpsse_ctx)
                return ERROR_JTAG_INIT_FAILED;
 
@@ -689,7 +694,9 @@ static int ftdi_initialize(void)
 
 static int ftdi_quit(void)
 {
-       mpsse_close(mpsse_ctx);
+#if BUILD_FTDI == 1
+       mpsse_libusb_close(mpsse_ctx);
+#endif
 
        struct signal *sig = signals;
        while (sig) {
@@ -718,6 +725,7 @@ COMMAND_HANDLER(ftdi_handle_device_desc_command)
        return ERROR_OK;
 }
 
+#if BUILD_FTDI == 1
 COMMAND_HANDLER(ftdi_handle_channel_command)
 {
        if (CMD_ARGC == 1)
@@ -727,6 +735,7 @@ COMMAND_HANDLER(ftdi_handle_channel_command)
 
        return ERROR_OK;
 }
+#endif
 
 COMMAND_HANDLER(ftdi_handle_layout_init_command)
 {
@@ -864,6 +873,7 @@ COMMAND_HANDLER(ftdi_handle_get_signal_command)
        return ERROR_OK;
 }
 
+#if BUILD_FTDI == 1
 COMMAND_HANDLER(ftdi_handle_vid_pid_command)
 {
        if (CMD_ARGC > MAX_USB_IDS * 2) {
@@ -893,6 +903,7 @@ COMMAND_HANDLER(ftdi_handle_vid_pid_command)
 
        return ERROR_OK;
 }
+#endif
 
 COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command)
 {
@@ -925,6 +936,7 @@ static const struct command_registration 
ftdi_subcommand_handlers[] = {
                .help = "set the USB device description of the FTDI device",
                .usage = "description_string",
        },
+#if BUILD_FTDI == 1
        {
                .name = "channel",
                .handler = &ftdi_handle_channel_command,
@@ -932,6 +944,7 @@ static const struct command_registration 
ftdi_subcommand_handlers[] = {
                .help = "set the channel of the FTDI device that is used as 
JTAG",
                .usage = "(0-3)",
        },
+#endif
        {
                .name = "layout_init",
                .handler = &ftdi_handle_layout_init_command,
@@ -962,6 +975,7 @@ static const struct command_registration 
ftdi_subcommand_handlers[] = {
                .help = "read the value of a layout-specific signal",
                .usage = "name",
        },
+#if BUILD_FTDI == 1
        {
                .name = "vid_pid",
                .handler = &ftdi_handle_vid_pid_command,
@@ -969,6 +983,7 @@ static const struct command_registration 
ftdi_subcommand_handlers[] = {
                .help = "the vendor ID and product ID of the FTDI device",
                .usage = "(vid pid)*",
        },
+#endif
        {
                .name = "tdo_sample_edge",
                .handler = &ftdi_handle_tdo_sample_edge_command,
diff --git a/src/jtag/drivers/mpsse-libusb.c b/src/jtag/drivers/mpsse-libusb.c
index eafce098fa..15dc61bbdb 100644
--- a/src/jtag/drivers/mpsse-libusb.c
+++ b/src/jtag/drivers/mpsse-libusb.c
@@ -300,7 +300,7 @@ error:
        return false;
 }
 
-struct mpsse_ctx *mpsse_open(const uint16_t vids[], const uint16_t pids[], 
const char *description,
+struct mpsse_ctx *mpsse_libusb_open(const uint16_t vids[], const uint16_t 
pids[], const char *description,
        const char *serial, const char *location, int channel)
 {
        struct mpsse_ctx_libusb *ctx = calloc(1, sizeof(*ctx));
@@ -367,11 +367,11 @@ struct mpsse_ctx *mpsse_open(const uint16_t vids[], const 
uint16_t pids[], const
 
        return &ctx->cctx;
 error:
-       mpsse_close(&ctx->cctx);
+       mpsse_libusb_close(&ctx->cctx);
        return 0;
 }
 
-void mpsse_close(struct mpsse_ctx *ctx)
+void mpsse_libusb_close(struct mpsse_ctx *ctx)
 {
        struct mpsse_ctx_libusb *ctx_libusb = container_of(ctx, struct 
mpsse_ctx_libusb, cctx);
 
diff --git a/src/jtag/drivers/mpsse.h b/src/jtag/drivers/mpsse.h
index a017aff002..c147906b60 100644
--- a/src/jtag/drivers/mpsse.h
+++ b/src/jtag/drivers/mpsse.h
@@ -29,9 +29,11 @@ enum ftdi_chip_type {
 struct mpsse_ctx;
 
 /* Device handling */
-struct mpsse_ctx *mpsse_open(const uint16_t *vid, const uint16_t *pid, const 
char *description,
+#ifdef BUILD_FTDI
+struct mpsse_ctx *mpsse_libusb_open(const uint16_t *vid, const uint16_t *pid, 
const char *description,
        const char *serial, const char *location, int channel);
-void mpsse_close(struct mpsse_ctx *ctx);
+void mpsse_libusb_close(struct mpsse_ctx *ctx);
+#endif
 bool mpsse_is_high_speed(struct mpsse_ctx *ctx);
 
 /* Command queuing. These correspond to the MPSSE commands with the same 
names, but no need to care

-- 

Reply via email to