Skip to content

Commit

Permalink
Merge pull request #1880 from MCUdude/usbproduct
Browse files Browse the repository at this point in the history
Make usbproduct available to programmers
  • Loading branch information
stefanrueger authored Aug 14, 2024
2 parents beaebd9 + 14d6e16 commit 2407424
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,7 @@ struct serial_device {
int (*set_dtr_rts)(const union filedescriptor *fd, int is_on);

const char *usbsn;
const char *usbproduct;
int flags;
#define SERDEV_FL_NONE 0x0000 /* no flags */
#define SERDEV_FL_CANSETSPEED 0x0001 /* device can change speed */
Expand Down
10 changes: 7 additions & 3 deletions src/stk500v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -2156,9 +2156,13 @@ static int stk500v2_open(PROGRAMMER *pgm, const char *port) {
return -1;
}

// Make USB serial number available to programmer
if (serdev && serdev->usbsn)
pgm->usbsn = serdev->usbsn;
// Make USB serial number and USB product name available to programmer
if (serdev) {
if (serdev->usbsn)
pgm->usbsn = serdev->usbsn;
if (serdev->usbproduct)
pgm->usbproduct = serdev->usbproduct;
}

// Drain any extraneous input, synchronise and drain again
if(stk500v2_drain(pgm, 0) < 0 || stk500v2_getsync(pgm) < 0 || stk500v2_drain(pgm, 0) < 0)
Expand Down
13 changes: 13 additions & 0 deletions src/usb_hidapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,19 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
}
}

// Store USB product string to prod_str
wchar_t prodstr[256];
if (hid_get_product_string(dev, prodstr, sizeof(prodstr)/sizeof(*prodstr)) == 0) {
size_t n = wcstombs(NULL, prodstr, 0) + 1;
if (n) {
char *cn = mmt_malloc(n);
if (wcstombs(cn, prodstr, n) != (size_t) -1)
if(serdev)
serdev->usbproduct = cache_string(cn);
mmt_free(cn);
}
}

fd->usb.handle = dev;

/*
Expand Down
2 changes: 2 additions & 0 deletions src/usb_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
pmsg_warning("reading product name, %s\n", usb_strerror());
strcpy(product, "[unnamed product]");
}
if(serdev)
serdev->usbproduct = cache_string(product);

/* We need to write to endpoint 2 to switch the PICkit4 and SNAP
* from PIC to AVR mode
Expand Down

0 comments on commit 2407424

Please sign in to comment.