add -V option to specify a VID/PID pair, or override the default

This commit is contained in:
Triss 2021-10-05 19:34:48 +02:00
parent 4c4d94e43b
commit 7ef085140a
11 changed files with 63 additions and 23 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
*.o
mspdebug
mspdebug.exe
inst/
config.mk

View File

@ -16,6 +16,8 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-include config.mk
CC ?= gcc
INSTALL = /usr/bin/install
PREFIX ?= /usr/local

View File

@ -364,7 +364,8 @@ static device_t bsl_open(const struct device_args *args)
if (args->flags & DEVICE_FLAG_TTY)
dev->serial = comport_open(args->path, 460800);
else
dev->serial = ti3410_open(args->path, args->requested_serial);
dev->serial = ti3410_open(args->path, args->requested_serial,
args->has_vid_pid, args->vid, args->pid);
if (!dev->serial) {
free(dev);

View File

@ -75,6 +75,7 @@ struct device_breakpoint {
#define DEVICE_FLAG_DO_FWUPDATE 0x10
#define DEVICE_FLAG_SKIP_CLOSE 0x20
#define DEVICE_FLAG_BSL_NME 0x40 /* BSL no-mass-erase */
#define DEVICE_FLAG_HAS_VID_PID 0x80
struct device_args {
int flags;
@ -88,6 +89,8 @@ struct device_args {
int bsl_gpio_rts;
int bsl_gpio_dtr;
uint8_t bsl_entry_password[32];
uint16_t vid, pid;
int has_vid_pid;
};
struct device_class {

View File

@ -44,9 +44,11 @@ static device_t fet_open_rf2500(const struct device_args *args)
}
#if defined(__APPLE__)
trans = rf2500hidapi_open(args->path, args->requested_serial);
trans = rf2500hidapi_open(args->path, args->requested_serial,
args->has_vid_pid, args->vid, args->pid);
#else
trans = rf2500_open(args->path, args->requested_serial);
trans = rf2500_open(args->path, args->requested_serial,
args->has_vid_pid, args->vid, args->pid);
#endif
if (!trans)
return NULL;
@ -79,8 +81,9 @@ static device_t fet_open_olimex_iso_mk2(const struct device_args *args)
if (args->flags & DEVICE_FLAG_TTY)
trans = comport_open(args->path, 115200);
else
trans = cdc_acm_open(args->path, args->requested_serial,
115200, 0x15ba, 0x0100);
trans = cdc_acm_open(args->path, args->requested_serial, 115200,
args->has_vid_pid ? args->vid : 0x15ba,
args->has_vid_pid ? args->pid : 0x0100);
if (!trans)
return NULL;
@ -101,8 +104,9 @@ static device_t fet_open_olimex_iso_mk2(const struct device_args *args)
trans = comport_open(args->path, 115200);
else
trans = cdc_acm_open(args->path,
args->requested_serial,
115200, 0x15ba, 0x0100);
args->requested_serial, 115200,
args->has_vid_pid ? args->vid : 0x15ba,
args->has_vid_pid ? args->pid : 0x0100);
if (!trans)
return NULL;
@ -141,8 +145,9 @@ static device_t fet_open_olimex(const struct device_args *args)
if (args->flags & DEVICE_FLAG_TTY)
trans = comport_open(args->path, 115200);
else
trans = cdc_acm_open(args->path, args->requested_serial,
115200, 0x15ba, 0x0031);
trans = cdc_acm_open(args->path, args->requested_serial, 115200,
args->has_vid_pid ? args->vid : 0x15ba,
args->has_vid_pid ? args->pid : 0x0031);
if (!trans)
return NULL;
@ -177,8 +182,9 @@ static device_t fet_open_olimex_v1(const struct device_args *args)
if (args->flags & DEVICE_FLAG_TTY)
trans = comport_open(args->path, 500000);
else
trans = cp210x_open(args->path, args->requested_serial,
500000, 0x15ba, 0x0002);
trans = cp210x_open(args->path, args->requested_serial, 500000,
args->has_vid_pid ? args->vid : 0x15ba,
args->has_vid_pid ? args->pid : 0x0002);
if (!trans)
return NULL;
@ -213,7 +219,8 @@ static device_t fet_open_olimex_iso(const struct device_args *args)
trans = comport_open(args->path, 200000);
else
trans = ftdi_open(args->path, args->requested_serial,
0x15ba, 0x0008, 200000);
args->has_vid_pid ? args->vid : 0x15ba,
args->has_vid_pid ? args->pid : 0x0008, 200000);
if (!trans)
return NULL;
@ -248,7 +255,8 @@ static device_t fet_open_uif(const struct device_args *args)
if (args->flags & DEVICE_FLAG_TTY)
trans = comport_open(args->path, 460800);
else
trans = ti3410_open(args->path, args->requested_serial);
trans = ti3410_open(args->path, args->requested_serial,
args->has_vid_pid, args->vid, args->pid);
if (!trans)
return NULL;

View File

@ -228,7 +228,8 @@ static const struct transport_class rf2500_transport = {
.set_modem = usbtr_set_modem
};
transport_t rf2500_open(const char *devpath, const char *requested_serial)
transport_t rf2500_open(const char *devpath, const char *requested_serial,
int has_vid_pid, uint16_t vid, uint16_t pid)
{
struct rf2500_transport *tr = malloc(sizeof(*tr));
struct usb_device *dev;
@ -248,7 +249,8 @@ transport_t rf2500_open(const char *devpath, const char *requested_serial)
if (devpath)
dev = usbutil_find_by_loc(devpath);
else
dev = usbutil_find_by_id(USB_FET_VENDOR, USB_FET_PRODUCT,
dev = usbutil_find_by_id(has_vid_pid ? vid : USB_FET_VENDOR,
has_vid_pid ? pid : USB_FET_PRODUCT,
requested_serial);
if (!dev) {

View File

@ -27,7 +27,9 @@
*
* A particular device may be specified in bus:dev form.
*/
transport_t rf2500_open(const char *dev_path, const char *requested_serial);
transport_t rf2500hidapi_open(const char *dev_path, const char *requested_serial);
transport_t rf2500_open(const char *dev_path, const char *requested_serial,
int has_vid_pid, uint16_t vid, uint16_t pid);
transport_t rf2500hidapi_open(const char *dev_path, const char *requested_serial,
int has_vid_pid, uint16_t vid, uint16_t pid);
#endif

View File

@ -161,7 +161,8 @@ static const wchar_t * get_wc(const char *c)
return wc;
}
transport_t rf2500hidapi_open(const char *devpath, const char *requested_serial)
transport_t rf2500hidapi_open(const char *devpath, const char *requested_serial,
int has_vid_pid, uint16_t vid, uint16_t pid)
{
struct rf2500_transport *tr = malloc(sizeof(*tr));
hid_device *handle;
@ -186,7 +187,8 @@ transport_t rf2500hidapi_open(const char *devpath, const char *requested_serial)
} else {
wc_serial = NULL;
}
handle = hid_open(USB_FET_VENDOR, USB_FET_PRODUCT, wc_serial);
handle = hid_open(has_vid_pid ? vid : USB_FET_VENDOR,
has_vid_pid ? pid : USB_FET_PRODUCT, wc_serial);
if ( wc_serial ) {
free((wchar_t *)wc_serial);
}

View File

@ -559,7 +559,8 @@ static const struct transport_class ti3410_transport = {
.set_modem = ti3410_set_modem
};
transport_t ti3410_open(const char *devpath, const char *requested_serial)
transport_t ti3410_open(const char *devpath, const char *requested_serial,
int has_vid_pid, uint16_t vid, uint16_t pid)
{
struct ti3410_transport *tr = malloc(sizeof(*tr));
struct usb_device *dev;
@ -578,7 +579,8 @@ transport_t ti3410_open(const char *devpath, const char *requested_serial)
if (devpath)
dev = usbutil_find_by_loc(devpath);
else
dev = usbutil_find_by_id(USB_FET_VENDOR, USB_FET_PRODUCT,
dev = usbutil_find_by_id(has_vid_pid ? vid : USB_FET_VENDOR,
has_vid_pid ? pid : USB_FET_PRODUCT,
requested_serial);
if (!dev) {

View File

@ -24,6 +24,7 @@
/* This function is for opening an eZ430-F2013 or FET430UIF device via
* libusb.
*/
transport_t ti3410_open(const char *dev_path, const char *requested_serial);
transport_t ti3410_open(const char *dev_path, const char *requested_serial,
int has_vid_pid, uint16_t vid, uint16_t pid);
#endif

View File

@ -92,7 +92,7 @@ static const struct device_class *const driver_table[] = {
&device_loadbsl,
&device_ezfet,
&device_rom_bsl,
&device_bp
&device_bp,
};
static const char *version_text =
@ -114,6 +114,9 @@ static void usage(const char *progname)
" Connect via the given tty device, rather than USB.\n"
" -U bus:dev\n"
" Specify a particular USB device to connect to.\n"
" -V vid:pid\n"
" Specify a particular vid:pid par of a USB to connect to, instead of\n"
" a driver-specific default.\n"
" -s serial\n"
" Specify a particular device serial number to connect to.\n"
" -j\n"
@ -398,6 +401,18 @@ static int parse_cmdline_args(int argc, char **argv,
want_usb = 1;
break;
case 'V':
// optarg is in "vid:pid" format, which we now need to parse
if (sscanf(optarg, "%04hx:%04hx", &args->devarg.vid, &args->devarg.pid) == 2) {
args->devarg.flags |= DEVICE_FLAG_HAS_VID_PID;
want_usb = 1;
} else {
printc("Invalid -V option specified: %s."
"Format should be '<vid>:<pid>'\n", optarg);
exit(1);
}
break;
case 's':
args->devarg.requested_serial = optarg;
break;