Utilise str_set_vid_pid_serno() for avrfti.c

This commit is contained in:
Stefan Rueger
2026-06-18 19:17:54 +01:00
parent e684c8df1c
commit f501c8ea40
3 changed files with 25 additions and 28 deletions

View File

@@ -613,7 +613,7 @@ they are automatically identified via their vendor and product IDs from
avrdude.conf or .avrduderc. Only when there are multiple programmers of
the same type plugged into the host computer is the -P option needed, see
below. Some -c programmers, however, ignore the -P option altogether, eg,
pickit2, teensy, ch341a or avrftdi; these cannot distinguish multiple plugged-in
pickit2, teensy or ch341a; these cannot distinguish multiple plugged-in
programmers.
.Pp
Most USB programmers, however, support the command-line syntax -P
@@ -623,8 +623,8 @@ request a match of the desired device's serial number with <serialno>. The
match is done after stripping any existing colons from the given serial
number on the command line, and right-to-left, so only the least
significant bytes from the serial number need to be given. The JTAG ICE
mkII, JTAGICE3, SNAP, and PICKit5 programmers are examples for this -P
port syntax.
mkII, JTAGICE3, SNAP, PICKit5 and avrftdi programmers are examples for
this -P port syntax.
.Pp
If
.Nm

View File

@@ -637,31 +637,30 @@ static int avrftdi_pin_setup(const PROGRAMMER *pgm) {
}
static int avrftdi_open(PROGRAMMER *pgm, const char *port) {
int vid, pid, interface, err;
int vid, pid, interface, err, numids;
char serno[64] = {0};
unsigned short new_vid = 0, new_pid = 0;
Avrftdi_data *pdata = to_pdata(pgm);
pmsg_debug("%s(\"%s\")\n", __func__, port);
if(!str_caseeq(port, "usb"))
pmsg_warning("option -P %s ignored\n", port);
// Override/set pid, vid and/or serno from -P usb[:<vid>:<pid>][:<serno>]
if((numids = str_set_vid_pid_serno(port, &new_vid, &new_pid, serno, sizeof serno)) < 0) {
pmsg_error("invalid -P %s; drop -P option or use -P usb[:<vid>:<pid>][:<serno>]\n", port);
return LIBAVRDUDE_EXIT_FAIL;
}
// Parameter validation
// Use vid/pid in following priority: config, defaults cmd-line is currently not supported
if(pgm->usbvid)
vid = pgm->usbvid;
else
vid = USB_VENDOR_FTDI;
// Set vid/pid in following priority: command-line, config, default
vid = numids >= 2? new_vid: pgm->usbvid? pgm->usbvid: USB_VENDOR_FTDI;
LNODEID usbpid = lfirst(pgm->usbpid);
pid = numids >= 2? new_pid: usbpid? *(int *) ldata(usbpid): USB_DEVICE_FT2232;
if(numids < 2 && usbpid && lnext(usbpid))
pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
if(usbpid) {
pid = *(int *) ldata(usbpid);
if(lnext(usbpid))
pmsg_warning("using PID 0x%04x, ignoring remaining PIDs in list\n", pid);
} else
pid = USB_DEVICE_FT2232;
const char *serial = *serno? serno: *pgm->usbsn? pgm->usbsn: NULL; // No SN means use first available
if(pgm->usbdev[0] == 'a' || pgm->usbdev[0] == 'A')
interface = INTERFACE_A;
@@ -676,8 +675,6 @@ static int avrftdi_open(PROGRAMMER *pgm, const char *port) {
E(ftdi_set_interface(pdata->ftdic, interface) < 0, pdata->ftdic);
const char *serial = *pgm->usbsn? pgm->usbsn: NULL; // No SN means use first available
// Todo: use desc and index argument, currently set to NULL and 0
err = ftdi_usb_open_desc_index(pdata->ftdic, vid, pid, NULL, serial, 0);
if(err) {

View File

@@ -840,18 +840,18 @@ they are automatically identified via their vendor and product IDs from
@code{avrdude.conf} or @code{.avrduderc}. Only when there are multiple
programmers of the same type plugged into the host computer is the
@code{-P} option needed, see below. Some @code{-c} programmers, however,
ignore the @code{-P} option altogether, eg, pickit5, teensy, ch341a or avrftdi;
ignore the @code{-P} option altogether, eg, pickit5, teensy or ch341a;
these cannot distinguish multiple plugged-in programmers.
Most USB programmers, however, support the command-line syntax @code{-P
usb[:@var{vid}:@var{pid}][:@var{serialno}]} which allows the user to
override the vendor and product IDs with hexadecimal numbers @var{vid} and
@var{pid} and/or request a match of the desired device's serial number with
@var{serialno}. The match is done after stripping any existing colons from the
given serial number on the command line, and right-to-left, so only the
least significant bytes from the serial number need to be given. The JTAG
ICE mkII, JTAGICE3, SNAP, and PICKit5 programmers are examples for this
@code{-P} port syntax.
@var{pid} and/or request a match of the desired device's serial number
with @var{serialno}. The match is done after stripping any existing colons
from the given serial number on the command line, and right-to-left, so
only the least significant bytes from the serial number need to be given.
The JTAG ICE mkII, JTAGICE3, SNAP, PICKit5 and avrftdi programmers are
examples for this @code{-P} port syntax.
If avrdude has been configured with libserialport support, a serial port
can be specified using a predefined serial adapter type in