Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for serial port "touch" functionality using libserialport #1507

Merged
merged 19 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add serial_rawclose() to aid -r "touch" for Linux
  • Loading branch information
stefanrueger committed Oct 6, 2023
commit 6897a3f1ded5d0fee7dfa1cee3c4f80861da6ab2
3 changes: 2 additions & 1 deletion src/libavrdude.h
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ struct serial_device {
int (*open)(const char *port, union pinfo pinfo, union filedescriptor *fd);
int (*setparams)(const union filedescriptor *fd, long baud, unsigned long cflags);
void (*close)(union filedescriptor *fd);
void (*rawclose)(union filedescriptor *fd); // Don't restore terminal attributes
void (*rawclose)(union filedescriptor *fd); // Don't restore terminal attributes (Linux)

int (*send)(const union filedescriptor *fd, const unsigned char * buf, size_t buflen);
int (*recv)(const union filedescriptor *fd, unsigned char * buf, size_t buflen);
Expand All @@ -692,6 +692,7 @@ extern struct serial_device usbhid_serdev;
#define serial_open (serdev->open)
#define serial_setparams (serdev->setparams)
#define serial_close (serdev->close)
#define serial_rawclose (serdev->rawclose)
#define serial_send (serdev->send)
#define serial_recv (serdev->recv)
#define serial_drain (serdev->drain)
Expand Down
1 change: 1 addition & 0 deletions src/ser_avrdoper.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ struct serial_device avrdoper_serdev =
{
.open = avrdoper_open,
.close = avrdoper_close,
.rawclose = avrdoper_close,
.send = avrdoper_send,
.recv = avrdoper_recv,
.drain = avrdoper_drain,
Expand Down
7 changes: 6 additions & 1 deletion src/ser_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ static int net_open(const char *port, union filedescriptor *fdp) {
return ret;
}


static int ser_set_dtr_rts(const union filedescriptor *fdp, int is_on) {
unsigned int ctl;
int r;
Expand Down Expand Up @@ -431,6 +430,11 @@ static void ser_close(union filedescriptor *fd) {
close(fd->ifd);
}

// Close but don't restore attributes
static void ser_rawclose(union filedescriptor *fd) {
saved_original_termios = 0;
close(fd->ifd);
}

static int ser_send(const union filedescriptor *fd, const unsigned char * buf, size_t buflen) {
int rc;
Expand Down Expand Up @@ -598,6 +602,7 @@ struct serial_device serial_serdev =
.open = ser_open,
.setparams = ser_setparams,
.close = ser_close,
.rawclose = ser_rawclose,
.send = ser_send,
.recv = ser_recv,
.drain = ser_drain,
Expand Down
1 change: 1 addition & 0 deletions src/ser_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ struct serial_device serial_serdev =
.open = ser_open,
.setparams = ser_setparams,
.close = ser_close,
.rawclose = ser_close,
.send = ser_send,
.recv = ser_recv,
.drain = ser_drain,
Expand Down
2 changes: 1 addition & 1 deletion src/serialadapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ int touch_serialport(char **portp, int baudrate, int nwaits) {
return -1;
}
serial_set_dtr_rts(&fd, 0);
serial_close(&fd);
serial_rawclose(&fd);

int nloops = 32, nap = 50;
#if defined(__arm__)
Expand Down
1 change: 1 addition & 0 deletions src/usb_hidapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ static int usbhid_drain(const union filedescriptor *fd, int display) {
struct serial_device usbhid_serdev = {
.open = usbhid_open,
.close = usbhid_close,
.rawclose = usbhid_close,
.send = usbhid_send,
.recv = usbhid_recv,
.drain = usbhid_drain,
Expand Down
2 changes: 2 additions & 0 deletions src/usb_libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ struct serial_device usb_serdev =
{
.open = usbdev_open,
.close = usbdev_close,
.rawclose = usbdev_close,
.send = usbdev_send,
.recv = usbdev_recv,
.drain = usbdev_drain,
Expand All @@ -591,6 +592,7 @@ struct serial_device usb_serdev_frame =
{
.open = usbdev_open,
.close = usbdev_close,
.rawclose = usbdev_close,
.send = usbdev_send,
.recv = usbdev_recv_frame,
.drain = usbdev_drain,
Expand Down
1 change: 1 addition & 0 deletions src/xbee.c
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ static int xbeedev_set_dtr_rts(const union filedescriptor *fdp, int is_on)
static struct serial_device xbee_serdev_frame = {
.open = xbeedev_open,
.close = xbeedev_close,
.rawclose = xbeedev_close,
.send = xbeedev_send,
.recv = xbeedev_recv,
.drain = xbeedev_drain,
Expand Down