From 28ce1b7021aff4a0cb227181b4eacf6db493522f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Sat, 23 Jan 2010 21:38:00 +0000 Subject: [PATCH] simplify usb cable driver declaring to aviod a lot of copy & paste cruft git-svn-id: https://urjtag.svn.sourceforge.net/svnroot/urjtag/trunk@1718 b68d4a1b-bc3d-0410-92ed-d4ac073336b7 --- urjtag/ChangeLog | 8 +- urjtag/src/tap/cable/ft2232.c | 197 ++----------------------- urjtag/src/tap/cable/generic_usbconn.h | 3 + urjtag/src/tap/cable/jlink.c | 9 +- urjtag/src/tap/cable/usbblaster.c | 60 +------- urjtag/src/tap/cable/xpc.c | 18 +-- urjtag/src/tap/usbconn/libftdx.h | 18 +++ 7 files changed, 48 insertions(+), 265 deletions(-) diff --git a/urjtag/ChangeLog b/urjtag/ChangeLog index c9282020..90270753 100644 --- a/urjtag/ChangeLog +++ b/urjtag/ChangeLog @@ -59,7 +59,13 @@ * src/tap/cable/ft2232.c, src/tap/cable/generic_usbconn.c, src/tap/cable/generic_usbconn.h, src/tap/cable/jlink.c, src/tap/cable/usbblaster.c, src/tap/cable/xpc.c: Constify the usb cable - drivers + drivers. + + * src/tap/cable/ft2232.c, src/tap/cable/generic_usbconn.h, + src/tap/cable/jlink.c, src/tap/cable/usbblaster.c, src/tap/cable/xpc.c, + src/tap/usbconn/libftdx.h: Create some helper macros for declaring USB + cable drivers to unify duplicate code and to help with FTDI part decls. + Avoids defining USB cable drivers when support has been disabled. 2010-01-22 Mike Frysinger diff --git a/urjtag/src/tap/cable/ft2232.c b/urjtag/src/tap/cable/ft2232.c index 6eb4de83..2735c212 100644 --- a/urjtag/src/tap/cable/ft2232.c +++ b/urjtag/src/tap/cable/ft2232.c @@ -1864,20 +1864,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_ft2232_ftdi = { - "FT2232", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0000, /* VID */ - 0x0000 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_ft2232_ftd2xx = { - "FT2232", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0000, /* VID */ - 0x0000 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0000, 0x0000, "-mpsse", "FT2232", ft2232) const urj_cable_driver_t urj_tap_cable_ft2232_armusbocd_driver = { "ARM-USB-OCD", @@ -1897,34 +1884,8 @@ const urj_cable_driver_t urj_tap_cable_ft2232_armusbocd_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_armusbocd_ftdi = { - "ARM-USB-OCD", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x15BA, /* VID */ - 0x0003 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_armusbocd_ftd2xx = { - "ARM-USB-OCD", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x15BA, /* VID */ - 0x0003 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_armusbocdtiny_ftdi = { - "ARM-USB-OCD", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x15BA, /* VID */ - 0x0004 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_armusbocdtiny_ftd2xx = { - "ARM-USB-OCD", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x15BA, /* VID */ - 0x0004 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x15BA, 0x0003, "-mpsse", "ARM-USB-OCD", armusbocd) +URJ_DECLARE_FTDX_CABLE(0x15BA, 0x0004, "-mpsse", "ARM-USB-OCD", armusbocdtiny) const urj_cable_driver_t urj_tap_cable_ft2232_armusbtiny_h_driver = { "ARM-USB-OCD-H", @@ -1944,20 +1905,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_armusbtiny_h_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_armusbtiny_h_ftdi = { - "ARM-USB-TINY-H", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x15BA, /* VID */ - 0x002A /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_armusbtiny_h_ftd2xx = { - "ARM-USB-TINY-H", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x15BA, /* VID */ - 0x002A /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x15BA, 0x002A, "-mpsse", "ARM-USB-TINY-H", armusbtiny_h) const urj_cable_driver_t urj_tap_cable_ft2232_gnice_driver = { "gnICE", @@ -1977,21 +1925,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_gnice_driver = { ft2232_flush, ft2232_usbcable_help }; - -const urj_usbconn_cable_t urj_tap_cable_usbconn_gnice_ftdi = { - "gnICE", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0456, /* VID */ - 0xF000 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_gnice_ftd2xx = { - "gnICE", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0456, /* VID */ - 0xF000 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0456, 0xF000, "-mpsse", "gnICE", gnice) const urj_cable_driver_t urj_tap_cable_ft2232_gniceplus_driver = { "gnICE+", @@ -2011,21 +1945,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_gniceplus_driver = { ft2232_flush, ft2232_usbcable_help }; - -const urj_usbconn_cable_t urj_tap_cable_usbconn_gniceplus_ftdi = { - "gnICE+", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0456, /* VID */ - 0xF001 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_gniceplus_ftd2xx = { - "gnICE+", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0456, /* VID */ - 0xF001 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0456, 0xF001, "-mpsse", "gnICE+", gniceplus) const urj_cable_driver_t urj_tap_cable_ft2232_jtagkey_driver = { "JTAGkey", @@ -2045,20 +1965,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_jtagkey_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_jtagkey_ftdi = { - "JTAGkey", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xCFF8 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_jtagkey_ftd2xx = { - "JTAGkey", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xCFF8 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0403, 0xCFF8, "-mpsse", "JTAGkey", jtagkey) const urj_cable_driver_t urj_tap_cable_ft2232_oocdlinks_driver = { "OOCDLink-s", @@ -2078,20 +1985,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_oocdlinks_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_oocdlinks_ftdi = { - "OOCDLink-s", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xbaf8 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_oocdlinks_ftd2xx = { - "OOCDLink-s", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xbaf8 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0403, 0xbaf8, "-mpsse", "OOCDLink-s", oocdlinks) const urj_cable_driver_t urj_tap_cable_ft2232_turtelizer2_driver = { "Turtelizer2", @@ -2111,20 +2005,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_turtelizer2_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_turtelizer2_ftdi = { - "Turtelizer2", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xBDC8 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_turtelizer2_ftd2xx = { - "Turtelizer2", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xBDC8 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0403, 0xBDC8, "-mpsse", "Turtelizer2", turtelizer2) const urj_cable_driver_t urj_tap_cable_ft2232_usbtojtagif_driver = { "USB-to-JTAG-IF", @@ -2144,20 +2025,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_usbtojtagif_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usbtojtagif_ftdi = { - "USB-to-JTAG-IF", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0000, /* VID */ - 0x0000 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usbtojtagif_ftd2xx = { - "USB-to-JTAG-IF", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0000, /* VID */ - 0x0000 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0000, 0x0000, "-mpsse", "USB-to-JTAG-IF", usbtojtagif) const urj_cable_driver_t urj_tap_cable_ft2232_signalyzer_driver = { "Signalyzer", @@ -2177,20 +2045,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_signalyzer_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_signalyzer_ftdi = { - "Signalyzer", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xbca1 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_signalyzer_ftd2xx = { - "Signalyzer", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xbca1 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0403, 0xbca1, "-mpsse", "Signalyzer", signalyzer) const urj_cable_driver_t urj_tap_cable_ft2232_flyswatter_driver = { "Flyswatter", @@ -2210,20 +2065,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_flyswatter_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_flyswatter_ftdi = { - "Flyswatter", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0x6010 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_flyswatter_ftd2xx = { - "Flyswatter", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0x6010 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0403, 0x6010, "-mpsse", "Flyswatter", flyswatter) const urj_cable_driver_t urj_tap_cable_ft2232_usbscarab2_driver = { "usbScarab2", @@ -2243,20 +2085,7 @@ const urj_cable_driver_t urj_tap_cable_ft2232_usbscarab2_driver = { ft2232_flush, ft2232_usbcable_help }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usbscarab2_ftdi = { - "usbScarab2", /* cable name */ - "usbScarab2", /* string pattern, not used */ - "ftdi-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xbbe0 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usbscarab2_ftd2xx = { - "usbScarab2", /* cable name */ - "usbScarab2", /* string pattern, not used */ - "ftd2xx-mpsse", /* default usbconn driver */ - 0x0403, /* VID */ - 0xbbe0 /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x0403, 0xbbe0, "-mpsse", "usbScarab2", usbscarab2) /* diff --git a/urjtag/src/tap/cable/generic_usbconn.h b/urjtag/src/tap/cable/generic_usbconn.h index ac343646..8dfc5ce5 100644 --- a/urjtag/src/tap/cable/generic_usbconn.h +++ b/urjtag/src/tap/cable/generic_usbconn.h @@ -40,4 +40,7 @@ void urj_tap_cable_generic_usbconn_done (urj_cable_t *cable); void urj_tap_cable_generic_usbconn_help (urj_log_level_t ll, const char *name); void urj_tap_cable_generic_usbconn_free (urj_cable_t *cable); +#define URJ_DECLARE_USBCONN_CABLE(vid, pid, driver, name, cable) \ +const urj_usbconn_cable_t urj_tap_cable_usbconn_##cable = { name, NULL, driver, vid, pid }; + #endif /* URJ_TAP_CABLE_GENERIC_H */ diff --git a/urjtag/src/tap/cable/jlink.c b/urjtag/src/tap/cable/jlink.c index a7ee3f36..99e08323 100644 --- a/urjtag/src/tap/cable/jlink.c +++ b/urjtag/src/tap/cable/jlink.c @@ -606,11 +606,4 @@ const urj_cable_driver_t urj_tap_cable_jlink_driver = { urj_tap_cable_generic_flush_using_transfer, urj_tap_cable_generic_usbconn_help }; - -const urj_usbconn_cable_t urj_tap_cable_usbconn_jlink = { - "jlink", /* cable name */ - NULL, /* string pattern, not used */ - "libusb", /* usbconn driver */ - 0x1366, /* VID */ - 0x0101 /* PID */ -}; +URJ_DECLARE_USBCONN_CABLE(0x1366, 0x0101, "libusb", "jlink", jlink) diff --git a/urjtag/src/tap/cable/usbblaster.c b/urjtag/src/tap/cable/usbblaster.c index b4dbe18a..fee2e670 100644 --- a/urjtag/src/tap/cable/usbblaster.c +++ b/urjtag/src/tap/cable/usbblaster.c @@ -529,59 +529,7 @@ const urj_cable_driver_t urj_tap_cable_usbblaster_driver = { usbblaster_flush, usbblaster_help, }; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usbblaster_ftdi = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi", /* default usbconn driver */ - 0x09FB, /* VID */ - 0x6001 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_cubic_cyclonium_ftdi = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi", /* default usbconn driver */ - 0x09FB, /* VID */ - 0x6002 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_nios_eval_ftdi = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi", /* default usbconn driver */ - 0x09FB, /* VID */ - 0x6003 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usb_jtag_ftdi = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi", /* default usbconn driver */ - 0x16C0, /* VID */ - 0x06AD /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usbblaster_ftd2xx = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx", /* default usbconn driver */ - 0x09FB, /* VID */ - 0x6001 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_cubic_cyclonium_ftd2xx = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx", /* default usbconn driver */ - 0x09FB, /* VID */ - 0x6002 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_nios_eval_ftd2xx = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftdi", /* default usbconn driver */ - 0x09FB, /* VID */ - 0x6003 /* PID */ -}; -const urj_usbconn_cable_t urj_tap_cable_usbconn_usb_jtag_ftd2xx = { - "UsbBlaster", /* cable name */ - NULL, /* string pattern, not used */ - "ftd2xx", /* default usbconn driver */ - 0x16C0, /* VID */ - 0x06AD /* PID */ -}; +URJ_DECLARE_FTDX_CABLE(0x09FB, 0x6001, "", "UsbBlaster", usbblaster) +URJ_DECLARE_FTDX_CABLE(0x09FB, 0x6002, "", "UsbBlaster", cubic_cyclonium) +URJ_DECLARE_FTDX_CABLE(0x09FB, 0x6003, "", "UsbBlaster", nios_eval) +URJ_DECLARE_FTDX_CABLE(0x16C0, 0x06AD, "", "UsbBlaster", usb_jtag) diff --git a/urjtag/src/tap/cable/xpc.c b/urjtag/src/tap/cable/xpc.c index d873e063..8556ba0d 100644 --- a/urjtag/src/tap/cable/xpc.c +++ b/urjtag/src/tap/cable/xpc.c @@ -698,14 +698,7 @@ const urj_cable_driver_t urj_tap_cable_xpc_int_driver = { urj_tap_cable_generic_flush_using_transfer, urj_tap_cable_generic_usbconn_help }; - -const urj_usbconn_cable_t urj_tap_cable_usbconn_xpc_int = { - "xpc_int", /* cable name */ - NULL, /* string pattern, not used */ - "libusb", /* usbconn driver */ - 0x03FD, /* VID (Xilinx) */ - 0x0008 /* PID (8) */ -}; +URJ_DECLARE_USBCONN_CABLE(0x03FD, 0x0008, "libusb", "xpc_int", xpc_int) const urj_cable_driver_t urj_tap_cable_xpc_ext_driver = { "xpc_ext", @@ -725,11 +718,4 @@ const urj_cable_driver_t urj_tap_cable_xpc_ext_driver = { urj_tap_cable_generic_flush_using_transfer, urj_tap_cable_generic_usbconn_help }; - -const urj_usbconn_cable_t urj_tap_cable_usbconn_xpc_ext = { - "xpc_ext", /* cable name */ - NULL, /* string pattern, not used */ - "libusb", /* usbconn driver */ - 0x03FD, /* VID (Xilinx) */ - 0x0008 /* PID (8) */ -}; +URJ_DECLARE_USBCONN_CABLE(0x03FD, 0x0008, "libusb", "xpc_ext", xpc_ext) diff --git a/urjtag/src/tap/usbconn/libftdx.h b/urjtag/src/tap/usbconn/libftdx.h index 634b0d83..a89e130e 100644 --- a/urjtag/src/tap/usbconn/libftdx.h +++ b/urjtag/src/tap/usbconn/libftdx.h @@ -34,4 +34,22 @@ #define URJ_USBCONN_FTD2XX_MAXRECV (63 * 64) #define URJ_USBCONN_FTDX_MAXRECV (URJ_USBCONN_FTD2XX_MAXRECV < URJ_USBCONN_FTDI_MAXRECV ? URJ_USBCONN_FTD2XX_MAXRECV : URJ_USBCONN_FTDI_MAXRECV) +/* + * Helpers to avoid having to copy & paste ifdef's everywhere + */ +#ifdef ENABLE_LOWLEVEL_FTDI +#define _URJ_DECLARE_FTDI_CABLE(v, p, d, n, c) URJ_DECLARE_USBCONN_CABLE(v, p, d, n, c) +#else +#define _URJ_DECLARE_FTDI_CABLE(v, p, d, n, c) +#endif +#ifdef ENABLE_LOWLEVEL_FTD2XX +#define _URJ_DECLARE_FTD2XX_CABLE(v, p, d, n, c) URJ_DECLARE_USBCONN_CABLE(v, p, d, n, c) +#else +#define _URJ_DECLARE_FTD2XX_CABLE(v, p, d, n, c) +#endif + +#define URJ_DECLARE_FTDX_CABLE(v, p, d, n, c) \ + _URJ_DECLARE_FTDI_CABLE(v, p, "ftdi"d, n, c##_ftdi) \ + _URJ_DECLARE_FTD2XX_CABLE(v, p, "ftd2xx"d, n, c##_ftd2xx) + #endif