From c251e32521229b7bd89a765481e2cd3b1ef02357 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 18 Nov 2020 15:18:05 -0600 Subject: Fix microcom to set serial device's terminal correctly. Can't use the same set_terminal() logic as ptys because it not displaying data, it should just accurately copy it. --- lib/lib.h | 1 + lib/tty.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/lib.h b/lib/lib.h index 150133b6..431ce5ad 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -337,6 +337,7 @@ int terminal_probesize(unsigned *xx, unsigned *yy); #define KEY_ALT (1<<18) int scan_key(char *scratch, int timeout_ms); int scan_key_getsize(char *scratch, int timeout_ms, unsigned *xx, unsigned *yy); +void xsetspeed(struct termios *tio, int speed); int set_terminal(int fd, int raw, int speed, struct termios *old); void xset_terminal(int fd, int raw, int speed, struct termios *old); void tty_esc(char *s); diff --git a/lib/tty.c b/lib/tty.c index a6b4576a..b0d0c5d5 100644 --- a/lib/tty.c +++ b/lib/tty.c @@ -61,6 +61,20 @@ int terminal_probesize(unsigned *xx, unsigned *yy) return 0; } +void xsetspeed(struct termios *tio, int speed) +{ + int i, speeds[] = {50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, + 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, + 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000, + 2500000, 3000000, 3500000, 4000000}; + + // Find speed in table, adjust to constant + for (i = 0; i < ARRAY_LEN(speeds); i++) if (speeds[i] == speed) break; + if (i == ARRAY_LEN(speeds)) error_exit("unknown speed: %d", speed); + cfsetspeed(tio, i+1+4081*(i>15)); +} + + // Reset terminal to known state, saving copy of old state if old != NULL. int set_terminal(int fd, int raw, int speed, struct termios *old) { -- cgit v1.2.3