Allow pickit5 vid/pid be specified as 0

This commit is contained in:
stefanrueger
2025-10-23 14:44:12 +02:00
parent a6553e80d3
commit f44301d5bc

View File

@@ -579,12 +579,12 @@ static int pickit5_open(PROGRAMMER *pgm, const char *port) {
return -1;
#endif
if(!str_starts(port, "usb")) {
pmsg_error("port names must start with usb\n");
if(!str_starts(port, "usb:") && !str_eq(port, "usb")) {
pmsg_error("port name %s must be usb:<vid>:<pid> or usb:<serno>\n", port);
return -1;
}
unsigned int new_vid = 0, new_pid = 0;
char *vidp, *pidp;
unsigned int new_vid = 0, new_pid = 0, setids = 0;
const char *vidp, *pidp;
/*
* The syntax for usb devices is defined as:
@@ -608,6 +608,7 @@ static int pickit5_open(PROGRAMMER *pgm, const char *port) {
vidp += 1;
pidp = strchr(vidp, ':');
if(pidp != NULL) {
setids = 1;
if(vidp != pidp) { // User specified an VID
// First: Handle VID input
if(sscanf(vidp, "%x", &new_vid) != 1) {
@@ -624,10 +625,8 @@ static int pickit5_open(PROGRAMMER *pgm, const char *port) {
return -1;
}
if((new_vid != 0) && (new_pid != 0)) {
pmsg_notice("overwriting VID:PID to %04x:%04x\n", new_vid, new_pid);
port = "usb"; // Overwrite the string to avoid confusing the libusb
}
pmsg_notice("overwriting VID:PID to %04x:%04x\n", new_vid, new_pid);
port = "usb"; // Overwrite the string to avoid confusing the libusb
} // pidp == NULL means vidp could point to serial number
} // vidp == NULL means just 'usb'
@@ -639,7 +638,7 @@ static int pickit5_open(PROGRAMMER *pgm, const char *port) {
// PICkit 5 does not have support for HID, so no need to support it
serdev = &usb_serdev;
if(new_pid != 0 && new_vid != 0) { // In case a specific VID/PID was specified
if(setids) { // In case a specific VID/PID was specified
pinfo.usbinfo.vid = new_vid;
pinfo.usbinfo.pid = new_pid;
pinfo.usbinfo.flags = PINFO_FL_SILENT;