Move static usbsn into serdev structure, remove serno access function

This commit is contained in:
Stefan Rueger 2023-01-02 16:55:33 +00:00
parent 8d8157bf8b
commit 0a883973a2
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
5 changed files with 11 additions and 25 deletions

View File

@ -1569,9 +1569,9 @@ int jtag3_open_common(PROGRAMMER *pgm, const char *port) {
pmsg_notice("found CMSIS-DAP compliant device, using EDBG protocol\n");
}
// Get USB serial number function if function pointer is present
if (serial_serno)
pgm->usbsn = serial_serno();
// Copy over pointer to USB serial number function
if (serdev && serdev->usbsn)
pgm->usbsn = serdev->usbsn;
/*
* drain any extraneous input

View File

@ -649,7 +649,6 @@ union pinfo
struct serial_device {
// open should return -1 on error, other values on success
int (*open)(const char *port, union pinfo pinfo, union filedescriptor *fd);
const char *(*serno)();
int (*setparams)(const union filedescriptor *fd, long baud, unsigned long cflags);
void (*close)(union filedescriptor *fd);
@ -659,6 +658,7 @@ struct serial_device {
int (*set_dtr_rts)(const union filedescriptor *fd, int is_on);
const char *usbsn;
int flags;
#define SERDEV_FL_NONE 0x0000 /* no flags */
#define SERDEV_FL_CANSETSPEED 0x0001 /* device can change speed */
@ -672,7 +672,6 @@ extern struct serial_device avrdoper_serdev;
extern struct serial_device usbhid_serdev;
#define serial_open (serdev->open)
#define serial_serno (serdev->serno)
#define serial_setparams (serdev->setparams)
#define serial_close (serdev->close)
#define serial_send (serdev->send)

View File

@ -1578,9 +1578,9 @@ static int stk500v2_open(PROGRAMMER *pgm, const char *port) {
return -1;
}
// Get USB serial number function if function pointer is present
if (serial_serno)
pgm->usbsn = serial_serno();
// Copy over pointer to USB serial number function
if (serdev && serdev->usbsn)
pgm->usbsn = serdev->usbsn;
/*
* drain any extraneous input

View File

@ -42,12 +42,6 @@
#include "usbdevs.h"
static const char *usbsn = "";
const char *usbhid_get_serno() {
return usbsn;
}
/*
* The "baud" parameter is meaningless for USB devices, so we reuse it
* to pass the desired USB device ID.
@ -142,7 +136,8 @@ static int usbhid_open(const char *port, union pinfo pinfo, union filedescriptor
if (n) {
char *cn = cfg_malloc(__func__, n);
if (wcstombs(cn, sn, n) != (size_t) -1)
usbsn = cache_string(cn);
if(serdev)
serdev->usbsn = cache_string(cn);
free(cn);
}
}
@ -319,7 +314,6 @@ static int usbhid_drain(const union filedescriptor *fd, int display) {
*/
struct serial_device usbhid_serdev = {
.open = usbhid_open,
.serno = usbhid_get_serno,
.close = usbhid_close,
.send = usbhid_send,
.recv = usbhid_recv,

View File

@ -58,12 +58,6 @@ static int buflen = -1, bufptr;
static int usb_interface;
static const char *usbsn = "";
const char *usbdev_get_serno() {
return usbsn;
}
/*
* The "baud" parameter is meaningless for USB devices, so we reuse it
* to pass the desired USB device ID.
@ -144,7 +138,8 @@ static int usbdev_open(const char *port, union pinfo pinfo, union filedescriptor
else
strcpy(string, "[unknown]");
}
usbsn = cache_string(string);
if(serdev)
serdev->usbsn = cache_string(string);
if (usb_get_string_simple(udev,
dev->descriptor.iProduct,
product, sizeof(product)) < 0)
@ -582,7 +577,6 @@ static int usbdev_drain(const union filedescriptor *fd, int display)
struct serial_device usb_serdev =
{
.open = usbdev_open,
.serno = usbdev_get_serno,
.close = usbdev_close,
.send = usbdev_send,
.recv = usbdev_recv,
@ -596,7 +590,6 @@ struct serial_device usb_serdev =
struct serial_device usb_serdev_frame =
{
.open = usbdev_open,
.serno = usbdev_get_serno,
.close = usbdev_close,
.send = usbdev_send,
.recv = usbdev_recv_frame,